cancel
Showing results for 
Search instead for 
Did you mean: 

Define an array in Flash

nanayakkaraan
Associate II
Posted on February 28, 2011 at 12:16

Define an array in Flash

16 REPLIES 16
domen23
Associate II
Posted on May 17, 2011 at 14:26

Just mark it const.

Posted on May 17, 2011 at 14:26

int *array = (int *)0x08008000;

It's just memory like anything else for reading. For writing the cell[s] you want to use must be blank/erased, and there is a programming sequence. C is not intrinsically going to be able to write to the memory as it would with RAM, you will need to code routines to do this.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hanser
Associate II
Posted on May 17, 2011 at 14:26

If the question was, how to allocate memory in flash, there is an application note for this:

AN2594

ColdWeather
Senior
Posted on May 17, 2011 at 14:26

As Domen Puncer wrote, a const tag before an array declaration forces the compiler/linker to place the array in flash:

const char Message[] = ''Hello, World'';

Anywhere in the flash of your STM32Fxxx device (address beginning from 0x8000000) the string above will be placed.

It means at the same time, the array cannot be changes at runtime (no assignments allowed). If you do wanna do this, you have to implement the flash modification routines as it's described in application notes.

Andrew Neil
Evangelist
Posted on May 17, 2011 at 14:26

''a const tag before an array declaration forces (sic) the compiler/linker to place the array in flash''

No, it does not force  it - but the compiler may decide that this allows  it to do so.

Different compilers may decide differently...
nanayakkaraan
Associate II
Posted on May 17, 2011 at 14:26

Hello bap68,

I want to download the application note you are talking about.

Just searching An 2594 did not support me.

can you give little bit of more information on that.

Thanks,

John F.
Senior
greg_t
Associate II
Posted on May 17, 2011 at 14:26

#define ADDRESS    ((uint16_t*)0x0801F800)

uint16_t*     Address    =   ADDRESS;   //it places var Address at flash address 0x0801F800

Andrew Neil
Evangelist
Posted on May 17, 2011 at 14:26

''uint16_t*     Address    =   ADDRESS;   //it places var Address at flash address 0x0801F800''

 

No, it does

not

!

'Address' here is a pointer that is being initialised to point to an address in flash.