inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1 /**
NYX 0:85b3fd62ea1a 2 ******************************************************************************
NYX 0:85b3fd62ea1a 3 * @file stm32f4xx_hal.c
NYX 0:85b3fd62ea1a 4 * @author MCD Application Team
NYX 0:85b3fd62ea1a 5 * @version V1.7.1
NYX 0:85b3fd62ea1a 6 * @date 14-April-2017
NYX 0:85b3fd62ea1a 7 * @brief HAL module driver.
NYX 0:85b3fd62ea1a 8 * This is the common part of the HAL initialization
NYX 0:85b3fd62ea1a 9 *
NYX 0:85b3fd62ea1a 10 @verbatim
NYX 0:85b3fd62ea1a 11 ==============================================================================
NYX 0:85b3fd62ea1a 12 ##### How to use this driver #####
NYX 0:85b3fd62ea1a 13 ==============================================================================
NYX 0:85b3fd62ea1a 14 [..]
NYX 0:85b3fd62ea1a 15 The common HAL driver contains a set of generic and common APIs that can be
NYX 0:85b3fd62ea1a 16 used by the PPP peripheral drivers and the user to start using the HAL.
NYX 0:85b3fd62ea1a 17 [..]
NYX 0:85b3fd62ea1a 18 The HAL contains two APIs' categories:
NYX 0:85b3fd62ea1a 19 (+) Common HAL APIs
NYX 0:85b3fd62ea1a 20 (+) Services HAL APIs
NYX 0:85b3fd62ea1a 21
NYX 0:85b3fd62ea1a 22 @endverbatim
NYX 0:85b3fd62ea1a 23 ******************************************************************************
NYX 0:85b3fd62ea1a 24 * @attention
NYX 0:85b3fd62ea1a 25 *
NYX 0:85b3fd62ea1a 26 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
NYX 0:85b3fd62ea1a 27 *
NYX 0:85b3fd62ea1a 28 * Redistribution and use in source and binary forms, with or without modification,
NYX 0:85b3fd62ea1a 29 * are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 30 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 31 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 32 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 33 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 34 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 35 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 36 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 37 * without specific prior written permission.
NYX 0:85b3fd62ea1a 38 *
NYX 0:85b3fd62ea1a 39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 42 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 45 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 46 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 49 *
NYX 0:85b3fd62ea1a 50 ******************************************************************************
NYX 0:85b3fd62ea1a 51 */
NYX 0:85b3fd62ea1a 52
NYX 0:85b3fd62ea1a 53 /* Includes ------------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 54 #include "stm32f4xx_hal.h"
NYX 0:85b3fd62ea1a 55
NYX 0:85b3fd62ea1a 56 /** @addtogroup STM32F4xx_HAL_Driver
NYX 0:85b3fd62ea1a 57 * @{
NYX 0:85b3fd62ea1a 58 */
NYX 0:85b3fd62ea1a 59
NYX 0:85b3fd62ea1a 60 /** @defgroup HAL HAL
NYX 0:85b3fd62ea1a 61 * @brief HAL module driver.
NYX 0:85b3fd62ea1a 62 * @{
NYX 0:85b3fd62ea1a 63 */
NYX 0:85b3fd62ea1a 64
NYX 0:85b3fd62ea1a 65 /* Private typedef -----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 66 /* Private define ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 67 /** @addtogroup HAL_Private_Constants
NYX 0:85b3fd62ea1a 68 * @{
NYX 0:85b3fd62ea1a 69 */
NYX 0:85b3fd62ea1a 70 /**
NYX 0:85b3fd62ea1a 71 * @brief STM32F4xx HAL Driver version number V1.7.1
NYX 0:85b3fd62ea1a 72 */
NYX 0:85b3fd62ea1a 73 #define __STM32F4xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
NYX 0:85b3fd62ea1a 74 #define __STM32F4xx_HAL_VERSION_SUB1 (0x07U) /*!< [23:16] sub1 version */
NYX 0:85b3fd62ea1a 75 #define __STM32F4xx_HAL_VERSION_SUB2 (0x01U) /*!< [15:8] sub2 version */
NYX 0:85b3fd62ea1a 76 #define __STM32F4xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
NYX 0:85b3fd62ea1a 77 #define __STM32F4xx_HAL_VERSION ((__STM32F4xx_HAL_VERSION_MAIN << 24U)\
NYX 0:85b3fd62ea1a 78 |(__STM32F4xx_HAL_VERSION_SUB1 << 16U)\
NYX 0:85b3fd62ea1a 79 |(__STM32F4xx_HAL_VERSION_SUB2 << 8U )\
NYX 0:85b3fd62ea1a 80 |(__STM32F4xx_HAL_VERSION_RC))
NYX 0:85b3fd62ea1a 81
NYX 0:85b3fd62ea1a 82 #define IDCODE_DEVID_MASK 0x00000FFFU
NYX 0:85b3fd62ea1a 83
NYX 0:85b3fd62ea1a 84 /* ------------ RCC registers bit address in the alias region ----------- */
NYX 0:85b3fd62ea1a 85 #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE)
NYX 0:85b3fd62ea1a 86 /* --- MEMRMP Register ---*/
NYX 0:85b3fd62ea1a 87 /* Alias word address of UFB_MODE bit */
NYX 0:85b3fd62ea1a 88 #define MEMRMP_OFFSET SYSCFG_OFFSET
NYX 0:85b3fd62ea1a 89 #define UFB_MODE_BIT_NUMBER POSITION_VAL(SYSCFG_MEMRMP_UFB_MODE)
NYX 0:85b3fd62ea1a 90 #define UFB_MODE_BB (uint32_t)(PERIPH_BB_BASE + (MEMRMP_OFFSET * 32U) + (UFB_MODE_BIT_NUMBER * 4U))
NYX 0:85b3fd62ea1a 91
NYX 0:85b3fd62ea1a 92 /* --- CMPCR Register ---*/
NYX 0:85b3fd62ea1a 93 /* Alias word address of CMP_PD bit */
NYX 0:85b3fd62ea1a 94 #define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20U)
NYX 0:85b3fd62ea1a 95 #define CMP_PD_BIT_NUMBER POSITION_VAL(SYSCFG_CMPCR_CMP_PD)
NYX 0:85b3fd62ea1a 96 #define CMPCR_CMP_PD_BB (uint32_t)(PERIPH_BB_BASE + (CMPCR_OFFSET * 32U) + (CMP_PD_BIT_NUMBER * 4U))
NYX 0:85b3fd62ea1a 97
NYX 0:85b3fd62ea1a 98 /* --- MCHDLYCR Register ---*/
NYX 0:85b3fd62ea1a 99 /* Alias word address of BSCKSEL bit */
NYX 0:85b3fd62ea1a 100 #define MCHDLYCR_OFFSET (SYSCFG_OFFSET + 0x30U)
NYX 0:85b3fd62ea1a 101 #define BSCKSEL_BIT_NUMBER POSITION_VAL(SYSCFG_MCHDLYCR_BSCKSEL)
NYX 0:85b3fd62ea1a 102 #define MCHDLYCR_BSCKSEL_BB (uint32_t)(PERIPH_BB_BASE + (MCHDLYCR_OFFSET * 32U) + (BSCKSEL_BIT_NUMBER * 4U))
NYX 0:85b3fd62ea1a 103 /**
NYX 0:85b3fd62ea1a 104 * @}
NYX 0:85b3fd62ea1a 105 */
NYX 0:85b3fd62ea1a 106
NYX 0:85b3fd62ea1a 107 /* Private macro -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 108 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 109 /** @addtogroup HAL_Private_Variables
NYX 0:85b3fd62ea1a 110 * @{
NYX 0:85b3fd62ea1a 111 */
NYX 0:85b3fd62ea1a 112 __IO uint32_t uwTick;
NYX 0:85b3fd62ea1a 113 /**
NYX 0:85b3fd62ea1a 114 * @}
NYX 0:85b3fd62ea1a 115 */
NYX 0:85b3fd62ea1a 116 /* Private function prototypes -----------------------------------------------*/
NYX 0:85b3fd62ea1a 117 /* Private functions ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 118
NYX 0:85b3fd62ea1a 119 /** @defgroup HAL_Exported_Functions HAL Exported Functions
NYX 0:85b3fd62ea1a 120 * @{
NYX 0:85b3fd62ea1a 121 */
NYX 0:85b3fd62ea1a 122
NYX 0:85b3fd62ea1a 123 /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
NYX 0:85b3fd62ea1a 124 * @brief Initialization and de-initialization functions
NYX 0:85b3fd62ea1a 125 *
NYX 0:85b3fd62ea1a 126 @verbatim
NYX 0:85b3fd62ea1a 127 ===============================================================================
NYX 0:85b3fd62ea1a 128 ##### Initialization and de-initialization functions #####
NYX 0:85b3fd62ea1a 129 ===============================================================================
NYX 0:85b3fd62ea1a 130 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 131 (+) Initializes the Flash interface the NVIC allocation and initial clock
NYX 0:85b3fd62ea1a 132 configuration. It initializes the systick also when timeout is needed
NYX 0:85b3fd62ea1a 133 and the backup domain when enabled.
NYX 0:85b3fd62ea1a 134 (+) de-Initializes common part of the HAL
NYX 0:85b3fd62ea1a 135 (+) Configure The time base source to have 1ms time base with a dedicated
NYX 0:85b3fd62ea1a 136 Tick interrupt priority.
NYX 0:85b3fd62ea1a 137 (++) Systick timer is used by default as source of time base, but user
NYX 0:85b3fd62ea1a 138 can eventually implement his proper time base source (a general purpose
NYX 0:85b3fd62ea1a 139 timer for example or other time source), keeping in mind that Time base
NYX 0:85b3fd62ea1a 140 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
NYX 0:85b3fd62ea1a 141 handled in milliseconds basis.
NYX 0:85b3fd62ea1a 142 (++) Time base configuration function (HAL_InitTick ()) is called automatically
NYX 0:85b3fd62ea1a 143 at the beginning of the program after reset by HAL_Init() or at any time
NYX 0:85b3fd62ea1a 144 when clock is configured, by HAL_RCC_ClockConfig().
NYX 0:85b3fd62ea1a 145 (++) Source of time base is configured to generate interrupts at regular
NYX 0:85b3fd62ea1a 146 time intervals. Care must be taken if HAL_Delay() is called from a
NYX 0:85b3fd62ea1a 147 peripheral ISR process, the Tick interrupt line must have higher priority
NYX 0:85b3fd62ea1a 148 (numerically lower) than the peripheral interrupt. Otherwise the caller
NYX 0:85b3fd62ea1a 149 ISR process will be blocked.
NYX 0:85b3fd62ea1a 150 (++) functions affecting time base configurations are declared as __weak
NYX 0:85b3fd62ea1a 151 to make override possible in case of other implementations in user file.
NYX 0:85b3fd62ea1a 152 @endverbatim
NYX 0:85b3fd62ea1a 153 * @{
NYX 0:85b3fd62ea1a 154 */
NYX 0:85b3fd62ea1a 155
NYX 0:85b3fd62ea1a 156 /**
NYX 0:85b3fd62ea1a 157 * @brief This function is used to initialize the HAL Library; it must be the first
NYX 0:85b3fd62ea1a 158 * instruction to be executed in the main program (before to call any other
NYX 0:85b3fd62ea1a 159 * HAL function), it performs the following:
NYX 0:85b3fd62ea1a 160 * Configure the Flash prefetch, instruction and Data caches.
NYX 0:85b3fd62ea1a 161 * Configures the SysTick to generate an interrupt each 1 millisecond,
NYX 0:85b3fd62ea1a 162 * which is clocked by the HSI (at this stage, the clock is not yet
NYX 0:85b3fd62ea1a 163 * configured and thus the system is running from the internal HSI at 16 MHz).
NYX 0:85b3fd62ea1a 164 * Set NVIC Group Priority to 4.
NYX 0:85b3fd62ea1a 165 * Calls the HAL_MspInit() callback function defined in user file
NYX 0:85b3fd62ea1a 166 * "stm32f4xx_hal_msp.c" to do the global low level hardware initialization
NYX 0:85b3fd62ea1a 167 *
NYX 0:85b3fd62ea1a 168 * @note SysTick is used as time base for the HAL_Delay() function, the application
NYX 0:85b3fd62ea1a 169 * need to ensure that the SysTick time base is always set to 1 millisecond
NYX 0:85b3fd62ea1a 170 * to have correct HAL operation.
NYX 0:85b3fd62ea1a 171 * @retval HAL status
NYX 0:85b3fd62ea1a 172 */
NYX 0:85b3fd62ea1a 173 HAL_StatusTypeDef HAL_Init(void)
NYX 0:85b3fd62ea1a 174 {
NYX 0:85b3fd62ea1a 175 /* Configure Flash prefetch, Instruction cache, Data cache */
NYX 0:85b3fd62ea1a 176 #if (INSTRUCTION_CACHE_ENABLE != 0U)
NYX 0:85b3fd62ea1a 177 __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
NYX 0:85b3fd62ea1a 178 #endif /* INSTRUCTION_CACHE_ENABLE */
NYX 0:85b3fd62ea1a 179
NYX 0:85b3fd62ea1a 180 #if (DATA_CACHE_ENABLE != 0U)
NYX 0:85b3fd62ea1a 181 __HAL_FLASH_DATA_CACHE_ENABLE();
NYX 0:85b3fd62ea1a 182 #endif /* DATA_CACHE_ENABLE */
NYX 0:85b3fd62ea1a 183
NYX 0:85b3fd62ea1a 184 #if (PREFETCH_ENABLE != 0U)
NYX 0:85b3fd62ea1a 185 __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
NYX 0:85b3fd62ea1a 186 #endif /* PREFETCH_ENABLE */
NYX 0:85b3fd62ea1a 187
NYX 0:85b3fd62ea1a 188 /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
NYX 0:85b3fd62ea1a 189 HAL_InitTick(TICK_INT_PRIORITY);
NYX 0:85b3fd62ea1a 190
NYX 0:85b3fd62ea1a 191 /* Init the low level hardware */
NYX 0:85b3fd62ea1a 192 HAL_MspInit();
NYX 0:85b3fd62ea1a 193
NYX 0:85b3fd62ea1a 194 /* Return function status */
NYX 0:85b3fd62ea1a 195 return HAL_OK;
NYX 0:85b3fd62ea1a 196 }
NYX 0:85b3fd62ea1a 197
NYX 0:85b3fd62ea1a 198 /**
NYX 0:85b3fd62ea1a 199 * @brief This function de-Initializes common part of the HAL and stops the systick.
NYX 0:85b3fd62ea1a 200 * This function is optional.
NYX 0:85b3fd62ea1a 201 * @retval HAL status
NYX 0:85b3fd62ea1a 202 */
NYX 0:85b3fd62ea1a 203 HAL_StatusTypeDef HAL_DeInit(void)
NYX 0:85b3fd62ea1a 204 {
NYX 0:85b3fd62ea1a 205 /* Reset of all peripherals */
NYX 0:85b3fd62ea1a 206 __HAL_RCC_APB1_FORCE_RESET();
NYX 0:85b3fd62ea1a 207 __HAL_RCC_APB1_RELEASE_RESET();
NYX 0:85b3fd62ea1a 208
NYX 0:85b3fd62ea1a 209 __HAL_RCC_APB2_FORCE_RESET();
NYX 0:85b3fd62ea1a 210 __HAL_RCC_APB2_RELEASE_RESET();
NYX 0:85b3fd62ea1a 211
NYX 0:85b3fd62ea1a 212 __HAL_RCC_AHB1_FORCE_RESET();
NYX 0:85b3fd62ea1a 213 __HAL_RCC_AHB1_RELEASE_RESET();
NYX 0:85b3fd62ea1a 214
NYX 0:85b3fd62ea1a 215 __HAL_RCC_AHB2_FORCE_RESET();
NYX 0:85b3fd62ea1a 216 __HAL_RCC_AHB2_RELEASE_RESET();
NYX 0:85b3fd62ea1a 217
NYX 0:85b3fd62ea1a 218 __HAL_RCC_AHB3_FORCE_RESET();
NYX 0:85b3fd62ea1a 219 __HAL_RCC_AHB3_RELEASE_RESET();
NYX 0:85b3fd62ea1a 220
NYX 0:85b3fd62ea1a 221 /* De-Init the low level hardware */
NYX 0:85b3fd62ea1a 222 HAL_MspDeInit();
NYX 0:85b3fd62ea1a 223
NYX 0:85b3fd62ea1a 224 /* Return function status */
NYX 0:85b3fd62ea1a 225 return HAL_OK;
NYX 0:85b3fd62ea1a 226 }
NYX 0:85b3fd62ea1a 227
NYX 0:85b3fd62ea1a 228 /**
NYX 0:85b3fd62ea1a 229 * @brief Initializes the MSP.
NYX 0:85b3fd62ea1a 230 * @retval None
NYX 0:85b3fd62ea1a 231 */
NYX 0:85b3fd62ea1a 232 __weak void HAL_MspInit(void)
NYX 0:85b3fd62ea1a 233 {
NYX 0:85b3fd62ea1a 234 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 235 the HAL_MspInit could be implemented in the user file
NYX 0:85b3fd62ea1a 236 */
NYX 0:85b3fd62ea1a 237 }
NYX 0:85b3fd62ea1a 238
NYX 0:85b3fd62ea1a 239 /**
NYX 0:85b3fd62ea1a 240 * @brief DeInitializes the MSP.
NYX 0:85b3fd62ea1a 241 * @retval None
NYX 0:85b3fd62ea1a 242 */
NYX 0:85b3fd62ea1a 243 __weak void HAL_MspDeInit(void)
NYX 0:85b3fd62ea1a 244 {
NYX 0:85b3fd62ea1a 245 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 246 the HAL_MspDeInit could be implemented in the user file
NYX 0:85b3fd62ea1a 247 */
NYX 0:85b3fd62ea1a 248 }
NYX 0:85b3fd62ea1a 249
NYX 0:85b3fd62ea1a 250 /**
NYX 0:85b3fd62ea1a 251 * @brief This function configures the source of the time base.
NYX 0:85b3fd62ea1a 252 * The time source is configured to have 1ms time base with a dedicated
NYX 0:85b3fd62ea1a 253 * Tick interrupt priority.
NYX 0:85b3fd62ea1a 254 * @note This function is called automatically at the beginning of program after
NYX 0:85b3fd62ea1a 255 * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
NYX 0:85b3fd62ea1a 256 * @note In the default implementation, SysTick timer is the source of time base.
NYX 0:85b3fd62ea1a 257 * It is used to generate interrupts at regular time intervals.
NYX 0:85b3fd62ea1a 258 * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
NYX 0:85b3fd62ea1a 259 * The the SysTick interrupt must have higher priority (numerically lower)
NYX 0:85b3fd62ea1a 260 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
NYX 0:85b3fd62ea1a 261 * The function is declared as __weak to be overwritten in case of other
NYX 0:85b3fd62ea1a 262 * implementation in user file.
NYX 0:85b3fd62ea1a 263 * @param TickPriority: Tick interrupt priority.
NYX 0:85b3fd62ea1a 264 * @retval HAL status
NYX 0:85b3fd62ea1a 265 */
NYX 0:85b3fd62ea1a 266 __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
NYX 0:85b3fd62ea1a 267 {
NYX 0:85b3fd62ea1a 268 /*Configure the SysTick to have interrupt in 1ms time basis*/
NYX 0:85b3fd62ea1a 269 HAL_SYSTICK_Config(SystemCoreClock/1000U);
NYX 0:85b3fd62ea1a 270
NYX 0:85b3fd62ea1a 271 /*Configure the SysTick IRQ priority */
NYX 0:85b3fd62ea1a 272 HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
NYX 0:85b3fd62ea1a 273
NYX 0:85b3fd62ea1a 274 /* Return function status */
NYX 0:85b3fd62ea1a 275 return HAL_OK;
NYX 0:85b3fd62ea1a 276 }
NYX 0:85b3fd62ea1a 277
NYX 0:85b3fd62ea1a 278 /**
NYX 0:85b3fd62ea1a 279 * @}
NYX 0:85b3fd62ea1a 280 */
NYX 0:85b3fd62ea1a 281
NYX 0:85b3fd62ea1a 282 /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
NYX 0:85b3fd62ea1a 283 * @brief HAL Control functions
NYX 0:85b3fd62ea1a 284 *
NYX 0:85b3fd62ea1a 285 @verbatim
NYX 0:85b3fd62ea1a 286 ===============================================================================
NYX 0:85b3fd62ea1a 287 ##### HAL Control functions #####
NYX 0:85b3fd62ea1a 288 ===============================================================================
NYX 0:85b3fd62ea1a 289 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 290 (+) Provide a tick value in millisecond
NYX 0:85b3fd62ea1a 291 (+) Provide a blocking delay in millisecond
NYX 0:85b3fd62ea1a 292 (+) Suspend the time base source interrupt
NYX 0:85b3fd62ea1a 293 (+) Resume the time base source interrupt
NYX 0:85b3fd62ea1a 294 (+) Get the HAL API driver version
NYX 0:85b3fd62ea1a 295 (+) Get the device identifier
NYX 0:85b3fd62ea1a 296 (+) Get the device revision identifier
NYX 0:85b3fd62ea1a 297 (+) Enable/Disable Debug module during SLEEP mode
NYX 0:85b3fd62ea1a 298 (+) Enable/Disable Debug module during STOP mode
NYX 0:85b3fd62ea1a 299 (+) Enable/Disable Debug module during STANDBY mode
NYX 0:85b3fd62ea1a 300
NYX 0:85b3fd62ea1a 301 @endverbatim
NYX 0:85b3fd62ea1a 302 * @{
NYX 0:85b3fd62ea1a 303 */
NYX 0:85b3fd62ea1a 304
NYX 0:85b3fd62ea1a 305 /**
NYX 0:85b3fd62ea1a 306 * @brief This function is called to increment a global variable "uwTick"
NYX 0:85b3fd62ea1a 307 * used as application time base.
NYX 0:85b3fd62ea1a 308 * @note In the default implementation, this variable is incremented each 1ms
NYX 0:85b3fd62ea1a 309 * in Systick ISR.
NYX 0:85b3fd62ea1a 310 * @note This function is declared as __weak to be overwritten in case of other
NYX 0:85b3fd62ea1a 311 * implementations in user file.
NYX 0:85b3fd62ea1a 312 * @retval None
NYX 0:85b3fd62ea1a 313 */
NYX 0:85b3fd62ea1a 314 __weak void HAL_IncTick(void)
NYX 0:85b3fd62ea1a 315 {
NYX 0:85b3fd62ea1a 316 uwTick++;
NYX 0:85b3fd62ea1a 317 }
NYX 0:85b3fd62ea1a 318
NYX 0:85b3fd62ea1a 319 /**
NYX 0:85b3fd62ea1a 320 * @brief Provides a tick value in millisecond.
NYX 0:85b3fd62ea1a 321 * @note This function is declared as __weak to be overwritten in case of other
NYX 0:85b3fd62ea1a 322 * implementations in user file.
NYX 0:85b3fd62ea1a 323 * @retval tick value
NYX 0:85b3fd62ea1a 324 */
NYX 0:85b3fd62ea1a 325 __weak uint32_t HAL_GetTick(void)
NYX 0:85b3fd62ea1a 326 {
NYX 0:85b3fd62ea1a 327 return uwTick;
NYX 0:85b3fd62ea1a 328 }
NYX 0:85b3fd62ea1a 329
NYX 0:85b3fd62ea1a 330 /**
NYX 0:85b3fd62ea1a 331 * @brief This function provides minimum delay (in milliseconds) based
NYX 0:85b3fd62ea1a 332 * on variable incremented.
NYX 0:85b3fd62ea1a 333 * @note In the default implementation , SysTick timer is the source of time base.
NYX 0:85b3fd62ea1a 334 * It is used to generate interrupts at regular time intervals where uwTick
NYX 0:85b3fd62ea1a 335 * is incremented.
NYX 0:85b3fd62ea1a 336 * @note This function is declared as __weak to be overwritten in case of other
NYX 0:85b3fd62ea1a 337 * implementations in user file.
NYX 0:85b3fd62ea1a 338 * @param Delay: specifies the delay time length, in milliseconds.
NYX 0:85b3fd62ea1a 339 * @retval None
NYX 0:85b3fd62ea1a 340 */
NYX 0:85b3fd62ea1a 341 __weak void HAL_Delay(__IO uint32_t Delay)
NYX 0:85b3fd62ea1a 342 {
NYX 0:85b3fd62ea1a 343 uint32_t tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 344 uint32_t wait = Delay;
NYX 0:85b3fd62ea1a 345
NYX 0:85b3fd62ea1a 346 /* Add a period to guarantee minimum wait */
NYX 0:85b3fd62ea1a 347 if (wait < HAL_MAX_DELAY)
NYX 0:85b3fd62ea1a 348 {
NYX 0:85b3fd62ea1a 349 wait++;
NYX 0:85b3fd62ea1a 350 }
NYX 0:85b3fd62ea1a 351
NYX 0:85b3fd62ea1a 352 while((HAL_GetTick() - tickstart) < wait)
NYX 0:85b3fd62ea1a 353 {
NYX 0:85b3fd62ea1a 354 }
NYX 0:85b3fd62ea1a 355 }
NYX 0:85b3fd62ea1a 356
NYX 0:85b3fd62ea1a 357 /**
NYX 0:85b3fd62ea1a 358 * @brief Suspend Tick increment.
NYX 0:85b3fd62ea1a 359 * @note In the default implementation , SysTick timer is the source of time base. It is
NYX 0:85b3fd62ea1a 360 * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
NYX 0:85b3fd62ea1a 361 * is called, the SysTick interrupt will be disabled and so Tick increment
NYX 0:85b3fd62ea1a 362 * is suspended.
NYX 0:85b3fd62ea1a 363 * @note This function is declared as __weak to be overwritten in case of other
NYX 0:85b3fd62ea1a 364 * implementations in user file.
NYX 0:85b3fd62ea1a 365 * @retval None
NYX 0:85b3fd62ea1a 366 */
NYX 0:85b3fd62ea1a 367 __weak void HAL_SuspendTick(void)
NYX 0:85b3fd62ea1a 368 {
NYX 0:85b3fd62ea1a 369 /* Disable SysTick Interrupt */
NYX 0:85b3fd62ea1a 370 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
NYX 0:85b3fd62ea1a 371 }
NYX 0:85b3fd62ea1a 372
NYX 0:85b3fd62ea1a 373 /**
NYX 0:85b3fd62ea1a 374 * @brief Resume Tick increment.
NYX 0:85b3fd62ea1a 375 * @note In the default implementation , SysTick timer is the source of time base. It is
NYX 0:85b3fd62ea1a 376 * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
NYX 0:85b3fd62ea1a 377 * is called, the SysTick interrupt will be enabled and so Tick increment
NYX 0:85b3fd62ea1a 378 * is resumed.
NYX 0:85b3fd62ea1a 379 * @note This function is declared as __weak to be overwritten in case of other
NYX 0:85b3fd62ea1a 380 * implementations in user file.
NYX 0:85b3fd62ea1a 381 * @retval None
NYX 0:85b3fd62ea1a 382 */
NYX 0:85b3fd62ea1a 383 __weak void HAL_ResumeTick(void)
NYX 0:85b3fd62ea1a 384 {
NYX 0:85b3fd62ea1a 385 /* Enable SysTick Interrupt */
NYX 0:85b3fd62ea1a 386 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
NYX 0:85b3fd62ea1a 387 }
NYX 0:85b3fd62ea1a 388
NYX 0:85b3fd62ea1a 389 /**
NYX 0:85b3fd62ea1a 390 * @brief Returns the HAL revision
NYX 0:85b3fd62ea1a 391 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
NYX 0:85b3fd62ea1a 392 */
NYX 0:85b3fd62ea1a 393 uint32_t HAL_GetHalVersion(void)
NYX 0:85b3fd62ea1a 394 {
NYX 0:85b3fd62ea1a 395 return __STM32F4xx_HAL_VERSION;
NYX 0:85b3fd62ea1a 396 }
NYX 0:85b3fd62ea1a 397
NYX 0:85b3fd62ea1a 398 /**
NYX 0:85b3fd62ea1a 399 * @brief Returns the device revision identifier.
NYX 0:85b3fd62ea1a 400 * @retval Device revision identifier
NYX 0:85b3fd62ea1a 401 */
NYX 0:85b3fd62ea1a 402 uint32_t HAL_GetREVID(void)
NYX 0:85b3fd62ea1a 403 {
NYX 0:85b3fd62ea1a 404 return((DBGMCU->IDCODE) >> 16U);
NYX 0:85b3fd62ea1a 405 }
NYX 0:85b3fd62ea1a 406
NYX 0:85b3fd62ea1a 407 /**
NYX 0:85b3fd62ea1a 408 * @brief Returns the device identifier.
NYX 0:85b3fd62ea1a 409 * @retval Device identifier
NYX 0:85b3fd62ea1a 410 */
NYX 0:85b3fd62ea1a 411 uint32_t HAL_GetDEVID(void)
NYX 0:85b3fd62ea1a 412 {
NYX 0:85b3fd62ea1a 413 return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
NYX 0:85b3fd62ea1a 414 }
NYX 0:85b3fd62ea1a 415
NYX 0:85b3fd62ea1a 416 /**
NYX 0:85b3fd62ea1a 417 * @brief Enable the Debug Module during SLEEP mode
NYX 0:85b3fd62ea1a 418 * @retval None
NYX 0:85b3fd62ea1a 419 */
NYX 0:85b3fd62ea1a 420 void HAL_DBGMCU_EnableDBGSleepMode(void)
NYX 0:85b3fd62ea1a 421 {
NYX 0:85b3fd62ea1a 422 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
NYX 0:85b3fd62ea1a 423 }
NYX 0:85b3fd62ea1a 424
NYX 0:85b3fd62ea1a 425 /**
NYX 0:85b3fd62ea1a 426 * @brief Disable the Debug Module during SLEEP mode
NYX 0:85b3fd62ea1a 427 * @retval None
NYX 0:85b3fd62ea1a 428 */
NYX 0:85b3fd62ea1a 429 void HAL_DBGMCU_DisableDBGSleepMode(void)
NYX 0:85b3fd62ea1a 430 {
NYX 0:85b3fd62ea1a 431 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
NYX 0:85b3fd62ea1a 432 }
NYX 0:85b3fd62ea1a 433
NYX 0:85b3fd62ea1a 434 /**
NYX 0:85b3fd62ea1a 435 * @brief Enable the Debug Module during STOP mode
NYX 0:85b3fd62ea1a 436 * @retval None
NYX 0:85b3fd62ea1a 437 */
NYX 0:85b3fd62ea1a 438 void HAL_DBGMCU_EnableDBGStopMode(void)
NYX 0:85b3fd62ea1a 439 {
NYX 0:85b3fd62ea1a 440 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
NYX 0:85b3fd62ea1a 441 }
NYX 0:85b3fd62ea1a 442
NYX 0:85b3fd62ea1a 443 /**
NYX 0:85b3fd62ea1a 444 * @brief Disable the Debug Module during STOP mode
NYX 0:85b3fd62ea1a 445 * @retval None
NYX 0:85b3fd62ea1a 446 */
NYX 0:85b3fd62ea1a 447 void HAL_DBGMCU_DisableDBGStopMode(void)
NYX 0:85b3fd62ea1a 448 {
NYX 0:85b3fd62ea1a 449 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
NYX 0:85b3fd62ea1a 450 }
NYX 0:85b3fd62ea1a 451
NYX 0:85b3fd62ea1a 452 /**
NYX 0:85b3fd62ea1a 453 * @brief Enable the Debug Module during STANDBY mode
NYX 0:85b3fd62ea1a 454 * @retval None
NYX 0:85b3fd62ea1a 455 */
NYX 0:85b3fd62ea1a 456 void HAL_DBGMCU_EnableDBGStandbyMode(void)
NYX 0:85b3fd62ea1a 457 {
NYX 0:85b3fd62ea1a 458 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
NYX 0:85b3fd62ea1a 459 }
NYX 0:85b3fd62ea1a 460
NYX 0:85b3fd62ea1a 461 /**
NYX 0:85b3fd62ea1a 462 * @brief Disable the Debug Module during STANDBY mode
NYX 0:85b3fd62ea1a 463 * @retval None
NYX 0:85b3fd62ea1a 464 */
NYX 0:85b3fd62ea1a 465 void HAL_DBGMCU_DisableDBGStandbyMode(void)
NYX 0:85b3fd62ea1a 466 {
NYX 0:85b3fd62ea1a 467 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
NYX 0:85b3fd62ea1a 468 }
NYX 0:85b3fd62ea1a 469
NYX 0:85b3fd62ea1a 470 /**
NYX 0:85b3fd62ea1a 471 * @brief Enables the I/O Compensation Cell.
NYX 0:85b3fd62ea1a 472 * @note The I/O compensation cell can be used only when the device supply
NYX 0:85b3fd62ea1a 473 * voltage ranges from 2.4 to 3.6 V.
NYX 0:85b3fd62ea1a 474 * @retval None
NYX 0:85b3fd62ea1a 475 */
NYX 0:85b3fd62ea1a 476 void HAL_EnableCompensationCell(void)
NYX 0:85b3fd62ea1a 477 {
NYX 0:85b3fd62ea1a 478 *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)ENABLE;
NYX 0:85b3fd62ea1a 479 }
NYX 0:85b3fd62ea1a 480
NYX 0:85b3fd62ea1a 481 /**
NYX 0:85b3fd62ea1a 482 * @brief Power-down the I/O Compensation Cell.
NYX 0:85b3fd62ea1a 483 * @note The I/O compensation cell can be used only when the device supply
NYX 0:85b3fd62ea1a 484 * voltage ranges from 2.4 to 3.6 V.
NYX 0:85b3fd62ea1a 485 * @retval None
NYX 0:85b3fd62ea1a 486 */
NYX 0:85b3fd62ea1a 487 void HAL_DisableCompensationCell(void)
NYX 0:85b3fd62ea1a 488 {
NYX 0:85b3fd62ea1a 489 *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)DISABLE;
NYX 0:85b3fd62ea1a 490 }
NYX 0:85b3fd62ea1a 491
NYX 0:85b3fd62ea1a 492 /**
NYX 0:85b3fd62ea1a 493 * @brief Return the unique device identifier (UID based on 96 bits)
NYX 0:85b3fd62ea1a 494 * @param UID: pointer to 3 words array.
NYX 0:85b3fd62ea1a 495 * @retval Device identifier
NYX 0:85b3fd62ea1a 496 */
NYX 0:85b3fd62ea1a 497 void HAL_GetUID(uint32_t *UID)
NYX 0:85b3fd62ea1a 498 {
NYX 0:85b3fd62ea1a 499 UID[0] = (uint32_t)(READ_REG(*((uint32_t *)UID_BASE)));
NYX 0:85b3fd62ea1a 500 UID[1] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
NYX 0:85b3fd62ea1a 501 UID[2] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
NYX 0:85b3fd62ea1a 502 }
NYX 0:85b3fd62ea1a 503
NYX 0:85b3fd62ea1a 504 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\
NYX 0:85b3fd62ea1a 505 defined(STM32F469xx) || defined(STM32F479xx)
NYX 0:85b3fd62ea1a 506 /**
NYX 0:85b3fd62ea1a 507 * @brief Enables the Internal FLASH Bank Swapping.
NYX 0:85b3fd62ea1a 508 *
NYX 0:85b3fd62ea1a 509 * @note This function can be used only for STM32F42xxx/43xxx devices.
NYX 0:85b3fd62ea1a 510 *
NYX 0:85b3fd62ea1a 511 * @note Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000)
NYX 0:85b3fd62ea1a 512 * and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000)
NYX 0:85b3fd62ea1a 513 *
NYX 0:85b3fd62ea1a 514 * @retval None
NYX 0:85b3fd62ea1a 515 */
NYX 0:85b3fd62ea1a 516 void HAL_EnableMemorySwappingBank(void)
NYX 0:85b3fd62ea1a 517 {
NYX 0:85b3fd62ea1a 518 *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)ENABLE;
NYX 0:85b3fd62ea1a 519 }
NYX 0:85b3fd62ea1a 520
NYX 0:85b3fd62ea1a 521 /**
NYX 0:85b3fd62ea1a 522 * @brief Disables the Internal FLASH Bank Swapping.
NYX 0:85b3fd62ea1a 523 *
NYX 0:85b3fd62ea1a 524 * @note This function can be used only for STM32F42xxx/43xxx devices.
NYX 0:85b3fd62ea1a 525 *
NYX 0:85b3fd62ea1a 526 * @note The default state : Flash Bank1 mapped at 0x08000000 (and aliased @0x00000000)
NYX 0:85b3fd62ea1a 527 * and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000)
NYX 0:85b3fd62ea1a 528 *
NYX 0:85b3fd62ea1a 529 * @retval None
NYX 0:85b3fd62ea1a 530 */
NYX 0:85b3fd62ea1a 531 void HAL_DisableMemorySwappingBank(void)
NYX 0:85b3fd62ea1a 532 {
NYX 0:85b3fd62ea1a 533
NYX 0:85b3fd62ea1a 534 *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)DISABLE;
NYX 0:85b3fd62ea1a 535 }
NYX 0:85b3fd62ea1a 536 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */
NYX 0:85b3fd62ea1a 537 /**
NYX 0:85b3fd62ea1a 538 * @}
NYX 0:85b3fd62ea1a 539 */
NYX 0:85b3fd62ea1a 540
NYX 0:85b3fd62ea1a 541 /**
NYX 0:85b3fd62ea1a 542 * @}
NYX 0:85b3fd62ea1a 543 */
NYX 0:85b3fd62ea1a 544
NYX 0:85b3fd62ea1a 545 /**
NYX 0:85b3fd62ea1a 546 * @}
NYX 0:85b3fd62ea1a 547 */
NYX 0:85b3fd62ea1a 548
NYX 0:85b3fd62ea1a 549 /**
NYX 0:85b3fd62ea1a 550 * @}
NYX 0:85b3fd62ea1a 551 */
NYX 0:85b3fd62ea1a 552
NYX 0:85b3fd62ea1a 553 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/