- CodeWarrior for MCU
I have a peculiar problem with reading from P-Flash after writing to it.
First I write S-Records to P-Flash using simple "program longword" command and also verify that the writing succeeded using "program check" command. After writing of every S-Record I invalidate the cache and try to calculate a checksum over the written bytes, wich I then compare against the actual checksum of the written S-Record. I use the following code to invalidate the cache:
#define main_discard_flash_cache FMC_PFB0CR |= FMC_PFB0CR_CINV_WAY; \
FMC_PFB0CR |= FMC_PFB0CR_S_B_INV;
I set all of the CINV_WAY bits and the S_B_INV bit.
This works great for the first 4 S-Records, but for all of others I fail to verify the checksum.
The peculiar part is that when I run the application in the debugger and put a breakpoint after the flash write and before the checksum calculation and just click "Resume" after the breakpoint triggered, then the checksum verification works correctly. The calculated value is also correct when I check in the debugger.
The firmware that I flashed also works perfectly fine. It's just the software verification that doesn't seem to work without debugger intervention.
So do I maybe have to do anything else to invalidate the flash? What does the debugger do with the flash when it halts the device?