Thank you for your reply!
Your code is from C40_ Ip_ Example_ Is it in S32K344?
I referred to one of the methods, but the result was not satisfactory.
Let me share my thoughts:
I am trying CAN BOOT. The upper computer sends two frames of data, and the lower computer calls its own function FLASH every time it receives it_ HAL_ WriteData() for Flash writing. This function mainly unlocks and then writes Flash based on the amount of data written. The main writing code is as follows (see the else branch at the end for details).
boolean FLASH_HAL_WriteData(const uint32 i_startAddr,
const uint8 *i_pDataBuf,
const uint32 i_dataLen)
{
boolean retstates = FALSE;
uint8 lessWriteLen = 8u;
uint8 aDataBuf[8u] = {0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu};
uint32 writeDataLen = 0u;
uint8 index = 0u;
uint32 sectorLength = 0u;
C40_Ip_StatusType C40Status;
C40_Ip_VirtualSectorsType VirtualSector;
C40_Ip_VirtualSectorsType endVirtualSector;
sectorLength = 8192U;
VirtualSector = (i_startAddr - 0x400000u)/sectorLength + FLS_MAX_DATA_SECTOR;
endVirtualSector = ((i_startAddr + i_dataLen) - 0x400000u) / sectorLength + FLS_MAX_DATA_SECTOR;
while(VirtualSector <= endVirtualSector)
{
if(STATUS_C40_IP_SECTOR_PROTECTED == C40_Ip_GetLock(VirtualSector))
{
C40_Ip_ClearLock(VirtualSector, 0);
}
VirtualSector++;
}
DisableAllInterrupts();
if(i_dataLen & (lessWriteLen - 1))
{
......
}
else
{
retstates = TRUE;
C40Status=C40_Ip_MainInterfaceWrite(i_startAddr,i_dataLen,i_pDataBuf, 0);
do
{
C40Status = C40_Ip_MainInterfaceWriteStatus();
}
while (STATUS_C40_IP_BUSY == C40Status);
if(STATUS_C40_IP_SUCCESS != C40Status)
{
retstates = FALSE;
}
}
EnableAllInterrupts();
return retstates;
}
But during debugging, it was found that FLASH_ HAL_ WriteData() returns a successful operation, but all the data written to the Flash area is 0xFF, which is not what I expected. In theory, this is considered a write failure, but the return value is STATUS_ C40_ IP_ SUCCESS has no problem.
I was wondering if my understanding was incorrect and there was a problem with the method of calling the function? Or is it caused by frequent unlocking of Flash. I hope you can give me some guidance, thank you very much!!!