 Hello and welcome to this presentation of the STM32 System Memories Protection. It will cover the different means for protecting code and or data from external and or internal attacks. Software providers may need to protect their software intellectual propriety from malicious users or from intrusive attacks. For this purpose, STM32L4 microcontrollers provide a couple of features for protecting code and or data located in either flash memory, SRAM2, or backup registers. These features can prevent the reading or writing of code and or data through the JTAG debugger, end user code, or SRAM Trojan code. The following means are provided for code protection purposes. RDP, Readout Protection, PC Rop, Proprietary Code Readout Protection, and WRP, Write Protection. These features are configurable via the STM32L4 option bytes. RDP prevents flash memory access through the JTAG for all flash memory. PC Rop prevents read access of configurable flash memory or SRAM areas performed by the CPU executing malicious third party code, Trojan Horse. WRP prevents accidental or malicious write erase operations. Let's take a closer look at the details of the Readout Protection feature. The STM32L4 Readout Protection feature offers three levels of protection for all SRAM2 and flash memory as well as the backup registers. Level 0 means no protection. This is the factory default. Read, write, and erase operations are permitted in the SRAM2 and flash memory as well as the backup registers. Option bytes are changeable in Level 0. Level 1 ensures total read protection of the chip's memories which includes the flash memory and the backup registers as well as a new feature to the STM32 family, the SRAM2 content. Whenever a debugger access is detected or boot mode is not set to a flash memory area, any access to the flash memory, the backup registers, or to the SRAM2 generates a system hard fault which blocks all code execution until the next power-on reset. Please note that option bytes can still be modified in Level 1. Level 2 provides the same protection features for the SRAM2, flash memory, and backup registers as described for Level 1. However, there are three major differences. The JTAG SWD debugger connection is disabled even at the ST factory to ensure that there are no back doors. The boot mode is forced to user flash memory regardless of what the boot 01 settings are and Level 2 is permanent. Once set to Level 2, there is no going back. RWP-WRP option bytes can no longer be changed as well as all the other option bytes. Changing the level of RDP protection is only permitted when the current protection level is 1. Changing the protection level from 1 to 0 will automatically erase the entire user flash memory, SRAM2, and backup registers. This table summarizes the different types of access authorized for the flash memory, backup registers, and SRAM2 according to the readout protection or RDP level configured boot mode and debug access as previously discussed. In summary, when RDP is set to Level 0, no protection mechanism is active and all memories can be read and modified. When RDP is other than Level 0, if the device is configured to boot from the user flash memory, then the user flash memory, backup registers, and SRAM2 can be read or modified regardless of the RDP level. The system flash memory can be read only. The option bytes can be read only when the RDP is set to Level 2. Otherwise, if the device is not configured to boot from the user flash memory or if a debugger access is detected, then almost all memories are not accessible except the system flash memory which can only be read in Level 1 and option bytes which can be read or modified in Level 1. Let's look at the transitions possible between each readout protection level. As already mentioned, STM32L4MCUs have three RDP levels. Level 0 means there is no memory protection and option bytes can be modified. From Level 0, the device can move to Level 1 or Level 2. Level 1 ensures the memory protection while keeping debug access enabled. From Level 1, the device can move to Level 0 or Level 2. Regression to Level 0 will cause a flash memory mass arrays. Level 2 ensures the memory protection the same as Level 1, but completely disables JTAG SWD debug access. Level 2 is a permanent state and moving to another RDP level is not possible. Let's take a closer look at the details of the Proprietary Code Readout Protection or PC Rop and how it's different from RDP. PC Rop means Proprietary Code Readout Protection. Why PC Rop? Proprietary Code Readout Protection is basically a way to protect the confidentiality of third-party software intellectual property code independently of the RDP level setting. Third parties may develop and sell specific software IPs for STM32 microcontrollers and original equipment manufacturers may use them when developing their own application code. Proprietary Code Readout Protection helps protect the confidentiality of third-party IPs and protects software intellectual property against malicious users. In other words, PC Rop consists of preventing malicious software or debuggers from reading sensitive code. The protected area is Execute Only and can only be reached by the STM32 CPU as an instruction code while all other accesses, DMA, debug, and CPU data read, write, and erase are strictly prohibited. This means that the code to be protected must be compiled using a specific compiler option. For example, dash execute underscore only for keel tools. The proprietary code readout protected areas in flash memory are defined through the option bytes. The PC Rop feature is improved on the STM32 L4 devices. Two separate PC Rop areas can now be set independently, one per bank, each one defined by a start and end address with a granularity of 64 bits. Note that once a PC Rop area is configured, its size can only be increased. Once the PC Rop areas have been defined, the only way to disable this protection feature is to change the RDP protection level from 1 to 0, which erases the entire flash memory. STM32 L4 microcontrollers have a new feature that prevents the code in the PC Rop areas from being erased during the regression operation. By setting the PC Rop RDP bit in the option bytes, the code in the PC Rop areas will not be lost. To further explain the execute only meaning of the PC Rop, the PC Rop is a sub-state of the RDP. The PC Rop is designed to prohibit other code executing on the STM32 from reading the flash memory. This is not the same as the RDP, where the protection targets external worlds. When the PC Rop is enabled, the AHB only allows the instruction bus to work, so code can only be executed. The data bus can't access that flash memory. Once the development phase is completed, the PC Rop can then be turned into an RDP setting, level 1. In this case, the external world is limited to read only, but the PC Rop settings for specific sectors still applies to all masters trying to read that code. Now let's take a closer look at the details of the write protection settings of the STM32 L4. The flash memory write protection mechanism is designed to prevent unwanted write access to defined areas in flash memory, such as boot loader or calibration constants that do not change. The write protection areas are defined through the option bytes. The user can define up to four different write protected flash memory areas independently, two per bank. Each of the four flash memory areas are defined by a start and end address with a granularity of 2 kilobytes. The size of the write areas can be modified whenever the RDP level is not set to level 2. Erase operations are treated as write operations on write protected areas, meaning they are not allowed. The write protection area of the SRAM2 is configured through the system configuration registers. Only one area can be set using the start and end address registers. The address granularity is 2 kilobytes. As with the flash memory, write operations on the protected area are not permitted. When regressing from RDP level 1 to level 0, the entire content of SRAM2 is erased.