How to prevent unaligned access on backup ram?
(and why is this a problem?)
It looks like the backup ram can not be called through unaligned access on my STM32U585. The mighty internet says that this should not be completely unexpected since it is basically a peripheral and no standard Ram.

I have set up the BKPSRAM in the linker file like this:
#include "partition.h"
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x000 ; /* required amount of heap */
_Min_Stack_Size = 0x800 ; /* required amount of stack */
/* Memories definition */
MEMORY
{
BKPSRAM (xrw) : ORIGIN = 0x40036400, LENGTH = 2K
SRAM4 (xrw) : ORIGIN = 0x28000000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = NON_SEC_RAM_SIZE /* Secure is using end RAM3 (64k). Actual start is 0x20000000 and actual length is 768K */
FLASH (rx) : ORIGIN = 0x8000000 + APP_SLOT0_NON_SEC_APP_OFFSET, LENGTH = NON_SEC_APP_SIZE /* Memory is divided. Actual start is 0x08000000 and actual length is 2048K */
}
/* Sections */
SECTIONS
{
...
/* backup ram area */
BKUP_RAM(NOLOAD):
{
. = ALIGN(8);
*(BKUP_RAM)
*(BKUP_RAM*)
. = ALIGN(8);
}>BKPSRAM
...The respective variables are moved in the section BKUP_RAM accordingly.
Compiler is the arm GCC toolchain 14.2.
I have found out that I can solve this with -mno-unaligned-access for the complete project, but of course this means missed optimization through the whole project. Is there a way to only mark the specific section/variables instead?


