cancel
Showing results for 
Search instead for 
Did you mean: 

OTA, Application Read Protection and PCROP

Daniel L
Associate III

Hi, I have a project where I need to read protect my application code. The problem with RDP is that it would erase the entire flash (including OTA). I assume this problem is to be solved by using PCROP on the OTA code. I have attempted to protect the memory from 0x0800 0000 to 0x0800 6FFF using the following commands in STM32Cube Programmer CLI. This results in the OTA code not running at all and not being read/write protected at all. What am I missing?

SET PROG="C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin"
SET BIN=STM32WB55_OTA.bin
SET ADDRESS=0x08000000
SET LOC="%cd%"
 
cd %PROG%
 
STM32_Programmer_CLI.exe -c port=SWD -w ""%LOC%\%BIN%"" 0x08000000 -ob pcrop1a_end=0x0D pcrop1a_strt=0x00 pcrop_rdp=0
 
pause

Thanks,

Daniel

4 REPLIES 4
Remi QUINTIN
ST Employee

​I dont see any obvious issue with your commands.

Do you get an error when programming the Flash memory?

Could you write the binary first and set the PRCOP options bytes then?

Daniel L
Associate III

Hi Remi, I have tried to split the command into two as follows with the same result. There are no error messages.

STM32_Programmer_CLI.exe -c port=SWD -w ""%LOC%\%BIN%"" 0x08000000
STM32_Programmer_CLI.exe -c port=SWD -ob pcrop1a_end=0x0D pcrop1a_strt=0x00 pcrop_rdp=0
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.1.0
      -------------------------------------------------------------------
 
ST-LINK SN  : 53FF6E065177485750520787
ST-LINK FW  : V2J31S7
Voltage     : 2.62V
SWD freq    : 4000 KHz
Connect mode: Normal
Reset mode  : Software reset
Device ID   : 0x495
Device name : STM32WBxx
Flash size  : 512 KBytes
Device type : MCU
Device CPU  : Cortex-M0+/M4
 
 
 
Memory Programming ...
Opening and parsing file: stm32wb55_ota.bin
  File          : stm32wb55_ota.bin
  Size          : 17268 Bytes
  Address       : 0x08000000
 
 
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 4]
Download in Progress:
██████████████████████████████████████████████████ 100%
 
File download complete
Time elapsed during download operation: 00:00:00.652
 
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin>STM32_Programmer_CLI.exe -c port=SWD -ob pcrop1a_end=0x0D pcrop1a_strt=0x00 pcrop_rdp=0
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.1.0
      -------------------------------------------------------------------
 
ST-LINK SN  : 53FF6E065177485750520787
ST-LINK FW  : V2J31S7
Voltage     : 2.62V
SWD freq    : 4000 KHz
Connect mode: Normal
Reset mode  : Software reset
Device ID   : 0x495
Device name : STM32WBxx
Flash size  : 512 KBytes
Device type : MCU
Device CPU  : Cortex-M0+/M4
 
 
UPLOADING OPTION BYTES DATA ...
 
  Bank          : 0x00
  Address       : 0x58004020
  Size          : 104 Bytes
 
██████████████████████████████████████████████████ 100%
 
 
PROGRAMMING OPTION BYTES AREA ...
Warning: Option Byte: pcrop_rdp, value: 0x0, was not modified.
 
  Bank          : 0x00
  Address       : 0x58004020
  Size          : 104 Bytes
 
██████████████████████████████████████████████████ 100%
 
Reconnecting...
Reconnected !
 
 
UPLOADING OPTION BYTES DATA ...
 
  Bank          : 0x00
  Address       : 0x58004020
  Size          : 104 Bytes
 
██████████████████████████████████████████████████ 100%
 
OPTION BYTE PROGRAMMING VERIFICATION:
 
Option Bytes successfully programmed

Remi QUINTIN
ST Employee

Did you recompile the stm32wb55_ota.bin with the right options?

It needs to be compile for execution only.

Moreover, be sure that any data section is located outside the protected area as those data would become unaccessible once the protection is set.​

What compile options are required? I have tried adding the option -mpure-code to the compiler flags.

I do not believe that the code is reading any memory in the protected area. It is a modified version of the OTA example application provided in STM32Cube_FW_WB_V1.2.0.

The strange thing is that STM32Cube Programmer can seemingly write over the PCROP memory areas repeatedly, running the above bat file multiple times.