<?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 LPC540xx - MCAN_SetMsgRAMBase asserts with XIP image in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC540xx-MCAN-SetMsgRAMBase-asserts-with-XIP-image/m-p/1800342#M55312</link>
    <description>&lt;P&gt;I work on the LPCXpresso54S018 development board. Because this board doesn't have internal flash I use the populated external flash W25Q128JVFM, and I build my application as an XIP image, to do so I define the XIP_IMAGE flag for the LPC54S018_spifi_flash.ld linker script. And few ASM flags for the startup_LPC54S018.S startup file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;IMG_BAUDRATE=96000000
W25Q128JVFM
XIP_IMAGE
__STARTUP_CLEAR_BSS&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the result for memory regions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[build] Memory region         Used Size  Region Size  %age Used
[build]     m_interrupts:         452 B        512 B     88.28%
[build]           m_text:       92616 B   16776704 B      0.55%
[build]           m_data:       58196 B     196604 B     29.60%
[build]       m_usb_sram:          0 GB         8 KB      0.00%&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I can the in the output.map file the `.data` region is at the very start of the internal RAM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.data           0x0000000000000008      0x5c0 load address 0x0000000010016608
                0x0000000000000008                . = ALIGN (0x4)
                0x0000000000000008                __DATA_RAM = .
                0x0000000000000008                __data_start__ = .&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, everything works good. I can flash or debug my program.&lt;/P&gt;&lt;P&gt;My issue comes when I try to use the CAN bus (MCAN driver), it seems the CAN message RAM is the source of the issue. When I add this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;__attribute__((aligned(1U &amp;lt;&amp;lt; CAN_MRBA_BA_SHIFT), section(".data"))) uint8_t msgRam[MSG_RAM_SIZE] = {1U};`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my result, as you can see the m_data region sharp increases:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[build] Memory region         Used Size  Region Size  %age Used
[build]     m_interrupts:         452 B        512 B     88.28%
[build]           m_text:      101360 B   16776704 B      0.60%
[build]           m_data:      124076 B     196604 B     63.11% ← +65880 bytes (33.51%)
[build]       m_usb_sram:          0 GB         8 KB      0.00%&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the output.map:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.data           0x0000000000010000      0x708 load address 0x00000000100186e8
                0x0000000000010000                . = ALIGN (0x4)
                0x0000000000010000                __DATA_RAM = .
                0x0000000000010000                __data_start__ = .
 *(.ramfunc*)
 *(.data)
 .data          0x0000000000010000      0x12d
                0x0000000000010000                msgRam&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the assert in the MCAN_SetMsgRAMBase function is triggered:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;assert(((value &amp;gt;= 0x20000000U) &amp;amp;&amp;amp; (value &amp;lt;= 0x20027FFFU)) || ((value &amp;gt;= 0x04000000U) &amp;amp;&amp;amp; (value &amp;lt;= 0x04007FFFU)));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I deal with this problem? What is the purpose of this assert, does it make sense for an XIP image, and how can I prevent the m_data region from increasing in this way?&lt;/P&gt;&lt;P&gt;Btw it seems the program works fine if I remove the assert.&lt;/P&gt;&lt;P&gt;To reproduce my issue, you can just build the mcan_loopback example as an XIP image. To do so, you need to edit the flag.cmake file as shown in the attachment.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2024 00:25:21 GMT</pubDate>
    <dc:creator>Theodore_Bardy</dc:creator>
    <dc:date>2024-02-02T00:25:21Z</dc:date>
    <item>
      <title>LPC540xx - MCAN_SetMsgRAMBase asserts with XIP image</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC540xx-MCAN-SetMsgRAMBase-asserts-with-XIP-image/m-p/1800342#M55312</link>
      <description>&lt;P&gt;I work on the LPCXpresso54S018 development board. Because this board doesn't have internal flash I use the populated external flash W25Q128JVFM, and I build my application as an XIP image, to do so I define the XIP_IMAGE flag for the LPC54S018_spifi_flash.ld linker script. And few ASM flags for the startup_LPC54S018.S startup file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;IMG_BAUDRATE=96000000
W25Q128JVFM
XIP_IMAGE
__STARTUP_CLEAR_BSS&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the result for memory regions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[build] Memory region         Used Size  Region Size  %age Used
[build]     m_interrupts:         452 B        512 B     88.28%
[build]           m_text:       92616 B   16776704 B      0.55%
[build]           m_data:       58196 B     196604 B     29.60%
[build]       m_usb_sram:          0 GB         8 KB      0.00%&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I can the in the output.map file the `.data` region is at the very start of the internal RAM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.data           0x0000000000000008      0x5c0 load address 0x0000000010016608
                0x0000000000000008                . = ALIGN (0x4)
                0x0000000000000008                __DATA_RAM = .
                0x0000000000000008                __data_start__ = .&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, everything works good. I can flash or debug my program.&lt;/P&gt;&lt;P&gt;My issue comes when I try to use the CAN bus (MCAN driver), it seems the CAN message RAM is the source of the issue. When I add this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;__attribute__((aligned(1U &amp;lt;&amp;lt; CAN_MRBA_BA_SHIFT), section(".data"))) uint8_t msgRam[MSG_RAM_SIZE] = {1U};`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my result, as you can see the m_data region sharp increases:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[build] Memory region         Used Size  Region Size  %age Used
[build]     m_interrupts:         452 B        512 B     88.28%
[build]           m_text:      101360 B   16776704 B      0.60%
[build]           m_data:      124076 B     196604 B     63.11% ← +65880 bytes (33.51%)
[build]       m_usb_sram:          0 GB         8 KB      0.00%&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the output.map:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.data           0x0000000000010000      0x708 load address 0x00000000100186e8
                0x0000000000010000                . = ALIGN (0x4)
                0x0000000000010000                __DATA_RAM = .
                0x0000000000010000                __data_start__ = .
 *(.ramfunc*)
 *(.data)
 .data          0x0000000000010000      0x12d
                0x0000000000010000                msgRam&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the assert in the MCAN_SetMsgRAMBase function is triggered:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;assert(((value &amp;gt;= 0x20000000U) &amp;amp;&amp;amp; (value &amp;lt;= 0x20027FFFU)) || ((value &amp;gt;= 0x04000000U) &amp;amp;&amp;amp; (value &amp;lt;= 0x04007FFFU)));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I deal with this problem? What is the purpose of this assert, does it make sense for an XIP image, and how can I prevent the m_data region from increasing in this way?&lt;/P&gt;&lt;P&gt;Btw it seems the program works fine if I remove the assert.&lt;/P&gt;&lt;P&gt;To reproduce my issue, you can just build the mcan_loopback example as an XIP image. To do so, you need to edit the flag.cmake file as shown in the attachment.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 00:25:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC540xx-MCAN-SetMsgRAMBase-asserts-with-XIP-image/m-p/1800342#M55312</guid>
      <dc:creator>Theodore_Bardy</dc:creator>
      <dc:date>2024-02-02T00:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: LPC540xx - MCAN_SetMsgRAMBase asserts with XIP image</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC540xx-MCAN-SetMsgRAMBase-asserts-with-XIP-image/m-p/1800566#M55320</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;For your question, as you have seen the line:&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-c"&gt;&lt;CODE&gt;__attribute__((aligned(1U &amp;lt;&amp;lt; CAN_MRBA_BA_SHIFT), section(".data"))) uint8_t msgRam[MSG_RAM_SIZE] = {1U};`&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The CAN_MRBA_BA_SHIFT is 16 bits, it means that the compiler has to allocate 64KB memory space with low 16 bits all 0x0000, for example the this is a valid address 0xXXXX_0000.&lt;/P&gt;
&lt;P&gt;This is the message RAM part, all the Receiver Filter, message buffer, and receiver FIFO are all put in the message RAM,the start address is written in the&amp;nbsp; Message RAM base address register, pls refer to section 36.8.44 Message RAM base address register.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xiangjun_rong_0-1706855155968.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/261544i8265744E0274C3A1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xiangjun_rong_0-1706855155968.png" alt="xiangjun_rong_0-1706855155968.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I have checked the CAN example with SDK with 2.7.0 version, it writes a memory address directly.&lt;/P&gt;
&lt;DIV style="background-color: #ffffff; padding: 0px 0px 0px 2px;"&gt;
&lt;DIV style="color: #000000; background-color: #ffffff; font-family: 'Consolas'; font-size: 10pt; white-space: pre;"&gt;
&lt;P style="background-color: #e8f2fe; margin: 0;"&gt;&lt;SPAN&gt;#define&lt;/SPAN&gt; &lt;SPAN&gt;MSG_RAM_BASE&lt;/SPAN&gt;&lt;SPAN&gt; 0x20010000U&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV style="background-color: #ffffff; padding: 0px 0px 0px 2px;"&gt;
&lt;DIV style="color: #000000; background-color: #ffffff; font-family: 'Consolas'; font-size: 10pt; white-space: pre;"&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;/* Set Message RAM base address and clear to avoid BEU/BEC error. */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt; MCAN_SetMsgRAMBase(EXAMPLE_MCAN, &lt;/SPAN&gt;&lt;SPAN&gt;MSG_RAM_BASE&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN&gt; *p = (&lt;/SPAN&gt;&lt;SPAN&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN&gt; *)(&lt;/SPAN&gt;&lt;SPAN&gt;MSG_RAM_BASE&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt; memset(p, 0, (8U + CAN_DATASIZE) * &lt;/SPAN&gt;&lt;SPAN&gt;sizeof&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;uint8_t&lt;/SPAN&gt;&lt;SPAN&gt;));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;In order to save the memory address, you can refer to the method to write an immediate value to the&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;Message RAM base address register.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;The assert() only verifies if the address is in the RAM address range.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;Hope it can help you&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;BR&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0;"&gt;&lt;SPAN&gt;XiangJun Rong&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 02 Feb 2024 06:46:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC540xx-MCAN-SetMsgRAMBase-asserts-with-XIP-image/m-p/1800566#M55320</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2024-02-02T06:46:57Z</dc:date>
    </item>
  </channel>
</rss>

