cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to setup RDP on STM32H7

AAgar.2
Associate III

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 */

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

4 REPLIES 4
TDK
Guru

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
Associate III

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.

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".

Oh wow it works on your STM32H743, not sure how I missed that critical line.

You just copied this code into your main? Did you do any modifications to the STM32Cube configuration (.ioc file)?

I will create and try in a new project shortly.

Appreciate your support TDK.