Jelajahi Sumber

Add build target for flashing F1 devices via OpenOCD.

Keir Fraser 4 tahun lalu
induk
melakukan
c5d9e6a5ab
3 mengubah file dengan 36 tambahan dan 1 penghapusan
  1. 4 1
      Makefile
  2. 10 0
      scripts/openocd/f1.cfg
  3. 22 0
      scripts/openocd/flash.py

+ 4 - 1
Makefile

@@ -2,7 +2,7 @@
 export FW_MAJOR := 0
 export FW_MINOR := 25
 
-TARGETS := all blinky clean dist windist mrproper ocd flash start serial pysetup
+TARGETS := all blinky clean dist windist mrproper f1_ocd ocd flash start serial pysetup
 .PHONY: $(TARGETS)
 
 ifneq ($(RULES_MK),y)
@@ -101,6 +101,9 @@ ocd: all
 	$(PYTHON) scripts/telnet.py localhost 4444 \
 	"reset init ; flash write_image erase `pwd`/$(PROJ)-$(VER).hex ; reset"
 
+f1_ocd: all
+	python3 scripts/openocd/flash.py `pwd`/$(PROJ)-$(VER).hex
+
 flash: all
 	sudo stm32flash -b $(BAUD) -w $(PROJ)-$(VER).hex $(DEV)
 

+ 10 - 0
scripts/openocd/f1.cfg

@@ -0,0 +1,10 @@
+# Uncomment the following for APM32F103
+#set CPUTAPID 0x2ba01477
+
+source [find interface/stlink.cfg]
+
+transport select hla_swd
+
+source [find target/stm32f1x.cfg]
+
+reset_config srst_only connect_assert_srst

+ 22 - 0
scripts/openocd/flash.py

@@ -0,0 +1,22 @@
+# flash.py <hex_filename>
+
+import os, sys, time, telnetlib
+
+cmd = 'reset init ; flash write_image erase %s ; reset\n' % sys.argv[1]
+
+# Start the OpenOCD daemon in the background and connect via telnet
+def open_ocd():
+    os.system('openocd -f scripts/openocd/f1.cfg &')
+    while True:
+        time.sleep(0.5)
+        try:
+            t = telnetlib.Telnet('localhost', 4444)
+        except:
+            pass
+        else:
+            return t
+
+with open_ocd() as t:
+    t.write(cmd.encode('utf-8'))
+    t.write('shutdown\n'.encode('utf-8'))
+    t.read_all() # Waits for EOF (telnet session shutdown)