cancel
Showing results for 
Search instead for 
Did you mean: 

F4 Flash Write - random or sequential?

martinmartin9129
Associate II
Posted on July 11, 2013 at 15:19

Hello,

is F4 Flash write can be random or only sequential? I've tryed to do

FLASH_Unlock();
FLASH_EraseSector(FLASH_Sector_8, VoltageRange_3);
for(i=0, EEAddr=EEA;i<32;i++){
FLASH_ProgramWord(EEAddr, ParArray[i]);
EEAddr+=4;
}
FLASH_Lock();

and all works fine, but when I try to do this:

FLASH_Unlock();
FLASH_EraseSector(FLASH_Sector_8, VoltageRange_3);
for(i=1, EEAddr=EEA+4;i<32;i++){
FLASH_ProgramWord(EEAddr, ParArray[i]);
EEAddr+=4;
}
FLASH_ProgramWord(EEA, ParArray[0]);
FLASH_Lock();

the 1st word, that I've tried to write at the end, does not writes. 1st 4 bytes are still ''FF''. So, write to flash should be sequential?
10 REPLIES 10
alexandr
Associate II
Posted on July 12, 2013 at 17:29

Nobody knows?

Posted on July 12, 2013 at 17:53

Nobody knows?

Why do people say this in forums, honestly it's like yelling into a vacuum. In space no one can hear you scream.

As far as my experience goes you can write flash in a sparse/random fashion, providing the location you're writing is blank. There may be additional impediments wrt to the bit width of the flash lines, which I suppose are 64 or 128 bits here.

Experiment, that's what I'd have to do to confirm either way.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alexandr
Associate II
Posted on July 12, 2013 at 18:00

>As far as my experience goes you can write flash in a sparse/random fashion, providing the location you're writing is blank.

So, why the second code does not works?

I making the Firmware Upgrade, and I wish to write all code, except the 1st aplication's word - the starting word of the Vector Table, that Bootloader check before jump to application.

And only in case of susscessfuly writing of application - to program the 1st word.

But, this word remains 0xFFFFFFFF.

The same thing in a parameters section of flash (this code was shown) - I want to program at first the words from [1] to [31], and only after this - [0].

Not works.

From [0]to[31] - works.

emalund
Associate III
Posted on July 12, 2013 at 22:30

just a note, the files generated by Keil for flash load are NOT sequential.

Erik
emalund
Associate III
Posted on July 12, 2013 at 22:34

stupid website decalres error even when post posted

Erik
Posted on July 13, 2013 at 00:18

So, why the second code does not works?

I'm not convinced it fails, it's working for me, I think you're doing something else wrong. Do the write or erase signal a failure?

void FlashBackward(void)
{
int i;
unsigned long EEA = 0x08080000;
unsigned long EEAddr;
static unsigned long ParArray[32] = {
0x00010203,0x04050607,0x08090A0B,0x0C0D0E0F,
0x10010203,0x14050607,0x18090A0B,0x1C0D0E0F,
0x20010203,0x24050607,0x28090A0B,0x2C0D0E0F,
0x30010203,0x34050607,0x38090A0B,0x3C0D0E0F,
0x40010203,0x44050607,0x48090A0B,0x4C0D0E0F,
0x50010203,0x54050607,0x58090A0B,0x5C0D0E0F,
0x60010203,0x64050607,0x68090A0B,0x6C0D0E0F,
0x70010203,0x74050607,0x78090A0B,0x7C0D0E0F };
FLASH_Unlock();
FLASH_EraseSector(FLASH_Sector_8, VoltageRange_3);
for(i=1, EEAddr=EEA+4; i<32; i++)
{
FLASH_ProgramWord(EEAddr, ParArray[i]);
EEAddr += 4;
}
FLASH_ProgramWord(EEA, ParArray[0]);
FLASH_Lock();
for(i=0; i<32; i++)
{
printf(''%08X '',*((unsigned long *)(EEA + 4 * i)) );
if ((i % 8) == 7)
putchar('
');
}
for(i=0; i<32; i++)
{
if (*((unsigned long *)(EEA + 4 * i)) != ParArray[i])
printf(''FAIL @ %2d
'', i);
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alexandr
Associate II
Posted on July 13, 2013 at 10:46

> the files generated by Keil for flash load are NOT sequential.

What does it means?!

>I'm not convinced it fails, it's working for me, I think you're doing something else wrong.

Very interesting! I show all the code, that not works!

Will try to check again.

> Do the write or erase signal a failure?

I didn''t checked.

Posted on July 13, 2013 at 12:55

> the files generated by Keil for flash load are NOT sequential.

 

What does it means?!

 

I'll let Erik confirm, but what I think he means is that things like HEX files do not have to have contiguous linear streams of data. They can be sparse (have gaps leaving 0xFF in the ROM, or whatever), and the records do not have to be in any particular order. Object files are often generated in this way because it's much easier for the LINKER to emit data in small blocks and in an interleaved manner. The two fold benefit being that it doesn't have to hold an entire memory image of the application, which has to be managed as it grows, and also it eliminates several passes over the data to get the placement order and sequencing done.

The point being that it's safer to assume HEX files are randomly ordered, than linear/sequential, and that if the flash failed under such conditions more people would have tripped over it.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
martinmartin9129
Associate II
Posted on July 14, 2013 at 09:40

I do not use .hex file to firmware upgrade, I use encripted .bin for firmware and nonencripted for ''eeprom''.