Implement option byte writing and set brown out level
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
#include <reflow-controller/temp-profile/temp-profile-executer.h>
|
||||
#include <reflow-controller/settings/spi-eeprom.h>
|
||||
#include <reflow-controller/main-cycle-counter.h>
|
||||
#include <stm-periph/option-bytes.h>
|
||||
|
||||
static void setup_nvic_priorities(void)
|
||||
{
|
||||
@@ -211,6 +212,35 @@ static inline void handle_boot_status(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read out the option bytes of the STM32 and program them to the desired values.
|
||||
*
|
||||
* - This function currently forces the brown out level to Level 3.
|
||||
*/
|
||||
static void check_and_program_opt_bytes(void)
|
||||
{
|
||||
struct option_bytes opts;
|
||||
int err;
|
||||
|
||||
/** - Read option bytes */
|
||||
stm_option_bytes_read(&opts);
|
||||
|
||||
|
||||
if (opts.brown_out_level != 0) {
|
||||
/* Set the brown out level to level 3 => highest brown out limit. */
|
||||
opts.brown_out_level = 0;
|
||||
/** - Program the option bytes if brown out level was not set correctly */
|
||||
err = stm_option_bytes_program(&opts);
|
||||
|
||||
/** - If programming failes, enter panic mode */
|
||||
if (err)
|
||||
panic_mode();
|
||||
|
||||
/** - If programming is successful, reset the system to apply new settings */
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup the system.
|
||||
*
|
||||
@@ -220,6 +250,9 @@ static inline void setup_system(void)
|
||||
{
|
||||
float tmp;
|
||||
|
||||
/** - Read the option bytes and if necessary program them to the desired values */
|
||||
check_and_program_opt_bytes();
|
||||
|
||||
/** - Setup the NVIC priorities of the core peripherals using interrupts */
|
||||
setup_nvic_priorities();
|
||||
|
||||
|
Reference in New Issue
Block a user