Skip to main content
DMA
Associate
January 21, 2022
Solved

FlashErase/FlashProgram not working with any optimization level (-Os size/-O1 general/-O2 speed/-O3 fast) except -O0 none.

  • January 21, 2022
  • 10 replies
  • 3794 views

Hi, I am working on SPC58NG84E7 bootloader. I have Bootloader code(at 0x00FC0000) with which i am using "FlashErase" API to Erase Flash Memory block at 0x00FF0000 with "-Os size" Optimization But its not working. Also, I tried putting breakpoint to the next line after erase, but breakpoint does not hit. Looks like its stuck in the execution.

I tried all other optimizations as well but same result.

Also, without optimization (NONE(-O0)) its working fine. 

Same result is for "FlashProgram" API.

What could be the issue here?

Please help me resolve the issue.

    This topic has been closed for replies.
    Best answer by ODOUV.1

    Hello,

    your parameters are good.

    Would you please check it could be the same issue than this one :

    Flash Erase for SPC58NG84E7 is not working (st.com)

    Best Regards,

    -Olivier

    10 replies

    ODOUV.1
    ST Employee
    January 21, 2022
    Andrei Chichak
    Lead
    February 11, 2022

    Agreed, if your program works properly with -O0 and bombs with any other optimization, it sounds like your program has some variables that should be marked volatile.

    The optimizer is getting rid of code that does nothing useful (in its opinion), like repeatedly checking a flag. Why would you check a flag that never gets set? That's useless, get rid of that code.

    Or setting a variable that never gets read, that's useless, get rid of that code.

    Now if those variables happen to be device registers, they should be marked as volatile to tell the optimizer not to make assumptions about there being no behind the scenes activity.

    Values that are being shared between interrupts and mainline code, or between tasks should be declared _Atomic (C11). And if you're doing complex things, the values should be guarded with a mutex.

    DMA
    DMAAuthor
    Associate
    January 27, 2022

    Hi Oliver,

    Thanks for your reply. But that issue is different than what i am facing. It didn't work.

    I am getting unhandled exception.

    Any other suggestions??

    Thanks and Regards

    Deepesh

    ODOUV.1
    ST Employee
    January 27, 2022

    Hello Deepesh,

    I have no over idea with your optimization level issue.

    I will forward your concern to the Flash Driver expert and let you know any feedback.

    Best Regards,

    -Olivier

    ODOUV.1
    ST Employee
    January 28, 2022

    Hello,

    how are you selecting your low block to erase at 0xFF_0000 ?

    do you use lowBlockSelect 0x200 ? and other select to 0 ?

    BRs,

    -Olivier

    DMA
    DMAAuthor
    Associate
    January 31, 2022

    Configuration for flash is as follows:

    SSD_CONFIG FLSHM_ssdConfig = {

    C55_REG_BASE, /* C55 control register base */

    MAIN_ARRAY_BASE, /* base of main array */

    { 0, 0, 0 }, /* blocks info of low address space */

    { 0, 0, 0 }, /* blocks info of mid address space */

    { 0, 0, 0 }, /* blocks info of high address space */

    0, /* number of blocks in 256K address space */

    UTEST_ARRAY_BASE, /* base of UTEST array */

    TRUE, /* interface flag indicate main or alternate interface */

    0x80,/* programmable size */

    FALSE /* debug mode selection */

    };

    Below steps to get flash block erased-

    #define LOWBLOCKSELECT 0x00000200U (0x00FF0000)

    #define MIDBLOCKSELECT 0x00000000U

    #define HIGHBLOCKSELECT 0x00000000U

     /* Unlock the requested block for Erase operation */

    nLargeBlockSelect.firstLargeBlockSelect = 0;

    nLargeBlockSelect.secondLargeBlockSelect = 0;

    SetLock(&FLSHM_ssdConfig, C55_BLOCK_LOW, UNLOCK_ALL_BLOCKS);

    /* Erase the requested block */

    Return_Val = FlashErase(&FLSHM_ssdConfig, C55_ERASE_MAIN, LOWBLOCKSELECT,

    MIDBLOCKSELECT, HIGHBLOCKSELECT, nLargeBlockSelect);

    if(Return_Val == C55_OK)

    {

     while(C55_INPROGRESS == FlashCheckStatus(&FLSHM_ssdConfig, C55_MODE_OP_ERASE, &opResult, &FLSHM_eraseCtxData));

     /* Erase is successful */

    }

    else

    {

    /* Erase failed */

    }

    ODOUV.1
    ODOUV.1Best answer
    ST Employee
    January 31, 2022

    Hello,

    your parameters are good.

    Would you please check it could be the same issue than this one :

    Flash Erase for SPC58NG84E7 is not working (st.com)

    Best Regards,

    -Olivier

    DMA
    DMAAuthor
    Associate
    January 31, 2022

    Hi Oliver

    Yes Its similar to the issue that I am facing currently.

    ODOUV.1
    ST Employee
    January 31, 2022

    Current solution is to put your program in RAM.

    I asked for an analysis from R&D.

    I will keep you informed.

    Best Regards,

    -Olivier

    ODOUV.1
    ST Employee
    January 31, 2022

    Could you try this Load in RAM configuration ? (in SPC58xGxx RLA Platfrom->runtime settings)0693W00000JNilIQAT.png 

    BRs,

    -Olivier

    DMA
    DMAAuthor
    Associate
    January 31, 2022

    Hi Oliver,

    I tried using this setting but same result is observed. I am not able to erase the memory.

    I also tried different memory blocks(0x01000000 and 0x01020000) but still not working and control got stuck in unhandled exception.

    Thanks and Regards

    Deepesh

    ODOUV.1
    ST Employee
    February 4, 2022

    Hello,

    R&D had no time to provide an analysis for this issue this week.

    I hope they could next one.

    Best Regards,

    -Olivier

    Ravi S
    Associate II
    March 15, 2022

    Hi Oliver ,

    Any update on this above issue .I am also facing similar issue .While debug I can able to erase flash .But I loaded the bootloader code into the flash flasherase not works .stuck inside the flash erase .If u have any update pls let me know.

    Thanks advance...