S32K344 - C40_Ip_MainInterfaceWrite only write all data if I run step by step in debugger

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K344 - C40_Ip_MainInterfaceWrite only write all data if I run step by step in debugger

707 Views
FredM
Contributor I
Hello,

Please I need help to understand and fix this issue. 



I write on the Flash memory sector 0x00600000U (C40_CODE_ARRAY_0_BLOCK_2_S256) custom data that I "memcpy" in a dynamic buffer and then I write the buffer variable using 
C40_Ip_MainInterfaceWrite(ulAddress, ulSize, pvSource, FLS_MASTER_ID);

The code works but only if I run it in debugger using breakpoints, I move forward step by step and I can see the whole memory sector with the correct content of the buffer variable.
If I restart the board I can see the 0x00600000U with persistent data and it's correct.
 
This is my issue:
But If I run the code without any breakpoint the 0x00600000U has no data written and/or fails written correct bytes values. It's breaking my mind since 3 days ago. Please can you help me to understand what I am missing?
I put a global variable failCounter and is increased only if I run the code without any breakpoint.
 
I tried to do these 2 previous solved questions:
https://community.nxp.com/t5/S32K/S32K344-C40-IP-Hardware-Fault-Problem/td-p/1697432

This is the CODE TO WRITE buffer variable into the FLASH MEM:

uint8_t functionToWriteOnFlash(void * buffer){
 
    // Unlock sector if needed
 
    if (STATUS_C40_IP_SECTOR_PROTECTED == C40_Ip_GetLock(FLS_SECTOR_ADDR)) {
        C40_Ip_ClearLock(FLS_SECTOR_ADDR, FLS_MASTER_ID);
    }

    // NOTE: Is this Necessary to rewrite the same previous sector ?
    eraseSector();

    size_t writeAddress = HEADER_ADDRESS;
    size_t remainingSize = totalSize;
    size_t chunkSize = 16;
    size_t currentSize = 0;
    uint8_t *bufferPtr = buffer;

    uint8_t resp;
    // Move through buffer 16 Bytes every iteration until end
    while (remainingSize > 0) {
        if (remainingSize < chunkSize && remainingSize % 16 != 0) {
            currentSize = (remainingSize > 16) ? (remainingSize - (remainingSize % 16)) : remainingSize;
        } else {
            currentSize = (remainingSize > chunkSize) ? chunkSize : remainingSize;
        }

        resp = writeNvs(writeAddress, currentSize, bufferPtr);

        writeAddress += currentSize;
        bufferPtr += currentSize;
        remainingSize -= currentSize;

        if (0 != resp) {
            return resp;
        }
    }

    if (remainingSize > 0) {
        resp = writeNvs(writeAddress, remainingSize, bufferPtr);

        if (0 != resp) {
            return resp;
        }
    }
    C40Status = C40_Ip_SetLock(FLS_SECTOR_ADDR,FLS_MASTER_ID);
    return 0;
}




 
static uint8_t writeNvs(size_t ulAddress, size_t ulSize, void *pvSource) {
 
    // WRITE DATA ONLY WORKS WHEN I DEBUG STEP BY STEP
 
    C40_Ip_MainInterfaceWrite(ulAddress, ulSize, pvSource, FLS_MASTER_ID);
 
    do {
        C40Status = C40_Ip_MainInterfaceWriteStatus();
    } while (STATUS_C40_IP_BUSY == C40Status);

    Nvs_Assert(STATUS_C40_IP_SUCCESS == C40Status);

    // Compare the data in memory with source
    // I ONLY GET failCounter = 0 IF I USE THE DEBUG STEP BY STEP
 
    C40Status = C40_Ip_Compare(ulAddress, ulSize, pvSource);
 
    if(STATUS_C40_IP_SUCCESS != C40Status){
        failCounter++;
    }

    return Nvs_Assert(STATUS_C40_IP_SUCCESS == C40Status);
}
0 Kudos
Reply
1 Reply

639 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @FredM,

There is no need to place the code to SRAM if you program another block, e.g. programming the 0x00600000 block from the 0x00400000U block.

This looks like a cache problem.

The driver synchronizes the cache if this option is set:

danielmartynek_0-1724673046675.png

 

Regards,

Daniel

0 Kudos
Reply