OpenOCD Stlink set read protection over STM32F103

Hello,
I m searching how to set the read data protection on a stm32f103. I m using a stlink over SWD. Seems firmware is uploaded via OpenOCD.
I found how to set te RDP byte with these OpenOCD commands :

# Set RDP to level 1
init
reset halt
stm32f1x lock 0
reset halt
exit

But I don’t really kown how to modify configuration from platformio to pass this parameter to openOCD.
Could you drive me ? Thanks in advance.

regards,

Aurélien

So here is the solution if someone search it :
You have to use custom upload script as follow :

in your platformio.ini put :

extra_scripts = extra_script.py
upload_protocol = custom

Create file extra_script.py near platformio.ini which contains :

Import("env", "projenv")
platform = env.PioPlatform()
env.Prepend(
    UPLOADERFLAGS=["-s", platform.get_package_dir("tool-openocd")+"/scripts"]
)
env.Append(
    UPLOADERFLAGS=["-f", "interface/stlink.cfg"]
)
env.Append(
    UPLOADERFLAGS=["-c", "transport select hla_swd"]
)
env.Append(
    UPLOADERFLAGS=["-f", "target/stm32f1x.cfg"]
)
env.Append(
    UPLOADERFLAGS=["-c", "program {$SOURCE} verify reset;reset halt;stm32f1x lock 0;reset halt; shutdown"] 
)

env.Replace(
    UPLOADER="openocd",
    UPLOADCMD="$UPLOADER $UPLOADERFLAGS"
)

Sorry, i’m not an expert programmer and i’m new to stm platform… if i use this script firmware is loaded correctly (it seems) but it not start at all. I’m sure i’m missing something… Which are all the steps needed to have it working?

Ok solved! A complete off/on (POR) cycle was requested after programming with read protection. A normal reset with button is not enough.
I adjusted py files: there was wrong quotation marks, and added start memory address 0x08000000 to prevent “No flash bank found for address 0x00000000”

Import("env", "projenv")

platform = env.PioPlatform()

env.Prepend(

UPLOADERFLAGS=["-s", platform.get_package_dir("tool-openocd")+"/scripts"]

)

env.Append(

UPLOADERFLAGS=["-f", "interface/stlink.cfg"]

)

env.Append(

UPLOADERFLAGS=["-c", "transport select hla_swd"]

)

env.Append(

UPLOADERFLAGS=["-f", "target/stm32f1x.cfg"]

)

env.Append(

UPLOADERFLAGS=["-c", "program {$SOURCE} 0x08000000 verify reset;reset halt;stm32f1x lock 0;reset halt; shutdown"] 

)

env.Replace(

UPLOADER="openocd",

UPLOADCMD="$UPLOADER $UPLOADERFLAGS"

)