Dear friend ,
I am now working on S12XHY128 flash driver.
but now it can not work well.
Here is the code of write function.
tFlashStatus FLASH_RAM_WriteRoutine(tFlashAddress uAddr, u16 uwLen, const u8 FLASH_FAR_POINTER aubData)
{
u16 uwNbData;
u8 ubIdx;
u8 ubStatus;
u8 ebStatus;
tFlashStatus eFlashStatus;
tFlashBoolean eFlashBoolean;
eFlashStatus = FLASH_NO_ERROR;
eFlashBoolean = FLASH_TRUE;
uwNbData = uwLen;
/* if no data to write */
if (uwNbData)
{
/* if FDIVLD not set */
if ((FLASH_FCLKDIV & FLASH_FCLKDIV_FDIVLD_MASK) == 0)
{
/* FCLKDIV must be set after each reset. */
FLASH_FCLKDIV = FLASH_FCLKDIV_CONF;
}
/* FCCOB availability check */
while ((FLASH_FSTAT & FLASH_FSTAT_CCIF_MASK) == 0U)
{
/* do nothing */
}
if (((FLASH_FSTAT & FLASH_FSTAT_ACCERR_MASK) != 0U) &&
((FLASH_FSTAT & FLASH_FSTAT_FPVIOL_MASK) != 0U))
{
/* Clear any error flags */
FLASH_FSTAT |= (FLASH_FSTAT_ACCERR_MASK | FLASH_FSTAT_FPVIOL_MASK);
}
/* Write the program command and the GPAGE part */
FLASH_FCCOBIX = 0U;
FLASH_FCCOBHI = FLASH_PROGRAM_P_FLASH;
FLASH_FCCOBLO = FLASH_WP_PAGE(uAddr);
uwtest = FLASH_FCCOB;
/* Write the 16-bit address part of phrase */
(FLASH_FCCOBIX)++;
FLASH_FCCOB = FLASH_WP_ADDR(uAddr);
uwtest = FLASH_FCCOB;
uAddr = (tFlashAddress)((u32)uAddr + 8U);
/* Fill the 8 bytes */
for (ubIdx = 0U; ubIdx < 8U; ubIdx++)
{
/* If we still have datas to write */
if (uwNbData != 0U)
{
/* If the byte is pair write the low part
else increment FCCOBIX index and write the high part */
if ((ubIdx % 2U) == 1U)
{
/* Write next data word to CCOB buffer. */
FLASH_FCCOBLO = *aubData;
aubData++;
uwtest = FLASH_FCCOB;
}
else
{
(FLASH_FCCOBIX)++;
FLASH_FCCOBHI = *aubData;
aubData++;
}
/* Decrement the byte number to write */
uwNbData--;
}
/* Else write 0xFFF in the last byte */
else
{
if ((ubIdx % 2U) == 1U)
{
/* Write next data word to CCOB buffer. */
FLASH_FCCOBLO = 0xFFU;
}
else
{
(FLASH_FCCOBIX)++;
FLASH_FCCOBHI = 0xFFU;
}
}
} /* End for(ubIdx = 0; ubIdx< 8; ubIdx++) */
ubfstat = FLASH_FSTAT;
/* Launch command */
FLASH_FSTAT |= FLASH_FSTAT_CCIF_MASK;
/* Bit polling for command completion check */
while ((FLASH_FSTAT & FLASH_FSTAT_CCIF_MASK) == 0U)
{
/* do nothing */
}
ubfstat = FLASH_FSTAT;
}
/* Check the error flags and return the error status */
if (((FLASH_FSTAT & (u8)(FLASH_FSTAT_ACCERR_MASK | FLASH_FSTAT_MGSTAT0_MASK | FLASH_FSTAT_MGSTAT1_MASK)) != 0U) ||
(eFlashBoolean == FLASH_FALSE))
{
eFlashStatus = FLASH_ACCESS_ERROR;
}
else if ((FLASH_FSTAT & FLASH_FSTAT_FPVIOL_MASK) != 0U)
{
eFlashStatus = FLASH_PROT_ERROR;
}
else
{
/* Nothing to do */
}
return eFlashStatus;
}
/*---------------------------{end FLASH_RAM_WriteRoutine}-----------------------------*/
But it does not work and I have erased before the write action.
The address I used is global address like following pic:

Does anyone know what is wrong and do you have sample code for me to reference?
Thanks a lot for your help.
br,
julie