2020-07-11 08:20 AM
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 */
Solved! Go to Solution.
2020-07-11 08:33 AM
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.
2020-07-11 08:33 AM
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.
2020-07-11 08:36 AM
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.
2020-07-11 09:09 AM
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.
2020-07-11 10:38 AM
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.