HAL Library 22- BOR for STM32Fxxx
BOR (Brown Out Reset) is a way to reset microcontroller if target voltage is below voltage we set. When this happens, MCU is in reset state until voltage comes above selected voltage. STM32F4/7xx devices have 4 possible BOR values, which are described later or in API documentation.
Library
Features
- Set Brown-Out detection value
- Get Brown-Out detection value
Dependencies
- HAL
- TM
- STM32Fxxx HAL
- defines.h
Functions and enumerations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/** * @brief Brown-out levels available */ typedef enum { TM_BOR_Level_None = OB_BOR_OFF, /*!< Disable brown-out detection */ TM_BOR_Level_1 = OB_BOR_LEVEL1, /*!< Set brown out detection level 1 */ TM_BOR_Level_2 = OB_BOR_LEVEL2, /*!< Set brown out detection level 2 */ TM_BOR_Level_3 = OB_BOR_LEVEL3 /*!< Set brown out detection level 3 */ } TM_BOR_Level_t; /** * @brief Result enumeration for settings */ typedef enum { TM_BOR_Result_Ok = 0x00, /*!< Everything OK */ TM_BOR_Result_Error /*!< An error has occurred */ } TM_BOR_Result_t; /** * @} */ /** * @defgroup TM_BOR_Functions * @brief Library Functions * @{ */ /** * @brief Sets new brown-out detection level * @note New value will be set only in case current value is different than user wants * @param BORValue: Value level for brown-out detection. This parameter can be a value of @ref TM_BOR_Level_t enumeration * @retval Member of @ref TM_BOR_Result_t */ TM_BOR_Result_t TM_BOR_Set(TM_BOR_Level_t BORValue); /** * @brief Gets current brown-out detection level * @param None * @retval Member of @ref TM_BOR_Level_t */ TM_BOR_Level_t TM_BOR_Get(void); /** * @} */ |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
/** * Keil project example for setting brown-out level * * Before you start, select your target, on the right of the "Load" button * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 * @conf PLL parameters are set in "Options for Target" -> "C/C++" -> "Defines" * @packs STM32F4xx/STM32F7xx Keil packs are requred with HAL driver support * @stdperiph STM32F4xx/STM32F7xx HAL drivers required */ /* Include core modules */ #include "stm32fxxx_hal.h" /* Include my libraries here */ #include "defines.h" #include "tm_stm32_disco.h" #include "tm_stm32_bor.h" int main(void) { /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Try to set brown-out to level 3 */ if (TM_BOR_Set(TM_BOR_Level_3) == TM_BOR_Result_Ok) { /* Brown-out level is set OK */ TM_DISCO_LedOn(LED_GREEN); } else { /* Problems with setting brown-out detection */ TM_DISCO_LedOn(LED_RED); } while (1) { /* Do nothing */ } } |
Project is available on Github, download all libraries below.
STM32 libraries based on STM32Fxxx HAL drivers.
Recent comments