2018-04-04 06:50 PM
Hi.
I am going to set the RDP-Level 1 programmatically.
Here is the test code:Here it stops at the HAL_FLASH_OB_Launch () function.The Reset button does not work in this state.The USB connection will work only if you reconnect it.Of course, the RDP setting was normal at Level 1.I think it works without reconnecting, why am I not?The development board is being tested with the ST Discovery Lora Kit (B-L072Z-LRWAN1).
The same phenomenon occurs with Nucleo-L073RZ.void lora_flash_read_protection_check( void )
{ /* Unlock the Flash to enable the flash control register access *************/ HAL_FLASH_Unlock();/* Unlock the Options Bytes *************************************************/
HAL_FLASH_OB_Unlock(); FLASH_OBProgramInitTypeDef OptionsBytesStruct;/* Get pages write protection status ****************************************/
HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);switch( OptionsBytesStruct.RDPLevel )
{ case OB_RDP_LEVEL_0: PRINTF('RDPLevel : LEVEL 0 \r\n' ); break; case OB_RDP_LEVEL_1: PRINTF('RDPLevel : LEVEL 1 \r\n' ); break; case OB_RDP_LEVEL_2: PRINTF('RDPLevel : LEVEL 2 \r\n' ); break; }uint8_t bRDPSet = false;
/* Check if readoutprtection is enabled ***********************/ if((OptionsBytesStruct.RDPLevel) == OB_RDP_LEVEL_0) { OptionsBytesStruct.OptionType= OPTIONBYTE_RDP; OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1; if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK) { PRINTF('Fail to Read-Out Protection Settings! \r\n'); } else bRDPSet = true;/* Generate System Reset to load the new option byte values ***************/
HAL_FLASH_OB_Launch(); }/* Lock the Options Bytes *************************************************/
HAL_FLASH_OB_Lock(); HAL_FLASH_Lock();}
int main(void)
{
/* STM32 HAL library initialization*/
HW_Main_Init();/* Configure the system clock*/
SystemClock_Config();/* Configure the hardware*/
HW_Init();/* Configure Debug mode */
DBG_Init();/* USER CODE BEGIN 1 */
lora_flash_read_protection_check();
....
}