经验分享——RA MCU 如何将变量放在指定地址上?

RA MCU使用e2studio和GCC编译器,如何将变量放在指定地址上?

  • 请参考以下方法,将变量放在指定地址:

    (1) 在“Memory Region”中添加了区域 MY_FLASH 并将其地址设置为 0x00018000。 LENGTH 值取决于数组的大小。可自行定义,这个例子中我设置为了0x100。

     

    (2) 然后在“fsp.ld”中添加你的内存部分(该文件的底部并在最后一个数字括号之前)。

     

    (3)使用定义的部分,如下所示:

    const char __attribute__((section (".test_section"))) my_dat [8] = {0, 1, 2, 3, 4, 5, 6, 7};

     

    调试,可以看到,变量已经被放在了指定位置上。

  • 请问如果是keil上使用gcc编译应该如何设置呢?

    我使用如下代码

    extern uint8_t __attribute__((section(".ARM.__at_0x20010000"))) memp_memory_POOL_256_base[];

    去声明后,发现会出现以下警告

    .\script\fsp.scat(84): warning: L6329W: Pattern *(.data) only matches removed unused sections.

    .\script\fsp.scat: Warning: L6918W: Execution region DTC_VECTOR_TABLE placed at 0x1ffe0000 needs padding to ensure alignment 4 of memp.o(.ARM.__at_0x20010000).

  • 请使用下面的实现方式试一下

    uint8_t memp_memory_POOL_256_base[] __attribute__((section(".ARM.__at_0x20010000")));