2
2
******************************************************************************
3
3
* @file stm32f4xx_hal.c
4
4
* @author MCD Application Team
5
- * @version V1.7.1
6
- * @date 14-April-2017
7
5
* @brief HAL module driver.
8
6
* This is the common part of the HAL initialization
9
7
*
68
66
* @{
69
67
*/
70
68
/**
71
- * @brief STM32F4xx HAL Driver version number V1.7.1
69
+ * @brief STM32F4xx HAL Driver version number V1.7.3
72
70
*/
73
71
#define __STM32F4xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
74
72
#define __STM32F4xx_HAL_VERSION_SUB1 (0x07U) /*!< [23:16] sub1 version */
75
- #define __STM32F4xx_HAL_VERSION_SUB2 (0x01U ) /*!< [15:8] sub2 version */
73
+ #define __STM32F4xx_HAL_VERSION_SUB2 (0x03U ) /*!< [15:8] sub2 version */
76
74
#define __STM32F4xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
77
75
#define __STM32F4xx_HAL_VERSION ((__STM32F4xx_HAL_VERSION_MAIN << 24U)\
78
76
|(__STM32F4xx_HAL_VERSION_SUB1 << 16U)\
86
84
/* --- MEMRMP Register ---*/
87
85
/* Alias word address of UFB_MODE bit */
88
86
#define MEMRMP_OFFSET SYSCFG_OFFSET
89
- #define UFB_MODE_BIT_NUMBER POSITION_VAL(SYSCFG_MEMRMP_UFB_MODE)
87
+ #define UFB_MODE_BIT_NUMBER SYSCFG_MEMRMP_UFB_MODE_Pos
90
88
#define UFB_MODE_BB (uint32_t)(PERIPH_BB_BASE + (MEMRMP_OFFSET * 32U) + (UFB_MODE_BIT_NUMBER * 4U))
91
89
92
90
/* --- CMPCR Register ---*/
93
91
/* Alias word address of CMP_PD bit */
94
92
#define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20U)
95
- #define CMP_PD_BIT_NUMBER POSITION_VAL(SYSCFG_CMPCR_CMP_PD)
93
+ #define CMP_PD_BIT_NUMBER SYSCFG_CMPCR_CMP_PD_Pos
96
94
#define CMPCR_CMP_PD_BB (uint32_t)(PERIPH_BB_BASE + (CMPCR_OFFSET * 32U) + (CMP_PD_BIT_NUMBER * 4U))
97
95
98
96
/* --- MCHDLYCR Register ---*/
99
97
/* Alias word address of BSCKSEL bit */
100
98
#define MCHDLYCR_OFFSET (SYSCFG_OFFSET + 0x30U)
101
- #define BSCKSEL_BIT_NUMBER POSITION_VAL(SYSCFG_MCHDLYCR_BSCKSEL)
99
+ #define BSCKSEL_BIT_NUMBER SYSCFG_MCHDLYCR_BSCKSEL_Pos
102
100
#define MCHDLYCR_BSCKSEL_BB (uint32_t)(PERIPH_BB_BASE + (MCHDLYCR_OFFSET * 32U) + (BSCKSEL_BIT_NUMBER * 4U))
103
101
/**
104
102
* @}
110
108
* @{
111
109
*/
112
110
__IO uint32_t uwTick ;
111
+ uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS ); /* Invalid PRIO */
112
+ HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT ; /* 1KHz */
113
113
/**
114
114
* @}
115
115
*/
@@ -125,16 +125,16 @@ __IO uint32_t uwTick;
125
125
*
126
126
@verbatim
127
127
===============================================================================
128
- ##### Initialization and de-initialization functions #####
128
+ ##### Initialization and Configuration functions #####
129
129
===============================================================================
130
130
[..] This section provides functions allowing to:
131
131
(+) Initializes the Flash interface the NVIC allocation and initial clock
132
132
configuration. It initializes the systick also when timeout is needed
133
133
and the backup domain when enabled.
134
- (+) de -Initializes common part of the HAL
135
- (+) Configure The time base source to have 1ms time base with a dedicated
134
+ (+) De -Initializes common part of the HAL.
135
+ (+) Configure the time base source to have 1ms time base with a dedicated
136
136
Tick interrupt priority.
137
- (++) Systick timer is used by default as source of time base, but user
137
+ (++) SysTick timer is used by default as source of time base, but user
138
138
can eventually implement his proper time base source (a general purpose
139
139
timer for example or other time source), keeping in mind that Time base
140
140
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
@@ -174,23 +174,29 @@ HAL_StatusTypeDef HAL_Init(void)
174
174
{
175
175
/* Configure Flash prefetch, Instruction cache, Data cache */
176
176
#if (INSTRUCTION_CACHE_ENABLE != 0U )
177
- __HAL_FLASH_INSTRUCTION_CACHE_ENABLE ();
177
+ __HAL_FLASH_INSTRUCTION_CACHE_ENABLE ();
178
178
#endif /* INSTRUCTION_CACHE_ENABLE */
179
179
180
180
#if (DATA_CACHE_ENABLE != 0U )
181
- __HAL_FLASH_DATA_CACHE_ENABLE ();
181
+ __HAL_FLASH_DATA_CACHE_ENABLE ();
182
182
#endif /* DATA_CACHE_ENABLE */
183
183
184
184
#if (PREFETCH_ENABLE != 0U )
185
185
__HAL_FLASH_PREFETCH_BUFFER_ENABLE ();
186
186
#endif /* PREFETCH_ENABLE */
187
187
188
+ /* Set Interrupt Group Priority */
189
+ /* MBED : moved to HAL_InitPre() */
190
+ #if !defined (TARGET_STM32F429xI )
191
+ HAL_NVIC_SetPriorityGrouping (NVIC_PRIORITYGROUP_4 );
192
+ #endif
193
+
188
194
/* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
189
195
HAL_InitTick (TICK_INT_PRIORITY );
190
-
196
+
191
197
/* Init the low level hardware */
192
198
HAL_MspInit ();
193
-
199
+
194
200
/* Return function status */
195
201
return HAL_OK ;
196
202
}
@@ -226,12 +232,12 @@ HAL_StatusTypeDef HAL_DeInit(void)
226
232
}
227
233
228
234
/**
229
- * @brief Initializes the MSP.
235
+ * @brief Initialize the MSP.
230
236
* @retval None
231
237
*/
232
238
__weak void HAL_MspInit (void )
233
239
{
234
- /* NOTE : This function Should not be modified, when the callback is needed,
240
+ /* NOTE : This function should not be modified, when the callback is needed,
235
241
the HAL_MspInit could be implemented in the user file
236
242
*/
237
243
}
@@ -242,7 +248,7 @@ __weak void HAL_MspInit(void)
242
248
*/
243
249
__weak void HAL_MspDeInit (void )
244
250
{
245
- /* NOTE : This function Should not be modified, when the callback is needed,
251
+ /* NOTE : This function should not be modified, when the callback is needed,
246
252
the HAL_MspDeInit could be implemented in the user file
247
253
*/
248
254
}
@@ -256,20 +262,31 @@ __weak void HAL_MspDeInit(void)
256
262
* @note In the default implementation, SysTick timer is the source of time base.
257
263
* It is used to generate interrupts at regular time intervals.
258
264
* Care must be taken if HAL_Delay() is called from a peripheral ISR process,
259
- * The the SysTick interrupt must have higher priority (numerically lower)
265
+ * The SysTick interrupt must have higher priority (numerically lower)
260
266
* than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
261
267
* The function is declared as __weak to be overwritten in case of other
262
268
* implementation in user file.
263
- * @param TickPriority: Tick interrupt priority.
269
+ * @param TickPriority Tick interrupt priority.
264
270
* @retval HAL status
265
271
*/
266
272
__weak HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority )
267
273
{
268
- /*Configure the SysTick to have interrupt in 1ms time basis*/
269
- HAL_SYSTICK_Config (SystemCoreClock /1000U );
274
+ /* Configure the SysTick to have interrupt in 1ms time basis*/
275
+ if (HAL_SYSTICK_Config (SystemCoreClock / (1000U / uwTickFreq )) > 0U )
276
+ {
277
+ return HAL_ERROR ;
278
+ }
270
279
271
- /*Configure the SysTick IRQ priority */
272
- HAL_NVIC_SetPriority (SysTick_IRQn , TickPriority , 0U );
280
+ /* Configure the SysTick IRQ priority */
281
+ if (TickPriority < (1UL << __NVIC_PRIO_BITS ))
282
+ {
283
+ HAL_NVIC_SetPriority (SysTick_IRQn , TickPriority , 0U );
284
+ uwTickPrio = TickPriority ;
285
+ }
286
+ else
287
+ {
288
+ return HAL_ERROR ;
289
+ }
273
290
274
291
/* Return function status */
275
292
return HAL_OK ;
@@ -306,14 +323,14 @@ __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
306
323
* @brief This function is called to increment a global variable "uwTick"
307
324
* used as application time base.
308
325
* @note In the default implementation, this variable is incremented each 1ms
309
- * in Systick ISR.
326
+ * in SysTick ISR.
310
327
* @note This function is declared as __weak to be overwritten in case of other
311
328
* implementations in user file.
312
329
* @retval None
313
330
*/
314
331
__weak void HAL_IncTick (void )
315
332
{
316
- uwTick ++ ;
333
+ uwTick += uwTickFreq ;
317
334
}
318
335
319
336
/**
@@ -327,6 +344,44 @@ __weak uint32_t HAL_GetTick(void)
327
344
return uwTick ;
328
345
}
329
346
347
+ /**
348
+ * @brief This function returns a tick priority.
349
+ * @retval tick priority
350
+ */
351
+ uint32_t HAL_GetTickPrio (void )
352
+ {
353
+ return uwTickPrio ;
354
+ }
355
+
356
+ /**
357
+ * @brief Set new tick Freq.
358
+ * @retval Status
359
+ */
360
+ HAL_StatusTypeDef HAL_SetTickFreq (HAL_TickFreqTypeDef Freq )
361
+ {
362
+ HAL_StatusTypeDef status = HAL_OK ;
363
+ assert_param (IS_TICKFREQ (Freq ));
364
+
365
+ if (uwTickFreq != Freq )
366
+ {
367
+ uwTickFreq = Freq ;
368
+
369
+ /* Apply the new tick Freq */
370
+ status = HAL_InitTick (uwTickPrio );
371
+ }
372
+
373
+ return status ;
374
+ }
375
+
376
+ /**
377
+ * @brief Return tick frequency.
378
+ * @retval tick period in Hz
379
+ */
380
+ HAL_TickFreqTypeDef HAL_GetTickFreq (void )
381
+ {
382
+ return uwTickFreq ;
383
+ }
384
+
330
385
/**
331
386
* @brief This function provides minimum delay (in milliseconds) based
332
387
* on variable incremented.
@@ -335,20 +390,20 @@ __weak uint32_t HAL_GetTick(void)
335
390
* is incremented.
336
391
* @note This function is declared as __weak to be overwritten in case of other
337
392
* implementations in user file.
338
- * @param Delay: specifies the delay time length, in milliseconds.
393
+ * @param Delay specifies the delay time length, in milliseconds.
339
394
* @retval None
340
395
*/
341
- __weak void HAL_Delay (__IO uint32_t Delay )
396
+ __weak void HAL_Delay (uint32_t Delay )
342
397
{
343
398
uint32_t tickstart = HAL_GetTick ();
344
399
uint32_t wait = Delay ;
345
-
346
- /* Add a period to guarantee minimum wait */
400
+
401
+ /* Add a freq to guarantee minimum wait */
347
402
if (wait < HAL_MAX_DELAY )
348
403
{
349
- wait ++ ;
404
+ wait += ( uint32_t )( uwTickFreq ) ;
350
405
}
351
-
406
+
352
407
while ((HAL_GetTick () - tickstart ) < wait )
353
408
{
354
409
}
@@ -392,7 +447,7 @@ __weak void HAL_ResumeTick(void)
392
447
*/
393
448
uint32_t HAL_GetHalVersion (void )
394
449
{
395
- return __STM32F4xx_HAL_VERSION ;
450
+ return __STM32F4xx_HAL_VERSION ;
396
451
}
397
452
398
453
/**
@@ -401,7 +456,7 @@ uint32_t HAL_GetHalVersion(void)
401
456
*/
402
457
uint32_t HAL_GetREVID (void )
403
458
{
404
- return ((DBGMCU -> IDCODE ) >> 16U );
459
+ return ((DBGMCU -> IDCODE ) >> 16U );
405
460
}
406
461
407
462
/**
@@ -410,7 +465,7 @@ uint32_t HAL_GetREVID(void)
410
465
*/
411
466
uint32_t HAL_GetDEVID (void )
412
467
{
413
- return ((DBGMCU -> IDCODE ) & IDCODE_DEVID_MASK );
468
+ return ((DBGMCU -> IDCODE ) & IDCODE_DEVID_MASK );
414
469
}
415
470
416
471
/**
@@ -491,7 +546,7 @@ void HAL_DisableCompensationCell(void)
491
546
492
547
/**
493
548
* @brief Return the unique device identifier (UID based on 96 bits)
494
- * @param UID: pointer to 3 words array.
549
+ * @param UID pointer to 3 words array.
495
550
* @retval Device identifier
496
551
*/
497
552
void HAL_GetUID (uint32_t * UID )
@@ -530,7 +585,6 @@ void HAL_EnableMemorySwappingBank(void)
530
585
*/
531
586
void HAL_DisableMemorySwappingBank (void )
532
587
{
533
-
534
588
* (__IO uint32_t * )UFB_MODE_BB = (uint32_t )DISABLE ;
535
589
}
536
590
#endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */
0 commit comments