Skip to content

Commit

Permalink
openocd: Add 'make ocd' target
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Aug 21, 2020
1 parent 9a5a29a commit c43c285
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ endif
BAUD=115200
DEV=/dev/ttyUSB0

flash:
ocd: gotek
python3 scripts/openocd/flash.py `pwd`/FF_Gotek-$(VER).hex

flash: gotek
sudo stm32flash -b $(BAUD) -w FF_Gotek-$(VER).hex $(DEV)

start:
Expand Down
8 changes: 8 additions & 0 deletions scripts/openocd/f1.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

source [find interface/stlink.cfg]

transport select hla_swd

source [find target/stm32f1x.cfg]

reset_config srst_only connect_assert_srst
22 changes: 22 additions & 0 deletions scripts/openocd/flash.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c43c285

Please sign in to comment.