Hello,
I have a unaligned memory access fault on S32K312 with MCAL RTD 3.0.0.
The issue description :
With Autoever Autosar V2.0.0 SWP release, OS reset happened which is caused by unaligned memory access fault.
The fault always happened when a global variable is defined in system RAM area of 0x2040C000~0x20418000.
In system RAM area of 0x20404000~20407fff, there is no this fault.
In DTCM area, there is no this fault.
I have checked the UNALIGN_TRP bit of Arm Cortex-m7 CCR register, it's disabled in init, and checked when fault happening, it is zero, Trapping disabled.
I tested two ways of the unaligned memory access which would trigger the fault.
. Way-1, structure elements access in unaligned memory
typedef struct {
uint8 a;
uint32 b;
}unaligned_test_t;
attribute((section(".SYSRAM_2040B000"))) unaligned_test_t unaligned_test_data_sram_2040B000;
attribute((section(".SYSRAM_2040C000"))) unaligned_test_t unaligned_test_data_sram_2040C000;
void unaligned_test(void)
{
unaligned_test_data_sram_2040B000.b = 0x10; // no unaligned access error.
unaligned_test_data_sram_2040C000.b = 0x10; // unaligned access error happened.
}
. Way-2, array access in unaligned memory
attribute((section(".SYSRAM_2040B000"))) uint8 unaligned_test_array_sram_2040B000;
attribute((section(".SYSRAM_2040C000"))) uint8 unaligned_test_array_sram_2040C000;
void unaligned_test(void){
uint32 * ptr;
for (uint32 i=0; i<16; i++)
{
ptr = (uint32 *)&unaligned_test_array_sram_2040B000[i];
*ptr = i; // no unaligned access error happened.
}
for (uint32 i=0; i<16; i++)
{
ptr = (uint32 *)&unaligned_test_array_sram_2040C000[i];
*ptr = i; // no unaligned access error happened on offset 0,4,8,12
// unaligned access error happened on offset 1,2,3,5,6,7,9,10,11,13,14,15.
}
}