cancel
Showing results for 
Search instead for 
Did you mean: 

Overwriting written flash memory with 0xFFFFFFFF on STM32L

mlakata
Associate II
Posted on August 27, 2013 at 20:48

I need a reliably method of overwriting flash memory on a STM32L device (STM32L152CB). On the other STM32F series, this was easy, as I could write zeros on top of previously written flash memory contents reliably. The STM32L seems to have inverted their flash memory polarity, so it is erased to 0x00000000 instead of 0xFFFFFFFF. No biggie, but I can't seem to reliably overwrite my previously written data with 0xFFFFFFFF.

Here is some code I have used for testing

    {

     uint32_t pattern = 0x04030201;

     FlashErasePage(0x0801E000,FLASH_PASSWORD);

     for(int j=0;j<64;j++) {

        FlashWriteArray(0x0801E000 + 4*j,(uint8_t*)&pattern,4);

        pattern += 0x04040404;

     }

     

     for(int j=0;j<64;j++) {

&sharpif 1

         uint32_t pattern = 0xFFFFFFFF;

         FlashWriteArray(0x0801E000 + 4*j,(uint8_t*)&pattern,4);

&sharpelse

         uint32_t pattern = 0x01010101;

         for(int i=0;i<8;i++) {

            FlashWriteArray(0x0801E000 + 4*j,(uint8_t*)&pattern,4);

            pattern <<=1;

         }

&sharpendif

and here is the result of the memory after ''overwriting'' with FFs:

ff ff ff bf ff ff ff ff ff ff ff ff ff ff ff fb f7 ff ff ff fd ff ff ff ff ff ff f7 ff ff ff ff fe ff ff ff ff ff ff ff ff ff ff 7f f7 ff ff ff ff ff ff fb ff ff ff ef ff ff ff ff ff ff ff df fe ff ff ff ff ff ff ff ff ff ff 7f f7 ff ff ff ff ff ff fb ff ff ff ef ff ff ff ff ff ff ff ff ff ff ff bf ff ff ff ff ff ff ff ff ff ff ff fb f7 ff ff ff fd ff ff ff ff ff ff f7 ff ff ff df f7 ff ff ff fd ff ff ff ff ff ff f7 fe ff ff ff ff ff ff bf ff ff ff ff ff ff ff ff fd ff ff ff ff ff ff fb ff ff ff ef ff ff ff ff ff ff ff bf fe ff ff ff ff ff ff ff ff ff ff 7f fb ff ff ff ff ff ff fb ff ff ff ef ff ff ff ff ff ff ff bf fe ff ff ff ff ff ff ff ff ff ff 7f ff ff ff ef f7 ff ff ff fd ff ff ff ff ff ff f7 fe ff ff ff ff ff ff bf ff ff ff ff ff ff ff ff fb ff ff ff

A you can see, it is not all ''ff'' but a random mix of single bit failures.

I experimented with writing patterns such as a shifting bit pattern, and this seems to work better, but I don't know if this is the right thing to do. As the shifting bit pattern is being written, I can see all sorts of weird behaviour in the flash memory. It does seem to finally end up as all FF in this example, but it seems to be by accident.

#stm32l #flash
10 REPLIES 10
emalund
Associate III
Posted on August 29, 2013 at 16:07

if unused = 0xff how are ypo going to use the slot?, you can't write to a slot that is set to the opposite of erase.

as to the missing bit: TIMING