It is one of these long weekends which allow to catch up on many things. One thing I finally completed was the move to FreeRTOS V7.1.1. With this I did some tests using the Tower boards, including the Kinetis one. So I have rebuild my Kinetis K60 application and was ready to flash the device. But then to my surprise I got this dialog:
Strange, I do not remember that I have secured that device. Actually I’m very careful not to secure any devices as this might be a permanent thing.
Most microcontroller offer different levels of protection, usually with special configuration registers and settings:
- Protect: the device or parts of it are protected against programming the flash memory. This is typically used to protect a bootloader or any parts of the device to be overwritten either by the debugger or by the application itself. To unprotect usually a configuration register has to be reprogrammed or the flash memory needs a mass erase.
- Secure: Access to the flash memory with an external tool or debugger is not possible any more. This used to protect the software on the device to be inspected or to prevent reverse engineering. To recover the device a mass erase typically has to be applied.
- Disable Mass Erase: This is probably the most dangerous option a device can offer for a developer. With this configuration set, it will not be possible to do a mass erase of the device. So if I combine ‘secure’ with ‘disable mass erase’, I will not be able to recover my device any more.
Depending on the device/flash features, CodeWarrior provides Protect/Unprotect and Secure/Unsecure target task actions for the flash programmer.
For this I have the Target Tasks view open (menu Window > Show View > Other > Debug > Target Tasks). In that view, I can create a new Target Task with the ‘import’ button:
Then I go to <installation path>\MCU\bin\plugins\support:
Then I go inside the Flash_Programmer folder and select the XML file matching my device:
Then I can double-click on the newly created Target Task and change/configure it:
And in that dialog I can add more actions:
The problem is that during development it can happen that I write wrong settings to my device, and with this accidentally secure it. And if my wrong settings as well include ‘disable mass erase’, I’m really doomed. And unsoldering a CPU from a board is not something easy if has >100 pins or is a ball grid array device type .
Back to my dialog from the beginning:
So it looks I might have accidentally secured my device? I pressed ‘Yes’, but unsecuring failed again, resulting with the same dialog. Tried it again: same thing. Oh, oh! Could it be that the ‘disable mass erase’ bit is set as well? That would be really bad. I only have that single Kinetis K60 board. Wait! I have as well the Kinetis K60F (Kinetis K60 with floating point using an Cortex-M4F) on my desk. And here was my problem: the OSBDM debug cable was not connected to the TWR-K60N512, but instead to the TWR-K60F120M one!
Connecting the correct TWR-K60N512 one to my host machine, and I was able to download my application .
Lessons learned, in priority order:
- Connecting to the wrong device might trigger a false alarm about the device being secured.
- Carefully check to which board/device I’m connecting.
- Cleanup my desk and reduce the number of boards, power supplies and USB cables on it.
Interestingly, my wife only agrees to point 3.
Happy Unsecuring, and Cleaning