S32K146 Read Collision when erasing/writing flash

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

S32K146 Read Collision when erasing/writing flash

Jump to solution
222 Views
chilambarasanm
Contributor I

when i try to erase or write to the program flash on my S32K146 i run into a Fault at the moment the FTFC should execute the command. Also the RDCOLLERR bit in the FTFC_STAT register is set.

BusFault: A precise (synchronous) data access error has occurred. and also instruction fetching error i got.

Strangely enough this does not happen, when i step through the program line by line. Then the flash gets programmed correctly.

 

This is my routine for erasing a flash sector:

status_t Flash_Write(const byte* pucSrc, ulong* pucDst, ushort usLen)
{
status_t ret = STATUS_N_OK;       /* Return code variable */
 
/* Check CCIF to verify the previous command is completed */
if (0U == (FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK))
{
ret = STATUS_N_OK;  /* Returning NOK as STATUS_BUSY is not handled */
}
else /* No previous command is pending */
{
/* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
FTFC->FSTAT = CLEAR_FTFC_FSTAT_ERROR_BITS;
 
/* Passing parameter to the command */
FTFC->FCCOB[3] = FTFC_PROGRAM_PHRASE;
FTFC->FCCOB[2] = GET_BIT_16_23(pucDst);
FTFC->FCCOB[1] = GET_BIT_8_15(pucDst);
FTFC->FCCOB[0] = GET_BIT_0_7(pucDst);
 
/* Calling flash command sequence function to execute the command */
ret = Flash_Command_Sequence();
 
}
return ret;
}
 
The error happens in Flash_Command_Sequence():
status_t Flash_Command_Sequence(void)
{
 
flash_drv_status_t Cmd_ret_Status = FTFx_N_OK;    /* Command execution return code variable */
status_t ret = STATUS_OK;    /* Return code variable, by default is OK */
 
/* Clear CCIF to launch command */
FTFC->FSTAT |= FTFC_FSTAT_CCIF_MASK;
 
while (0U == (FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK))
{
/* Wait till CCIF bit is set indicating the requested command is completed*/
 
}
 
Cmd_ret_Status = (flash_drv_status_t)(FTFC->FSTAT & (FTFC_FSTAT_MGSTAT0_MASK | FTFC_FSTAT_FPVIOL_MASK \
| FTFC_FSTAT_ACCERR_MASK | FTFC_FSTAT_RDCOLERR_MASK));
 
if (Cmd_ret_Status != FTFx_OK) 
{
/* Some error has occured */
ret = STATUS_N_OK;
}
return (ret);
}
 
 
As mentioned earlier, this only happens when NOT debugging step by step. I suspect this has something to do with the flash being busy, but i did not find anything that would help me understand.

 

0 Kudos
1 Solution
168 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

There's simple rule - whatever the situation is, you can't access a flash block which is being erased or programmed. As you can see in the source files, FLASH_DRV_CommandSequence is executed in RAM:

lukaszadrapa_0-1709538933876.png

 

Not sure what kind of differences you did, so please check if the function is really executed from RAM.

And try to disable interrupt when programming the flash. This is the most common issue.

Regards,

Lukas

View solution in original post

0 Kudos
3 Replies
202 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @chilambarasanm 

this is caused by Read While Write (RWW) error.

RWW is supported only between partitions/blocks. S32K146 has two 512KB blocks of program flash memory. When a block is being programmed or erased, the code must run from different block or from data flash or from RAM. If there are interrupts which could access the block, it's necessary to either disable all interrupts or put all the interrupt resources (vector table, ISR handlers...) to different block or to RAM.

Some screenshots from the reference manual:

lukaszadrapa_0-1709238990183.png

 

lukaszadrapa_1-1709238999539.png

Regards,

Lukas

 

0 Kudos
175 Views
chilambarasanm
Contributor I

Hi lukaszadrapa,


Thanks for the reply it worked. I have one more query related to this.

 

My memory mapping order will be like this for S32K144:

Vector table : 0x00000000 - 0x000003FF

Flash Config: 0x00000400 - 0x0000040F

Bootloader area : 0x00000410 - 0x00003FFF

Parameter area : 0x00004000 - 0x00004FFF

Application area : 0x00006000 - 0x00023FFF

 

During Bootloader sequence my Flash_Command() will be executed from my ROM area only at that time there is no issue in the Flashing part.

But when i try to write the parameter in the respective area and Flash_Command() is executing from Application area at that time i am facing issues related to BUS_Fault but during debugging i am not facing any issues.

 

if Flash_Command() has to executed from RAM area then for Bootloader how it works can you explain on this part.

0 Kudos
169 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

There's simple rule - whatever the situation is, you can't access a flash block which is being erased or programmed. As you can see in the source files, FLASH_DRV_CommandSequence is executed in RAM:

lukaszadrapa_0-1709538933876.png

 

Not sure what kind of differences you did, so please check if the function is really executed from RAM.

And try to disable interrupt when programming the flash. This is the most common issue.

Regards,

Lukas

0 Kudos