Yesterday I sat down to try and write some debug code for my sensor detector only to realize debugging a microcontroller is going to be more difficult than normal that normal software.
The only loop in the program is the main ‘loop’ procedure which is a standard arduino function. This procedure is called thousands of times a second.
To start the debugging, I need to know which of the procedures in this ‘outerblock’ is called when it goes into lala land.
I can’t just print a debug msg before each proc is called as the serial interface is way too slow for that. I decided to xmit a packet as each proc was called and then I’d look at the last packet when the problem occurred. Right. Within a minute thousands of packets were generated.
I had to stand back and think about the problem again.
I can’t really communicate with anything except memory. But when the hang occurs, I loose control and can’t dump memory.
BUT, I think that interrupts are probably still working since the problem must be a loop in a driver. So my current thought is to write to memory an identifier indicating where I am currently. Then I will have a watchdog timer running on an interrupt. If the watchdog sees the program is no longer running, it can send a debug packet and report the last procedure called.
Now just have to implement the idea.