constant data in flash does not increase application size

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

constant data in flash does not increase application size

1,381 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by askar on Mon Aug 04 04:02:56 MST 2014
I am using LPCXpresso version 7.30 for developing application for LPC4357.
in m4 application I want to define a buffer of data that must be located in internal flash
I defined the buffer as below:

__RODATA(Flash) const char data[]  =
{
  //filled with about 1000 bytes of data.
};

after compiling the project, the binary size of output file is not affected with above definition
and remained as before.
is there any problem for above item?


0 项奖励
回复
7 回复数

1,345 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by askar on Wed Aug 06 05:17:09 MST 2014
Many thanks for every body helped me to solve the problem,

I were using the constant item inside a function that was not exported out of
that function, now when I use it as a reference variable in a function
all things become ok.

all of below worked for me:
const char x123[] = {  /*data*/ };
static const char x123[] = {  /*data*/ };
__RODATA(MFFlashA512) const char x123[] = {  /*data*/ };


Best Regards,
0 项奖励
回复

1,345 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Wed Aug 06 00:43:46 MST 2014
The linker will discard unused code and data - this includes items that are indirectly reference by something that is discarded. You can see what has been discarded by reading the .map file.

Please post your code, or post an example, that demonstrates your problem, and we will tell you what you are doing wrong.

0 项奖励
回复

1,345 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Wed Aug 06 00:11:42 MST 2014

Quote: askar

I defined the buffer as below:

__RODATA(Flash) const char data[]  =
{
  //filled with about 1000 bytes of data.
};

after compiling the project, the binary size of output file is not affected with above definition
and remained as before.
is there any problem for above item?



You do realise that assuming you are using the default memory configuration, all you have done here is put the constant data item into the flash bank that it will be placed in by default?

If you are still having issues, then I would suggest that you actually try posting a test project for us to look at, or at least your map file and a snippet of code showing your definition and use of your constant.

Note that if your constant really isn't being used, then it ought to be shown as being discarded in the linker map file.

HTH!
0 项奖励
回复

1,345 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by askar on Tue Aug 05 20:13:16 MST 2014
Hi OldManVimes,

Thank you for your reply,
the "Flash" and definitions such as "MFlashA512" are defined in project.
also using "static" before "const" has no difference.
I checked the map file and there is some strange items there.
some of the constant items defined simply with "const char x[] = {/*some array elements*/ };" are
located in flash bankA but some does not.
I defined another constant item in the source file that the above constant was defined
but in map file, the new item was not placed anywhere.
I have used the item in application.

Best Regards
0 项奖励
回复

1,345 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by askar on Tue Aug 05 20:05:15 MST 2014

Hi lpcxpresso-support,

Thank you very much for your reply,

yes I am using and referencing the constant item.
0 项奖励
回复

1,345 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Aug 04 06:05:55 MST 2014
Are you referencing/using 'data'? If not, the linker will discard it as being unused.
0 项奖励
回复

1,345 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldManVimes on Mon Aug 04 05:04:05 MST 2014
I currently do not have access to an instance of LPCXpresso, so I'm commenting of the top of my head.

Possible issue:
The 'linker section' named "Flash" does not exist. Therefore the linker will not  include the array in the binary. If you use managed linker scripts, then look at the device specific settings in the project settings.

Tip: If you generate a .map file after linking, then you can check the location for the array in the image. This is a very useful tool and .map files are easy to read.

Alternative coding style:
static const char data[] = { /* data */ };

The 'static' is probably optional, but useful. The point is that making an array 'const' will ensure it is placed in the .rodata section by the linker. So if you have no requirement for a specific location within flash memory, then there is no need for the section specifier.

For shits and giggles:
static char data[] = { /* non zero data */ };

What happens now is that the linker places the array in the .data section. It still gets added to flash, but the start-up code will copy it from flash to RAM. That last step is not done when data is const.

Hope this helps and that I haven't provided any false information (since I am unable to fact check this post at the moment).

0 项奖励
回复