Stm32cubemx + Stm32 HAL (S)RAM usage
Dear Community,
I am new to the STM32, have used the Renesas platform in the past, it seems to me that the STM32 HAL is using precious (S)RAM memory for information that could be considered constant.
For each peripheral that you configure in Stm32cubemx there will be a handle in main.c like so:
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;
UART_HandleTypeDef huart3;The size of UART_HandleTypeDef turns out to be 128 bytes, each one of them... And no, this memory is not used as a data buffer to read/write to the uart. B.T.W. DMA_HandleTypeDef is 120 bytes as such using a UART with RX and TX DMA will cost you....
Looking at the definition of UART_HandleTypeDef it turns out that some fields are indeed used to keep track of dynamic information (transfer state etc). However a lot of them could be considered constants, so why are they in RAM?
Would it not be more efficient/flexible to generate multiple struct variables of which some could be constant, allowing them to remain in flash, like so:
static const UART_InitTypeDef uart2initData =
{
.BaudRate = 9600,
.WordLength = 8,
// etc.
}
static UART_DynDataTypeDef uart2dynData;
const UART_HandleTypeDef huart2 =
{
.pInit = &uart2initData,
.pDynData = &uart2dynData,
}
This way a lot of (S)RAM usage could be prevented...
Looking forward to your opinions...
Regards,
Martin
#stm32cubemx-stm32-hal-sram-waste*