In general the memory protection scheme of STM32 mcu is synthetized in the image below.
Attention to use the level 2 because is irreversible.
See this presentation that is for STM32WB but the concepts are the same for other STM32 mcu.
Other interesting information are in the links below.
- AN5156 – Introduction to STM32 microcontrollers security
- Protect and control software stored in flash memory
- Microcontroller’s Firmware Protection
- AN4992 – Overview secure firmware install (SFI)
- AN4852 – Programming an external Flash memory using the UART bootloader built-in STM32 microcontrollers
- STM32F7 cryptographic processor (CRYP)
- OCTOSPI on-the-fly decryption. This technology is present on some STM32 like the STM32L5 (Core M33), see for example the STM32L562