cancel
Showing results for 
Search instead for 
Did you mean: 

Thread awareness debugging in FreeRTOS [STM32CubeIDE 1.1.0 has a bug for using "-rtos FreeRTOS" on ST-LINK(OpenOCD)].

KOkun.1048
Associate III

In STM32CubeIDE 1.0.2, after I added '-c "$_TARGETNAME configure -rtos FreeRTOS"' to 'OpenOCD Options', I could debug FreeRTOS's target with threading mode.

But, in STM32CubeIDE 1.1.0, even if I set same settings to 'OpenOCD Options', I could not debug with threading mode. In this version, openocd outputs 'Error: No symbols for FreeRTOS'.

Could you please check about this?

31 REPLIES 31
egoltzman
Senior

I'm using CubeIDE 1.3.1

My project is an STM32L496VG based FreeRTOS & TouchGFX project with mixed C and C++

I successfully build run and debug the project with ST-Link (OpenOCD)

I follow the list of actions above and did all of them but I can't get the Thread awareness to work.

  • I added a file with this code:
#include "FreeRTOS.h"
 
#ifdef __GNUC__
#define USED __attribute__((used))
#else
#define USED
#endif
 
const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1;
  • I set OpenOCD options to -c "$_TARGETNAME configure -rtos FreeRTOS"
  • In the run command I added - symbol-file Debug/MY_PROJECT.elf (Where MY_PROJECT is the project name)
  • I set the starting breakpoint to the first Task (TouchGFX_Task)

I get this terminal output:

Open On-Chip Debugger 0.10.0+dev-01193-g5ce997d (2020-02-20-10:57)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 8000 kHz
adapter_nsrst_delay: 100
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 8000 kHz
Info : STLINK V2J36S26 (API v2) VID:PID 0483:374B
Info : using stlink api v2
Info : Target voltage: 3.264694
Info : SRST line asserted
Info : STM32L496VGYxP.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Error: No symbols for FreeRTOS
Info : SRST line released
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000590 msp: 0x20050000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
Info : device idcode = 0x20006461 (STM32L49/L4Axx - Rev: B)
Info : flash size = 1024kbytes
Info : flash mode : dual-bank
Info : SRST line asserted
Info : SRST line released
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000590 msp: 0x20050000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
Info : Padding image section 0 at 0x080001ac with 4 bytes
Warn : Padding 4 bytes to keep 8-byte write size
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x20000050 msp: 0x20050000
Info : block write succeeded
Warn : keep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (5141). Workaround: increase "set remotetimeout" in GDB
Info : SRST line asserted
Info : SRST line released
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000590 msp: 0x20050000
Error: FreeRTOS: uxTopUsedPriority is not defined, consult the OpenOCD manual for a work-around

I can see here two issues:

  1. Error: No symbols for FreeRTOS even though I added the "symbol-file" command
  2. Error: FreeRTOS: uxTopUsedPriority is not defined, consult the OpenOCD manual for a work-around even though I can see the symbole in my map:
.rodata.uxTopUsedPriority
                0x0000000000000000        0x4 Application/User/openOCD_ThreadAware.o

What I'm doing wrong?

@DB.7abatunde​ , @egoltzman​ 

Please add the following option to linker options.

-Wl,-undefined=uxTopUsedPriority

And, please confirm your uxTopUsedPriority symbol, again.

In my map file,

 .rodata.uxTopUsedPriority

        0x000000000803eff8        uxTopUsedPriority

Maybe, in your binary, uxTopUsedPriority was eliminated, since the symbol is not reffered.

Thank you KOkun!

The linker option did the job

KOkun.1048
Associate III

Update procedure.

  1. add work-around for openocd to your codes (Please refer to the bellow "uxTopUsedPriority")
  2. add `-Wl,-undefined=uxTopUsedPriority' to linker options
  3. select ST-LINK(OpenOCD) . "Debug Configurations => Debugger => Debug Probe"
  4. add `-c "$_TARGETNAME configure -rtos FreeRTOS" ' to "Debug Configurations => Debugger => OpenOCD Options"
  5. change break point from main to first task entry function in "Debug Configurations => Startup => Set breakpoint at"
  6. add `symbol-file BUILD_DIR/YOUR_TARGET.elf ' to "Debug Configurations => Startup => Run Commands"
#include "FreeRTOS.h"
 
#ifdef __GNUC__
#define USED __attribute__((used))
#else
#define USED
#endif
 
const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1;

(*)YOUR_TARGET.elf means the elf binary with debug symbols.

(*)BUILD_DIR is the directory includes YOUR_TARGET.elf. and separator is "/" even if windows platform.

In STM32CubeIDE 1.0.2, "6." procedure is not needed. But, after STM32CubeIDE 1.1.0, "6." is needed for thread awareness debug.

ST members, could you confirm this?

egoltzman
Senior

I checked this on CubeIDE 1.3.1 and it is working

I checked this on CubeIDE 1.3.1 and it's working too.

That fixed it. Cheers!

Many thanks for sharing your solution!

However I am struggling with linker part - 2.

In my CUBE v1.3.1 the linker options appears to be read only. That is at: Properties=>C/C++ Build=>ToolSettings=>MCU GCC Linker=>All options

Sorted my issue above: just add the linker fix to the Command box:

Properties=>C/C++ Build=>ToolSettings=>MCU GCC Linker=>Command:

and change "gcc" to "gcc -Wl,-undefined=uxTopUsedPriority"

KOkun.1048
Associate III

Please add "-Wl,-undefined=uxTopUsedPriority" to your linker options.

JBeca.1
Associate II

Hi,

I'm using STm32F446RE and I don't reach a valid configuration to debug with multi thread support. I'm using st cube ide 1.2.0

I followed the 6 steps defined by @KOkun.1048​ and I get error allocating threads. This is the error message:

Open On-Chip Debugger 0.10.0+dev-00022-g02bea1f (2020-01-08-09:31)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 8000 kHz
adapter_nsrst_delay: 100
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 8000 kHz
Info : STLINK v2.1 JTAG v35 API v2 M26 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.248915
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Stlink adapter speed set to 4000 kHz
Info : STM32F446RETx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800099c msp: 0x20020000
configuring PLL
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Stlink adapter speed set to 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
Info : device id = 0x10006421
Info : flash size = 512kbytes
Info : Padding image section 0 with 12 bytes
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x20000046 msp: 0x20020000
Error: Error allocating memory for -184299509 threads
Error: Error allocating memory for -184299509 threads

Any idea?

Thanks for you support

Jordi