Showing results for 
Search instead for 
Did you mean: 

ModusToolbox Blog


Task-Aware Debugging

I was asked a question last week about multi-threaded debugging in ModusToolbox IDE. I knew there was a plug-in for that but I had never used it. So I gave it a shot and here's how you can enable task-aware debugging with the FreeRTOS kernel.

It turns out that you do not need to install the plug-in - it is already there - but you do need to enable it for OpenOCD. I did that in the file ModusToolbox_1.1\tools\openocd-2.1\scripts\target\psoc6_common.cfg. On line 228, make this addition:

${TARGET}.cm4 configure -rtos auto -work-area-phys $_WORKAREAADDR_CM4 -work-area-size $_WORKAREASIZE_CM4 -work-area-backup 0

The "auto" is taken to mean FreeRTOS by the plug-in, but you can use "-rtos FreeRTOS" if you prefer to be explicit. Next you need to define a variable that the plug-in expects (but is no longer defined in FreeRTOS). I just created a global variable like this:

static volatile int uxTopUsedPriority;

Then, in main(), I use the variable to make sure it is not optimized out by the compiler.

uxTopUsedPriority = configMAX_PRIORITIES - 1;

All I needed now was a project to debug. I created one from the PioneerKitAppFreeRTOS template and made a copy of the "blinky" task (so my application would be slightly more interesting). When I run the debugger and hit a breakpoint in one of the blinky functions, the Quick Panel Debug tab looks like this, which make it really easy to figure out what tasks are in the application and which one I am debugging.

Task-Aware Debugging in ModusToolbox IDE

Now, there is one slight problem with this... it breaks debugging of non-FreeRTOS applications! Oopsy! The reason for this is that the "-rtos auto" causes the debugger to look for missing symbols when you are not using the RTOS. I fixed this by making copies of psoc6.cfg and psoc6_common.cfg (called psoc6_rtos.cfg and psoc6_common_rtos.cfg) in the target folder above. In the psoc6_rtos.cfg file I edited the last line as follows:

source [find target/psoc6_common_rtos.cfg]

In the original psoc6_common.cfg file I backed out the edit so that this file is returned to its original state. Now I have RTOS and non-RTOS config files and, by default, the launch configuration for your projects will use the non-RTOS setup. However, when I do want to enable multi-thread debugging, I just edit the Debug Configuration (Run menu) to use the new files instead. In the Debugger tab there is a filed for Config Options and I change the config file as follows:

-c "source [find target/psoc6.cfg]"

Here is an image of that change.

Enabling Task-aware Debugging in ModusToolbox IDE

I am really happy with this discovery. I can now enable task-aware debugging for a project in just a couple of minutes. I think it will become a standard practice for me. I hope you like it too! I attached my config files so you can just copy them into the target folder, rather than edit the installed IDE files (remember to log into to access them).

Top labels