STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal_cortex.c
Go to the documentation of this file.
1
80/* Includes ------------------------------------------------------------------*/
81#include "stm32f4xx_hal.h"
82
92#ifdef HAL_CORTEX_MODULE_ENABLED
93
94/* Private types -------------------------------------------------------------*/
95/* Private variables ---------------------------------------------------------*/
96/* Private constants ---------------------------------------------------------*/
97/* Private macros ------------------------------------------------------------*/
98/* Private functions ---------------------------------------------------------*/
99/* Exported functions --------------------------------------------------------*/
100
141void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
142{
143 /* Check the parameters */
144 assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
145
146 /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
147 NVIC_SetPriorityGrouping(PriorityGroup);
148}
149
163void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
164{
165 uint32_t prioritygroup = 0x00U;
166
167 /* Check the parameters */
170
171 prioritygroup = NVIC_GetPriorityGrouping();
172
173 NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
174}
175
185void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
186{
187 /* Check the parameters */
189
190 /* Enable interrupt */
191 NVIC_EnableIRQ(IRQn);
192}
193
201void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
202{
203 /* Check the parameters */
205
206 /* Disable interrupt */
207 NVIC_DisableIRQ(IRQn);
208}
209
215{
216 /* System Reset */
217 NVIC_SystemReset();
218}
219
227uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
228{
229 return SysTick_Config(TicksNumb);
230}
251#if (__MPU_PRESENT == 1U)
256void HAL_MPU_Disable(void)
257{
258 /* Make sure outstanding transfers are done */
259 __DMB();
260
261 /* Disable fault exceptions */
262 SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
263
264 /* Disable the MPU and clear the control register*/
265 MPU->CTRL = 0U;
266}
267
279void HAL_MPU_Enable(uint32_t MPU_Control)
280{
281 /* Enable the MPU */
282 MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
283
284 /* Enable fault exceptions */
285 SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
286
287 /* Ensure MPU setting take effects */
288 __DSB();
289 __ISB();
290}
291
296void HAL_MPU_EnableRegion(uint32_t RegionNumber)
297{
298 /* Check the parameters */
299 assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
300
301 /* Set the Region number */
302 MPU->RNR = RegionNumber;
303
304 /* Enable the Region */
305 SET_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
306}
307
312void HAL_MPU_DisableRegion(uint32_t RegionNumber)
313{
314 /* Check the parameters */
315 assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
316
317 /* Set the Region number */
318 MPU->RNR = RegionNumber;
319
320 /* Disable the Region */
321 CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
322}
323
330void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
331{
332 /* Check the parameters */
333 assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
334 assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
335 assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
336 assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
337 assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
338 assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
339 assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
340 assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
341 assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
342 assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
343
344 /* Set the Region number */
345 MPU->RNR = MPU_Init->Number;
346
347 /* Disable the Region */
348 CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
349
350 /* Apply configuration */
351 MPU->RBAR = MPU_Init->BaseAddress;
352 MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) |
353 ((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) |
354 ((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) |
355 ((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) |
356 ((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) |
357 ((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) |
358 ((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) |
359 ((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) |
360 ((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
361}
362#endif /* __MPU_PRESENT */
363
369{
370 __SEV();
371 __WFE();
372}
373
379{
380 /* Get the PRIGROUP[10:8] field value */
381 return NVIC_GetPriorityGrouping();
382}
383
405void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
406{
407 /* Check the parameters */
408 assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
409 /* Get priority for Cortex-M system or device specific interrupts */
410 NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
411}
412
420void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
421{
422 /* Check the parameters */
424
425 /* Set interrupt pending */
426 NVIC_SetPendingIRQ(IRQn);
427}
428
438uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
439{
440 /* Check the parameters */
442
443 /* Return 1 if pending else 0 */
444 return NVIC_GetPendingIRQ(IRQn);
445}
446
454void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
455{
456 /* Check the parameters */
458
459 /* Clear pending interrupt */
460 NVIC_ClearPendingIRQ(IRQn);
461}
462
471uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
472{
473 /* Check the parameters */
475
476 /* Return 1 if active else 0 */
477 return NVIC_GetActive(IRQn);
478}
479
488void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
489{
490 /* Check the parameters */
492 if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
493 {
494 SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
495 }
496 else
497 {
498 SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
499 }
500}
501
510
515__weak void HAL_SYSTICK_Callback(void)
516{
517 /* NOTE : This function Should not be modified, when the callback is needed,
518 the HAL_SYSTICK_Callback could be implemented in the user file
519 */
520}
521
530#endif /* HAL_CORTEX_MODULE_ENABLED */
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
Disables a device specific interrupt in the NVIC interrupt controller.
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
Sets the priority of an interrupt.
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
Enables a device specific interrupt in the NVIC interrupt controller.
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_SystemReset(void)
Initiates a system reset request to reset the MCU.
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
Sets the priority grouping field (preemption priority and subpriority) using the required unlock sequ...
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
Clears the pending bit of an external interrupt.
void HAL_CORTEX_ClearEvent(void)
Clear pending events.
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
Configures the SysTick clock source.
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
Gets Pending Interrupt (reads the pending register in the NVIC and returns the pending bit for the sp...
void HAL_SYSTICK_IRQHandler(void)
This function handles SYSTICK interrupt request.
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
Gets the priority of an interrupt.
uint32_t HAL_NVIC_GetPriorityGrouping(void)
Gets the priority grouping field from the NVIC Interrupt Controller.
void HAL_SYSTICK_Callback(void)
SYSTICK callback.
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
Gets active interrupt ( reads the active register in NVIC and returns the active bit).
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
Sets Pending bit of an external interrupt.
#define IS_NVIC_SUB_PRIORITY(PRIORITY)
#define IS_SYSTICK_CLK_SOURCE(SOURCE)
#define IS_NVIC_PRIORITY_GROUP(GROUP)
#define IS_NVIC_DEVICE_IRQ(IRQ)
#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY)
#define SYSTICK_CLKSOURCE_HCLK
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.