How to properly use Segger RTT with ChibiOS ?
Info is here:
https://www.segger.com/products/debug-probes/j-link/technology/real-time-transfer/about-real-time-transfer/
or
https://mcuoneclipse.com/2015/07/07/using-segger-real-time-terminal-rtt-with-eclipse/
With enabled debuging in chconf.h file it works, I see RTTprintf messages, but with disabled CH_DBG_* functions not, sometimes I got unhandled exception.
What I missing ?
RTT support
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: RTT support
Hi,
Which DBG option is disabling it? it depends on how RTT has been integrated with ChibiOS, this is not clear in your post.
If it uses the CH_CFG_TRACE_HOOK hook then tracing has to be enabled or it won't be triggered.
Giovanni
Which DBG option is disabling it? it depends on how RTT has been integrated with ChibiOS, this is not clear in your post.
If it uses the CH_CFG_TRACE_HOOK hook then tracing has to be enabled or it won't be triggered.
Giovanni
Re: RTT support
RTTprint use vsnprintf, I had too small THD_WORKING_AREA for use this function. It was first issue.
Is the way to detect to small THD_WORKING_AREA ?
I have another problem, one task is working correctly with debug RTT, if two different tasks use debug function with vsnprintf, system works only for 10s seconds, next only idle task is working with port_wait_for_interrupt() loop. Where can be problem ? CH_DBG dont't show warnings.
My code looks:
Is the way to detect to small THD_WORKING_AREA ?
I have another problem, one task is working correctly with debug RTT, if two different tasks use debug function with vsnprintf, system works only for 10s seconds, next only idle task is working with port_wait_for_interrupt() loop. Where can be problem ? CH_DBG dont't show warnings.
My code looks:
Code: Select all
#define NUM_BUFFERS 7
#define BUFFERS_SIZE 10
char buffers[NUM_BUFFERS][BUFFERS_SIZE];
volatile uint32_t bufIndex;
msg_t mbDebugQueue[NUM_BUFFERS];
mailbox_t mbDebug;
uint32_t debugFlags;
THD_WORKING_AREA(waThreadLed, 2048);
THD_FUNCTION(threadLed, arg)
{
(void) arg;
while (1)
{
ledOn(LED1);
chThdSleepMilliseconds(20);
ledOff(LED1);
chThdSleepMilliseconds(1000);
debug(DBG_DUMP, "led\n");
}
}
THD_WORKING_AREA(waThreadDebug, 2048);
THD_FUNCTION(threadDebug, arg)
{
msg_t msg;
(void) arg;
while (1)
{
debug(DBG_DUMP, "dbg\n");
if (chMBFetch(&mbDebug, &msg, MS2ST(100)) == MSG_OK)
{
RTTputs((char *) msg);
}
// RTTputs("threadDebug\n");
}
}
void debugInit(void)
{
debugFlags = DEBUG_FLAGS_DEFAULT;
bufIndex = 0;
chMBObjectInit(&mbDebug, (msg_t*) &mbDebugQueue, NUM_BUFFERS);
}
void debug(uint32_t type, const char *format, ...)
{
msg_t status;
int i=0;
va_list args;
va_start(args, format);
vsnprintf(&buffers[bufIndex % NUM_BUFFERS][0], BUFFERS_SIZE, format, args);
if(chMBPost(&mbDebug, (msg_t) &buffers[bufIndex % NUM_BUFFERS][0], TIME_INFINITE) == MSG_OK)
bufIndex++;
}
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: RTT support
Hi,
The working area can only be inspected after use using a debugger or the ChibiOS Eclipse plugin. There is no way to calculate it.
About vsnprintf(), that is a library function, it is possible it performs memory allocation, have you included syscalls.c in your project?
Giovanni
The working area can only be inspected after use using a debugger or the ChibiOS Eclipse plugin. There is no way to calculate it.
About vsnprintf(), that is a library function, it is possible it performs memory allocation, have you included syscalls.c in your project?
Giovanni
Re: RTT support
How to check working area with debugger ?
Yes, I have included $(CHIBIOS)/os/various/syscalls.c in Makefile.
Can it be problem with concurrency ? Should I use mutex to only one call vsnprintf ? How to debug this issue ?
Yes, I have included $(CHIBIOS)/os/various/syscalls.c in Makefile.
Can it be problem with concurrency ? Should I use mutex to only one call vsnprintf ? How to debug this issue ?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: RTT support
You need to fill the working area with a patterne (there is an option for this) then verify how much of the area the stack touched.
About concurrency, it could be, it depends on how RTT has been called from hooks, in general hooks are called from within critical zones, this could be a problem if allocation is performed there.
Try enabling assertions and state checker and see if something is caught.
Giovanni
About concurrency, it could be, it depends on how RTT has been called from hooks, in general hooks are called from within critical zones, this could be a problem if allocation is performed there.
Try enabling assertions and state checker and see if something is caught.
Giovanni
Re: RTT support
I have enabled all CH_DGB function, but I can't catch issue.
Problem was with TIME_INFINITE in chMBPost. I have changed to MS2ST(100) and all works correctly.
Why TIME_INFINITE hangs task switching ?
Problem was with TIME_INFINITE in chMBPost. I have changed to MS2ST(100) and all works correctly.
Why TIME_INFINITE hangs task switching ?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times