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
  • 使用
相关推荐
lzj_pxxw1 小时前
嵌入式开发技巧:舍弃标志位,用宏定义函数实现程序单次运行
笔记·stm32·单片机·嵌入式硬件·学习
XINVRY-FPGA2 小时前
XCAU10P-2SBVB484I Xilinx Artix UltraScale+ FPGA
嵌入式硬件·fpga开发·云计算·硬件工程·dsp开发·射频工程·fpga
木子单片机2 小时前
基于51单片机温度检测报警
stm32·单片机·嵌入式硬件·51单片机·keil
hazy1k12 小时前
51单片机基础-步进电机控制
stm32·单片机·嵌入式硬件·51单片机
第二层皮-合肥13 小时前
RTC时钟原理
单片机·嵌入式硬件
小莞尔15 小时前
【51单片机】【protues仿真】基于51单片机送带计数器系统
c语言·单片机·嵌入式硬件·物联网·51单片机
云知谷16 小时前
【嵌入式基本功】单片机嵌入式学习路线
linux·c语言·c++·单片机·嵌入式硬件
小叮当⇔18 小时前
IOT项目——STM32
stm32·嵌入式硬件·物联网
光子物联单片机18 小时前
STM32G474单片机开发入门(十五)CAN通信功能详解及实战
stm32·单片机·嵌入式硬件·mcu
A9better18 小时前
嵌入式开发学习日志40——stm32之I2C协议层
stm32·单片机·嵌入式硬件·学习