adammunich
Member
Howdy forum,
I have encountered a strange bug where I cannot seem to write to P-Flash.
First, I set the FlexRam to act as normal RAM
Which seems to work, as my blinky LED test does not fire
But now, when I try to erase a sector,
My script will hang indefinitely at the while loop.
If I comment out the while loop, I end up with an FTFL_FSTAT_ACCERR flag set.
My flash protection bits are very liberal, I am protecting only the first 8K of flash, which I am not writing to with my test script.
As well, I have defined the flexRam memory addresses in my linker script and they are read/writable. My clock is 48MHz, 48MHz bus, 24MHz flash.
Any ideas what I could be doing wrong? Perhaps there is some initialization features I missed?
I have encountered a strange bug where I cannot seem to write to P-Flash.
First, I set the FlexRam to act as normal RAM
Code:
// wait for ready
while ((FTFL_FSTAT & FTFL_FSTAT_CCIF) != FTFL_FSTAT_CCIF) {};
// Set flexram command
FTFL_FCCOB0 = SET_FLEXRAM_FUNCTION;
FTFL_FCCOB1 = 0xFF;
// Clear error flags
FTFL_FSTAT = FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL | FTFL_FSTAT_RDCOLERR;
// Launch command
FTFL_FSTAT = FTFL_FSTAT_CCIF;
// wait for ready
while ((FTFL_FSTAT & FTFL_FSTAT_CCIF) != FTFL_FSTAT_CCIF) {};
Which seems to work, as my blinky LED test does not fire
Code:
if (FTFL_FSTAT & FTFL_FSTAT_ACCERR) {
while (1) {
led_toggle();
for (long j = 1000000; j; --j) {
watchdog_refresh();
}
}
}
But now, when I try to erase a sector,
Code:
// erase sector
uint32_t address = 0x4000;
FTFL_FCCOB0 = ERSSCR;
FTFL_FCCOB1 = (address >> 16) & 0xFF;
FTFL_FCCOB2 = (address >> 8) & 0xFF;
FTFL_FCCOB3 = address & 0xFF;
// Clear error flags
FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL | FTFL_FSTAT_MGSTAT0;
// Launch command
FTFL_FSTAT = FTFL_FSTAT_CCIF;
// wait for ready
while ((FTFL_FSTAT & FTFL_FSTAT_CCIF) != FTFL_FSTAT_CCIF) {};
My script will hang indefinitely at the while loop.
If I comment out the while loop, I end up with an FTFL_FSTAT_ACCERR flag set.
My flash protection bits are very liberal, I am protecting only the first 8K of flash, which I am not writing to with my test script.
Code:
const uint8_t flashconfigbytes[16] =
{
// Backdoor comparison key (disabled)
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0xff, 0xff, 0xff,
0xfe, // Data flash protection (FDPROT)
0xff, // EEPROM protection (FEPROT)
0xff, // Flash nonvolatile option byte (FOPT)
0x40 // Flash security byte (FSEC)
};
As well, I have defined the flexRam memory addresses in my linker script and they are read/writable. My clock is 48MHz, 48MHz bus, 24MHz flash.
Any ideas what I could be doing wrong? Perhaps there is some initialization features I missed?