MCUXpresso IDE FreeRTOS Debug Guide
MCUXpresso IDE FreeRTOS Debug Guide
Debug Guide
Rev. 10.3.0 — 27 November, 2018 User guide
NXP Semiconductors MCUXpresso IDE FreeRTOS Debug Guide
27 November, 2018
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
1. Introduction .................................................................................................................. 1
2. LinkServer FreeRTOS Thread Aware Debugging ........................................................... 2
2.1. Behavior when thread aware debugging ............................................................. 4
2.2. Required Source Code Changes ........................................................................ 5
2.2.1. Modify – File tasks.c ............................................................................... 5
2.2.2. Modify – File FreeRTOSConfig.h ................................................................... 6
2.2.3. Create – New File freertos_tasks_c_additions.h ........................................... 6
3. FreeRTOS Task Aware Debug Views ........................................................................... 9
3.1. Showing the FreeRTOS TAD Views ................................................................... 9
3.2. Task List View .................................................................................................. 9
3.3. Queue List View .............................................................................................. 10
3.4. Timer List View ............................................................................................... 11
3.5. Heap Usage View ........................................................................................... 12
3.5.1. Memory Scheme in Use ........................................................................ 12
3.5.2. Heap Usage View Functionality ............................................................. 12
4. Thread Aware Debugging with Other Debug Probes .................................................... 14
4.1. P&E Micro Probes ........................................................................................... 14
4.2. SEGGER J-Link Probes .................................................................................. 14
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
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.
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 - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
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 - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
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 - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
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.
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
execution of a user task is halted either through a user action (halt) or a debug event (breakpoint,
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):
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.
#if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 )
#include "freertos_tasks_c_additions.h"
static void freertos_tasks_c_additions_init( void )
{
#ifdef FREERTOS_TASKS_C_ADDITIONS_INIT
FREERTOS_TASKS_C_ADDITIONS_INIT();
#endif
}
#endif
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
#define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1
#define configUSE_TRACE_FACILITY 1
For convenience, the freertos_tasks_c_additions.h header file you will create 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:
#if (configUSE_TRACE_FACILITY == 0)
#error "configUSE_TRACE_FACILITY must be enabled"
#endif
#define FREERTOS_DEBUG_CONFIG_MAJOR_VERSION 1
#define FREERTOS_DEBUG_CONFIG_MINOR_VERSION 1
// NOTE!!
// Default to a FreeRTOS version which didn't include these macros. FreeRTOS
// v7.5.3 is used here.
#ifndef tskKERNEL_VERSION_BUILD
#define tskKERNEL_VERSION_BUILD 3
#endif
#ifndef tskKERNEL_VERSION_MINOR
#define tskKERNEL_VERSION_MINOR 5
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
#endif
#ifndef tskKERNEL_VERSION_MAJOR
#define tskKERNEL_VERSION_MAJOR 7
#endif
// NOTE!!
// The configFRTOS_MEMORY_SCHEME macro describes the heap scheme using a value
// 1 - 5 which corresponds to the following schemes:
//
// heap_1 - the very simplest, does not permit memory to be freed
// heap_2 - permits memory to be freed, but not does coalescence adjacent free
// blocks.
// heap_3 - simply wraps the standard malloc() and free() for thread safety
// heap_4 - coalesces adjacent free blocks to avoid fragmentation. Includes
// absolute address placement option
// heap_5 - as per heap_4, with the ability to span the heap across
// multiple non-adjacent memory areas
#ifndef configFRTOS_MEMORY_SCHEME
#define configFRTOS_MEMORY_SCHEME 3 // thread safe malloc
#endif
#ifdef __cplusplus
extern "C" {
#endif
// NOTES!!
// IAR documentation is confusing. It suggests the data must be statically
// linked, and the #pragma placed immediately before the symbol definition.
// The IAR supplied examples violate both "rules", so this is a best guess.
//
#if defined(__GNUC__)
const uint8_t FreeRTOSDebugConfig[] __attribute__((section(".rodata"))) =
#elif defined(__CC_ARM)
const uint8_t FreeRTOSDebugConfig[] __attribute__((used)) =
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma required=FreeRTOSDebugConfig
const uint8_t FreeRTOSDebugConfig[] =
#endif
{
FREERTOS_DEBUG_CONFIG_MAJOR_VERSION,
FREERTOS_DEBUG_CONFIG_MINOR_VERSION,
tskKERNEL_VERSION_MAJOR,
tskKERNEL_VERSION_MINOR,
tskKERNEL_VERSION_BUILD,
configFRTOS_MEMORY_SCHEME,
offsetof(struct tskTaskControlBlock, pxTopOfStack),
# if (tskKERNEL_VERSION_MAJOR > 8)
offsetof(struct tskTaskControlBlock, xStateListItem),
# else
offsetof(struct tskTaskControlBlock, xGenericListItem),
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
# endif
offsetof(struct tskTaskControlBlock, xEventListItem),
offsetof(struct tskTaskControlBlock, pxStack),
offsetof(struct tskTaskControlBlock, pcTaskName),
offsetof(struct tskTaskControlBlock, uxTCBNumber),
offsetof(struct tskTaskControlBlock, uxTaskNumber),
configMAX_TASK_NAME_LEN,
configMAX_PRIORITIES,
0 // pad to 32-bit boundary
};
#ifdef __cplusplus
}
#endif
// end freertos_tasks_c_additions.h
---------------------------------- cut here ----------------------------------
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
Note: These Views are independent of the debug probe being used, as they just use GDB
commands to receive information from the target.
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.
TCB#
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
Task Name
Task Handle
Task State
Priority
Stack Usage
• Graphical view of current stack usage, with current allocation and stack size available to the
task
Event Object
• Lists the object a blocked task is waiting for. Use vQueueAddToRegistry() to assign a symbolic
name to semaphore, mutex, and queues with configQUEUE_REGISTRY_SIZE greater than zero
Runtime
Stack base
Stack Top
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
• Number of queue
Queue Name
Address
Length
• Length of queue. The first number indicates the number of elements in the queue, followed by
the maximum number of elements possible
Item Size
# Tx Waiting
# Rx Waiting
Queue Type
Head
Tail
Read from
Write to
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
ID
Timer Name
• Name of timer
Period (ticks)
Auto reload?
Timer Number
• Number of timer
Timer callback
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.
Type
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
Heap Base
Heap End
Heap Usage
• Amount of memory used with the total amount of memory
Free Space
In the lower part of the View there is information about the heap memory blocks:
• Block number
Details
Block Start
Block End
Size
• Size of memory
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.
To turn it on, enable the “Select RTOS plugin” option for “GDBServer/RTOSPlugin_FreeRTOS”
in the Launch Configuration for your project:
MCUXpresso IDE FreeRTOS Debug Guide - All information provided in this document is subject to legal disclaimers © 2018 NXP Semiconductors. All rights reserved.