2025-01-22 04:52 PM
Maybe my question should be on Stackoverflow, but I thought there would be qualified people here to help me.
I need to keep a data structure updated between two processors, with a size around 100B to 200B and something around 1 to 3 updates per second. The two µCUs are connected via SPI and I haven't determined which one is the master yet. But one µCU is STM32 and the other ESP32
I've never used DMA, but I'm researching the ST database and Google for information on how it works and how it would be to keep such structures constantly updated.
Would this be the best choice? SPI + DMA
Or keep a timer sending data via SPI?
2025-01-23 03:00 AM
Indeed, this is a generic question - not specific to STM32 at all.
@carlosdelfino wrote:Would this be the best choice? SPI + DMA
Or keep a timer sending data via SPI?
An SPI link is an SPI link - it's irrelevant whether it is fed by DMA, or bit-banged, or whatever.
Whether it makes sense for either or both ends of the link to use DMA is Impossible to say - that would depend entirely on specific requirements & constraints of your particular project.
2025-01-23 04:40 AM - edited 2025-01-23 04:42 AM
As far as arquitecture is concerned i usually go your way, so your idea is valid:
Processor1 Circular buffer TX-->(physical+transport abstraction layers)--> Processor2 Circular buffer Rx.
Processor1 Circular buffer RX<--(physical+transport abstraction layers)<-- Processor2 Circular buffer Tx.
as @Andrew Neil said (physical+transport abstraction layers) would be UART, SPI, SPI+DMa, bitbanged random protocol,....etc. Depends of your requirements.
SPI+DMA is a valid option, i normally do UART+DMA because i never use screens or anything requiring SPI.
If you use DMA, you might want to flag or decode the reception of new data within the DMA completed interruption.
2025-01-23 04:10 PM
I need to keep both structs up to date, in fact the stm32 will have a representation of the state of my device that needs to be replicated in the esp32, I will have functions that will encapsulate the changes in the stm32 struct, but there will be a pooling mechanism to copy the struct whenever it is available, but the issue with all this is that I am intrigued by the DMA features,
I have never used it and I wonder if it is a solution to such a problem, in other words the problem is not the spi, but the DMA itself.
I only found out that the ESP32 also has DMA when I started researching this feature, until then I never needed it. I thought it was a feature specific to Cortex-M, or more complex processors.
2025-01-23 04:25 PM - edited 2025-01-23 04:28 PM
These are really two entirely separate issues:
DMA may be part of (2), but is unrelated to (1).
DMA is very common and widespread in computer architectures - certainly not specific to STM32:
https://en.wikipedia.org/wiki/Direct_memory_access
https://www.techtarget.com/whatis/definition/Direct-Memory-Access-DMA
https://pebblebay.com/direct-memory-access-embedded-systems/
2025-01-23 05:39 PM
I haven't studied Computer Architecture much, although I've started my own processor with FPGA (https://riscuinho.github.io). I know that DMA is part of computer architecture and it's nothing new, but it's new to me, especially in the universe of µCUs.
I haven't yet understood how DMA works in a microcontroller. I know that it saves the processor time in handling data between the device and the memory, but I haven't yet understood how this can be done, say with a pooled system. I'd like an example to help me understand better, or some reading specifically in the context of Cortex-M.
2025-01-23 06:04 PM - edited 2025-01-23 06:19 PM
The 3rd link in my previous post relates specifically to embedded systems.
The ST Cube Firmware Packs all contain DMA examples where supported.
@carlosdelfino wrote:say with a pooled system.
Not sure what you mean by that?
.
PS:
Also:
2025-01-23 07:19 PM
Pooled System => a thread that would be permanently reading and sending the struct through SPI.
The suggested article was a great read, it confirmed my perception of DMA. Now I need to learn how to use it properly for my needs, as the STM32F4, STM32H7 and ESP32 families allow.
I will study the available examples.
Thank you.
ps. I am using a translator, although I am fluent in reading, I am not good at writing in English.
2025-01-24 01:31 AM
@carlosdelfino wrote:Pooled System => a thread that would be permanently reading and sending the struct through SPI.
Did you mean polled ?
2025-01-24 11:11 AM