Question
Launching option bytes bricks the MCU
Hi,
I am trying to set the write protection on my STM32G071 uC. I found the explanation here on how to do it in code. However once HAL_FLASH_OB_Launch is executed, the debugger loses connection and the uC is bricked. I tried to get a connection again via ST-Link Utility and STM32CubeProgrammer to no avail. I've tried it on a Nucleo and on a custom board.
Below you can see my code, it really isn't much different from the one on the site.
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* unlock flash and option bytes*/
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
/* read current config and set WRP settings */
HAL_FLASHEx_OBGetConfig(&ob);
ob.OptionType = OPTIONBYTE_WRP;
ob.WRPArea = OB_WRPAREA_ZONE_A;
ob.WRPStartOffset = 14;
ob.WRPEndOffset = 15;
if ( HAL_OK != HAL_FLASHEx_OBProgram(&ob) )
{
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
for(;;);
}
HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
HAL_FLASHEx_OBGetConfig(&ob);Anybody have an idea what could be going wrong?
