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
MMitc
Associate II

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.

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 III

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 II

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

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

KOkun.1048
Associate III

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

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 III

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

@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