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
  • 使用
相关推荐
郭子涵本人3 小时前
51单片机(markdown格式阅读)
单片机·嵌入式硬件·51单片机
格里姆肖4 小时前
小米铁蛋电机1代驱动开发
单片机·嵌入式硬件
hazy1k4 小时前
51单片机基础-LCD1602液晶显示
stm32·单片机·嵌入式硬件·51单片机·1024程序员节
兆龙电子单片机设计8 小时前
【STM32项目开源】STM32单片机医疗点滴控制系统
stm32·单片机·开源·毕业设计·电子信息
dadaobusi9 小时前
看到一段SVA代码,让AI解释了一下
单片机·嵌入式硬件·fpga开发
门外的兔子10 小时前
【FPGA】Quartus Prime Lite 23.1 最新版 安装教程 ModelSim_18.1 下载安装 + 联调仿真教程 + 详细安装教程 2025最新
嵌入式硬件·fpga开发·1024程序员节
Hero_112710 小时前
Stm32 之 按键篇
stm32·单片机·嵌入式硬件
切糕师学AI12 小时前
MCU中的 HSI、HSE、LSI、LSE
嵌入式硬件·mcu·硬件时钟
星一工作室12 小时前
STM32项目分享:基于STM32单片机的恒温药箱的设计
stm32·单片机·嵌入式硬件
堕落年代12 小时前
STM32的DH11温湿度模块和LED灯的综合实训
stm32·单片机·嵌入式硬件