2024-07-01 12:39 AM
Hello all
I am interfacing various peripherals on the STM42F446RE, SPI, I2C, UART etc, and in the process i'm choosing to use the DMA controller.
when configuring various 3rd party ICs some may have many registers to setup,
Rather than use global array variables eating up resorces of the ARM, is it safe to use local variables within the peripherals DMA setup when calling HAL_SPI_DMA functions ??
void setup_spi (void)
{
#define array 24
uint8_t spi_tx[array] = { 10, 20, 30, 40, 50, 60, 70 };
}
my concern with the above is..., does the data get lost when exiting the function before it is written to the DMA ??
is this ok to do this ??? or should I use global variables when writing to the DMA
Thank in advance for any info
2024-07-02 09:06 PM
As you rightly suspected, it's prone to failure at some point in time, since its local variable. In case your RAM is fully utilised, you can keep couple of fixed buffers and switch them as you do the coding for different purposes. It all depends on your logic design.
2024-07-02 09:26 PM
If you allow the context to collapse it's not going to be safe/usable.
If this is a constant pattern use FLASH, and DMA out of that.
If the routine doesn't re-enter you can define the array as static within the function/scope and it will make it global. This is safer, and you can't have multiple DMA transactions in-flight any way.