Placing an Array in Flash

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaSi_281136
Level 3
Level 3
25 replies posted 10 replies posted 5 replies posted

I ran out of SRAM in my application and so I have 4000 bytes of data that I'd like to store in Flash as an array.
I tried 'const int8 pgm[4000] = {0x4c, ....};'

   

However when I build the project the Output window shows that it was stored as SRAM.

   

Thanks.

0 Likes
9 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Was the definition made within a function (main() is a function,too) or was it declared globally?

   

const only works globally or with static class.

   

 

   

Bob

0 Likes
DaSi_281136
Level 3
Level 3
25 replies posted 10 replies posted 5 replies posted
        It was declared globally.   
0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

This might help -

   

 

   

I would have liked to see a different solution like a "flash" qualifier, but GCC developers have choosen a different solution. Now the "const" qualifier has two different meanings depending on the context it appears.

   

Used in a parameter-list the consequences are: the parameter will not be modified by a direct assignment.

   

Used in a variable declaration and followed by an initialization the variable will be put into the code area which will be flash memory in all embeddeds.

   

This improvement is not ARM specific but works in GCC generally.

   

http://www.keil.com/support/docs/2829.htm     Abs variable location Keil and ARM GCC

   

 

   

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CCYQFjABahUKEwikpM2wrf7GAhVJmIA...

   

 

   

Regards, Dana.

0 Likes
Rolf_Nooteboom
Level 5
Level 5
10 sign-ins 5 solutions authored First solution authored

First define your structure / array:

   
     typedef SettingsStruct {   
   
         unsigned char Setting1;   
   
         unsigned char Setting2;   
   
     }   
   

 

   

For Keil:

   
     const    SettingsStruct code Settings = {0x00, 0x01};   
   

 

   

And for GCC: 

   
     volatile    SettingsStruct         Settings      __attribute__ ((section (".FlashData")));   
   

 

   

And use this define in the Linker's Custom Flags (Project > Build Settings > ARM... > Command Line)

   
     -Wl,--section-start=.FlashData=0x00010000   
   
        
   

Regards,

   

Rolf

DaSi_281136
Level 3
Level 3
25 replies posted 10 replies posted 5 replies posted
        I'll try that when I get back to my workstation. Thanks!   
0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

How do you prove that the table is not in flash? In my example project it clearly works.

   

 

   

Bob

0 Likes
DaSi_281136
Level 3
Level 3
25 replies posted 10 replies posted 5 replies posted

I took a second look and Bob was right. I should have paid closer attention 😞
However, when I tried to use an EM_EEPROM I couldn't get it to work.
The example project seems to be for PSOC3 and the data sheet is rather anemic.
 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Please post your Em_EEPROM project to let us have a look on. Remember Em_EEPROM is not supported for PSoC4 BLE!

   

Btw: When you right click on the component select "Find Example Project", select PSoC4 4200 you will get a project for your selected device. Defining a variable to be in the EEProm area is not quite easy and mya vary from compiler to compiler. More universal is to define a structure and a pointer to it, then assign the begin of the EEProm area to the pointer.

   

 

   

Bob

0 Likes

I'm using a PSOC5lp.
I blew away the project and can't remember exactly what I was doing.
When I get a chance I'll try it again and find an example for the 5lp.

0 Likes