To program flash, use address 0x44020000
//*****************************************************************************
// FLASH Parameters
//*****************************************************************************
// Start address for region of flash available for web page upload
#define FLASH_START_ADDRESS 0x44020000
// End address for region of flash available for web page upload
#define FLASH_END_ADDRESS 0x4403FFFF
// Flash erase page size
#define FLASH_PAGE_SIZE 0x0800
// Number of flash pages erased per task itteration
#define PAGES_PER_SESSION 0x08
// Address for flash region as seen by CPU
#define FAT_FILE_BASE_ADDR 0x00020000
void flash_init( void )
{
// So, for fSYS = 66 MHz, writing 0x54 to CFMCLKD will set fCLK to 196.43 kHz which is a valid frequency
// for the timing of program and erase operations.
// WARNING
// For proper program and erase operations, it is critical to set fCLK between
// 150 kHz and 200 kHz. Array damage due to overstress can occur when fCLK
// is less than 150 kHz. Incomplete programming and erasure can occur when
// fCLK is greater than 200 kHz.
MCF_CFM_CFMCLKD = 0x54;
init_serial_flash();
}
//*****************************************************************************
// Flash page erase function.
//
// Author: Eric Gregori (847) 651 - 1971
//
eric.gregori@freescale.com//*****************************************************************************
volatile void flash_page_erase( unsigned long *address, unsigned long data )
{
mcf5xxx_irq_disable();
*address = data;
MCF_CFM_CFMCMD = 0x40;
MCF_CFM_CFMUSTAT = 0x80;
while( !(MCF_CFM_CFMUSTAT & MCF_CFM_CFMUSTAT_CCIF))
{};
mcf5xxx_irq_enable();
}
//*****************************************************************************
// Flash write function.
//
// Author: Eric Gregori (847) 651 - 1971
//
eric.gregori@freescale.com//*****************************************************************************
volatile void flash_write( unsigned long *address, unsigned long data )
{
mcf5xxx_irq_disable();
*address = data;
MCF_CFM_CFMCMD = 0x20;
MCF_CFM_CFMUSTAT = 0x80;
while( !(MCF_CFM_CFMUSTAT & MCF_CFM_CFMUSTAT_CCIF))
{};
mcf5xxx_irq_enable();
}
//*****************************************************************************
// Flash test function, used to erase flash for demo
//
// Author: Eric Gregori (847) 651 - 1971
//
eric.gregori@freescale.com//*****************************************************************************
int flash_erase( void *pio )
{
unsigned long address;
flash_init();
for( address = FLASH_START_ADDRESS; address < FLASH_END_ADDRESS; address += FLASH_PAGE_SIZE )
flash_page_erase( (unsigned long *)address, (unsigned long)0 );
return(0);
}