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"
2026-01-13 7:37 AM
Hey there MSSloan1962!
Any updates on this matter?
Kouthair
2026-01-14 4:55 AM
I updated STM Electronics API to latest version by installing V2.21.0 of STM Cube Programmer. So far I haven't had a feedback as to whether that fixed the problem or not.
2026-01-20 3:31 AM
The customer is still getting the RDP Enabled error (-16). I've put the device into BootLoader mode and tried the "STM32_Programmer_CLI -c port=COM7 -rdu", although COM7 has disappeared due to the device being put into Bootloader Mode. I get the output from the STM32_Programmer_CLI program:
Exit Code: -1073741819
Output:
-------------------------------------------------------------------
STM32CubeProgrammer v2.21.0
-------------------------------------------------------------------
Error: Cannot open port COM7, it may be used by another application or port name is invalid.
Disabling memory read protection...
Warning: Connection to UART device is lost
Warning: Connection to UART device is lost
Does the device need to be in Bootloader more or not for the -rdu to work?
Does a device need to be connected for the readUnprotect() to work? Might be in a catch-22 situation. I want to disable RDP but I can't connect because RDP enabled.
2026-01-20 4:17 AM
Another thing I've noticed is that where connection is failing, the messages sent when connecting are different:
The following messages are generated by the CubeProgrammer_API.dll when the Connect routine is called:
USB speed : Full Speed (12MBit/s)
Manuf. ID : STMicroelectronics
Product ID : STM32 BOOTLOADER
SN : 205736983432
DFU protocol: 1.1
Board : --
Device ID : 0x451
Connection works (Error = 0)
I notice that on the log where the connections are failing, the messages are slight corrupted:
USB speed : Full Speed (12MBit/s)
Manuf. ID :
Product ID : STMicroelectronics
SN : STM32 BOOTLOADER
DFU protocol: 1.1
Board : --
Device ID : unknown
Connection fails (Error = -16)
Could this have anything to do with it?