I have an application running on a Kinetis K20 (MK20DX256VLQ10), with MQX 4.0, compiled with CW 10.3. I have a weird issue with reading the data flash immediately after programming a virgin device. To re-create, I do a full erase of the chip, program my application and data (which goes in the dataflash @ 0x10000000), then execute. When I try to read the data flash I get a bus fault and am returned 0xFF for all values. It doesn't matter how many times I reset the controller, it always fails. However, all I have to do is stop the debugger and start a new debug session, and it magically works from there on out. This is also true if I program the device and then run stand-alone. If I program a virgin device and then try to power it up, the reads don't work. I know this, because my graphics for the display are held in the data flash, so nothing appears on the screen when the reads aren't working. However, I reconnect to the J-Link and reprogram, and everything runs fine from there on out.
I have dumped the registers in both cases, and don't see anything that could explain this. I did notice that the flash bank control registers (FMC_PFB0CR & FMC_PFB1CR) are set to 0x3002001F on the first program attempt, and then 0x30020000 after I stop and restart the debugger. So, I'm wondering what the debugger is doing that is magically solving this issue.
I have attached a dump of the register contents of both a failed flash read and a good flash read.
Original Attachment has been moved to: bad_read.regs.zip
Original Attachment has been moved to: good_read.regs.zip