Page 1 of 1
RTT support
Posted: Thu Dec 28, 2017 6:06 pm
by omcdr
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 ?
Re: RTT support
Posted: Thu Dec 28, 2017 6:09 pm
by Giovanni
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
Re: RTT support
Posted: Fri Dec 29, 2017 11:25 am
by omcdr
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:
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++;
}
Re: RTT support
Posted: Fri Dec 29, 2017 2:23 pm
by Giovanni
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
Re: RTT support
Posted: Fri Dec 29, 2017 5:22 pm
by omcdr
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 ?
Re: RTT support
Posted: Fri Dec 29, 2017 5:27 pm
by Giovanni
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
Re: RTT support
Posted: Fri Dec 29, 2017 11:10 pm
by omcdr
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 ?
Re: RTT support
Posted: Sat Dec 30, 2017 8:23 am
by Giovanni
It depends, from where is it called?
Giovanni