add stm32mp157
This commit is contained in:
@ -0,0 +1,974 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_hal.c
|
||||
* @author MCD Application Team
|
||||
* @brief HAL module driver.
|
||||
* This is the common part of the HAL initialization
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The common HAL driver contains a set of generic and common APIs that can be
|
||||
used by the PPP peripheral drivers and the user to start using the HAL.
|
||||
[..]
|
||||
The HAL contains two APIs' categories:
|
||||
(+) Common HAL APIs
|
||||
(+) Services HAL APIs
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL HAL
|
||||
* @brief HAL module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup HAL_Private_Defines HAL Private Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief STM32MP1xx HAL Driver version number
|
||||
*/
|
||||
#define __STM32MP1xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
|
||||
#define __STM32MP1xx_HAL_VERSION_SUB1 (0x07U) /*!< [23:16] sub1 version */
|
||||
#define __STM32MP1xx_HAL_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
|
||||
#define __STM32MP1xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
||||
#define __STM32MP1xx_HAL_VERSION ((__STM32MP1xx_HAL_VERSION_MAIN << 24)\
|
||||
|(__STM32MP1xx_HAL_VERSION_SUB1 << 16)\
|
||||
|(__STM32MP1xx_HAL_VERSION_SUB2 << 8 )\
|
||||
|(__STM32MP1xx_HAL_VERSION_RC))
|
||||
|
||||
#define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
|
||||
#define VREFBUF_TIMEOUT_VALUE (uint32_t)10 /* 10 ms */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_Private_Constants HAL Private Constants
|
||||
* @{
|
||||
*/
|
||||
#define SYSCFG_DEFAULT_TIMEOUT 100U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup HAL_Exported_Variables HAL Exported Variables
|
||||
* @{
|
||||
*/
|
||||
__IO uint32_t uwTick;
|
||||
#if defined(CORE_CM4)
|
||||
uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
|
||||
#else /* CA7 */
|
||||
uint32_t uwTickPrio = (1UL << 4); /* Invalid PRIO */
|
||||
#endif
|
||||
HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup HAL_Private_Functions HAL Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_Group1 Initialization and de-initialization Functions
|
||||
* @brief Initialization and de-initialization functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Initializes the Flash interface the NVIC allocation and initial clock
|
||||
configuration. It initializes the systick also when timeout is needed
|
||||
and the backup domain when enabled.
|
||||
(+) De-Initializes common part of the HAL.
|
||||
(+) Configure The time base source to have 1ms time base with a dedicated
|
||||
Tick interrupt priority.
|
||||
(++) SysTick timer is used by default as source of time base, but user
|
||||
can eventually implement his proper time base source (a general purpose
|
||||
timer for example or other time source), keeping in mind that Time base
|
||||
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
|
||||
handled in milliseconds basis.
|
||||
(++) Time base configuration function (HAL_InitTick ()) is called automatically
|
||||
at the beginning of the program after reset by HAL_Init() or at any time
|
||||
when clock is configured, by HAL_RCC_ClockConfig().
|
||||
(++) Source of time base is configured to generate interrupts at regular
|
||||
time intervals. Care must be taken if HAL_Delay() is called from a
|
||||
peripheral ISR process, the Tick interrupt line must have higher priority
|
||||
(numerically lower) than the peripheral interrupt. Otherwise the caller
|
||||
ISR process will be blocked.
|
||||
(++) functions affecting time base configurations are declared as __weak
|
||||
to make override possible in case of other implementations in user file.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function is used to initialize the HAL Library; it must be the first
|
||||
* instruction to be executed in the main program (before to call any other
|
||||
* HAL function), it performs the following:
|
||||
* Configures the SysTick to generate an interrupt each 1 millisecond,
|
||||
* which is clocked by the HSI (at this stage, the clock is not yet
|
||||
* configured and thus the system is running from the internal HSI at 64 MHz).
|
||||
* Set NVIC Group Priority to 4.
|
||||
* Calls the HAL_MspInit() callback function defined in user file
|
||||
* "stm32mp1xx_hal_msp.c" to do the global low level hardware initialization
|
||||
*
|
||||
* @note SysTick is used as time base for the HAL_Delay() function, the application
|
||||
* need to ensure that the SysTick time base is always set to 1 millisecond
|
||||
* to have correct HAL operation.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_Init(void)
|
||||
{
|
||||
/* Set Interrupt Group Priority */
|
||||
#if defined (CORE_CM4)
|
||||
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
|
||||
#endif
|
||||
|
||||
/* Update the SystemCoreClock global variable */
|
||||
SystemCoreClock = HAL_RCC_GetSystemCoreClockFreq();
|
||||
|
||||
/* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
|
||||
if(HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Init the low level hardware */
|
||||
HAL_MspInit();
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function de-Initializes common part of the HAL and stops the systick.
|
||||
* This function is optional.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DeInit(void)
|
||||
{
|
||||
/* Reset of all peripherals */
|
||||
|
||||
|
||||
/* De-Init the low level hardware */
|
||||
HAL_MspDeInit();
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the MSP.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MspInit(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_MspInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the MSP.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MspDeInit(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_MspDeInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function configures the source of the time base.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
* reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
|
||||
* @note In the default implementation, SysTick timer is the source of time base.
|
||||
* It is used to generate interrupts at regular time intervals.
|
||||
* Care must be taken if HAL_Delay() is called from a peripheral ISR process,
|
||||
* The the SysTick interrupt must have higher priority (numerically lower)
|
||||
* than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
|
||||
* The function is declared as __weak to be overwritten in case of other
|
||||
* implementation in user file.
|
||||
* @param TickPriority: Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
/*Configure the Tick to have interrupt in 1ms time basis*/
|
||||
#if defined (CORE_CA7)
|
||||
|
||||
#if defined(USE_ST_CASIS)
|
||||
HAL_SYSTICK_Config(SystemCoreClock/1000);
|
||||
#elif defined (USE_PL1_SecurePhysicalTimer_IRQ)
|
||||
/* Stop Timer */
|
||||
PL1_SetControl(0x0);
|
||||
|
||||
PL1_SetCounterFrequency(HSI_VALUE);
|
||||
|
||||
/* Initialize Counter */
|
||||
PL1_SetLoadValue(HSI_VALUE/1000);
|
||||
|
||||
/* Disable corresponding IRQ */
|
||||
IRQ_Disable(SecurePhysicalTimer_IRQn);
|
||||
IRQ_ClearPending(SecurePhysicalTimer_IRQn);
|
||||
|
||||
/* Set timer priority to lowest (Only bit 7:3 are implemented in MP1 CA7 GIC) */
|
||||
/* TickPriority is based on 16 level priority (from MCUs) so set it in 7:4 and leave bit 3=0 */
|
||||
if (TickPriority < (1UL << 4))
|
||||
{
|
||||
IRQ_SetPriority(SecurePhysicalTimer_IRQn, TickPriority << 4);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Set edge-triggered IRQ */
|
||||
IRQ_SetMode(SecurePhysicalTimer_IRQn, IRQ_MODE_TRIG_EDGE);
|
||||
|
||||
/* Enable corresponding interrupt */
|
||||
IRQ_Enable(SecurePhysicalTimer_IRQn);
|
||||
|
||||
/* Kick start Timer */
|
||||
PL1_SetControl(0x1);
|
||||
#else
|
||||
/*Set Counter Frequency */
|
||||
PL1_SetCounterFrequency(HSI_VALUE);
|
||||
// __set_CNTFRQ(HSI_VALUE);
|
||||
/* Initialize Counter */
|
||||
PL1_SetLoadValue(0x1);
|
||||
// __set_CNTP_TVAL(0x1);
|
||||
#endif
|
||||
|
||||
#endif /* CORE_CA7 */
|
||||
|
||||
|
||||
#if defined (CORE_CM4)
|
||||
if ((uint32_t)uwTickFreq == 0U)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Configure the SysTick to have interrupt in 1ms time basis*/
|
||||
if (HAL_SYSTICK_Config(SystemCoreClock /(1000U / uwTickFreq)) > 0U)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
#endif /* CORE_CM4 */
|
||||
|
||||
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_Group2 HAL Control functions
|
||||
* @brief HAL Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### HAL Control functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Provide a tick value in millisecond
|
||||
(+) Provide a blocking delay in millisecond
|
||||
(+) Suspend the time base source interrupt
|
||||
(+) Resume the time base source interrupt
|
||||
(+) Get the HAL API driver version
|
||||
(+) Get the device identifier
|
||||
(+) Get the device revision identifier
|
||||
(+) Enable/Disable Debug module during SLEEP mode
|
||||
(+) Enable/Disable Debug module during STOP mode
|
||||
(+) Enable/Disable Debug module during STANDBY mode
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function is called to increment a global variable "uwTick"
|
||||
* used as application time base.
|
||||
* @note In the default implementation, this variable is incremented each 1ms
|
||||
* in Systick ISR.
|
||||
* @note This function is declared as __weak to be overwritten in case of other
|
||||
* implementations in user file.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_IncTick(void)
|
||||
{
|
||||
uwTick += (uint32_t)uwTickFreq;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Provides a tick value in millisecond.
|
||||
* @note This function is declared as __weak to be overwritten in case of other
|
||||
* implementations in user file.
|
||||
* @retval tick value
|
||||
*/
|
||||
__weak uint32_t HAL_GetTick(void)
|
||||
{
|
||||
#if defined (CORE_CA7)
|
||||
|
||||
#if defined (USE_ST_CASIS)
|
||||
return ( Gen_Timer_Get_PhysicalCount() / (HSI_VALUE/1000));
|
||||
#elif defined (USE_PL1_SecurePhysicalTimer_IRQ)
|
||||
/* tick is incremented in SecurePhysicalTimer_IRQ handler */
|
||||
return uwTick;
|
||||
#else
|
||||
/* tick value directly got from 64bits CA7 register*/
|
||||
if ((RCC->STGENCKSELR & RCC_STGENCKSELR_STGENSRC) == RCC_STGENCLKSOURCE_HSE)
|
||||
{
|
||||
return ((uint32_t)PL1_GetCurrentPhysicalValue() / (HSE_VALUE / 1000UL));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((uint32_t)PL1_GetCurrentPhysicalValue() / (HSI_VALUE / 1000UL));
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CORE_CA7 */
|
||||
|
||||
|
||||
#if defined (CORE_CM4)
|
||||
/* tick is incremented in systick handler */
|
||||
return uwTick;
|
||||
#endif /* CORE_CM4 */
|
||||
|
||||
}
|
||||
|
||||
#if defined (CORE_CM4)
|
||||
/**
|
||||
* @brief This function returns a tick priority.
|
||||
* @retval tick priority
|
||||
*/
|
||||
uint32_t HAL_GetTickPrio(void)
|
||||
{
|
||||
return uwTickPrio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set new tick Freq.
|
||||
* @retval Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
HAL_TickFreqTypeDef prevTickFreq;
|
||||
assert_param(IS_TICKFREQ(Freq));
|
||||
|
||||
if (uwTickFreq != Freq)
|
||||
{
|
||||
/* Back up uwTickFreq frequency */
|
||||
prevTickFreq = uwTickFreq;
|
||||
|
||||
/* Update uwTickFreq global variable used by HAL_InitTick() */
|
||||
uwTickFreq = Freq;
|
||||
|
||||
/* Apply the new tick Freq */
|
||||
status = HAL_InitTick(uwTickPrio);
|
||||
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
/* Restore previous tick frequency */
|
||||
uwTickFreq = prevTickFreq;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return tick frequency.
|
||||
* @retval tick period in Hz
|
||||
*/
|
||||
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
|
||||
{
|
||||
return uwTickFreq;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief This function provides accurate delay (in milliseconds) based
|
||||
* on variable incremented.
|
||||
* @note In the default implementation , SysTick timer is the source of time base.
|
||||
* It is used to generate interrupts at regular time intervals where uwTick
|
||||
* is incremented.
|
||||
* @note ThiS function is declared as __weak to be overwritten in case of other
|
||||
* implementations in user file.
|
||||
* @param Delay: specifies the delay time length, in milliseconds.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_Delay(uint32_t Delay)
|
||||
{
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
uint32_t wait = Delay;
|
||||
|
||||
/* Add a freq to guarantee minimum wait */
|
||||
if (wait < HAL_MAX_DELAY)
|
||||
{
|
||||
wait += (uint32_t)(uwTickFreq);
|
||||
}
|
||||
|
||||
while ((HAL_GetTick() - tickstart) < wait)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note In the default implementation , SysTick timer is the source of time base. It is
|
||||
* used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
|
||||
* is called, the the SysTick interrupt will be disabled and so Tick increment
|
||||
* is suspended.
|
||||
* @note This function is declared as __weak to be overwritten in case of other
|
||||
* implementations in user file.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SuspendTick(void)
|
||||
{
|
||||
#if defined (CORE_CA7)
|
||||
#elif defined (CORE_CM4)
|
||||
/* Disable SysTick Interrupt */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note In the default implementation , SysTick timer is the source of time base. It is
|
||||
* used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
|
||||
* is called, the the SysTick interrupt will be enabled and so Tick increment
|
||||
* is resumed.
|
||||
* @note This function is declared as __weak to be overwritten in case of other
|
||||
* implementations in user file.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_ResumeTick(void)
|
||||
{
|
||||
#if defined (CORE_CA7)
|
||||
#elif defined (CORE_CM4)
|
||||
/* Enable SysTick Interrupt */
|
||||
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the HAL revision
|
||||
* @retval version : 0xXYZR (8bits for each decimal, R for RC)
|
||||
*/
|
||||
uint32_t HAL_GetHalVersion(void)
|
||||
{
|
||||
return __STM32MP1xx_HAL_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the device revision identifier.
|
||||
* @retval Device revision identifier
|
||||
*/
|
||||
uint32_t HAL_GetREVID(void)
|
||||
{
|
||||
return((DBGMCU->IDCODE) >> 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the device identifier.
|
||||
* @retval Device identifier
|
||||
*/
|
||||
uint32_t HAL_GetDEVID(void)
|
||||
{
|
||||
return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the first word of the unique device identifier (UID based on 96 bits)
|
||||
* @retval Device identifier
|
||||
*/
|
||||
uint32_t HAL_GetUIDw0(void)
|
||||
{
|
||||
return(READ_REG(*((uint32_t *)UID_BASE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the second word of the unique device identifier (UID based on 96 bits)
|
||||
* @retval Device identifier
|
||||
*/
|
||||
uint32_t HAL_GetUIDw1(void)
|
||||
{
|
||||
return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the third word of the unique device identifier (UID based on 96 bits)
|
||||
* @retval Device identifier
|
||||
*/
|
||||
uint32_t HAL_GetUIDw2(void)
|
||||
{
|
||||
return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable DBG wake up on AIEC
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDBGWakeUp(void)
|
||||
{
|
||||
#if defined (CORE_CA7)
|
||||
SET_BIT(EXTI_C1->IMR3, EXTI_IMR3_IM75);
|
||||
#elif defined (CORE_CM4)
|
||||
SET_BIT(EXTI_C2->IMR3, EXTI_IMR3_IM75);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable DBG wake up on AIEC
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDBGWakeUp(void)
|
||||
{
|
||||
#if defined (CORE_CA7)
|
||||
CLEAR_BIT(EXTI_C1->IMR3, EXTI_IMR3_IM75);
|
||||
#elif defined (CORE_CM4)
|
||||
CLEAR_BIT(EXTI_C2->IMR3, EXTI_IMR3_IM75);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain1 SLEEP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDBGSleepMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain1 SLEEP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDBGSleepMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain1 STOP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDBGStopMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain1 STOP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDBGStopMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain1 STANDBY mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDBGStandbyMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain1 STANDBY mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDBGStandbyMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configure the internal voltage reference buffer voltage scale.
|
||||
* @param VoltageScaling specifies the output voltage to achieve
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.048 V.
|
||||
* This requires VDDA equal to or higher than 2.4 V.
|
||||
* @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT2 around 2.5 V.
|
||||
* This requires VDDA equal to or higher than 2.8 V.
|
||||
* @arg SYSCFG_VREFBUF_VOLTAGE_SCALE2: VREF_OUT3 around 1.5 V.
|
||||
* This requires VDDA equal to or higher than 1.8 V.
|
||||
* @arg SYSCFG_VREFBUF_VOLTAGE_SCALE3: VREF_OUT4 around 1.8 V.
|
||||
* This requires VDDA equal to or higher than 2.1 V.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
|
||||
|
||||
MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the internal voltage reference buffer high impedance mode.
|
||||
* @param Mode specifies the high impedance mode
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE: VREF+ pin is internally connect to VREFINT output.
|
||||
* @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE: VREF+ pin is high impedance.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
|
||||
|
||||
MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tune the Internal Voltage Reference buffer (VREFBUF).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
|
||||
|
||||
MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Internal Voltage Reference buffer (VREFBUF).
|
||||
* @retval HAL_OK/HAL_TIMEOUT
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
|
||||
|
||||
/* Get Start Tick*/
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for VRR bit */
|
||||
while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Internal Voltage Reference buffer (VREFBUF).
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_DisableVREFBUF(void)
|
||||
{
|
||||
CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Ethernet PHY Interface Selection either MII or RMII
|
||||
* @param SYSCFG_ETHInterface: Selects the Ethernet PHY interface
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SYSCFG_ETH_MII : Select the Media Independent Interface
|
||||
* @arg SYSCFG_ETH_GMII : Select the Gigabit Media Independent Interface
|
||||
* @arg SYSCFG_ETH_RGMII: Select the Gigabit Reduced Media Independent Interface
|
||||
* @arg SYSCFG_ETH_RMII : Select the Reduced Media Independent Interface
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_ETHInterfaceSelect(uint32_t SYSCFG_ETHInterface)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_SYSCFG_ETHERNET_CONFIG(SYSCFG_ETHInterface));
|
||||
SYSCFG->PMCCLRR = SYSCFG_PMCSETR_ETH_SEL|SYSCFG_PMCSETR_ETH_SELMII_SEL;
|
||||
SYSCFG->PMCSETR = (uint32_t)(SYSCFG_ETHInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analog Switch control for dual analog pads.
|
||||
* @param SYSCFG_AnalogSwitch: Selects the analog pad
|
||||
* This parameter can be one or a combination of the following values:
|
||||
* @arg SYSCFG_SWITCH_PA0 : Select PA0 analog switch
|
||||
* @arg SYSCFG_SWITCH_PA1: Select PA1 analog switch
|
||||
* @param SYSCFG_SwitchState: Open or Close the analog switch between dual pads (
|
||||
* This parameter can be one or a combination of the following values:
|
||||
* @arg SYSCFG_SWITCH_PA0_OPEN
|
||||
* @arg SYSCFG_SWITCH_PA0_CLOSE
|
||||
* @arg SYSCFG_SWITCH_PA1_OPEN
|
||||
* @arg SYSCFG_SWITCH_PA1_CLOSE
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void HAL_SYSCFG_AnalogSwitchConfig(uint32_t SYSCFG_AnalogSwitch , uint32_t SYSCFG_SwitchState )
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_SYSCFG_ANALOG_SWITCH(SYSCFG_AnalogSwitch));
|
||||
assert_param(IS_SYSCFG_SWITCH_STATE(SYSCFG_SwitchState));
|
||||
SYSCFG->PMCCLRR = SYSCFG_AnalogSwitch;
|
||||
SYSCFG->PMCSETR = (uint32_t)(SYSCFG_SwitchState);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables the booster to reduce the total harmonic distortion of the analog
|
||||
* switch when the supply voltage is lower than 2.7 V.
|
||||
* @note Activating the booster allows to guaranty the analog switch AC performance
|
||||
* when the supply voltage is below 2.7 V: in this case, the analog switch
|
||||
* performance is the same on the full voltage range
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_EnableBOOST(void)
|
||||
{
|
||||
SYSCFG->PMCSETR = SYSCFG_PMCSETR_EN_BOOSTER;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables the booster
|
||||
* @note Activating the booster allows to guaranty the analog switch AC performance
|
||||
* when the supply voltage is below 2.7 V: in this case, the analog switch
|
||||
* performance is the same on the full voltage range
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_DisableBOOST(void)
|
||||
{
|
||||
SYSCFG->PMCCLRR = SYSCFG_PMCCLRR_EN_BOOSTER;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables the I/O Compensation Cell.
|
||||
* @note The I/O compensation cell can be used only when the device supply
|
||||
* voltage ranges from 2.4 to 3.6 V.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableCompensationCell(void)
|
||||
{
|
||||
#if defined(CORE_CM4)
|
||||
SYSCFG->CMPENSETR = SYSCFG_CMPENSETR_MCU_EN;
|
||||
#elif defined(CORE_CA7)
|
||||
SYSCFG->CMPENSETR = SYSCFG_CMPENSETR_MPU_EN;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Power-down the I/O Compensation Cell.
|
||||
* @note The I/O compensation cell can be used only when the device supply
|
||||
* voltage ranges from 2.4 to 3.6 V.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableCompensationCell(void)
|
||||
{
|
||||
#if defined(CORE_CM4)
|
||||
SYSCFG->CMPENCLRR = SYSCFG_CMPENCLRR_MCU_EN;
|
||||
#elif defined(CORE_CA7)
|
||||
SYSCFG->CMPENCLRR = SYSCFG_CMPENCLRR_MPU_EN;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief To Enable optimize the I/O speed when the product voltage is low.
|
||||
* @note This bit is active only if PRODUCT_BELOW_25V user option bit is set. It must be
|
||||
* used only if the product supply voltage is below 2.5 V. Setting this bit when VDD is
|
||||
* higher than 2.5 V might be destructive.
|
||||
* @param SYSCFG_HighSpeedSignal: Signal selection (TRACE, QUADSPI...)
|
||||
* This parameter can be one or a combination of the following values:
|
||||
* @arg SYSCFG_HIGHSPEED_TRACE_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_QUADSPI_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_ETH_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_SDMMC_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_SPI_SIGNAL
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_EnableIOSpeedOptimize(uint32_t SYSCFG_HighSpeedSignal )
|
||||
{
|
||||
SYSCFG->IOCTRLSETR = SYSCFG_HighSpeedSignal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief To Disable optimize the I/O speed when the product voltage is low.
|
||||
* @note This bit is active only if PRODUCT_BELOW_25V user option bit is set. It must be
|
||||
* used only if the product supply voltage is below 2.5 V. Setting this bit when VDD is
|
||||
* higher than 2.5 V might be destructive.
|
||||
* @param SYSCFG_HighSpeedSignal: Signal selection (TRACE, QUADSPI...)
|
||||
* This parameter can be one or a combination of the following values:
|
||||
* @arg SYSCFG_HIGHSPEED_TRACE_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_QUADSPI_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_ETH_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_SDMMC_SIGNAL
|
||||
* @arg SYSCFG_HIGHSPEED_SPI_SIGNAL
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_DisableIOSpeedOptimize(uint32_t SYSCFG_HighSpeedSignal )
|
||||
{
|
||||
SYSCFG->IOCTRLCLRR = SYSCFG_HighSpeedSignal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Code selection for the I/O Compensation cell
|
||||
* @param SYSCFG_CompCode: Selects the code to be applied for the I/O compensation cell
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SYSCFG_CELL_CODE : Select Code from the cell (available in the SYSCFG_CCVR)
|
||||
* @arg SYSCFG_REGISTER_CODE: Select Code from the SYSCFG compensation cell code register (SYSCFG_CCCR)
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_CompensationCodeSelect(uint32_t SYSCFG_CompCode)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_SYSCFG_CODE_SELECT(SYSCFG_CompCode));
|
||||
MODIFY_REG(SYSCFG->CMPCR, SYSCFG_CMPCR_SW_CTRL, (uint32_t)(SYSCFG_CompCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Code selection for the I/O Compensation cell
|
||||
* @param SYSCFG_PMOSCode: PMOS compensation code
|
||||
* This code is applied to the I/O compensation cell when the CS bit of the
|
||||
* SYSCFG_CMPCR is set
|
||||
* @param SYSCFG_NMOSCode: NMOS compensation code
|
||||
* This code is applied to the I/O compensation cell when the CS bit of the
|
||||
* SYSCFG_CMPCR is set
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_CompensationCodeConfig(uint32_t SYSCFG_PMOSCode, uint32_t SYSCFG_NMOSCode )
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_SYSCFG_CODE_CONFIG(SYSCFG_PMOSCode));
|
||||
assert_param(IS_SYSCFG_CODE_CONFIG(SYSCFG_NMOSCode));
|
||||
MODIFY_REG(SYSCFG->CMPCR, SYSCFG_CMPCR_RANSRC|SYSCFG_CMPCR_RAPSRC, (((uint32_t)(SYSCFG_PMOSCode)<< 4)|(uint32_t)(SYSCFG_NMOSCode)) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable IO compensation mechanism
|
||||
* E.g. before going into STOP
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_DisableIOCompensation(void)
|
||||
{
|
||||
uint32_t pmos_val = 0;
|
||||
uint32_t nmos_val = 0;
|
||||
|
||||
/* Get I/O compensation cell values for PMOS and NMOS transistors */
|
||||
pmos_val = (__HAL_SYSCFG_GET_PMOS_CMP() >> 28);
|
||||
nmos_val = (__HAL_SYSCFG_GET_NMOS_CMP() >> 24);
|
||||
|
||||
/* Copy actual value of SYSCFG_CMPCR.APSRC[3:0]/ANSRC[3:0] in
|
||||
* SYSCFG_CMPCR.RAPSRC[3:0]/RANSRC[3:0]
|
||||
*/
|
||||
HAL_SYSCFG_CompensationCodeConfig(pmos_val, nmos_val);
|
||||
|
||||
/* Set SYSCFG_CMPCR.SW_CTRL = 1 */
|
||||
HAL_SYSCFG_CompensationCodeSelect(SYSCFG_REGISTER_CODE);
|
||||
|
||||
/* Disable the Compensation Cell */
|
||||
HAL_DisableCompensationCell();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable IO compensation mechanism
|
||||
* By default the I/O compensation cell is not used. However when the
|
||||
* I/O output buffer speed is configured in 50 MHz mode and above, it
|
||||
* is recommended to use the compensation cell for a slew rate control
|
||||
* on I/O tf(IO)out/tr(IO)out commutation to reduce the I/O noise on
|
||||
* the power supply.
|
||||
* @note Use polling mode for timeout as code could be used on critical
|
||||
* section (IRQs disabled)
|
||||
* @retval HAL_StatusTypeDef value
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SYSCFG_EnableIOCompensation(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint32_t count = SYSCFG_DEFAULT_TIMEOUT * (SystemCoreClock / 20U / 1000U);
|
||||
|
||||
/* Set SYSCFG_CMPENSETR.MCU_EN */
|
||||
HAL_EnableCompensationCell();
|
||||
|
||||
/* Wait SYSCFG_CMPCR.READY = 1 */
|
||||
do
|
||||
{
|
||||
if (count-- == 0U)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
while (__HAL_SYSCFG_CMP_CELL_GET_FLAG() == 0U);
|
||||
|
||||
/* Set SYSCFG_CMPCR.SW_CTRL = 0 */
|
||||
HAL_SYSCFG_CompensationCodeSelect(SYSCFG_CELL_CODE);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -0,0 +1,438 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_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 de-initialization functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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-M exceptions are managed by CMSIS functions.
|
||||
|
||||
(#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping()
|
||||
function according to the following table.
|
||||
(#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority().
|
||||
(#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ().
|
||||
(#) please refer to programming manual for details in how to configure priority.
|
||||
|
||||
-@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ preemption 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 preemption 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 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
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CORTEX CORTEX
|
||||
* @brief CORTEX HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides the CORTEX HAL driver functions allowing to configure Interrupts
|
||||
Systick functionalities
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the priority grouping field (preemption 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 bits for preemption priority
|
||||
* 4 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority
|
||||
* 3 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority
|
||||
* 2 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority
|
||||
* 1 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority
|
||||
* 0 bits for subpriority
|
||||
* @note When the NVIC_PriorityGroup_0 is selected, IRQ preemption 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 Sets 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 (stm32mp1xxxx.h))
|
||||
* @param PreemptPriority: The preemption 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 = 0x00;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
|
||||
assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
|
||||
|
||||
prioritygroup = NVIC_GetPriorityGrouping();
|
||||
|
||||
NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables 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 (stm32mp1xxxx.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 Disables 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 (stm32mp1xxxx.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 Initiates a system reset request to reset the MCU.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SystemReset(void)
|
||||
{
|
||||
/* System Reset */
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer.
|
||||
* 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)
|
||||
{
|
||||
return SysTick_Config(TicksNumb);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
|
||||
* @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
|
||||
* @{
|
||||
*/
|
||||
#if (__MPU_PRESENT == 1)
|
||||
/**
|
||||
* @brief Initializes and configures the Region and the memory to be protected.
|
||||
* @param MPU_Init: Pointer to a MPU_Region_InitTypeDef structure that contains
|
||||
* the initialization and configuration information.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
|
||||
assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU->RNR = MPU_Init->Number;
|
||||
|
||||
if ((MPU_Init->Enable) != RESET)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
|
||||
assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
|
||||
assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
|
||||
assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
|
||||
assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
|
||||
assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
|
||||
assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
|
||||
assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
|
||||
|
||||
MPU->RBAR = MPU_Init->BaseAddress;
|
||||
MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) |
|
||||
((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) |
|
||||
((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) |
|
||||
((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) |
|
||||
((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) |
|
||||
((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) |
|
||||
((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) |
|
||||
((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) |
|
||||
((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
MPU->RBAR = 0x00;
|
||||
MPU->RASR = 0x00;
|
||||
}
|
||||
}
|
||||
#endif /* __MPU_PRESENT */
|
||||
|
||||
/**
|
||||
* @brief Gets 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 Gets 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 (stm32mp1xxxx.h))
|
||||
* @param PriorityGroup: the priority grouping bits length.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority
|
||||
* 4 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority
|
||||
* 3 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority
|
||||
* 2 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority
|
||||
* 1 bits for subpriority
|
||||
* @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority
|
||||
* 0 bits 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_PRIORITY_GROUP(PriorityGroup));
|
||||
/* Get priority for Cortex-M system or device specific interrupts */
|
||||
NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets 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 (stm32mp1xxxx.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 Gets Pending Interrupt (reads the pending register in the NVIC
|
||||
* and returns 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 (stm32mp1xxxx.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 Clears 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 (stm32mp1xxxx.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 Gets active interrupt ( reads the active register in NVIC and returns 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 (stm32mp1xxxx.h))
|
||||
* @retval status: - 0 Interrupt status is not pending.
|
||||
* - 1 Interrupt status is pending.
|
||||
*/
|
||||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
/* Return 1 if active else 0 */
|
||||
return NVIC_GetActive(IRQn);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function handles 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
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,601 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_hal_dma_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief DMA Extension HAL module driver
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the DMA Extension peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The DMA Extension HAL driver can be used as follows:
|
||||
(+) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function
|
||||
for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode.
|
||||
|
||||
(+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
|
||||
(+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
|
||||
Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
|
||||
to respectively enable/disable the request generator.
|
||||
|
||||
(+) To handle the DMAMUX Interrupts, the function HAL_DMAEx_MUX_IRQHandler should be called from
|
||||
the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler or DMAMUX2_OVR_IRQHandler .
|
||||
As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMA_MUX_IRQHandler should be
|
||||
called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project
|
||||
(exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator)
|
||||
|
||||
-@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed.
|
||||
-@- When Multi (Double) Buffer mode is enabled, the transfer is circular by default.
|
||||
-@- In Multi (Double) buffer mode, it is possible to update the base address for
|
||||
the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled.
|
||||
-@- Multi (Double) buffer mode is only possible with D2 DMAs i.e DMA1 or DMA2. not BDMA.
|
||||
Multi (Double) buffer mode is not possible with D3 BDMA.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DMAEx DMAEx
|
||||
* @brief DMA Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private Constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/** @addtogroup DMAEx_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions ---------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup DMAEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup DMAEx_Exported_Functions_Group1
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended features functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure the source, destination address and data length and
|
||||
Start MultiBuffer DMA transfer
|
||||
(+) Configure the source, destination address and data length and
|
||||
Start MultiBuffer DMA transfer with interrupt
|
||||
(+) Change on the fly the memory0 or memory1 address.
|
||||
(+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
|
||||
(+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
|
||||
(+) Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
|
||||
to respectively enable/disable the request generator.
|
||||
(+) Handle DMAMUX interrupts using HAL_DMAEx_MUX_IRQHandler : should be called from
|
||||
the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler or DMAMUX2_OVR_IRQHandler
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Starts the multi_buffer DMA Transfer.
|
||||
* @param hdma : pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param SrcAddress: The source memory Buffer address
|
||||
* @param DstAddress: The destination memory Buffer address
|
||||
* @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint32_t *ifcRegister_Base; /* DMA Stream Interrupt Clear register */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
/* Memory-to-memory transfer not supported in double buffering mode */
|
||||
if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
|
||||
{
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if (HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
/* Change DMA peripheral state */
|
||||
hdma->State = HAL_DMA_STATE_BUSY;
|
||||
|
||||
/* Initialize the error code */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||
|
||||
/* Enable the Double buffer mode */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->CR |= (uint32_t)DMA_SxCR_DBM;
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
|
||||
|
||||
/* Configure the source, destination address and the data length */
|
||||
DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
|
||||
|
||||
/* Calculate the interrupt clear flag register (IFCR) base address */
|
||||
ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
|
||||
|
||||
/* Clear all flags */
|
||||
*ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);
|
||||
|
||||
/* Clear the DMAMUX synchro overrun flag */
|
||||
hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
|
||||
|
||||
if(hdma->DMAmuxRequestGen != 0U)
|
||||
{
|
||||
/* Clear the DMAMUX request generator overrun flag */
|
||||
hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
|
||||
}
|
||||
|
||||
/* Enable the peripheral */
|
||||
__HAL_DMA_ENABLE(hdma);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts the multi_buffer DMA Transfer with interrupt enabled.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param SrcAddress: The source memory Buffer address
|
||||
* @param DstAddress: The destination memory Buffer address
|
||||
* @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint32_t *ifcRegister_Base; /* DMA Stream Interrupt Clear register */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
/* Memory-to-memory transfer not supported in double buffering mode */
|
||||
if(hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
|
||||
{
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if (HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
/* Change DMA peripheral state */
|
||||
hdma->State = HAL_DMA_STATE_BUSY;
|
||||
|
||||
/* Initialize the error code */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||
|
||||
/* Enable the Double buffer mode */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->CR |= (uint32_t)DMA_SxCR_DBM;
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
|
||||
|
||||
/* Configure the source, destination address and the data length */
|
||||
DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
|
||||
|
||||
/* Calculate the interrupt clear flag register (IFCR) base address */
|
||||
ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
|
||||
|
||||
/* Clear all flags */
|
||||
*ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);
|
||||
|
||||
/* Clear the DMAMUX synchro overrun flag */
|
||||
hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
|
||||
|
||||
if(hdma->DMAmuxRequestGen != 0U)
|
||||
{
|
||||
/* Clear the DMAMUX request generator overrun flag */
|
||||
hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
|
||||
}
|
||||
|
||||
/* Enable Common interrupts*/
|
||||
MODIFY_REG(((DMA_Stream_TypeDef *)hdma->Instance)->CR, (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT), (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME));
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->FCR |= DMA_IT_FE;
|
||||
|
||||
if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
|
||||
{
|
||||
/*Enable Half Transfer IT if corresponding Callback is set*/
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_IT_HT;
|
||||
}
|
||||
|
||||
/* Check if DMAMUX Synchronization is enabled*/
|
||||
if ((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)
|
||||
{
|
||||
/* Enable DMAMUX sync overrun IT*/
|
||||
hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;
|
||||
}
|
||||
|
||||
if(hdma->DMAmuxRequestGen != 0U)
|
||||
{
|
||||
/* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/
|
||||
/* enable the request gen overrun IT*/
|
||||
hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;
|
||||
}
|
||||
|
||||
/* Enable the peripheral */
|
||||
__HAL_DMA_ENABLE(hdma);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Change the memory0 or memory1 address on the fly.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param Address: The new address
|
||||
* @param memory: the memory to be changed, This parameter can be one of
|
||||
* the following values:
|
||||
* MEMORY0 /
|
||||
* MEMORY1
|
||||
* @note The MEMORY0 address can be changed only when the current transfer use
|
||||
* MEMORY1 and the MEMORY1 address can be changed only when the current
|
||||
* transfer use MEMORY0.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
|
||||
{
|
||||
if (memory == MEMORY0)
|
||||
{
|
||||
/* change the memory0 address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = Address;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* change the memory1 address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = Address;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the DMAMUX synchronization parameters for a given DMA stream (instance).
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
|
||||
{
|
||||
uint32_t syncSignalID = 0;
|
||||
uint32_t syncPolarity = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
|
||||
assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
|
||||
assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
|
||||
|
||||
if (pSyncConfig->SyncEnable == ENABLE)
|
||||
{
|
||||
assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig->SyncPolarity));
|
||||
assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
|
||||
syncSignalID = pSyncConfig->SyncSignalID;
|
||||
syncPolarity = pSyncConfig->SyncPolarity;
|
||||
}
|
||||
|
||||
/*Check if the DMA state is ready */
|
||||
if (hdma->State == HAL_DMA_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
/* Disable the synchronization and event generation before applying a new config */
|
||||
CLEAR_BIT(hdma->DMAmuxChannel->CCR, (DMAMUX_CxCR_SE | DMAMUX_CxCR_EGE));
|
||||
|
||||
/* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
|
||||
MODIFY_REG(hdma->DMAmuxChannel->CCR, \
|
||||
(~DMAMUX_CxCR_DMAREQ_ID), \
|
||||
(syncSignalID << DMAMUX_CxCR_SYNC_ID_Pos) | \
|
||||
((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
|
||||
syncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
|
||||
((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* Return error status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the DMAMUX request generator block used by the given DMA stream (instance).
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
|
||||
* contains the request generator parameters.
|
||||
*
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator(DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
HAL_DMA_StateTypeDef temp_state = hdma->State;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
|
||||
|
||||
assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
|
||||
assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
|
||||
|
||||
/* check if the DMA state is ready
|
||||
and DMA is using a DMAMUX request generator block
|
||||
*/
|
||||
if(hdma->DMAmuxRequestGen == 0U)
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_PARAM;
|
||||
|
||||
/* error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else if(((hdma->DMAmuxRequestGen->RGCR & DMAMUX_RGxCR_GE) == 0U) && (temp_state == HAL_DMA_STATE_READY))
|
||||
{
|
||||
/* RequestGenerator must be disable prior to the configuration i.e GE bit is 0 */
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
/* Set the request generator new parameters*/
|
||||
hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
|
||||
((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \
|
||||
pRequestGeneratorConfig->Polarity;
|
||||
/* Process Locked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the DMAMUX request generator block used by the given DMA stream (instance).
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
/* check if the DMA state is ready
|
||||
and DMA is using a DMAMUX request generator block */
|
||||
if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))
|
||||
{
|
||||
|
||||
/* Enable the request generator*/
|
||||
hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the DMAMUX request generator block used by the given DMA stream (instance).
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
/* check if the DMA state is ready
|
||||
and DMA is using a DMAMUX request generator block */
|
||||
if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))
|
||||
{
|
||||
|
||||
/* Disable the request generator*/
|
||||
hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handles DMAMUX interrupt request.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
/* Check for DMAMUX Synchronization overrun */
|
||||
if ((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
|
||||
{
|
||||
/* Disable the synchro overrun interrupt */
|
||||
hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
|
||||
|
||||
/* Clear the DMAMUX synchro overrun flag */
|
||||
hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
|
||||
|
||||
/* Update error code */
|
||||
hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
|
||||
|
||||
if (hdma->XferErrorCallback != NULL)
|
||||
{
|
||||
/* Transfer error callback */
|
||||
hdma->XferErrorCallback(hdma);
|
||||
}
|
||||
}
|
||||
|
||||
if(hdma->DMAmuxRequestGen != 0)
|
||||
{
|
||||
/* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */
|
||||
if ((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
|
||||
{
|
||||
/* Disable the request gen overrun interrupt */
|
||||
hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
|
||||
|
||||
/* Clear the DMAMUX request generator overrun flag */
|
||||
hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
|
||||
|
||||
/* Update error code */
|
||||
hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
|
||||
|
||||
if (hdma->XferErrorCallback != NULL)
|
||||
{
|
||||
/* Transfer error callback */
|
||||
hdma->XferErrorCallback(hdma);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup DMAEx_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set the DMA Transfer parameter.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param SrcAddress: The source memory Buffer address
|
||||
* @param DstAddress: The destination memory Buffer address
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
||||
{
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
/* Configure DMA Stream data length */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->NDTR = DataLength;
|
||||
|
||||
/* Peripheral to Memory */
|
||||
if ((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
|
||||
{
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->PAR = DstAddress;
|
||||
|
||||
/* Configure DMA Stream source address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = SrcAddress;
|
||||
}
|
||||
/* Memory to Peripheral */
|
||||
else
|
||||
{
|
||||
/* Configure DMA Stream source address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->PAR = SrcAddress;
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = DstAddress;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -0,0 +1,724 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_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) 2019 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 throught multiplexer.
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
|
||||
(#) Configure the configurable EXTI line using HAL_EXTI_SetConfigLine().
|
||||
NOTE: in addition HAL_EXTI_SetInterruptAndEventMask shall be used
|
||||
to configure interrupt and events mask of this configurable line
|
||||
(++) 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 "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI
|
||||
* @{
|
||||
*/
|
||||
/** MISRA C:2012 deviation rule has been granted for following rule:
|
||||
* Rule-18.1_b - Medium: Array `EXTICR' 1st subscript interval [0,7] may be out
|
||||
* of bounds [0,3] in following API :
|
||||
* HAL_EXTI_SetConfigLine
|
||||
* HAL_EXTI_GetConfigLine
|
||||
* HAL_EXTI_ClearConfigLine
|
||||
*/
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines ------------------------------------------------------------*/
|
||||
/** @defgroup EXTI_Private_Constants EXTI Private Constants
|
||||
* @{
|
||||
*/
|
||||
#define EXTI_MODE_C1 0x10u
|
||||
#define EXTI_MODE_C2 0x20u
|
||||
#define EXTI_MODE_INTERRUPT 0x01u
|
||||
#define EXTI_MODE_EVENT 0x02u
|
||||
#define EXTI_MODE_OFFSET 0x04u /* 0x10: offset between CPU IMR/EMR registers */
|
||||
#define EXTI_CONFIG_OFFSET 0x08u /* 0x20: offset between CPU Rising/Falling configuration 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 except Interrupt and Event mask of a dedicated Exti line.
|
||||
* It is relevant only for configurable events.
|
||||
* @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 parameters */
|
||||
assert_param(IS_EXTI_LINE(pExtiConfig->Line));
|
||||
|
||||
/* 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) != 0x0u)
|
||||
{
|
||||
assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
|
||||
|
||||
/* Configure rising trigger */
|
||||
regaddr = (&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x0u)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store rising trigger mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* Configure falling trigger */
|
||||
regaddr = (&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x0u)
|
||||
{
|
||||
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];
|
||||
regval &= ~(EXTI_EXTICR1_EXTI0 << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
|
||||
regval |= (pExtiConfig->GPIOSel << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
|
||||
EXTI->EXTICR[linepos >> 2u] = regval;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*Set Interrupt And Event Mask for Core 1 if configuration for Core 1 given into parameter mode */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_C1) != 0x0u)
|
||||
{
|
||||
regaddr = (&EXTI->C1IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x0u)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store interrupt mode */
|
||||
*regaddr = regval;
|
||||
}
|
||||
|
||||
/*Set Interrupt And Event Mask for Core 2 if configuration for Core 2 given into parameter mode */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_C2) != 0x0u)
|
||||
{
|
||||
regaddr = (&EXTI->C2IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x0u)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store interrupt mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* The event mode cannot be configured if the line does not support it */
|
||||
assert_param(((pExtiConfig->Line & EXTI_EVENT) == EXTI_EVENT) || ((pExtiConfig->Mode & EXTI_MODE_EVENT) != EXTI_MODE_EVENT));
|
||||
|
||||
regaddr = (&EXTI->C2EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0x0u)
|
||||
{
|
||||
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(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 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 1 mode : interrupt */
|
||||
regaddr = (&EXTI->C1IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0x0u)
|
||||
{
|
||||
pExtiConfig->Mode = EXTI_MODE_C1_INTERRUPT;
|
||||
}
|
||||
else
|
||||
{
|
||||
pExtiConfig->Mode = EXTI_MODE_C1_NONE;
|
||||
}
|
||||
|
||||
/* Get core 2 mode : interrupt */
|
||||
regaddr = (&EXTI->C2IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0x0u)
|
||||
{
|
||||
pExtiConfig->Mode |= EXTI_MODE_C2_INTERRUPT;
|
||||
}
|
||||
else
|
||||
{
|
||||
pExtiConfig->Mode |= EXTI_MODE_C2_NONE;
|
||||
}
|
||||
|
||||
/* Get Core 2 mode : event */
|
||||
regaddr = (&EXTI->C2EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0x0u)
|
||||
{
|
||||
pExtiConfig->Mode |= EXTI_MODE_C2_EVENT;
|
||||
}
|
||||
|
||||
/* Get default Trigger and GPIOSel configuration */
|
||||
pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
|
||||
pExtiConfig->GPIOSel = 0x0u;
|
||||
|
||||
/* 2] Get trigger for configurable lines : rising */
|
||||
if ((pExtiConfig->Line & EXTI_CONFIG) != 0x0u)
|
||||
{
|
||||
regaddr = (&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if configuration of selected line is enable */
|
||||
if ((regval & maskline) != 0x0u)
|
||||
{
|
||||
pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
|
||||
}
|
||||
|
||||
/* Get falling configuration */
|
||||
regaddr = (&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if configuration of selected line is enable */
|
||||
if ((regval & maskline) != 0x0u)
|
||||
{
|
||||
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];
|
||||
pExtiConfig->GPIOSel = ((regval << (EXTI_EXTICR1_EXTI1_Pos * (3uL - (linepos & 0x03u)))) >> 24);
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear whole configuration of a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(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 = (&EXTI->C1IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
regaddr = (&EXTI->C2IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* 2] Clear event mode */
|
||||
regaddr = (&EXTI->C2EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* 3] Clear triggers in case of configurable lines */
|
||||
if ((hexti->Line & EXTI_CONFIG) != 0x0u)
|
||||
{
|
||||
regaddr = (&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
regaddr = (&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];
|
||||
regval &= ~(EXTI_EXTICR1_EXTI0 << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
|
||||
EXTI->EXTICR[linepos >> 2u] = 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(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 = (&EXTI->RPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & maskline);
|
||||
|
||||
if (regval != 0x0u)
|
||||
{
|
||||
/* Clear pending bit */
|
||||
*regaddr = maskline;
|
||||
|
||||
/* Call rising callback */
|
||||
if (hexti->RisingCallback != NULL)
|
||||
{
|
||||
hexti->RisingCallback();
|
||||
}
|
||||
}
|
||||
|
||||
/* Get falling edge pending bit */
|
||||
regaddr = (&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & maskline);
|
||||
|
||||
if (regval != 0x0u)
|
||||
{
|
||||
/* 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(EXTI_HandleTypeDef *hexti, uint32_t Edge)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check 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 = (&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get rising edge pending bit */
|
||||
regaddr = (&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(EXTI_HandleTypeDef *hexti, uint32_t Edge)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check 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 = (&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get falling edge pending register address */
|
||||
regaddr = (&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(EXTI_HandleTypeDef *hexti)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check 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 = (&EXTI->SWIER1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
*regaddr = maskline;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -0,0 +1,563 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_hal_gpio.c
|
||||
* @author MCD 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) 2019 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 #####
|
||||
==============================================================================
|
||||
[..]
|
||||
Subject to the specific hardware characteristics of each I/O port listed in the datasheet, each
|
||||
port bit of the General Purpose IO (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 input floating 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.
|
||||
|
||||
[..]
|
||||
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 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 input floating 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 "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup GPIO GPIO
|
||||
* @brief GPIO HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines ------------------------------------------------------------*/
|
||||
/** @addtogroup GPIO_Private_Constants GPIO Private Constants
|
||||
* @{
|
||||
*/
|
||||
#define GPIO_MODE ((uint32_t)0x00000003)
|
||||
#define EXTI_MODE ((uint32_t)0x10000000)
|
||||
#define GPIO_MODE_IT ((uint32_t)0x00010000)
|
||||
#define GPIO_MODE_EVT ((uint32_t)0x00020000)
|
||||
#define RISING_EDGE ((uint32_t)0x00100000)
|
||||
#define FALLING_EDGE ((uint32_t)0x00200000)
|
||||
#define GPIO_OUTPUT_TYPE ((uint32_t)0x00000010)
|
||||
|
||||
#define GPIO_NUMBER ((uint32_t)16)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup GPIO_Exported_Functions GPIO Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup GPIO_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to initialize and de-initialize the GPIOs
|
||||
to be ready for use.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init.
|
||||
* @param GPIOx: where x can be (A..K) to select the GPIO peripheral.
|
||||
* @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, GPIO_InitTypeDef *GPIO_Init)
|
||||
{
|
||||
uint32_t position;
|
||||
uint32_t ioposition;
|
||||
uint32_t iocurrent;
|
||||
uint32_t temp;
|
||||
EXTI_Core_TypeDef * EXTI_CurrentCPU;
|
||||
|
||||
#if defined(CORE_CM4)
|
||||
EXTI_CurrentCPU = EXTI_C2; /* EXTI for CM4 CPU */
|
||||
#else
|
||||
EXTI_CurrentCPU = EXTI_C1; /* EXTI for CA7 CPU */
|
||||
#endif
|
||||
|
||||
/* 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));
|
||||
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
|
||||
|
||||
/* Configure the port pins */
|
||||
for(position = 0; position < GPIO_NUMBER; position++)
|
||||
{
|
||||
/* Get the IO position */
|
||||
ioposition = ((uint32_t)0x01) << position;
|
||||
/* Get the current IO position */
|
||||
iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
|
||||
|
||||
if(iocurrent == ioposition)
|
||||
{
|
||||
/*--------------------- GPIO Mode Configuration ------------------------*/
|
||||
/* In case of Alternate function mode selection */
|
||||
if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
|
||||
{
|
||||
/* Check the Alternate function parameter */
|
||||
assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
|
||||
|
||||
/* Configure Alternate function mapped with the current IO */
|
||||
temp = GPIOx->AFR[position >> 3];
|
||||
temp &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
|
||||
temp |= ((uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & (uint32_t)0x07) * 4));
|
||||
GPIOx->AFR[position >> 3] = temp;
|
||||
}
|
||||
|
||||
/* Configure IO Direction mode (Input, Output, Alternate or Analog) */
|
||||
temp = GPIOx->MODER;
|
||||
temp &= ~(GPIO_MODER_MODER0 << (position * 2));
|
||||
temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2));
|
||||
GPIOx->MODER = temp;
|
||||
|
||||
/* In case of Output or Alternate function mode selection */
|
||||
if((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) ||
|
||||
(GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
|
||||
{
|
||||
/* Check the Speed parameter */
|
||||
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
|
||||
/* Configure the IO Speed */
|
||||
temp = GPIOx->OSPEEDR;
|
||||
temp &= ~(GPIO_OSPEEDR_OSPEEDR0 << (position * 2));
|
||||
temp |= (GPIO_Init->Speed << (position * 2));
|
||||
GPIOx->OSPEEDR = temp;
|
||||
|
||||
/* Configure the IO Output Type */
|
||||
temp = GPIOx->OTYPER;
|
||||
temp &= ~(GPIO_OTYPER_OT0 << position) ;
|
||||
temp |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position);
|
||||
GPIOx->OTYPER = temp;
|
||||
}
|
||||
|
||||
/* Activate the Pull-up or Pull down resistor for the current IO */
|
||||
temp = GPIOx->PUPDR;
|
||||
temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
|
||||
temp |= ((GPIO_Init->Pull) << (position * 2));
|
||||
GPIOx->PUPDR = temp;
|
||||
|
||||
/*--------------------- EXTI Mode Configuration ------------------------*/
|
||||
/* Configure the External Interrupt or event for the current IO */
|
||||
if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
|
||||
{
|
||||
temp = EXTI->EXTICR[position >> 2U];
|
||||
temp &= ~(0xFFU << (8U * (position & 0x03U)));
|
||||
temp |= (GPIO_GET_INDEX(GPIOx) << (8U * (position & 0x03U)));
|
||||
EXTI->EXTICR[position >> 2U] = temp;
|
||||
|
||||
/* Clear EXTI line configuration */
|
||||
temp = EXTI_CurrentCPU->IMR1;
|
||||
temp &= ~((uint32_t)iocurrent);
|
||||
if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI_CurrentCPU->IMR1 = temp;
|
||||
|
||||
temp = EXTI_CurrentCPU->EMR1;
|
||||
temp &= ~((uint32_t)iocurrent);
|
||||
if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI_CurrentCPU->EMR1 = temp;
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
temp = EXTI->RTSR1;
|
||||
temp &= ~((uint32_t)iocurrent);
|
||||
if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->RTSR1 = temp;
|
||||
|
||||
temp = EXTI->FTSR1;
|
||||
temp &= ~((uint32_t)iocurrent);
|
||||
if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->FTSR1 = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-initializes the GPIOx peripheral registers to their default reset values.
|
||||
* @param GPIOx: where x can be (A..Z) to select the GPIO peripheral.
|
||||
* @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).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
||||
{
|
||||
uint32_t position;
|
||||
uint32_t ioposition;
|
||||
uint32_t iocurrent;
|
||||
uint32_t tmp;
|
||||
EXTI_Core_TypeDef * EXTI_CurrentCPU;
|
||||
|
||||
#if defined(CORE_CM4)
|
||||
EXTI_CurrentCPU = EXTI_C2; /* EXTI for CM4 CPU */
|
||||
#else
|
||||
EXTI_CurrentCPU = EXTI_C1; /* EXTI for CA7 CPU */
|
||||
#endif
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
|
||||
/* Configure the port pins */
|
||||
for(position = 0; position < GPIO_NUMBER; position++)
|
||||
{
|
||||
/* Get the IO position */
|
||||
ioposition = ((uint32_t)0x01) << position;
|
||||
/* Get the current IO position */
|
||||
iocurrent = (GPIO_Pin) & ioposition;
|
||||
|
||||
if(iocurrent == ioposition)
|
||||
{
|
||||
/*------------------------- EXTI Mode Configuration --------------------*/
|
||||
tmp = EXTI->EXTICR[position >> 2];
|
||||
tmp &= (((uint32_t)0xFF) << (8 * (position & 0x03)));
|
||||
if(tmp == ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (8 * (position & 0x03))))
|
||||
{
|
||||
/* Clear EXTI line configuration for Current CPU */
|
||||
EXTI_CurrentCPU->IMR1 &= ~((uint32_t)iocurrent);
|
||||
EXTI_CurrentCPU->EMR1 &= ~((uint32_t)iocurrent);
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
EXTI->RTSR1 &= ~((uint32_t)iocurrent);
|
||||
EXTI->FTSR1 &= ~((uint32_t)iocurrent);
|
||||
|
||||
/* Configure the External Interrupt or event for the current IO */
|
||||
tmp = ((uint32_t)0xFF) << (8 * (position & 0x03));
|
||||
EXTI->EXTICR[position >> 2] &= ~tmp;
|
||||
}
|
||||
|
||||
/*------------------------- GPIO Mode Configuration --------------------*/
|
||||
/* Configure IO in Analog Mode */
|
||||
GPIOx->MODER |= (GPIO_MODER_MODER0 << (position * 2));
|
||||
|
||||
/* Configure the default Alternate Function in current IO */
|
||||
GPIOx->AFR[position >> 3] &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
|
||||
|
||||
/* Configure the default value for IO Speed */
|
||||
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEEDR0 << (position * 2));
|
||||
|
||||
/* 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_PUPDR0 << (position * 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup GPIO_Exported_Functions_Group2 IO operation functions
|
||||
* @brief GPIO Read, Write, Toggle, Lock and EXTI management functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Reads the specified input port pin.
|
||||
* @param GPIOx: where x can be (A..K) to select the GPIO peripheral.
|
||||
* @param GPIO_Pin: specifies the port bit to read.
|
||||
* This parameter can be GPIO_PIN_x where x can be (0..15).
|
||||
* @retval The input port pin value.
|
||||
*/
|
||||
GPIO_PinState HAL_GPIO_ReadPin(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) != (uint32_t)GPIO_PIN_RESET)
|
||||
{
|
||||
bitstatus = GPIO_PIN_SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = GPIO_PIN_RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets or clears the selected data port bit.
|
||||
*
|
||||
* @note This function uses GPIOx_BSRR register 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..K) to select the GPIO peripheral.
|
||||
* @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 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 = GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BSRR = (uint32_t)GPIO_Pin << GPIO_NUMBER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the specified GPIO pins.
|
||||
* @param GPIOx: Where x can be (A..K) to select the GPIO peripheral.
|
||||
* @param GPIO_Pin: Specifies the pins to be toggled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
if ((GPIOx->ODR & GPIO_Pin) != 0x00u)
|
||||
{
|
||||
GPIOx->BRR = (uint32_t)GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BSRR = (uint32_t)GPIO_Pin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Locks 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..K) to select the GPIO peripheral
|
||||
* @param GPIO_Pin: specifies the port bit to be locked.
|
||||
* This parameter can be any combination of GPIO_PIN_x where x can be (0..15).
|
||||
* @retval None
|
||||
*/
|
||||
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) != RESET)
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) != RESET)
|
||||
{
|
||||
__HAL_GPIO_EXTI_CLEAR_RISING_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_Rising_Callback(GPIO_Pin);
|
||||
}
|
||||
|
||||
if (__HAL_GPIO_EXTI_GET_FALLING_IT(GPIO_Pin) != RESET)
|
||||
{
|
||||
__HAL_GPIO_EXTI_CLEAR_FALLING_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_Falling_Callback(GPIO_Pin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief EXTI line 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 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
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -0,0 +1,435 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_hal_hsem.c
|
||||
* @author MCD Application Team
|
||||
* @brief HSEM HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the semaphore peripheral:
|
||||
* + Semaphore Take function (2-Step Procedure) , non blocking
|
||||
* + Semaphore FastTake function (1-Step Procedure) , non blocking
|
||||
* + Semaphore Status check
|
||||
* + Semaphore Clear Key Set and Get
|
||||
* + Release and release all functions
|
||||
* + Semaphore notification enabling and disabling and callnack functions
|
||||
* + IRQ handler management
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#)Take a semaphore In 2-Step mode Using function HAL_HSEM_Take. This function takes as parameters :
|
||||
(++) the semaphore ID from 0 to 31
|
||||
(++) the process ID from 0 to 255
|
||||
(#) Fast Take semaphore In 1-Step mode Using function HAL_HSEM_FastTake. This function takes as parameter :
|
||||
(++) the semaphore ID from 0_ID to 31. Note that the process ID value is implicitly assumed as zero
|
||||
(#) Check if a semaphore is Taken using function HAL_HSEM_IsSemTaken. This function takes as parameter :
|
||||
(++) the semaphore ID from 0_ID to 31
|
||||
(++) It returns 1 if the given semaphore is taken otherwise (Free) zero
|
||||
(#)Release a semaphore using function with HAL_HSEM_Release. This function takes as parameters :
|
||||
(++) the semaphore ID from 0 to 31
|
||||
(++) the process ID from 0 to 255:
|
||||
(++) Note: If ProcessID and MasterID match, semaphore is freed, and an interrupt
|
||||
may be generated when enabled (notification activated). If ProcessID or MasterID does not match,
|
||||
semaphore remains taken (locked)
|
||||
|
||||
(#)Release all semaphores at once taken by a given Master using function HAL_HSEM_Release_All
|
||||
This function takes as parameters :
|
||||
(++) the Release Key (value from 0 to 0xFFFF) can be Set or Get respectively by
|
||||
HAL_HSEM_SetClearKey() or HAL_HSEM_GetClearKey functions
|
||||
(++) the Master ID:
|
||||
(++) Note: If the Key and MasterID match, all semaphores taken by the given CPU that corresponds
|
||||
to MasterID will be freed, and an interrupt may be generated when enabled (notification activated). If the
|
||||
Key or the MasterID doesn't match, semaphores remains taken (locked)
|
||||
|
||||
(#)Semaphores Release all key functions:
|
||||
(++) HAL_HSEM_SetClearKey() to set semaphore release all Key
|
||||
(++) HAL_HSEM_GetClearKey() to get release all Key
|
||||
(#)Semaphores notification functions :
|
||||
(++) HAL_HSEM_ActivateNotification to activate a notification callback on
|
||||
a given semaphores Mask (bitfield). When one or more semaphores defined by the mask are released
|
||||
the callback HAL_HSEM_FreeCallback will be asserted giving as parameters a mask of the released
|
||||
semaphores (bitfield).
|
||||
|
||||
(++) HAL_HSEM_DeactivateNotification to deactivate the notification of a given semaphores Mask (bitfield).
|
||||
(++) See the description of the macro __HAL_HSEM_SEMID_TO_MASK to check how to calculate a semaphore mask
|
||||
Used by the notification functions
|
||||
*** HSEM HAL driver macros list ***
|
||||
=============================================
|
||||
[..] Below the list of most used macros in HSEM HAL driver.
|
||||
|
||||
(+) __HAL_HSEM_SEMID_TO_MASK: Helper macro to convert a Semaphore ID to a Mask.
|
||||
[..] Example of use :
|
||||
[..] mask = __HAL_HSEM_SEMID_TO_MASK(8) | __HAL_HSEM_SEMID_TO_MASK(21) | __HAL_HSEM_SEMID_TO_MASK(25).
|
||||
[..] All next macros take as parameter a semaphore Mask (bitfiled) that can be constructed using __HAL_HSEM_SEMID_TO_MASK as the above example.
|
||||
(+) __HAL_HSEM_ENABLE_IT: Enable the specified semaphores Mask interrupts.
|
||||
(+) __HAL_HSEM_DISABLE_IT: Disable the specified semaphores Mask interrupts.
|
||||
(+) __HAL_HSEM_GET_IT: Checks whether the specified semaphore interrupt has occurred or not.
|
||||
(+) __HAL_HSEM_GET_FLAG: Get the semaphores status release flags.
|
||||
(+) __HAL_HSEM_CLEAR_FLAG: Clear the semaphores status release flags.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM HSEM
|
||||
* @brief HSEM HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_HSEM_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#if defined(DUAL_CORE)
|
||||
#ifndef HSEM_R_MASTERID
|
||||
#define HSEM_R_MASTERID HSEM_R_COREID
|
||||
#endif
|
||||
|
||||
#ifndef HSEM_RLR_MASTERID
|
||||
#define HSEM_RLR_MASTERID HSEM_RLR_COREID
|
||||
#endif
|
||||
|
||||
#ifndef HSEM_CR_MASTERID
|
||||
#define HSEM_CR_MASTERID HSEM_CR_COREID
|
||||
#endif
|
||||
#endif /* DUAL_CORE */
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions HSEM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions_Group1 Take and Release functions
|
||||
* @brief HSEM Take and Release functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### HSEM Take and Release functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Take a semaphore with 2 Step method
|
||||
(+) Fast Take a semaphore with 1 Step method
|
||||
(+) Check semaphore state Taken or not
|
||||
(+) Release a semaphore
|
||||
(+) Release all semaphore at once
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Take a semaphore in 2 Step mode.
|
||||
* @param SemID: semaphore ID from 0 to 31
|
||||
* @param ProcessID: Process ID from 0 to 255
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_HSEM_SEMID(SemID));
|
||||
assert_param(IS_HSEM_PROCESSID(ProcessID));
|
||||
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/* First step write R register with MasterID, processID and take bit=1*/
|
||||
HSEM->R[SemID] = ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK);
|
||||
|
||||
/* second step : read the R register . Take achieved if MasterID and processID match and take bit set to 1 */
|
||||
if (HSEM->R[SemID] == ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK))
|
||||
{
|
||||
/*take success when MasterID and ProcessID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#else
|
||||
/* First step write R register with MasterID, processID and take bit=1*/
|
||||
HSEM->R[SemID] = (ProcessID | HSEM_CR_COREID_CURRENT | HSEM_R_LOCK);
|
||||
|
||||
/* second step : read the R register . Take achieved if MasterID and processID match and take bit set to 1 */
|
||||
if (HSEM->R[SemID] == (ProcessID | HSEM_CR_COREID_CURRENT | HSEM_R_LOCK))
|
||||
{
|
||||
/*take success when MasterID and ProcessID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Semaphore take fails*/
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fast Take a semaphore with 1 Step mode.
|
||||
* @param SemID: semaphore ID from 0 to 31
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HSEM_FastTake(uint32_t SemID)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_HSEM_SEMID(SemID));
|
||||
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/* Read the RLR register to take the semaphore */
|
||||
if (HSEM->RLR[SemID] == (((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_RLR_MASTERID) | HSEM_RLR_LOCK))
|
||||
{
|
||||
/*take success when MasterID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#else
|
||||
/* Read the RLR register to take the semaphore */
|
||||
if (HSEM->RLR[SemID] == (HSEM_CR_COREID_CURRENT | HSEM_RLR_LOCK))
|
||||
{
|
||||
/*take success when MasterID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Semaphore take fails */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/**
|
||||
* @brief Check semaphore state Taken or not.
|
||||
* @param SemID: semaphore ID
|
||||
* @retval HAL HSEM state
|
||||
*/
|
||||
uint32_t HAL_HSEM_IsSemTaken(uint32_t SemID)
|
||||
{
|
||||
return (((HSEM->R[SemID] & HSEM_R_LOCK) != 0U) ? 1UL : 0UL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Release a semaphore.
|
||||
* @param SemID: semaphore ID from 0 to 31
|
||||
* @param ProcessID: Process ID from 0 to 255
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_Release(uint32_t SemID, uint32_t ProcessID)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_HSEM_SEMID(SemID));
|
||||
assert_param(IS_HSEM_PROCESSID(ProcessID));
|
||||
|
||||
/* Clear the semaphore by writing to the R register : the MasterID , the processID and take bit = 0 */
|
||||
HSEM->R[SemID] = (ProcessID | HSEM_CR_COREID_CURRENT);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release All semaphore used by a given Master .
|
||||
* @param Key: Semaphore Key , value from 0 to 0xFFFF
|
||||
* @param CoreID: CoreID of the CPU that is using semaphores to be released
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t CoreID)
|
||||
{
|
||||
assert_param(IS_HSEM_KEY(Key));
|
||||
assert_param(IS_HSEM_COREID(CoreID));
|
||||
|
||||
HSEM->CR = ((Key << HSEM_CR_KEY_Pos) | (CoreID << HSEM_CR_COREID_Pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions_Group2 HSEM Set and Get Key functions
|
||||
* @brief HSEM Set and Get Key functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### HSEM Set and Get Key functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Set semaphore Key
|
||||
(+) Get semaphore Key
|
||||
@endverbatim
|
||||
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set semaphore Key .
|
||||
* @param Key: Semaphore Key , value from 0 to 0xFFFF
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_SetClearKey(uint32_t Key)
|
||||
{
|
||||
assert_param(IS_HSEM_KEY(Key));
|
||||
|
||||
MODIFY_REG(HSEM->KEYR, HSEM_KEYR_KEY, (Key << HSEM_KEYR_KEY_Pos));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get semaphore Key .
|
||||
* @retval Semaphore Key , value from 0 to 0xFFFF
|
||||
*/
|
||||
uint32_t HAL_HSEM_GetClearKey(void)
|
||||
{
|
||||
return (HSEM->KEYR >> HSEM_KEYR_KEY_Pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions_Group3 HSEM IRQ handler management
|
||||
* @brief HSEM Notification functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### HSEM IRQ handler management and Notification functions #####
|
||||
==============================================================================
|
||||
[..] This section provides HSEM IRQ handler and Notification function.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Activate Semaphore release Notification for a given Semaphores Mask .
|
||||
* @param SemMask: Mask of Released semaphores
|
||||
* @retval Semaphore Key
|
||||
*/
|
||||
void HAL_HSEM_ActivateNotification(uint32_t SemMask)
|
||||
{
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/*enable the semaphore mask interrupts */
|
||||
if (HAL_GetCurrentCPUID() == HSEM_CPU1_COREID)
|
||||
{
|
||||
/*Use interrupt line 0 for CPU1 Master */
|
||||
HSEM->C1IER |= SemMask;
|
||||
}
|
||||
else /* HSEM_CPU2_COREID */
|
||||
{
|
||||
/*Use interrupt line 1 for CPU2 Master*/
|
||||
HSEM->C2IER |= SemMask;
|
||||
}
|
||||
#else
|
||||
HSEM_COMMON->IER |= SemMask;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deactivate Semaphore release Notification for a given Semaphores Mask .
|
||||
* @param SemMask: Mask of Released semaphores
|
||||
* @retval Semaphore Key
|
||||
*/
|
||||
void HAL_HSEM_DeactivateNotification(uint32_t SemMask)
|
||||
{
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/*enable the semaphore mask interrupts */
|
||||
if (HAL_GetCurrentCPUID() == HSEM_CPU1_COREID)
|
||||
{
|
||||
/*Use interrupt line 0 for CPU1 Master */
|
||||
HSEM->C1IER &= ~SemMask;
|
||||
}
|
||||
else /* HSEM_CPU2_COREID */
|
||||
{
|
||||
/*Use interrupt line 1 for CPU2 Master*/
|
||||
HSEM->C2IER &= ~SemMask;
|
||||
}
|
||||
#else
|
||||
HSEM_COMMON->IER &= ~SemMask;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles HSEM interrupt request
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_IRQHandler(void)
|
||||
{
|
||||
uint32_t statusreg;
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
if (HAL_GetCurrentCPUID() == HSEM_CPU1_COREID)
|
||||
{
|
||||
/* Get the list of masked freed semaphores*/
|
||||
statusreg = HSEM->C1MISR; /*Use interrupt line 0 for CPU1 Master*/
|
||||
|
||||
/*Disable Interrupts*/
|
||||
HSEM->C1IER &= ~((uint32_t)statusreg);
|
||||
|
||||
/*Clear Flags*/
|
||||
HSEM->C1ICR = ((uint32_t)statusreg);
|
||||
}
|
||||
else /* HSEM_CPU2_COREID */
|
||||
{
|
||||
/* Get the list of masked freed semaphores*/
|
||||
statusreg = HSEM->C2MISR;/*Use interrupt line 1 for CPU2 Master*/
|
||||
|
||||
/*Disable Interrupts*/
|
||||
HSEM->C2IER &= ~((uint32_t)statusreg);
|
||||
|
||||
/*Clear Flags*/
|
||||
HSEM->C2ICR = ((uint32_t)statusreg);
|
||||
}
|
||||
#else
|
||||
/* Get the list of masked freed semaphores*/
|
||||
statusreg = HSEM_COMMON->MISR;
|
||||
|
||||
/*Disable Interrupts*/
|
||||
HSEM_COMMON->IER &= ~((uint32_t)statusreg);
|
||||
|
||||
/*Clear Flags*/
|
||||
HSEM_COMMON->ICR = ((uint32_t)statusreg);
|
||||
|
||||
#endif
|
||||
/* Call FreeCallback */
|
||||
HAL_HSEM_FreeCallback(statusreg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Semaphore Released Callback.
|
||||
* @param SemMask: Mask of Released semaphores
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_HSEM_FreeCallback(uint32_t SemMask)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(SemMask);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_HSEM_FreeCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_HSEM_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,376 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_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
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 STM32MP1xx
|
||||
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
|
||||
|
||||
##### 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_EnableFastModePlus()
|
||||
(++) HAL_I2CEx_DisableFastModePlus()
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_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 Enable the I2C fast mode plus driving capability.
|
||||
* @param ConfigFastModePlus Selects the pin.
|
||||
* This parameter can be one of the @ref I2CEx_FastModePlus values
|
||||
* @note For I2C1, fast mode plus driving capability can be enabled on all selected
|
||||
* I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
|
||||
* on each one of the following pins PB6, PB7, PB8 and PB9.
|
||||
* @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
|
||||
* can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
|
||||
* @note For all I2C2 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C2 parameter.
|
||||
* @note For all I2C3 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C3 parameter.
|
||||
* @note For all I2C4 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C4 parameter.
|
||||
* @note For all I2C5 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C5 parameter.
|
||||
* @note For all I2C6 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C6 parameter.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
|
||||
|
||||
/* Enable SYSCFG clock */
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
/* Enable fast mode plus driving capability for selected pin */
|
||||
SET_BIT(SYSCFG->PMCSETR, (uint32_t)ConfigFastModePlus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the I2C fast mode plus driving capability.
|
||||
* @param ConfigFastModePlus Selects the pin.
|
||||
* This parameter can be one of the @ref I2CEx_FastModePlus values
|
||||
* @note For I2C1, fast mode plus driving capability can be disabled on all selected
|
||||
* I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
|
||||
* on each one of the following pins PB6, PB7, PB8 and PB9.
|
||||
* @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
|
||||
* can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
|
||||
* @note For all I2C2 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C2 parameter.
|
||||
* @note For all I2C3 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C3 parameter.
|
||||
* @note For all I2C4 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C4 parameter.
|
||||
* @note For all I2C5 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C5 parameter.
|
||||
* @note For all I2C6 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C6 parameter.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
|
||||
|
||||
/* Enable SYSCFG clock */
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
/* Disable fast mode plus driving capability for selected pin */
|
||||
SET_BIT(SYSCFG->PMCCLRR, (uint32_t)ConfigFastModePlus);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,796 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_hal_pwr.c
|
||||
* @author MCD Application Team
|
||||
* @brief PWR HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Power Controller (PWR) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 "stm32mp1xx_hal.h"
|
||||
|
||||
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PWR PWR
|
||||
* @brief PWR HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @addtogroup PWR_Private_Constants PWR Private Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask
|
||||
* @{
|
||||
*/
|
||||
#define PVD_MODE_IT ((uint32_t)0x00010000U)
|
||||
#define PVD_RISING_EDGE ((uint32_t)0x00000001U)
|
||||
#define PVD_FALLING_EDGE ((uint32_t)0x00000002U)
|
||||
#define PVD_RISING_FALLING_EDGE ((uint32_t)0x00000003U)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup PWR_Private_Functions PWR Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PWR_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and de-initialization functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
After reset, the backup domain (RTC registers, RTC backup data
|
||||
registers and backup SRAM) is protected against possible unwanted
|
||||
write accesses.
|
||||
To enable access to the RTC Domain and RTC registers, proceed as follows:
|
||||
(+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess()
|
||||
function.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables access to the backup domain
|
||||
* In reset state, the RCC_BDCR, PWR_CR2, RTC, and backup registers are
|
||||
* protected against parasitic write access. DBP bit must be set to
|
||||
* enable write access to these.
|
||||
* @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
|
||||
* Backup Domain Access should be kept enabled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableBkUpAccess(void)
|
||||
{
|
||||
/* Enable access to RTC and backup registers */
|
||||
SET_BIT(PWR->CR1, PWR_CR1_DBP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables access to the backup domain (RTC registers, RTC
|
||||
* backup data registers and backup SRAM).
|
||||
* @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
|
||||
* Backup Domain Access should be kept enabled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableBkUpAccess(void)
|
||||
{
|
||||
/* Disable access to RTC and backup registers */
|
||||
CLEAR_BIT(PWR->CR1, PWR_CR1_DBP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup PWR_Group2 Peripheral Control functions
|
||||
* @brief Low Power modes configuration functions
|
||||
*
|
||||
@verbatim
|
||||
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
|
||||
*** PVD configuration ***
|
||||
=========================
|
||||
[..]
|
||||
(+) The PVD is used to monitor the VDD power supply by comparing it to a
|
||||
threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR1).
|
||||
(+) The PVD can also be used to monitor a voltage level on the PVD_IN pin.
|
||||
In this case, the voltage level on PVD_IN is compared to the internal
|
||||
VREFINT level.
|
||||
(+) A PVDO flag is available, in the PWR control status register 1
|
||||
(PWR_CSR1), to indicate whether VDD or voltage level on PVD_IN is
|
||||
higher or lower than the PVD threshold. This event is internally
|
||||
connected to the EXTI line16 and can generate an interrupt if enabled.
|
||||
This is done through __HAL_PWR_PVD_AVD_EXTI_ENABLE_IT() macro.
|
||||
(+) The PVD is stopped in Standby mode.
|
||||
|
||||
*** WakeUp pins configuration ***
|
||||
================================
|
||||
[..]
|
||||
(+) WakeUp pins are used to wake up the system from Standby mode. WKUP
|
||||
pins, if enabled, the WKUP pin pulls can be configured by WKUPPUPD
|
||||
register bits in PWR wakeup control register (PWR_WKUPCR).
|
||||
|
||||
*** Low Power modes configuration ***
|
||||
=====================================
|
||||
[..]
|
||||
Several Low-power modes are available to save power when the MPU and/or
|
||||
MCU do not need to execute code (i.e. when waiting for an external event).
|
||||
Please refer to Reference Manual for more information.
|
||||
MPU and MCU sub-system modes:
|
||||
(+) CSleep mode: MPU/MCU clocks stopped and the MPU/MCU sub-system allocated
|
||||
peripheral(s) clocks operate according to RCC PERxLPEN
|
||||
(+) CStop mode: MPU/MCU and MPU/MCU sub-system peripheral(s) clock stopped
|
||||
(+) CStandby mode: MPU and MPU sub-system peripheral(s) clock stopped and
|
||||
wakeup via reset
|
||||
System modes:
|
||||
(+) Stop mode: bus matrix clocks stalled, the oscillators can be stopped.
|
||||
VDDCORE is supplied.
|
||||
To enter into this mode:
|
||||
- Both MPU and MCU sub-systems are in CStop or CStandby.
|
||||
- At least one PDDS bit (PWR_MPUCR/PWR_MCUCR) selects Stop.
|
||||
(+) LP-Stop mode: bus matrix clocks stalled, the oscillators can be stopped.
|
||||
VDDCORE is supplied.
|
||||
To enter into this mode:
|
||||
- Both MPU and MCU sub-systems are in CStop or CStandby.
|
||||
- The LPDS bit (PWR_CR1) selects LP-Stop.
|
||||
- The LVDS bit (PWR_CR1) selects normal voltage.
|
||||
- At least one PDDS bit (PWR_MPUCR/PWR_MCUCR) selects Stop.
|
||||
(+) LPLV-Stop mode: bus matrix clocks stalled, the oscillators can be stopped.
|
||||
VDDCORE may be supplied at a lower level.
|
||||
To enter into this mode:
|
||||
- Both MPU and MCU sub-systems are in CStop or CStandby.
|
||||
- The LPDS and LVDS bits (PWR_CR1) select LPLV-Stop.
|
||||
- At least one PDDS bit (PWR_MPUCR/PWR_MCUCR) selects Stop.
|
||||
(+) Standby mode: System powered down.
|
||||
To enter into this mode:
|
||||
- MPU sub-system is in CStandby or CStop with CSTBYDIS = 1
|
||||
and MCU subsystem is in CStop.
|
||||
- All PDDS bits (PWR_MPUCR/PWR_MCUCR) select Standby.
|
||||
|
||||
*** CSleep mode ***
|
||||
==================
|
||||
[..]
|
||||
(+) Entry:
|
||||
The CSleep mode is entered by using the HAL_PWR_EnterSLEEPMode(Regulator, SLEEPEntry)
|
||||
functions with:
|
||||
(++) STOPEntry:
|
||||
(++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
|
||||
(++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
|
||||
|
||||
-@@- The Regulator parameter is not used for the STM32MP1 family
|
||||
and is kept as parameter just to maintain compatibility with the
|
||||
lower power families (STM32L). Use i.e. PWR_MAINREGULATOR_ON
|
||||
(+) Exit:
|
||||
MCU: Any peripheral interrupt acknowledged by the nested vectored interrupt
|
||||
controller (NVIC) if entered by WFI or any event if entered by WFE
|
||||
MPU: Any Interrupt enabled in GIC if entered by WFI or any event if
|
||||
entered by WFE
|
||||
|
||||
|
||||
*** CStop mode ***
|
||||
=================
|
||||
[..]
|
||||
(+) Entry:
|
||||
The CStop mode is entered using the HAL_PWR_EnterSTOP(ModeRegulator, STOPEntry)
|
||||
function with:
|
||||
(++) Regulator:
|
||||
(+++) PWR_MAINREGULATOR_ON: Main regulator ON.
|
||||
(+++) PWR_LOWPOWERREGULATOR_ON: Low Power regulator ON.
|
||||
(++) STOPEntry:
|
||||
(+++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction
|
||||
(+++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction
|
||||
(+) Exit:
|
||||
MCU: Any EXTI Line (Internal or External) configured in Interrupt/Event mode
|
||||
depending of entry mode.
|
||||
MPU: Any EXTI Line (Internal or External) configured in Interrupt mode
|
||||
|
||||
*** MPU CStandby mode / MCU CStop allowing Standby mode ***
|
||||
====================
|
||||
[..]
|
||||
(+)
|
||||
The Standby mode allows to achieve the lowest power consumption. On Standby
|
||||
mode the voltage regulator is disabled. The PLLs, the HSI oscillator and
|
||||
the HSE oscillator are also switched off. SRAM and register contents are
|
||||
lost except for the RTC registers, RTC backup registers, backup SRAM and
|
||||
Standby circuitry.
|
||||
|
||||
(++) Entry:
|
||||
(+++) The MPU CStandby mode / MCU CStop allowing Standby mode is entered
|
||||
using the HAL_PWR_EnterSTANDBYMode() function.
|
||||
(++) Exit:
|
||||
Any EXTI Line (Internal or External) configured in Interrupt mode
|
||||
if system is not in Standby mode
|
||||
(+++) If system is in Standby mode wake up is generated by reset through:
|
||||
WKUP pins, RTC alarm (Alarm A and Alarm B), RTC wakeup, tamper
|
||||
event, time-stamp event, external reset in NRST pin, IWDG reset.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
|
||||
* @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration
|
||||
* information for the PVD.
|
||||
* @note Refer to the electrical characteristics of your device datasheet for
|
||||
* more details about the voltage threshold corresponding to each
|
||||
* detection level.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
|
||||
assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
|
||||
|
||||
/* Set PLS[7:5] bits according to PVDLevel value */
|
||||
MODIFY_REG(PWR->CR1, PWR_CR1_PLS, sConfigPVD->PVDLevel);
|
||||
|
||||
/* Clear any previous config. Keep it clear if no IT mode is selected */
|
||||
__HAL_PWR_PVD_AVD_EXTI_DISABLE_IT();
|
||||
__HAL_PWR_PVD_AVD_EXTI_DISABLE_RISING_FALLING_EDGE();
|
||||
|
||||
/* Configure interrupt mode */
|
||||
if ((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
|
||||
{
|
||||
__HAL_PWR_PVD_AVD_EXTI_ENABLE_IT();
|
||||
}
|
||||
|
||||
/* Configure the edge */
|
||||
if ((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
|
||||
{
|
||||
__HAL_PWR_PVD_AVD_EXTI_ENABLE_RISING_EDGE();
|
||||
}
|
||||
|
||||
if ((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
|
||||
{
|
||||
__HAL_PWR_PVD_AVD_EXTI_ENABLE_FALLING_EDGE();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the Power Voltage Detector(PVD).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnablePVD(void)
|
||||
{
|
||||
/* Enable the power voltage detector */
|
||||
SET_BIT(PWR->CR1, PWR_CR1_PVDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables the Power Voltage Detector(PVD).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisablePVD(void)
|
||||
{
|
||||
/* Disable the power voltage detector */
|
||||
CLEAR_BIT(PWR->CR1, PWR_CR1_PVDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the WakeUp PINx functionality.
|
||||
* @param WakeUpPinPolarity: Specifies which Wake-Up pin to enable.
|
||||
* This parameter can be one of the following legacy values, which sets the default polarity:
|
||||
* detection on high level (rising edge):
|
||||
* @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6
|
||||
* or one of the following value where the user can explicitly states the enabled pin and
|
||||
* the chosen polarity
|
||||
* @arg PWR_WAKEUP_PIN1_HIGH or PWR_WAKEUP_PIN1_LOW or
|
||||
* @arg PWR_WAKEUP_PIN2_HIGH or PWR_WAKEUP_PIN2_LOW
|
||||
* @arg PWR_WAKEUP_PIN3_HIGH or PWR_WAKEUP_PIN3_LOW
|
||||
* @arg PWR_WAKEUP_PIN4_HIGH or PWR_WAKEUP_PIN4_LOW
|
||||
* @arg PWR_WAKEUP_PIN5_HIGH or PWR_WAKEUP_PIN5_LOW
|
||||
* @arg PWR_WAKEUP_PIN6_HIGH or PWR_WAKEUP_PIN6_LOW
|
||||
* @note PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent.
|
||||
*
|
||||
* @note GPIOs are set as next when WKUP pin is enabled (Additional function)
|
||||
* WKUP1 : PA0
|
||||
* WKUP2 : PA2
|
||||
* WKUP3 : PC13
|
||||
* WKUP4 : PI8
|
||||
* WKUP5 : PI11
|
||||
* WKUP6 : PC1
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)
|
||||
{
|
||||
uint32_t clear_mask = 0;
|
||||
|
||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity));
|
||||
|
||||
if ((WakeUpPinPolarity & PWR_WAKEUP_PIN1) == PWR_WAKEUP_PIN1)
|
||||
{
|
||||
clear_mask |= (PWR_WKUPCR_WKUPP_1 | PWR_WKUPCR_WKUPPUPD1);
|
||||
}
|
||||
if ((WakeUpPinPolarity & PWR_WAKEUP_PIN2) == PWR_WAKEUP_PIN2)
|
||||
{
|
||||
clear_mask |= (PWR_WKUPCR_WKUPP_2 | PWR_WKUPCR_WKUPPUPD2);
|
||||
}
|
||||
if ((WakeUpPinPolarity & PWR_WAKEUP_PIN3) == PWR_WAKEUP_PIN3)
|
||||
{
|
||||
clear_mask |= (PWR_WKUPCR_WKUPP_3 | PWR_WKUPCR_WKUPPUPD3);
|
||||
}
|
||||
if ((WakeUpPinPolarity & PWR_WAKEUP_PIN4) == PWR_WAKEUP_PIN4)
|
||||
{
|
||||
clear_mask |= (PWR_WKUPCR_WKUPP_4 | PWR_WKUPCR_WKUPPUPD4);
|
||||
}
|
||||
if ((WakeUpPinPolarity & PWR_WAKEUP_PIN5) == PWR_WAKEUP_PIN5)
|
||||
{
|
||||
clear_mask |= (PWR_WKUPCR_WKUPP_5 | PWR_WKUPCR_WKUPPUPD5);
|
||||
}
|
||||
if ((WakeUpPinPolarity & PWR_WAKEUP_PIN6) == PWR_WAKEUP_PIN6)
|
||||
{
|
||||
clear_mask |= (PWR_WKUPCR_WKUPP_6 | PWR_WKUPCR_WKUPPUPD6);
|
||||
}
|
||||
|
||||
/* Enables and Specifies the Wake-Up pin polarity and the pull configuration
|
||||
for the event detection (rising or falling edge) */
|
||||
#ifdef CORE_CA7
|
||||
CLEAR_BIT(PWR->MPUWKUPENR, (WakeUpPinPolarity & PWR_WAKEUP_PIN_MASK)); /* Disable WKUP pin */
|
||||
MODIFY_REG(PWR->WKUPCR, clear_mask,
|
||||
(WakeUpPinPolarity & (PWR_WKUPCR_WKUPP | PWR_WKUPCR_WKUPPUPD))); /* Modify polarity and pull configuration */
|
||||
SET_BIT(PWR->WKUPCR, (WakeUpPinPolarity & PWR_WKUPCR_WKUPC)); /* Clear wake up flag */
|
||||
SET_BIT(PWR->MPUWKUPENR, (WakeUpPinPolarity & PWR_WAKEUP_PIN_MASK)); /* Enable the Wake up pin for CPU1 */
|
||||
#endif
|
||||
#ifdef CORE_CM4
|
||||
CLEAR_BIT(PWR->MCUWKUPENR, (WakeUpPinPolarity & PWR_WAKEUP_PIN_MASK)); /* Disable WKUP pin */
|
||||
MODIFY_REG(PWR->WKUPCR, clear_mask,
|
||||
(WakeUpPinPolarity & (PWR_WKUPCR_WKUPP | PWR_WKUPCR_WKUPPUPD))); /* Modify polarity and pull configuration */
|
||||
SET_BIT(PWR->WKUPCR, (WakeUpPinPolarity & PWR_WKUPCR_WKUPC)); /* Clear wake up flag */
|
||||
SET_BIT(PWR->MCUWKUPENR, (WakeUpPinPolarity & PWR_WAKEUP_PIN_MASK)); /* Enable the Wake up pin for CPU2 */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disables the WakeUp PINx functionality.
|
||||
* @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_WAKEUP_PIN1
|
||||
* @arg PWR_WAKEUP_PIN2
|
||||
* @arg PWR_WAKEUP_PIN3
|
||||
* @arg PWR_WAKEUP_PIN4
|
||||
* @arg PWR_WAKEUP_PIN5
|
||||
* @arg PWR_WAKEUP_PIN6
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
|
||||
{
|
||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
||||
#ifdef CORE_CA7
|
||||
CLEAR_BIT(PWR->MPUWKUPENR, (WakeUpPinx & PWR_WAKEUP_PIN_MASK));
|
||||
#endif
|
||||
#ifdef CORE_CM4
|
||||
CLEAR_BIT(PWR->MCUWKUPENR, (WakeUpPinx & PWR_WAKEUP_PIN_MASK));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable WakeUp PINx Interrupt on AIEC and NVIC.
|
||||
* @param WakeUpPinx: Specifies the Power Wake-Up pin
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_WAKEUP_PIN1
|
||||
* @arg PWR_WAKEUP_PIN2
|
||||
* @arg PWR_WAKEUP_PIN3
|
||||
* @arg PWR_WAKEUP_PIN4
|
||||
* @arg PWR_WAKEUP_PIN5
|
||||
* @arg PWR_WAKEUP_PIN6
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableWakeUpPinIT(uint32_t WakeUpPinx)
|
||||
{
|
||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
||||
switch ((WakeUpPinx & PWR_WAKEUP_PIN_MASK))
|
||||
{
|
||||
case PWR_WAKEUP_PIN1:
|
||||
__HAL_WKUP_EXTI_ENABLE_IT(EXTI_IMR2_IM55);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN2:
|
||||
__HAL_WKUP_EXTI_ENABLE_IT(EXTI_IMR2_IM56);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN3:
|
||||
__HAL_WKUP_EXTI_ENABLE_IT(EXTI_IMR2_IM57);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN4:
|
||||
__HAL_WKUP_EXTI_ENABLE_IT(EXTI_IMR2_IM58);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN5:
|
||||
__HAL_WKUP_EXTI_ENABLE_IT(EXTI_IMR2_IM59);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN6:
|
||||
__HAL_WKUP_EXTI_ENABLE_IT(EXTI_IMR2_IM60);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disable WakeUp PINx Interrupt on AIEC and NVIC.
|
||||
* @param WakeUpPinx: Specifies the Power Wake-Up pin
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_WAKEUP_PIN1
|
||||
* @arg PWR_WAKEUP_PIN2
|
||||
* @arg PWR_WAKEUP_PIN3
|
||||
* @arg PWR_WAKEUP_PIN4
|
||||
* @arg PWR_WAKEUP_PIN5
|
||||
* @arg PWR_WAKEUP_PIN6
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableWakeUpPinIT(uint32_t WakeUpPinx)
|
||||
{
|
||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
||||
switch ((WakeUpPinx & PWR_WAKEUP_PIN_MASK))
|
||||
{
|
||||
case PWR_WAKEUP_PIN1:
|
||||
__HAL_WKUP_EXTI_DISABLE_IT(EXTI_IMR2_IM55);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN2:
|
||||
__HAL_WKUP_EXTI_DISABLE_IT(EXTI_IMR2_IM56);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN3:
|
||||
__HAL_WKUP_EXTI_DISABLE_IT(EXTI_IMR2_IM57);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN4:
|
||||
__HAL_WKUP_EXTI_DISABLE_IT(EXTI_IMR2_IM58);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN5:
|
||||
__HAL_WKUP_EXTI_DISABLE_IT(EXTI_IMR2_IM59);
|
||||
break;
|
||||
|
||||
case PWR_WAKEUP_PIN6:
|
||||
__HAL_WKUP_EXTI_DISABLE_IT(EXTI_IMR2_IM60);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enters CSleep mode.
|
||||
*
|
||||
* @note In CSleep mode, all I/O pins keep the same state as in Run mode.
|
||||
*
|
||||
* @note In CSleep mode, the systick is stopped to avoid exit from this mode with
|
||||
* systick interrupt when used as time base for Timeout
|
||||
*
|
||||
* @param Regulator: Specifies the regulator state in CSLEEP mode.
|
||||
* This parameter is not used for the STM32MP1 family and is kept as
|
||||
* parameter just to maintain compatibility with the lower power families
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_MAINREGULATOR_ON: CSLEEP mode with regulator ON
|
||||
* @arg PWR_LOWPOWERREGULATOR_ON: CSLEEP mode with low power regulator ON
|
||||
* @param SLEEPEntry: Specifies if CSLEEP mode in entered with WFI or WFE instruction.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_SLEEPENTRY_WFI: enter CSLEEP mode with WFI instruction
|
||||
* @arg PWR_SLEEPENTRY_WFE: enter CSLEEP mode with WFE instruction
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PWR_REGULATOR(Regulator));
|
||||
assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
|
||||
|
||||
#ifdef CORE_CM4
|
||||
/* Ensure CM4 do not enter to CSTOP mode */
|
||||
/* Clear SLEEPDEEP bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
|
||||
#endif
|
||||
|
||||
/* Select SLEEP mode entry -------------------------------------------------*/
|
||||
if (SLEEPEntry == PWR_SLEEPENTRY_WFI)
|
||||
{
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Request Wait For Event */
|
||||
__SEV();
|
||||
__WFE();
|
||||
__WFE();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enters CSTOP
|
||||
* This function puts core domain into CSTOP allowing system STOP mode
|
||||
* if both MPU and MCU cores are on CSTOP mode
|
||||
* @note In Stop mode, all I/O pins keep the same state as in Run mode.
|
||||
* @note When exiting Stop mode by issuing an interrupt or a wake up event,
|
||||
* the HSI oscillator is selected as CM4 system clock.
|
||||
* @note RCC_WAKEUP_IRQn IT must be programmed to have the highest priority and
|
||||
* to be the only one IT having this value before calling HAL_PWR_EnterSTOPMode.
|
||||
* Make sure RCC_WAKEUP_IRQn is the only one IT allowed to wake up core
|
||||
* before calling HAL_PWR_EnterSTOPMode (BASEPRI)
|
||||
* Reestablish priority level once system is completely waken up (clock
|
||||
* restore and IO compensation)
|
||||
* @note When the voltage regulator operates in low power mode, an additional
|
||||
* startup delay is incurred when waking up from Stop mode.
|
||||
* By keeping the internal regulator ON during Stop mode, the consumption
|
||||
* is higher although the startup time is reduced.
|
||||
* @param Regulator: Specifies the regulator state in Stop mode.
|
||||
* This parameter is unused on MCU but any value must be provided.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
|
||||
* @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
|
||||
* @param STOPEntry: Specifies if CStop mode is entered with WFI or WFE instruction.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_STOPENTRY_WFI: Enter CStop mode with WFI instruction
|
||||
* @arg PWR_STOPENTRY_WFE: Enter CStop mode with WFE instruction
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PWR_REGULATOR(Regulator));
|
||||
assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
|
||||
|
||||
#ifdef CORE_CM4
|
||||
/*Forbid going to STANDBY mode (select STOP mode) */
|
||||
CLEAR_BIT(PWR->MCUCR, PWR_MCUCR_PDDS);
|
||||
|
||||
/*Allow CORE_CM4 to enter CSTOP mode
|
||||
Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
|
||||
#endif/* CORE_CM4 */
|
||||
|
||||
#ifdef CORE_CA7
|
||||
if (Regulator == PWR_MAINREGULATOR_ON)
|
||||
{
|
||||
/* Select STOP mode */
|
||||
CLEAR_BIT(PWR->CR1, PWR_CR1_LPDS);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Select LP-STOP mode */
|
||||
SET_BIT(PWR->CR1, PWR_CR1_LPDS);
|
||||
}
|
||||
|
||||
/* Clear MPU STANDBY, STOP and HOLD flags.(Always read as 0) */
|
||||
SET_BIT(PWR->MPUCR, PWR_MPUCR_CSSF);
|
||||
|
||||
/* MPU STAY in STOP MODE */
|
||||
CLEAR_BIT(PWR->MPUCR, PWR_MPUCR_PDDS);
|
||||
|
||||
/* MPU CSTANDBY mode disabled */
|
||||
SET_BIT(PWR->MPUCR, PWR_MPUCR_CSTBYDIS);
|
||||
|
||||
/* RCC Stop Request Set Register */
|
||||
#if defined(RCC_MP_SREQSETR_STPREQ_P0) & defined(RCC_MP_SREQSETR_STPREQ_P1)
|
||||
/* CA7_CORE0 and CA7_CORE1 available */
|
||||
RCC->MP_SREQSETR = RCC_MP_SREQSETR_STPREQ_P0 | RCC_MP_SREQSETR_STPREQ_P1;
|
||||
#else
|
||||
/* Only CA7_CORE0 available */
|
||||
RCC->MP_SREQSETR = RCC_MP_SREQSETR_STPREQ_P0;
|
||||
#endif /* RCC_MP_SREQSETR_STPREQ_P0 & RCC_MP_SREQSETR_STPREQ_P1 */
|
||||
|
||||
#else
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(Regulator);
|
||||
#endif /*CORE_CA7*/
|
||||
|
||||
/* Select Stop mode entry --------------------------------------------------*/
|
||||
if (STOPEntry == PWR_STOPENTRY_WFI)
|
||||
{
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
else if (STOPEntry == PWR_STOPENTRY_WFE)
|
||||
{
|
||||
/* Request Wait For Event */
|
||||
__SEV();
|
||||
__WFE();
|
||||
__WFE();
|
||||
}
|
||||
|
||||
#ifdef CORE_CM4
|
||||
/* Reset SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
|
||||
#endif/* CORE_CM4 */
|
||||
|
||||
#ifdef CORE_CA7
|
||||
/* RCC Clear Request Set Register */
|
||||
#if defined(RCC_MP_SREQCLRR_STPREQ_P0) & defined(RCC_MP_SREQCLRR_STPREQ_P1)
|
||||
/* CA7_CORE0 and CA7_CORE1 available */
|
||||
RCC->MP_SREQCLRR = RCC_MP_SREQCLRR_STPREQ_P0 | RCC_MP_SREQCLRR_STPREQ_P1;
|
||||
#else
|
||||
/* Only CA7_CORE0 available */
|
||||
RCC->MP_SREQCLRR = RCC_MP_SREQCLRR_STPREQ_P0;
|
||||
#endif /* RCC_MP_SREQCLRR_STPREQ_P0 | RCC_MP_SREQCLRR_STPREQ_P1 */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enters MPU CStandby / MCU CSTOP allowing system Standby mode.
|
||||
* @note In Standby mode, all I/O pins are high impedance except for:
|
||||
* - Reset pad (still available)
|
||||
* - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC
|
||||
* Alarm out, or RTC clock calibration out.
|
||||
* - RTC_AF2 pin (PI8) if configured for tamper or time-stamp.
|
||||
* - WKUP pins if enabled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnterSTANDBYMode(void)
|
||||
{
|
||||
|
||||
#ifdef CORE_CM4
|
||||
/*Allow to go to STANDBY mode */
|
||||
SET_BIT(PWR->MCUCR, PWR_MCUCR_PDDS);
|
||||
|
||||
/*Allow CORE_CM4 to enter CSTOP mode
|
||||
Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
#endif /* CORE_CM4 */
|
||||
|
||||
#ifdef CORE_CA7
|
||||
|
||||
/* Clear MPU STANDBY, STOP and HOLD flags.(Always read as 0) */
|
||||
SET_BIT(PWR->MPUCR, PWR_MPUCR_CSSF);
|
||||
/* system Power Down Deepsleep selection */
|
||||
/* MPU go in STANDBY MODE */
|
||||
SET_BIT(PWR->MPUCR, PWR_MPUCR_PDDS);
|
||||
|
||||
/* MPU CSTANDBY mode enabled */
|
||||
CLEAR_BIT(PWR->MPUCR, PWR_MPUCR_CSTBYDIS);
|
||||
|
||||
/* RCC Stop Request Set Register */
|
||||
#if defined(RCC_MP_SREQSETR_STPREQ_P0) & defined(RCC_MP_SREQSETR_STPREQ_P1)
|
||||
/* CA7_CORE0 and CA7_CORE1 available */
|
||||
RCC->MP_SREQSETR = RCC_MP_SREQSETR_STPREQ_P0 | RCC_MP_SREQSETR_STPREQ_P1;
|
||||
#else
|
||||
/* Only CA7_CORE0 available */
|
||||
RCC->MP_SREQSETR = RCC_MP_SREQSETR_STPREQ_P0;
|
||||
#endif /* RCC_MP_SREQSETR_STPREQ_P0 & RCC_MP_SREQSETR_STPREQ_P1 */
|
||||
#endif
|
||||
|
||||
/* Clear Reset Status */
|
||||
__HAL_RCC_CLEAR_RESET_FLAGS();
|
||||
|
||||
|
||||
/* This option is used to ensure that store operations are completed */
|
||||
#if defined ( __CC_ARM)
|
||||
__force_stores();
|
||||
#endif
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode.
|
||||
* @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
||||
* re-enters CSleep mode when an interruption handling is over.
|
||||
* Setting this bit is useful when the processor is expected to run only on
|
||||
* interruptions handling.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableSleepOnExit(void)
|
||||
{
|
||||
#ifdef CORE_CM4
|
||||
/* Set SLEEPONEXIT bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode.
|
||||
* @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
||||
* re-enters CSLEEP mode when an interruption handling is over.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableSleepOnExit(void)
|
||||
{
|
||||
#ifdef CORE_CM4
|
||||
/* Clear SLEEPONEXIT bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables CORTEX SEVONPEND bit.
|
||||
* @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes
|
||||
* WFE to wake up when an interrupt moves from inactive to pended.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableSEVOnPend(void)
|
||||
{
|
||||
#ifdef CORE_CM4
|
||||
/* Set SEVONPEND bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables CORTEX SEVONPEND bit.
|
||||
* @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes
|
||||
* WFE to wake up when an interrupt moves from inactive to pended.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableSEVOnPend(void)
|
||||
{
|
||||
#ifdef CORE_CM4
|
||||
/* Clear SEVONPEND bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR PVD interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWR_PVDCallback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWR_PVDCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -0,0 +1,792 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_hal_pwr_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended PWR HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of PWR extension peripheral:
|
||||
* + Peripheral Extended features functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 "stm32mp1xx_hal.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PWREx PWREx
|
||||
* @brief PWR HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @addtogroup PWREx_Private_Constants PWREx Private Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PWREx_AVD_Mode_Mask PWR Extended AVD Mode Mask
|
||||
* @{
|
||||
*/
|
||||
#define AVD_MODE_IT ((uint32_t)0x00010000U)
|
||||
#define AVD_MODE_EVT ((uint32_t)0x00020000U)
|
||||
#define AVD_RISING_EDGE ((uint32_t)0x00000001U)
|
||||
#define AVD_FALLING_EDGE ((uint32_t)0x00000002U)
|
||||
#define AVD_RISING_FALLING_EDGE ((uint32_t)0x00000003U)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup PWREx_REG_SET_TIMEOUT PWR Extended Flag Setting Time Out Value
|
||||
* @{
|
||||
*/
|
||||
#define PWR_FLAG_SETTING_DELAY_US ((uint32_t)1000U)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup PWREx_Private_Functions PWREx Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PWREx_Group1 Peripheral Extended features functions
|
||||
* @brief Peripheral Extended features functions
|
||||
*
|
||||
@verbatim
|
||||
|
||||
===============================================================================
|
||||
##### Peripheral extended features functions #####
|
||||
===============================================================================
|
||||
|
||||
*** Main and Backup Regulators configuration ***
|
||||
================================================
|
||||
[..]
|
||||
(+) The backup domain includes 4 Kbytes of backup SRAM accessible only from
|
||||
the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is
|
||||
retained even in Standby or VBAT mode when the low power backup regulator
|
||||
is enabled. It can be considered as an internal EEPROM when VBAT is
|
||||
always present. You can use the HAL_PWR_EnableBkUpReg() function to
|
||||
enable the low power backup regulator.
|
||||
|
||||
(+) When the backup domain is supplied by VDD (analog switch connected to VDD)
|
||||
the backup SRAM is powered from VDD which replaces the VBAT power supply to
|
||||
save battery life.
|
||||
|
||||
(+) The backup SRAM is not mass erased by a tamper event. It is read
|
||||
protected to prevent confidential data, such as cryptographic private
|
||||
key, from being accessed.
|
||||
|
||||
Refer to the product datasheets for more details.
|
||||
|
||||
|
||||
*** VBAT battery charging ***
|
||||
=============================
|
||||
[..]
|
||||
(+) When VDD is present, the external battery connected to VBAT can be charged through an
|
||||
internal resistance. VBAT charging can be performed either through a 5 KOhm resistor
|
||||
or through a 1.5 KOhm resistor.
|
||||
(+) VBAT charging is enabled by HAL_PWREx_EnableBatteryCharging(ResistorValue) function
|
||||
with:
|
||||
(++) ResistorValue:
|
||||
(+++) PWR_BATTERY_CHARGING_RESISTOR_5: 5 KOhm resistor.
|
||||
(+++) PWR_BATTERY_CHARGING_RESISTOR_1_5: 1.5 KOhm resistor.
|
||||
(+) VBAT charging is disabled by HAL_PWREx_DisableBatteryCharging() function.
|
||||
|
||||
*** VBAT and Temperature supervision ***
|
||||
========================================
|
||||
[..]
|
||||
(+) The VBAT battery voltage supply can be monitored by comparing it with two threshold
|
||||
levels: VBAThigh and VBATlow. VBATH flag and VBATL flag in the PWR control register 2
|
||||
(PWR_CR2), indicate if VBAT is higher or lower than the threshold.
|
||||
(+) The temperature can be monitored by comparing it with two threshold levels, TEMPhigh
|
||||
and TEMPlow. TEMPH and TEMPL flags, in the PWR control register 2 (PWR_CR2),
|
||||
indicate whether the device temperature is higher or lower than the threshold.
|
||||
(+) The VBAT and the temperature monitoring is enabled by HAL_PWREx_EnableMonitoring()
|
||||
function and disabled by HAL_PWREx_DisableMonitoring() function.
|
||||
(+) The HAL_PWREx_GetVBATLevel() function return the VBAT level which can be:
|
||||
PWR_VBAT_BELOW_LOW_THRESHOLD or PWR_VBAT_ABOVE_HIGH_THRESHOLD or
|
||||
PWR_VBAT_BETWEEN_HIGH_LOW_THRESHOLD.
|
||||
(+) The HAL_PWREx_GetTemperatureLevel() function return the Temperature level which
|
||||
can be: PWR_TEMP_BELOW_LOW_THRESHOLD or PWR_TEMP_ABOVE_HIGH_THRESHOLD or
|
||||
PWR_TEMP_BETWEEN_HIGH_LOW_THRESHOLD.
|
||||
|
||||
*** AVD configuration ***
|
||||
=========================
|
||||
[..]
|
||||
(+) The AVD is used to monitor the VDDA power supply by comparing it to a
|
||||
threshold selected by the AVD Level (ALS[3:0] bits in the PWR_CSR1 register).
|
||||
(+) A AVDO flag is available to indicate if VDDA is higher or lower
|
||||
than the AVD threshold. This event is internally connected to the EXTI
|
||||
line 16 to generate an interrupt if enabled.
|
||||
It is configurable through __HAL_PWR_PVD_AVD_EXTI_ENABLE_IT() macro.
|
||||
(+) The AVD is stopped in System Standby mode.
|
||||
|
||||
|
||||
*** USB Regulator supervision ***
|
||||
===================================
|
||||
[..]
|
||||
(+) When the USB regulator is enabled, the VDD33USB supply level detector shall
|
||||
be enabled through HAL_PWREx_EnableUSBVoltageDetector() function and disabled by
|
||||
HAL_PWREx_DisableUSBVoltageDetector() function.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables the Backup Regulator.
|
||||
* @note After reset PWR_CR2 register is write-protected and the DBP bit in the
|
||||
* PWR control register 1 (PWR_CR1) has to be set before it can be written.
|
||||
* Use HAL_PWR_EnableBkUpAccess() to do this.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Enable Backup regulator */
|
||||
SET_BIT(PWR->CR2, PWR_CR2_BREN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till Backup regulator ready flag is set */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables the Backup Regulator.
|
||||
* @note After reset PWR_CR2 register is write-protected and the DBP bit in the
|
||||
* PWR control register 1 (PWR_CR1) has to be set before it can be written.
|
||||
* Use HAL_PWR_EnableBkUpAccess() to do this.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Disable Backup regulator */
|
||||
CLEAR_BIT(PWR->CR2, PWR_CR2_BREN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till Backup regulator ready flag is reset */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the Retention Regulator.
|
||||
* @note After reset PWR_CR2 register is write-protected and the DBP bit in the
|
||||
* PWR control register 1 (PWR_CR1) has to be set before it can be written.
|
||||
* Use HAL_PWR_EnableBkUpAccess() to do this.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_EnableRetReg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Enable Backup regulator */
|
||||
SET_BIT(PWR->CR2, PWR_CR2_RREN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till Retention regulator ready flag is set */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_RRR) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables the Retention Regulator.
|
||||
* @note After reset PWR_CR2 register is write-protected and the DBP bit in the
|
||||
* PWR control register 1 (PWR_CR1) has to be set before it can be written.
|
||||
* Use HAL_PWR_EnableBkUpAccess() to do this.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_DisableRetReg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Disable Backup regulator */
|
||||
CLEAR_BIT(PWR->CR2, PWR_CR2_RREN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till Backup regulator ready flag is set */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_RRR) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the 1V1 Regulator.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_Enable1V1Reg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Enable 1V1 regulator */
|
||||
SET_BIT(PWR->CR3, PWR_CR3_REG11EN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till 1V1 regulator ready flag is set */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_11R) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disables the 1V1 Regulator.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_Disable1V1Reg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Disable 1V1 regulator */
|
||||
CLEAR_BIT(PWR->CR3, PWR_CR3_REG11EN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till 1V1 regulator ready flag is reset */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_11R) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the 1V8 Regulator.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_Enable1V8Reg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Enable 1V8 regulator */
|
||||
SET_BIT(PWR->CR3, PWR_CR3_REG18EN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till 1V8 regulator ready flag is set */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_18R) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disables the 1V8 Regulator.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_Disable1V8Reg(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Disable 1V8 regulator */
|
||||
CLEAR_BIT(PWR->CR3, PWR_CR3_REG18EN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till 1V8 regulator ready flag is reset */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_18R) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the USB voltage level detector.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_EnableUSBVoltageDetector(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Enable the USB voltage detector */
|
||||
SET_BIT(PWR->CR3, PWR_CR3_USB33DEN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait until USB33 regulator ready flag is set */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_USB) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the USB voltage level detector.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PWREx_DisableUSBVoltageDetector(void)
|
||||
{
|
||||
uint32_t tickstart = 0;
|
||||
|
||||
/* Disable the USB voltage detector */
|
||||
CLEAR_BIT(PWR->CR3, PWR_CR3_USB33DEN);
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait until USB33 regulator ready flag is reset */
|
||||
while (__HAL_PWR_GET_FLAG(PWR_FLAG_USB) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY_US)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Battery charging.
|
||||
* When VDD is present, charge the external battery through an internal resistor.
|
||||
* @param ResistorValue: Specifies the charging resistor.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_BATTERY_CHARGING_RESISTOR_5: 5 KOhm resistor.
|
||||
* @arg PWR_BATTERY_CHARGING_RESISTOR_1_5: 1.5 KOhm resistor.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorValue)
|
||||
{
|
||||
assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorValue));
|
||||
|
||||
/* Specify the charging resistor */
|
||||
MODIFY_REG(PWR->CR3, PWR_CR3_VBRS, ResistorValue);
|
||||
|
||||
/* Enable the Battery charging */
|
||||
SET_BIT(PWR->CR3, PWR_CR3_VBE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disable the Battery charging.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWREx_DisableBatteryCharging(void)
|
||||
{
|
||||
/* Disable the Battery charging */
|
||||
CLEAR_BIT(PWR->CR3, PWR_CR3_VBE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the VBAT and temperature monitoring.
|
||||
* @note After reset PWR_CR2 register is write-protected and the DBP bit in the
|
||||
* PWR control register 1 (PWR_CR1) has to be set before it can be written.
|
||||
* Use HAL_PWR_EnableBkUpAccess() to do this.
|
||||
* @retval HAL status
|
||||
*/
|
||||
void HAL_PWREx_EnableMonitoring(void)
|
||||
{
|
||||
/* Enable the VBAT and Temperature monitoring */
|
||||
SET_BIT(PWR->CR2, PWR_CR2_MONEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the VBAT and temperature monitoring.
|
||||
* @note After reset PWR_CR2 register is write-protected and the DBP bit in the
|
||||
* PWR control register 1 (PWR_CR1) has to be set before it can be written.
|
||||
* Use HAL_PWR_EnableBkUpAccess() to do this.
|
||||
* @retval HAL status
|
||||
*/
|
||||
void HAL_PWREx_DisableMonitoring(void)
|
||||
{
|
||||
/* Disable the VBAT and Temperature monitoring */
|
||||
CLEAR_BIT(PWR->CR2, PWR_CR2_MONEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Indicate whether the junction temperature is between, above or below the threshold.
|
||||
* @retval Temperature level.
|
||||
*/
|
||||
uint32_t HAL_PWREx_GetTemperatureLevel(void)
|
||||
{
|
||||
uint32_t tempLevel;
|
||||
uint32_t regValue;
|
||||
|
||||
/* Read the temperature flags */
|
||||
regValue = PWR->CR2 & (PWR_CR2_TEMPH | PWR_CR2_TEMPL);
|
||||
|
||||
/* Compare the read value to the temperature threshold */
|
||||
if (regValue == PWR_CR2_TEMPL)
|
||||
{
|
||||
tempLevel = PWR_TEMP_BELOW_LOW_THRESHOLD;
|
||||
}
|
||||
else if (regValue == PWR_CR2_TEMPH)
|
||||
{
|
||||
tempLevel = PWR_TEMP_ABOVE_HIGH_THRESHOLD;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempLevel = PWR_TEMP_BETWEEN_HIGH_LOW_THRESHOLD;
|
||||
}
|
||||
|
||||
return tempLevel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Indicate whether the Battery voltage level is between, above or below the threshold.
|
||||
* @retval VBAT level.
|
||||
*/
|
||||
uint32_t HAL_PWREx_GetVBATLevel(void)
|
||||
{
|
||||
uint32_t VBATLevel;
|
||||
uint32_t regValue;
|
||||
|
||||
/* Read the VBAT flags */
|
||||
regValue = PWR->CR2 & (PWR_CR2_VBATH | PWR_CR2_VBATL);
|
||||
|
||||
/* Compare the read value to the VBAT threshold */
|
||||
if (regValue == PWR_CR2_VBATL)
|
||||
{
|
||||
VBATLevel = PWR_VBAT_BELOW_LOW_THRESHOLD;
|
||||
}
|
||||
else if (regValue == PWR_CR2_VBATH)
|
||||
{
|
||||
VBATLevel = PWR_VBAT_ABOVE_HIGH_THRESHOLD;
|
||||
}
|
||||
else
|
||||
{
|
||||
VBATLevel = PWR_VBAT_BETWEEN_HIGH_LOW_THRESHOLD;
|
||||
}
|
||||
|
||||
return VBATLevel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configure the analog voltage threshold detected by the Analog Voltage Detector(AVD).
|
||||
* @param sConfigAVD: pointer to an PWR_AVDTypeDef structure that contains the configuration
|
||||
* information for the AVD.
|
||||
* @note Refer to the electrical characteristics of your device datasheet for more details
|
||||
* about the voltage threshold corresponding to each detection level.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWREx_ConfigAVD(PWREx_AVDTypeDef *sConfigAVD)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PWR_AVD_LEVEL(sConfigAVD->AVDLevel));
|
||||
assert_param(IS_PWR_AVD_MODE(sConfigAVD->Mode));
|
||||
|
||||
/* Set the ALS[18:17] bits according to AVDLevel value */
|
||||
MODIFY_REG(PWR->CR1, PWR_CR1_ALS, sConfigAVD->AVDLevel);
|
||||
|
||||
/* Clear any previous config. Keep it clear if no IT mode is selected */
|
||||
__HAL_PWR_PVD_AVD_EXTI_DISABLE_IT();
|
||||
__HAL_PWR_PVD_AVD_EXTI_DISABLE_RISING_EDGE();
|
||||
__HAL_PWR_PVD_AVD_EXTI_DISABLE_FALLING_EDGE();
|
||||
|
||||
/* Configure the interrupt mode */
|
||||
if (AVD_MODE_IT == (sConfigAVD->Mode & AVD_MODE_IT))
|
||||
{
|
||||
__HAL_PWR_PVD_AVD_EXTI_ENABLE_IT();
|
||||
}
|
||||
|
||||
/* Configure the edge */
|
||||
if (AVD_RISING_EDGE == (sConfigAVD->Mode & AVD_RISING_EDGE))
|
||||
{
|
||||
__HAL_PWR_PVD_AVD_EXTI_ENABLE_RISING_EDGE();
|
||||
}
|
||||
|
||||
if (AVD_FALLING_EDGE == (sConfigAVD->Mode & AVD_FALLING_EDGE))
|
||||
{
|
||||
__HAL_PWR_PVD_AVD_EXTI_ENABLE_FALLING_EDGE();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Analog Voltage Detector(AVD).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWREx_EnableAVD(void)
|
||||
{
|
||||
/* Enable the Analog Voltage Detector */
|
||||
SET_BIT(PWR->CR1, PWR_CR1_AVDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Analog Voltage Detector(AVD).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWREx_DisableAVD(void)
|
||||
{
|
||||
/* Disable the Analog Voltage Detector */
|
||||
CLEAR_BIT(PWR->CR1, PWR_CR1_AVDEN);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function handles the PWR PVD/AVD interrupt request.
|
||||
* @note This API should be called under the PVD_AVD_IRQHandler().
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWREx_PVD_AVD_IRQHandler(void)
|
||||
{
|
||||
/* PVD EXTI line interrupt detected */
|
||||
if (READ_BIT(PWR->CR1, PWR_CR1_PVDEN) != RESET)
|
||||
{
|
||||
/* PWR PVD interrupt user callback */
|
||||
HAL_PWR_PVDCallback();
|
||||
}
|
||||
|
||||
/* AVD EXTI line interrupt detected */
|
||||
if (READ_BIT(PWR->CR1, PWR_CR1_AVDEN) != RESET)
|
||||
{
|
||||
/* PWR AVD interrupt user callback */
|
||||
HAL_PWREx_AVDCallback();
|
||||
}
|
||||
|
||||
/* Clear PWR PVD AVD EXTI pending bit */
|
||||
__HAL_PWR_PVD_AVD_EXTI_CLEAR_FLAG();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR AVD interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWREx_AVDCallback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWREx_AVDCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void HAL_PWREx_WAKEUP_PIN_IRQHandler(void)
|
||||
{
|
||||
|
||||
/* Wakeup pin EXTI line interrupt detected */
|
||||
if (READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF1) != RESET)
|
||||
{
|
||||
/* Clear PWR WKUPF1 flag */
|
||||
SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC1);
|
||||
|
||||
/* PWR WKUP1 interrupt user callback */
|
||||
HAL_PWREx_WKUP1_Callback();
|
||||
}
|
||||
|
||||
if (READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF2) != RESET)
|
||||
{
|
||||
/* Clear PWR WKUPF2 flag */
|
||||
SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC2);
|
||||
|
||||
/* PWR WKUP2 interrupt user callback */
|
||||
HAL_PWREx_WKUP2_Callback();
|
||||
}
|
||||
|
||||
if (READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF3) != RESET)
|
||||
{
|
||||
/* Clear PWR WKUPF3 flag */
|
||||
SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC3);
|
||||
|
||||
/* PWR WKUP3 interrupt user callback */
|
||||
HAL_PWREx_WKUP3_Callback();
|
||||
}
|
||||
|
||||
if (READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF4) != RESET)
|
||||
{
|
||||
/* Clear PWR WKUPF4 flag */
|
||||
SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC4);
|
||||
|
||||
/* PWR WKUP4 interrupt user callback */
|
||||
HAL_PWREx_WKUP4_Callback();
|
||||
}
|
||||
|
||||
if (READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF5) != RESET)
|
||||
{
|
||||
/* Clear PWR WKUPF5 flag */
|
||||
SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC5);
|
||||
|
||||
/* PWR WKUP5 interrupt user callback */
|
||||
HAL_PWREx_WKUP5_Callback();
|
||||
}
|
||||
|
||||
if (READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF6) != RESET)
|
||||
{
|
||||
/* Clear PWR WKUPF6 flag */
|
||||
SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC6);
|
||||
|
||||
/* PWR WKUP6 interrupt user callback */
|
||||
HAL_PWREx_WKUP6_Callback();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR WKUP1 interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWREx_WKUP1_Callback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWREx_WKUP1Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR WKUP2 interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWREx_WKUP2_Callback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWREx_WKUP2Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR WKUP3 interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWREx_WKUP3_Callback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWREx_WKUP3Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR WKUP4 interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWREx_WKUP4_Callback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWREx_WKUP4Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR WKUP5 interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWREx_WKUP5_Callback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWREx_WKUP5Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PWR WKUP6 interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWREx_WKUP6_Callback(void)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWREx_WKUP6Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_PWR_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,727 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32mp1xx_hal_uart_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended UART HAL module driver.
|
||||
* This file provides firmware functions to manage the following extended
|
||||
* functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
|
||||
* + Initialization and de-initialization functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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
|
||||
==============================================================================
|
||||
##### UART peripheral extended features #####
|
||||
==============================================================================
|
||||
|
||||
(#) Declare a UART_HandleTypeDef handle structure.
|
||||
|
||||
(#) For the UART RS485 Driver Enable mode, initialize the UART registers
|
||||
by calling the HAL_RS485Ex_Init() API.
|
||||
|
||||
(#) FIFO mode enabling/disabling and RX/TX FIFO threshold programming.
|
||||
|
||||
-@- When UART operates in FIFO mode, FIFO mode must be enabled prior
|
||||
starting RX/TX transfers. Also RX/TX FIFO thresholds must be
|
||||
configured prior starting RX/TX transfers.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32mp1xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32MP1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup UARTEx UARTEx
|
||||
* @brief UART Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup UARTEX_Private_Constants UARTEx Private Constants
|
||||
* @{
|
||||
*/
|
||||
/* UART RX FIFO depth */
|
||||
#define RX_FIFO_DEPTH 8U
|
||||
|
||||
/* UART TX FIFO depth */
|
||||
#define TX_FIFO_DEPTH 8U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup UARTEx_Private_Functions UARTEx Private Functions
|
||||
* @{
|
||||
*/
|
||||
static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
|
||||
static void UARTEx_SetNbDataToProcess(UART_HandleTypeDef *huart);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup UARTEx_Exported_Functions UARTEx Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup UARTEx_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Extended Initialization and Configuration Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and Configuration functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
|
||||
in asynchronous mode.
|
||||
(+) For the asynchronous mode the parameters below can be configured:
|
||||
(++) Baud Rate
|
||||
(++) Word Length
|
||||
(++) Stop Bit
|
||||
(++) Parity: If the parity is enabled, then the MSB bit of the data written
|
||||
in the data register is transmitted but is changed by the parity bit.
|
||||
(++) Hardware flow control
|
||||
(++) Receiver/transmitter modes
|
||||
(++) Over Sampling Method
|
||||
(++) One-Bit Sampling Method
|
||||
(+) For the asynchronous mode, the following advanced features can be configured as well:
|
||||
(++) TX and/or RX pin level inversion
|
||||
(++) data logical level inversion
|
||||
(++) RX and TX pins swap
|
||||
(++) RX overrun detection disabling
|
||||
(++) DMA disabling on RX error
|
||||
(++) MSB first on communication line
|
||||
(++) auto Baud rate detection
|
||||
[..]
|
||||
The HAL_RS485Ex_Init() API follows the UART RS485 mode configuration
|
||||
procedures (details for the procedures are available in reference manual).
|
||||
|
||||
@endverbatim
|
||||
|
||||
Depending on the frame length defined by the M1 and M0 bits (7-bit,
|
||||
8-bit or 9-bit), the possible UART formats are listed in the
|
||||
following table.
|
||||
|
||||
Table 1. UART frame format.
|
||||
+-----------------------------------------------------------------------+
|
||||
| M1 bit | M0 bit | PCE bit | UART frame |
|
||||
|---------|---------|-----------|---------------------------------------|
|
||||
| 0 | 0 | 0 | | SB | 8 bit data | STB | |
|
||||
|---------|---------|-----------|---------------------------------------|
|
||||
| 0 | 0 | 1 | | SB | 7 bit data | PB | STB | |
|
||||
|---------|---------|-----------|---------------------------------------|
|
||||
| 0 | 1 | 0 | | SB | 9 bit data | STB | |
|
||||
|---------|---------|-----------|---------------------------------------|
|
||||
| 0 | 1 | 1 | | SB | 8 bit data | PB | STB | |
|
||||
|---------|---------|-----------|---------------------------------------|
|
||||
| 1 | 0 | 0 | | SB | 7 bit data | STB | |
|
||||
|---------|---------|-----------|---------------------------------------|
|
||||
| 1 | 0 | 1 | | SB | 6 bit data | PB | STB | |
|
||||
+-----------------------------------------------------------------------+
|
||||
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the RS485 Driver enable feature according to the specified
|
||||
* parameters in the UART_InitTypeDef and creates the associated handle.
|
||||
* @param huart UART handle.
|
||||
* @param Polarity Select the driver enable polarity.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref UART_DE_POLARITY_HIGH DE signal is active high
|
||||
* @arg @ref UART_DE_POLARITY_LOW DE signal is active low
|
||||
* @param AssertionTime Driver Enable assertion time:
|
||||
* 5-bit value defining the time between the activation of the DE (Driver Enable)
|
||||
* signal and the beginning of the start bit. It is expressed in sample time
|
||||
* units (1/8 or 1/16 bit time, depending on the oversampling rate)
|
||||
* @param DeassertionTime Driver Enable deassertion time:
|
||||
* 5-bit value defining the time between the end of the last stop bit, in a
|
||||
* transmitted message, and the de-activation of the DE (Driver Enable) signal.
|
||||
* It is expressed in sample time units (1/8 or 1/16 bit time, depending on the
|
||||
* oversampling rate).
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime,
|
||||
uint32_t DeassertionTime)
|
||||
{
|
||||
uint32_t temp;
|
||||
|
||||
/* Check the UART handle allocation */
|
||||
if (huart == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Check the Driver Enable UART instance */
|
||||
assert_param(IS_UART_DRIVER_ENABLE_INSTANCE(huart->Instance));
|
||||
|
||||
/* Check the Driver Enable polarity */
|
||||
assert_param(IS_UART_DE_POLARITY(Polarity));
|
||||
|
||||
/* Check the Driver Enable assertion time */
|
||||
assert_param(IS_UART_ASSERTIONTIME(AssertionTime));
|
||||
|
||||
/* Check the Driver Enable deassertion time */
|
||||
assert_param(IS_UART_DEASSERTIONTIME(DeassertionTime));
|
||||
|
||||
if (huart->gState == HAL_UART_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
huart->Lock = HAL_UNLOCKED;
|
||||
|
||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
|
||||
UART_InitCallbacksToDefault(huart);
|
||||
|
||||
if (huart->MspInitCallback == NULL)
|
||||
{
|
||||
huart->MspInitCallback = HAL_UART_MspInit;
|
||||
}
|
||||
|
||||
/* Init the low level hardware */
|
||||
huart->MspInitCallback(huart);
|
||||
#else
|
||||
/* Init the low level hardware : GPIO, CLOCK, CORTEX */
|
||||
HAL_UART_MspInit(huart);
|
||||
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
|
||||
}
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_UART_DISABLE(huart);
|
||||
|
||||
/* Set the UART Communication parameters */
|
||||
if (UART_SetConfig(huart) == HAL_ERROR)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
|
||||
{
|
||||
UART_AdvFeatureConfig(huart);
|
||||
}
|
||||
|
||||
/* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */
|
||||
SET_BIT(huart->Instance->CR3, USART_CR3_DEM);
|
||||
|
||||
/* Set the Driver Enable polarity */
|
||||
MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, Polarity);
|
||||
|
||||
/* Set the Driver Enable assertion and deassertion times */
|
||||
temp = (AssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS);
|
||||
temp |= (DeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS);
|
||||
MODIFY_REG(huart->Instance->CR1, (USART_CR1_DEDT | USART_CR1_DEAT), temp);
|
||||
|
||||
/* Enable the Peripheral */
|
||||
__HAL_UART_ENABLE(huart);
|
||||
|
||||
/* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
|
||||
return (UART_CheckIdleState(huart));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup UARTEx_Exported_Functions_Group2 IO operation functions
|
||||
* @brief Extended functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
This subsection provides a set of Wakeup and FIFO mode related callback functions.
|
||||
|
||||
(#) Wakeup from Stop mode Callback:
|
||||
(+) HAL_UARTEx_WakeupCallback()
|
||||
|
||||
(#) TX/RX Fifos Callbacks:
|
||||
(+) HAL_UARTEx_RxFifoFullCallback()
|
||||
(+) HAL_UARTEx_TxFifoEmptyCallback()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief UART wakeup from Stop mode callback.
|
||||
* @param huart UART handle.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(huart);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_UARTEx_WakeupCallback can be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UART RX Fifo full callback.
|
||||
* @param huart UART handle.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_UARTEx_RxFifoFullCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(huart);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_UARTEx_RxFifoFullCallback can be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UART TX Fifo empty callback.
|
||||
* @param huart UART handle.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_UARTEx_TxFifoEmptyCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(huart);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_UARTEx_TxFifoEmptyCallback can be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup UARTEx_Exported_Functions_Group3 Peripheral Control functions
|
||||
* @brief Extended Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..] This section provides the following functions:
|
||||
(+) HAL_MultiProcessorEx_AddressLength_Set() API optionally sets the UART node address
|
||||
detection length to more than 4 bits for multiprocessor address mark wake up.
|
||||
(+) HAL_UARTEx_StopModeWakeUpSourceConfig() API defines the wake-up from stop mode
|
||||
trigger: address match, Start Bit detection or RXNE bit status.
|
||||
(+) HAL_UARTEx_EnableStopMode() API enables the UART to wake up the MCU from stop mode
|
||||
(+) HAL_UARTEx_DisableStopMode() API disables the above functionality
|
||||
(+) HAL_UARTEx_EnableFifoMode() API enables the FIFO mode
|
||||
(+) HAL_UARTEx_DisableFifoMode() API disables the FIFO mode
|
||||
(+) HAL_UARTEx_SetTxFifoThreshold() API sets the TX FIFO threshold
|
||||
(+) HAL_UARTEx_SetRxFifoThreshold() API sets the RX FIFO threshold
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief By default in multiprocessor mode, when the wake up method is set
|
||||
* to address mark, the UART handles only 4-bit long addresses detection;
|
||||
* this API allows to enable longer addresses detection (6-, 7- or 8-bit
|
||||
* long).
|
||||
* @note Addresses detection lengths are: 6-bit address detection in 7-bit data mode,
|
||||
* 7-bit address detection in 8-bit data mode, 8-bit address detection in 9-bit data mode.
|
||||
* @param huart UART handle.
|
||||
* @param AddressLength This parameter can be one of the following values:
|
||||
* @arg @ref UART_ADDRESS_DETECT_4B 4-bit long address
|
||||
* @arg @ref UART_ADDRESS_DETECT_7B 6-, 7- or 8-bit long address
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength)
|
||||
{
|
||||
/* Check the UART handle allocation */
|
||||
if (huart == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the address length parameter */
|
||||
assert_param(IS_UART_ADDRESSLENGTH_DETECT(AddressLength));
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_UART_DISABLE(huart);
|
||||
|
||||
/* Set the address length */
|
||||
MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, AddressLength);
|
||||
|
||||
/* Enable the Peripheral */
|
||||
__HAL_UART_ENABLE(huart);
|
||||
|
||||
/* TEACK and/or REACK to check before moving huart->gState to Ready */
|
||||
return (UART_CheckIdleState(huart));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Wakeup from Stop mode interrupt flag selection.
|
||||
* @note It is the application responsibility to enable the interrupt used as
|
||||
* usart_wkup interrupt source before entering low-power mode.
|
||||
* @param huart UART handle.
|
||||
* @param WakeUpSelection Address match, Start Bit detection or RXNE/RXFNE bit status.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref UART_WAKEUP_ON_ADDRESS
|
||||
* @arg @ref UART_WAKEUP_ON_STARTBIT
|
||||
* @arg @ref UART_WAKEUP_ON_READDATA_NONEMPTY
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint32_t tickstart;
|
||||
|
||||
/* check the wake-up from stop mode UART instance */
|
||||
assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
|
||||
/* check the wake-up selection parameter */
|
||||
assert_param(IS_UART_WAKEUP_SELECTION(WakeUpSelection.WakeUpEvent));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(huart);
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_UART_DISABLE(huart);
|
||||
|
||||
/* Set the wake-up selection scheme */
|
||||
MODIFY_REG(huart->Instance->CR3, USART_CR3_WUS, WakeUpSelection.WakeUpEvent);
|
||||
|
||||
if (WakeUpSelection.WakeUpEvent == UART_WAKEUP_ON_ADDRESS)
|
||||
{
|
||||
UARTEx_Wakeup_AddressConfig(huart, WakeUpSelection);
|
||||
}
|
||||
|
||||
/* Enable the Peripheral */
|
||||
__HAL_UART_ENABLE(huart);
|
||||
|
||||
/* Init tickstart for timeout managment*/
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait until REACK flag is set */
|
||||
if (UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
|
||||
{
|
||||
status = HAL_TIMEOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Initialize the UART State */
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable UART Stop Mode.
|
||||
* @note The UART is able to wake up the MCU from Stop 1 mode as long as UART clock is HSI or LSE.
|
||||
* @param huart UART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(huart);
|
||||
|
||||
/* Set UESM bit */
|
||||
SET_BIT(huart->Instance->CR1, USART_CR1_UESM);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable UART Stop Mode.
|
||||
* @param huart UART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(huart);
|
||||
|
||||
/* Clear UESM bit */
|
||||
CLEAR_BIT(huart->Instance->CR1, USART_CR1_UESM);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the FIFO mode.
|
||||
* @param huart UART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_EnableFifoMode(UART_HandleTypeDef *huart)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(huart);
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Save actual UART configuration */
|
||||
tmpcr1 = READ_REG(huart->Instance->CR1);
|
||||
|
||||
/* Disable UART */
|
||||
__HAL_UART_DISABLE(huart);
|
||||
|
||||
/* Enable FIFO mode */
|
||||
SET_BIT(tmpcr1, USART_CR1_FIFOEN);
|
||||
huart->FifoMode = UART_FIFOMODE_ENABLE;
|
||||
|
||||
/* Restore UART configuration */
|
||||
WRITE_REG(huart->Instance->CR1, tmpcr1);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
UARTEx_SetNbDataToProcess(huart);
|
||||
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the FIFO mode.
|
||||
* @param huart UART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_DisableFifoMode(UART_HandleTypeDef *huart)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(huart);
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Save actual UART configuration */
|
||||
tmpcr1 = READ_REG(huart->Instance->CR1);
|
||||
|
||||
/* Disable UART */
|
||||
__HAL_UART_DISABLE(huart);
|
||||
|
||||
/* Enable FIFO mode */
|
||||
CLEAR_BIT(tmpcr1, USART_CR1_FIFOEN);
|
||||
huart->FifoMode = UART_FIFOMODE_DISABLE;
|
||||
|
||||
/* Restore UART configuration */
|
||||
WRITE_REG(huart->Instance->CR1, tmpcr1);
|
||||
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the TXFIFO threshold.
|
||||
* @param huart UART handle.
|
||||
* @param Threshold TX FIFO threshold value
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref UART_TXFIFO_THRESHOLD_1_8
|
||||
* @arg @ref UART_TXFIFO_THRESHOLD_1_4
|
||||
* @arg @ref UART_TXFIFO_THRESHOLD_1_2
|
||||
* @arg @ref UART_TXFIFO_THRESHOLD_3_4
|
||||
* @arg @ref UART_TXFIFO_THRESHOLD_7_8
|
||||
* @arg @ref UART_TXFIFO_THRESHOLD_8_8
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_SetTxFifoThreshold(UART_HandleTypeDef *huart, uint32_t Threshold)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
|
||||
assert_param(IS_UART_TXFIFO_THRESHOLD(Threshold));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(huart);
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Save actual UART configuration */
|
||||
tmpcr1 = READ_REG(huart->Instance->CR1);
|
||||
|
||||
/* Disable UART */
|
||||
__HAL_UART_DISABLE(huart);
|
||||
|
||||
/* Update TX threshold configuration */
|
||||
MODIFY_REG(huart->Instance->CR3, USART_CR3_TXFTCFG, Threshold);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
UARTEx_SetNbDataToProcess(huart);
|
||||
|
||||
/* Restore UART configuration */
|
||||
WRITE_REG(huart->Instance->CR1, tmpcr1);
|
||||
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the RXFIFO threshold.
|
||||
* @param huart UART handle.
|
||||
* @param Threshold RX FIFO threshold value
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref UART_RXFIFO_THRESHOLD_1_8
|
||||
* @arg @ref UART_RXFIFO_THRESHOLD_1_4
|
||||
* @arg @ref UART_RXFIFO_THRESHOLD_1_2
|
||||
* @arg @ref UART_RXFIFO_THRESHOLD_3_4
|
||||
* @arg @ref UART_RXFIFO_THRESHOLD_7_8
|
||||
* @arg @ref UART_RXFIFO_THRESHOLD_8_8
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_SetRxFifoThreshold(UART_HandleTypeDef *huart, uint32_t Threshold)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
|
||||
assert_param(IS_UART_RXFIFO_THRESHOLD(Threshold));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(huart);
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Save actual UART configuration */
|
||||
tmpcr1 = READ_REG(huart->Instance->CR1);
|
||||
|
||||
/* Disable UART */
|
||||
__HAL_UART_DISABLE(huart);
|
||||
|
||||
/* Update RX threshold configuration */
|
||||
MODIFY_REG(huart->Instance->CR3, USART_CR3_RXFTCFG, Threshold);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
UARTEx_SetNbDataToProcess(huart);
|
||||
|
||||
/* Restore UART configuration */
|
||||
WRITE_REG(huart->Instance->CR1, tmpcr1);
|
||||
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup UARTEx_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the UART wake-up from stop mode parameters when triggered by address detection.
|
||||
* @param huart UART handle.
|
||||
* @param WakeUpSelection UART wake up from stop mode parameters.
|
||||
* @retval None
|
||||
*/
|
||||
static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
|
||||
{
|
||||
assert_param(IS_UART_ADDRESSLENGTH_DETECT(WakeUpSelection.AddressLength));
|
||||
|
||||
/* Set the USART address length */
|
||||
MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, WakeUpSelection.AddressLength);
|
||||
|
||||
/* Set the USART address node */
|
||||
MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)WakeUpSelection.Address << UART_CR2_ADDRESS_LSB_POS));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate the number of data to process in RX/TX ISR.
|
||||
* @note The RX FIFO depth and the TX FIFO depth is extracted from
|
||||
* the UART configuration registers.
|
||||
* @param huart UART handle.
|
||||
* @retval None
|
||||
*/
|
||||
static void UARTEx_SetNbDataToProcess(UART_HandleTypeDef *huart)
|
||||
{
|
||||
uint8_t rx_fifo_depth;
|
||||
uint8_t tx_fifo_depth;
|
||||
uint8_t rx_fifo_threshold;
|
||||
uint8_t tx_fifo_threshold;
|
||||
uint8_t numerator[] = {1U, 1U, 1U, 3U, 7U, 1U, 0U, 0U};
|
||||
uint8_t denominator[] = {8U, 4U, 2U, 4U, 8U, 1U, 1U, 1U};
|
||||
|
||||
if (huart->FifoMode == UART_FIFOMODE_DISABLE)
|
||||
{
|
||||
huart->NbTxDataToProcess = 1U;
|
||||
huart->NbRxDataToProcess = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx_fifo_depth = RX_FIFO_DEPTH;
|
||||
tx_fifo_depth = TX_FIFO_DEPTH;
|
||||
rx_fifo_threshold = (uint8_t)(READ_BIT(huart->Instance->CR3, USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos);
|
||||
tx_fifo_threshold = (uint8_t)(READ_BIT(huart->Instance->CR3, USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos);
|
||||
huart->NbTxDataToProcess = ((uint16_t)tx_fifo_depth * numerator[tx_fifo_threshold]) / (uint16_t)denominator[tx_fifo_threshold];
|
||||
huart->NbRxDataToProcess = ((uint16_t)rx_fifo_depth * numerator[rx_fifo_threshold]) / (uint16_t)denominator[rx_fifo_threshold];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
Reference in New Issue
Block a user