Close

stm32g0, openocd, and mecrisp stellaris - part 4

andrew-clappAndrew Clapp wrote 11/17/2021 at 00:18 • 2 min read • Like

One of the cool things about using openocd is that you can interact with it, say to figure stuff out for the first time.  Then you can program it to be consistent.  For example, reading the option bytes worked out like this.

1) Make this openocd.cfg:

source [find /usr/local/share/openocd/scripts/interface/stlink.cfg]
source [find /usr/local/share/openocd/scripts/target/stm32g0x.cfg]
gdb_memory_map enable
gdb_flash_program enable
init
reset_config trst_and_srst
jtag configure stm32g0x.jrc -event setup "jtag tapenable stm32g0x.cpu"
jtag tapisenabled stm32g0x.cpu
dap create CPU -chain-position stm32g0x.cpu

2) Now, fire up openocd.

et:option-bytes$ openocd
Open On-Chip Debugger 0.10.0+dev-00937-g8021aef90 (2021-11-03-16:13)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 2000 kHz
Info : STLINK V2J38S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.278873
Info : stm32g0x.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : Listening on port 3333 for gdb connections
1
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

 3) In another window, connect to it via telnet:

telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> jtag tapisenabled stm32g0x.cpu
1
> stm32l4x option_read 0 0x00
device id = 0x10016466
flash size = 16kbytes
Single Bank 16 kiB STM32G03x/G04x/G07x/G08x found
Option Register: <0x40022000> = 0x40600
> exit
Connection closed by foreign host.

I verified that the config worked, and the trap is enabled, just nice to know.  Then I read the option bytes.  Now that I have figured out exactly what was needed to read the option bytes, I don't want to have to fire up openocd and telnet to the instance every time.  That would be great for doing some real time debug work, but I am using forth, which pretty much does that for me already.  So, I want a convenient way to get the option bytes.  I have the command I want the output of, so I just tell openocd to run the command and exit.

et:option-bytes$ openocd -d0 -f read-opt-bytes-1 -c "stm32l4x option_read 0 0x20" -c "exit"
Open On-Chip Debugger 0.10.0+dev-00937-g8021aef90 (2021-11-03-16:13)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 0

Option Register: <0x40022020> = 0xfffffeaa

et:option-bytes$ openocd -d0 -f read-opt-bytes-2 -c "stm32l4x option_read 0 0x20" -c "exit"
Open On-Chip Debugger 0.10.0+dev-00937-g8021aef90 (2021-11-03-16:13)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 0

Option Register: <0x40022020> = 0xfffffeaa

So there it is, running the same process interactively, then programming it to be a scripted command that can be run.  I hope you find this information useful.

Like

Discussions