Skip to content

Commit

Permalink
fw/flash.py: Support erasing the entire chip
Browse files Browse the repository at this point in the history
  • Loading branch information
jpieper committed Sep 9, 2021
1 parent 84a4522 commit f03b6fc
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions fw/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import platform
import subprocess
import sys
Expand All @@ -27,17 +28,21 @@


def main():
tmpdir = tempfile.TemporaryDirectory()
parser = argparse.ArgumentParser()
parser.add_argument('--erase', action='store_true')
parser.add_argument(
'elffile', nargs='?',
default='bazel-out/stm32g4-opt/bin/fw/moteus.elf')
parser.add_argument(
'bootloader', nargs='?',
default='bazel-out/stm32g4-opt/bin/fw/can_bootloader.elf')

args = parser.parse_args()

moteus_elffile = (
sys.argv[1]
if len(sys.argv) > 1 else
'bazel-out/stm32g4-opt/bin/fw/moteus.elf')
tmpdir = tempfile.TemporaryDirectory()

bootloader_elffile = (
sys.argv[2]
if len(sys.argv) > 2 else
'bazel-out/stm32g4-opt/bin/fw/can_bootloader.elf')
moteus_elffile = args.elffile
bootloader_elffile = args.bootloader

subprocess.check_call(
f'{OBJCOPY} -Obinary ' +
Expand All @@ -60,6 +65,8 @@ def main():
subprocess.check_call(
f'{OPENOCD} -c "init" ' +
f'-c "reset_config none separate; ' +
f' halt; ' +
(f' stm32l4x mass_erase 0; ' if args.erase else '') +
f' program {tmpdir.name}/out.08000000.bin verify 0x8000000; ' +
f' program {tmpdir.name}/out.0800c000.bin verify 0x800c000; ' +
f' program {tmpdir.name}/out.08010000.bin verify ' +
Expand Down

0 comments on commit f03b6fc

Please sign in to comment.