 Hello and welcome to this MOOC about STM32 U5-K8 RDP. During this hands-on, we will learn how to provision OM keys. We will see together how we do a K8 RDP regression, including from RDP level 2, and we will see how to remove and modify those keys. But first, let's check together the setup we will use. For this hands-on, we will use a Nucleo U575 ZDQ and the GPIO toggle trust zone code example delivered in the STM32 U5. This is a trust zone application with two some lead blinking from secure and non-secure application. In the material of this hands-on, we provide you a pre-compiled binaries. First, we need to activate the trust zone and configure the first bank of flash as secure and the second bank as non-secure thanks option byte. Then we will flash the secure and non-secure binaries. During this hands-on, we will use a STM32 Q-Programmer version 2.9.0 in common line. Please ensure the STL firmware of your Nucleo is up to date according to the Q-Programmer version used. As previously stated, we will use STM32 Q-Programmer in common line. Here is the list of the common line we will use to achieve our prerequisites. First, we will set option byte. First, I display them. I set the trust zone one, then the flash automatic. Then the two commands to flash the non-secure binaries and the secure binaries. The last command is just to load the firmware upgrade of your STL if needed. First, I plug my Nucleo U575 ZD. I will first load the update of the STL firmware just to be sure I would say in my common line. I'm just in the folder of the Q-Programmer bin. This will open this window and I can open in the update mode. I can see the current version is v3g8m3 and I can update it to the last one. Let's do this upgrade. Ok, the upgrade finished successfully. Now I'm ready how it's going to work. Let's first display the current option byte. The common line for the Q-Programmer. The port is software debugging link. Mode under reset and I do option byte display. Just this basic command. So what is the current configuration? LDP level 0. Truezone is not enabled. So I need to enable it. I can't see how I would say the flash watermark because the Truezone is not yet enabled. So first I will enable Truezone. Now if I display again, I will say my option byte. Truezone is now enabled of course. But now I can found the flash watermark. As you can see the first bank is un secure. And the second bank is also secure. So I have to modify this. So in this command I set again the first one just to ensure that everything is in line. So the first bank is secure and the second bank is not secure. So I will take this command. Oops, sorry. And now configuration should be ok. Then I will flash the binaries. So first the non secure one. And then the secure one. Sorry. And now if I press reset I should have a lead blinking. Which is the case. So I would say that now we are ready to start our hands on. This hands on scenario will have 7 steps. The first step will be the key provisioning. That means to write in the option byte the OEM keys. Then we will change the RDP level from level 0 to level 2. Now thanks to the OEM2 key we are able to do the regression from level 2 to level 1. And then from the level 1 to the level 0.5. To be able to come back to level 0 we need to go through the level 1. And now thanks to the OEM1 key we are able to do the regression to level 0. The last step will be to remove the OEM keys. Let's start with the key provisioning. To check if our device have been already provisioned we can check the OEM log bit in the flash and SSR register. This is an extract from the reference manual of the U5. So if I check the flash and SSR register I should have 0, that means no OEM key are there. And to provision the key we've got this basic command line with Q programmer, with a lock AIDP parameter and then the value of the OEM1 key. Then we can check again the flash and SSR register. So first let's check the flash and SSR register. So I would just display the correct address I would say. If we change this to 0, that means our bit 18 or 19, 0. No OEM key have been provisioned yet. So I can just now do the provisioning of the OEM1 key with this value. Ok? And we have to remind this one because we can read it back after. So we just load the command. And as you can see, lock AIDP1 password successfully done. It was distributed. Now let's check again the flash and SSR register. And now you can see that the bit 18 has been set to 1. So we know that the target has been provisioned properly. For the OEM2 key is quite similar. We just change the parameter lock AIDP1 to lock AIDP2. And we set a different value for the OEM2 key. So the provisioning of the second key. I check again the flash and SSR register just to be sure. For the moment just the OEM1 key have been provisioned. So I will provision the OEM2 keys with this specific value. And if I check again the SSR, as you can see now the bit 19 has been set to 1. So we have finished the provisioning. The second step is to activate AIDP level 2. And please ensure you properly provision OEM2 key before this step. Because if you don't do this, you will break your device. So to switch on AIDP level 2 just to write in the option byte. I would say in a classical way. I will take the opportunity here to experiment the command to get the authentication ID of the device. Obviously the value that you will see on your device will be different from the one I'm using here. So now we will move to AIDP level 2. For sure, it's not something we do so much often. And as we are provisioned, we are sure that we will manage to recover the board. So let's launch it. Ok, you've got this error because it can't reconnect for sure. As we have a specific mode with AIDP level 2. The LED are not blinking. I need to do a power on reset. So I unplug this jumper or you can just unplug and re-plug the USB cable. In this mode, I can still get the authentication ID. So I've got this specific command. And here you can see, even if there is some error, you can see here the debank authentication ID. Now let's trigger the regression from AIDP level 2 to AIDP level 1. So as you can see in the command line to unlock AIDP level 2, we need to give the OEM2 key value that we provisioned previously. On this command has been launched, the regression will be automatically set. You will have some error message due to the SGM32Q programmer can't connect anymore on such kind of thing, but you can ignore them. So let's experiment this. So let's unlock our AIDP level 2 and do the regression to AIDP level 1. So for this, I use this command and you can see unlock AIDP with the OEM2 key. My LED is not blinking. That means I need to do a power on reset. So before starting, everything is fine. I can launch a command right now. So you've got some error message, but in fact, if I just plug and plug, and if I check AIDP, I was able to connect. And as you can see, AIDP level is FF with mean level 1. The regression was done automatically. So we managed to recover from AIDP level 2, and it was for the first time on a SGM32. The next step is a regression from level 1 to level 0.5. Remember, this means that the non-secure application will be automatically errors. So here we will need to use the OEM2 key to be able to do this regression. So for the regression from level 1 to level 0.5, first we need to unlock the AIDP regression and then to set the option by to the correct value. So here we have two commands. One to unlock the regression and give the OEM2 key value. And then we can set the AIDP option by to 55, which is 0.5. To finish just this step, we will flash again the non-secure application which have been automatically errors by this regression. So let's unlock AIDP 0.5. So unlock AIDP 1 with the OEM2 key value. Now I do the regression of the AIDP level to 0.5 which imply the errors of the non-secure application. Here I can do an OB display if you want, just to show you what are the value. You can see we are in AIDP 0.5 now. This trace is not correct. So I will flash again my non-secure application because if I just do a power hun reset here as you can see no lead blinking at all. But if I flash again my non-secure application and do a power hun reset, the lead blinking is there. Now I want to come back to AIDP level 0 but for this we must first go to AIDP level 1. So this is a basic command just to set the option byte. Nothing specific here. So I think I will do a step 5 and a step 6 at the same time on my target. So on the last key AIDP regression we have not tested yet is the regression from level 1 to level 0. Thanks to the OEM1 key which imply a full flash mass errors. So to command is needed for this regression first we need to unlock the AIDP regression with the unlock AIDP 1 parameter and the OEM1 key value. Then we can set the option byte AIDP to AA which is level 0. So to do the regression to level 0 I have to go to the AIDP level 1 first. So I am switching to AIDP level 1. Now the flash is locked as we are switching if I do a power hun reset my lead is blinking. Now I will unlock first the AIDP 0 regression so unlock AIDP 1 and I give the OEM1 key. Now I can trigger the regression to level 0 which imply a full flash mass errors. If I check the option byte now you can see that your with AIDP level 0 and the flash is empty. The last step is to remove the OEM keys. So here removing a key in fact is to set the value to FFFF ok? So I will just check the flash and SSR register before I will set the OEM1 key to FFFF then I can check the flash and SSR register after. To remove the OEM2 keys similar you just need to change the parameter lock AIDP1 to lock AIDP2 and set the value to FFFF. So if I read the flash and SSR register so you've got the bit 19 and 18 that have been set because the OEM keys are here. If I eras the OEM1 key eras in fact set it to the value FFFF so if I do this and if I check again the flash and SSR register as you can see the bit has changed so it was a bit 18 if I will remember and if I do the same things for the OEM2 key so just the parameter change then if I check now no more OEM keys so this is the way how to remove the OEM keys and you can set a new value if you want or keep this AIDP legacy mode. We are reaching the end of this presentation so I would like to point out some useful documentation the reference manual and also the AN5347 where you can find many information about the KID AIDP so we have seen together how U5KID AIDP allows to control the regression of the AIDP from any level including the level 2 and this in a secure way you need to know the OEM key value to be able to do a regression an important point this does not impact the level of protection of the flash content I hope you like this video and thank you for your attention