쓰기 방지
#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08000000) /* Base @ of Page 0, 2 Kbytes */
#define ADDR_FLASH_PAGE_127 ((uint32_t)0x0803F800) /* Base @ of Page 127, 2 Kbytes */
#define FLASH_WRP_START_ADDR ADDR_FLASH_PAGE_0 /* Start @ of user Flash area */
#define FLASH_WRP_END_ADDR ADDR_FLASH_PAGE_127 /* End @ of user Flash area */
#define START_PAGE 0
/*******************************************************************************
* Function Name :
* Parameters :
* Return :
* Description :
*******************************************************************************/
uint32_t GetPage_FLASH(uint32_t Addr)
{
uint32_t page = 0;
if (Addr < (FLASH_BASE + FLASH_BANK_SIZE)){
/* Bank 1 */
page = (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
}
else{
/* Bank 2 */
page = (Addr - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE;
}
return page;
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void Config_WRP(void)
{
uint32_t StartPage = 0, EndPage = 0;
FLASH_OBProgramInitTypeDef FLASH_Handle;
uint32_t RDPTimeout = BOR_FLAG_TIMEOUT;
FLASH_Handle.WRPArea = OB_WRPAREA_BANK1_AREAA;//OB_WRPAREA_BANK1_AREAB;
StartPage = GetPage_FLASH(FLASH_WRP_START_ADDR);
EndPage = GetPage_FLASH(FLASH_WRP_END_ADDR);
HAL_FLASHEx_OBGetConfig(&FLASH_Handle);
if(FLASH_Handle.WRPStartOffset != START_PAGE){
FLASH_Handle.OptionType = OPTIONBYTE_WRP;
FLASH_Handle.WRPStartOffset = StartPage;
FLASH_Handle.WRPEndOffset = EndPage;
while (HAL_FLASH_Unlock() != HAL_OK){
if((RDPTimeout--) == 0){break;}
DEBUGPRINT("HAL_FLASH_Unlock\r\n");
}
RDPTimeout = BOR_FLAG_TIMEOUT;
while (HAL_FLASH_OB_Unlock() != HAL_OK){
if((RDPTimeout--) == 0){break;}
DEBUGPRINT("HAL_FLASH_OB_Unlock\r\n");
}
RDPTimeout = BOR_FLAG_TIMEOUT;
while (HAL_FLASHEx_OBProgram(&FLASH_Handle) != HAL_OK){
if((RDPTimeout--) == 0){break;}
DEBUGPRINT("HAL_FLASHEx_OBProgram\r\n");
}
RDPTimeout = BOR_FLAG_TIMEOUT;
while (HAL_FLASH_OB_Launch() != HAL_OK){
if((RDPTimeout--) == 0){break;}
DEBUGPRINT("HAL_FLASH_OB_Launch\r\n");
}
RDPTimeout = BOR_FLAG_TIMEOUT;
while (HAL_FLASH_OB_Lock() != HAL_OK){
if((RDPTimeout--) == 0){break;}
DEBUGPRINT("HAL_FLASH_OB_Lock\r\n");
}
RDPTimeout = BOR_FLAG_TIMEOUT;
while (HAL_FLASH_Lock() != HAL_OK){
if((RDPTimeout--) == 0){break;}
DEBUGPRINT("HAL_FLASH_Lock\r\n");
}
}
}
'초보의 아웅다웅 설계하기 > STM32' 카테고리의 다른 글
SW6STM에서 고정위치에 바이너리 라이팅하기 (0) | 2020.05.20 |
---|---|
인터럽트 벡터 위치 확인과 변경 (0) | 2020.03.13 |
STM32 PID 제어 (0) | 2020.01.16 |
STM32H750 ReadProtection, BrownOutReset 설정 (0) | 2020.01.08 |
STM32H750 내부 온도 센서 값 읽기 (0) | 2020.01.06 |