Closed sfe-SparkFro closed 10 months ago
Hi @sfe-SparkFro For mcu with smaller flash, you have to do some customization. https://github.com/stm32duino/Arduino_Core_STM32/wiki/HAL-configuration#example-of-blinkino-for-nucleo-l031k6-with-32768-bytes-of-flash-and-8192-bytes-of-ra
Warning have to be fix in the STM32Cube.
Thanks for the reply @fpistm!
Just to confirm, it should be as simple as creating a file called hal_conf_extra.h
to the sketch directory, and adding #define HAL_*_MODULE_DISABLED
for each module to disable, correct?
Doing this does have some minor effects, but not significant enough to get the I2C scanner example small enough. I tested the effect of adding each HAL_*_MODULE_DISABLED
listed here and was only able to save 752 bytes. Here's my hal_conf_extra.h
with comments describing the effect of each macro:
// Reduces flash size by 752 bytes
#define HAL_CRC_MODULE_DISABLED // 280 bytes
#define HAL_EXTI_MODULE_DISABLED // 472 bytes
// Changes warnings, does not chage flash size
#define HAL_ADC_MODULE_DISABLED
// No effect
#define HAL_I2S_MODULE_DISABLED
#define HAL_RTC_MODULE_DISABLED
#define HAL_SAI_MODULE_DISABLED
#define HAL_SPI_MODULE_DISABLED
#define HAL_DAC_MODULE_DISABLED
#define HAL_ICACHE_MODULE_DISABLED
#define HAL_SUBGHZ_MODULE_DISABLED
#define HAL_ETH_MODULE_DISABLED
#define HAL_OSPI_MODULE_DISABLED
#define HAL_QSPI_MODULE_DISABLED
#define HAL_SD_MODULE_DISABLED
// Can't disable these modules, required for i2c_scanner example
// #define HAL_I2C_MODULE_DISABLED
// #define HAL_TIM_MODULE_DISABLED
And here's the new Output with this hal_conf_extra.h
:
C:\Users\Dryw\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.7.1\variants\STM32C0xx\C011D6Y_C011F(4-6)(P-U)_C031F(4-6)P\generic_clock.c: In function 'SystemClock_Config':
C:\Users\Dryw\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.7.1\variants\STM32C0xx\C011D6Y_C011F(4-6)(P-U)_C031F(4-6)P\generic_clock.c:46:3: warning: implicit declaration of function 'LL_SetSystemCoreClock' [-Wimplicit-function-declaration]
46 | LL_SetSystemCoreClock(48000000);
| ^~~~~~~~~~~~~~~~~~~~~
c:/users/dryw/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Dryw\AppData\Local\Temp\arduino\sketches\13BD30998A11CD6BA9E390C223E9CA66/stm32c0_test.ino.elf section `.text' will not fit in region `FLASH'
c:/users/dryw/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld.exe: region `FLASH' overflowed by 6628 bytes
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
The HAL configuration wiki also suggests disabling Serial
. FWIW, doing this (Tools -> U(S)ART support -> Disabled) and removing all Serial
code from the example does reduce the size enough to fit in the flash memory. But only barely (~14kB out of 16kB), and I actually need both Serial
and Wire
, so this is not a viable solution.
Well, unfortunately, it will be hard to reduce enough the size of code to fit your needs. This core is generic to support all STM32 families and sometimes it could not fit in very small size of flash depending on the set of feature. One other way could be t disable the I2C and implement a I2C light driver using LL but can't do it.
Note that I've fixed the LL_SetSystemCoreClock
warning thanks https://github.com/stm32duino/Arduino_Core_STM32/commit/75bda51e7c6d79415326ac43a199ee36200d93a1
Fair enough, I understand, and I appreciate your time! I'll see about using the LL drivers; my initial tests with them in the STM32CubeIDE have helped a lot in reducing the flash memory requirement. I do also have the opportunity to switch to the 32kB package (STM32C011F6Ux), so that will help too.
If possible, I would like to suggest adding a warning or something in the Notes column here (and to other devices with a small flash size) that out-of-the-box functionality will be limited in Arduino. IMO, not being able to use multiple Arduino drivers simultaneously (eg. Wire
and Serial
) is a pretty severe limitation of an Arduino core, and that could be stated more clearly.
Thanks again!
Updated issue title to hopefully make this more searchable.
Describe the bug
I'm having issues compiling code for the STM32C0. This problem actually exists with most code I try to compile, but to limit the scope of this issue, I'll focus on the I2C scanner example, since it demonstrates the fundamental problems and it should be easy for others to reproduce. Attempting to compile this example for the STM32C011F4Ux gives several warnings and fails due to not enough flash memory (it states the FLASH region overflowed by ~7kB).
To Reproduce
Expected behavior
The example should compile with no warnings and not overflow the FLASH region (ideally use much less so I still have room for my own code!)
Screenshots
Easier to just paste the Output after clicking the Verify button:
Desktop:
Board:
Additional context
I understand that this MCU only has 16kB of flash, but this example really should not use so much memory that it can't be flashed in the first place. For reference, compiling the I2C scanner example for the Arudino Uno (the kind of MCU the STM32C0 is advertised to replace) uses about 4kB of flash memory. Even the blink example uses over 12kB of flash by itself! Simply including Wire.h from the blink example causes the FLASH region to be overflowed by almost 1kB. Makes it basically impossible to do anything with I2C.