cancel
Showing results for 
Search instead for 
Did you mean: 

Write FLASH from RAM

smartpocket
Associate II
Posted on January 01, 2008 at 16:58

Write FLASH from RAM

12 REPLIES 12
smartpocket
Associate II
Posted on December 03, 2004 at 05:04

Hi to all

I have a problem whit writing in to flash.

My code is in flash (Sector B0F0 to B0F4).

All the routines for wrtiting in flash is executed from RAM (flash.o execution is mapped at address 0x20000000 in scat file).

I write the sector B0F5 to B0F7.

When i execute step by step the code work fine, but in normal run mode the micro stop at undefined address.

The problem is probably the 0x6E000010 code returned from an access to flash during writing flash operation . . .

(??? if an interrupt is activated ? the fw tries to access the flash???)

FOr example this is ERASE FLASH routine:

void FLASH_EraseSector(dword Xsectors)

{

volatile dword temp;

WaitForLastTask(FLASH_BANK0);

WaitForLastTask(FLASH_BANK1);

FLASHR->FCR0 |= FLASH_SER_Mask;

FLASHR->FCR1 |= Xsectors;

FLASHR->FCR0 |= FLASH_WMS_Mask;

// while ((FLASHR->FCR0 & 0x6) != 0);

// while (((FLASHR->FCR0 & FLASH_SER_Mask) != 0) |

// ((FLASHR->FCR0 & 0x06) != 0));

do

{

temp = FLASHR->FCR0 & 0x00000006;

}

while(temp != 0);

}

Can anyone help me ?

smart

anis2
Associate II
Posted on December 03, 2004 at 05:49

Hi smart,

I think that you have forgotten the bit LOCK of the register FLASHR_FCR0.

This status bit is very important because we can not access to any register if this bit is set to 1, so just add this line of code after anny access to or from the FLASH:

while(FLASHR_FCR0 & 0x16);

This line of code should replace the following code:

do

{

temp = FLASHR->FCR0 & 0x00000006;

}

while(temp != 0);

Regards,

Bouha

smartpocket
Associate II
Posted on December 03, 2004 at 06:22

Hi Bouha,

i have already test this solution . . . but it NOT work: also now the micro stop at undefine address if run normaly and it work fine only if i execute step by step !!

tnks for your help

smart

anis2
Associate II
Posted on December 03, 2004 at 06:52

Hi smart,

Please add the to the flash.o (in scatter file) the program which call the flash routines, because this program must be also excuted from RAM.

Rgds,

Bouha

smartpocket
Associate II
Posted on December 03, 2004 at 07:36

Hi Bouha,

i have moved all the calling routines in RAM but

. . . it not work . . .

the debugger stop and return ''Stopped due to unknown reasons - Stopped at 0x00000008: Line 195 '' (=UndefinedHandler)

(note: i'm testing the EraseSector(..) routine...)

tnks

smart

anis2
Associate II
Posted on December 03, 2004 at 11:46

Hi smart,

In this time i think that i have the solution to your problem,

Please find attached an example which illustrates how to erase a sector then writes some data, this example is executed from the flash sector 0 then erase and write a data to sector 1.

This example work fine with my board :)

Rgds,

Bouha

________________

Attachments :

flash_example.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtTJ&d=%2Fa%2F0X0000000aQR%2FKpyYBuoOT.EP5ekOd4vpFfaDKhzxS3wEayU6BqeBTvI&asPdf=false
smartpocket
Associate II
Posted on December 03, 2004 at 12:03

Hi Bouha,

tnks for your code.

But it is possible execute from B0F0 and write to B0F1 ?

In my first tests i have writing data in B0F5 executing code from [B0F0..B0F2] . . . but from Reference Manual (pag. 46, Par. 2.4) i read that:

''... the write operation commands must be executed from the other bank or another memory...'' .

It is also possible to write a SECTOR executing code from another SECTOR of SAME bank ?

Thanks !!

smart

PS - now I try your suggestions

:)

anis2
Associate II
Posted on December 03, 2004 at 12:15

Hi smart,

No, we can not execute code from a SECTOR and write to another SECTOR, but we can do this by executing the code from RAM using the scatter file .

Rgds,

Bouha

smartpocket
Associate II
Posted on December 06, 2004 at 04:18

Hi RISC,

OK, it is clear. . .

This is the structure of my application:

- B0F0 to B0F4 - Code of application (USB included)

- Address 0x20000000 (RAM) : routines for writing in FLASH (B0F5-B0F7)

- RAM +0 : other variables

(scat file attached)

In this situation, when i execute step by step the call to the flash routines work fine, but in normal running the micro stop at undefined address.

NOTE - Memory map

[....]

Execution Region FLASH_RW (Base: 0x20000000, Size: 0x000008ac, Max: 0xffffffff, ABSOLUTE)

Base Addr Size Type Attr Idx E Section Name Object

0x20000000 0x00000874 Code RO 350 .text flash.o

0x20000874 0x00000028 Code RO 351 i.FLASH_EraseBank flash.o

0x2000089c 0x00000010 Code RO 352 i.ResetBit flash.o

[....]

Can you help me ?