cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F215 gets stuck

Not applicable

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:

  • Remove DMA
  • Change Systick for a TIM
  • Modify interrupt priorities in various ways (higher priority CAN, higher priority USART, higher priority DMA, different priority groups, etc).
  •  

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.

6 REPLIES 6
KnarfB
Principal III

> 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

TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
Not applicable

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.

KnarfB
Principal III

As already said, you might have to really dig deep here to find the root cause in your software.

KnarfB

Not applicable

After debugging I realized that I had some problems:

  • A variable did overflow
  • Therefore, when trying to access the buffer in that position, the HardFalt interrupt was executed.

Thanks!

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..