2021-09-08 12:43 PM
I am using STM32L011K4 with 16KB flash memory. I did simple code to implement I2C ,timer with PWM. But I have issue of memory overflow.
I have enabled following:
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C1_Init(void);
static void MX_TIM2_Init(void);
What should I do?
2021-09-08 12:48 PM
Enable optimization by selecting the Release configuration rather than Debug.
Remove unnecessary or optimize existing code.
Reduce the heap and stack sizes to minimum required.
HAL isn't really build to run on chips with only 16kB of flash.
2021-09-08 12:55 PM
Thanks for reply. Where is Release configuration option in stm32CubeIDE? Also, if I don't use HAL then what should use?
2021-09-08 01:01 PM
2021-09-08 01:27 PM
I will try assessing through registers. Does it matters in the terms of memory space if microcontroller is 32bit, 16bit or 8 bit. Does 32bit microcontroller's flash memory gets full faster than 16bit or 8bit? I am using 32bit micro, may be that's why it gets full faster? Every word takes 32bit. Am I correct?
2021-09-08 01:27 PM
16KB isn't a lot of memory, floating point libraries will also eat a lot of space.
Keil might do a more efficient job, ST has a free Keil license for STM32 Cortex-M0(+) parts.
Still you might actually have to get involved in the coding task rather than expecting Cube / HAL to be the best fit. You might want to optimize the code to reflect the specific use case rather the the general use case with all possible options available/supported.
2021-09-08 02:10 PM
Most of the thumb instructions are 16-bit wide, but operate on data/registers which are 32-bit wide. The trade-off vs old 8-bit MCU is that it can typically do more math with each instruction so needs less of them.
Code and Data size tends to get consumed faster, especially with compilers and libraries
I picked the L011 due to their small physical size, MAXIM has some small CM4F parts with more memory that I'd probably chose in retrospect, as everyone wanted diagnostic and configuration options.