2022-02-17 07:55 AM
Due to privacy policies I cannot publish my code.
I am creating a datalogger that receives information from CAN IT and USART IT and stores it on a microSD via SPI. With each interruption I get the time from the RTC and I also use the ADC to unmount the microSD when the voltage level drops.
It should be noted that the information I receive from the UART is periodic and of known length: 50 bytes every 98 ms while the information received by CAN has a more random behavior and its flow is very intense because it would be exposed to a CAN network with tens of different messages. The main function doesn't have times, it just waits for the buffers to fill up.
To avoid loss of information due to communication failures, I have implemented the reception of USART with DMA and it receives to IDLE.
My specific problem is that everything works fine for about 1 minute and then the micro gets stuck, I can tell by the blinking of an LED.
If I disable CAN, USART works without problems. If I disable USART, CAN works fine. It is the implementation of both peripherals that causes conflict.
I've tried different things but nothing seems to work:
I could think that it is a deficiency of the microcontroller in the face of so many interruptions, but I do not understand how at the beginning everything works and after a while it no longer works.
2022-02-17 08:20 AM
> then the micro gets stuck
"gets stuck" is not a good description. Leave a debugger attached and check what's going on. Hard fault? Check error conditions for all API calls. Use SWO tracing. Use some GPIO for monitoring IRQs.. and hook up a logic analyzer and check the real-time behaviour.
hth
KnarfB
2022-02-17 08:25 AM
Where does it get stuck? Debug it, hit pause, and see where the execution is. What does "stuck" mean specifically?
Unlikely to be a hardware issue with too many interruptions. More likely that your software logic is getting tripped up somewhere. Perhaps due to an overflow or a race condition.
2022-02-17 08:30 AM
I mean that I toggle a led each time the write function is going to be executed on the microSD. The microcontroller gets stuck because after that time (1 min approx) the led stops toggling and the execution of the program is interrupted, which also means that the microSD cannot be unmounted and the files get corrupted.
2022-02-17 08:41 AM
As already said, you might have to really dig deep here to find the root cause in your software.
KnarfB
2022-02-17 11:44 AM
After debugging I realized that I had some problems:
Thanks!
2022-02-17 01:38 PM
I'd recommend using a Hard Fault Handler that outputs actionable data to the USART, and blinks another LED, or one at a high rate, so you can establish that it's found it's way there, and not just quietly died in the while(1) loop.
See also ErrorHandler(), and useful reporting there of file/line info so some diagnostics can be gleaned.