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
  • 使用
相关推荐
SY师弟4 分钟前
51单片机基础部分——矩阵按键检测
嵌入式硬件·矩阵·51单片机
Lester_11011 小时前
嵌入式学习笔记 - freeRTOS xTaskResumeAll( )函数解析
笔记·stm32·单片机·学习·freertos
阿超爱嵌入式2 小时前
STM32学习之I2C(理论篇)
stm32·嵌入式硬件·学习
三月雪落无痕4 小时前
altium designer2024绘制stm32过程笔记x`
笔记·嵌入式硬件
天天爱吃肉82186 小时前
新能源汽车热管理核心技术解析:冬季续航提升40%的行业方案
android·python·嵌入式硬件·汽车
章鱼哥嵌入式开发6 小时前
# STM32F103 SD卡读写程序
stm32·单片机
广药门徒7 小时前
定时器时钟来源可以从输入捕获引脚输入
单片机·嵌入式硬件
爱睡觉的王宇昊11 小时前
二、【ESP32开发全栈指南:ESP32 GPIO深度使用】
单片机·嵌入式硬件
学生哥-_-17 小时前
STM32通过KEIL pack包轻松移植LVGL,并学会使用GUI guider
stm32·lvgl·tftlcd·gui guider·gt911
三三十二17 小时前
STM32实战:数字音频播放器开发指南
stm32·单片机·嵌入式硬件