 Welcome to this STM32 tips video. Today I would like to check together how to change the ADP level without doing a power-on reset. Let's start with a reminder about the ADP level 1 definition. Shortly, if a debugger access is detected, then the flash is locked. That means it can't be accessed anymore, even by the core. And you need to do a full power-on reset to re-enable the access to the flash to the execution of your code. At the first step in this video, I propose that we just try to activate the ADP level 1 on a target with removing the debugging link. Let's see what happens. The first step, thanks CUBE programmer, I will change my firmware of the ST link. If I click on firmware upgrade and open in update mode, we can see that I've got the debugging link, but also this master edge functionality will allow you to drag and drop to the master edge volume in your PC to flash your boards and the VCP. I want to remove the master edge because this one, when I activate ADP level 1, will be detected as an intrusion and will lock the flash. So I will change the type, just for our example, and just keep debug and VCP. That way I can remove the debugging link, thanks removing those jumper and just keeping the VCP. Okay, once it's done, now I can connect to my board. Nothing in flash, option byte, readout protection, level 0. I will flash my binary with LED blinking program and I will just press the reset button. Then you can see some traces and also my LED is blinking. So now I propose we activate ADP level 1. So here I will just go there, upgrade to the level 1, apply. So it has been properly updated. Now before I will say click on OK, I will just remove the two jumper. Then I will close, I will say my debugging link. Okay, and I press reset button. Nothing happened. I would say it's not working. The only way to have this working again is to unplug the jumper with like a power on reset. And now it's okay. The explanation of this behavior is in fact inside the reference manual. As you can see, if the read protection is set while the debugger is connected, then you need to apply a power on reset. An additional information could be found in the reference manual of some STM32L0. To activate ADP level 1, you can also do a transition to the stone by state. The main issue of all this mechanism is how I can achieve ADP level 1 if I've got a device which is battery powered. And this battery is already soldered on the board. That means you can do a full power on reset. If we focus on the first reference manual, you can activate ADP while the debugger is not connected. So I propose we are using the embedded code to activate the ADP. And let's see what happens. Thanks to HL, it's easy to activate the ADP from the code. You just need to unlock the flash, unlock the option byte, and you get the configuration of the option byte. You can check what is the current level. If this one is different from one, you will just program the option byte and then you will launch the reload of the option byte. Reloading the option byte, HL flash, or be launched, will generate a reset. Let's try this on the target now. So the first step will be to reconnect the jumper to have the debugging link. I connect to my board. I've got a data with error because it was protected, so I remove the ADP. This will erase all my flash. And I clear the buffer here. So now let's go to my blinking example. And in the code, I think about a flag just to activate the ADP level 1 from the software. So it activates this portion of code. So, gladly what I showed you before, I unlock the flash, unlock the option byte, check the current ADP level. If it's different from one, I put it to one. Then I program the option byte, then I will load them. So let's build this application. Now we just program it. Just start. It will be the same. You will see different traces. And here again, I will remove my debugging link. And I will press reset. This time, the application started and activate the ADP level 1. So here in the decade, it was ADP level 0. And you do the OB launch, but it seems not to be setting. I can't do anything. If I do a full power cycle like before, it starts in unindicated was level 1. So again, we've got an issue here. The explanation of this behavior is due to the fact when the debugger is connected, or if we activate the embedded bootloader, there is an internal flag that is set to 1. And if you are an ADP level 1 and this flag is set, then the flash is locked. Unfortunately, this flag is only reset by a power on reset. Or a transition from standby state. You remember it was in the reference manual of the L0. And this is how we solve our issue. Modification of the code is simple. We will replace the OB launch by a transition to standby. First, we will program the ATC to wake up from standby for sure. And then we'll go in standby state. So the final step, I hope so. Let's connect again the debugging link. Connect with cube ID. That I read because we've got ADP level 1. Let's remove it again. Okay, so now flash is empty. I will also clean up the traces. And let's modify our code. So I already prepared a flag for you. And which portion of code is now activated? We don't do anymore the OB launch, but this time we program the ATC. And then we'll go in standby mode. Okay, so I save this modification, compile it again. And let's test this code. So I will just program my binary again. Download is complete. So I will remove my debugging link. And I press the reset button. And this time you have since transitioned to ADP level 1 without any power on reset. Okay, if I connect, sorry, I have to put my jumper again. And if I connect, you've got the confirmation that option byte is activated. Okay. As conclusion to this video, we have seen together how to change the ADP level without power on reset. With just a transition of standby state and a wake up with ATC. Thanks for your attention.