2023-07-07 04:56 AM - edited 2023-12-07 05:35 AM
The locked state occurs any instance that the device is configured to such that
This is why if you attempt to write RDP to level 1 in STM32CubeProgrammer while the TrustZone® is activated, you get a warning:
STM32CubeProgrammer gives us a brief warning, but we need to look deeper to understand why the locked state could occur. AN5347 section 7.1 has a description of how the device behaves when RDP level 1 is enabled with TrustZone®, both when executing secure and nonsecure code.
As can be seen above, there are a couple of situations that can occur with RDP level 1 and TrustZone®:
When executing secure code in the lock state, the only way to make the device connectable is to enter the system memory bootloader.
In this situation, avoiding a permanent lockout of the device depends on our ability to enter the system memory bootloader.
At this point, whether or not you are able to recover the device depends on the configuration of the nSWBOOT0.
If nSWBOOT0 = 0 prior to entering the locked state, you are permanently locked out of connecting to the debugger on this device.
nSWBOOT0 determines whether or not the entry of the system memory bootloader/RSS is determined by the physical BOOT0 pin, or the nBOOT0 option bit. If nSWBOOT0 = 0, the boot location is determined by the nBOOT0 option bit. Since you cannot connect to the debugger, you are never able to connect to the device to toggle the nBOOT0 bit. This means that your device will be permanently locked out of debugging since there are no options to revert RDP to level 0 at this point.
If nSWBOOT0 = 1 prior to entering the locked state, you can use the BOOT0 pin to enter the RSS/system memory bootloader and revert RDP to level 0.
If you are using custom hardware in which you cannot access the BOOT0 pin, you will once again be out of options to recover the device. However, if you can access the BOOT0, you can recover the device by connecting BOOT0 pin to VDD voltage, then power cycling the device. Upon boot, the device should be executing code in the system memory, and therefore the debugger should connect. Once connected, revert RDP to level 0 in the option bytes. Remove VDD from BOOT0 and power cycle again. The U5 should be executing code from user flash again, except the debugger can be connected as usual.
Although the potential to permanently lock out the debugger exists on the U5, awareness of the issue allows for options to avoid this locked state. In summary, here are a few suggestions to help avoid and mitigate being locked out of your device: