Greetings folks,
I'm looking to create a write function for a MC56F8365 component (performing the tests on the MC56F8367EVME board), and based on the guide provided in the 56F8300 Peripheral User Manual, I came up with the following (I'm still working with FMCLK, but the DIVLD bit in FMCLKD has been set) :
uint8_t flash_write(uint32_t *addr, uint16_t *buf, uint16_t len)
{
uint16_t *pdata = buf, plen = len;
uint32_t *paddr = addr;
if(FMCMD & 0x40){
FMCMD &= 0xFFBF;
}
/* Check FM clock */
while(len--){
/* Check to see if the command buffer is empty; otherwise, wait. */
while((FMUSTAT & 0x0080) == 0);
/* Select the desired flash space to write to. */
FMCR |= 0x0002;
/* Write the desired data at the desired address. */
*((uint16_t*)addr) = *buf;
/* Write the program command to the FMCMD register */
FMCMD |= 0x0020;
/* Clear the CBEIF bit of FMUSTAT */
FMUSTAT |= 0x0080;
/* Check the FMUSTAT register for protection, access errors */
if(FMUSTAT & 0x0020){ // Protection Violation Check;
FMUSTAT |= 0x0020;
GPIO_C_DR |= 2;
return 1;
}
if(FMUSTAT & 0x0010){ // Access Error Check
FMUSTAT |= 0x0010;
GPIO_C_DR |= 4;
return 1;
}
/* Loop back around for another write; otherwise, check CCCIF */
addr++;
buf++;
}
while((FMUSTAT & 0x0040) == 0);
/* Verify via previous variables */
while(plen--){
if( *paddr++ != *pdata++ ){
GPIO_C_DR |= 8;
return 1;
}
}
return 0;
}
Upon running the code (either through the debugger or the flash programmer in CW 10.6 via a PE Micro Multilink Universal), the locations I intended to write to remain blank (0xFFFF). Any ideas?
NOTE: Prior to operation, the Debugger notes the flash registers set as the following:
FMCLKD = 0x00a0
FMCR = 0x0000
FMSECH = 0x8000
FMSECL = 0xFFFF
FMPROT = 0x0000
FMPROTB = 0x000
FMUSTAT = 0x00c0
FMCMD = 0x0020