I'm hoping to get some help understanding why I am unable to get CPR1 to protect Sector-0 on my LPC11U68. Any help will be greatly appreciated. I am interfacing my target hardware directly to my PC via the USB Bootloader. I am using LPCXpresso to generate my .axf & .bin files.
I am able to build my application and load it into my target hardware using CRP0 and everything works fine. Now that everything is working great, I want to set CRP to CRP1, so that I can do subsequent partial code image downloads to the target without changing the contents of Sector 0. It is my understanding that this is exactly what CRP1 is all about. I am able to successfully configure my target hardware with CRP1 - that's not the problem.
The problem is that any file I subsequently attempt to program into Flash via the USB Bootloader ALWAYS overwrites Sector 0. The idea was that with CRP set to CRP1, I could transfer a subsequent file to the target via the USB Bootloader and Sector 0 would be protected - but I am unable to make that happen.
I have read every datasheet, App Note and Forum post I can find and am still at a loss. I have modified my Linker Script to include the 0x2FC declaration and am using the macro for setting CRP1. I am able to confirm that the .bin file generated by the link is correct by dumping the .bin file to a "hex viewer" utility. The CRP1 code is right there. Here's what's happening:
1) I build my code image with CRP set for CRP1, then generate the .bin file from the .axf file (using LPCXpresso).
2) My target hardware is connected directly to my PC via its USB connector.
3) My target hardware shows at the Drive Designator as "CRP DISABLD".
4) I delete the "firmware.bin" file, and paste in my "CRP1" code image, then power cycle the target.
3) When I reset my target (configured to enter the Bootloader again) the Target now shows up again as a drive in Windows Explorer, now indicating that it is currently "CRP1 ENABLD".
4) So far so good.
5) Now I delete the "firmware.bin" file and paste in the new "field upgrade" .bin file, intended to update other Sectors, but not make any changes to Sector 0.
6) After reset, it is obvious that the processor/code is not running.
7) When I re-enter the Bootloader, now the drive designator shows up as "CRP DISABLD"
8) So Sector 0 and the CRP value in Sector 0 got changed. When I transfered the incremental file via the USB Bootloader.
9) From what I can observe, it appears that Sector 0 has been erased or at least overwritten.
10) The .bin file I'm loading while in CRP1 is small enough so that it should not result in the erasure of Sector-0 which is possible when "all sectors are being erased".
A) So does the act of deleting the "firmware.bin" file result in the erasure of the whole Flash, including Sector-0?
If so, how is CRP1 any different from CRP2?
B) The .bin file generated by LPCXpresso IDE is padded with "fill" characters from 0x00000000 to 0x00000FFF. Is there an option to generate the .bin file such that it does NOT have ANY characters for addresses prior to 0x00001000 (Sector 1)? Would this avoid having Sector 0 get written?
I've tried everything - I'm just about done with my design - it's all working fine - the final step was to protect Sector-0 using CRP1 so I could do field upgrades to the other Sectors without changing Sector-0, but anything I attempt to bootload into the chip via USB ALWAYS corrupts Sector-0, even though CRP is clearly set to CRP1 and not ALL sectors are being erased. Or at least they're not supposed to be getting erased.
Lastly, does CPR1 and Sector 0 protection NOT work when using the USB Bootloader for some reason?
Thank you very much for any help you can offer.