HAL CORTEX How to Use ¶
- group CORTEX_How_To_Use
-
CORTEX main features ¶
The HAL CORTEX driver contains four main blocks: ¶
-
NVIC: Nested Vector Interrupt Controller
-
The NVIC is an embedded interrupt controller that supports low-latency interrupt processing.
-
It contains a configurable interrupt handling ability. Configured items can be:
-
Priority grouping that specifies the range of preemption priority and sub priority.
-
Preemption priority ability between interrupts.
-
Subpriority ability between interrupts.
-
-
-
Within the Cortex-M33, the NVIC block is banked :
-
Secure NVIC to handle secure configurable interrupts.
-
Non-Secure NVIC to handle non-secure configurable interrupts.
-
-
-
SYSTICK: System Timer
-
The SysTick, is a 24 bits count-down timer. It can be used as a simple counter or as tick timer in a real time operating system (RTOS).
-
Within the Cortex-M33, the SYSTICK block is banked :
-
Secure SYSTICK to be used for the secure application.
-
Non-Secure SYSTICK to be used for the non-secure application.
-
-
-
MPU: Memory Protection Unit
-
The MPU allows a privileged software to define memory regions, assign memory access permission and memory attributes to each of them to improve the system reliability.
-
Within the Cortex-M33, the MPU block is banked :
-
Secure MPU to be used for secure regions definition (Up to 12 regions).
-
Non-Secure MPU to be used for non-secure regions definition (Up to 8 regions).
-
-
-
SCB: System Control Block
-
The SCB provides system information and system control that includes configuration, control and reporting of system fault exceptions.
-
How to use the CORTEX HAL module driver ¶
The CORTEX HAL driver can be used as follows : ¶
This driver provides the HAL_CORTEX driver functions allowing to configure the NVIC, SYSTICK, MPU and SCB blocks.
-
How to configure NVIC Interrupts using CORTEX HAL driver :
-
Configure the NVIC Priority Grouping using HAL_CORTEX_NVIC_SetPriorityGrouping() function ones at startup.
-
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_0 is selected, IRQ pre-emption is no more configurable. The pending IRQ priority is managed only by the sub-priority.
-
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_1 is selected, there is one bit for preemption priority and three bits for sub-priority.
-
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_2 is selected, there are two bits for preemption priority and two bits for sub-priority.
-
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_3 is selected, there are three bits for preemption priority and one bit for sub-priority.
-
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_4 is selected, IRQ sub-priority is no more configurable. The pending IRQ priority is managed only by the pre-emption priority.
-
-
Configure the priority of the selected IRQ channels using HAL_CORTEX_NVIC_SetPriority() function :
-
IRQ priority order (sorted by highest to lowest priority):
-
The lowest is the preemption priority numerical value, the highest is the preemption priority.
-
The lowest is the subpriority numerical value, the the highest is the subpriority.
-
-
Get the priority grouping using HAL_CORTEX_NVIC_GetPriorityGrouping() function.
-
Get the priority of an interrupt using HAL_CORTEX_NVIC_GetPriority() function.
-
-
Enable the selected IRQ channels using HAL_CORTEX_NVIC_EnableIRQ() function.
-
Disable the selected IRQ channels using HAL_CORTEX_NVIC_DisableIRQ() function.
-
To check if an IRQ channel is enable or not, use HAL_CORTEX_NVIC_IsEnabledIRQ() function.
-
To check if an IRQ channel is active or not, use HAL_CORTEX_NVIC_IsActiveIRQ() function.
-
To set pending bit of an interrupt, use HAL_CORTEX_NVIC_SetPendingIRQ() function.
-
To check if the IRQn channel is in pending state or not, use HAL_CORTEX_NVIC_IsPendingIRQ() function. When pending, use HAL_CORTEX_NVIC_ClearPendingIRQ() to clear the event.
-
When a system reset is needed within the application, use HAL_CORTEX_NVIC_SystemReset() function.
-
Configure the security attribute of the selected interrupt using HAL_CORTEX_NVIC_SetIRQSecureAttr() function.
-
Get the security attribute of the Interrupt using HAL_CORTEX_NVIC_GetIRQSecureAttr() function.
-
Within the Cortex-M33 driver, all NVIC IRQ management functions are banked. APIs titled HAL_CORTEX_NVICNS_XXX() are provided to manage NVIC non-secure instance by a secure software.
-
To redirect an IRQ channel to secure NVIC instance or a non-secure NVIC instance, use HAL_CORTEX_NVIC_SetIRQSecureAttr() , this API can be used only by a secure code.
-
-
-
How to configure SYSTICK using CORTEX HAL driver :
-
Configure the SYSTICK notification frequency and its source clock using HAL_CORTEX_SYSTICK_SetFreq() and HAL_CORTEX_SYSTICK_SetClkSource() functions.
-
To suspend the SYSTICK, use HAL_CORTEX_SYSTICK_Suspend() function. when suspending use HAL_CORTEX_SYSTICK_Resume() function to resume the SYSTICK.
-
To handle the SYSTICK interrupts, use HAL_CORTEX_SYSTICK_IRQHandler() function.
-
Within the Cortex-M33 driver, the functions HAL_CORTEX_SYSTICK_SetFreq() and HAL_CORTEX_SYSTICK_SetClkSource() are banked. APIs titled HAL_CORTEX_SYSTICKNS_SetFreq() and HAL_CORTEX_SYSTICKNS_SetClkSource() are provided to configure SYSTICK non-secure instance by a secure software.
-
-
How to configure MPU using CORTEX HAL driver :
-
To configure a device memory attribute, use HAL_CORTEX_MPU_SetDeviceMemAttr() function and to configure a normal memory (cache memory), use HAL_CORTEX_MPU_SetCacheMemAttr() function.
-
To get the device memory attributes config, use HAL_CORTEX_MPU_GetDeviceMemAttr() function.
-
To get the cache memory attributes config, use HAL_CORTEX_MPU_GetCacheMemAttr() function.
-
To configure an MPU region, use HAL_CORTEX_MPU_SetConfigRegion() function.
-
To get the MPU region config, use HAL_CORTEX_MPU_GetConfigRegion() function.
-
To enable or disable an MPU region, use HAL_CORTEX_MPU_EnableRegion() or HAL_CORTEX_MPU_DisableRegion() functions.
-
To enable or disable the MPU, use HAL_CORTEX_MPU_Enable() or HAL_CORTEX_MPU_Disable() functions.
-
To check if the MPU is enabled or not, use HAL_CORTEX_MPU_IsEnabled() function.
-
To check if the given MPU region is enabled or not, use HAL_CORTEX_MPU_IsEnabledRegion() function.
-
Within the Cortex-M33 driver, all MPU management functions are banked. APIs titled HAL_CORTEX_MPUNS_XXX() are provided to manage MPU non-secure instance by a secure software.
-
-
How to configure SCB using CORTEX HAL driver :
-
When there is a need to get the CPU ID information within the application, use HAL_CORTEX_SCB_GetInfo() function.
-
Some exceptions can be redirected to their own IRQ channels or to HARDFAULT IRQ channel. These exceptions are :
-
USAGE FAULT
-
BUS FAULT
-
MEMORY MANAGEMENT FAULT
-
SECURE FAULT (Limited to Cortex-M33 when TrustZone is enabled)
-
-
When there is a need to redirect any exception to a hardfault, use HAL_CORTEX_SCB_DisableHardFaultEscalation() function.
-
When there is a need to disable any hardfault redirection, use HAL_CORTEX_SCB_EnableHardFaultEscalation() function.
-
Within the Cortex-M33 driver, the functions HAL_CORTEX_SCB_DisableHardFaultEscalation() and HAL_CORTEX_SCB_EnableHardFaultEscalation() are banked. APIs titled HAL_CORTEX_SCBNS_DisableHardFaultEscalation() and HAL_CORTEX_SCBNS_EnableHardFaultEscalation() are provided to manage SCB non-secure instance by a secure software.
-
-