ADS124S08 Bibliothek hinzugefügt, erste möglichkeit wie auswertung funktionieren könnte hinzugefügt, sollte aber noch weniger blockierend gemacht werden
This commit is contained in:
1067
Software/Station_SW/Drivers/STM32U3xx_HAL_Driver/Src/stm32u3xx_hal.c
Normal file
1067
Software/Station_SW/Drivers/STM32U3xx_HAL_Driver/Src/stm32u3xx_hal.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,875 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32u3xx_hal_cortex.c
|
||||
* @author MCD Application Team
|
||||
* @brief CORTEX HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the CORTEX:
|
||||
* + Initialization and Configuration functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
|
||||
[..]
|
||||
*** How to configure Interrupts using CORTEX HAL driver ***
|
||||
===========================================================
|
||||
[..]
|
||||
This section provides functions allowing to configure the NVIC interrupts (IRQ).
|
||||
The Cortex-M33 exceptions are managed by CMSIS functions.
|
||||
|
||||
(#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping() function.
|
||||
(#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority().
|
||||
(#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ().
|
||||
|
||||
-@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ pre-emption is no more possible.
|
||||
The pending IRQ priority will be managed only by the sub priority.
|
||||
|
||||
-@- IRQ priority order (sorted by highest to lowest priority):
|
||||
(+@) Lowest pre-emption priority
|
||||
(+@) Lowest sub priority
|
||||
(+@) Lowest hardware priority (IRQ number)
|
||||
|
||||
[..]
|
||||
*** How to configure SysTick using CORTEX HAL driver ***
|
||||
========================================================
|
||||
[..]
|
||||
Setup SysTick Timer for time base.
|
||||
|
||||
(+) The HAL_SYSTICK_Config() function calls the SysTick_Config() function which
|
||||
is a CMSIS function that:
|
||||
(++) Configures the SysTick Reload register with value passed as function parameter.
|
||||
(++) Configures the SysTick IRQ priority to the lowest value (0x0F).
|
||||
(++) Resets the SysTick Counter register.
|
||||
(++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
|
||||
(++) Enables the SysTick Interrupt.
|
||||
(++) Starts the SysTick Counter.
|
||||
|
||||
(+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
|
||||
__HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
|
||||
HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
|
||||
inside the stm32u3xx_hal_cortex.h file.
|
||||
|
||||
(+) You can change the SysTick IRQ priority by calling the
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function
|
||||
call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
|
||||
|
||||
(+) To adjust the SysTick time base, use the following formula:
|
||||
|
||||
Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
|
||||
(++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
|
||||
(++) Reload Value should not exceed 0xFFFFFF
|
||||
|
||||
[..]
|
||||
*** How to configure MPU using CORTEX HAL driver ***
|
||||
========================================================
|
||||
[..]
|
||||
This section provides functions allowing to configure the MPU.
|
||||
The Cortex-M33 includes a memory protection unit (MPU) that can restrict the read and write accesses to
|
||||
memory regions (including regions mapped to peripherals).
|
||||
In Armv8-M architecture, memory types are divided into:
|
||||
(#) normal memory
|
||||
(#) device memory
|
||||
|
||||
A normal memory has the following attributes:
|
||||
(#) cacheability: memories cacheable or non-cacheable
|
||||
(#) shareability: normal memory shareable or non-shareable
|
||||
(#) execute never: memories marked as executable or execute never (XN)
|
||||
|
||||
A device memory has the following attributes:
|
||||
(#) G or nG: gathering or non-gathering. (multiple accesses to a device can be merged into a single
|
||||
transaction except for operations with memory ordering semantics, for example, memory barrier
|
||||
instructions, load acquire/store release).
|
||||
(#) R or nR: reordering
|
||||
(#) E or nE: early write acknowledge (similar to bufferable)
|
||||
|
||||
Only four combinations of these attributes are valid:
|
||||
(#) device-nGnRnE: equivalent to Armv7-M strongly ordered memory type
|
||||
(#) device-nGnRE: equivalent to Armv7-M device memory
|
||||
(#) device-nGRE: new to Armv8-M
|
||||
(#) device-GRE: new to Armv8-M
|
||||
|
||||
A normal memory has the following attributes:
|
||||
(#) Cache Allocation attribute : set when a cache line is allocated (no allocation, read/write/read-write allocation)
|
||||
(#) Cache write policy : write through (write to cache AND memory), write back (memory is written when the cache line is evicted)
|
||||
(#) Transient : indicates that the region will be used for a short period of time
|
||||
For normal memory, attributes can be set for inner and outer caches separately.
|
||||
Note that outer attributes set to 0 change the memory to device mode. Both inner and outer attributes should be set for normal memory.
|
||||
|
||||
Sample configurations
|
||||
(#) Inner-outer cacheable, write back, read-write allocate INNER_OUTER(MPU_RW_ALLOCATE | MPU_WRITE_BACK)
|
||||
(#) Inner write back, read allocation, outer non-cacheable (MPU_R_ALLOCATE | MPU_WRITE_BACK) | OUTER(MPU_NOT_CACHEABLE)
|
||||
For detail on memory attributes, refer to the ARMv8-m MPU documentation.
|
||||
|
||||
On STM32U3xx, the MPUs are split memory into regions (up to eight for the non-secure MPU,
|
||||
and up to twelve for the secure MPU).
|
||||
The secure MPU is only available when TrustZone is activated.
|
||||
|
||||
(#) Enable the MPU using HAL_MPU_Enable() function or HAL_MPU_Enable_NS function for non-secure MPU.
|
||||
(#) Disable the MPU using HAL_MPU_Disable() function or HAL_MPU_Disable_NS function for non-secure MPU.
|
||||
(#) Enable the MPU region using HAL_MPU_EnableRegion() function or HAL_MPU_EnableRegion_NS function for non-secure MPU region.
|
||||
(#) Disable the MPU region using HAL_MPU_DisableRegion() function or HAL_MPU_DisableRegion_NS function for non-secure MPU region.
|
||||
(#) Configure the MPU region using HAL_MPU_ConfigRegion() function or HAL_MPU_ConfigRegion_NS function
|
||||
for non-secure MPU.
|
||||
(#) Configure the MPU memory attributes using HAL_MPU_ConfigMemoryAttributes() function or
|
||||
HAL_MPU_ConfigMemoryAttributes_NS function for non-secure MPU.
|
||||
|
||||
(#) The HAL_MPU_XXX_NS functions are only available when TrustZone is activated and CPU in secure state.
|
||||
_NS functions are targeting non secure MPU, in any other cases APIs without NS shall be used.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
|
||||
The table below gives the allowed values of the pre-emption priority and subpriority according
|
||||
to the Priority Grouping configuration performed by HAL_NVIC_SetPriorityGrouping() function.
|
||||
|
||||
=================================================================================================================
|
||||
NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPrio | NVIC_IRQChannelSubPrio | Description
|
||||
=================================================================================================================
|
||||
NVIC_PRIORITYGROUP_0 | 0 | 0-15 | 0 bit for pre-emption priority
|
||||
| | | 4 bits for subpriority
|
||||
-----------------------------------------------------------------------------------------------------------------
|
||||
NVIC_PRIORITYGROUP_1 | 0-1 | 0-7 | 1 bit for pre-emption priority
|
||||
| | | 3 bits for subpriority
|
||||
-----------------------------------------------------------------------------------------------------------------
|
||||
NVIC_PRIORITYGROUP_2 | 0-3 | 0-3 | 2 bits for pre-emption priority
|
||||
| | | 2 bits for subpriority
|
||||
-----------------------------------------------------------------------------------------------------------------
|
||||
NVIC_PRIORITYGROUP_3 | 0-7 | 0-1 | 3 bits for pre-emption priority
|
||||
| | | 1 bit for subpriority
|
||||
-----------------------------------------------------------------------------------------------------------------
|
||||
NVIC_PRIORITYGROUP_4 | 0-15 | 0 | 4 bits for pre-emption priority
|
||||
| | | 0 bit for subpriority
|
||||
=================================================================================================================
|
||||
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32u3xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32U3xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CORTEX
|
||||
* @brief CORTEX HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/** @defgroup CORTEX_Private_Functions CORTEX Private Functions
|
||||
* @{
|
||||
*/
|
||||
static void MPU_ConfigRegion(MPU_Type *MPUx, const MPU_Region_InitTypeDef *pMPU_RegionInit);
|
||||
static void MPU_ConfigMemoryAttributes(MPU_Type *MPUx, const MPU_Attributes_InitTypeDef *pMPU_AttributesInit);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup CORTEX_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup CORTEX_Exported_Functions_Group1
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Initialization and Configuration functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides the CORTEX HAL driver functions allowing to configure Interrupts
|
||||
SysTick functionalities
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the priority grouping field (pre-emption priority and subpriority)
|
||||
* using the required unlock sequence.
|
||||
* @param PriorityGroup The priority grouping bits length.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg NVIC_PRIORITYGROUP_0 0 bit for pre-emption priority,
|
||||
* 4 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_1 1 bit for pre-emption priority,
|
||||
* 3 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_2 2 bits for pre-emption priority,
|
||||
* 2 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_3 3 bits for pre-emption priority,
|
||||
* 1 bit for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_4 4 bits for pre-emption priority,
|
||||
* 0 bit for subpriority
|
||||
* @note When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
|
||||
* The pending IRQ priority will be managed only by the subpriority.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
||||
|
||||
/* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
|
||||
NVIC_SetPriorityGrouping(PriorityGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the priority of an interrupt.
|
||||
* @param IRQn External interrupt number.
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @param PreemptPriority The pre-emption priority for the IRQn channel.
|
||||
* This parameter can be a value between 0 and 15
|
||||
* A lower priority value indicates a higher priority
|
||||
* @param SubPriority the subpriority level for the IRQ channel.
|
||||
* This parameter can be a value between 0 and 15
|
||||
* A lower priority value indicates a higher priority.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
|
||||
{
|
||||
uint32_t prioritygroup;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_PRIO_INTERRUPT(IRQn));
|
||||
prioritygroup = NVIC_GetPriorityGrouping();
|
||||
assert_param(IS_NVIC_SUB_PRIORITY(SubPriority, prioritygroup));
|
||||
assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority, prioritygroup));
|
||||
|
||||
NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable a device specific interrupt in the NVIC interrupt controller.
|
||||
* @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
|
||||
* function should be called before.
|
||||
* @param IRQn External interrupt number.
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
/* Enable interrupt */
|
||||
NVIC_EnableIRQ(IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable a device specific interrupt in the NVIC interrupt controller.
|
||||
* @param IRQn External interrupt number.
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
/* Disable interrupt */
|
||||
NVIC_DisableIRQ(IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initiate a system reset request to reset the MCU.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SystemReset(void)
|
||||
{
|
||||
/* System Reset */
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the System Timer with interrupt enabled and start the System Tick Timer (SysTick):
|
||||
* Counter is in free running mode to generate periodic interrupts.
|
||||
* @param TicksNumb Specifies the ticks Number of ticks between two interrupts.
|
||||
* @retval status: - 0 Function succeeded.
|
||||
* - 1 Function failed.
|
||||
*/
|
||||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
|
||||
{
|
||||
if ((TicksNumb - 1UL) > SysTick_LOAD_RELOAD_Msk)
|
||||
{
|
||||
/* Reload value impossible */
|
||||
return (1UL);
|
||||
}
|
||||
|
||||
/* Set reload register */
|
||||
WRITE_REG(SysTick->LOAD, (uint32_t)(TicksNumb - 1UL));
|
||||
|
||||
/* Load the SysTick Counter Value */
|
||||
WRITE_REG(SysTick->VAL, 0UL);
|
||||
|
||||
/* Enable SysTick IRQ and SysTick Timer */
|
||||
SET_BIT(SysTick->CTRL, (SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk));
|
||||
|
||||
/* Function successful */
|
||||
return (0UL);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup CORTEX_Exported_Functions_Group2
|
||||
* @brief Cortex control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the CORTEX
|
||||
(NVIC, SYSTICK, MPU) functionalities.
|
||||
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the priority grouping field from the NVIC Interrupt Controller.
|
||||
* @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
|
||||
*/
|
||||
uint32_t HAL_NVIC_GetPriorityGrouping(void)
|
||||
{
|
||||
/* Get the PRIGROUP[10:8] field value */
|
||||
return NVIC_GetPriorityGrouping();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the priority of an interrupt.
|
||||
* @param IRQn External interrupt number.
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @param PriorityGroup the priority grouping bits length.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg NVIC_PRIORITYGROUP_0 0 bit for pre-emption priority,
|
||||
* 4 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_1 1 bit for pre-emption priority,
|
||||
* 3 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_2 2 bits for pre-emption priority,
|
||||
* 2 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_3 3 bits for pre-emption priority,
|
||||
* 1 bit for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_4 4 bits for pre-emption priority,
|
||||
* 0 bit for subpriority
|
||||
* @param pPreemptPriority Pointer on the Preemptive priority value (starting from 0).
|
||||
* @param pSubPriority Pointer on the Subpriority value (starting from 0).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_PRIO_INTERRUPT(IRQn));
|
||||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
||||
|
||||
/* Get priority for Cortex-M system or device specific interrupts */
|
||||
NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Pending bit of an external interrupt.
|
||||
* @param IRQn External interrupt number
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
/* Set interrupt pending */
|
||||
NVIC_SetPendingIRQ(IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Pending Interrupt (read the pending register in the NVIC
|
||||
* and return the pending bit for the specified interrupt).
|
||||
* @param IRQn External interrupt number.
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @retval status: - 0 Interrupt status is not pending.
|
||||
* - 1 Interrupt status is pending.
|
||||
*/
|
||||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
/* Return 1 if pending else 0 */
|
||||
return NVIC_GetPendingIRQ(IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear the pending bit of an external interrupt.
|
||||
* @param IRQn External interrupt number.
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
/* Clear pending interrupt */
|
||||
NVIC_ClearPendingIRQ(IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get active interrupt (read the active register in NVIC and return the active bit).
|
||||
* @param IRQn External interrupt number
|
||||
* This parameter can be an enumerator of IRQn_Type enumeration
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer
|
||||
* to the appropriate CMSIS device file (stm32u3xxxx.h))
|
||||
* @retval status: - 0 Interrupt status is not pending.
|
||||
* - 1 Interrupt status is pending.
|
||||
*/
|
||||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
|
||||
{
|
||||
/* Return 1 if active else 0 */
|
||||
return NVIC_GetActive(IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the SysTick clock source.
|
||||
* @param CLKSource specifies the SysTick clock source.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SYSTICK_CLKSOURCE_LSI LSI clock selected as SysTick clock source.
|
||||
* @arg SYSTICK_CLKSOURCE_LSE LSE clock selected as SysTick clock source.
|
||||
* @arg SYSTICK_CLKSOURCE_HCLK AHB clock selected as SysTick clock source.
|
||||
* @arg SYSTICK_CLKSOURCE_HCLK_DIV8 AHB clock divided by 8 selected as SysTick clock source.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
|
||||
switch (CLKSource)
|
||||
{
|
||||
/* Select HCLK as Systick clock source */
|
||||
case SYSTICK_CLKSOURCE_HCLK:
|
||||
SET_BIT(SysTick->CTRL, SysTick_CTRL_CLKSOURCE_Msk);
|
||||
break;
|
||||
/* Select HCLK_DIV8 as Systick clock source */
|
||||
case SYSTICK_CLKSOURCE_HCLK_DIV8:
|
||||
CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_CLKSOURCE_Msk);
|
||||
MODIFY_REG(RCC->CCIPR1, RCC_CCIPR1_SYSTICKSEL, (0x00000000U));
|
||||
break;
|
||||
/* Select LSI as Systick clock source */
|
||||
case SYSTICK_CLKSOURCE_LSI:
|
||||
CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_CLKSOURCE_Msk);
|
||||
MODIFY_REG(RCC->CCIPR1, RCC_CCIPR1_SYSTICKSEL, RCC_CCIPR1_SYSTICKSEL_0);
|
||||
break;
|
||||
/* Select LSE as Systick clock source */
|
||||
case SYSTICK_CLKSOURCE_LSE:
|
||||
CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_CLKSOURCE_Msk);
|
||||
MODIFY_REG(RCC->CCIPR1, RCC_CCIPR1_SYSTICKSEL, RCC_CCIPR1_SYSTICKSEL_1);
|
||||
break;
|
||||
default:
|
||||
/* Nothing to do */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the SysTick clock source configuration.
|
||||
* @retval SysTick clock source that can be one of the following values:
|
||||
* @arg SYSTICK_CLKSOURCE_LSI: LSI clock selected as SysTick clock source.
|
||||
* @arg SYSTICK_CLKSOURCE_LSE: LSE clock selected as SysTick clock source.
|
||||
* @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
|
||||
* @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
|
||||
*/
|
||||
uint32_t HAL_SYSTICK_GetCLKSourceConfig(void)
|
||||
{
|
||||
uint32_t systick_source;
|
||||
|
||||
/* Read SysTick->CTRL register for internal or external clock source */
|
||||
if (READ_BIT(SysTick->CTRL, SysTick_CTRL_CLKSOURCE_Msk) != 0U)
|
||||
{
|
||||
/* Internal clock source */
|
||||
systick_source = SYSTICK_CLKSOURCE_HCLK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* External clock source, check the selected one in RCC */
|
||||
switch (__HAL_RCC_GET_SYSTICK_SOURCE())
|
||||
{
|
||||
case RCC_SYSTICKCLKSOURCE_LSI:
|
||||
systick_source = SYSTICK_CLKSOURCE_LSI;
|
||||
break;
|
||||
|
||||
case RCC_SYSTICKCLKSOURCE_LSE:
|
||||
systick_source = SYSTICK_CLKSOURCE_LSE;
|
||||
break;
|
||||
|
||||
default: /* RCC_SYSTICKCLKSOURCE_HCLK_DIV8 */
|
||||
systick_source = SYSTICK_CLKSOURCE_HCLK_DIV8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return systick_source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle SYSTICK interrupt request.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSTICK_IRQHandler(void)
|
||||
{
|
||||
HAL_SYSTICK_Callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SYSTICK callback.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SYSTICK_Callback(void)
|
||||
{
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_SYSTICK_Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear pending event(s).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_CORTEX_ClearEvent(void)
|
||||
{
|
||||
__SEV();
|
||||
__WFE();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the MPU.
|
||||
* @param MPU_Control Specifies the control mode of the MPU during hard fault,
|
||||
* NMI, FAULTMASK and privileged access to the default memory
|
||||
* This parameter can be one of the following values:
|
||||
* @arg MPU_HFNMI_PRIVDEF_NONE
|
||||
* @arg MPU_HARDFAULT_NMI
|
||||
* @arg MPU_PRIVILEGED_DEFAULT
|
||||
* @arg MPU_HFNMI_PRIVDEF
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Enable(uint32_t MPU_Control)
|
||||
{
|
||||
/* Force any outstanding transfers to complete before enabling MPU */
|
||||
__DMB();
|
||||
|
||||
/* Enable the MPU */
|
||||
MPU->CTRL = (MPU_Control | MPU_CTRL_ENABLE_Msk);
|
||||
|
||||
/* Enable fault exceptions */
|
||||
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
|
||||
/* Ensure MPU setting take effects */
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/**
|
||||
* @brief Enable the non-secure MPU.
|
||||
* @param MPU_Control: Specifies the control mode of the MPU during hard fault,
|
||||
* NMI, FAULTMASK and privileged access to the default memory
|
||||
* This parameter can be one of the following values:
|
||||
* @arg MPU_HFNMI_PRIVDEF_NONE
|
||||
* @arg MPU_HARDFAULT_NMI
|
||||
* @arg MPU_PRIVILEGED_DEFAULT
|
||||
* @arg MPU_HFNMI_PRIVDEF
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Enable_NS(uint32_t MPU_Control)
|
||||
{
|
||||
__DMB(); /* Data Memory Barrier operation to force any outstanding writes to memory before enabling the MPU */
|
||||
|
||||
/* Enable the MPU */
|
||||
MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||
|
||||
/* Enable fault exceptions */
|
||||
SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
|
||||
/* Follow ARM recommendation with */
|
||||
/* Data Synchronization and Instruction Synchronization Barriers to ensure MPU configuration */
|
||||
__DSB(); /* Ensure that the subsequent instruction is executed only after the write to memory */
|
||||
__ISB(); /* Flush and refill pipeline with updated MPU configuration settings */
|
||||
}
|
||||
#endif /* defined (CPU_IN_SECURE_STATE) */
|
||||
|
||||
/**
|
||||
* @brief Disable the MPU.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Disable(void)
|
||||
{
|
||||
/* Force any outstanding transfers to complete before disabling MPU */
|
||||
__DMB();
|
||||
|
||||
/* Disable fault exceptions */
|
||||
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
|
||||
/* Disable the MPU */
|
||||
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
|
||||
|
||||
/* Ensure MPU setting take effects */
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/**
|
||||
* @brief Disable the non-secure MPU.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Disable_NS(void)
|
||||
{
|
||||
/* Force any outstanding transfers to complete before disabling MPU */
|
||||
__DMB();
|
||||
|
||||
/* Disable fault exceptions */
|
||||
SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
|
||||
/* Disable the MPU */
|
||||
MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk;
|
||||
|
||||
/* Ensure MPU setting take effects */
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
#endif /* defined (CPU_IN_SECURE_STATE) */
|
||||
|
||||
/**
|
||||
* @brief Enable the MPU Region.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_EnableRegion(uint32_t RegionNumber)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU->RNR = RegionNumber;
|
||||
|
||||
/* Enable the Region */
|
||||
SET_BIT(MPU->RLAR, MPU_RLAR_EN_Msk);
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/**
|
||||
* @brief Enable the non-secure MPU Region.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_EnableRegion_NS(uint32_t RegionNumber)
|
||||
{
|
||||
assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU_NS->RNR = RegionNumber;
|
||||
|
||||
/* Enable the Region */
|
||||
SET_BIT(MPU_NS->RLAR, MPU_RLAR_EN_Msk);
|
||||
}
|
||||
#endif /* defined (CPU_IN_SECURE_STATE) */
|
||||
|
||||
/**
|
||||
* @brief Disable the MPU Region.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_DisableRegion(uint32_t RegionNumber)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU->RNR = RegionNumber;
|
||||
|
||||
/* Disable the Region */
|
||||
CLEAR_BIT(MPU->RLAR, MPU_RLAR_EN_Msk);
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/**
|
||||
* @brief Disable the non-secure MPU Region.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_DisableRegion_NS(uint32_t RegionNumber)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU_NS->RNR = RegionNumber;
|
||||
|
||||
/* Disable the Region */
|
||||
CLEAR_BIT(MPU_NS->RLAR, MPU_RLAR_EN_Msk);
|
||||
}
|
||||
#endif /* defined (CPU_IN_SECURE_STATE) */
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize and configure the Region and the memory to be protected.
|
||||
* @param pMPU_RegionInit Pointer to a MPU_Region_InitTypeDef structure that contains
|
||||
* the initialization and configuration information.
|
||||
* @retval None
|
||||
* @note STM32U3xx supports 12 secure and 8 non secure MPU regions.
|
||||
*/
|
||||
void HAL_MPU_ConfigRegion(const MPU_Region_InitTypeDef *pMPU_RegionInit)
|
||||
{
|
||||
MPU_ConfigRegion(MPU, pMPU_RegionInit);
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/**
|
||||
* @brief Initialize and configure the Region and the memory to be protected for non-secure MPU.
|
||||
* @param pMPU_RegionInit Pointer to a MPU_Region_InitTypeDef structure that contains
|
||||
* the initialization and configuration information.
|
||||
* @note STM32U3xx supports 8 non secure MPU regions.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_ConfigRegion_NS(const MPU_Region_InitTypeDef *pMPU_RegionInit)
|
||||
{
|
||||
MPU_ConfigRegion(MPU_NS, pMPU_RegionInit);
|
||||
}
|
||||
#endif /* defined (CPU_IN_SECURE_STATE) */
|
||||
|
||||
/**
|
||||
* @brief Initialize and configure the memory attributes.
|
||||
* @param pMPU_AttributesInit Pointer to a MPU_Attributes_InitTypeDef structure that contains
|
||||
* the initialization and configuration information.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_ConfigMemoryAttributes(const MPU_Attributes_InitTypeDef *pMPU_AttributesInit)
|
||||
{
|
||||
MPU_ConfigMemoryAttributes(MPU, pMPU_AttributesInit);
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/**
|
||||
* @brief Initialize and configure the memory attributes for non-secure MPU.
|
||||
* @param pMPU_AttributesInit Pointer to a MPU_Attributes_InitTypeDef structure that contains
|
||||
* the initialization and configuration information.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_ConfigMemoryAttributes_NS(const MPU_Attributes_InitTypeDef *pMPU_AttributesInit)
|
||||
{
|
||||
MPU_ConfigMemoryAttributes(MPU_NS, pMPU_AttributesInit);
|
||||
}
|
||||
#endif /* defined (CPU_IN_SECURE_STATE) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup CORTEX_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
static void MPU_ConfigRegion(MPU_Type *MPUx, const MPU_Region_InitTypeDef *pMPU_RegionInit)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(pMPU_RegionInit->Number));
|
||||
assert_param(IS_MPU_REGION_ENABLE(pMPU_RegionInit->Enable));
|
||||
|
||||
/* Set the Region number */
|
||||
MPUx->RNR = pMPU_RegionInit->Number;
|
||||
|
||||
/* Disable the Region */
|
||||
CLEAR_BIT(MPUx->RLAR, MPU_RLAR_EN_Msk);
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_INSTRUCTION_ACCESS(pMPU_RegionInit->DisableExec));
|
||||
assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(pMPU_RegionInit->AccessPermission));
|
||||
assert_param(IS_MPU_ACCESS_SHAREABLE(pMPU_RegionInit->IsShareable));
|
||||
assert_param(IS_MPU_ATTRIBUTES_NUMBER(pMPU_RegionInit->AttributesIndex));
|
||||
|
||||
MPUx->RBAR = (((uint32_t)pMPU_RegionInit->BaseAddress & 0xFFFFFFE0UL) |
|
||||
((uint32_t)pMPU_RegionInit->IsShareable << MPU_RBAR_SH_Pos) |
|
||||
((uint32_t)pMPU_RegionInit->AccessPermission << MPU_RBAR_AP_Pos) |
|
||||
((uint32_t)pMPU_RegionInit->DisableExec << MPU_RBAR_XN_Pos));
|
||||
|
||||
MPUx->RLAR = (((uint32_t)pMPU_RegionInit->LimitAddress & 0xFFFFFFE0UL) |
|
||||
((uint32_t)pMPU_RegionInit->AttributesIndex << MPU_RLAR_AttrIndx_Pos) |
|
||||
((uint32_t)pMPU_RegionInit->Enable << MPU_RLAR_EN_Pos));
|
||||
}
|
||||
|
||||
static void MPU_ConfigMemoryAttributes(MPU_Type *MPUx, const MPU_Attributes_InitTypeDef *pMPU_AttributesInit)
|
||||
{
|
||||
__IO uint32_t *p_mair;
|
||||
uint32_t attr_values;
|
||||
uint32_t attr_number;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_ATTRIBUTES_NUMBER(pMPU_AttributesInit->Number));
|
||||
/* No need to check Attributes value as all 0x0..0xFF possible */
|
||||
|
||||
if (pMPU_AttributesInit->Number < MPU_ATTRIBUTES_NUMBER4)
|
||||
{
|
||||
/* Program MPU_MAIR0 */
|
||||
p_mair = &(MPUx->MAIR0);
|
||||
attr_number = pMPU_AttributesInit->Number;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Program MPU_MAIR1 */
|
||||
p_mair = &(MPUx->MAIR1);
|
||||
attr_number = (uint32_t)pMPU_AttributesInit->Number - 4U;
|
||||
}
|
||||
|
||||
attr_values = *(p_mair);
|
||||
attr_values &= ~(0xFFU << (attr_number * 8U));
|
||||
*(p_mair) = attr_values | ((uint32_t)pMPU_AttributesInit->Attributes << (attr_number * 8U));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,854 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32u3xx_hal_exti.c
|
||||
* @author MCD Application Team
|
||||
* @brief EXTI HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the General Purpose Input/Output (EXTI) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + IO operation functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### EXTI Peripheral features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) Each Exti line can be configured within this driver.
|
||||
|
||||
(+) Exti line can be configured in 3 different modes
|
||||
(++) Interrupt
|
||||
(++) Event
|
||||
(++) Both of them
|
||||
|
||||
(+) Configurable Exti lines can be configured with 3 different triggers
|
||||
(++) Rising
|
||||
(++) Falling
|
||||
(++) Both of them
|
||||
|
||||
(+) When set in interrupt mode, configurable Exti lines have two diffenrents
|
||||
interrupt pending registers which allow to distinguish which transition
|
||||
occurs:
|
||||
(++) Rising edge pending interrupt
|
||||
(++) Falling
|
||||
|
||||
(+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can
|
||||
be selected through multiplexer.
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
|
||||
(#) Configure the EXTI line using HAL_EXTI_SetConfigLine().
|
||||
(++) Choose the interrupt line number by setting "Line" member from
|
||||
EXTI_ConfigTypeDef structure.
|
||||
(++) Configure the interrupt and/or event mode using "Mode" member from
|
||||
EXTI_ConfigTypeDef structure.
|
||||
(++) For configurable lines, configure rising and/or falling trigger
|
||||
"Trigger" member from EXTI_ConfigTypeDef structure.
|
||||
(++) For Exti lines linked to gpio, choose gpio port using "GPIOSel"
|
||||
member from GPIO_InitTypeDef structure.
|
||||
|
||||
(#) Get current Exti configuration of a dedicated line using
|
||||
HAL_EXTI_GetConfigLine().
|
||||
(++) Provide exiting handle as parameter.
|
||||
(++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter.
|
||||
|
||||
(#) Clear Exti configuration of a dedicated line using HAL_EXTI_GetConfigLine().
|
||||
(++) Provide exiting handle as parameter.
|
||||
|
||||
(#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback().
|
||||
(++) Provide exiting handle as first parameter.
|
||||
(++) Provide which callback will be registered using one value from
|
||||
EXTI_CallbackIDTypeDef.
|
||||
(++) Provide callback function pointer.
|
||||
|
||||
(#) Get interrupt pending bit using HAL_EXTI_GetPending().
|
||||
|
||||
(#) Clear interrupt pending bit using HAL_EXTI_GetPending().
|
||||
|
||||
(#) Generate software interrupt using HAL_EXTI_GenerateSWI().
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32u3xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32U3xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines ------------------------------------------------------------*/
|
||||
/** @defgroup EXTI_Private_Constants EXTI Private Constants
|
||||
* @{
|
||||
*/
|
||||
#define EXTI_MODE_OFFSET 0x04U /* byte offset between IMR/EMR registers */
|
||||
#define EXTI_CONFIG_OFFSET 0x08U /* byte offset between Rising/Falling configuration registers */
|
||||
#define EXTI_PRIVCFGR_OFFSET 0x04U /* byte offset between PRIVCFGR1/PRIVCFGR2 registers */
|
||||
#define EXTI_SECCFGR_OFFSET 0x04U /* byte offset between SECCFGR1/SECCFGR2 registers */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup EXTI_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI_Exported_Functions_Group1
|
||||
* @brief Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Configuration functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set configuration of a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @param pExtiConfig Pointer on EXTI configuration to be set.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check null pointer */
|
||||
if ((hexti == NULL) || (pExtiConfig == NULL))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(pExtiConfig->Line));
|
||||
assert_param(IS_EXTI_MODE(pExtiConfig->Mode));
|
||||
|
||||
/* Assign line number to handle */
|
||||
hexti->Line = pExtiConfig->Line;
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* Configure triggers for configurable lines */
|
||||
if ((pExtiConfig->Line & EXTI_CONFIG) != 0U)
|
||||
{
|
||||
assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
|
||||
|
||||
/* Configure rising trigger */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store rising trigger mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* Configure falling trigger */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store falling trigger mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* Configure gpio port selection in case of gpio exti line */
|
||||
if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
|
||||
{
|
||||
assert_param(IS_EXTI_GPIO_PORT(pExtiConfig->GPIOSel));
|
||||
assert_param(IS_EXTI_GPIO_PIN(linepos));
|
||||
|
||||
regval = EXTI->EXTICR[(linepos >> 2U) & 0x03UL];
|
||||
regval &= ~(EXTI_EXTICR1_EXTI0 << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
|
||||
regval |= (pExtiConfig->GPIOSel << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
|
||||
EXTI->EXTICR[(linepos >> 2U) & 0x03UL] = regval;
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure interrupt mode : read current mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store interrupt mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* Configure event mode : read current mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store event mode */
|
||||
*regaddr = regval;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get configuration of a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @param pExtiConfig Pointer on structure to store Exti configuration.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_GetConfigLine(const EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
|
||||
{
|
||||
const __IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check null pointer */
|
||||
if ((hexti == NULL) || (pExtiConfig == NULL))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
|
||||
/* Store handle line number to configiguration structure */
|
||||
pExtiConfig->Line = hexti->Line;
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* 1] Get core mode : interrupt */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0U)
|
||||
{
|
||||
pExtiConfig->Mode = EXTI_MODE_INTERRUPT;
|
||||
}
|
||||
else
|
||||
{
|
||||
pExtiConfig->Mode = EXTI_MODE_NONE;
|
||||
}
|
||||
|
||||
/* Get event mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0U)
|
||||
{
|
||||
pExtiConfig->Mode |= EXTI_MODE_EVENT;
|
||||
}
|
||||
|
||||
/* 2] Get trigger for configurable lines : rising */
|
||||
if ((pExtiConfig->Line & EXTI_CONFIG) != 0U)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if configuration of selected line is enable */
|
||||
if ((regval & maskline) != 0U)
|
||||
{
|
||||
pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
|
||||
}
|
||||
else
|
||||
{
|
||||
pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
|
||||
}
|
||||
|
||||
/* Get falling configuration */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if configuration of selected line is enable */
|
||||
if ((regval & maskline) != 0U)
|
||||
{
|
||||
pExtiConfig->Trigger |= EXTI_TRIGGER_FALLING;
|
||||
}
|
||||
|
||||
/* Get Gpio port selection for gpio lines */
|
||||
if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
|
||||
{
|
||||
assert_param(IS_EXTI_GPIO_PIN(linepos));
|
||||
|
||||
regval = EXTI->EXTICR[(linepos >> 2U) & 0x03UL];
|
||||
pExtiConfig->GPIOSel = (regval >> (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03U))) & EXTI_EXTICR1_EXTI0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pExtiConfig->GPIOSel = 0U;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
|
||||
pExtiConfig->GPIOSel = 0U;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear whole configuration of a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(const EXTI_HandleTypeDef *hexti)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check null pointer */
|
||||
if (hexti == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (hexti->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* 1] Clear interrupt mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* 2] Clear event mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* 3] Clear triggers in case of configurable lines */
|
||||
if ((hexti->Line & EXTI_CONFIG) != 0U)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* Get Gpio port selection for gpio lines */
|
||||
if ((hexti->Line & EXTI_GPIO) == EXTI_GPIO)
|
||||
{
|
||||
assert_param(IS_EXTI_GPIO_PIN(linepos));
|
||||
|
||||
regval = EXTI->EXTICR[(linepos >> 2U) & 0x03UL];
|
||||
regval &= ~(EXTI_EXTICR1_EXTI0 << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
|
||||
EXTI->EXTICR[(linepos >> 2U) & 0x03UL] = regval;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Register callback for a dedicaated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @param CallbackID User callback identifier.
|
||||
* This parameter can be one of @arg @ref EXTI_CallbackIDTypeDef values.
|
||||
* @param pPendingCbfn function pointer to be stored as callback.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti,
|
||||
EXTI_CallbackIDTypeDef CallbackID,
|
||||
void (*pPendingCbfn)(void))
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_EXTI_COMMON_CB_ID:
|
||||
hexti->RisingCallback = pPendingCbfn;
|
||||
hexti->FallingCallback = pPendingCbfn;
|
||||
break;
|
||||
|
||||
case HAL_EXTI_RISING_CB_ID:
|
||||
hexti->RisingCallback = pPendingCbfn;
|
||||
break;
|
||||
|
||||
case HAL_EXTI_FALLING_CB_ID:
|
||||
hexti->FallingCallback = pPendingCbfn;
|
||||
break;
|
||||
|
||||
default:
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Store line number as handle private field.
|
||||
* @param hexti Exti handle.
|
||||
* @param ExtiLine Exti line number.
|
||||
* This parameter can be from 0 to @ref EXTI_LINE_NB.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(ExtiLine));
|
||||
|
||||
/* Check null pointer */
|
||||
if (hexti == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Store line number as handle private field */
|
||||
hexti->Line = ExtiLine;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI_Exported_Functions_Group2
|
||||
* @brief EXTI IO functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Handle EXTI interrupt request.
|
||||
* @param hexti Exti handle.
|
||||
* @retval none.
|
||||
*/
|
||||
void HAL_EXTI_IRQHandler(const EXTI_HandleTypeDef *hexti)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
|
||||
|
||||
/* Get rising edge pending bit */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & maskline);
|
||||
|
||||
if (regval != 0U)
|
||||
{
|
||||
/* Clear pending bit */
|
||||
*regaddr = maskline;
|
||||
|
||||
/* Call rising callback */
|
||||
if (hexti->RisingCallback != NULL)
|
||||
{
|
||||
hexti->RisingCallback();
|
||||
}
|
||||
}
|
||||
|
||||
/* Get falling edge pending bit */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & maskline);
|
||||
|
||||
if (regval != 0U)
|
||||
{
|
||||
/* Clear pending bit */
|
||||
*regaddr = maskline;
|
||||
|
||||
/* Call rising callback */
|
||||
if (hexti->FallingCallback != NULL)
|
||||
{
|
||||
hexti->FallingCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get interrupt pending bit of a dedicated line.
|
||||
* @param hexti Exti handle.
|
||||
* @param Edge Specify which pending edge as to be checked.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref EXTI_TRIGGER_RISING
|
||||
* @arg @ref EXTI_TRIGGER_FALLING
|
||||
* @retval 1 if interrupt is pending else 0.
|
||||
*/
|
||||
uint32_t HAL_EXTI_GetPending(const EXTI_HandleTypeDef *hexti, uint32_t Edge)
|
||||
{
|
||||
const __IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_PENDING_EDGE(Edge));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (hexti->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
if (Edge != EXTI_TRIGGER_RISING)
|
||||
{
|
||||
/* Get falling edge pending bit */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get rising edge pending bit */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
}
|
||||
|
||||
/* return 1 if bit is set else 0 */
|
||||
regval = ((*regaddr & maskline) >> linepos);
|
||||
return regval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear interrupt pending bit of a dedicated line.
|
||||
* @param hexti Exti handle.
|
||||
* @param Edge Specify which pending edge as to be clear.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref EXTI_TRIGGER_RISING
|
||||
* @arg @ref EXTI_TRIGGER_FALLING
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_EXTI_ClearPending(const EXTI_HandleTypeDef *hexti, uint32_t Edge)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_PENDING_EDGE(Edge));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
|
||||
|
||||
if (Edge != EXTI_TRIGGER_RISING)
|
||||
{
|
||||
/* Get falling edge pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get falling edge pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
}
|
||||
|
||||
/* Clear Pending bit */
|
||||
*regaddr = maskline;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generate a software interrupt for a dedicated line.
|
||||
* @param hexti Exti handle.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_EXTI_GenerateSWI(const EXTI_HandleTypeDef *hexti)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
|
||||
|
||||
regaddr = (__IO uint32_t *)(&EXTI->SWIER1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
*regaddr = maskline;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup EXTI_Exported_Functions_Group3 EXTI line attributes management functions
|
||||
* @brief EXTI attributes management functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### EXTI attributes functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure the EXTI line attribute(s).
|
||||
* @note Available attributes are to secure EXTI line and set EXT line as privileged.
|
||||
* Default state is not secure and unprivileged access allowed.
|
||||
* @note Secure and non-secure attributes can only be set from the secure
|
||||
* state when the system implements the security (TZEN=1).
|
||||
* @note Security and privilege attributes can be set independently.
|
||||
* @param ExtiLine Exti line number.
|
||||
* This parameter can be from 0 to @ref EXTI_LINE_NB.
|
||||
* @param LineAttributes can be one or a combination of the following values:
|
||||
* @arg @ref EXTI_LINE_PRIV Privileged-only access
|
||||
* @arg @ref EXTI_LINE_NPRIV Privileged/Non-privileged access
|
||||
* @arg @ref EXTI_LINE_SEC Secure-only access
|
||||
* @arg @ref EXTI_LINE_NSEC Secure/Non-secure access
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EXTI_ConfigLineAttributes(uint32_t ExtiLine, uint32_t LineAttributes)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(ExtiLine));
|
||||
assert_param(IS_EXTI_LINE_ATTRIBUTES(LineAttributes));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((ExtiLine & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (ExtiLine & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* Configure privilege or non-privilege attributes */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PRIVCFGR1 + (EXTI_PRIVCFGR_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((LineAttributes & EXTI_LINE_PRIV) == EXTI_LINE_PRIV)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else if ((LineAttributes & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
/* Store privilege or non-privilege attribute */
|
||||
*regaddr = regval;
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/* Configure secure or non-secure attributes */
|
||||
regaddr = (uint32_t *)(&EXTI->SECCFGR1 + (EXTI_SECCFGR_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((LineAttributes & EXTI_LINE_SEC) == EXTI_LINE_SEC)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else if ((LineAttributes & EXTI_LINE_NSEC) == EXTI_LINE_NSEC)
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
/* Store secure or non-secure attribute */
|
||||
*regaddr = regval;
|
||||
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the EXTI line attribute(s).
|
||||
* @note Secure and non-secure attributes are only available from secure state
|
||||
* when the system implements the security (TZEN=1)
|
||||
* @param ExtiLine Exti line number.
|
||||
* This parameter can be from 0 to @ref EXTI_LINE_NB.
|
||||
* @param pLineAttributes: pointer to return line attributes.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_GetConfigLineAttributes(uint32_t ExtiLine, uint32_t *pLineAttributes)
|
||||
{
|
||||
const __IO uint32_t *regaddr;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
uint32_t attributes;
|
||||
|
||||
/* Check null pointer */
|
||||
if (pLineAttributes == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(ExtiLine));
|
||||
|
||||
/* Compute line register offset and line mask */
|
||||
offset = ((ExtiLine & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (ExtiLine & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* Get privilege or non-privilege attribute */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PRIVCFGR1 + (EXTI_PRIVCFGR_OFFSET * offset));
|
||||
|
||||
if ((*regaddr & maskline) != 0U)
|
||||
{
|
||||
attributes = EXTI_LINE_PRIV;
|
||||
}
|
||||
else
|
||||
{
|
||||
attributes = EXTI_LINE_NPRIV;
|
||||
}
|
||||
|
||||
/* Get secure or non-secure attribute */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->SECCFGR1 + (EXTI_SECCFGR_OFFSET * offset));
|
||||
|
||||
if ((*regaddr & maskline) != 0U)
|
||||
{
|
||||
attributes |= EXTI_LINE_SEC;
|
||||
}
|
||||
else
|
||||
{
|
||||
attributes |= EXTI_LINE_NSEC;
|
||||
}
|
||||
|
||||
/* return value */
|
||||
*pLineAttributes = attributes;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
/**
|
||||
* @brief Lock the secure and privilege configuration registers.
|
||||
* @note Once security and privilege configuration locked, it can no longer be modified
|
||||
* until next system reset
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EXTI_LockAttributes(void)
|
||||
{
|
||||
SET_BIT(EXTI->LOCKR, EXTI_LOCKR_LOCK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the secure and privilege configuration registers LOCK status
|
||||
* @retval 1 if the secure and privilege configuration registers have been locked else 0.
|
||||
*/
|
||||
uint32_t HAL_EXTI_GetLockAttributes(void)
|
||||
{
|
||||
return READ_BIT(EXTI->LOCKR, EXTI_LOCKR_LOCK);
|
||||
}
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,806 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32u3xx_hal_flash.c
|
||||
* @author MCD Application Team
|
||||
* @brief FLASH HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the internal FLASH memory:
|
||||
* + Program operations functions
|
||||
* + Memory Control functions
|
||||
* + Peripheral Errors functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Flash peripheral features #####
|
||||
==============================================================================
|
||||
|
||||
[..] The Flash memory interface manages CPU AHB C-Bus accesses to the Flash memory.
|
||||
It implements the erase and program Flash memory operations and the read
|
||||
and write protection mechanisms.
|
||||
|
||||
[..] The Flash memory interface implements the TrustZone security features (TZ) supported
|
||||
by ARM Cortex-M33 core (CM33).
|
||||
|
||||
[..] The FLASH main features are:
|
||||
(+) Flash memory read operations
|
||||
(+) Flash memory program/erase operations
|
||||
(+) Read / write protections
|
||||
(+) Option bytes programming
|
||||
(+) TrustZone aware
|
||||
(+) Watermark-based area protection including the secure hide area
|
||||
(+) Block-based page protection
|
||||
(+) Error code correction (ECC) : Data in flash are 72-bits word
|
||||
(8 bits added per double-word)
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This driver provides functions and macros to configure and program the FLASH
|
||||
memory of all STM32U3xx devices.
|
||||
|
||||
(#) Flash Memory IO Programming functions:
|
||||
(++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
|
||||
HAL_FLASH_Lock() functions
|
||||
(++) Program functions: double-words and burst program (16 double-words)
|
||||
(++) There are two modes of programming:
|
||||
(+++) Polling mode using HAL_FLASH_Program() function
|
||||
(+++) Interrupt mode using HAL_FLASH_Program_IT() function
|
||||
|
||||
(#) Interrupts and flags management functions:
|
||||
(++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
|
||||
(++) Callback functions are called when the flash operations are finished :
|
||||
HAL_FLASH_EndOfOperationCallback() when everything is ok, otherwise
|
||||
HAL_FLASH_OperationErrorCallback()
|
||||
(++) Get error flag status by calling HAL_GetError()
|
||||
|
||||
(#) Option bytes management functions :
|
||||
(++) Lock and Unlock the option bytes using HAL_FLASH_OB_Unlock() and
|
||||
HAL_FLASH_OB_Lock() functions
|
||||
(++) Launch the reload of the option bytes using HAL_FLASH_OB_Launch() function.
|
||||
In this case, a reset is generated
|
||||
|
||||
[..]
|
||||
In addition to these functions, this driver includes a set of macros allowing
|
||||
to handle the following operations:
|
||||
(+) Set the latency
|
||||
(+) Enable/Disable the Flash power-down during low-power run and sleep modes
|
||||
(+) Enable/Disable the Flash interrupts
|
||||
(+) Monitor the Flash flags status
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32u3xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32U3xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH FLASH
|
||||
* @brief FLASH HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/** @addtogroup FLASH_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
#define FLASH_NB_WORDS_IN_BURST 32
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/** @defgroup FLASH_Private_Variables FLASH Private Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Variable used for Program/Erase sectors under interruption
|
||||
*/
|
||||
FLASH_ProcessTypeDef pFlash = {.Lock = HAL_UNLOCKED, \
|
||||
.ErrorCode = HAL_FLASH_ERROR_NONE, \
|
||||
.ProcedureOnGoing = 0U, \
|
||||
.Address = 0U, \
|
||||
.Page = 0U, \
|
||||
.NbPagesToErase = 0U
|
||||
};
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup FLASH_Private_Functions FLASH Private Functions
|
||||
* @{
|
||||
*/
|
||||
static void FLASH_Program_DoubleWord(uint32_t Address, uint32_t DataAddress);
|
||||
static void FLASH_Program_Burst(uint32_t Address, uint32_t DataAddress);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup FLASH_Exported_Functions FLASH Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
|
||||
* @brief Programming operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Programming operation functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to manage the FLASH
|
||||
program operations.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Program a double-word or a burst of 16 double-words at a specified address.
|
||||
*
|
||||
* @param TypeProgram Indicate the way to program at a specified address
|
||||
* This parameter can be a value of @ref FLASH_Type_Program
|
||||
* @param Address Specifies the address to be programmed.
|
||||
* This parameter shall be aligned to the Flash word (64 bits)
|
||||
* @param DataAddress Specifies the address of data to be programmed.
|
||||
* This parameter shall be 32-bit aligned
|
||||
*
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t DataAddress)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
__IO uint32_t *reg_cr;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(&pFlash);
|
||||
|
||||
/* Reset error code */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
/* Verify that next operation can be proceed */
|
||||
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Set current operation type */
|
||||
pFlash.ProcedureOnGoing = TypeProgram;
|
||||
|
||||
/* Access to SCR or CR depends on operation type */
|
||||
reg_cr = (IS_FLASH_SECURE_OPERATION() != 0U) ? &(FLASH->SCR) : &(FLASH_NS->CR);
|
||||
|
||||
if ((TypeProgram & (~FLASH_NON_SECURE_MASK)) == FLASH_TYPEPROGRAM_DOUBLEWORD)
|
||||
{
|
||||
/* Program a double-word (64-bit) at a specified address */
|
||||
FLASH_Program_DoubleWord(Address, DataAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Program a burst of 16 double-words at a specified address */
|
||||
FLASH_Program_Burst(Address, DataAddress);
|
||||
}
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||
|
||||
/* If the program operation is completed, disable the PG (and BWR Bit in Burst programming mode) */
|
||||
CLEAR_BIT((*reg_cr), (TypeProgram & ~(FLASH_NON_SECURE_MASK)));
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
|
||||
/* return status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Program a double-word or a burst of 16 double-words at a specified address with interrupt enabled.
|
||||
*
|
||||
* @param TypeProgram Indicate the way to program at a specified address.
|
||||
* This parameter can be a value of @ref FLASH_Type_Program
|
||||
* @param Address Specifies the address to be programmed.
|
||||
* This parameter shall be aligned to the Flash word (64 bits)
|
||||
* @param DataAddress Specifies the address of data to be programmed.
|
||||
* This parameter shall be 32-bit aligned
|
||||
*
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t DataAddress)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
__IO uint32_t *reg_cr;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
|
||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(&pFlash);
|
||||
|
||||
/* Reset error code */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
/* Verify that next operation can be proceed */
|
||||
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set internal variables used by the IRQ handler */
|
||||
pFlash.ProcedureOnGoing = TypeProgram;
|
||||
pFlash.Address = Address;
|
||||
|
||||
/* Access to SCR or CR depends on operation type */
|
||||
reg_cr = (IS_FLASH_SECURE_OPERATION() != 0U) ? &(FLASH->SCR) : &(FLASH_NS->CR);
|
||||
|
||||
/* Enable End of Operation and Error interrupts */
|
||||
(*reg_cr) |= (FLASH_IT_EOP | FLASH_IT_OPERR);
|
||||
|
||||
if ((TypeProgram & (~FLASH_NON_SECURE_MASK)) == FLASH_TYPEPROGRAM_DOUBLEWORD)
|
||||
{
|
||||
/* Program a double-word (64-bit) at a specified address */
|
||||
FLASH_Program_DoubleWord(Address, DataAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Program a burst of 16 double-words at a specified address */
|
||||
FLASH_Program_Burst(Address, DataAddress);
|
||||
}
|
||||
}
|
||||
|
||||
/* return status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle FLASH interrupt request.
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_FLASH_IRQHandler(void)
|
||||
{
|
||||
uint32_t param = 0U;
|
||||
uint32_t error;
|
||||
__IO uint32_t *reg_cr;
|
||||
__IO uint32_t *reg_sr;
|
||||
uint32_t type;
|
||||
|
||||
type = (pFlash.ProcedureOnGoing & ~(FLASH_NON_SECURE_MASK));
|
||||
/* Access to CR and SR registers depends on operation type */
|
||||
reg_cr = (IS_FLASH_SECURE_OPERATION() != 0U) ? &(FLASH->SCR) : &(FLASH_NS->CR);
|
||||
reg_sr = (IS_FLASH_SECURE_OPERATION() != 0U) ? &(FLASH->SSR) : &(FLASH_NS->SR);
|
||||
|
||||
/* Save Flash errors */
|
||||
error = (*reg_sr) & FLASH_FLAG_SR_ERRORS;
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
error |= (FLASH->SR & FLASH_FLAG_OPTWERR);
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
/* Set parameter of the callback */
|
||||
if (type == FLASH_TYPEERASE_PAGES)
|
||||
{
|
||||
param = pFlash.Page;
|
||||
}
|
||||
else if (type == FLASH_TYPEERASE_MASSERASE)
|
||||
{
|
||||
param = pFlash.Bank;
|
||||
}
|
||||
else if (type == FLASH_TYPEPROGRAM_DOUBLEWORD)
|
||||
{
|
||||
param = pFlash.Address;
|
||||
}
|
||||
else if (type == FLASH_TYPEPROGRAM_BURST)
|
||||
{
|
||||
param = pFlash.Address;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Empty statement (to be compliant MISRA 15.7) */
|
||||
}
|
||||
|
||||
/* Clear operation bit on the on-going procedure */
|
||||
CLEAR_BIT((*reg_cr), (type | FLASH_CR_BKER | FLASH_CR_PNB));
|
||||
|
||||
/* Check FLASH operation error flags */
|
||||
if (error != 0U)
|
||||
{
|
||||
/* Save the error code */
|
||||
pFlash.ErrorCode |= error;
|
||||
|
||||
/* Clear error programming flags */
|
||||
(*reg_sr) = error;
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
if ((error & FLASH_FLAG_OPTWERR) != 0U)
|
||||
{
|
||||
FLASH->SR = FLASH_FLAG_OPTWERR;
|
||||
}
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
/* Stop the procedure ongoing */
|
||||
pFlash.ProcedureOnGoing = 0U;
|
||||
|
||||
/* FLASH error interrupt user callback */
|
||||
HAL_FLASH_OperationErrorCallback(param);
|
||||
}
|
||||
|
||||
/* Check FLASH End of Operation flag */
|
||||
if (((*reg_sr) & FLASH_FLAG_EOP) != 0U)
|
||||
{
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
(*reg_sr) = FLASH_FLAG_EOP;
|
||||
|
||||
if (type == FLASH_TYPEERASE_PAGES)
|
||||
{
|
||||
/* Nb of pages to erase can be decreased */
|
||||
pFlash.NbPagesToErase--;
|
||||
|
||||
/* Check if there are still pages to erase */
|
||||
if (pFlash.NbPagesToErase != 0U)
|
||||
{
|
||||
/* Increment page number */
|
||||
pFlash.Page++;
|
||||
FLASH_PageErase(pFlash.Page, pFlash.Bank);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No more pages to Erase */
|
||||
pFlash.ProcedureOnGoing = 0U;
|
||||
param = 0xFFFFFFFFU;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*Clear the procedure ongoing*/
|
||||
pFlash.ProcedureOnGoing = 0U;
|
||||
}
|
||||
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(param);
|
||||
}
|
||||
|
||||
if (pFlash.ProcedureOnGoing == 0U)
|
||||
{
|
||||
/* Disable End of Operation and Error interrupts */
|
||||
(*reg_cr) &= ~(FLASH_IT_EOP | FLASH_IT_OPERR);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
}
|
||||
|
||||
/* Check ECC Correction Error */
|
||||
if ((FLASH->ECCCR & (FLASH_IT_ECCC | FLASH_FLAG_ECCC)) == (FLASH_IT_ECCC | FLASH_FLAG_ECCC))
|
||||
{
|
||||
/* Call User callback */
|
||||
HAL_FLASHEx_EccCorrectionCallback();
|
||||
|
||||
/* Clear ECC correction flag in order to allow new ECC error record */
|
||||
SET_BIT(FLASH->ECCCR, FLASH_ECCCR_ECCC);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FLASH end of operation interrupt callback.
|
||||
*
|
||||
* @param ReturnValue The value saved in this parameter depends on the ongoing procedure :
|
||||
* @arg Mass Erase: 0
|
||||
* @arg Page Erase: Page which has been erased
|
||||
* (if 0xFFFFFFFF, it means that all the selected pages have been erased)
|
||||
* @arg Program: Address which was selected for data program
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(ReturnValue);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FLASH operation error interrupt callback.
|
||||
*
|
||||
* @param ReturnValue The value saved in this parameter depends on the ongoing procedure :
|
||||
* @arg Mass Erase: 0
|
||||
* @arg Page Erase: Page number which returned an error
|
||||
* @arg Program: Address which was selected for data program
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(ReturnValue);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_FLASH_OperationErrorCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
|
||||
* @brief Management functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the FLASH
|
||||
memory operations.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Unlock the FLASH control register access.
|
||||
*
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U)
|
||||
{
|
||||
/* Authorize the FLASH Registers access */
|
||||
WRITE_REG(FLASH->KEYR, FLASH_KEY1);
|
||||
WRITE_REG(FLASH->KEYR, FLASH_KEY2);
|
||||
|
||||
/* verify Flash is unlocked */
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
if (READ_BIT(FLASH->SCR, FLASH_SCR_LOCK) != 0U)
|
||||
{
|
||||
/* Authorize the FLASH Registers access */
|
||||
WRITE_REG(FLASH->SKEYR, FLASH_KEY1);
|
||||
WRITE_REG(FLASH->SKEYR, FLASH_KEY2);
|
||||
|
||||
/* verify Flash is unlocked */
|
||||
if (READ_BIT(FLASH->SCR, FLASH_SCR_LOCK) != 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock the FLASH control register access.
|
||||
*
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Lock(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
|
||||
/* Set the LOCK Bit to lock the FLASH Registers access */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_LOCK);
|
||||
|
||||
/* verify Flash is locked */
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U)
|
||||
{
|
||||
status = HAL_OK;
|
||||
}
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
SET_BIT(FLASH->SCR, FLASH_SCR_LOCK);
|
||||
|
||||
/* verify Flash is locked */
|
||||
if (READ_BIT(FLASH->SCR, FLASH_SCR_LOCK) != 0U)
|
||||
{
|
||||
status = HAL_OK;
|
||||
}
|
||||
}
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlock the FLASH Option Bytes Registers access.
|
||||
*
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
|
||||
{
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) != 0U)
|
||||
{
|
||||
/* Authorizes the Option Byte register programming */
|
||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
|
||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
|
||||
|
||||
/* Verify that the Option Bytes are unlocked */
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) != 0U)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock the FLASH Option Bytes Registers access.
|
||||
*
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
|
||||
{
|
||||
/* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_OPTLOCK);
|
||||
|
||||
/* Verify that the Option Bytes are locked */
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) != 0U)
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Launch the option byte loading.
|
||||
*
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
|
||||
{
|
||||
/* Set the bit to force the option byte reloading */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);
|
||||
|
||||
/* We should not reach here : Option byte launch generates Option byte reset
|
||||
so return error */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions
|
||||
* @brief Peripheral Errors functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Errors functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection permits to get in run-time Errors of the FLASH peripheral.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the specific FLASH error flag.
|
||||
*
|
||||
* @retval FLASH_ErrorCode The returned value can be
|
||||
* @arg @ref HAL_FLASH_ERROR_NONE No error set
|
||||
* @arg @ref HAL_FLASH_ERROR_OP FLASH Operation error
|
||||
* @arg @ref HAL_FLASH_ERROR_PROG FLASH Programming error
|
||||
* @arg @ref HAL_FLASH_ERROR_WRP FLASH Write protection error
|
||||
* @arg @ref HAL_FLASH_ERROR_PGA FLASH Programming alignment error
|
||||
* @arg @ref HAL_FLASH_ERROR_SIZ FLASH Size error
|
||||
* @arg @ref HAL_FLASH_ERROR_PGS FLASH Programming sequence error
|
||||
* @arg @ref HAL_FLASH_ERROR_OPTW FLASH Option modification error
|
||||
*/
|
||||
uint32_t HAL_FLASH_GetError(void)
|
||||
{
|
||||
return pFlash.ErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup FLASH_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Wait for a FLASH operation to complete.
|
||||
* @param Timeout Maximum flash operation timeout
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
|
||||
{
|
||||
/* Wait for the FLASH operation to complete by polling on BUSY and WDW flags to be reset.
|
||||
Even if the FLASH operation fails, the BUSY & WDW flags will be reset, and an error flag will be set */
|
||||
|
||||
uint32_t timeout = HAL_GetTick();
|
||||
uint32_t error;
|
||||
__IO uint32_t *reg_sr;
|
||||
|
||||
/* Access to SECSR or NSSR registers depends on operation type */
|
||||
reg_sr = (IS_FLASH_SECURE_OPERATION() != 0U) ? &(FLASH->SSR) : &(FLASH_NS->SR);
|
||||
|
||||
while (((*reg_sr) & (FLASH_FLAG_BSY | FLASH_FLAG_WDW)) != 0U)
|
||||
{
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if ((HAL_GetTick() - timeout) >= Timeout)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check FLASH operation error flags */
|
||||
error = ((*reg_sr) & FLASH_FLAG_SR_ERRORS);
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
error |= (FLASH->SR & FLASH_FLAG_OPTWERR);
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
if (error != 0U)
|
||||
{
|
||||
/*Save the error code*/
|
||||
pFlash.ErrorCode |= error;
|
||||
|
||||
/* Clear error programming flags */
|
||||
(*reg_sr) = error;
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
if ((error & FLASH_FLAG_OPTWERR) != 0U)
|
||||
{
|
||||
FLASH->SR = FLASH_FLAG_OPTWERR;
|
||||
}
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check FLASH End of Operation flag */
|
||||
if (((*reg_sr) & FLASH_FLAG_EOP) != 0U)
|
||||
{
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
(*reg_sr) = FLASH_FLAG_EOP;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Program a double-word (64-bit) at a specified address.
|
||||
* @param Address Specifies the address to be programmed.
|
||||
* @param DataAddress Specifies the address of data to be programmed.
|
||||
* @retval None
|
||||
*/
|
||||
static void FLASH_Program_DoubleWord(uint32_t Address, uint32_t DataAddress)
|
||||
{
|
||||
uint8_t index = 2;
|
||||
uint32_t *dest_addr = (uint32_t *)Address;
|
||||
uint32_t *src_addr = (uint32_t *)DataAddress;
|
||||
uint32_t primask_bit;
|
||||
__IO uint32_t *reg_cr;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
|
||||
|
||||
/* Access to SCR or CR registers depends on operation type */
|
||||
reg_cr = (IS_FLASH_SECURE_OPERATION() != 0U) ? &(FLASH->SCR) : &(FLASH_NS->CR);
|
||||
|
||||
/* Set PG bit */
|
||||
SET_BIT((*reg_cr), FLASH_CR_PG);
|
||||
|
||||
/* Enter critical section: Disable interrupts to avoid any interruption during the loop */
|
||||
primask_bit = __get_PRIMASK();
|
||||
__disable_irq();
|
||||
|
||||
/* Program the double-word */
|
||||
do
|
||||
{
|
||||
*dest_addr = *src_addr;
|
||||
dest_addr++;
|
||||
src_addr++;
|
||||
index--;
|
||||
} while (index != 0U);
|
||||
|
||||
/* Exit critical section: restore previous priority mask */
|
||||
__set_PRIMASK(primask_bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Program a burst of 16x double-words at a specified address.
|
||||
* @param Address Specifies the address to be programmed.
|
||||
* @param DataAddress Specifies the address where the data are stored.
|
||||
* @retval None
|
||||
*/
|
||||
static void FLASH_Program_Burst(uint32_t Address, uint32_t DataAddress)
|
||||
{
|
||||
uint8_t burst_index = FLASH_NB_WORDS_IN_BURST;
|
||||
uint32_t *dest_addr = (uint32_t *)Address;
|
||||
uint32_t *src_addr = (uint32_t *)DataAddress;
|
||||
uint32_t primask_bit;
|
||||
__IO uint32_t *reg_cr;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_MAIN_MEM_ADDRESS(Address));
|
||||
|
||||
/* Access to SCR or CR registers depends on operation type */
|
||||
reg_cr = (IS_FLASH_SECURE_OPERATION() != 0U) ? &(FLASH->SCR) : &(FLASH_NS->CR);
|
||||
|
||||
/* Set PG and BWR bits */
|
||||
SET_BIT((*reg_cr), (FLASH_CR_PG | FLASH_CR_BWR));
|
||||
|
||||
/* Enter critical section: Disable interrupts to avoid any interruption during the loop */
|
||||
primask_bit = __get_PRIMASK();
|
||||
__disable_irq();
|
||||
|
||||
/* Program the burst */
|
||||
do
|
||||
{
|
||||
*dest_addr = *src_addr;
|
||||
dest_addr++;
|
||||
src_addr++;
|
||||
burst_index--;
|
||||
} while (burst_index != 0U);
|
||||
|
||||
/* Exit critical section: restore previous priority mask */
|
||||
__set_PRIMASK(primask_bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,708 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32u3xx_hal_gpio.c
|
||||
* @author GPM Application Team
|
||||
* @brief GPIO HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the General Purpose Input/Output (GPIO) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + IO operation functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### GPIO Peripheral features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) Each port bit of the general-purpose I/O (GPIO) ports can be individually
|
||||
configured by software in several modes:
|
||||
(++) Input mode
|
||||
(++) Analog mode
|
||||
(++) Output mode
|
||||
(++) Alternate function mode
|
||||
(++) External interrupt/event lines
|
||||
|
||||
(+) During and just after reset, the alternate functions and external interrupt
|
||||
lines are not active and the I/O ports are configured in analog mode.
|
||||
|
||||
(+) All GPIO pins have weak internal pull-up and pull-down resistors, which can be
|
||||
activated or not.
|
||||
|
||||
(+) In Output or Alternate mode, each IO can be configured on open-drain or push-pull
|
||||
type and the IO speed can be selected depending on the VDD value.
|
||||
|
||||
(+) The microcontroller IO pins are connected to onboard peripherals/modules through a
|
||||
multiplexer that allows only one peripheral alternate function (AF) connected
|
||||
to an IO pin at a time. In this way, there can be no conflict between peripherals
|
||||
sharing the same IO pin.
|
||||
|
||||
(+) All ports have external interrupt/event capability. To use external interrupt
|
||||
lines, the port must be configured in input mode. All available GPIO pins are
|
||||
connected to the 16 external interrupt/event lines from EXTI0 to EXTI15.
|
||||
|
||||
(+) The external interrupt/event controller consists of up to 23 edge detectors
|
||||
(16 lines are connected to GPIO) for generating event/interrupt requests (each
|
||||
input line can be independently configured to select the type (interrupt or event)
|
||||
and the corresponding trigger event (rising or falling or both). Each line can
|
||||
also be masked independently.
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) Enable the GPIO AHB clock using the following function: __HAL_RCC_GPIOx_CLK_ENABLE().
|
||||
|
||||
(#) Configure the GPIO pin(s) using HAL_GPIO_Init().
|
||||
(++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
|
||||
(++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef
|
||||
structure.
|
||||
(++) In case of Output or alternate function mode selection: the speed is
|
||||
configured through "Speed" member from GPIO_InitTypeDef structure.
|
||||
(++) In alternate mode is selection, the alternate function connected to the IO
|
||||
is configured through "Alternate" member from GPIO_InitTypeDef structure.
|
||||
(++) Analog mode is required when a pin is to be used as ADC channel
|
||||
or DAC output.
|
||||
(++) In case of external interrupt/event selection the "Mode" member from
|
||||
GPIO_InitTypeDef structure select the type (interrupt or event) and
|
||||
the corresponding trigger event (rising or falling or both).
|
||||
|
||||
(#) In case of external interrupt/event mode selection, configure NVIC IRQ priority
|
||||
mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
|
||||
HAL_NVIC_EnableIRQ().
|
||||
|
||||
(#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
|
||||
|
||||
(#) To set/reset the level of a pin configured in output mode use
|
||||
HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
|
||||
|
||||
(#) To set the level of several pins and reset level of several other pins in
|
||||
same cycle, use HAL_GPIO_WriteMultipleStatePin().
|
||||
|
||||
(#) To lock pin configuration until next reset use HAL_GPIO_LockPin().
|
||||
|
||||
(#) During and just after reset, the alternate functions are not
|
||||
active and the GPIO pins are configured in analog mode (except JTAG
|
||||
pins).
|
||||
|
||||
(#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
|
||||
(PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
|
||||
priority over the GPIO function.
|
||||
|
||||
(#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
|
||||
general purpose PH0 and PH1, respectively, when the HSE oscillator is off.
|
||||
The HSE has priority over the GPIO function.
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32u3xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32U3xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup GPIO
|
||||
* @{
|
||||
*/
|
||||
/** MISRA C:2012 deviation rule has been granted for following rules:
|
||||
* Rule-12.2 - Medium: RHS argument is in interval [0,INF] which is out of
|
||||
* range of the shift operator in following API :
|
||||
* HAL_GPIO_Init
|
||||
* HAL_GPIO_DeInit
|
||||
*/
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines ------------------------------------------------------------*/
|
||||
/** @addtogroup GPIO_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
#define GPIO_NUMBER (16U)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup GPIO_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup GPIO_Exported_Functions_Group1
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
|
||||
* @note If GPIOx peripheral pin is used in EXTI_MODE and the pin is secure/privilege, it is up
|
||||
* to the application to insure that the corresponding EXTI line is set secure/privilege.
|
||||
* insure that the corresponding EXTI line is set secure.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Init pointer to a GPIO_InitTypeDef structure that contains
|
||||
* the configuration information for the specified GPIO peripheral.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, const GPIO_InitTypeDef *GPIO_Init)
|
||||
{
|
||||
uint32_t position = 0x00U;
|
||||
uint32_t iocurrent;
|
||||
uint32_t temp;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
|
||||
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
|
||||
|
||||
/* Configure the port pins */
|
||||
while (((GPIO_Init->Pin) >> position) != 0x00U)
|
||||
{
|
||||
/* Get current io position */
|
||||
iocurrent = (GPIO_Init->Pin) & (1UL << position);
|
||||
|
||||
if (iocurrent != 0x00U)
|
||||
{
|
||||
/*--------------------- GPIO Mode Configuration ------------------------*/
|
||||
/* In case of Output or Alternate function mode selection */
|
||||
if (((GPIO_Init->Mode & GPIO_MODE) == MODE_OUTPUT) || ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF))
|
||||
{
|
||||
/* Check the Speed parameter */
|
||||
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
|
||||
|
||||
/* Configure the IO Speed */
|
||||
temp = GPIOx->OSPEEDR;
|
||||
temp &= ~(GPIO_OSPEEDR_OSPEED0 << (position * GPIO_OSPEEDR_OSPEED1_Pos));
|
||||
temp |= (GPIO_Init->Speed << (position * GPIO_OSPEEDR_OSPEED1_Pos));
|
||||
GPIOx->OSPEEDR = temp;
|
||||
|
||||
/* Configure the IO Output Type */
|
||||
temp = GPIOx->OTYPER;
|
||||
temp &= ~(GPIO_OTYPER_OT0 << position) ;
|
||||
temp |= (((GPIO_Init->Mode & OUTPUT_TYPE) >> OUTPUT_TYPE_Pos) << position);
|
||||
GPIOx->OTYPER = temp;
|
||||
}
|
||||
|
||||
if (((GPIO_Init->Mode & GPIO_MODE) != MODE_ANALOG) ||
|
||||
(((GPIO_Init->Mode & GPIO_MODE) == MODE_ANALOG) && (GPIO_Init->Pull != GPIO_PULLUP)))
|
||||
{
|
||||
/* Check the Pull parameter */
|
||||
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
|
||||
|
||||
/* Activate the Pull-up or Pull down resistor for the current IO */
|
||||
temp = GPIOx->PUPDR;
|
||||
temp &= ~(GPIO_PUPDR_PUPD0 << (position * GPIO_PUPDR_PUPD1_Pos));
|
||||
temp |= ((GPIO_Init->Pull) << (position * GPIO_PUPDR_PUPD1_Pos));
|
||||
GPIOx->PUPDR = temp;
|
||||
}
|
||||
|
||||
/* In case of Alternate function mode selection */
|
||||
if ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF)
|
||||
{
|
||||
/* Check the Alternate function parameters */
|
||||
assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
|
||||
|
||||
/* Configure Alternate function mapped with the current IO */
|
||||
temp = GPIOx->AFR[position >> 3U];
|
||||
temp &= ~(0xFu << ((position & 0x07U) * GPIO_AFRL_AFSEL1_Pos));
|
||||
temp |= ((GPIO_Init->Alternate) << ((position & 0x07U) * GPIO_AFRL_AFSEL1_Pos));
|
||||
GPIOx->AFR[position >> 3U] = temp;
|
||||
}
|
||||
|
||||
/* Configure IO Direction mode (Input, Output, Alternate or Analog) */
|
||||
temp = GPIOx->MODER;
|
||||
temp &= ~(GPIO_MODER_MODE0 << (position * GPIO_MODER_MODE1_Pos));
|
||||
temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * GPIO_MODER_MODE1_Pos));
|
||||
GPIOx->MODER = temp;
|
||||
|
||||
/*--------------------- EXTI Mode Configuration ------------------------*/
|
||||
/* Configure the External Interrupt or event for the current IO */
|
||||
if ((GPIO_Init->Mode & EXTI_MODE) != 0x00U)
|
||||
{
|
||||
temp = EXTI->EXTICR[position >> 2U];
|
||||
temp &= ~(0x0FuL << ((position & 0x03U) * EXTI_EXTICR1_EXTI1_Pos));
|
||||
temp |= (GPIO_GET_INDEX(GPIOx) << ((position & 0x03U) * EXTI_EXTICR1_EXTI1_Pos));
|
||||
EXTI->EXTICR[position >> 2U] = temp;
|
||||
|
||||
/* Clear EXTI line configuration */
|
||||
temp = EXTI->IMR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & EXTI_IT) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->IMR1 = temp;
|
||||
|
||||
temp = EXTI->EMR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & EXTI_EVT) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->EMR1 = temp;
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
temp = EXTI->RTSR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & TRIGGER_RISING) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->RTSR1 = temp;
|
||||
|
||||
temp = EXTI->FTSR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & TRIGGER_FALLING) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->FTSR1 = temp;
|
||||
}
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-initialize the GPIOx peripheral registers to their default reset values.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin specifies the port bit to be written.
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
||||
{
|
||||
uint32_t position = 0x00U;
|
||||
uint32_t iocurrent;
|
||||
uint32_t tmp;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
/* Configure the port pins */
|
||||
while ((GPIO_Pin >> position) != 0x00U)
|
||||
{
|
||||
/* Get current io position */
|
||||
iocurrent = (GPIO_Pin) & (1UL << position);
|
||||
|
||||
if (iocurrent != 0x00U)
|
||||
{
|
||||
/*------------------------- EXTI Mode Configuration --------------------*/
|
||||
/* Clear the External Interrupt or Event for the current IO */
|
||||
|
||||
tmp = EXTI->EXTICR[position >> 2U];
|
||||
tmp &= (0x0FUL << ((position & 0x03U) * EXTI_EXTICR1_EXTI1_Pos));
|
||||
if (tmp == (GPIO_GET_INDEX(GPIOx) << ((position & 0x03U) * EXTI_EXTICR1_EXTI1_Pos)))
|
||||
{
|
||||
/* Clear EXTI line configuration */
|
||||
EXTI->IMR1 &= ~(iocurrent);
|
||||
EXTI->EMR1 &= ~(iocurrent);
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
EXTI->RTSR1 &= ~(iocurrent);
|
||||
EXTI->FTSR1 &= ~(iocurrent);
|
||||
|
||||
tmp = 0x0FuL << ((position & 0x03U) * EXTI_EXTICR1_EXTI1_Pos);
|
||||
EXTI->EXTICR[position >> 2U] &= ~tmp;
|
||||
}
|
||||
|
||||
/*------------------------- GPIO Mode Configuration --------------------*/
|
||||
/* Configure IO in Analog Mode */
|
||||
GPIOx->MODER |= (GPIO_MODER_MODE0 << (position * GPIO_MODER_MODE1_Pos));
|
||||
|
||||
/* Configure the default Alternate Function in current IO */
|
||||
GPIOx->AFR[position >> 3U] &= ~(0xFu << ((position & 0x07U) * GPIO_AFRL_AFSEL1_Pos)) ;
|
||||
|
||||
/* Configure the default value for IO Speed */
|
||||
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED0 << (position * GPIO_OSPEEDR_OSPEED1_Pos));
|
||||
|
||||
/* Configure the default value IO Output Type */
|
||||
GPIOx->OTYPER &= ~(GPIO_OTYPER_OT0 << position) ;
|
||||
|
||||
/* Deactivate the Pull-up and Pull-down resistor for the current IO */
|
||||
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPD0 << (position * GPIO_PUPDR_PUPD1_Pos));
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup GPIO_Exported_Functions_Group2
|
||||
* @brief GPIO Read, Write, Toggle, Lock and EXTI management functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Read the specified input port pin.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin specifies the port bit to read.
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @retval The input port pin value.
|
||||
*/
|
||||
GPIO_PinState HAL_GPIO_ReadPin(const GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
GPIO_PinState bitstatus;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
if ((GPIOx->IDR & GPIO_Pin) != 0x00U)
|
||||
{
|
||||
bitstatus = GPIO_PIN_SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = GPIO_PIN_RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set or clear the selected data port bit.
|
||||
* @note This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
|
||||
* accesses. In this way, there is no risk of an IRQ occurring between
|
||||
* the read and the modify access.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin specifies the port bit to be written.
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @param PinState specifies the value to be written to the selected bit.
|
||||
* This parameter can be one of the GPIO_PinState enum values:
|
||||
* @arg GPIO_PIN_RESET: to clear the port pin
|
||||
* @arg GPIO_PIN_SET: to set the port pin
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_PIN_ACTION(PinState));
|
||||
|
||||
if (PinState != GPIO_PIN_RESET)
|
||||
{
|
||||
GPIOx->BSRR = (uint32_t)GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BRR = (uint32_t)GPIO_Pin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle the specified GPIO pin.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin specifies the pin to be toggled.
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
uint32_t odr;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
/* get current Output Data Register value */
|
||||
odr = GPIOx->ODR;
|
||||
|
||||
/* Set selected pins that were at low level, and reset ones that were high */
|
||||
GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set and clear several pins of a dedicated port in same cycle.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param PinReset specifies the port bits to be reset
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15) or zero.
|
||||
* @param PinSet specifies the port bits to be set
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15) or zero.
|
||||
* @note Both PinReset and PinSet combinations shall not get any common bit, else
|
||||
* assert would be triggered.
|
||||
* @note At least one of the two parameters used to set or reset shall be different from zero.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_WriteMultipleStatePin(GPIO_TypeDef *GPIOx, uint16_t PinReset, uint16_t PinSet)
|
||||
{
|
||||
uint32_t tmp;
|
||||
|
||||
/* Check the parameters */
|
||||
/* Make sure at least one parameter is different from zero and that there is no common pin */
|
||||
assert_param(IS_GPIO_PIN((uint32_t)PinReset | (uint32_t)PinSet));
|
||||
assert_param(IS_GPIO_COMMON_PIN(PinReset, PinSet));
|
||||
|
||||
tmp = (((uint32_t)PinReset << 16) | PinSet);
|
||||
GPIOx->BSRR = tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock GPIO Pins configuration registers.
|
||||
* @note The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
|
||||
* GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
|
||||
* @note The configuration of the locked GPIO pins can no longer be modified
|
||||
* until the next reset.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin specifies the port bits to be locked.
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @retval HAL_OK if success, HAL_ERROR otherwise
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
__IO uint32_t tmp = GPIO_LCKR_LCKK;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
/* Apply lock key write sequence */
|
||||
tmp |= GPIO_Pin;
|
||||
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
|
||||
GPIOx->LCKR = tmp;
|
||||
/* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
|
||||
GPIOx->LCKR = GPIO_Pin;
|
||||
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
|
||||
GPIOx->LCKR = tmp;
|
||||
/* Read LCKK register. This read is mandatory to complete key lock sequence */
|
||||
tmp = GPIOx->LCKR;
|
||||
|
||||
/* read again in order to confirm lock is active */
|
||||
if ((GPIOx->LCKR & GPIO_LCKR_LCKK) != 0x00U)
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable speed optimization for several pin of dedicated port.
|
||||
* @note It must be used only if the I/O supply voltage is below 2.7 V.
|
||||
* @note Not all I/Os support the HSLV mode. Refer to the I/O structure in the corresponding
|
||||
* datasheet for the list of I/Os supporting this feature. Other I/Os HSLV configuration must
|
||||
* be kept at reset value.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin: specifies the port bit to be optimized.
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_EnableHighSpeedLowVoltage(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
|
||||
/* Set HSLVR gpio pin */
|
||||
GPIOx->HSLVR |= GPIO_Pin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable speed optimization for several pin of dedicated port.
|
||||
* @note Not all I/Os support the HSLV mode. Refer to the I/O structure in the corresponding
|
||||
* datasheet for the list of I/Os supporting this feature. Other I/Os HSLV configuration must
|
||||
* be kept at reset value.
|
||||
* @note It must be used only if the I/O supply voltage is below 2.7 V.
|
||||
* @param GPIOx where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin: specifies the port bit to be unoptimized.
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_DisableHighSpeedLowVoltage(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
|
||||
/* Set HSLVR gpio pin */
|
||||
GPIOx->HSLVR &= ~(GPIO_Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle EXTI interrupt request.
|
||||
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
|
||||
{
|
||||
/* EXTI line interrupt detected */
|
||||
if (__HAL_GPIO_EXTI_GET_RISING_IT(GPIO_Pin) != 0x00U)
|
||||
{
|
||||
__HAL_GPIO_EXTI_CLEAR_RISING_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_Rising_Callback(GPIO_Pin);
|
||||
}
|
||||
|
||||
if (__HAL_GPIO_EXTI_GET_FALLING_IT(GPIO_Pin) != 0x00U)
|
||||
{
|
||||
__HAL_GPIO_EXTI_CLEAR_FALLING_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_Falling_Callback(GPIO_Pin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief EXTI line rising detection callback.
|
||||
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(GPIO_Pin);
|
||||
|
||||
/* NOTE: This function should not be modified, when the callback is needed,
|
||||
the HAL_GPIO_EXTI_Rising_Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief EXTI line falling detection callback.
|
||||
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(GPIO_Pin);
|
||||
|
||||
/* NOTE: This function should not be modified, when the callback is needed,
|
||||
the HAL_GPIO_EXTI_Falling_Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup GPIO_Exported_Functions_Group3 IO attributes management functions
|
||||
* @brief GPIO attributes management functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO attributes functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (CPU_IN_SECURE_STATE)
|
||||
|
||||
/**
|
||||
* @brief Configure the GPIO pins attributes.
|
||||
* @note Available attributes are to secure GPIO pin(s), so this function is
|
||||
* only available in secure
|
||||
* @param GPIOx: where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin: specifies the port bit to be written.
|
||||
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
||||
* @param PinAttributes: specifies the pin(s) to be set in secure mode, other being set non secured.
|
||||
* @note Refer to the product datasheet to know which bits are available for each port.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_ConfigPinAttributes(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t PinAttributes)
|
||||
{
|
||||
uint32_t sec;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_PIN_ATTRIBUTES(PinAttributes));
|
||||
|
||||
/* Configure the port pins */
|
||||
sec = GPIOx->SECCFGR;
|
||||
if (PinAttributes != GPIO_PIN_NSEC)
|
||||
{
|
||||
sec |= (uint32_t)GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
sec &= ~((uint32_t)GPIO_Pin);
|
||||
}
|
||||
|
||||
GPIOx->SECCFGR = sec;
|
||||
}
|
||||
#endif /* CPU_IN_SECURE_STATE */
|
||||
|
||||
/**
|
||||
* @brief Get the GPIO pins attributes.
|
||||
* @param GPIOx: where x can be (A..E, G, H).
|
||||
* @param GPIO_Pin: specifies the port bit to be written.
|
||||
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
||||
* @param pPinAttributes: pointer to return the pin attributes.
|
||||
* @note Refer to the product datasheet to know which bits are available for each port.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GPIO_GetConfigPinAttributes(const GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin,
|
||||
uint32_t *pPinAttributes)
|
||||
{
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_SINGLE_PIN(GPIO_Pin));
|
||||
|
||||
/* Check null pointer */
|
||||
if (pPinAttributes == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((GPIOx->SECCFGR & GPIO_Pin) != 0x00U)
|
||||
{
|
||||
*pPinAttributes = GPIO_PIN_SEC;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pPinAttributes = GPIO_PIN_NSEC;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,502 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32u3xx_hal_i2c_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief I2C Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of I2C Extended peripheral:
|
||||
* + Filter Mode Functions
|
||||
* + WakeUp Mode Functions
|
||||
* + FastModePlus Functions
|
||||
* + Autonomous Mode Functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### I2C peripheral Extended features #####
|
||||
==============================================================================
|
||||
|
||||
[..] Comparing to other previous devices, the I2C interface for STM32U3xx
|
||||
devices contains the following additional features
|
||||
|
||||
(+) Possibility to disable or enable Analog Noise Filter
|
||||
(+) Use of a configured Digital Noise Filter
|
||||
(+) Disable or enable wakeup from Stop mode(s)
|
||||
(+) Disable or enable Fast Mode Plus
|
||||
(+) Configure Autonomous mode
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..] This driver provides functions to configure Noise Filter and Wake Up Feature
|
||||
(#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()
|
||||
(#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()
|
||||
(#) Configure the enable or disable of I2C Wake Up Mode using the functions :
|
||||
(++) HAL_I2CEx_EnableWakeUp()
|
||||
(++) HAL_I2CEx_DisableWakeUp()
|
||||
(#) Configure the enable or disable of fast mode plus driving capability using the functions :
|
||||
(++) HAL_I2CEx_ConfigFastModePlus()
|
||||
(#) Set or get or clear the autonomous mode configuration using these functions :
|
||||
(++) HAL_I2CEx_SetConfigAutonomousMode()
|
||||
(++) HAL_I2CEx_GetConfigAutonomousMode()
|
||||
(++) HAL_I2CEx_ClearConfigAutonomousMode()
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32u3xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32U3xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup I2CEx I2CEx
|
||||
* @brief I2C Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup I2CEx_Exported_Functions_Group1 Filter Mode Functions
|
||||
* @brief Filter Mode Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Filter Mode Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Noise Filters
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure I2C Analog noise filter.
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @param AnalogFilter New state of the Analog filter.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
|
||||
assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Reset I2Cx ANOFF bit */
|
||||
hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
|
||||
|
||||
/* Set analog filter bit*/
|
||||
hi2c->Instance->CR1 |= AnalogFilter;
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure I2C Digital noise filter.
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
|
||||
{
|
||||
uint32_t tmpreg;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
|
||||
assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Get the old register value */
|
||||
tmpreg = hi2c->Instance->CR1;
|
||||
|
||||
/* Reset I2Cx DNF bits [11:8] */
|
||||
tmpreg &= ~(I2C_CR1_DNF);
|
||||
|
||||
/* Set I2Cx DNF coefficient */
|
||||
tmpreg |= DigitalFilter << 8U;
|
||||
|
||||
/* Store the new register value */
|
||||
hi2c->Instance->CR1 = tmpreg;
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup I2CEx_Exported_Functions_Group2 WakeUp Mode Functions
|
||||
* @brief WakeUp Mode Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### WakeUp Mode Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Wake Up Feature
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable I2C wakeup from Stop mode(s).
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Enable wakeup from stop mode */
|
||||
hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable I2C wakeup from Stop mode(s).
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Enable wakeup from stop mode */
|
||||
hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup I2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
|
||||
* @brief Fast Mode Plus Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Fast Mode Plus Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Fast Mode Plus
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure I2C Fast Mode Plus.
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @param FastModePlus New state of the Fast Mode Plus.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_ConfigFastModePlus(I2C_HandleTypeDef *hi2c, uint32_t FastModePlus)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
|
||||
assert_param(IS_I2C_FASTMODEPLUS(FastModePlus));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
if (FastModePlus == I2C_FASTMODEPLUS_ENABLE)
|
||||
{
|
||||
/* Set I2Cx FMP bit */
|
||||
hi2c->Instance->CR1 |= (I2C_CR1_FMP);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Reset I2Cx FMP bit */
|
||||
hi2c->Instance->CR1 &= ~(I2C_CR1_FMP);
|
||||
}
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup I2CEx_Exported_Functions_Group4 Autonomous Mode Functions
|
||||
* @brief Autonomous Mode Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Autonomous Mode functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Autonomous Mode
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set Autonomous Mode configuration
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @param sConfig Pointer to a I2C_AutonomousModeConfTypeDef structure that contains
|
||||
* the configuration information of the autonomous mode for the specified I2Cx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_SetConfigAutonomousMode(I2C_HandleTypeDef *hi2c,
|
||||
const I2C_AutonomousModeConfTypeDef *sConfig)
|
||||
{
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_TRIG_INPUT_INSTANCE(hi2c->Instance));
|
||||
assert_param(IS_I2C_TRIG_SOURCE(hi2c->Instance, sConfig->TriggerSelection));
|
||||
assert_param(IS_I2C_AUTO_MODE_TRG_POL(sConfig->TriggerPolarity));
|
||||
|
||||
/* Disable the selected I2C peripheral to be able to configure AUTOCR */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* I2Cx AUTOCR Configuration */
|
||||
WRITE_REG(hi2c->Instance->AUTOCR,
|
||||
(sConfig->TriggerState | \
|
||||
((sConfig->TriggerSelection) & I2C_AUTOCR_TRIGSEL_Msk) | \
|
||||
sConfig->TriggerPolarity));
|
||||
|
||||
/* Enable the selected I2C peripheral */
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Autonomous Mode configuration
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @param sConfig Pointer to a I2C_AutonomousModeConfTypeDef structure that contains
|
||||
* the configuration information of the autonomous mode for the specified I2Cx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_GetConfigAutonomousMode(const I2C_HandleTypeDef *hi2c,
|
||||
I2C_AutonomousModeConfTypeDef *sConfig)
|
||||
{
|
||||
uint32_t autocr_tmp;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_TRIG_INPUT_INSTANCE(hi2c->Instance));
|
||||
|
||||
autocr_tmp = hi2c->Instance->AUTOCR;
|
||||
|
||||
sConfig->TriggerState = (autocr_tmp & I2C_AUTOCR_TRIGEN);
|
||||
if (IS_I2C_GRP2_INSTANCE(hi2c->Instance))
|
||||
{
|
||||
sConfig->TriggerSelection = ((autocr_tmp & I2C_AUTOCR_TRIGSEL) | I2C_TRIG_GRP2);
|
||||
}
|
||||
else
|
||||
{
|
||||
sConfig->TriggerSelection = ((autocr_tmp & I2C_AUTOCR_TRIGSEL) | I2C_TRIG_GRP1);
|
||||
}
|
||||
sConfig->TriggerPolarity = (autocr_tmp & I2C_AUTOCR_TRIGPOL);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear Autonomous Mode configuration
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_ClearConfigAutonomousMode(I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_TRIG_INPUT_INSTANCE(hi2c->Instance));
|
||||
|
||||
/* Disable the selected I2C peripheral to be able to clear AUTOCR */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
CLEAR_REG(hi2c->Instance->AUTOCR);
|
||||
|
||||
/* Enable the selected I2C peripheral */
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,651 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32u3xx_hal_icache.c
|
||||
* @author MCD Application Team
|
||||
* @brief ICACHE HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Instruction Cache (ICACHE).
|
||||
* + Initialization and Configuration
|
||||
* + Invalidate functions
|
||||
* + Monitoring management
|
||||
* + Memory address remap management
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### ICACHE main features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The Instruction Cache (ICACHE) is introduced on C-AHB code bus of
|
||||
Cortex-M33 processor to improve performance when fetching instruction
|
||||
and data from both internal and external memories. It allows close to
|
||||
zero wait states performance.
|
||||
|
||||
(+) The ICACHE provides two performance counters (Hit and Miss),
|
||||
cache invalidate maintenance operation, error management and TrustZone
|
||||
security support.
|
||||
|
||||
(+) The ICACHE provides additionally the possibility to remap input address
|
||||
falling into up to four memory regions (used to remap aliased code in
|
||||
external memories to the internal Code region, for execution)
|
||||
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
The ICACHE HAL driver can be used as follows:
|
||||
|
||||
(#) Optionally configure the Instruction Cache mode with
|
||||
HAL_ICACHE_ConfigAssociativityMode() if the default configuration
|
||||
does not suit the application requirements.
|
||||
|
||||
(#) Enable and disable the Instruction Cache with respectively
|
||||
HAL_ICACHE_Enable() and HAL_ICACHE_Disable().
|
||||
Use HAL_ICACHE_IsEnabled() to get the Instruction Cache status.
|
||||
To ensure a deterministic cache behavior after power on, system reset or after
|
||||
a call to @ref HAL_ICACHE_Disable(), the application must call
|
||||
@ref HAL_ICACHE_WaitForInvalidateComplete(). Indeed on power on, system reset
|
||||
or cache disable, an automatic cache invalidation procedure is launched and the
|
||||
cache is bypassed until the operation completes.
|
||||
|
||||
(#) Initiate the cache maintenance invalidation procedure with either
|
||||
HAL_ICACHE_Invalidate() (blocking mode) or HAL_ICACHE_Invalidate_IT()
|
||||
(interrupt mode). When interrupt mode is used, the callback function
|
||||
HAL_ICACHE_InvalidateCompleteCallback() is called when the invalidate
|
||||
procedure is complete. The function HAL_ICACHE_WaitForInvalidateComplete()
|
||||
may be called to wait for the end of the invalidate procedure automatically
|
||||
initiated when disabling the Instruction Cache with HAL_ICACHE_Disable().
|
||||
The cache operation is bypassed during the invalidation procedure.
|
||||
|
||||
(#) Use the performance monitoring counters for Hit and Miss with the following
|
||||
functions: HAL_ICACHE_Monitor_Start(), HAL_ICACHE_Monitor_Stop(),
|
||||
HAL_ICACHE_Monitor_Reset(), HAL_ICACHE_Monitor_GetHitValue() and
|
||||
HAL_ICACHE_Monitor_GetMissValue()
|
||||
|
||||
(#) Enable and disable up to four regions to remap input address from external
|
||||
memories to the internal Code region for execution with
|
||||
HAL_ICACHE_EnableRemapRegion() and HAL_ICACHE_DisableRemapRegion()
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32u3xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32U3xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup ICACHE ICACHE
|
||||
* @brief HAL ICACHE module driver
|
||||
* @{
|
||||
*/
|
||||
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED)
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup ICACHE_Private_Constants ICACHE Private Constants
|
||||
* @{
|
||||
*/
|
||||
#define ICACHE_INVALIDATE_TIMEOUT_VALUE 1U /* 1ms */
|
||||
#define ICACHE_DISABLE_TIMEOUT_VALUE 1U /* 1ms */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @defgroup ICACHE_Private_Macros ICACHE Private Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define IS_ICACHE_ASSOCIATIVITY_MODE(__MODE__) (((__MODE__) == ICACHE_1WAY) || \
|
||||
((__MODE__) == ICACHE_2WAYS))
|
||||
|
||||
#define IS_ICACHE_MONITOR_TYPE(__TYPE__) (((__TYPE__) == ICACHE_MONITOR_HIT_MISS) || \
|
||||
((__TYPE__) == ICACHE_MONITOR_HIT) || \
|
||||
((__TYPE__) == ICACHE_MONITOR_MISS))
|
||||
|
||||
#define IS_ICACHE_REGION_NUMBER(__NUMBER__) ((__NUMBER__) < 4U)
|
||||
|
||||
#define IS_ICACHE_REGION_SIZE(__SIZE__) (((__SIZE__) == ICACHE_REGIONSIZE_2MB) || \
|
||||
((__SIZE__) == ICACHE_REGIONSIZE_4MB) || \
|
||||
((__SIZE__) == ICACHE_REGIONSIZE_8MB) || \
|
||||
((__SIZE__) == ICACHE_REGIONSIZE_16MB) || \
|
||||
((__SIZE__) == ICACHE_REGIONSIZE_32MB) || \
|
||||
((__SIZE__) == ICACHE_REGIONSIZE_64MB) || \
|
||||
((__SIZE__) == ICACHE_REGIONSIZE_128MB))
|
||||
|
||||
#define IS_ICACHE_REGION_TRAFFIC_ROUTE(__TRAFFICROUTE__) (((__TRAFFICROUTE__) == ICACHE_MASTER1_PORT) || \
|
||||
((__TRAFFICROUTE__) == ICACHE_MASTER2_PORT))
|
||||
|
||||
#define IS_ICACHE_REGION_OUTPUT_BURST_TYPE(__OUTPUTBURSTTYPE_) (((__OUTPUTBURSTTYPE_) == ICACHE_OUTPUT_BURST_WRAP) || \
|
||||
((__OUTPUTBURSTTYPE_) == ICACHE_OUTPUT_BURST_INCR))
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ICACHE_Exported_Functions ICACHE Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup ICACHE_Exported_Functions_Group1 Initialization and control functions
|
||||
* @brief Initialization and control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Initialization and control functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to initialize and control the
|
||||
Instruction Cache (mode, invalidate procedure, performance counters).
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure the Instruction Cache cache associativity mode selection.
|
||||
* @param AssociativityMode Associativity mode selection
|
||||
* This parameter can be one of the following values:
|
||||
* @arg ICACHE_1WAY 1-way cache (direct mapped cache)
|
||||
* @arg ICACHE_2WAYS 2-ways set associative cache (default)
|
||||
* @retval HAL status (HAL_OK/HAL_ERROR)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_ConfigAssociativityMode(uint32_t AssociativityMode)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ICACHE_ASSOCIATIVITY_MODE(AssociativityMode));
|
||||
|
||||
/* Check cache is not enabled */
|
||||
if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
MODIFY_REG(ICACHE->CR, ICACHE_CR_WAYSEL, AssociativityMode);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the Instruction Cache.
|
||||
* @retval HAL status (HAL_OK)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_DeInit(void)
|
||||
{
|
||||
/* Reset interrupt enable value */
|
||||
WRITE_REG(ICACHE->IER, 0U);
|
||||
|
||||
/* Clear any pending flags */
|
||||
WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF | ICACHE_FCR_CERRF);
|
||||
|
||||
/* Disable cache then set default associative mode value */
|
||||
CLEAR_BIT(ICACHE->CR, ICACHE_CR_EN);
|
||||
WRITE_REG(ICACHE->CR, ICACHE_CR_WAYSEL);
|
||||
|
||||
/* Stop monitor and reset monitor values */
|
||||
CLEAR_BIT(ICACHE->CR, ICACHE_MONITOR_HIT_MISS);
|
||||
SET_BIT(ICACHE->CR, (ICACHE_MONITOR_HIT_MISS << 2U));
|
||||
CLEAR_BIT(ICACHE->CR, (ICACHE_MONITOR_HIT_MISS << 2U));
|
||||
|
||||
/* Reset regions configuration values */
|
||||
WRITE_REG(ICACHE->CRR0, ICACHE_REGIONSIZE_2MB << ICACHE_CRRx_RSIZE_Pos);
|
||||
WRITE_REG(ICACHE->CRR1, ICACHE_REGIONSIZE_2MB << ICACHE_CRRx_RSIZE_Pos);
|
||||
WRITE_REG(ICACHE->CRR2, ICACHE_REGIONSIZE_2MB << ICACHE_CRRx_RSIZE_Pos);
|
||||
WRITE_REG(ICACHE->CRR3, ICACHE_REGIONSIZE_2MB << ICACHE_CRRx_RSIZE_Pos);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Instruction Cache.
|
||||
* @note This function always returns HAL_OK even if there is any ongoing
|
||||
* cache operation. The Instruction Cache is bypassed until the
|
||||
* cache operation completes.
|
||||
* @retval HAL status (HAL_OK)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_Enable(void)
|
||||
{
|
||||
SET_BIT(ICACHE->CR, ICACHE_CR_EN);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Instruction Cache.
|
||||
* @note This function waits for the cache being disabled but
|
||||
* not for the end of the automatic cache invalidation procedure.
|
||||
* @retval HAL status (HAL_OK/HAL_TIMEOUT)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_Disable(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Make sure BSYENDF is reset before to disable the instruction cache */
|
||||
/* as it automatically starts a cache invalidation procedure */
|
||||
WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
|
||||
|
||||
CLEAR_BIT(ICACHE->CR, ICACHE_CR_EN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for instruction cache being disabled */
|
||||
while (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > ICACHE_DISABLE_TIMEOUT_VALUE)
|
||||
{
|
||||
/* New check to avoid false timeout detection in case of preemption */
|
||||
if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
|
||||
{
|
||||
status = HAL_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check whether the Instruction Cache is enabled or not.
|
||||
* @retval Status (0: disabled, 1: enabled)
|
||||
*/
|
||||
uint32_t HAL_ICACHE_IsEnabled(void)
|
||||
{
|
||||
return ((READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U) ? 1UL : 0UL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Invalidate the Instruction Cache.
|
||||
* @note This function waits for the end of cache invalidation procedure
|
||||
* and clears the associated BSYENDF flag.
|
||||
* @retval HAL status (HAL_OK/HAL_ERROR/HAL_TIMEOUT)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_Invalidate(void)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
/* Check if no ongoing operation */
|
||||
if (READ_BIT(ICACHE->SR, ICACHE_SR_BUSYF) == 0U)
|
||||
{
|
||||
/* Launch cache invalidation */
|
||||
SET_BIT(ICACHE->CR, ICACHE_CR_CACHEINV);
|
||||
}
|
||||
|
||||
status = HAL_ICACHE_WaitForInvalidateComplete();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Invalidate the Instruction Cache with interrupt.
|
||||
* @note This function launches cache invalidation and returns.
|
||||
* User application shall resort to interrupt generation to check
|
||||
* the end of the cache invalidation with the BSYENDF flag and the
|
||||
* HAL_ICACHE_InvalidateCompleteCallback() callback.
|
||||
* @retval HAL status (HAL_OK/HAL_ERROR)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_Invalidate_IT(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check no ongoing operation */
|
||||
if (READ_BIT(ICACHE->SR, ICACHE_SR_BUSYF) != 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Make sure BSYENDF is reset before to start cache invalidation */
|
||||
WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
|
||||
|
||||
/* Enable end of cache invalidation interrupt */
|
||||
SET_BIT(ICACHE->IER, ICACHE_IER_BSYENDIE);
|
||||
|
||||
/* Launch cache invalidation */
|
||||
SET_BIT(ICACHE->CR, ICACHE_CR_CACHEINV);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait for the end of the Instruction Cache invalidate procedure.
|
||||
* @note This function checks and clears the BSYENDF flag when set.
|
||||
* @retval HAL status (HAL_OK/HAL_TIMEOUT)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_WaitForInvalidateComplete(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Check if ongoing invalidation operation */
|
||||
if (READ_BIT(ICACHE->SR, ICACHE_SR_BUSYF) != 0U)
|
||||
{
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for end of cache invalidation */
|
||||
while (READ_BIT(ICACHE->SR, ICACHE_SR_BSYENDF) == 0U)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > ICACHE_INVALIDATE_TIMEOUT_VALUE)
|
||||
{
|
||||
/* New check to avoid false timeout detection in case of preemption */
|
||||
if (READ_BIT(ICACHE->SR, ICACHE_SR_BSYENDF) == 0U)
|
||||
{
|
||||
status = HAL_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear BSYENDF */
|
||||
WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Start the Instruction Cache performance monitoring.
|
||||
* @param MonitorType Monitoring type
|
||||
* This parameter can be one of the following values:
|
||||
* @arg ICACHE_MONITOR_HIT_MISS Hit & Miss monitoring
|
||||
* @arg ICACHE_MONITOR_HIT Hit monitoring
|
||||
* @arg ICACHE_MONITOR_MISS Miss monitoring
|
||||
* @retval HAL status (HAL_OK)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_Monitor_Start(uint32_t MonitorType)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ICACHE_MONITOR_TYPE(MonitorType));
|
||||
|
||||
SET_BIT(ICACHE->CR, MonitorType);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the Instruction Cache performance monitoring.
|
||||
* @note Stopping the monitoring does not reset the values.
|
||||
* @param MonitorType Monitoring type
|
||||
* This parameter can be one of the following values:
|
||||
* @arg ICACHE_MONITOR_HIT_MISS Hit & Miss monitoring
|
||||
* @arg ICACHE_MONITOR_HIT Hit monitoring
|
||||
* @arg ICACHE_MONITOR_MISS Miss monitoring
|
||||
* @retval HAL status (HAL_OK)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_Monitor_Stop(uint32_t MonitorType)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ICACHE_MONITOR_TYPE(MonitorType));
|
||||
|
||||
CLEAR_BIT(ICACHE->CR, MonitorType);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the Instruction Cache performance monitoring values.
|
||||
* @param MonitorType Monitoring type
|
||||
* This parameter can be one of the following values:
|
||||
* @arg ICACHE_MONITOR_HIT_MISS Hit & Miss monitoring
|
||||
* @arg ICACHE_MONITOR_HIT Hit monitoring
|
||||
* @arg ICACHE_MONITOR_MISS Miss monitoring
|
||||
* @retval HAL status (HAL_OK)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_Monitor_Reset(uint32_t MonitorType)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ICACHE_MONITOR_TYPE(MonitorType));
|
||||
|
||||
/* Force/Release reset */
|
||||
SET_BIT(ICACHE->CR, (MonitorType << 2U));
|
||||
CLEAR_BIT(ICACHE->CR, (MonitorType << 2U));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Instruction Cache performance Hit monitoring value.
|
||||
* @note Upon reaching the 32-bit maximum value, monitor does not wrap.
|
||||
* @retval Hit monitoring value
|
||||
*/
|
||||
uint32_t HAL_ICACHE_Monitor_GetHitValue(void)
|
||||
{
|
||||
return (ICACHE->HMONR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Instruction Cache performance Miss monitoring value.
|
||||
* @note Upon reaching the 32-bit maximum value, monitor does not wrap.
|
||||
* @retval Miss monitoring value
|
||||
*/
|
||||
uint32_t HAL_ICACHE_Monitor_GetMissValue(void)
|
||||
{
|
||||
return (ICACHE->MMONR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup ICACHE_Exported_Functions_Group2 IRQ and callback functions
|
||||
* @brief IRQ and callback functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### IRQ and callback functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to handle ICACHE global interrupt
|
||||
and the associated callback functions.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Handle the Instruction Cache interrupt request.
|
||||
* @note This function should be called under the ICACHE_IRQHandler().
|
||||
* @note This function respectively disables the interrupt and clears the
|
||||
* flag of any pending flag before calling the associated user callback.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ICACHE_IRQHandler(void)
|
||||
{
|
||||
/* Get current interrupt flags and interrupt sources value */
|
||||
uint32_t itflags = READ_REG(ICACHE->SR);
|
||||
uint32_t itsources = READ_REG(ICACHE->IER);
|
||||
|
||||
/* Check Instruction cache Error interrupt flag */
|
||||
if (((itflags & itsources) & ICACHE_FLAG_ERROR) != 0U)
|
||||
{
|
||||
/* Disable error interrupt */
|
||||
CLEAR_BIT(ICACHE->IER, ICACHE_IER_ERRIE);
|
||||
|
||||
/* Clear ERR pending flag */
|
||||
WRITE_REG(ICACHE->FCR, ICACHE_FCR_CERRF);
|
||||
|
||||
/* Instruction cache error interrupt user callback */
|
||||
HAL_ICACHE_ErrorCallback();
|
||||
}
|
||||
|
||||
/* Check Instruction cache BusyEnd interrupt flag */
|
||||
if (((itflags & itsources) & ICACHE_FLAG_BUSYEND) != 0U)
|
||||
{
|
||||
/* Disable end of cache invalidation interrupt */
|
||||
CLEAR_BIT(ICACHE->IER, ICACHE_IER_BSYENDIE);
|
||||
|
||||
/* Clear BSYENDF pending flag */
|
||||
WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
|
||||
|
||||
/* Instruction cache busyend interrupt user callback */
|
||||
HAL_ICACHE_InvalidateCompleteCallback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cache invalidation complete callback.
|
||||
*/
|
||||
__weak void HAL_ICACHE_InvalidateCompleteCallback(void)
|
||||
{
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_ICACHE_InvalidateCompleteCallback() should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Error callback.
|
||||
*/
|
||||
__weak void HAL_ICACHE_ErrorCallback(void)
|
||||
{
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_ICACHE_ErrorCallback() should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup ICACHE_Exported_Functions_Group3 Memory remapped regions functions
|
||||
* @brief Memory remapped regions functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Memory remapped regions functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to manage the remapping of
|
||||
external memories to internal Code for execution.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure and enable a region for memory remapping.
|
||||
* @note The Instruction Cache and the region must be disabled.
|
||||
* @param Region Region number
|
||||
This parameter can be a value of @arg @ref ICACHE_Region
|
||||
* @param pRegionConfig Pointer to structure of ICACHE region configuration parameters
|
||||
* @retval HAL status (HAL_OK/HAL_ERROR)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_EnableRemapRegion(uint32_t Region, const ICACHE_RegionConfigTypeDef *const pRegionConfig)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint32_t *p_reg;
|
||||
uint32_t value;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ICACHE_REGION_NUMBER(Region));
|
||||
assert_param(IS_ICACHE_REGION_SIZE(pRegionConfig->Size));
|
||||
assert_param(IS_ICACHE_REGION_TRAFFIC_ROUTE(pRegionConfig->TrafficRoute));
|
||||
assert_param(IS_ICACHE_REGION_OUTPUT_BURST_TYPE(pRegionConfig->OutputBurstType));
|
||||
|
||||
/* Check cache is not enabled */
|
||||
if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get region control register address */
|
||||
p_reg = &(ICACHE->CRR0) + (1U * Region);
|
||||
|
||||
/* Check region is not already enabled */
|
||||
if ((*p_reg & ICACHE_CRRx_REN) != 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Region 2MB: BaseAddress size 8 bits, RemapAddress size 11 bits */
|
||||
/* Region 4MB: BaseAddress size 7 bits, RemapAddress size 10 bits */
|
||||
/* Region 8MB: BaseAddress size 6 bits, RemapAddress size 9 bits */
|
||||
/* Region 16MB: BaseAddress size 5 bits, RemapAddress size 8 bits */
|
||||
/* Region 32MB: BaseAddress size 4 bits, RemapAddress size 7 bits */
|
||||
/* Region 64MB: BaseAddress size 3 bits, RemapAddress size 6 bits */
|
||||
/* Region 128MB: BaseAddress size 2 bits, RemapAddress size 5 bits */
|
||||
value = ((pRegionConfig->BaseAddress & 0x1FFFFFFFU) >> 21U) & \
|
||||
(0xFFU & ~(pRegionConfig->Size - 1U));
|
||||
value |= ((pRegionConfig->RemapAddress >> 5U) & \
|
||||
((uint32_t)(0x7FFU & ~(pRegionConfig->Size - 1U)) << ICACHE_CRRx_REMAPADDR_Pos));
|
||||
value |= (pRegionConfig->Size << ICACHE_CRRx_RSIZE_Pos) | pRegionConfig->TrafficRoute | \
|
||||
pRegionConfig->OutputBurstType;
|
||||
*p_reg = (value | ICACHE_CRRx_REN);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the memory remapping for a predefined region.
|
||||
* @param Region Region number
|
||||
This parameter can be a value of @arg @ref ICACHE_Region
|
||||
* @retval HAL status (HAL_OK/HAL_ERROR)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ICACHE_DisableRemapRegion(uint32_t Region)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint32_t *p_reg;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ICACHE_REGION_NUMBER(Region));
|
||||
|
||||
/* Check cache is not enabled */
|
||||
if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get region control register address */
|
||||
p_reg = &(ICACHE->CRR0) + (1U * Region);
|
||||
|
||||
*p_reg &= ~ICACHE_CRRx_REN;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,341 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32u3xx_hal_spi_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended SPI HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* SPI peripheral extended functionalities :
|
||||
* + IO operation functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32u3xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32U3xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SPIEx SPIEx
|
||||
* @brief SPI Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
|
||||
* @brief Data transfers functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of extended functions to manage the SPI
|
||||
data transfers.
|
||||
|
||||
(#) SPIEx function:
|
||||
(++) HAL_SPIEx_FlushRxFifo()
|
||||
(++) HAL_SPIEx_EnableLockConfiguration()
|
||||
(++) HAL_SPIEx_ConfigureUnderrun()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Flush the RX fifo.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SPI module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(const SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint32_t itflag = hspi->Instance->SR;
|
||||
__IO uint32_t tmpreg;
|
||||
|
||||
while (((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_RX_FIFO_0PACKET) || ((itflag & SPI_FLAG_RXWNE) != 0UL))
|
||||
{
|
||||
count += (uint8_t)4UL;
|
||||
tmpreg = hspi->Instance->RXDR;
|
||||
UNUSED(tmpreg); /* To avoid GCC warning */
|
||||
|
||||
if (IS_SPI_FULL_INSTANCE(hspi->Instance))
|
||||
{
|
||||
if (count > SPI_HIGHEND_FIFO_SIZE)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count > SPI_LOWEND_FIFO_SIZE)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Lock for the AF configuration of associated IOs
|
||||
* and write protect the Content of Configuration register 2
|
||||
* when SPI is enabled
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_EnableLockConfiguration(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
HAL_StatusTypeDef errorcode = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hspi);
|
||||
|
||||
if (hspi->State != HAL_SPI_STATE_READY)
|
||||
{
|
||||
errorcode = HAL_BUSY;
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/* Check if the SPI is disabled to edit IOLOCK bit */
|
||||
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
SET_BIT(hspi->Instance->CR1, SPI_CR1_IOLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_SPI_DISABLE(hspi);
|
||||
|
||||
SET_BIT(hspi->Instance->CR1, SPI_CR1_IOLOCK);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_SPI_ENABLE(hspi);
|
||||
}
|
||||
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the UNDERRUN condition and behavior of slave transmitter.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @param UnderrunDetection : Detection of underrun condition at slave transmitter
|
||||
* This parameter is not supported in this SPI version.
|
||||
* It is kept in order to not break the compatibility.
|
||||
* @param UnderrunBehaviour : Behavior of slave transmitter at underrun condition
|
||||
* This parameter can be a value of @ref SPI_Underrun_Behaviour.
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_ConfigureUnderrun(SPI_HandleTypeDef *hspi, uint32_t UnderrunDetection,
|
||||
uint32_t UnderrunBehaviour)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(UnderrunDetection);
|
||||
|
||||
HAL_StatusTypeDef errorcode = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hspi);
|
||||
|
||||
/* Check State and Insure that Underrun configuration is managed only by Salve */
|
||||
if ((hspi->State != HAL_SPI_STATE_READY) || (hspi->Init.Mode != SPI_MODE_SLAVE))
|
||||
{
|
||||
errorcode = HAL_BUSY;
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_UNDERRUN_BEHAVIOUR(UnderrunBehaviour));
|
||||
|
||||
/* Check if the SPI is disabled to edit CFG1 register */
|
||||
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Configure Underrun fields */
|
||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRCFG, UnderrunBehaviour);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_SPI_DISABLE(hspi);
|
||||
|
||||
/* Configure Underrun fields */
|
||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRCFG, UnderrunBehaviour);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_SPI_ENABLE(hspi);
|
||||
}
|
||||
|
||||
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Autonomous Mode configuration
|
||||
* @param hspi Pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SPIx peripheral.
|
||||
* @param sConfig Pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information of the autonomous mode for the specified SPIx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_SetConfigAutonomousMode(SPI_HandleTypeDef *hspi,
|
||||
const SPI_AutonomousModeConfTypeDef *sConfig)
|
||||
{
|
||||
if (hspi->State == HAL_SPI_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hspi);
|
||||
|
||||
hspi->State = HAL_SPI_STATE_BUSY;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_AUTONOMOUS_INSTANCE(hspi->Instance));
|
||||
assert_param(IS_SPI_TRIG_SOURCE(hspi->Instance, sConfig->TriggerSelection));
|
||||
assert_param(IS_SPI_AUTO_MODE_TRG_POL(sConfig->TriggerPolarity));
|
||||
|
||||
/* Disable the selected SPI peripheral to be able to configure AUTOCR */
|
||||
__HAL_SPI_DISABLE(hspi);
|
||||
|
||||
/* SPIx AUTOCR Configuration */
|
||||
WRITE_REG(hspi->Instance->AUTOCR, (sConfig->TriggerState | ((sConfig->TriggerSelection) & SPI_AUTOCR_TRIGSEL_Msk) |
|
||||
sConfig->TriggerPolarity));
|
||||
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Autonomous Mode configuration
|
||||
* @param hspi Pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SPIx peripheral.
|
||||
* @param sConfig Pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information of the autonomous mode for the specified SPIx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_GetConfigAutonomousMode(const SPI_HandleTypeDef *hspi,
|
||||
SPI_AutonomousModeConfTypeDef *sConfig)
|
||||
{
|
||||
uint32_t autocr_tmp;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_AUTONOMOUS_INSTANCE(hspi->Instance));
|
||||
|
||||
autocr_tmp = hspi->Instance->AUTOCR;
|
||||
|
||||
sConfig->TriggerState = (autocr_tmp & SPI_AUTOCR_TRIGEN);
|
||||
if (IS_SPI_GRP2_INSTANCE(hspi->Instance))
|
||||
{
|
||||
sConfig->TriggerSelection = ((autocr_tmp & SPI_AUTOCR_TRIGSEL) | SPI_TRIG_GRP2);
|
||||
}
|
||||
else
|
||||
{
|
||||
sConfig->TriggerSelection = ((autocr_tmp & SPI_AUTOCR_TRIGSEL) | SPI_TRIG_GRP1);
|
||||
}
|
||||
sConfig->TriggerPolarity = (autocr_tmp & SPI_AUTOCR_TRIGPOL);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear Autonomous Mode configuration
|
||||
* @param hspi Pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SPIx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_ClearConfigAutonomousMode(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
if (hspi->State == HAL_SPI_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hspi);
|
||||
|
||||
hspi->State = HAL_SPI_STATE_BUSY;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_AUTONOMOUS_INSTANCE(hspi->Instance));
|
||||
|
||||
/* Disable the selected SPI peripheral to be able to clear AUTOCR */
|
||||
__HAL_SPI_DISABLE(hspi);
|
||||
|
||||
CLEAR_REG(hspi->Instance->AUTOCR);
|
||||
|
||||
/* Enable the selected SPI peripheral */
|
||||
__HAL_SPI_ENABLE(hspi);
|
||||
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user