System lockup when using chvprintf()

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

System lockup when using chvprintf()

Post by JetForMe »

I have a situation in which my app, which uses the synchronous message mechanism, stops executing after some time (hours). In an effort to narrow down the source of the problem (my debugging is limited to printf()), I commented out some code. As long as I don't log anything (for which I use chvprintf()), it seems to run indefinitely (going on 10 hours now).

Here's the setup: Everything is statically allocated. I have a thread that blinks an LED (which is how I can tell it locked up). I have a "main" thread. There are two more threads, a "GPSBroker" and a "GPSReader". The reader loops reading bytes from the serial port to which the GPS is attached. It parses the packets and the messages the GPSBroker to update the broker's state (which is just a handful of GPS parameters). The main thread messages the broker periodically to get the current GPS state. The main thread loops, doing some synchronous reads of other I/O (a SPI port), some ADC reads, writing to another serial port, and logging via chvprintf(). Everything else is fine, but if I leave in the chvprintf() calls, it locks up after 30 minutes to a couple hours.

One note: I added a mutex around my chvprintf() call (code here: https://pastee.org/v264r) because sometimes I get characters interleaved. This didn't seem to make any difference in the behavior (it locked up before and after I added the mutex). Floating point conversions are enabled. The stack should be big enough (I don't think chvprintf() would suddenly need more stack for the same set of strings).

I find it hard to believe chvprintf() would be responsible for this, but experiments suggest it is. Any ideas? Thanks!
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: System lockup when using chvprintf()

Post by Giovanni »

You should enable the debug options, especially the state checker, and see what triggers it.

You need a debugger however.

Giovanni
JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Re: System lockup when using chvprintf()

Post by JetForMe »

Giovanni wrote:You should enable the debug options, especially the state checker, and see what triggers it.

You need a debugger however.


Oh yeah, I forgot about the debug options; that might help. A debugger, for this project especially, is impossible. In general, I've found it hard to use a debugger, too, because I'm on OS X. Does anyone have a working OS X embedded ARM debug solution?
skute
Posts: 64
Joined: Wed Aug 29, 2012 10:17 pm

Re: System lockup when using chvprintf()

Post by skute »

JetForMe wrote:
Giovanni wrote:You should enable the debug options, especially the state checker, and see what triggers it.

You need a debugger however.


Oh yeah, I forgot about the debug options; that might help. A debugger, for this project especially, is impossible. In general, I've found it hard to use a debugger, too, because I'm on OS X. Does anyone have a working OS X embedded ARM debug solution?


I've been using Eclipse + OpenOCD + https://www.olimex.com/Products/ARM/JTAG/ARM-USB-TINY-H/ along with https://launchpad.net/gcc-arm-embedded toolchain on OS X.
JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Re: System lockup when using chvprintf()

Post by JetForMe »

skute wrote:I've been using Eclipse + OpenOCD + https://www.olimex.com/Products/ARM/JTAG/ARM-USB-TINY-H/ along with https://launchpad.net/gcc-arm-embedded toolchain on OS X.


Can I use that without eclipse (i.e., command-line gdb)? Where is the USB driver for it? I have some other OpenOCD dongle, but I've never gotten it to work.
skute
Posts: 64
Joined: Wed Aug 29, 2012 10:17 pm

Re: System lockup when using chvprintf()

Post by skute »

JetForMe wrote:Can I use that without eclipse (i.e., command-line gdb)? Where is the USB driver for it? I have some other OpenOCD dongle, but I've never gotten it to work.


Yes, eclipse isn't necessary. There are a bunch of websites which describe setting up the complete solution but also provide a lot of detail of setting up OpenOCD with the olimex debugger (http://salvatoremenendez.blogspot.com/2011/08/mac-os-eclipse-openocd-stm32-arm-cortex.html); OpenOCD has some good documentation on communicating with GDB. You shouldn't need anything other than the FTDI drivers for the debugger as well.
JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Re: System lockup when using chvprintf()

Post by JetForMe »

skute wrote:
JetForMe wrote:Yes, eclipse isn't necessary. There are a bunch of websites which describe setting up the complete solution but also provide a lot of detail of setting up OpenOCD with the olimex debugger (http://salvatoremenendez.blogspot.com/2011/08/mac-os-eclipse-openocd-stm32-arm-cortex.html); OpenOCD has some good documentation on communicating with GDB. You shouldn't need anything other than the FTDI drivers for the debugger as well.


Awesome, thanks, I'll take a look. Sadly, I don't have access to the JTAG pins on this particular board.
JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Re: System lockup with synchronous message passing

Post by JetForMe »

So, I determined that chvprintf() was not the culprit. The lockup was rare enough that I just set up the watchdog timer to restart the system when it occurred. Then I made a change that seemed to make the crash more frequent, every 10 to 20 seconds of execution time (I did a lot more work in my Application thread).

On a hunch, I changed the priorities of the threads involved. The Application thread sends messages to a Broker thread. Another thread (the Reader thread) also sends messages to the Broker thread. I made the Broker the highest priority thread, at 100. I made the reader just a bit lower, at 99. And the Application thread is the default (64). Now it is rock-solid, and doesn't lock up at all.

Any chance there's the potential for deadlock when all threads have the same priority, and all are sending synchronous messages as described?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: System lockup when using chvprintf()

Post by Giovanni »

Define "lockup", locked doing what?

Giovanni
JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Re: System lockup when using chvprintf()

Post by JetForMe »

No idea. As I said, I have no way to debug this. It just stops execution. All threads stop.
Post Reply