Page 1 of 1

Debugging with STM32

Posted: Fri Aug 14, 2015 9:36 am
by king2
Hi!
I'm not sure this is STM32 specific, anyway, I need solution for STM32.

I set breakpoint to chSysHalt function, and when ChibiOS halts for some reason, I can see this and try to find reason for this stop.
But 'reason' variable contains name of calling function only, and I have to find this function, set breakpoint, restart app, trace and try to get real reason for stopping. It is boring anyway and not always I get get same conditions when step-by-step tracing.

As I understand, chDbgCheck/chDbgAssert are receiving 'remark' const char, but not sending it next to chsysHalt function.

Why?
How can I get both __func__ and remark at sysHalt point?
I'm newbiew, and I do not know which parts of which libs I can use and where, so it is will be nice if you will provide me with code example.
Thank you in advance!

Re: Debugging with STM32

Posted: Fri Aug 14, 2015 10:47 am
by Giovanni
Hi,

Because the remark strings would take too space and the test suite would not fit on some devices.

After stopping in chSysHalt() look at the stack trace, the debugger will show you the exact points of the halt, including the remarks string. Basically there is no need to have them in memory, the debugger can show you them from sources.

Giovanni

Re: Debugging with STM32

Posted: Fri Aug 14, 2015 11:05 am
by king2
I have not so big monitor to display stack too :)
But I'm absolutely sure that I have enough memory in my STM32F429 (in fact, most of it unused yet, and I can spend some memory when debugging for debugging to be more suitable for me).

Maybe it is a possibility to define my own checkDbg/assertDbg function?
What I should insert and in which file? Pleeease! :)

Re: Debugging with STM32

Posted: Fri Aug 14, 2015 11:57 am
by Giovanni
It is possible, note that those functions are macros and can be redefined. You may place your own versions in chconf.h.

Giovanni

Re: Debugging with STM32

Posted: Fri Aug 14, 2015 12:28 pm
by king2
Sorry, but I'm newbiew.
I can use sprintf for concatenating string here, for example, but I think there is a simpler way :)
May be you can put here example of such function?

Thanks!

Re: Debugging with STM32

Posted: Fri Aug 14, 2015 1:16 pm
by Giovanni
I would use strcat(), it is simpler. You could also use chprintf() on a MemoryStream object, see HAL documentation regarding streams.

Giovanni

Re: Debugging with STM32

Posted: Fri Aug 14, 2015 1:52 pm
by king2
I sure I did it not optimal way, but it works..

Code: Select all

#define chDbgAssert(c, r) do {                             \
    if (CH_DBG_ENABLE_ASSERTS != FALSE) {                  \
        if (!(c)) {                                        \
            char error_string[128] = r;                    \
            strcat(error_string, " (");                    \
            strcat(error_string, __func__);                \
            strcat(error_string, ")");                     \
            chSysHalt(error_string);                       \
        }                                                  \
    }                                                      \
} while (false)