<?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>i.MX RT Crossover MCUs中的主题 Re: Getting initialized variables into HyperRAM</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Getting-initialized-variables-into-HyperRAM/m-p/1511793#M21275</link>
    <description>&lt;P&gt;Thanks Mike,&lt;/P&gt;&lt;P&gt;I played around with this for a little bit and came up with a solution. Figured I'd post that for the next person who runs into this. The main missing piece was telling the linker where to place the data section. A section needed to be carved out below the .data section and the AT() keyword needed to be used:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  __HYPERRAM_DATA_ROM = __HYPERFLASH_DATA_ROM + (__end_data_hyperflash - __start_data_hyperflash);

  /* HyperRam section*/  
  .data_hyperram : AT(__HYPERRAM_DATA_ROM)
  {
    FILL(0xff)
    . = ALIGN(4) ;
    __start_data_hyperram = .;    
    KEEP(*(m_hyperram_data))    
    . = ALIGN(4) ;
    . = ALIGN(32);
    __ram_function_start__ = .;
    KEEP(*(m_hyperram_code))
    . = ALIGN(128);
    __ram_function_end__ = .;    
    __end_data_hyperram = .;
  } &amp;gt; m_hyperram&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Then I found two different ways to copy the initialized values into RAM, one through modifying the startup assembly code, or you can do this with C in the startup routine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ASM:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#ifdef __STARTUP_INITIALIZE_RAMFUNCTION
    ldr    r2, =__ram_function_start__
    ldr    r3, =__ram_function_end__
#ifdef __PERFORMANCE_IMPLEMENTATION
/* Here are two copies of loop implementations. First one favors performance
 * and the second one favors code size. Default uses the second one.
 * Define macro "__PERFORMANCE_IMPLEMENTATION" in project to use the first one */
    subs    r3, r2
    ble    .LC_ramfunc_copy_end
.LC_ramfunc_copy_start:
    subs    r3, #4
    ldr    r0, [r1, r3]
    str    r0, [r2, r3]
    bgt    .LC_ramfunc_copy_start
.LC_ramfunc_copy_end:
#else  /* code size implemenation */
.LC_ramfunc_copy_start:
    cmp     r2, r3
    ittt    lt
    ldrlt   r0, [r1], #4
    strlt   r0, [r2], #4
    blt    .LC_ramfunc_copy_start
#endif
#endif /* __STARTUP_INITIALIZE_RAMFUNCTION */&lt;/LI-CODE&gt;&lt;P&gt;C:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;extern unsigned int __start_data_hyperflash;
extern unsigned int __end_data_hyperflash;
extern unsigned int __HYPERFLASH_DATA_ROM;

void copy_hyperram_data()
{
#ifndef __HYPERFLASH_ASM_ROM_COPY
  unsigned int* hyperflash_rom_table = &amp;amp;__HYPERFLASH_DATA_ROM;
  unsigned int* hyperflash_ram_table = &amp;amp;__start_data_hyperflash;
  unsigned int hyperflash_copy_size = (&amp;amp;__end_data_hyperflash - &amp;amp;__start_data_hyperflash);

  for (unsigned int Index = 0; Index &amp;lt; hyperflash_copy_size; Index++)
  {
    hyperflash_ram_table[Index] = hyperflash_rom_table[Index];
  }
#endif  //__HYPERRAM_ASM_ROM_COPY
}&lt;/LI-CODE&gt;&lt;P&gt;Granted this is for my specific use case, but I'd imagine other linker files would follow the same procedure.&lt;/P&gt;&lt;P&gt;-Derek&lt;/P&gt;</description>
    <pubDate>Thu, 25 Aug 2022 13:40:33 GMT</pubDate>
    <dc:creator>derekkrouze</dc:creator>
    <dc:date>2022-08-25T13:40:33Z</dc:date>
    <item>
      <title>Getting initialized variables into HyperRAM</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Getting-initialized-variables-into-HyperRAM/m-p/1509720#M21217</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've recently gotten HyperRAM working with the i.mx rt 1064. However, now I'm trying to place data in it for use with the application. I'm using a variation of the MIMXRT1064xxxxx_flexspi_nor.ld provided with the NXP sdk. I am currently not using MCUXpresso, but gcc and vscode implementation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added the memory region to the .ld file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;MEMORY
{
  m_flash_config        (RX)  : ORIGIN = 0x70000000, LENGTH = 0x00001000
  m_ivt                 (RX)  : ORIGIN = 0x70001000, LENGTH = 0x00001000
  m_interrupts          (RX)  : ORIGIN = 0x70002000, LENGTH = 0x00000400
  m_text                (RX)  : ORIGIN = 0x70002400, LENGTH = 0x003FDC00
  m_data                (RW)  : ORIGIN = 0x20000000, LENGTH = 0x00020000
  m_data2               (RW)  : ORIGIN = 0x20200000, LENGTH = 0x00080000
  m_hyperram            (RWX)  : ORIGIN = 0x60000000, LENGTH = 0x00020000
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;and a basic way to move data into the custom section:&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  .data_hyperram :
  {
    FILL(0xff)
    . = ALIGN(4) ;
    __start_data_hyperram = .;
    KEEP(*(m_hyperram_data))    
    . = ALIGN(4) ;
    __end_data_hyperram = .;
  } &amp;gt; m_hyperram​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my application I then have a macro to place variables there:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#define HYPERRAM_SECTION_DATA(func) __attribute__((section("m_hyperram_data"))) func

HYPERRAM_SECTION_DATA(volatile uint32_t testdata = 0x12345678);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;My variables seem to be correctly placed into the HyperRAM section, but they are not initialized. I am unsure if there is more I need to add to my .ld file, or if there are custom copy routines that I need to add to the startup.s file. Any help on where to go from here would be greatly appreciated.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 22 Aug 2022 21:37:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Getting-initialized-variables-into-HyperRAM/m-p/1509720#M21217</guid>
      <dc:creator>derekkrouze</dc:creator>
      <dc:date>2022-08-22T21:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Getting initialized variables into HyperRAM</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Getting-initialized-variables-into-HyperRAM/m-p/1510783#M21253</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;It needs related routine/code to do the vaiable initialization at HyperRAM.&lt;/P&gt;
&lt;P&gt;The MCUXpresso provides related code to do the variable initialization, while I am not sure&amp;nbsp;&lt;SPAN&gt;gcc and vscode implementation provide the same function or not.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You need to add related code at &amp;lt;startup.s&amp;gt; file to do related variable initialization.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks for the attention.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 08:57:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Getting-initialized-variables-into-HyperRAM/m-p/1510783#M21253</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2022-08-24T08:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Getting initialized variables into HyperRAM</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Getting-initialized-variables-into-HyperRAM/m-p/1511793#M21275</link>
      <description>&lt;P&gt;Thanks Mike,&lt;/P&gt;&lt;P&gt;I played around with this for a little bit and came up with a solution. Figured I'd post that for the next person who runs into this. The main missing piece was telling the linker where to place the data section. A section needed to be carved out below the .data section and the AT() keyword needed to be used:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  __HYPERRAM_DATA_ROM = __HYPERFLASH_DATA_ROM + (__end_data_hyperflash - __start_data_hyperflash);

  /* HyperRam section*/  
  .data_hyperram : AT(__HYPERRAM_DATA_ROM)
  {
    FILL(0xff)
    . = ALIGN(4) ;
    __start_data_hyperram = .;    
    KEEP(*(m_hyperram_data))    
    . = ALIGN(4) ;
    . = ALIGN(32);
    __ram_function_start__ = .;
    KEEP(*(m_hyperram_code))
    . = ALIGN(128);
    __ram_function_end__ = .;    
    __end_data_hyperram = .;
  } &amp;gt; m_hyperram&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Then I found two different ways to copy the initialized values into RAM, one through modifying the startup assembly code, or you can do this with C in the startup routine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ASM:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#ifdef __STARTUP_INITIALIZE_RAMFUNCTION
    ldr    r2, =__ram_function_start__
    ldr    r3, =__ram_function_end__
#ifdef __PERFORMANCE_IMPLEMENTATION
/* Here are two copies of loop implementations. First one favors performance
 * and the second one favors code size. Default uses the second one.
 * Define macro "__PERFORMANCE_IMPLEMENTATION" in project to use the first one */
    subs    r3, r2
    ble    .LC_ramfunc_copy_end
.LC_ramfunc_copy_start:
    subs    r3, #4
    ldr    r0, [r1, r3]
    str    r0, [r2, r3]
    bgt    .LC_ramfunc_copy_start
.LC_ramfunc_copy_end:
#else  /* code size implemenation */
.LC_ramfunc_copy_start:
    cmp     r2, r3
    ittt    lt
    ldrlt   r0, [r1], #4
    strlt   r0, [r2], #4
    blt    .LC_ramfunc_copy_start
#endif
#endif /* __STARTUP_INITIALIZE_RAMFUNCTION */&lt;/LI-CODE&gt;&lt;P&gt;C:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;extern unsigned int __start_data_hyperflash;
extern unsigned int __end_data_hyperflash;
extern unsigned int __HYPERFLASH_DATA_ROM;

void copy_hyperram_data()
{
#ifndef __HYPERFLASH_ASM_ROM_COPY
  unsigned int* hyperflash_rom_table = &amp;amp;__HYPERFLASH_DATA_ROM;
  unsigned int* hyperflash_ram_table = &amp;amp;__start_data_hyperflash;
  unsigned int hyperflash_copy_size = (&amp;amp;__end_data_hyperflash - &amp;amp;__start_data_hyperflash);

  for (unsigned int Index = 0; Index &amp;lt; hyperflash_copy_size; Index++)
  {
    hyperflash_ram_table[Index] = hyperflash_rom_table[Index];
  }
#endif  //__HYPERRAM_ASM_ROM_COPY
}&lt;/LI-CODE&gt;&lt;P&gt;Granted this is for my specific use case, but I'd imagine other linker files would follow the same procedure.&lt;/P&gt;&lt;P&gt;-Derek&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 13:40:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Getting-initialized-variables-into-HyperRAM/m-p/1511793#M21275</guid>
      <dc:creator>derekkrouze</dc:creator>
      <dc:date>2022-08-25T13:40:33Z</dc:date>
    </item>
  </channel>
</rss>

