Arduino_Core_STM32 icon indicating copy to clipboard operation
Arduino_Core_STM32 copied to clipboard

chore: mark some segments as READONLY

Open fpistm opened this issue 1 year ago • 1 comments

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 avatar Aug 20 '24 14:08 fpistm

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 avatar Aug 21 '24 09:08 fpistm

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.

fpistm avatar Sep 04 '24 12:09 fpistm