cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WLE5XX Flash write

HDaou
Associate

I am using an STM32WLE5 in a design, in the user manual section 3.3.8 it specifically says:

Programming in a previously programmed double-word is only allowed when programming an all 0 value. It is not allowed to program any other value in a previously programmed double-word. Any attempt sets PROGERR flag in FLASH_SR, except when programming an already programmed double-word with an all 0 value.

In practice this is not working, I noticed the MCU differentiates between "virgin" all FF double word which is the erase state and a programmed all FF double word. I believe this is related to ECC but I would like to get more information about this if possible.

Below is a small code snippet that illustrates the test I am running:

    uint8_t *addr = (uint8_t *) 0x08000800;
    uint8_t zeroes[8] = {0};
    uint8_t effs[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};
 
    hal_flash_page_erase(addr);                                  //Page erase to all FFs as expected
    flash_write_dw(addr, effs);                                     //Manually programming 1st dw as effs
    flash_write_dw(addr+8, effs);                                 //Manually programming 2nd dw as effs
    flash_write_dw(addr+16, effs);                               //Manually programming  3rd dw as effs
    flash_write_dw(addr+24, effs);                               //Manually programming 4th dw as effs
 
    flash_write_dw(addr, zeroes);            //Reprogram 1st dw as zeros, does not work
    flash_write_dw(addr+8, zeroes);       //Reprogram 2nd dw as zeros, does not work
    flash_write_dw(addr+16, zeroes);     //Reprogram 3rd dw as zeros, does not work
    flash_write_dw(addr+24, zeroes);     //Reprogram 4th dw as zeros, does not work
    flash_write_dw(addr+32, zeroes);     //Reprogram 5th dw as zeros, WORKS DW still erased
    flash_write_dw(addr+40, zeroes);     //Reprogram 6th dw as zeros, WORKS DW still erased

1 REPLY 1
HDaou
Associate

I did more tests on this and if the starting condition is not all FFs for example FEs, then the programming works as expected. Which is counter intuitive.

Changing the effs array as following makes the logic works uint8_t effs[8] = {0xFE 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};

Can someone shed some light as to what is the main reason behind this ?