Page 1 of 2

System lockup when using chvprintf()

Posted: Mon Sep 29, 2014 7:38 pm
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!

Re: System lockup when using chvprintf()

Posted: Mon Sep 29, 2014 8:29 pm
by Giovanni
You should enable the debug options, especially the state checker, and see what triggers it.

You need a debugger however.

Giovanni

Re: System lockup when using chvprintf()

Posted: Mon Sep 29, 2014 8:32 pm
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?

Re: System lockup when using chvprintf()

Posted: Mon Sep 29, 2014 10:00 pm
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.

Re: System lockup when using chvprintf()

Posted: Mon Sep 29, 2014 10:04 pm
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.

Re: System lockup when using chvprintf()

Posted: Mon Sep 29, 2014 10:23 pm
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.

Re: System lockup when using chvprintf()

Posted: Mon Sep 29, 2014 10:31 pm
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.

Re: System lockup with synchronous message passing

Posted: Fri Oct 10, 2014 10:25 am
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?

Re: System lockup when using chvprintf()

Posted: Fri Oct 10, 2014 11:43 am
by Giovanni
Define "lockup", locked doing what?

Giovanni

Re: System lockup when using chvprintf()

Posted: Fri Oct 10, 2014 5:40 pm
by JetForMe
No idea. As I said, I have no way to debug this. It just stops execution. All threads stop.