OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 6323|回复: 10

GNU/GCC , arm-none-eabi-gcc 不识别__attribute__((at(xxx))); 请问如何把大数组定义在SDRAM

[复制链接]

1

主题

7

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2018-9-11
在线时间
5 小时
发表于 2018-9-11 16:31:36 | 显示全部楼层 |阅读模式
1金钱
使用GNU/GCC , arm-none-eabi-gcc 不识别__attribute__((at(0X68000000)));       

请问需要怎么搞, 把大数组放在SDRAM中?  谢谢

看资料可以类似使用 __attribute__ (( section (".ext1text") )), 请问LD文件怎么写? 谢谢!

最佳答案

查看完整内容[请看2#楼]

__attribute__((section(".ARM.__at_0x68000000")))
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

3

主题

1907

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
4106
金钱
4106
注册时间
2018-8-14
在线时间
696 小时
发表于 2018-9-11 16:31:37 | 显示全部楼层
rockzhou 发表于 2018-9-12 09:14
arm-none-eabi-gcc -v

gcc version 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 24049 ...

__attribute__((section(".ARM.__at_0x68000000")))
回复

使用道具 举报

3

主题

312

帖子

0

精华

高级会员

Rank: 4

积分
907
金钱
907
注册时间
2011-10-19
在线时间
196 小时
发表于 2018-9-11 17:24:41 | 显示全部楼层
本帖最后由 ufbycd 于 2018-9-11 17:33 编辑

你这数组属于已初始化的全局变量,似乎要牵涉到启动代码,似乎有点麻烦。
回复

使用道具 举报

1

主题

7

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2018-9-11
在线时间
5 小时
 楼主| 发表于 2018-9-11 18:09:04 | 显示全部楼层
__attribute__ (( section (".sdram") )) uint16_t DCMI_FRAMEBUFFER2[800*600 + 64];
__attribute__ (( section (".sdram") )) uint16_t LTDC_FRAMEBUFFER[1024*600];

全局,不用初始化,没有={xxx}, 不修改启动, 只想在程序中如下应用,从Camera采集到   ->  SDRAM_addr1  -> 相关操作  -> SDRAM_addr2  -> LTDC显示(映射在SDRAM_addr3)  
回复

使用道具 举报

1

主题

7

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2018-9-11
在线时间
5 小时
 楼主| 发表于 2018-9-11 19:55:09 | 显示全部楼层
代码中用法:
#define IN_SDRAM(NAME) __attribute__ (( section (NAME) ))

IN_SDRAM(".LTDC") uint16_t LTDC_FRAMEBUFFER[1024*600];
IN_SDRAM(".DCMI") uint16_t DCMI_FRAMEBUFFER[800*600 + 64];

在函数中打印:
    printf("SDRAM map:  0x%x  0x%x \r\n ", LTDC_FRAMEBUFFER, DCMI_FRAMEBUFFER);

结果:
SDRAM map:  0x0  0x12c000
回复

使用道具 举报

1

主题

7

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2018-9-11
在线时间
5 小时
 楼主| 发表于 2018-9-11 19:57:15 | 显示全部楼层
本帖最后由 rockzhou 于 2018-9-11 19:58 编辑

这个LD文件验证不对
/*
*****************************************************************************
**

**  File        : LinkerScript.ld
**
**  Abstract    : Linker script for STM32F767IGTx Device with
**                1024KByte FLASH, 512KByte RAM
**
**                Set heap size, stack size and stack location according
**                to application requirements.
**
**                Set memory bank area and size if external memory is used.
**
**  Target      : STMicroelectronics STM32
**
**
**  Distribution: The file is distributed as is, without any warranty
**                of any kind.
**
**  (c)Copyright Ac6.
**  You may use this file as-is or modify it according to the needs of your
**  project. Distribution of this file (unmodified or modified) is not
**  permitted. Ac6 permit registered System Workbench for MCU users the
**  rights to distribute the assembled, compiled & linked contents of this
**  file as part of an application binary file, provided that it is built
**  using the System Workbench for MCU toolchain.
**
*****************************************************************************
*/

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20080000;    /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x2800;      /* required amount of heap  */
_Min_Stack_Size = 0x1000; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 512K
FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 1024K
SDRAM (xrw)   : ORIGIN = 0xC00000000, LENGTH = 32M
}

/* Define output sections */
SECTIONS
{
  /* The startup code goes first into FLASH */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH

  /* The program code and other data goes into FLASH */
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH

  /* Constant data goes into FLASH */
  .rodata :
  {
    . = ALIGN(4);
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    . = ALIGN(4);
  } >FLASH

  .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
  .ARM : {
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
  } >FLASH

  .preinit_array     :
  {
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
  } >FLASH
  .init_array :
  {
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
  } >FLASH
  .fini_array :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
  } >FLASH

  /* used by the startup to initialize data */
  _sidata = LOADADDR(.data);

  /* Initialized data sections goes into RAM, load LMA copy after code */
  .data :
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */

    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
  } >RAM AT> FLASH


  /* Uninitialized data section */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss secion */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM

        /* --- begin generated external memory sections -- */
  _sidata = LOADADDR(.data);
        . = _sidata + SIZEOF(.data);
        . = ALIGN(4);
        _sisdram_text = .;

        .sdram_text : AT(_sisdram_text)
        {
                . = ALIGN(4);
                _ssdram_text = .;

                PROVIDE(__sdram_text_start = _ssdram_text);
                *(.sdram_text)
                *(.sdram_text*)
                . = ALIGN(4);
                _esdram_text = .;

                PROVIDE(__sdram_text_end = _esdram_text);
        } > SDRAM

        . = _sisdram_text + SIZEOF(.sdram_text);
        . = ALIGN(4);
        _sisdram_data = .;

        .sdram_data : AT(_sisdram_data)
        {
                . = ALIGN(4);
                _ssdram_data = .;

                PROVIDE(__sdram_data_start = _ssdram_data);
                *(.sdram_data)
                *(.sdram_data*)
                . = ALIGN(4);
                _esdram_data = .;

                PROVIDE(__sdram_data_end = _esdram_data);
        } > SDRAM

        .sdram_bss (NOLOAD) :
        {
                . = ALIGN(4);
                _ssdram_bss = .;

                PROVIDE(__sdram_bss_start = _ssdram_bss);
                *(.sdram_bss)
                *(.sdram_bss*)
                *(.LTDC)
                *(.DCMI)
                *(.mem2base)
                *(.mem2mapbase)

                . = ALIGN(4);
                _esdram_bss = .;

                PROVIDE(__sdram_bss_end = _esdram_bss);
        } > SDRAM

        /* --- end generated external memory sections -- */

  /* User_heap_stack section, used to check that there is enough RAM left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
  } >RAM



  /* Remove information from the standard libraries */
  /DISCARD/ :
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }

  .ARM.attributes 0 : { *(.ARM.attributes) }


}



回复

使用道具 举报

3

主题

1907

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
4106
金钱
4106
注册时间
2018-8-14
在线时间
696 小时
发表于 2018-9-11 21:17:21 | 显示全部楼层
之前因编译器升到6.0, 也出现同样的问题, 据说明书说是改了格式, 按着说明书的改就行了
不想改可以选择用5.0编译就不会出错了
回复

使用道具 举报

1

主题

7

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2018-9-11
在线时间
5 小时
 楼主| 发表于 2018-9-12 09:14:06 | 显示全部楼层
arm-none-eabi-gcc -v

gcc version 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496] (GNU Tools for ARM Embedded Processors)

请问怎么修改?
回复

使用道具 举报

1

主题

7

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2018-9-11
在线时间
5 小时
 楼主| 发表于 2018-9-12 09:14:29 | 显示全部楼层
edmund1234 发表于 2018-9-11 21:17
之前因编译器升到6.0, 也出现同样的问题, 据说明书说是改了格式, 按着说明书的改就行了
不想改可以选择 ...

arm-none-eabi-gcc -v

gcc version 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496] (GNU Tools for ARM Embedded Processors)

请问怎么修改?
回复

使用道具 举报

18

主题

422

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1139
金钱
1139
注册时间
2014-5-24
在线时间
116 小时
发表于 2018-9-12 15:15:42 | 显示全部楼层
本帖最后由 emWin 于 2018-9-12 15:19 编辑

类似问题可查阅,GNU Linker Manual:
[mw_shl_code=c,true]Figure 11. Assigning an object to a named memory section.
int x __attribute__((section("section_name")));[/mw_shl_code]

An Introduction to the GNU Compiler and Linker.pdf (116.55 KB, 下载次数: 128)
I See Fire.·.·.·.·.·.·.·.·.·.·.·.·.·.·.·.·.·.·.·.  只给方向,不妨碍思考
回复

使用道具 举报

0

主题

1

帖子

0

精华

新手入门

积分
2
金钱
2
注册时间
2018-10-28
在线时间
0 小时
发表于 2018-10-28 23:29:14 | 显示全部楼层
完全没必要用__attribute__ at的,而且这样的代码缺乏移植性(虽然可能也不需要考虑移植性);
按照C语言的标准语法,数组名基本等同于指针,所以你这0x68000000直接强转为指针类型就行了,比如
char *pArray = (char*)0x68000000;
pArray就可以当做你需要的大数组来用了;这样的定义不会有任何问题,只要按正常流程初始化SDRAM之后再使用即可。

如果你定义是二维数组,则需要指定“每行”有几个元素,例如你本来要定义一个二维数组char array[5][6],那么可以这样写:
char (*pArray)[6] = (char(*)[6])0x68000000;
编译器只需要知道每行有6个就行了,像pArray[1][2]这样使用的时候,编译器就可以正确地偏移地址了;但有多少行就不管了,和一维数组同理,数组越界的风险需要程序员自己规避。
三维或多维数组以此类推。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-8 14:32

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表