2018.06.26 13:34

STM32L4xx에서 BrownOut 설정

 HAL_FLASH_Unlock()을 하지 않고  HAL_FLASH_OB_Unlock()만을 하였더니 계속 에러가 발생하였습니다. 가만 생각해보면 당연한건데 그걸 놓쳤었네요.

전압레벨 설정은 아래와 같고 기본은 1.7V입니다.

ReadOut Protect도 같이 설정되어 있습니다.

 

#define OB_BOR_LEVEL_0            ((uint32_t)FLASH_OPTR_BOR_LEV_0)     /*!< Reset level threshold is around 1.7V */
#define OB_BOR_LEVEL_1            ((uint32_t)FLASH_OPTR_BOR_LEV_1)     /*!< Reset level threshold is around 2.0V */
#define OB_BOR_LEVEL_2            ((uint32_t)FLASH_OPTR_BOR_LEV_2)     /*!< Reset level threshold is around 2.2V */
#define OB_BOR_LEVEL_3            ((uint32_t)FLASH_OPTR_BOR_LEV_3)     /*!< Reset level threshold is around 2.5V */
#define OB_BOR_LEVEL_4            ((uint32_t)FLASH_OPTR_BOR_LEV_4)     /*!< Reset level threshold is around 2.8V */

 




#define USRCONFIGMASK 0xFFFFF8FF

#define BORLEVELMASK 0x00000700

/*******************************************************************************

* Function Name : 

* Parameters    : None

* Return        : None

* Description   : 

*******************************************************************************/

uint32_t Get_USRConfig(void) 

{

FLASH_OBProgramInitTypeDef FLASH_Handle;

/* Read option bytes */

HAL_FLASHEx_OBGetConfig(&FLASH_Handle);

return (FLASH_Handle.USERConfig & USRCONFIGMASK);

}


/*******************************************************************************

* Function Name : 

* Parameters    : None

* Return        : None

* Description   : 

*******************************************************************************/

uint32_t Get_BORConfig(void)

{

FLASH_OBProgramInitTypeDef FLASH_Handle;

/* Read option bytes */

HAL_FLASHEx_OBGetConfig(&FLASH_Handle);


return (FLASH_Handle.USERConfig & BORLEVELMASK);

}

 

void Config_BOR(void)

{

uint32_t BORTimeout = BOR_FLAG_TIMEOUT; 

FLASH_OBProgramInitTypeDef FLASH_Handle; 

HAL_FLASHEx_OBGetConfig(&FLASH_Handle); 

DEBUGPRINT("USERConfig %X\r\n", FLASH_Handle.USERConfig); 

DEBUGPRINT("FLASH_Handle.RDPLevel %X \r\n", FLASH_Handle.RDPLevel); 

if(Get_BORConfig() != BORLEVEL){ 

FLASH_Handle.USERConfig = (Get_USRConfig() | BORLEVEL); 

FLASH_Handle.OptionType = (OPTIONBYTE_USER | OPTIONBYTE_RDP); 

FLASH_Handle.USERType = OB_USER_BOR_LEV; 

FLASH_Handle.RDPLevel = OB_RDP_LEVEL_1; 

while (HAL_FLASH_Unlock() != HAL_OK){ 

if((BORTimeout--) == 0){DEBUGPRINT("HAL_FLASH_Unlock Fail\r\n");break;}

DEBUGPRINT("HAL_FLASH_Unlock\r\n"); 

    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR); 

BORTimeout = BOR_FLAG_TIMEOUT; 

while (HAL_FLASH_OB_Unlock() != HAL_OK){ 

if((BORTimeout--) == 0){DEBUGPRINT("HAL_FLASH_OB_Unlock Fail\r\n");break;}

DEBUGPRINT("USERConfig %X\r\n", FLASH_Handle.USERConfig); 

DEBUGPRINT("FLASH_Handle.RDPLevel %X \r\n", FLASH_Handle.RDPLevel); 

BORTimeout = BOR_FLAG_TIMEOUT; 

while (HAL_FLASHEx_OBProgram(&FLASH_Handle) != HAL_OK){ 

if((BORTimeout--) == 0){DEBUGPRINT("HAL_FLASHEx_OBProgram Fail\r\n");break;}

DEBUGPRINT("HAL_FLASHEx_OBProgram\r\n"); 

BORTimeout = BOR_FLAG_TIMEOUT; 

while (HAL_FLASH_OB_Lock() != HAL_OK){ 

if((BORTimeout--) == 0){DEBUGPRINT("HAL_FLASH_OB_Lock Fail\r\n");break;}

DEBUGPRINT("HAL_FLASH_OB_Lock\r\n"); 

BORTimeout = BOR_FLAG_TIMEOUT; 

while (HAL_FLASH_Lock() != HAL_OK){ 

if((BORTimeout--) == 0){DEBUGPRINT("HAL_FLASH_Lock Fail\r\n");break;}

DEBUGPRINT("HAL_FLASH_Lock\r\n"); 

}

}

}

Posted by 초보 HW 엔지니어 로망와니

댓글을 달아 주세요