2025-03-08 11:55 PM - last edited on 2025-03-09 12:07 AM by STOne-32
I am writing a field oriented control library targeting the STM32F4xx and STM32G4xx series.
In the program, I have to:
1) Read 2 sensors using I2C
2) UART serial communication with host PC to send real-time motor parameters or receive new commands
3) Read 4 ADC pins
4) CAN bus (yet to implement, can be omitted)
As of now, I am using DMA for UART and ADC reads. The ADC read is configured in circlar mode with continuous DMA requests enabled. The I2C communication with sensors are just left in blocking mode for now, but I am trying to convert it to DMA or interrupt since it is quite slow.
One issue I had a while back was the UART DMA transmit not working properly. Some UART transmits just simply wouldn't execute, and later I found out it was due to the circular ADC DMA conversions. Changing the priority of the UART to be higher than the ADC reads solved the problem, but I just want to ask, is there a preferred way of establishing all the above communications?
As in, should I use DMA for everything? Or is it more beneficial to make some events interrupt based? I always have this weird feeling that using too many DMA streams isn't optimal.
2025-03-09 1:10 AM
We had similar problems with our stm32H7 platform.
As we moved to AZRTOS, problems were solved at once (well, after we used threads and devices with correct settings ).
What is your OS? if you are AZRTOS, you can re-use our library..
2025-03-09 6:42 AM
>is there a preferred way of establishing all the above communications?
No, i just can tell "my way" .
1. for hi-speed and many data points or data blocks, DMA is the best - obviously.
2. for hi or low speed, but no "stream" of many elements, like UART, CAN or just a button-press, INT is best;
because no load for the cpu, in the long times, nothing happens, but fast reaction, if a signal is coming.
Anyway you (the cpu) has to look, what is the data and do something then, so nothing is better, if this info is at first transferred by DMA and then processed - its just more overhead .
So handling fast and continuous data with DMA (circular , for continuous streams) at lower priority and
small packets or (single) bytes with INT at higher priority working perfect, giving fastest response and low cpu load.