2 ******************************************************************************
3 * @file stm32f3xx_hal.c
4 * @author MCD Application Team
7 * @brief HAL module driver.
8 * This is the common part of the HAL initialization
11 ==============================================================================
12 ##### How to use this driver #####
13 ==============================================================================
15 The common HAL driver contains a set of generic and common APIs that can be
16 used by the PPP peripheral drivers and the user to start using the HAL.
18 The HAL contains two APIs categories:
19 (+) HAL Initialization and de-initialization functions
20 (+) HAL Control functions
23 ******************************************************************************
26 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
28 * Redistribution and use in source and binary forms, with or without modification,
29 * are permitted provided that the following conditions are met:
30 * 1. Redistributions of source code must retain the above copyright notice,
31 * this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright notice,
33 * this list of conditions and the following disclaimer in the documentation
34 * and/or other materials provided with the distribution.
35 * 3. Neither the name of STMicroelectronics nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 ******************************************************************************
53 /* Includes ------------------------------------------------------------------*/
54 #include "stm32f3xx_hal.h"
56 /** @addtogroup STM32F3xx_HAL_Driver
60 /** @defgroup HAL HAL module driver
61 * @brief HAL module driver.
65 #ifdef HAL_MODULE_ENABLED
67 /* Private typedef -----------------------------------------------------------*/
68 /* Private define ------------------------------------------------------------*/
69 /** @defgroup HAL_Private Constants
73 * @brief STM32F3xx HAL Driver version number V1.1.0
75 #define __STM32F3xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */
76 #define __STM32F3xx_HAL_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */
77 #define __STM32F3xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
78 #define __STM32F3xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */
79 #define __STM32F3xx_HAL_VERSION ((__STM32F3xx_HAL_VERSION_MAIN << 24)\
80 |(__STM32F3xx_HAL_VERSION_SUB1 << 16)\
81 |(__STM32F3xx_HAL_VERSION_SUB2 << 8 )\
82 |(__STM32F3xx_HAL_VERSION_RC))
84 #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
89 /* Private macro -------------------------------------------------------------*/
90 /* Private variables ---------------------------------------------------------*/
91 static __IO uint32_t uwTick;
92 /* Private function prototypes -----------------------------------------------*/
93 /* Exported functions --------------------------------------------------------*/
95 /** @defgroup HAL_Exported_Functions HAL Exported Functions
99 /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
100 * @brief Initialization and de-initialization functions
103 ===============================================================================
104 ##### Initialization and de-initialization functions #####
105 ===============================================================================
106 [..] This section provides functions allowing to:
107 (+) Initializes the Flash interface the NVIC allocation and initial clock
108 configuration. It initializes the systick also when timeout is needed
109 and the backup domain when enabled.
110 (+) de-Initializes common part of the HAL
111 (+) Configure The time base source to have 1ms time base with a dedicated
112 Tick interrupt priority.
113 (++) Systick timer is used by default as source of time base, but user
114 can eventually implement his proper time base source (a general purpose
115 timer for example or other time source), keeping in mind that Time base
116 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
117 handled in milliseconds basis.
118 (++) Time base configuration function (HAL_InitTick ()) is called automatically
119 at the beginning of the program after reset by HAL_Init() or at any time
120 when clock is configured, by HAL_RCC_ClockConfig().
121 (++) Source of time base is configured to generate interrupts at regular
122 time intervals. Care must be taken if HAL_Delay() is called from a
123 peripheral ISR process, the Tick interrupt line must have higher priority
124 (numerically lower) than the peripheral interrupt. Otherwise the caller
125 ISR process will be blocked.
126 (++) functions affecting time base configurations are declared as __Weak
127 to make override possible in case of other implementations in user file.
134 * @brief This function configures the Flash prefetch,
135 * Configures time base source, NVIC and Low level hardware
137 * @note This function is called at the beginning of program after reset and before
138 * the clock configuration
140 * @note The Systick configuration is based on HSI clock, as HSI is the clock
141 * used after a system Reset and the NVIC configuration is set to Priority group 4
143 * @note The time base configuration is based on MSI clock when exting from Reset.
144 * Once done, time base tick start incrementing.
145 * In the default implementation,Systick is used as source of time base.
146 * the tick variable is incremented each 1ms in its ISR.
151 HAL_StatusTypeDef HAL_Init(void)
153 /* Configure Flash prefetch */
154 #if (PREFETCH_ENABLE != 0)
155 __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
156 #endif /* PREFETCH_ENABLE */
158 /* Set Interrupt Group Priority */
159 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
161 /* Enable systick and configure 1ms tick (default clock after Reset is HSI) */
162 HAL_InitTick(TICK_INT_PRIORITY);
164 /* Init the low level hardware */
167 /* Return function status */
172 * @brief This function de-Initializes common part of the HAL and stops the source
174 * This function is optional.
177 HAL_StatusTypeDef HAL_DeInit(void)
179 /* Reset of all peripherals */
180 __APB1_FORCE_RESET();
181 __APB1_RELEASE_RESET();
183 __APB2_FORCE_RESET();
184 __APB2_RELEASE_RESET();
187 __AHB_RELEASE_RESET();
189 /* De-Init the low level hardware */
192 /* Return function status */
197 * @brief Initializes the MSP.
200 __weak void HAL_MspInit(void)
202 /* NOTE : This function Should not be modified, when the callback is needed,
203 the HAL_MspInit could be implemented in the user file
208 * @brief DeInitializes the MSP.
211 __weak void HAL_MspDeInit(void)
213 /* NOTE : This function Should not be modified, when the callback is needed,
214 the HAL_MspDeInit could be implemented in the user file
219 * @brief This function configures the source of the time base.
220 * The time source is configured to have 1ms time base with a dedicated
221 * Tick interrupt priority.
222 * @note This function is called automatically at the beginning of program after
223 * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
224 * @note In the default implementation , SysTick timer is the source of time base.
225 * It is used to generate interrupts at regular time intervals.
226 * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
227 * The the SysTick interrupt must have higher priority (numerically lower)
228 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
229 * The function is declared as __Weak to be overwritten in case of other
230 * implementation in user file.
231 * @param TickPriority: Tick interrupt priorty.
234 __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
237 /*Configure the SysTick to have interrupt in 1ms time basis*/
238 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
240 /*Configure the SysTick IRQ priority */
241 HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0);
243 /* Return function status */
251 /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
252 * @brief HAL Control functions
255 ===============================================================================
256 ##### HAL Control functions #####
257 ===============================================================================
258 [..] This section provides functions allowing to:
259 (+) provide a tick value in millisecond
260 (+) provide a blocking delay in millisecond
261 (+) Suspend the time base source interrupt
262 (+) Resume the time base source interrupt
263 (+) Get the HAL API driver version
264 (+) Get the device identifier
265 (+) Get the device revision identifier
266 (+) Enable/Disable Debug module during Sleep mode
267 (+) Enable/Disable Debug module during STOP mode
268 (+) Enable/Disable Debug module during STANDBY mode
276 * @brief This function is called to increment a global variable "uwTick"
277 * used as application time base.
278 * @note In the default implemetation, this variable is incremented each 1ms
280 * The function is declared as __Weak to be overwritten in case of other
281 * implementations in user file.
284 __weak void HAL_IncTick(void)
290 * @brief Povides a tick value in millisecond.
291 * @note The function is declared as __Weak to be overwritten in case of other
292 * implementations in user file.
295 __weak uint32_t HAL_GetTick(void)
301 * @brief This function provides accurate delay (in milliseconds) based
302 * on variable incremented.
303 * @note In the default implementation , SysTick timer is the source of time base.
304 * It is used to generate interrupts at regular time intervals where uwTick
306 * The function is declared as __Weak to be overwritten in case of other
307 * implementations in user file.
308 * @param Delay: specifies the delay time length, in milliseconds.
311 __weak void HAL_Delay(__IO uint32_t Delay)
313 uint32_t tickstart = HAL_GetTick();
314 while((HAL_GetTick() - tickstart) < Delay)
320 * @brief Suspend Tick increment.
321 * @note In the default implementation , SysTick timer is the source of time base. It is
322 * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
323 * is called, the the SysTick interrupt will be disabled and so Tick increment
325 * The function is declared as __Weak to be overwritten in case of other
326 * implementations in user file.
329 __weak void HAL_SuspendTick(void)
332 /* Disable SysTick Interrupt */
333 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
338 * @brief Resume Tick increment.
339 * @note In the default implementation , SysTick timer is the source of time base. It is
340 * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
341 * is called, the the SysTick interrupt will be enabled and so Tick increment
343 * The function is declared as __Weak to be overwritten in case of other
344 * implementations in user file.
347 __weak void HAL_ResumeTick(void)
349 /* Enable SysTick Interrupt */
350 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
355 * @brief This function returns the HAL revision
356 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
358 uint32_t HAL_GetHalVersion(void)
360 return __STM32F3xx_HAL_VERSION;
364 * @brief Returns the device revision identifier.
365 * @retval Device revision identifier
367 uint32_t HAL_GetREVID(void)
369 return((DBGMCU->IDCODE) >> 16);
373 * @brief Returns the device identifier.
374 * @retval Device identifier
376 uint32_t HAL_GetDEVID(void)
378 return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
382 * @brief Enable the Debug Module during SLEEP mode
385 void HAL_EnableDBGSleepMode(void)
387 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
391 * @brief Disable the Debug Module during SLEEP mode
394 void HAL_DisableDBGSleepMode(void)
396 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
400 * @brief Enable the Debug Module during STOP mode
403 void HAL_EnableDBGStopMode(void)
405 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
409 * @brief Disable the Debug Module during STOP mode
412 void HAL_DisableDBGStopMode(void)
414 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
418 * @brief Enable the Debug Module during STANDBY mode
421 void HAL_EnableDBGStandbyMode(void)
423 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
427 * @brief Disable the Debug Module during STANDBY mode
430 void HAL_DisableDBGStandbyMode(void)
432 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
443 #endif /* HAL_MODULE_ENABLED */
452 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/