stm32duino : Debugging FreeRTOS threads


Debugging multi threaded program can be a real pain if you don't have thread support in the debugger.

In my case, i'm debugging the STM32DUINO_DSO firmware which have ~ 4 threads running on top of FreeRTOS 10.2

I usually use my blackmagic, but it seems having it support FreeRTOS is not coming soon.

So back to stlink v2 (cheap ebay clone) and openocd

The openOcd version provided by ubuntu is recent enough, good.

1. openOcd configuration file


Let's create a new profile for the bluepill, just activating FreeRTOS support.
    cd /usr/share/openocd
    cp scripts/target/stm32f1x.cfg scripts/target/bluepill.cfg
  sudo vi scripts/target/bluepill.cfg

There is only one line to change to activate freeRTOS support

Look for $_TARGETNAME configure and add "-rtos FreeRTOS" just after configure
i.e. line 47 becomes 

$_TARGETNAME configure -rtos FreeRTOS -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
Good, almost done

2. help script


Second create a debugOcd.sh script that you can call by just doing
~/debugOcd.sh the_elf_to_debug.elf

   #!/bin/sh
   export PFX=/home/fx/Arduino_stm32/arm-none-eabi-gcc/download/gcc-arm-none-eabi-8.2.1-1.7/bin/
   ${PFX}arm-none-eabi-gdb-py3 -x  /home/fx/openocd.gdb $@


Last, create the gdb command script (in my case /home/fx/openocd.gdb)

   target remote localhost:3333
   set confirm off
   load

It is a very basic version of it.

3- Change FreeRTOSConfig.h


A symbol needed by openOcd has changed name, let's rename it back through FreeRTOSConfig.h by adding
    #define uxTopReadyPriority uxTopUsedPriority
at the top of the file

4. Start openOcd


Let's start openOcd, using our bluepill.cfg script ...
   openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -
f /usr/share/openocd/scripts/target/bluepill.cfg

5. and use

and connect
   bash ~/debugOcd.sh DSO_150.elf

   (gdb) info threads
   [New Thread 536884536]
   [New Thread 536881816]
   [New Remote target]
    Id   Target Id                                     Frame
   * 1    Thread 536882416 (Name: IDLE, State: Running) 0x08002178 in __start__ ()
    2    Thread 536884536 (Name: Capture)              0xa5a5a5a4 in ?? ()
    3    Thread 536881816 (Name: MainTask)             xQueueSemaphoreTake (xQueue=0x200031d0 <ucHeap+2928>,  
   xTicksToWait=<optimized out>, xTicksToWait@entry=11) at /home/fx/Arduino_stm32/dso/MapleFreeRTOS1000/Source/queue.c:1569
    4    Remote target  

Comments

Popular posts from this blog

Component tester with STM32 : Part 1 ADC, Resistor

Fixing the INA3221

INA3221, weird wiring