关于C语言【全局变量】与【全局常量】在STM32中储存方式的区别

2019-10-15 20:18发布

本人在使用 STM32液晶屏的时候,在工程里面 写入了一个 u16 a[]={这张图片的RGB565代码,1万个数据};
编译后 HEX文件有 88KB 1.png
后来 试着 在数组前面增加了一个 const修饰 , const u16 a[]={这张图片的RGB565代码,1万个数据};
编译后 HEX文件约200KB 2.png

3.png
4.png

搞不明白的是 这100多KB差别在哪里。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
22条回答
777ai77
1楼-- · 2019-10-18 14:19
zc123 发表于 2016-12-28 16:38
在no const里面,最后面的RW数据明显被优化掉了,
==================================================== ...

确实调用到了,已经附上源程序代码,删掉了一些不需要的函数。 在interface.c内部调用到 这个数组。分const和no_const两个程序,均已实物测试可以在LCD屏幕上 显示图片。 程序源码.zip (5.21 MB, 下载次数: 119) 2016-12-28 19:15 上传 点击文件名下载附件
777ai77
2楼-- · 2019-10-18 16:09
jinggx 发表于 2016-12-28 12:52
有const编译后放在RO-data中,无const编译后放在RW-data中,两种情况烧录在芯片中所占的FLASH大小几乎相等 ...

我按16楼的方法生成了bin文件,确实 有const的 bin文件72KB, 无const 的bin文件 32KB。 已经在实物上测试过,均可以显示正常显示出图片。 源码已经上传到19楼了。
jinggx
3楼-- · 2019-10-18 16:20
 精彩回答 2  元偷偷看……
777ai77
4楼-- · 2019-10-18 19:33
jinggx 发表于 2016-12-29 16:13
把 u16改成u32 类型可能结果就一样大小了,我没有试,你可以去试一下。

原因:据我分析,stm32的FLASH ...

无const改成 u32  build不通过。 空间不够了
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching interface.o(.data).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching startup_stm32f10x_hd.o(STACK).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching startup_stm32f10x_hd.o(HEAP).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching usart.o(.bss).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching libspace.o(.bss).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching touch.o(.data).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching system_stm32f10x.o(.data).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching stm32f10x_rcc.o(.data).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching lcd.o(.bss).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching usart.o(.data).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching lcd.o(.data).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching delay.o(.data).
..OBJTOUCH.axf: Error: L6406E: No space in execution regions with .ANY selector matching ft5206.o(.data).
..OBJTOUCH.axf: Error: L6407E: Sections of aggregate size 0x1673c bytes could not fit into .ANY selector(s).
Not enough information to list image symbols.
Not enough information to list the image map.

一周热门 更多>