I've implemented bindings for SEGGER SystemView and RTT.
RTT is a technology used to stream data to the PC via the debugger, without additional pins. It can be very fast. Check here: https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer/
SystemView is a technology that can provide insight into the running code. It requires RTT. See here: https://www.segger.com/products/development-tools/systemview/. It can produce output like this one:
To use these tools, you will need a J-Link, which is not usually free. I'm working with the STM32F407 Discovery board, whose on-board ST-link can be converted to a J-Link for free (see here: https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/).
As a first step, configure the J-Link GDB server as the debugger, and check that the connection is working and you can download and debug code.
To use SystemView:
1- Clone my ChibiOS-Contrib repo (https://github.com/dismirlian/ChibiOS-Contrib/tree/segger_systemview), which should be merged to the upstream ChibiOS-Contrib repo after it passes the necessary reviews.
2- Unzip the SEGGER code (ChibiOS-Contrib\ext\SEGGER-RTT_6.44i+SystemView_2.52h.7z) in place.
3- Include the following in the Makefile:
Code: Select all
include $(CHIBIOS_CONTRIB)/os/various/segger_bindings/segger_rtt.mk
include $(CHIBIOS_CONTRIB)/os/various/segger_bindings/segger_systemview.mk
4- Copy the configuration files (ChibiOS-Contrib\os\various\segger_bindings\example_configurations\*) to your project's cfg directory. You might want to edit these, but the default configurations should be good enough.
5- Add the following to the bottom of your chconf.h file:
Code: Select all
/*===========================================================================*/
/* Other configurations */
/*===========================================================================*/
#if !defined(_FROM_ASM_)
#include "SEGGER_SYSVIEW_ChibiOS.h"
#endif
6- You will need to rename the following hooks in your chconf.h file:
Code: Select all
CH_CFG_CONTEXT_SWITCH_HOOK to _CH_CFG_CONTEXT_SWITCH_HOOK
CH_CFG_THREAD_EXIT_HOOK to _CH_CFG_THREAD_EXIT_HOOK
CH_CFG_IRQ_PROLOGUE_HOOK to _CH_CFG_IRQ_PROLOGUE_HOOK
CH_CFG_IRQ_EPILOGUE_HOOK to _CH_CFG_IRQ_EPILOGUE_HOOK
CH_CFG_SYSTEM_HALT_HOOK to _CH_CFG_SYSTEM_HALT_HOOK
7- Download SystemView and copy ChibiOS-Contrib\os\various\segger_bindings\SYSVIEW_ChibiOS.txt to C:\Path\to\SystemView\Description\
8- #include "SEGGER_SYSVIEW_ChibiOS.h" and add the following call to main(), after chSysInit():
Code: Select all
SYSVIEW_ChibiOS_Start(STM32_SYSCLK, STM32_SYSCLK, "I#15=SysTick");
9- As an optional step, modify ChibiOS source code to add CH_CFG_THREAD_READY_HOOK. CH_CFG_THREAD_READY_HOOK is an *extra* hook, not present in the "stock" ChibiOS code. It is important if you want SystemView to show all the ready threads, even if they are not executing. The hook should be placed just before the return lines of the chSchReadyI and the chSchReadyAheadI functions, in chschd.c:
Code: Select all
thread_t *chSchReadyAheadI(thread_t *tp) {
...
CH_CFG_THREAD_READY_HOOK(tp);
return tp;
}
thread_t *chSchReadyI(thread_t *tp) {
...
CH_CFG_THREAD_READY_HOOK(tp);
return tp;
}
An example project can be found at ChibiOS-Contrib\demos\STM32\RT-STM32F407-DISCOVERY-RTT+SystemView
To use RTT:
- You can follow steps 1~4 (without the references to SystemView, if you don't need it).
- You can use the RTT functions directly (SEGGER_RTT_printf, etc - more lightweight), or use the RTT sequential stream abstraction for ChibiOS (see the demo for an example).
Results:
- part of ChibiOS test suite:
- test suite using RTT output instead of serial port, via RTT sequential stream abstraction:
Cheers,
D.