Print kernel error messages through swo

Hello. I have a custom board with an stm32f407 MCU. I use PA_2 and PA_3 (usart2) for printing the debug messages on the serial console. I will update the design and I want to use ST’s swo viewer for debugging in the updated design . This way I can have 2 more pins for my application. There are libraries (thanks to the mbed community) and they work pretty well for printing the messages through the swo viewer. However, I also need to see the crash reports and other error messages generated by the kernel. Here is an example:

++ MbedOS Error Info ++
Error Status: 0x80020125 Code: 293 Module: 2
Error Message: CMSIS-RTOS error: Stack overflow
Location: 0x800D859
File: mbed_rtx_handlers.c+60
Error Value: 0x1
Current Thread: LR-SX1276 Id: 0x200035C8 Entry: 0x800FAA1 StackSize: 0x400 StackMem: 0x20005F38 SP: 0x2001FF2C
For more info, visit: https://mbed.com/s/error?error=0x80020125&tgt=PROTO_F407
-- MbedOS Error Info --

Is there a way to forward the kernel error messages to the swo viewer? In this example for instance I see irq_thread(osPriorityRealtime, 1024, NULL, "LR-SX1276") in SX1276_LoRaRadio.cpp is crashing. Here the problem is stack overlow that is allocated for the irq thread LR-SX1276. I see it is actually possible to track the error through Mbed Studio’s debugger but the error messages are still handy and descriptive. So I would prefer to get benefit from this feature of mbed os through swo.

Hello hckar,

This link might help you redirect the console to SWO.

1 Like

Okay. I did not think it is this much easy. Here is the solution in case someone else needs it:

#include "SWO.h"

SWO_Channel debugport("swo_channel");

FileHandle *mbed::mbed_override_console(int) {
     return &debugport;
 }

@hudakz thank you for the link.