Skip to main content
nanayakkaraan
Associate III
February 28, 2011
Question

Define an array in Flash

  • February 28, 2011
  • 16 replies
  • 3868 views
Posted on February 28, 2011 at 12:16

Define an array in Flash

    This topic has been closed for replies.

    16 replies

    Tesla DeLorean
    Guru
    May 17, 2011
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    domen23
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 14:26

    Just mark it const.

    ColdWeather
    Senior
    May 17, 2011
    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.

    hanser
    Associate
    May 17, 2011
    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

    John F.
    Associate III
    May 17, 2011
    nanayakkaraan
    Associate III
    May 17, 2011
    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,

    Andrew Neil
    Super User
    May 17, 2011
    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...
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Andrew Neil
    Super User
    May 17, 2011
    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.

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    greg_t
    Associate III
    May 17, 2011
    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

    greg_t
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:26

    Any var is just a pointer to memory

    Array in RAM is a pointer

    If pointer points to flash memory address  -  the compiler will not create the ASM code that writes to flash