NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
1. Introduction
Many of the examples provided as part of MCUXpresso SDK and LPCOpen packages are built
around the FreeRTOS real time operating system. FreeRTOS is also a popular choice when
developing MCU software applications for real products.
For more information on FreeRTOS please visit http://www.freertos.org
This guide examines some of the functionality included in MCUXpresso IDE to assist you
in debugging applications built around FreeRTOS. It does not provide any information on
FreeRTOS itself or on developing applications that use FreeRTOS.
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
2. LinkServer FreeRTOS Thread Aware Debugging
When debugging via LinkServer debug probes, the MCUXpresso IDE debugger can provide
FreeRTOS thread aware debug if :
1. Minor modifications are made to the application, so that configuration information required by
the debugger is present in the image file.
2. Debugging is carried out in All-Stop mode (rather than the default Non-Stop mode). This
selection is made when first making a debug connection for a particular project (or after
deleting an existing launch configuration). For more details, please see the MCUXpresso IDE
User Guide.
The source code modifications required are described in Required Source Code
Changes [5].
Note: Example projects supplied as part of MCUXpresso IDE compatible SDK packages should
already have had these changes made to them.
Without these changes, or if Non-Stop debug mode is used, only the current thread will be seen
in the Debug View, as shown in the below screenshot:
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
However, once the necessary changes are made to the application source, and All-Stop debug
mode is used, the Debug View will display each thread separately, as shown in the next
screenshot:
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
Note: MCUXpresso IDE v10.0.0 provided a limited form of thread aware debugging in Non-
Stop debug mode. However due to restrictions in the way GDB’s Non-Stop debug functionality
operates, this has been removed in MCUXpresso IDE v10.0.2 and later. This means that it is no
longer possible to make use of Live Variables functionality within the Global Variables View at
the same time as LinkServer FreeRTOS thread aware debug.
2.1 Behavior when thread aware debugging
MCUXpresso IDE LinkServer FreeRTOS thread aware debugging is available once the
FreeRTOS scheduler has started (so will not appear straight after loading the application when
the default breakpoint on main() is reached). Debug works in stop mode. In other words, if
execution of a user task is halted either through a user action (halt) or a debug event (breakpoint,
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
watchpoint, fault, etc.), the stopped thread is current and no application thread executes in
the background. The register context for any thread is available in the register window. For
suspended or blocked threads, the register context is the context in effect when the thread was
swapped out, regardless of which thread stack level is examined within the traceback window.
In the below example, the MCU is halted in Thread #2, but a backtrace for Thread #1 is also
opened up (and backtrace information for Threads #3, #4, and #5 is also available):
2.2 Required Source Code Changes
MCUXpresso IDE debug is implemented via a GDB remote console application (i.e. a stub). A
“remote debug stub” underneath GDB has access to symbolic information (through GDB), but
has no direct knowledge of symbol data types. Thread aware debug for FreeRTOS requires
16 bytes of configuration data (symbol FreeRTOSDebugConfig) be added to the application to
describe the as-built kernel configuration for a given FreeRTOS project.
The following notes describe the FreeRTOS project modifications required to enable thread
aware debug.
Note: Example projects supplied as part of MCUXpresso IDE compatible SDK packages should
already have had these changes made to them. And future releases of FreeRTOS are also
expected to include the same changes. Thus these changes are generally only required for LPC
preinstalled parts with LPCOpen FreeRTOS using projects.
2.2.1 Modify – File tasks.c
The MCUXpresso IDE FreeRTOS thread aware debug requires the addition of the following
conditional include, and function definition, to the end of the tasks.c source file. This code can be
placed after the FREERTOS_MODULE_TEST conditional include, if it exists:
Note that the function freertos_tasks_c_additions_init() will be called by vTaskStartScheduler() in
future releases of FreeRTOS, but is not currently used by the MCUXpresso IDE.
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
2.2.2 Modify – File FreeRTOSConfig.h
The FreeRTOSConfig.h header file is included in the FreeRTOS source distribution. To enable a
FreeRTOS project for thread aware debug, add the following macro definition to this file:
Next, ensure the configUSE_TRACE_FACILITY macro is set to 1.
#define configUSE_TRACE_FACILITY 1
2.2.3 Create – New File freertos_tasks_c_additions.h
A copy of this file can also be found within the MCUXpresso IDE product installation at:
<install dir>/ide/Examples/Misc
For convenience, the freertos_tasks_c_additions.h header file can be placed in the same folder as
the FreeRTOSConfig.h header file.
There is also one edit to freertos_tasks_c_additions.h itself that may be required for a particular
FreeRTOS project configuration. The macro configFRTOS_MEMORY_SCHEME describes the project heap
mechanism using a value 1 – 5 according to the following:
1. heap_1 : The very simplest; does not permit memory to be freed
2. heap_2 : Permits memory to be freed, but not does coalesce adjacent free blocks
3. heap_3 : Simply wraps the standard malloc() and free() for thread safety
4. heap_4 : Coalesces adjacent free blocks to avoid fragmentation. Includes absolute address
placement option
5. heap_5 : As per heap_4, with the ability to span the heap across multiple non-adjacent
memory areas
Note: Future versions of FreeRTOS may incorporate the configFRTOS_MEMORY_SCHEME macro as a
configuration parameter in FreeRTOSConfig.h.
2.3 Detection and placement of FreeRTOS Debug Config block
2.3.1 Debugger Messages
LinkServer FreeRTOS Thread Aware Debugging requires that a data block containing the
configuration information required by the debugger is present in the image. It also requires that
the debug session is carried out in All-Stop mode.
If both of these criteria are met, then when you start your debug session, confirmation that
LinkServer FreeRTOS Thread Aware Debugging is active is recorded in the “Debug Messages”
log inside the IDE’s Console view:
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
If the image is debugged in Non-Stop mode, then the log will indicate that thread aware debugging
will not be available:
...
GDB nonstop mode enabled
FreeRTOS stack backtrace is disabled in Non-stop mode (use All-stop)
...
If the image does not contain the FreeRTOS Debug Config block, at all, then this section of the
Debug Messages log will make no reference to FreeRTOS thread awareness:
In MCUXpresso IDE v11.1.0 and later, the IDE’s managed linker script mechanism will now
attempt to ensure that the FreeRTOS Debug Config block is more reliably placed into the image
by explicitly keeping the .rodata* sections from the FreeRTOS tasks.c file (actually pulled in from
the freertos_tasks_c_additions.h file).
This is done in the freertos_debugconfig.ldt linker script template file, which attempts to determine
if the project is a FreeRTOS-using one . This is done based on the FreeRTOS component being
included in the project (for SDK-based projects,) or from the pathname (for non-SDK projects,
based on pre-installed parts).
This will cause a FreeRTOS line, similar to the one in the following snippet, to be placed in the
main generated linker script (.ld) file inside your project’s Debug (or Release) folder:
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
} > PRPROGRAM_FLASH
If this FreeRTOS check within the managed linker script mechanism fails for some reason, then
you can force the inclusion of the FreeRTOS Debug Config blog in your project by adding a
folder to root directory of your project called “linkscripts” and adding a file to it called “user.ldt”
containing the following:
<#assign force_freertos=true>
For more details of linker script template files, please see the MCUXpresso IDE User Guide.
2.4 Switching between all-stop and non-stop debug modes
When debugging a project for the first time using a LinkServer debug connection (or when you
have deleted any existing launch configuration files), you can select whether to debug in Non-Stop or All-Stop mode (so that you can choose whether or not you wish to use FreeRTOS thread
awareness).
However, you can also easily modify an existing launch configuration file to switch between All-Stop and Non-Stop as follows.
• Open the project up in the Project Explorer view and double click on the appropriate launch
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
3. FreeRTOS Task Aware Debug Views
MCUXpresso IDE includes several additional Views to further simplify FreeRTOS application
debugging, known collectively as the FreeRTOS TAD (Task Aware Debugger for GDB):
• Task List : shows list of tasks with status information
• Queue List : shows currently active queues, semaphore, and mutex
• Timer List : lists the RTOS software timers
• Heap Usage : shows current heap usage and memory block allocation
Note: These Views are independent of the debug probe being used, as they just use GDB
commands to receive information from the target.
3.1 Showing the FreeRTOS TAD Views
The FreeRTOS Views can be opened using the “FreeRTOS” main menu in the MCUXpresso IDE.
The Views are “stop mode” Views: with the target halted or stopped, the Views will query the
device under debug and read the necessary information through the debug connection.
This will also happen during single stepping, so to improve stepping performance it is advisable
to:
1. Only have the needed Views in the foreground/visible, or close the Views if they are not used.
2. Make use of the Pause View feature, allowing you to single step without the Views constantly
reloading data.
3.2 Task List View
This View shows the tasks in a table:
TCB#
• Task Control Block. configUSE_TRACE_FACILITY needs to be set to 1
Task Name
• Name of task. configMAX_TASK_NAME_LEN needs to be greater than zero
Task Handle
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
Period (ticks)
• Period of timer in ticks
Auto reload?
• Whether the timer is automatically restarted after expiration
Timer Number
• Number of timer
Timer callback
• Address and name of callback function
3.5 Heap Usage View
This View provides information about the heap memory used.
3.5.1 Memory Scheme in Use
The Heap Usage View determines the used memory scheme (heap type) from:
1. The value of the configFRTOS_MEMORY_SCHEME in the FreeRTOSDebugConfig structure (as described in
Required Source Code Changes [5] above)
2. Else, the value of the user-defined variable freeRTOSMemoryScheme
3. Else from the details contained in the available FreeRTOS heap related variables ( ucHeap,
xHeapStructSize and heapSTRUCT_SIZE).
If the freeRTOSMemoryScheme variable is to be used, then this can be defined as follows, but you must
ensure that there is a reference to this symbol, so that it is not removed by the linker.
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
Heap Usage
• Amount of memory used with the total amount of memory
Free Space
• Amount of free memory with percentage
Heap Usage Graph
• Graphical view of percentage used
In the lower part of the View there is information about the heap memory blocks:
#
• Block number
Details
• Allocated, Free or the Task Stack or Task TCB
Block Start
• Start address of memory
Block End
• End address of memory
Size
• Size of memory
3.6 Timeouts
When using slow debug probes such as the OpenSDA debug probes fitted to many FRDM
boards, it is possible that timeouts will be reported within the IDE.
The timeout period can be extended if this occurs using the Workspace preference as shown
below:
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
4. Thread Aware Debugging with Other Debug Probes
4.1 PEmicro Probes
FreeRTOS thread aware debugging with PEmicro debug probes is automatically supported
without any special option.
However on odd occasions this can cause problems and it is possible to turn it off using the
launch configuration server parameter:
-kernel=none
4.2 SEGGER J-Link Probes
FreeRTOS thread aware debugging for SEGGER J-Link debug probes is disabled by default.
To turn it on, enable the “Select RTOS plugin” option for “GDBServer/RTOSPlugin_FreeRTOS”
in the J-Link Launch Configuration for your project:
Alternatively, this default can be changed for new launch configurations via an IDE Workspace
J-Link preference as show below:
MCUXpresso IDE FreeRTOS Debug Guide -
User Guide
All information provided in this document is subject to legal disclaimers