STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal.c
Go to the documentation of this file.
1
35/* Includes ------------------------------------------------------------------*/
36#include "stm32f4xx_hal.h"
37
47/* Private typedef -----------------------------------------------------------*/
48/* Private define ------------------------------------------------------------*/
55#define __STM32F4xx_HAL_VERSION_MAIN (0x01U)
56#define __STM32F4xx_HAL_VERSION_SUB1 (0x08U)
57#define __STM32F4xx_HAL_VERSION_SUB2 (0x03U)
58#define __STM32F4xx_HAL_VERSION_RC (0x00U)
59#define __STM32F4xx_HAL_VERSION ((__STM32F4xx_HAL_VERSION_MAIN << 24U)\
60 |(__STM32F4xx_HAL_VERSION_SUB1 << 16U)\
61 |(__STM32F4xx_HAL_VERSION_SUB2 << 8U )\
62 |(__STM32F4xx_HAL_VERSION_RC))
63
64#define IDCODE_DEVID_MASK 0x00000FFFU
65
66/* ------------ RCC registers bit address in the alias region ----------- */
67#define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE)
68/* --- MEMRMP Register ---*/
69/* Alias word address of UFB_MODE bit */
70#define MEMRMP_OFFSET SYSCFG_OFFSET
71#define UFB_MODE_BIT_NUMBER SYSCFG_MEMRMP_UFB_MODE_Pos
72#define UFB_MODE_BB (uint32_t)(PERIPH_BB_BASE + (MEMRMP_OFFSET * 32U) + (UFB_MODE_BIT_NUMBER * 4U))
73
74/* --- CMPCR Register ---*/
75/* Alias word address of CMP_PD bit */
76#define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20U)
77#define CMP_PD_BIT_NUMBER SYSCFG_CMPCR_CMP_PD_Pos
78#define CMPCR_CMP_PD_BB (uint32_t)(PERIPH_BB_BASE + (CMPCR_OFFSET * 32U) + (CMP_PD_BIT_NUMBER * 4U))
79
80/* --- MCHDLYCR Register ---*/
81/* Alias word address of BSCKSEL bit */
82#define MCHDLYCR_OFFSET (SYSCFG_OFFSET + 0x30U)
83#define BSCKSEL_BIT_NUMBER SYSCFG_MCHDLYCR_BSCKSEL_Pos
84#define MCHDLYCR_BSCKSEL_BB (uint32_t)(PERIPH_BB_BASE + (MCHDLYCR_OFFSET * 32U) + (BSCKSEL_BIT_NUMBER * 4U))
89/* Private macro -------------------------------------------------------------*/
90/* Private variables ---------------------------------------------------------*/
94__IO uint32_t uwTick;
95uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
100/* Private function prototypes -----------------------------------------------*/
101/* Private functions ---------------------------------------------------------*/
102
158{
159 /* Configure Flash prefetch, Instruction cache, Data cache */
160#if (INSTRUCTION_CACHE_ENABLE != 0U)
162#endif /* INSTRUCTION_CACHE_ENABLE */
163
164#if (DATA_CACHE_ENABLE != 0U)
166#endif /* DATA_CACHE_ENABLE */
167
168#if (PREFETCH_ENABLE != 0U)
170#endif /* PREFETCH_ENABLE */
171
172 /* Set Interrupt Group Priority */
174
175 /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
177
178 /* Init the low level hardware */
179 HAL_MspInit();
180
181 /* Return function status */
182 return HAL_OK;
183}
184
191{
192 /* Reset of all peripherals */
195
198
201
204
207
208 /* De-Init the low level hardware */
210
211 /* Return function status */
212 return HAL_OK;
213}
214
219__weak void HAL_MspInit(void)
220{
221 /* NOTE : This function should not be modified, when the callback is needed,
222 the HAL_MspInit could be implemented in the user file
223 */
224}
225
230__weak void HAL_MspDeInit(void)
231{
232 /* NOTE : This function should not be modified, when the callback is needed,
233 the HAL_MspDeInit could be implemented in the user file
234 */
235}
236
253__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
254{
255 /* Configure the SysTick to have interrupt in 1ms time basis*/
256 if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
257 {
258 return HAL_ERROR;
259 }
260
261 /* Configure the SysTick IRQ priority */
262 if (TickPriority < (1UL << __NVIC_PRIO_BITS))
263 {
264 HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
265 uwTickPrio = TickPriority;
266 }
267 else
268 {
269 return HAL_ERROR;
270 }
271
272 /* Return function status */
273 return HAL_OK;
274}
275
312__weak void HAL_IncTick(void)
313{
315}
316
323__weak uint32_t HAL_GetTick(void)
324{
325 return uwTick;
326}
327
332uint32_t HAL_GetTickPrio(void)
333{
334 return uwTickPrio;
335}
336
342{
343 HAL_StatusTypeDef status = HAL_OK;
344 HAL_TickFreqTypeDef prevTickFreq;
345
347
348 if (uwTickFreq != Freq)
349 {
350 /* Back up uwTickFreq frequency */
351 prevTickFreq = uwTickFreq;
352
353 /* Update uwTickFreq global variable used by HAL_InitTick() */
354 uwTickFreq = Freq;
355
356 /* Apply the new tick Freq */
357 status = HAL_InitTick(uwTickPrio);
358
359 if (status != HAL_OK)
360 {
361 /* Restore previous tick frequency */
362 uwTickFreq = prevTickFreq;
363 }
364 }
365
366 return status;
367}
368
378
390__weak void HAL_Delay(uint32_t Delay)
391{
392 uint32_t tickstart = HAL_GetTick();
393 uint32_t wait = Delay;
394
395 /* Add a freq to guarantee minimum wait */
396 if (wait < HAL_MAX_DELAY)
397 {
398 wait += (uint32_t)(uwTickFreq);
399 }
400
401 while((HAL_GetTick() - tickstart) < wait)
402 {
403 }
404}
405
416__weak void HAL_SuspendTick(void)
417{
418 /* Disable SysTick Interrupt */
419 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
420}
421
432__weak void HAL_ResumeTick(void)
433{
434 /* Enable SysTick Interrupt */
435 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
436}
437
442uint32_t HAL_GetHalVersion(void)
443{
445}
446
451uint32_t HAL_GetREVID(void)
452{
453 return((DBGMCU->IDCODE) >> 16U);
454}
455
460uint32_t HAL_GetDEVID(void)
461{
462 return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
463}
464
470{
471 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
472}
473
479{
480 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
481}
482
488{
489 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
490}
491
497{
498 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
499}
500
506{
507 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
508}
509
515{
516 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
517}
518
526{
527 *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)ENABLE;
528}
529
537{
538 *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)DISABLE;
539}
540
545uint32_t HAL_GetUIDw0(void)
546{
547 return (READ_REG(*((uint32_t *)UID_BASE)));
548}
549
554uint32_t HAL_GetUIDw1(void)
555{
556 return (READ_REG(*((uint32_t *)(UID_BASE + 4U))));
557}
558
563uint32_t HAL_GetUIDw2(void)
564{
565 return (READ_REG(*((uint32_t *)(UID_BASE + 8U))));
566}
567
568#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\
569 defined(STM32F469xx) || defined(STM32F479xx)
580void HAL_EnableMemorySwappingBank(void)
581{
582 *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)ENABLE;
583}
584
595void HAL_DisableMemorySwappingBank(void)
596{
597 *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)DISABLE;
598}
599#endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
Sets the priority of an interrupt.
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
Initializes the System Timer and its interrupt, and starts the System Tick Timer. Counter is in free ...
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
Sets the priority grouping field (preemption priority and subpriority) using the required unlock sequ...
#define NVIC_PRIORITYGROUP_4
#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()
Enable the FLASH prefetch buffer.
#define __HAL_FLASH_DATA_CACHE_ENABLE()
Enable the FLASH data cache.
#define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE()
Enable the FLASH instruction cache.
void HAL_MspInit(void)
Initialize the MSP.
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
This function configures the source of the time base. The time source is configured to have 1ms time ...
HAL_StatusTypeDef HAL_DeInit(void)
This function de-Initializes common part of the HAL and stops the systick. This function is optional.
void HAL_MspDeInit(void)
DeInitializes the MSP.
HAL_StatusTypeDef HAL_Init(void)
This function is used to initialize the HAL Library; it must be the first instruction to be executed ...
void HAL_EnableCompensationCell(void)
Enables the I/O Compensation Cell.
void HAL_DBGMCU_EnableDBGStandbyMode(void)
Enable the Debug Module during STANDBY mode.
void HAL_DBGMCU_DisableDBGStopMode(void)
Disable the Debug Module during STOP mode.
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
Set new tick Freq.
uint32_t HAL_GetUIDw1(void)
Returns second word of the unique device identifier (UID based on 96 bits)
uint32_t HAL_GetUIDw2(void)
Returns third word of the unique device identifier (UID based on 96 bits)
void HAL_DisableCompensationCell(void)
Power-down the I/O Compensation Cell.
void HAL_DBGMCU_DisableDBGStandbyMode(void)
Disable the Debug Module during STANDBY mode.
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
Return tick frequency.
void HAL_SuspendTick(void)
Suspend Tick increment.
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
void HAL_IncTick(void)
This function is called to increment a global variable "uwTick" used as application time base.
void HAL_ResumeTick(void)
Resume Tick increment.
void HAL_DBGMCU_DisableDBGSleepMode(void)
Disable the Debug Module during SLEEP mode.
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
uint32_t HAL_GetTickPrio(void)
This function returns a tick priority.
void HAL_DBGMCU_EnableDBGStopMode(void)
Enable the Debug Module during STOP mode.
uint32_t HAL_GetREVID(void)
Returns the device revision identifier.
void HAL_DBGMCU_EnableDBGSleepMode(void)
Enable the Debug Module during SLEEP mode.
uint32_t HAL_GetUIDw0(void)
Returns first word of the unique device identifier (UID based on 96 bits)
uint32_t HAL_GetHalVersion(void)
Returns the HAL revision.
uint32_t HAL_GetDEVID(void)
Returns the device identifier.
#define __STM32F4xx_HAL_VERSION
#define UFB_MODE_BB
#define CMPCR_CMP_PD_BB
#define IDCODE_DEVID_MASK
#define IS_TICKFREQ(FREQ)
uint32_t uwTickPrio
HAL_TickFreqTypeDef uwTickFreq
__IO uint32_t uwTick
HAL_TickFreqTypeDef
@ HAL_TICK_FREQ_DEFAULT
#define __HAL_RCC_AHB1_FORCE_RESET()
#define __HAL_RCC_AHB2_RELEASE_RESET()
#define __HAL_RCC_AHB2_FORCE_RESET()
#define __HAL_RCC_AHB3_RELEASE_RESET()
#define __HAL_RCC_AHB3_FORCE_RESET()
#define __HAL_RCC_APB1_FORCE_RESET()
#define __HAL_RCC_APB2_FORCE_RESET()
#define __HAL_RCC_AHB1_RELEASE_RESET()
#define __HAL_RCC_APB1_RELEASE_RESET()
#define __HAL_RCC_APB2_RELEASE_RESET()
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
#define TICK_INT_PRIORITY
HAL_StatusTypeDef
HAL Status structures definition
@ HAL_ERROR
@ HAL_OK
#define HAL_MAX_DELAY