To easiest our life working with an RTOS we gonna use a tool called RTOS viewer, There is a really good one from SEGGER but comes with a price, we need to change the debug server from OpenOCD to JlinkGDBServer, and there is something else, we need to reprogram out nucleo board debuggers from STLink to Jlink.
Download the application SEGGER STLinkReflash utility from this page ST-LINK On-Board and follow the instruction to reflash the board. this needs to be carried out in Windows
Installing the new debug tools
Once the debugger is reprogrammed in our board it is time to install some new tools (at this point you can go back to linux)
Linux
Install the SEGGER Jlink tools
$ paru -S jlink-software-and-documentation jlink-systemview
Windows
On windows just download de Jlink software package from the SEGGER webpage
To avoid the headache of integrate the SEGGER RTT viewer in every project that runs FreeRTOS, Diego already prepare a template you can clone from bitbucket
$ git clone https://modularmx-admin@bitbucket.org/modularmx/template-g0rtos.git
or using SSH
$ git clone git@bitbucket.org:modularmx/template-g0rtos.git
Something quiet important to notice on the makefile is the targets for make open uses the Jlink GDB server instead of OpenOCD
#---open a debug server conection------------------------------------------------------------------
open :
JLinkGDBServer -if SWD -device stm32g0b1re -nogui -port 3333
# openocd -f board/st_nucleo_g0.cfg
Mandatory to call the following two functions (it is already done in the template)
SEGGER_SYSVIEW_Conf( );
SEGGER_SYSVIEW_Start( );
make and flash the example that comes with the template. Upss, you cannot flash with the Jlink, because we don not have the appropriate license, but we can run a debug session, make open in one terminal and make debug in another one. Now to display the messages type in a third terminal make terminal
$ make terminal
JLinkRTTClient
###RTT Client: ************************************************************
###RTT Client: * SEGGER Microcontroller GmbH *
###RTT Client: * Solutions for real time microcontroller applications *
###RTT Client: ************************************************************
###RTT Client: * *
###RTT Client: * (c) 2012 - 2016 SEGGER Microcontroller GmbH *
###RTT Client: * *
###RTT Client: * www.segger.com Support: support@segger.com *
###RTT Client: * *
###RTT Client: ************************************************************
###RTT Client: * *
###RTT Client: * SEGGER J-Link RTT Client Compiled Mar 15 2023 13:58:53 *
###RTT Client: * *
###RTT Client: ************************************************************
###RTT Client: -----------------------------------------------
###RTT Client: Connecting to J-Link RTT Server via localhost:19021 ................
###RTT Client: Connected.
SEGGER J-Link V7.86d - Real time terminal output
J-Link STLink V21 compiled Aug 12 2019 10:29:20 V1.0, SN=776087936
Process: JLinkGDBServerCLExe
Hola mundo de SEGGER
Hola mundo de SEGGER
Hola mundo de SEGGER
Hola mundo de SEGGER
Hola mundo de SEGGER
Hola mundo de SEGGER
System View
Display messages in a terminal faster than semihosting and serial port is not the best we can do. replace the example code for the following one with two tasks.
#include "app_bsp.h"
static void vTask1( void *parameters );
static void vTask2( void *parameters );
int main( void )
{
HAL_Init( );
/*enable RTT and system view*/
SEGGER_SYSVIEW_Conf( );
SEGGER_SYSVIEW_Start( );
xTaskCreate( vTask1, "Task1", 128u, NULL, 1u, NULL );
xTaskCreate( vTask2, "Task2", 128u, NULL, 1u, NULL );
vTaskStartScheduler( );
return 0u;
}
static void vTask1( void *parameters )
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOC_CLK_ENABLE( );
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = GPIO_PIN_0;
HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );
for( ; ; )
{
HAL_GPIO_TogglePin( GPIOC, GPIO_PIN_0 );
/*With this printf version the string will be displayed in SystemView*/
SEGGER_SYSVIEW_PrintfHost("Tare1 Hola mundo de SEGGER");
HAL_Delay( 1000u );
}
}
static void vTask2( void *parameters )
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOC_CLK_ENABLE( );
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = GPIO_PIN_1;
HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );
for( ; ; )
{
HAL_GPIO_TogglePin( GPIOC, GPIO_PIN_1 );
/*With this printf version the string will be displayed in SystemView*/
SEGGER_SYSVIEW_PrintfHost("Tare2 Hola mundo de SEGGER");
HAL_Delay( 2000u );
}
}
SEGGER_RTT_printf
function will display the information in the Jlink RTT terminal only, while the SEGGER_SYSVIEW_PrintfHost
will do also on System View. Is up to you decide which one is best for you. SEGGER_SYSVIEW_PrintfHost
is not necessary the ‘\n' or '\r’In order to avoid typing in several terminal it is much better to use the Cortex-debug plugin for our VSCode, you only need to create a new launch.json file inside the .vscode directory.
{
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "./Build/temp.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "STM32G0B1RE",
"interface": "swd",
"serverpath": "/usr/bin/JLinkGDBServer",
"armToolchainPath": "/usr/bin",
"svdFile": "${workspaceRoot}/STM32G0B1.svd",
"debuggerArgs": [
"-iex","set auto-load safe-path /"
],
"runToEntryPoint": "main",
"rttConfig": {
"enabled": true,
"address": "auto",
"decoders": [
{
"port": 0,
"type": "console"
}
]
}
}
]
}
Now open SystemView and open a connection using the following configuration
Once your program is running with the VSCode cortex-debug, open systemview and click on the play icon (green triangle), then you can stop anytime since your program repeats always the same routines. You’ll see the task running and been switching in and out, the shceduler running, log events and messages printed, besides the CPU usage of each task.
NOTE for some reason CPU usage is not working but i will figure it out soon
And if you want to keep using the RTT output from VSCode you can already do that, just open the new terminal RTT Ch0 Console