什么是一个结构放到闪存的最通用的方法(微控制器) [英] What is the most general approach to place a structure into the flash (microcontrollers)

查看:77
本文介绍了什么是一个结构放到闪存的最通用的方法(微控制器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GCC ARM的V-4.8.3工具链的嵌入式C项目。
我有仅在整个程序的生命周期读取查表结构的阵列。因为我运行的RAM(并有充足的Flash未利用地)是更好的主意,他们推入闪光灯,这将不会影响程序的功能。问题是如何。

I am working on an embedded C project using GCC for ARM V-4.8.3 toolchain. I have an array of look-up structures that are read only during the life cycle of the entire program. Since I am running out of RAM (and have plenty of Flash unused) it is better idea to push them into the flash, which will not affect the function of the program. The problem is how.

这样做的一个方法是使用变量__attribute__((节(TEXT)))通过GCC提供。在这种情况下我的code是编译器相关的。如果我想使用Microchip的编译器,例如用我的code我需要编辑code移植到新的环境。

One way to do so is using the variable __attribute__ ((section ("TEXT"))) provided by GCC. In this case my code is compiler dependent. If I want to use my code using Microchip compiler for instance I need to edit the code to port to the new environment.

来我的脑海里正在使用的链接脚本的另一种方法。该结构只是声明到code。

The other way coming to my mind is using the linker script. The structure is only declared into the code.

在我看来,第二个方法是更加便携一些。尽管仍然需要调整连接器脚本,对我来说这是好。是否有更多的一般方法将使code更便携为把变量到闪存的背景?

It seems to me that the second approach is a bit more portable. Although it is still needed to adjust the linker script, to me it is better. Is there more general approach that would make the code more portable into the context of placing variables into the flash?

排位赛他们作为一个常量,意味着它们将被放置到 rodata 部分。没有到文本部分,在那里,他们属于

Qualifying them as a constant, means that they will be placed into rodata section. Not into the text section where they "belong".

推荐答案

如果不要紧的其中的在他们最终闪光灯,只需声明结构作为静常量应足以和100%的便携性。

If it doesn't matter where in the flash they end up, simply declaring the struct as static const should be sufficient and 100% portable.

__ __属性,当你需要在一个特定的地址分配的东西应该只需要其他非标准的东西。

__attribute__ and other non-standard things should only be needed when you need to allocate something at a specific address.

这篇关于什么是一个结构放到闪存的最通用的方法(微控制器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆