2025-12-02 3:35 AM
I assume RDP means Readout Protection. Is there any means for disabling it programmatically with C#? How would it get enabled? I'm pretty sure I'm not enabling it with my program. I tried "–ob rdp=0x0" but got a -1 result, meaning Not Connected. So I'm in a situation where I can't connect because I'm getting -16 (RDP enabled) and I can't disable RDP because I'm not connected
2025-12-02 5:52 AM
RDP level 1 typically also requires a full erase at the same time. See the reference manual for the device you are working with. Yes, it can be done with STM32CubeProgrammer CLI.
2025-12-05 6:19 AM - edited 2025-12-05 6:37 AM
Hi MSSloan1962,
You can disable Read Out Protection programmatically to allow bootloader access by using the read unprotect command "-rdu" in the STM32CubeProgrammer CLI.
This command switches the RDP level from Level 1 to Level 0, which removes the read protection.
I attached below a code snippet in C# that can do this, make sure to check the path of the STM32CubeProgrammer CLI.
using System;
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
string cliExe = @"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe";
string args = "-c port=COMx -rdu"; //Replace x with the correct COM
string workDir = Directory.GetCurrentDirectory();
try
{
if (!File.Exists(cliExe))
{
Console.WriteLine("CLI not found at:\n" + cliExe);
Console.WriteLine("Please verify the path to STM32_Programmer_CLI.exe.");
return;
}
var psi = new ProcessStartInfo
{
FileName = cliExe, // STM32CubeProgrammer Cli executable
Arguments = args,
WorkingDirectory = workDir, // Current directory
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
using var proc = new Process { StartInfo = psi };
proc.Start();
string stdout = proc.StandardOutput.ReadToEnd();
string stderr = proc.StandardError.ReadToEnd();
proc.WaitForExit();
Console.WriteLine("Exit Code: " + proc.ExitCode);
if (!string.IsNullOrWhiteSpace(stdout))
Console.WriteLine("Output:\n" + stdout);
if (!string.IsNullOrWhiteSpace(stderr))
Console.WriteLine("Error:\n" + stderr);
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}
}Kouthair.
2025-12-09 1:48 AM
I think I'm going to have to get my hands on a unit which is responding with -16 when the connection attempt happens to see if this works.
2025-12-09 4:36 AM
I tried the program with a device in normal Comms mode and got:
Exit Code: 1
Output:
-------------------------------------------------------------------
STM32CubeProgrammer v2.11.0
-------------------------------------------------------------------
Serial Port COM7 is successfully opened.
Port configuration: parity = even, baudrate = 115200, data-bit = 8,
stop-bit = 1.0, flow-control = off
Timeout error occured while waiting for acknowledgement.
Timeout error occured while waiting for acknowledgement.
Error: Activating device: KO. Please, verify the boot mode configuration and check the serial port configuration. Reset your device then try again...
Disabling memory read protection...
Timeout error occured while waiting for acknowledgement.
Timeout error occured while waiting for acknowledgement.
Error: Unable to disable memory read protection
C:\Users\msloan\source\repos\TurnOffRDP\bin\Debug\net8.0\TurnOffRDP.exe (process 13576) exited with code 0 (0x0).
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
Then I tried the device in STM Bootloader Mode and got and Exit Code = -1073749819
2025-12-09 7:25 AM
Hello MSSloan1962,
I recommend upgrading to the latest version of STM32CubeProgrammer via this link.
Additionally, please verify whether the MCU is in system bootloader mode.
Alternatively, try setting the RDP level to 0 using ST-Link, if possible, or execute the following command via CLI:
"STM32_Programmer_CLI -c port=COMx -rdu"