Howto saving Data in Flash in Cortex M3/M4

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

hoppel
Posts: 3
Joined: Wed Apr 18, 2012 9:09 am

Howto saving Data in Flash in Cortex M3/M4

Postby hoppel » Mon Apr 23, 2012 4:46 pm

Hello,

today, i have a question about the flash. We had a project, where we can save data into flash, using it like an eeprom.
Therefor we had a linkerscript.
Here is the beginning code:

Code: Select all

ENTRY(Reset_Handler)

MEMORY {
   RAM      (RWX) : ORIGIN = 0x20000000     , LENGTH = 20K
   EXTSRAM  (RWX) : ORIGIN = 0x68000000     , LENGTH = 0
   FLASH    (RX)  : ORIGIN = 0x08000000     , LENGTH = 126K /* adjust to Device -- Flash Size -2k*/
   EEMUL    (RWX) : ORIGIN = 0x08000000+510K, LENGTH = 2K
}

_estack         = ORIGIN(RAM)+LENGTH(RAM);      /* end of the stack */
_seemul         = ORIGIN(EEMUL);                /* start of the eeprom emulation area */
_min_stack      = 0x100;                        /* minimum stack space to reserve for the user app */


We found that script in www, it works fine. But i have no experience about that script language.
Now we switched to use Chibios, because we likes the idea behind a RT.
So my Question is, how i have to change the Chibios Linker scripts to use the flash for storage.

Regards,
Andre

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Howto saving Data in Flash in Cortex M3/M4

Postby Giovanni » Mon Apr 23, 2012 6:38 pm

Hi Andre,

The linker script in ChibiOS is very similar, you have to reserve some flash space for the EEPROM emulator, something like:

Code: Select all

MEMORY
{
    flash : org = 0x08000000, len = 112K
    EEMUL: org = 0x08000000 + 112K, len = 16K
    ram : org = 0x20000000, len = 20k
}


I think it would work like in your example.

Giovanni

hoppel
Posts: 3
Joined: Wed Apr 18, 2012 9:09 am

Re: Howto saving Data in Flash in Cortex M3/M4

Postby hoppel » Mon Apr 23, 2012 9:14 pm

Ok, thank you. I will test it.

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: Howto saving Data in Flash in Cortex M3/M4

Postby alex31 » Tue Jul 17, 2012 10:13 pm

On 1024k flash device, the pages at beginning of address space are 16Ko long and can be erased in relatively short time.

the pages at the end of address space are 128ko long and can take 1 second to be erased, so if i want to use a 16ko page, is it possible
to reserve page 0 for EEPROM emulator, then put the program on page 1 and subsequent ?

Thanks
Alexandre

User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Location: Minsk, Belarus
Been thanked: 7 times

Re: Howto saving Data in Flash in Cortex M3/M4

Postby barthess » Wed Jul 18, 2012 6:53 am

Yes, it is possible. But in 0 sector you must place bootloader loading your program from proper sector.
EEMUL must reside in 1st (or any not 0th) sector.
Here you can find some discussion viewtopic.php?f=2&t=229

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: Howto saving Data in Flash in Cortex M3/M4

Postby alex31 » Wed Jul 18, 2012 9:57 am

Thanks for pointing this thread.

Did you resolve all the problem mentioned in the thread to make your program began at an offseted address ?

Alexandre

User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Location: Minsk, Belarus
Been thanked: 7 times

Re: Howto saving Data in Flash in Cortex M3/M4

Postby barthess » Wed Jul 18, 2012 11:14 am

Sure.

jeremie.delaitre
Posts: 26
Joined: Fri Oct 05, 2012 3:16 pm
Been thanked: 1 time

Re: Howto saving Data in Flash in Cortex M3/M4

Postby jeremie.delaitre » Fri Nov 09, 2012 5:34 pm

Hi,

I'm trying to save data (app settings) in flash too on the STM32P407 board.
I've changed my linker script with:

Code: Select all

MEMORY
{
    flash : org = 0x08000000, len = 500k
    persistentdata : org = 0x08000000 + 500k, len = 128k
    ram : org = 0x20000000, len = 112k
    ethram : org = 0x2001C000, len = 16k
    ccmram : org = 0x10000000, len = 64k
}

...

SECTIONS
{
...
    .persistentdata :
    {
        *(.persistentdata)
        KEEP(*(.persistentdata))
    } > persistentdata
...


Then, I've declared some variable with:

Code: Select all

__attribute__ ((section (".persistentdata")))
__IO uint32_t persistentValue;
__attribute__ ((section (".persistentdata")))
__IO uint32_t persistentValue2;


Everything compile as expected but when print persistentValue, then change its value and reprint it, I always got 0.

Do you have any hint?

I've read on the Internet that I should maybe erase the NAND page/sector before writing the new value (like when I flash my program with openocd) but how can I do that?

Saving app settings in flash seems to be a quiet common requirement so I'm wondering if it makes sense to have some helper in ChibiOS to do that?

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: Howto saving Data in Flash in Cortex M3/M4

Postby mabl » Fri Nov 09, 2012 6:06 pm

I've not much time now. But for writing flash pages, I've once hacked this together:
https://github.com/mabl/ARMCM3-STM32F10 ... ADER/flash

jeremie.delaitre
Posts: 26
Joined: Fri Oct 05, 2012 3:16 pm
Been thanked: 1 time

Re: Howto saving Data in Flash in Cortex M3/M4

Postby jeremie.delaitre » Mon Nov 12, 2012 10:20 am

Awesome! I'll give it a try when time permits (probably next week).


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 8 guests