Doorgaan naar hoofdcontent

Lock-ups and freezes w/ an STM32F4Discovery board with ST-Link v2, OpenOCD and GDB

This post is especially an outing of my joy now that I have finally resolved my issue debugging the STM32F4xx using OpenOcd.

There exist many blogpost, tutorials, manuals about setting up an STM32F4Discovery + OpenOcd + gdb combo.
I won't explain how to do it here, but it is an awesome, powerful and very cheap set-up.

I chose the STM32F4Discovery board as the demo board for my course on embedded C, because it's cheap, full of features and has on-board debugging hardware.

Writing a custom crt0, I ran into problems however. Stepping through the early init code, assembly instruction per assembly instruction, gdb would just lock-up, freeze, at random moments. Not always on the same instruction, not always at the same moment. I could also set a breakpoint on a certain line, then type 'c' to continue, and the debugger would never break, or even respond to a Ctrl+C.

Furthermore, using st-util, from the texane github (https://github.com/texane/stlink) would work.It's awefully slow (especially when using the split layout in gdb-tui, that disassbles on-the-fly)

Digging up a mailinglist message from about a year ago (http://www.mail-archive.com/openocd-devel@lists.sourceforge.net/msg01605.html) I finally found the solution to the problem.

The STM32F4 features a "DBGMCU" register,
which by default will leave the debug function of the mcu in an unpowered state when in standby, stop or sleep mode.

Changed my openocd.cfg file to:
 #Include configs from openocd  
 source [find board/stm32f4discovery.cfg]  
 source [find mem_helper.tcl]  
 # Disable power-saving for debug circuitry  
 $_TARGETNAME configure -event reset-init {  
   # allow debugging during sleep/stop/standby modes:  
   # set DBG_SLEEP, DBG_STOP and DBG_STANDBY bits in DBGMCU_CR  
   mmw 0xe0042004 0x7 0x0  
 }  

Then, additionally, it is very important to reset the board in a clean way.
For this, issue a "monitor reset halt" command. I automated it by adding it to my .gdbinit file:
 tar ext :3333
 monitor halt
 file out/main.elf
 load out/main.elf
 monitor reset halt
 stepi
This config will make gdb(tui) automatically connect to openocd, then stop the cpu, flash the ELF file, load symbols from the elf file, reset the mcu in a clean way and then step to the first instruction to be executed.
This leaved the cpu halted, at the first assembly instruction. From there, you can set-up breakpoints, or just hit 'c' to start running. 

Once I had taken care of both these topics, gone was my trouble!

Happy debugging!

Reacties

Populaire posts van deze blog

[RPi4][ Using the PiMoroni Fan Shim on LibreElec including the LEDs!

I recently bought a brand new Raspberry Pi 4, and wanted to try Kodi on it. There is only one Kodi-distribution which has more or less decent support for RPi 4 at the moment, and that's LibreElec (although still Alpha). Since the RPi 4 is famously overheating and throttling without a fan or at least a heatsink, I got a PiMoroni Fan Shim. Nice piece of hardware, but their library cannot run on LibreElec, because they do not support installing python libraries through pip etc... On LibreElec, the whole rootfs is a read-only squashfs image. So there's no way you can install the Pimoroni python library on LibreElec, but I found an alternative: I found Phil Randal's blog at  http://www.philrandal.co.uk/blog/archives/2019/07/entry_214.html , where he described how to get at least the Fan portion of the Fan Shim working on LibreElec. I decided to build on that, and port the LED functionality to LibreElec as well, without the need for "pip install" or a

The excellent JTAGenum for Arduino

As I said before, I've been fiddling with finding the JTAG port on a Verbatim PowerBay NAS. I did not succeed (yet), but have had the chance to try out JTAGenum for Arduino. It is an excellent JTAG pin finder (and other things too). Check it out here: http://deadhacker.com/2010/02/03/jtag-enumeration/ The guy's description of the tool is: 1. Given a large set of pins on a device determine which are JTAG lines 2. Enumerate the Instruction Register to find undocumented functionality 3. be easy to build and apply It's really easy to use, but it did not manage to find the JTAG pins on my device. There might be another problem, such as: - JTAG is disabled once the device is powered up - The pins I'm fiddling with are not JTAG pins - I ruined the circuitry already - I'm just not trying hard enough Back to JTAGenum: Since Arduino IDE 1.0.1 , some things have changed and so the GIT version of JTAGenum would not compile as-is. Therefor the JTAGenum sketch had

Arch Linux: Fixing empty/blank windows for graphical applications that require root

When running applications such as "unetbootin" or "tuxboot", you might get a blank window, instead of the actual application. Even when running it through "gksudo", or having a decent polkit running (e.g. inside Gnome). E.g.: This is because these application use MIT_SHM (Shared memory), which for some reason does not work when running graphical applications as root, while being logged in as a regular user in X. The solution is to disable MIT_SHM. E.g.: $ sudo QT_X11_NO_MITSHM=1 tuxboot