RM46L852: FLASH Verification fail

Part Number: RM46L852


I'm struggeling with verifying FLASH content. 

After flashing a block of 4K data, I do a readback, which fails. However, when looking at the data in the debugger, it is correctly FLASH'ed. 

Is there some latency between flashing data and readback that I need to be aware of? (I'm using the FLASH API).

If I just skip the whole verify process, everything works fine, but it bug's me that this is the case. I have tried programming just data part, and also auto generating ECC bits with same result. 

Code:

 
//FLashing a block of data: (this is repeated until 4K is flashed)
 
uint32_t flashload_programBlock(uint32_t *flashAddress,uint8_t *data){
    Fapi_FlashStatusType status;
    uint8_t i;

    //Program 16 bytes
    status = Fapi_issueProgrammingCommand(flashAddress, data, 16, 0, 0, Fapi_AutoEccGeneration);
    if(Fapi_Status_Success != status){
        return FAPI_PROGRAMMING_COMMAND_FAILED;
    }
    waitFlashReady();
    if( 0 != FAPI_GET_FSM_STATUS){
        return FAPI_FSM_NOT_ZERO;
    }

    return SUCCESS;
}
 
//Verifying:
uint32_t flashload_verify(uint8_t *address, uint32_t noOfBytes){
    uint32_t i;
    for (i = 0; i < noOfBytes;i++){
        if(*address++ != flashload_rxbuf[i]){
            return WRITE_VERIFY_ERROR;
        }
    }
    return SUCCESS;
}
 
  • Hi LA Ma,

    I used same logic as your in my code and it is working fine:

    Please refer my attached project once:

    FAPI_TEST_RM46 (3).zip

    I am doing this testing on FEE area that is at address 0xF0200000, where you are doing this in your code?

    --
    Thanks & regards,
    Jagadish.

  • I'm using the main FLASH area from address 0x00020000 and forward (Bank0/Sector7). It looks like you are using the EEPROM section. 

    I have done some more debugging, and it seams that if I force optimize=0 on the verification function it seams to work. (more testing needed)

    In general all the c code is compiled with optimize=2. 

    If I put "__attribute__((optimize("0")))" in front of the verification process it appears to work. 

    I still don't get why, and it could just be that some timing stuff has changed when de-optimizing.

  • Hi LA Ma,

    Your verification is failing due to Flash Wrapper data cache coherency issues. When you program flash using Fapi_issueProgrammingCommand(), the newly programmed data may still be in the Flash Wrapper's pipeline buffers/data cache. When you immediately read back the data for verification, you may be reading stale cached data instead of the actual programmed flash content.

    The reason disabling optimization (optimize=0) appears to "fix" the issue is that it likely introduces enough delays and changes the memory access patterns such that the cache happens to be flushed or bypassed, but this is not a reliable solution.

    So, can you please do below process and let me know your feedback:

    call Fapi_flushPipeline() before performing any non-API flash reads after programming. According to the Flash API documentation:

    "This function flushes the Flash Wrapper data cache. The data cache must be flushed before the first non-API Flash read after an erase or program operation.

  • That did the trick. Thanks

    I had a feeling it was a cache issue, and had tried clearing cache using mcr p15 commands, but it was probably the wrong cache..

    Suggestion:
    Add the flush command to the recommended program flow in section 5.2 and 5.3 of the SPNU504x doc 

  • Thank you for the suggestion and observation.