2 ******************************************************************************
\r
3 * @file stm32f7xx_hal.c
\r
4 * @author MCD Application Team
\r
6 * @date 24-March-2015
\r
7 * @brief HAL module driver.
\r
8 * This is the common part of the HAL initialization
\r
11 ==============================================================================
\r
12 ##### How to use this driver #####
\r
13 ==============================================================================
\r
15 The common HAL driver contains a set of generic and common APIs that can be
\r
16 used by the PPP peripheral drivers and the user to start using the HAL.
\r
18 The HAL contains two APIs' categories:
\r
20 (+) Services HAL APIs
\r
23 ******************************************************************************
\r
26 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
28 * Redistribution and use in source and binary forms, with or without modification,
\r
29 * are permitted provided that the following conditions are met:
\r
30 * 1. Redistributions of source code must retain the above copyright notice,
\r
31 * this list of conditions and the following disclaimer.
\r
32 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
33 * this list of conditions and the following disclaimer in the documentation
\r
34 * and/or other materials provided with the distribution.
\r
35 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
36 * may be used to endorse or promote products derived from this software
\r
37 * without specific prior written permission.
\r
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
42 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
45 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
46 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
50 ******************************************************************************
\r
53 /* Includes ------------------------------------------------------------------*/
\r
54 #include "stm32f7xx_hal.h"
\r
56 /** @addtogroup STM32F7xx_HAL_Driver
\r
60 /** @defgroup HAL HAL
\r
61 * @brief HAL module driver.
\r
65 /* Private typedef -----------------------------------------------------------*/
\r
66 /* Private define ------------------------------------------------------------*/
\r
68 * @brief STM32F7xx HAL Driver version number V1.0.0RC1
\r
70 #define __STM32F7xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */
\r
71 #define __STM32F7xx_HAL_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
\r
72 #define __STM32F7xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
\r
73 #define __STM32F7xx_HAL_VERSION_RC (0x01) /*!< [7:0] release candidate */
\r
74 #define __STM32F7xx_HAL_VERSION ((__STM32F7xx_HAL_VERSION_MAIN << 24)\
\r
75 |(__STM32F7xx_HAL_VERSION_SUB1 << 16)\
\r
76 |(__STM32F7xx_HAL_VERSION_SUB2 << 8 )\
\r
77 |(__STM32F7xx_HAL_VERSION_RC))
\r
79 #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
\r
81 /* Private macro -------------------------------------------------------------*/
\r
82 /* Private variables ---------------------------------------------------------*/
\r
83 static __IO uint32_t uwTick;
\r
85 /* Private function prototypes -----------------------------------------------*/
\r
86 /* Private functions ---------------------------------------------------------*/
\r
88 /** @defgroup HAL_Private_Functions HAL Private Functions
\r
92 /** @defgroup HAL_Group1 Initialization and de-initialization Functions
\r
93 * @brief Initialization and de-initialization functions
\r
96 ===============================================================================
\r
97 ##### Initialization and de-initialization functions #####
\r
98 ===============================================================================
\r
99 [..] This section provides functions allowing to:
\r
100 (+) Initializes the Flash interface the NVIC allocation and initial clock
\r
101 configuration. It initializes the systick also when timeout is needed
\r
102 and the backup domain when enabled.
\r
103 (+) de-Initializes common part of the HAL
\r
104 (+) Configure The time base source to have 1ms time base with a dedicated
\r
105 Tick interrupt priority.
\r
106 (++) Systick timer is used by default as source of time base, but user
\r
107 can eventually implement his proper time base source (a general purpose
\r
108 timer for example or other time source), keeping in mind that Time base
\r
109 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
\r
110 handled in milliseconds basis.
\r
111 (++) Time base configuration function (HAL_InitTick ()) is called automatically
\r
112 at the beginning of the program after reset by HAL_Init() or at any time
\r
113 when clock is configured, by HAL_RCC_ClockConfig().
\r
114 (++) Source of time base is configured to generate interrupts at regular
\r
115 time intervals. Care must be taken if HAL_Delay() is called from a
\r
116 peripheral ISR process, the Tick interrupt line must have higher priority
\r
117 (numerically lower) than the peripheral interrupt. Otherwise the caller
\r
118 ISR process will be blocked.
\r
119 (++) functions affecting time base configurations are declared as __weak
\r
120 to make override possible in case of other implementations in user file.
\r
126 * @brief This function is used to initialize the HAL Library; it must be the first
\r
127 * instruction to be executed in the main program (before to call any other
\r
128 * HAL function), it performs the following:
\r
129 * Configure the Flash prefetch, and instruction cache through ART accelerator.
\r
130 * Configures the SysTick to generate an interrupt each 1 millisecond,
\r
131 * which is clocked by the HSI (at this stage, the clock is not yet
\r
132 * configured and thus the system is running from the internal HSI at 16 MHz).
\r
133 * Set NVIC Group Priority to 4.
\r
134 * Calls the HAL_MspInit() callback function defined in user file
\r
135 * "stm32f7xx_hal_msp.c" to do the global low level hardware initialization
\r
137 * @note SysTick is used as time base for the HAL_Delay() function, the application
\r
138 * need to ensure that the SysTick time base is always set to 1 millisecond
\r
139 * to have correct HAL operation.
\r
140 * @retval HAL status
\r
142 HAL_StatusTypeDef HAL_Init(void)
\r
144 /* Configure Flash prefetch and Instruction cache through ART accelerator */
\r
145 #if (ART_ACCLERATOR_ENABLE != 0)
\r
146 __HAL_FLASH_ART_ENABLE();
\r
147 #endif /* ART_ACCLERATOR_ENABLE */
\r
149 /* Set Interrupt Group Priority */
\r
150 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
\r
152 /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
\r
153 HAL_InitTick(TICK_INT_PRIORITY);
\r
155 /* Init the low level hardware */
\r
158 /* Return function status */
\r
163 * @brief This function de-Initializes common part of the HAL and stops the systick.
\r
164 * This function is optional.
\r
165 * @retval HAL status
\r
167 HAL_StatusTypeDef HAL_DeInit(void)
\r
169 /* Reset of all peripherals */
\r
170 __HAL_RCC_APB1_FORCE_RESET();
\r
171 __HAL_RCC_APB1_RELEASE_RESET();
\r
173 __HAL_RCC_APB2_FORCE_RESET();
\r
174 __HAL_RCC_APB2_RELEASE_RESET();
\r
176 __HAL_RCC_AHB1_FORCE_RESET();
\r
177 __HAL_RCC_AHB1_RELEASE_RESET();
\r
179 __HAL_RCC_AHB2_FORCE_RESET();
\r
180 __HAL_RCC_AHB2_RELEASE_RESET();
\r
182 __HAL_RCC_AHB3_FORCE_RESET();
\r
183 __HAL_RCC_AHB3_RELEASE_RESET();
\r
185 /* De-Init the low level hardware */
\r
188 /* Return function status */
\r
193 * @brief Initializes the MSP.
\r
196 __weak void HAL_MspInit(void)
\r
198 /* NOTE : This function Should not be modified, when the callback is needed,
\r
199 the HAL_MspInit could be implemented in the user file
\r
204 * @brief DeInitializes the MSP.
\r
207 __weak void HAL_MspDeInit(void)
\r
209 /* NOTE : This function Should not be modified, when the callback is needed,
\r
210 the HAL_MspDeInit could be implemented in the user file
\r
215 * @brief This function configures the source of the time base.
\r
216 * The time source is configured to have 1ms time base with a dedicated
\r
217 * Tick interrupt priority.
\r
218 * @note This function is called automatically at the beginning of program after
\r
219 * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
\r
220 * @note In the default implementation, SysTick timer is the source of time base.
\r
221 * It is used to generate interrupts at regular time intervals.
\r
222 * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
\r
223 * The the SysTick interrupt must have higher priority (numerically lower)
\r
224 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
\r
225 * The function is declared as __weak to be overwritten in case of other
\r
226 * implementation in user file.
\r
227 * @param TickPriority: Tick interrupt priority.
\r
228 * @retval HAL status
\r
230 __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
\r
232 /*Configure the SysTick to have interrupt in 1ms time basis*/
\r
233 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
\r
235 /*Configure the SysTick IRQ priority */
\r
236 HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0);
\r
238 /* Return function status */
\r
246 /** @defgroup HAL_Group2 HAL Control functions
\r
247 * @brief HAL Control functions
\r
250 ===============================================================================
\r
251 ##### HAL Control functions #####
\r
252 ===============================================================================
\r
253 [..] This section provides functions allowing to:
\r
254 (+) Provide a tick value in millisecond
\r
255 (+) Provide a blocking delay in millisecond
\r
256 (+) Suspend the time base source interrupt
\r
257 (+) Resume the time base source interrupt
\r
258 (+) Get the HAL API driver version
\r
259 (+) Get the device identifier
\r
260 (+) Get the device revision identifier
\r
261 (+) Enable/Disable Debug module during SLEEP mode
\r
262 (+) Enable/Disable Debug module during STOP mode
\r
263 (+) Enable/Disable Debug module during STANDBY mode
\r
270 * @brief This function is called to increment a global variable "uwTick"
\r
271 * used as application time base.
\r
272 * @note In the default implementation, this variable is incremented each 1ms
\r
274 * @note This function is declared as __weak to be overwritten in case of other
\r
275 * implementations in user file.
\r
278 __weak void HAL_IncTick(void)
\r
284 * @brief Provides a tick value in millisecond.
\r
285 * @note This function is declared as __weak to be overwritten in case of other
\r
286 * implementations in user file.
\r
287 * @retval tick value
\r
289 __weak uint32_t HAL_GetTick(void)
\r
295 * @brief This function provides accurate delay (in milliseconds) based
\r
296 * on variable incremented.
\r
297 * @note In the default implementation , SysTick timer is the source of time base.
\r
298 * It is used to generate interrupts at regular time intervals where uwTick
\r
300 * @note ThiS function is declared as __weak to be overwritten in case of other
\r
301 * implementations in user file.
\r
302 * @param Delay: specifies the delay time length, in milliseconds.
\r
305 __weak void HAL_Delay(__IO uint32_t Delay)
\r
307 uint32_t tickstart = 0;
\r
308 tickstart = HAL_GetTick();
\r
309 while((HAL_GetTick() - tickstart) < Delay)
\r
315 * @brief Suspend Tick increment.
\r
316 * @note In the default implementation , SysTick timer is the source of time base. It is
\r
317 * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
\r
318 * is called, the the SysTick interrupt will be disabled and so Tick increment
\r
320 * @note This function is declared as __weak to be overwritten in case of other
\r
321 * implementations in user file.
\r
324 __weak void HAL_SuspendTick(void)
\r
326 /* Disable SysTick Interrupt */
\r
327 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
\r
331 * @brief Resume Tick increment.
\r
332 * @note In the default implementation , SysTick timer is the source of time base. It is
\r
333 * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
\r
334 * is called, the the SysTick interrupt will be enabled and so Tick increment
\r
336 * @note This function is declared as __weak to be overwritten in case of other
\r
337 * implementations in user file.
\r
340 __weak void HAL_ResumeTick(void)
\r
342 /* Enable SysTick Interrupt */
\r
343 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
\r
347 * @brief Returns the HAL revision
\r
348 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
\r
350 uint32_t HAL_GetHalVersion(void)
\r
352 return __STM32F7xx_HAL_VERSION;
\r
356 * @brief Returns the device revision identifier.
\r
357 * @retval Device revision identifier
\r
359 uint32_t HAL_GetREVID(void)
\r
361 return((DBGMCU->IDCODE) >> 16);
\r
365 * @brief Returns the device identifier.
\r
366 * @retval Device identifier
\r
368 uint32_t HAL_GetDEVID(void)
\r
370 return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
\r
374 * @brief Enable the Debug Module during SLEEP mode
\r
377 void HAL_DBGMCU_EnableDBGSleepMode(void)
\r
379 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
\r
383 * @brief Disable the Debug Module during SLEEP mode
\r
386 void HAL_DBGMCU_DisableDBGSleepMode(void)
\r
388 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
\r
392 * @brief Enable the Debug Module during STOP mode
\r
395 void HAL_DBGMCU_EnableDBGStopMode(void)
\r
397 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
\r
401 * @brief Disable the Debug Module during STOP mode
\r
404 void HAL_DBGMCU_DisableDBGStopMode(void)
\r
406 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
\r
410 * @brief Enable the Debug Module during STANDBY mode
\r
413 void HAL_DBGMCU_EnableDBGStandbyMode(void)
\r
415 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
\r
419 * @brief Disable the Debug Module during STANDBY mode
\r
422 void HAL_DBGMCU_DisableDBGStandbyMode(void)
\r
424 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
\r
428 * @brief Enables the I/O Compensation Cell.
\r
429 * @note The I/O compensation cell can be used only when the device supply
\r
430 * voltage ranges from 2.4 to 3.6 V.
\r
433 void HAL_EnableCompensationCell(void)
\r
435 SYSCFG->CMPCR |= SYSCFG_CMPCR_CMP_PD;
\r
439 * @brief Power-down the I/O Compensation Cell.
\r
440 * @note The I/O compensation cell can be used only when the device supply
\r
441 * voltage ranges from 2.4 to 3.6 V.
\r
444 void HAL_DisableCompensationCell(void)
\r
446 SYSCFG->CMPCR &= (uint32_t)~((uint32_t)SYSCFG_CMPCR_CMP_PD);
\r
450 * @brief Enables the FMC Memory Mapping Swapping.
\r
452 * @note SDRAM is accessible at 0x60000000
\r
453 * and NOR/RAM is accessible at 0xC0000000
\r
457 void HAL_EnableFMCMemorySwapping(void)
\r
459 SYSCFG->MEMRMP |= SYSCFG_MEMRMP_SWP_FMC_0;
\r
463 * @brief Disables the FMC Memory Mapping Swapping
\r
465 * @note SDRAM is accessible at 0xC0000000 (default mapping)
\r
466 * and NOR/RAM is accessible at 0x60000000 (default mapping)
\r
470 void HAL_DisableFMCMemorySwapping(void)
\r
473 SYSCFG->MEMRMP &= (uint32_t)~((uint32_t)SYSCFG_MEMRMP_SWP_FMC);
\r
492 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r