Skip to main content
AAgar.2
Associate III
July 11, 2020
Solved

Unable to setup RDP on STM32H7

  • July 11, 2020
  • 1 reply
  • 1603 views

I am trying to setup the RDP programmatically on the STM32H7. I am running the code below. All functions return HAL_OK except HAL_FLASH_OB_Launch() which returns HAL_ERROR and its unclear to me why. Any ideas on how to debug this will be helpful as well.

int main(void)
{
 /* MCU Configuration */
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 MX_RTC_Init();
 
 int err = 0;
 
 if ( HAL_FLASH_Unlock() != HAL_OK ) { err = 1 }
	if ( HAL_FLASH_OB_Unlock() != HAL_OK ) { err = 1}
 
	FLASH_OBProgramInitTypeDef ob_struct = {0};
 
	// RDP on Flash bank 2
	ob_struct.Banks = FLASH_BANK_2;
	ob_struct.OptionType = OPTIONBYTE_RDP;
	ob_struct.RDPLevel = OB_RDP_LEVEL_1;
 
	// Program options bytes
	HAL_FLASHEx_OBProgram(&ob_struct);
	if ( HAL_FLASH_OB_Launch() != HAL_OK) { err = 1 }
 
	// Lock memory
	HAL_FLASH_OB_Lock();
	HAL_FLASH_Lock();
 /* USER CODE END Init */

This topic has been closed for replies.
Best answer by TDK

That code doesn't compile.

In addition, err is always 1.

I suspect there is something you've either left out of your post or you're misinterpreting err=1 as something failing.

Also possible is you're in RDP level 2, which can't be changed.

In any case, after I fix the code, it works on my STM32H743 chip.

1 reply

TDK
TDKBest answer
Super User
July 11, 2020

That code doesn't compile.

In addition, err is always 1.

I suspect there is something you've either left out of your post or you're misinterpreting err=1 as something failing.

Also possible is you're in RDP level 2, which can't be changed.

In any case, after I fix the code, it works on my STM32H743 chip.

"If you feel a post has answered your question, please click ""Accept as Solution""."
AAgar.2
AAgar.2Author
Associate III
July 11, 2020

That was a copying mistake. I've set err to 0 initially.

Like I said the the problem is not err = 1. The problem is HAL_FLASH_OB_Launch() which returns HAL_ERROR.

What further information is needed, the code execution from beginning in main is here. I can provide what is needed.

TDK
Super User
July 11, 2020

I don't see how values change in copy/paste. Like I said, the code works once I fix the compile errors. Try the same thing in STM32CubeProgrammer to see if it works there.

"If you feel a post has answered your question, please click ""Accept as Solution""."