<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic unaligned memory access fault on S32K312 with MCAL RTD 3.0.0 in S32K</title>
    <link>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1885757#M36478</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a unaligned memory access fault on S32K312 with MCAL RTD 3.0.0.&lt;/P&gt;&lt;P&gt;The issue description :&lt;/P&gt;&lt;P&gt;With Autoever Autosar V2.0.0 SWP release, OS reset happened which is caused by unaligned memory access fault.&lt;BR /&gt;The fault always happened when a global variable is defined in system RAM area of 0x2040C000~0x20418000.&lt;BR /&gt;In system RAM area of 0x20404000~20407fff, there is no this fault.&lt;BR /&gt;In DTCM area, there is no this fault.&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;I tested two ways of the unaligned memory access which would trigger the fault.&lt;/P&gt;&lt;P&gt;. Way-1, structure elements access in unaligned memory&lt;/P&gt;&lt;P&gt;typedef struct {&lt;BR /&gt;uint8 a;&lt;BR /&gt;uint32 b;&lt;BR /&gt;}unaligned_test_t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;attribute((section(".SYSRAM_2040B000"))) unaligned_test_t unaligned_test_data_sram_2040B000;&lt;BR /&gt;attribute((section(".SYSRAM_2040C000"))) unaligned_test_t unaligned_test_data_sram_2040C000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void unaligned_test(void)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;unaligned_test_data_sram_2040B000.b = 0x10; // no unaligned access error.&lt;BR /&gt;unaligned_test_data_sram_2040C000.b = 0x10; // unaligned access error happened.&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. Way-2, array access in unaligned memory&lt;/P&gt;&lt;P&gt;attribute((section(".SYSRAM_2040B000"))) uint8 unaligned_test_array_sram_2040B000;&lt;BR /&gt;attribute((section(".SYSRAM_2040C000"))) uint8 unaligned_test_array_sram_2040C000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void unaligned_test(void){&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;uint32 * ptr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;for (uint32 i=0; i&amp;lt;16; i++)&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr = (uint32 *)&amp;amp;unaligned_test_array_sram_2040B000[i];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *ptr = i;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // no unaligned access error happened.&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;for (uint32 i=0; i&amp;lt;16; i++)&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr = (uint32 *)&amp;amp;unaligned_test_array_sram_2040C000[i];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *ptr = i;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // no unaligned access error happened on offset 0,4,8,12&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// unaligned access error happened on offset 1,2,3,5,6,7,9,10,11,13,14,15.&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2024 05:18:03 GMT</pubDate>
    <dc:creator>Hudson001</dc:creator>
    <dc:date>2024-06-12T05:18:03Z</dc:date>
    <item>
      <title>unaligned memory access fault on S32K312 with MCAL RTD 3.0.0</title>
      <link>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1885757#M36478</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a unaligned memory access fault on S32K312 with MCAL RTD 3.0.0.&lt;/P&gt;&lt;P&gt;The issue description :&lt;/P&gt;&lt;P&gt;With Autoever Autosar V2.0.0 SWP release, OS reset happened which is caused by unaligned memory access fault.&lt;BR /&gt;The fault always happened when a global variable is defined in system RAM area of 0x2040C000~0x20418000.&lt;BR /&gt;In system RAM area of 0x20404000~20407fff, there is no this fault.&lt;BR /&gt;In DTCM area, there is no this fault.&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;I tested two ways of the unaligned memory access which would trigger the fault.&lt;/P&gt;&lt;P&gt;. Way-1, structure elements access in unaligned memory&lt;/P&gt;&lt;P&gt;typedef struct {&lt;BR /&gt;uint8 a;&lt;BR /&gt;uint32 b;&lt;BR /&gt;}unaligned_test_t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;attribute((section(".SYSRAM_2040B000"))) unaligned_test_t unaligned_test_data_sram_2040B000;&lt;BR /&gt;attribute((section(".SYSRAM_2040C000"))) unaligned_test_t unaligned_test_data_sram_2040C000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void unaligned_test(void)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;unaligned_test_data_sram_2040B000.b = 0x10; // no unaligned access error.&lt;BR /&gt;unaligned_test_data_sram_2040C000.b = 0x10; // unaligned access error happened.&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. Way-2, array access in unaligned memory&lt;/P&gt;&lt;P&gt;attribute((section(".SYSRAM_2040B000"))) uint8 unaligned_test_array_sram_2040B000;&lt;BR /&gt;attribute((section(".SYSRAM_2040C000"))) uint8 unaligned_test_array_sram_2040C000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void unaligned_test(void){&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;uint32 * ptr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;for (uint32 i=0; i&amp;lt;16; i++)&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr = (uint32 *)&amp;amp;unaligned_test_array_sram_2040B000[i];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *ptr = i;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // no unaligned access error happened.&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;for (uint32 i=0; i&amp;lt;16; i++)&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr = (uint32 *)&amp;amp;unaligned_test_array_sram_2040C000[i];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *ptr = i;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // no unaligned access error happened on offset 0,4,8,12&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// unaligned access error happened on offset 1,2,3,5,6,7,9,10,11,13,14,15.&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 05:18:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1885757#M36478</guid>
      <dc:creator>Hudson001</dc:creator>
      <dc:date>2024-06-12T05:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: unaligned memory access fault on S32K312 with MCAL RTD 3.0.0</title>
      <link>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1886049#M36494</link>
      <description>&lt;P&gt;The issue disappeared after MPU init code masked, that means MPU disabled. So why the MPU would trigger the unaligned access issue? The MPU config is in below,&lt;/P&gt;&lt;LI-CODE lang="c"&gt;  Region  Description                   Start       End           Size[KB]  permission                attribute                 execute              srd     enable
--------  ----------------------------  ----------  ----------  ----------  ------------------------  ------------------------  -------------------  ------  ----------
       0  BACKGROUND_REGION             0x0         0xFFFFFFFF     4194304  MPU_ACCESS_P_PRIV_RW      MPU_ATTR_STR_ORD_DEV      MPU_INST_ACCESS_DIS  0x00    MPU_ENABLE
       1  CM7_SELF_ITCM_REGION          0x0         0x00007FFF          32  MPU_ACCESS_P_PRIV_RW      MPU_ATTR_NORM_MEM_WT      MPU_INST_ACCESS_EN   0x00    MPU_ENABLE
       2  PROGRAM_FLASH_REGION_ADDR     0x00400000  0x005FFFFF        2048  MPU_ACCESS_P_PRIV_RO      MPU_ATTR_NORM_MEM_WT      MPU_INST_ACCESS_EN   0x00    MPU_ENABLE
       3  DATA_FLASH_REGION_ADDR        0x10000000  0x1001FFFF         128  MPU_ACCESS_P_PRIV_RW      MPU_ATTR_NORM_MEM_WT      MPU_INST_ACCESS_DIS  0x00    MPU_ENABLE
       4  CM7_SELF_DTCM_REGION_ADDR     0x20000000  0x2000FFFF          64  MPU_ACCESS_P_PRIV_RW      MPU_ATTR_NORM_MEM_WT      MPU_INST_ACCESS_DIS  0x00    MPU_ENABLE
       5  SRAM_REGION_ADDR              0x20400000  0x20417FFF          96  MPU_ACCESS_P_PRIV_RW      MPU_ATTR_NORM_MEM_WT      MPU_INST_ACCESS_EN   0x00    MPU_ENABLE
       6  PERI_REGISTER_REGION_ADDR     0x40008000  0x40807FFF        8192  MPU_ACCESS_P_PRIV_RW      MPU_ATTR_SHR_DEV          MPU_INST_ACCESS_DIS  0x00    MPU_ENABLE
*/
static const uint32 EcuM_Rbar[CPU_MPU_MEMORY_COUNT] = {0x00000000UL, 0x00000000UL, 0x00400000UL, 0x10000000UL, 0x20000000UL, 0x20400000UL, 0x40008000UL};
static const uint32 EcuM_Rasr[CPU_MPU_MEMORY_COUNT] = {0x1100003FUL, 0x0102001DUL, 0x05020029UL, 0x11020021UL, 0x1102001FUL, 0x0102F821UL, 0x1101002DUL};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 10:13:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1886049#M36494</guid>
      <dc:creator>Hudson001</dc:creator>
      <dc:date>2024-06-12T10:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: unaligned memory access fault on S32K312 with MCAL RTD 3.0.0</title>
      <link>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1886997#M36559</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/234876"&gt;@Hudson001&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;In ARM®v7-M Architecture Reference Manual&lt;/P&gt;
&lt;P&gt;Section A3.5.7 Memory access restrictions&lt;/P&gt;
&lt;P&gt;You can read:&lt;/P&gt;
&lt;P&gt;"An instruction that generates an unaligned memory access to Device or Strongly-ordered memory is &lt;BR /&gt;UNPREDICTABLE."&lt;/P&gt;
&lt;P&gt;Here are the definitions of the memory types:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://developer.arm.com/documentation/dui0646/c/Cortex-M7-Peripherals/Optional-Memory-Protection-Unit/MPU-access-permission-attributes" target="_blank"&gt;https://developer.arm.com/documentation/dui0646/c/Cortex-M7-Peripherals/Optional-Memory-Protection-Unit/MPU-access-permission-attributes&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 12:19:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1886997#M36559</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2024-06-13T12:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: unaligned memory access fault on S32K312 with MCAL RTD 3.0.0</title>
      <link>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1887565#M36591</link>
      <description>&lt;P&gt;Thank you Daniel,&lt;/P&gt;&lt;P&gt;But still not clear why the unaligned error happened on system ram address &amp;gt;=0x2040c000, the MPU setting seems applied on whole sysRam 0x20400000 with&amp;nbsp;MPU Rasr register value&amp;nbsp;0x0102F821&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 06:09:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1887565#M36591</guid>
      <dc:creator>Hudson001</dc:creator>
      <dc:date>2024-06-14T06:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: unaligned memory access fault on S32K312 with MCAL RTD 3.0.0</title>
      <link>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1887952#M36615</link>
      <description>&lt;P&gt;I see, it is a normal type memory.&lt;/P&gt;
&lt;P&gt;I have just reproduced the error using your RASR value.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_0-1718373692711.png" style="width: 664px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/284251iD099CC28F42F404D/image-dimensions/664x163?v=v2" width="664" height="163" role="button" title="danielmartynek_0-1718373692711.png" alt="danielmartynek_0-1718373692711.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In my test project, there are only 2 regions, this one and one that covers the whole map (Strongly ordered)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_1-1718373781518.png" style="width: 493px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/284252i5D5C7075A95DEDB7/image-dimensions/493x270?v=v2" width="493" height="270" role="button" title="danielmartynek_1-1718373781518.png" alt="danielmartynek_1-1718373781518.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Why do you enable the subregions there?&lt;/P&gt;
&lt;P&gt;It works when the subregions are disabled, refer to ARM documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you try this configuration?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_2-1718373926610.png" style="width: 495px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/284254iEEDF643FD07B5202/image-dimensions/495x405?v=v2" width="495" height="405" role="button" title="danielmartynek_2-1718373926610.png" alt="danielmartynek_2-1718373926610.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_3-1718373975259.png" style="width: 632px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/284255i05E53A614B3AC267/image-dimensions/632x122?v=v2" width="632" height="122" role="button" title="danielmartynek_3-1718373975259.png" alt="danielmartynek_3-1718373975259.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 14:07:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1887952#M36615</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2024-06-14T14:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: unaligned memory access fault on S32K312 with MCAL RTD 3.0.0</title>
      <link>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1890311#M36750</link>
      <description>&lt;P&gt;Hi Daniel, I got understand the RASR register usage.&lt;/P&gt;&lt;P&gt;The MPU region size (RASR.Size) is defined as 2^(16+1) = 128KB, so each subregion is 128K/8 = 16K. On S32K312, SRAM is 96KB, so SRD bit of RASR should be 0xC0, subregion 7,6 disabled, subregion 5-0 enabled.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested RASR with value of 0x01020021 and 0x0102C021, both worked, unaligned error did not happen on whole SRAM region of 0x20400000~0x20417FFF.&lt;/P&gt;&lt;P&gt;Thanks for your great support^^&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Hudson&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 10:37:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/unaligned-memory-access-fault-on-S32K312-with-MCAL-RTD-3-0-0/m-p/1890311#M36750</guid>
      <dc:creator>Hudson001</dc:creator>
      <dc:date>2024-06-19T10:37:25Z</dc:date>
    </item>
  </channel>
</rss>

