Hello friends,
I am using CW 10.1 and Kinetis MK10N512VMD100.
Processor is running at 40MHz and flash is running at 20MHz.
I have written a simple program that will erase and program the flash.
After programming the flash once it has been erased I have reviewed the memory of the programmed flash space using the memory browser and it does contain the written information.
I have declared in the .lfc file not to include the area of the flash that I am rewriting, so
the linker will not put information there. I have verified in the project map file that indeed the sections
I am erasing are free from data.
However when trying to access the flash memory to verify its content I have an unhandled interrupt from time to time on specific flash address After checking what might trigger the unhandled interrupt
I was able to narrow the source to one of the following (Interrupt sources 5, 3)
PRECISERR: Precise data bus error
BFARVALID: BusFault
UNDEFINSTR: Undefined instruction UsageFault
I have tried changing clock rates, to see if this has any affect without success
Am I doing something wrong? Is there a silicon problem with clocking the flash?
See the attached sample program
// Not all the program is listed , only the flash erase section and the relevant include files
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "FTFL_PDD.h"
#define FTFL_CMD_WRITE_LONG_WORD 0x06
#define FTFL_CMD_ERASE_FLASH_SECTOR 0x09
#define FTFL_CMD_PROGRAM_SECTION 0x0B
#define SECTOR_SIZE 2048 // 0x800
uint32_t gBadWords;
uint32_t gTest;
int8_t FLASH_Erase(uint32_t StartAddress, uint32_t NoSectors)
{
// Start Address must be on a Sector boundaries
uint32_t CurrentSectorStartAddress;
uint32_t EndAddress,AddressData;
// Clocking the FTFL module
SIM_SCGC6 |= 1;
while (!(FTFL_FSTAT_REG(FTFL_BASE_PTR) & FTFL_FSTAT_CCIF_MASK)); // Should never happen
// Clear all error registers - Write 1 will clear them
FTFL_FSTAT_REG(FTFL_BASE_PTR) = (FTFL_FSTAT_FPVIOL_MASK | FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_RDCOLERR_MASK);
CurrentSectorStartAddress=StartAddress;
EndAddress=StartAddress+NoSectors*SECTOR_SIZE;
while (NoSectors)
{
while (!(FTFL_FSTAT_REG(FTFL_BASE_PTR) & FTFL_FSTAT_CCIF_MASK)); // Wait for previous erase sequence to end
if (FTFL_FSTAT_REG(FTFL_BASE_PTR)
& (FTFL_FSTAT_RDCOLERR_MASK | FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK | FTFL_FSTAT_MGSTAT0_MASK )
) return(1); // Error during last cycle
// See section 28.4.10
FTFL_PDD_SetFCCOBCommand(FTFL_BASE_PTR,FTFL_CMD_ERASE_FLASH_SECTOR); // Write Erase Command to FCCOB0 , Can be taken out of the while loop
FTFL_PDD_SetFCCOBAddress(FTFL_BASE_PTR,CurrentSectorStartAddress); // Write FCCOB1,FCCOB2,FCC0B3 with the address
FTFL_PDD_LaunchCommand(FTFL_BASE_PTR); // Just write '1' to CCIF , However this also clears the errors (which we dont' have)
NoSectors--;
CurrentSectorStartAddress+=SECTOR_SIZE;
} // loop around number of sectors to erase
// Check that indeed all is erased
// The next few lines causes bus fault interrupt
// Using the memroy browser once can see that the memory is erased
CurrentSectorStartAddress = StartAddress;
gBadWords=0;
while (CurrentSectorStartAddress<EndAddress)
{
AddressData = *(uint32_t *)CurrentSectorStartAddress;
if (AddressData != 0xFFFFFFFFUL)
gBadWords++;
CurrentSectorStartAddress+=4;
}
// Un clocking the FTFL module
SIM_SCGC6 &= (uint32_t) 0xFFFFFFFE;
return(0);
} // End of FLASH1_Erase