Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ static uint16_t convertAdcToMilliamps(uint8_t adc_8bit, uint16_t sense_resistor_
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/**
* @brief Disable Brown-Out Reset (BOR) if it is currently enabled in the option bytes.
*/
static void disable_bor_if_enabled(void) {
if (FLASH->OPTR & FLASH_OPTR_BOR_EN) {
FLASH_OBProgramInitTypeDef ob_cfg = {0};

HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();

ob_cfg.OptionType = OPTIONBYTE_USER;
ob_cfg.USERType = OB_USER_BOR_EN;
ob_cfg.USERConfig = OB_BOR_DISABLE;

HAL_FLASHEx_OBProgram(&ob_cfg);

/* Launch option byte reload - this triggers a system reset */
HAL_FLASH_OB_Launch();

/* Should not reach here as OB_Launch resets the MCU */
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
}
}

/* USER CODE END 0 */

/**
Expand All @@ -117,6 +142,9 @@ int main(void)

/* USER CODE BEGIN Init */

/* Disable BOR in option bytes if it is currently enabled */
disable_bor_if_enabled();

/* USER CODE END Init */

/* Configure the system clock */
Expand Down
Loading