stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.86k stars 979 forks source link

chore: mark some segments as READONLY #2490

Closed fpistm closed 2 months ago

fpistm commented 3 months ago

This PR reverts 794945c10abb2dc6a875c471bb9aa4cbb131e5a2 then update all linker scripts to mark some segments as READONLY.

Prevent LOAD segment with RWX permissions warning. The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier.

Fixes #2475.

fpistm commented 3 months ago

This PR fixed all warnings for standard application. Anyway, if a Flash operation (write) is performedclosed to the code segment warning can be raised. Main example is when the EEPROM emulation is used as it uses last flash page, mainly for mcu with small flash size.

I've reproduced easily with a Blink example on a STM32L4 target by adding:

  FLASH_EraseInitTypeDef EraseInitStruct;
  uint32_t pageError = 0;

  HAL_FLASHEx_Erase(&EraseInitStruct, &pageError);
  HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x0800F000, 10);
fpistm commented 2 months ago

To go further, warning is reached due to the usage of at least one RAM function: #define __RAM_FUNC __attribute__((section(".RamFunc")))

Example with HAL FLASH API: https://github.com/stm32duino/Arduino_Core_STM32/blob/2aa4e44bc5f114b2b6eae053d8ebc0eb45a4e93a/system/Drivers/STM32C0xx_HAL_Driver/Src/stm32c0xx_hal_flash.c#L653

So, I kept the warning disabled, but new linker script should use the READONLY attribute to prevent warning.