STM32定义变量到指定内存位置

rt thread, 怎么定义变量到指定内存位置?

OpenCat是由未来可编程机器人宠物制造商Petoi开发的基于Arduino和Raspberry Pi的开源四足机器人宠物框架。

非 gcc 版

  • 定义一个宏
c 复制代码
  #ifndef      __MEMORY_AT    
    #if     (defined (__CC_ARM))      
      #define  __MEMORY_AT(x)     __attribute__((at(x)))    
    #elif   (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))      
      #define  __MEMORY_AT__(x)   __attribute__((section(".ARM.__AT_"#x)))      
      #define  __MEMORY_AT(x)     __MEMORY_AT__(x)    
    #else      
      #define  __MEMORY_AT(x)      
      #warning Position memory containing __MEMORY_AT macro at absolute address!    
  #endif  
#endif
  • 使用
c 复制代码
uint8_t blended_address_buffer[480*272*2] __MEMORY_AT(0xC0000000);

gcc 版

  • 修改链接文件
c 复制代码
  /* Program Entry, set to mark it as "used" and avoid gc */
  MEMORY
  {
      CODE (rx) : ORIGIN = 0x08000000, LENGTH = 1024k /* 1024KB flash */
      RAM1 (rw) : ORIGIN = 0x20000000, LENGTH =  192k /* 192K sram */
      RAM2 (rw) : ORIGIN = 0x10000000, LENGTH =   64k /* 64K sram */
      SDRAM (rw): ORIGIN = 0xC0000000, LENGTH = 8092k /* 1024KB sdram */
  }
  SECTIONS
  {
      ... /* 忽略其它内容 */
      .sdram : 
      {
          KEEP(*(.sdram_section))
      } >SDRAM
  }
  • 定义一个宏
c 复制代码
  #ifndef      __MEMORY_AT
    #define  __MEMORY_AT(x)     __attribute__((section(".#x")))
  #endif
  • 使用
相关推荐
「QT(C++)开发工程师」35 分钟前
STM32 | FreeRTOS 消息队列
stm32·单片机·嵌入式硬件
sword devil9001 小时前
STM32烧录程序正常,但是运行异常
stm32·单片机·嵌入式硬件
YOYO--小天2 小时前
4G和5G模块的使用
linux·嵌入式硬件·5g
百里东风2 小时前
STM32IIC实战-OLED模板
stm32·单片机·嵌入式硬件
一月千帆2 小时前
基于STM32的INA226电压电流检测仪
stm32·单片机·嵌入式硬件
A-花开堪折4 小时前
OpenMCU(七):STM32F103开发环境搭建
stm32·单片机·嵌入式硬件
#金毛12 小时前
四、STM32 HAL库API完全指南:从功能分类到实战示例
stm32·单片机·嵌入式硬件
百里东风13 小时前
STM32外设AD-定时器触发 + DMA读取模板
stm32·单片机·嵌入式硬件
Deacde_ZY14 小时前
【控制波形如何COPY并无痛使用】
单片机·嵌入式硬件
小乌龟不会飞14 小时前
gflags 安装及使用
c++·mfc·gflags 库