cancel
Showing results for 
Search instead for 
Did you mean: 

FLASH. How to start ?

amoreno
Associate II
Posted on April 18, 2008 at 14:18

FLASH. How to start ?

4 REPLIES 4
amoreno
Associate II
Posted on April 18, 2008 at 06:09

Hi,

Trying to implement writing data on my own STR711 flash, it seems that doesn’t work properly for me.

I using examples available on ST website (str7xfpmsw.zip) and Workbench 5.1

Reading “readme.txt�, it says:

Important Note

==============

FLASH_WaitForLastOperation() function must be fetched from RAM since

The first Flash Erase/Program operation is started when the WMS bit is set

and after setting this bit, Bank 0 is no longer accessible.

This example should be executed from RAM, not from FLASH.

How should I execute first instruction from RAM ?? my whole program is on flash !.

I don’t know how to do it. Please show me a clear example.

Thank you for your time

Alfa.

jgoril
Associate II
Posted on April 18, 2008 at 07:49

Hello.

Firstly, your code in flash must copy the flash-treatment routines (+ return back to flash) somewhere into RAM. Then jump to that address in RAM and execute flash write/erase access (completely from RAM). Finally, jump back into flash and continue... :)

amoreno
Associate II
Posted on April 18, 2008 at 07:53

Hello Opijozko,

Thanks for your reply, but.... how? could you please show me an example?

how must I copy flash-treatment routines to RAM?

I'm a newbie in ARM and Workbench enviorement

Thanks for your help and time.

Alfa

jpeacock2
Associate II
Posted on April 18, 2008 at 14:18

Not sure about the STR71x but on STR75x only the very first flash command needs to be in RAM. Usually this is the command to the protection registers to make sure the target flash bank is unprotected for writes and erasures. After that the rest of the flash commands can run from the bank not being modified.

I map a small subroutine (to set the proection registers) into RAM using the __attribute keyword in GCC to assign the routine to a specific section. In the loader map I assign the section to initialized RAM, so that on startup the code is copied into RAM from flash. Finally, I use the GCC long call option when calling the RAM code, since it's not in the flash address range.

Code:

/*-----------------------------------------------------------------------------------*/

/**

* Unprotect Infomem flash segments.

*

* Write the flash bank 1 unprotect.

*

* This routine must execute from RAM since the first FLASH

* operation will disable bank 0 until WMS completes.

*/

FlagStatus __attribute__ ((section(''.rwcode''))) ifm_Bank(u32 FLASH_Sectors, FunctionalState FLASH_NewState)

{

FLASH->CR0 |= FLASH_SPR_MASK; /* change write protection */

FLASH->AR = FLASH_NVWPAR_ADDRESS & 0x001ffffc; /* Load protection reg address NVWPAR */

if(FLASH_NewState == DISABLE) FLASH->DR0 = 0xfffcff00 | FLASH_Sectors; /* disable bank protect */

else FLASH->DR0 = 0xfffcff00; /* enable protect all banks */

FLASH->CR0 |= FLASH_WMS_MASK; /* start unprotect operation, bank 0 offline */

while( FLASH->CR0 & FLASH_FLAG_LOCKBSY ) ;

return FLASH_GetWriteProtectionStatus(FLASH_Sectors); // return protect status

}

Part of the loader script:

/* This is the initialized data section

The program executes knowing that the data is in the RAM (at sidata)

but the loader puts the initial values in the FLASH.

It is a task of the startup to copy the initial values from FLASH to RAM. */

.data : AT ( _sidata )

{

. = ALIGN(4);

_sdata = . ; /* used by startup to init .data section */

*(.data) /* initialized RAM */

. = ALIGN(4);

*(.rwcode) /* RAM executable code */

. = ALIGN(4);

_edata = . ;

} >RAM

Everythign from .sdata to .edata is copied from flash to RAM by the C runtime startup.