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
  • 使用
相关推荐
猫猫的小茶馆9 分钟前
【STM32】预分频因子(Prescaler)和重装载值(Reload Value)
c语言·stm32·单片机·嵌入式硬件·mcu·51单片机
Vitta_U16 分钟前
MFC的List Control自适应主界面大小
c++·list·mfc
riveting42 分钟前
明远智睿H618:开启多场景智慧生活新时代
人工智能·嵌入式硬件·智能硬件·lga封装·3506
三万棵雪松2 小时前
【STM32HAL-第1讲 基础篇-单片机简介】
stm32·单片机·嵌入式硬件
玉树临风江流儿2 小时前
炸鸡派-基础测试例程
单片机·嵌入式硬件
板栗焖小鸡2 小时前
STM32-PWM驱动无源蜂鸣器
stm32·学习
智者知已应修善业4 小时前
【51单片机用数码管显示流水灯的种类是按钮控制数码管加一和流水灯】2022-6-14
c语言·经验分享·笔记·单片机·嵌入式硬件·51单片机
智商偏低10 小时前
单片机之helloworld
单片机·嵌入式硬件
青牛科技-Allen11 小时前
GC3910S:一款高性能双通道直流电机驱动芯片
stm32·单片机·嵌入式硬件·机器人·医疗器械·水泵、
白鱼不小白13 小时前
stm32 USART串口协议与外设(程序)——江协教程踩坑经验分享
stm32·单片机·嵌入式硬件