Skip to main content
KOkun.1048
Associate II
October 23, 2019
Question

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

  • October 23, 2019
  • 20 replies
  • 16100 views

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?

This topic has been closed for replies.

20 replies

MMitc
Associate III
November 9, 2019

Not an answer, but I also have this problem, no thread awareness. I never had it working before. But I've tried everything I can find written about this.

Note that the Debug Tab does not show threads, but the NXP Task Aware Debugger eclipse add in does show threads and queues version 1.0.2 (201704260904)

So this appears to be an STM32Cube issue.

Version: 1.1.0 Build: 4551_20191014-1140 (UTC)

Probe: ST-LINK OpenOCD

Target : NUCLEO-L476RG

I have included the special file for newer FreeRTOS:

#include "FreeRTOS.h"
 
#ifdef __GNUC__
#define USED __attribute__((used))
#else
#define USED
#endif
 
const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1;

and this is in the map file: 

.rodata.uxTopUsedPriority
 0x0000000008012810 0x4 Core/Src/freertos_openocd_patch.o
 0x0000000008012810 uxTopUsedPriority

I am using a user defined script so that last line can be added:

# This is an genericBoard board with a single STM32L476RGTx chip
#
# Generated by STM32CubeIDE
# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)
 
source [find interface/stlink.cfg]
 
set WORKAREASIZE 0x8000
 
transport select "hla_swd"
 
set CHIPNAME STM32L476RGTx
set BOARDNAME genericBoard
 
# Enable debug when in low power modes
set ENABLE_LOW_POWER 1
 
# Stop Watchdog counters when halt
set STOP_WATCHDOG 1
 
# STlink Debug clock frequency
set CLOCK_FREQ 4000
 
# Reset configuration
# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI...)
reset_config srst_only srst_nogate connect_assert_srst
set CONNECT_UNDER_RESET 1
set CORE_RESET 0
 
# BCTM CPU variables
 
source [find target/stm32l4x.cfg]
$_TARGETNAME configure -rtos FreeRTOS
 

Console Log:

Open On-Chip Debugger 0.10.0+dev-00021-g524e8c8 (2019-10-14-11:52)
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
padded zone erase set to 1
adapter speed: 4000 kHz
adapter_nsrst_delay: 100
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 4000 kHz
Info : STLINK v2.1 JTAG v34 API v2 M25 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.225841
Info : Stlink adapter speed set to 4000 kHz
Info : STM32L476RGTx.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: 0x080032a8 msp: 0x20018000
Info : Stlink adapter speed set to 4000 kHz
adapter speed: 4000 kHz
Info : Device id = 0x10076415
Info : STM32L4xx flash size is 1024kb, base address is 0x8000000
Info : Erase the padded zone before the write
Warn : Adding extra erase range, 00000000 to 0x00000187
Warn : Adding extra erase range, 0x00000190 to 0x000007ff
Info : Padding image section 0 with 8 bytes
Warn : Padding 4 bytes to keep 8-byte write size
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x20000050 msp: 0x20018000
Error: No symbols for FreeRTOS

Notice it is trying to find the symbols, but does not.

I also tried the config with: $_TARGETNAME configure -rtos auto but then it does not even get the Error message.

KOkun.1048
Associate II
November 11, 2019

Thank you for your comment.

I had add the following code you pointed out from before.

In CubeIDE 1.0.2, thread awareness worked as expected. But, CubeIDE 1.1.0 does not work.

I think openocd in CubeIDE 1.1.0 has a bug.

#include "FreeRTOS.h"
 
#ifdef __GNUC__
#define USED __attribute__((used))
#else
#define USED
#endif
 
const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1;

KOkun.1048
Associate II
November 11, 2019

I found the work-around. In STM32CubeIDE 1.1.0, I could success thread awareness debug.

After I add "symbol-file MY_TARGET.elf" to "Debug Configurations => Startup => Run Commands", I could success thread awareness debug in FreeRTOS target.

In STM32CubeIDE 1.0.2, this work-around is not needed.

Summary,

  1. add work-around for openocd to your codes (Please refer to the upper "uxTopUsedPriority")
  2. select ST-LINK(OpenOCD) . "Debug Configurations => Debugger => Debug Probe"
  3. add `-c "$_TARGETNAME configure -rtos FreeRTOS" ' to "Debug Configurations => Debugger => OpenOCD Options"
  4. add `symbol-file YOUR_TARGET.elf ' to "Debug Configurations => Startup => Run Commands"

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

MMitc
Associate III
November 11, 2019

@User15718233458848318581 Thanks SO much! Your addition if add `symbol-file YOUR_TARGET.elf ' to "Debug Configurations => Startup => Run Commands" fixed it for me.

Note that in Windows, just putting the filename was insufficient, I had the add the whole path, and reverse the slashes to be unix like. ST folks, this maybe where the bug is.

It's also odd that the debugger did not otherwise seem to lack symbols, so it's kind of nonsensical that this command would need to be added at all.

KOkun.1048
Associate II
November 12, 2019

Yes, we need `symbol-file BUILD_DIR/YOUR_TARGET.elf ' ​in all platform (at least Windows and Linux).

KOkun.1048
Associate II
November 12, 2019

Summary,

  1. add work-around for openocd to your codes (Please refer to the upper "uxTopUsedPriority")
  2. select ST-LINK(OpenOCD) . "Debug Configurations => Debugger => Debug Probe"
  3. add `-c "$_TARGETNAME configure -rtos FreeRTOS" ' to "Debug Configurations => Debugger => OpenOCD Options"
  4. change break point from main to first task entry function in "Debug Configurations => Startup => Set breakpoint at"
  5. add `symbol-file BUILD_DIR/YOUR_TARGET.elf ' to "Debug Configurations => Startup => Run Commands"

(*)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, "5." is not needed. But, In STM32CubeIDE 1.1.0 "5." is needed for thread awareness debug.

ST members, could you confirm this?

dave2012
Associate III
December 27, 2019

KOkun.1048,

I tried your steps but I see the following in the OpenOCD debug console:

"Error: Error allocating memory for 134271793 threads"

It seems that perhaps 'uxTopUsedPriority' is being read as 0x0800D331 (134271793) but I've checked this symbol exists via the debugger and its value is 56.

Any suggestions ?

Thanks

Dave

KOkun.1048
Associate II
January 6, 2020

Hi daveb1,

I didn't encounter your situation.

I think that the error message comes from the followings.

<openocd/src/rtos/FreeRTOS.c>

 if ((thread_list_size == 0) || (rtos->current_thread == 0)) {
 /* Either : No RTOS threads - there is always at least the current execution though */
 /* OR : No current thread - all threads suspended - show the current execution
 * of idling */
 char tmp_str[] = "Current Execution";
 thread_list_size++;
 tasks_found++;
 rtos->thread_details = malloc(
 sizeof(struct thread_detail) * thread_list_size);
 if (!rtos->thread_details) {
 LOG_ERROR("Error allocating memory for %d threads", thread_list_size);
 return ERROR_FAIL;
 }
 rtos->thread_details->threadid = 1;
 rtos->thread_details->exists = true;
 rtos->thread_details->extra_info_str = NULL;
 rtos->thread_details->thread_name_str = malloc(sizeof(tmp_str));
 strcpy(rtos->thread_details->thread_name_str, tmp_str);
 
 if (thread_list_size == 1) {
 rtos->thread_count = 1;
 return ERROR_OK;
 }
 } else {
 /* create space for new thread details */
 rtos->thread_details = malloc(
 sizeof(struct thread_detail) * thread_list_size);
 if (!rtos->thread_details) {
 LOG_ERROR("Error allocating memory for %d threads", thread_list_size);
 return ERROR_FAIL;
 }
 }

Maybe you misunderstand the pointer and the entity for 'uxTopUsedPriority'.

Please check your 'uxTopUsedPriority' type.

Regards,

Koji

ConfusedContrarian
Associate III
February 6, 2020

@KOkun.1048​ , @MMitc​ , could you please elaborate on where you add the openocd workaround? I'm having trouble with thread-awareness as well. I created a new .c file and added it there but I still get the same error  FreeRTOS: uxTopUsedPriority is not defined, consult the OpenOCD manual for a work-around

egoltzman
Senior
May 2, 2020

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?

KOkun.1048
Associate II
May 3, 2020

@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.

egoltzman
Senior
May 3, 2020

Thank you KOkun!

The linker option did the job

KOkun.1048
Associate II
May 3, 2020

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?

TAyi
Visitor II
May 8, 2020

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