cancel
Showing results for 
Search instead for 
Did you mean: 

The option bytes are not being written in STM32L433

Seiji_Hiraki
Associate

I would like to enable write protection via an option byte.

However, HAL_FLASH_OB_Launch() hangs, and even if the CPU is reset afterwards, the option byte is not rewritten.

This issue occurs with both combinations: my board + J-Link or Nucleo + ST-Link.

I have the following function to set the option bytes:

 

void set_write_protection(uint32_t WRPArea, uint32_t start, uint32_t end)
{
    FLASH_OBProgramInitTypeDef OBInit;
    HAL_StatusTypeDef status;

	HAL_FLASH_Unlock();
	HAL_FLASH_OB_Unlock();
	OBInit.WRPArea = WRPArea;
    HAL_FLASHEx_OBGetConfig(&OBInit);
    if (OBInit.WRPStartOffset != start || OBInit.WRPEndOffset != end) {
    	OBInit.WRPStartOffset = start;
    	OBInit.WRPEndOffset = end;
        OBInit.OptionType = OPTIONBYTE_WRP;
        status = HAL_FLASHEx_OBProgram(&OBInit);
        if (status != HAL_OK) {
            return;
        }
    	HAL_FLASH_OB_Launch();
    }
	HAL_FLASH_OB_Lock();
	HAL_FLASH_Lock();
}

void set_area1_write_protection(uint8_t enable)
{
	if (enable)
		set_write_protection(OB_WRPAREA_BANK1_AREAA, 0x00, 0x20);
 	else
		set_write_protection(OB_WRPAREA_BANK1_AREAA, 0xFF, 0x00);
}

 

Is there any way to successfully enable Write Protection?

 

0 REPLIES 0