Hello,
i just implemented a flash driver for a bootloader on the MPC5748G. To do so, i followed the example "flash_program_erase_mpc5746c" and used the interface "flash_c55_driver.h".
My flash driver offers two fine granular functions to write and erase:
Fls_Write(uint32_t address, uint8_t * buffer_p, uint32_t size)
Fls_Erase(uint32_t address, uint32_t size);
Both functions seem to work fine, except for one strange bug in the write routine.
When i write the first 32 Bit of the page, the inserted data is correct.
When i write the second 32 Bit of the page, the inserted data in the second 32 Bit is correct. Yet, the first 32 Bit of the page gets incremented by one.
Pseudocode of my implementation:
#define FLASH_PFCR1 0x000000000U
#define FLASH_PFCR2 0x000000004U
#define FLASH_FMC_BFEN_MASK 0x000000001U
uint32_t pflash_pfcr1, pflash_pfcr2;
Fls_Write(uint32_t address, uint8_t * data, uint32_t size)
{
uint32_t failedAddress;
if(Fls_initialized == false)
{
FLS_DRV_Init();
FLASH_DRV_SetLock(First/Second_256K_Blocks);
FLASH_DRV_GetLock(everything else);
}
DisableFlashControllerCache(FLASH_PFCR1, FLASH_FMC_BFEN_MASK, &pflash_pfcr1);
DisableFlashControllerCache(FLASH_PFCR2, FLASH_FMC_BFEN_MASK, &pflash_pfcr2);
flash_context_data_t contextData;
contextData.dest = address;
contextData.size = size;
contextData.source = (uint32_t) data;
FLASH_DRV_Program(&contextData, address, size, (uint32) data);
if (STATUS_SUCCESS == ret)
{
do
{
ret = FLASH_DRV_CheckProgramStatus(&pCtxData, &opResult);
}while(ret == STATUS_FLASH_INPROGRESS);
}
Flash_DRV_ProgramVerify(address, size, (uint32_t) data, 0x90 , &failedAddress, NULL_CALLBACK)
RestoreFlashControllerCache(FLASH_PFCR1, pflash_pfcr1)
RestoreFlashControllerCache(FLASH_PFCR2, pflash_pfcr2)
}
Any ideas? As you might have noticed, i don't know what contextData is supposed to do. Therefore, i pass the same thing to the SDK function twice.
Hi,
this is expected behavior. The reason can be found here in the reference manual:
You need to program 64bit words in single operation.
The flipped bit is an effect of ECC single bit error correction.
Regards,
Lukas