first commit
This commit is contained in:
+995
@@ -0,0 +1,995 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief HAL module driver.
|
||||
* This is the common part of the HAL initialization
|
||||
*
|
||||
@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
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL HAL
|
||||
* @brief HAL module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief STM32H7xx HAL Driver version number V1.2.0
|
||||
*/
|
||||
#define __STM32H7xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */
|
||||
#define __STM32H7xx_HAL_VERSION_SUB1 (0x02) /*!< [23:16] sub1 version */
|
||||
#define __STM32H7xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
|
||||
#define __STM32H7xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */
|
||||
#define __STM32H7xx_HAL_VERSION ((__STM32H7xx_HAL_VERSION_MAIN << 24)\
|
||||
|(__STM32H7xx_HAL_VERSION_SUB1 << 16)\
|
||||
|(__STM32H7xx_HAL_VERSION_SUB2 << 8 )\
|
||||
|(__STM32H7xx_HAL_VERSION_RC))
|
||||
|
||||
#define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
|
||||
#define VREFBUF_TIMEOUT_VALUE (uint32_t)10 /* 10 ms */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static __IO uint32_t uwTick;
|
||||
static uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
|
||||
static 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 16 MHz).
|
||||
* Set NVIC Group Priority to 4.
|
||||
* Calls the HAL_MspInit() callback function defined in user file
|
||||
* "stm32h7xx_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 */
|
||||
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
|
||||
|
||||
/* 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 */
|
||||
__HAL_RCC_AHB3_FORCE_RESET();
|
||||
__HAL_RCC_AHB3_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_AHB1_FORCE_RESET();
|
||||
__HAL_RCC_AHB1_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_AHB2_FORCE_RESET();
|
||||
__HAL_RCC_AHB2_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_AHB4_FORCE_RESET();
|
||||
__HAL_RCC_AHB4_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_APB3_FORCE_RESET();
|
||||
__HAL_RCC_APB3_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_APB1L_FORCE_RESET();
|
||||
__HAL_RCC_APB1L_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_APB1H_FORCE_RESET();
|
||||
__HAL_RCC_APB1H_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_APB2_FORCE_RESET();
|
||||
__HAL_RCC_APB2_RELEASE_RESET();
|
||||
|
||||
__HAL_RCC_APB4_FORCE_RESET();
|
||||
__HAL_RCC_APB4_RELEASE_RESET();
|
||||
|
||||
/* 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 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;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
return uwTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
assert_param(IS_TICKFREQ(Freq));
|
||||
|
||||
if (uwTickFreq != Freq)
|
||||
{
|
||||
uwTickFreq = Freq;
|
||||
|
||||
/* Apply the new tick Freq */
|
||||
status = HAL_InitTick(uwTickPrio);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return tick frequency.
|
||||
* @retval tick period in Hz
|
||||
*/
|
||||
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
|
||||
{
|
||||
return uwTickFreq;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function provides minimum 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)
|
||||
{
|
||||
/* Disable SysTick Interrupt */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
/* Enable SysTick Interrupt */
|
||||
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the HAL revision
|
||||
* @retval version : 0xXYZR (8bits for each decimal, R for RC)
|
||||
*/
|
||||
uint32_t HAL_GetHalVersion(void)
|
||||
{
|
||||
return __STM32H7xx_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 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_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));
|
||||
|
||||
MODIFY_REG(SYSCFG->PMCR, SYCFG_PMCR_EPIS_SEL, (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
|
||||
* @arg SYSCFG_SWITCH_PC2 : Select PC2 analog switch
|
||||
* @arg SYSCFG_SWITCH_PC3: Select PC3 analog switch
|
||||
* @param SYSCFG_SwitchState: Open or Close the analog switch between dual pads (PXn and PXn_C)
|
||||
* 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
|
||||
* @arg SYSCFG_SWITCH_PC2_OPEN
|
||||
* @arg SYSCFG_SWITCH_PC2_CLOSE
|
||||
* @arg SYSCFG_SWITCH_PC3_OPEN
|
||||
* @arg SYSCFG_SWITCH_PC3_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));
|
||||
|
||||
MODIFY_REG(SYSCFG->PMCR, (uint32_t) SYSCFG_AnalogSwitch, (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)
|
||||
{
|
||||
SET_BIT(SYSCFG->PMCR, SYSCFG_PMCR_BOOSTEN) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
CLEAR_BIT(SYSCFG->PMCR, SYSCFG_PMCR_BOOSTEN) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief BootCM7 address 0 configuration
|
||||
* @param BootRegister :Specifies the Boot Address register (Address0 or Address1)
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SYSCFG_BOOT_ADDR0 : Select the boot address0
|
||||
* @arg SYSCFG_BOOT_ADDR1: Select the boot address1
|
||||
* @param BootAddress :Specifies the CM7 Boot Address to be loaded in Address0 or Address1
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_CM7BootAddConfig(uint32_t BootRegister, uint32_t BootAddress)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSCFG_BOOT_REGISTER(BootRegister));
|
||||
assert_param(IS_SYSCFG_BOOT_ADDRESS(BootAddress));
|
||||
if ( BootRegister == SYSCFG_BOOT_ADDR0 )
|
||||
{
|
||||
/* Configure CM7 BOOT ADD0 */
|
||||
MODIFY_REG(SYSCFG->UR2, SYSCFG_UR2_BOOT_ADD0, ((BootAddress >> 16) << POSITION_VAL(SYSCFG_UR2_BOOT_ADD0)));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Configure CM7 BOOT ADD1 */
|
||||
MODIFY_REG(SYSCFG->UR3, SYSCFG_UR3_BOOT_ADD1, (BootAddress >> 16));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
SET_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_EN) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
CLEAR_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_EN) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_EnableIOSpeedOptimize(void)
|
||||
{
|
||||
SET_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_HSLV) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSCFG_DisableIOSpeedOptimize(void)
|
||||
{
|
||||
CLEAR_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_HSLV) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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->CCCSR, SYSCFG_CCCSR_CS, (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->CCCR, SYSCFG_CCCR_NCC|SYSCFG_CCCR_PCC, (((uint32_t)(SYSCFG_PMOSCode)<< 4)|(uint32_t)(SYSCFG_NMOSCode)) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain1 SLEEP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDBGSleepMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEPD1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain1 SLEEP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDBGSleepMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEPD1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain1 STOP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDBGStopMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain1 STOP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDBGStopMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain1 STANDBY mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDBGStandbyMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain1 STANDBY mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDBGStandbyMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain3 STOP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDomain3DBGStopMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain3 STOP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDomain3DBGStopMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during Domain3 STANDBY mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EnableDomain3DBGStandbyMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during Domain3 STANDBY mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DisableDomain3DBGStandbyMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the FMC Memory Mapping Swapping config.
|
||||
* @param BankMapConfig: Defines the FMC Bank mapping configuration. This parameter can be
|
||||
FMC_SWAPBMAP_DISABLE, FMC_SWAPBMAP_SDRAM_SRAM, FMC_SWAPBMAP_SDRAMB2
|
||||
* @retval HAL state
|
||||
*/
|
||||
void HAL_SetFMCMemorySwappingConfig(uint32_t BankMapConfig)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_FMC_SWAPBMAP_MODE(BankMapConfig));
|
||||
MODIFY_REG(FMC_Bank1->BTCR[0], FMC_BCR1_BMAP, BankMapConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get FMC Bank mapping mode.
|
||||
* @retval The FMC Bank mapping mode. This parameter can be
|
||||
FMC_SWAPBMAP_DISABLE, FMC_SWAPBMAP_SDRAM_SRAM, FMC_SWAPBMAP_SDRAMB2
|
||||
*/
|
||||
uint32_t HAL_GetFMCMemorySwappingConfig(void)
|
||||
{
|
||||
return READ_BIT(FMC_Bank1->BTCR[0], FMC_BCR1_BMAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the EXTI input event line edge
|
||||
* @note No edge configuration for direct lines but for configurable lines:(EXTI_LINE0..EXTI_LINE21),
|
||||
* EXTI_LINE49,EXTI_LINE51,EXTI_LINE82,EXTI_LINE84,EXTI_LINE85 and EXTI_LINE86.
|
||||
* @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
|
||||
* (EXTI_LINE0....EXTI_LINE88)excluding :line45, line81,line83 which are reserved
|
||||
* @param EXTI_Edge: Specifies EXTI line Edge used.
|
||||
* This parameter can be one of the following values :
|
||||
* @arg EXTI_RISING_EDGE : Configurable line, with Rising edge trigger detection
|
||||
* @arg EXTI_FALLING_EDGE: Configurable line, with Falling edge trigger detection
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EXTI_EdgeConfig(uint32_t EXTI_Line , uint32_t EXTI_Edge )
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_EXTI_CONFIG_LINE(EXTI_Line));
|
||||
assert_param(IS_EXTI_EDGE_LINE(EXTI_Edge));
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
CLEAR_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR1)) + ((EXTI_Line >> 5 ) * 0x20)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
CLEAR_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR1)) + ((EXTI_Line >> 5 ) * 0x20)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
|
||||
if( (EXTI_Edge & EXTI_RISING_EDGE) == EXTI_RISING_EDGE)
|
||||
{
|
||||
SET_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR1)) + ((EXTI_Line >> 5 ) * 0x20)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
}
|
||||
if( (EXTI_Edge & EXTI_FALLING_EDGE) == EXTI_FALLING_EDGE)
|
||||
{
|
||||
SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR1)) + ((EXTI_Line >> 5 ) * 0x20)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generates a Software interrupt on selected EXTI line.
|
||||
* @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
|
||||
* (EXTI_LINE0..EXTI_LINE21),EXTI_LINE49,EXTI_LINE51,EXTI_LINE82,EXTI_LINE84,EXTI_LINE85 and EXTI_LINE86.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_CONFIG_LINE(EXTI_Line));
|
||||
|
||||
SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->SWIER1)) + ((EXTI_Line >> 5 ) * 0x20)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clears the EXTI's line pending flags for Domain D1
|
||||
* @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
|
||||
* (EXTI_LINE0....EXTI_LINE88)excluding :line45, line81,line83 which are reserved
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EXTI_D1_ClearFlag(uint32_t EXTI_Line)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_D1_LINE(EXTI_Line));
|
||||
SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI_D1->PR1)) + ((EXTI_Line >> 5 ) * 0x10)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the EXTI input event line for Domain D1
|
||||
* @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
|
||||
* (EXTI_LINE0....EXTI_LINE88)excluding :line45, line81,line83 which are reserved
|
||||
* @param EXTI_Mode: Specifies which EXTI line is used as interrupt or an event.
|
||||
* This parameter can be one or a combination of the following values :
|
||||
* @arg EXTI_MODE_IT : Interrupt Mode selected
|
||||
* @arg EXTI_MODE_EVT : Event Mode selected
|
||||
* @param EXTI_LineCmd controls (Enable/Disable) the EXTI line.
|
||||
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EXTI_D1_EventInputConfig(uint32_t EXTI_Line , uint32_t EXTI_Mode, uint32_t EXTI_LineCmd )
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_EXTI_D1_LINE(EXTI_Line));
|
||||
assert_param(IS_EXTI_MODE_LINE(EXTI_Mode));
|
||||
|
||||
if( (EXTI_Mode & EXTI_MODE_IT) == EXTI_MODE_IT)
|
||||
{
|
||||
if( EXTI_LineCmd == DISABLE)
|
||||
{
|
||||
/* Clear EXTI line configuration */
|
||||
CLEAR_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI_D1->IMR1)) + ((EXTI_Line >> 5 ) * 0x10)),(uint32_t)(1 << (EXTI_Line & 0x1F)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI_D1->IMR1)) + ((EXTI_Line >> 5 ) * 0x10)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
}
|
||||
}
|
||||
if( (EXTI_Mode & EXTI_MODE_EVT) == EXTI_MODE_EVT)
|
||||
{
|
||||
if( EXTI_LineCmd == DISABLE)
|
||||
{
|
||||
/* Clear EXTI line configuration */
|
||||
CLEAR_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI_D1->EMR1)) + ((EXTI_Line >> 5 ) * 0x10)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI_D1->EMR1)) + ((EXTI_Line >> 5 ) * 0x10)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configure the EXTI input event line for Domain D3
|
||||
* @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
|
||||
* (EXTI_LINE0...EXTI_LINE15),(EXTI_LINE19...EXTI_LINE21),EXTI_LINE25, EXTI_LINE34,
|
||||
* EXTI_LINE35,EXTI_LINE41,(EXTI_LINE48...EXTI_LINE53),EXTI_LINE88
|
||||
* @param EXTI_LineCmd controls (Enable/Disable) the EXTI line.
|
||||
* @param EXTI_ClearSrc: Specifies the clear source of D3 pending event.
|
||||
* This parameter can be one of the following values :
|
||||
* @arg BDMA_CH6_CLEAR : BDMA ch6 event selected as D3 domain pendclear source
|
||||
* @arg BDMA_CH7_CLEAR : BDMA ch7 event selected as D3 domain pendclear source
|
||||
* @arg LPTIM4_OUT_CLEAR : LPTIM4 out selected as D3 domain pendclear source
|
||||
* @arg LPTIM5_OUT_CLEAR : LPTIM5 out selected as D3 domain pendclear source
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_EXTI_D3_EventInputConfig(uint32_t EXTI_Line, uint32_t EXTI_LineCmd , uint32_t EXTI_ClearSrc )
|
||||
{
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_EXTI_D3_LINE(EXTI_Line));
|
||||
assert_param(IS_EXTI_D3_CLEAR(EXTI_ClearSrc));
|
||||
|
||||
if( EXTI_LineCmd == DISABLE)
|
||||
{
|
||||
/* Clear EXTI line configuration */
|
||||
CLEAR_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->D3PMR1)) + ((EXTI_Line >> 5 ) * 0x20)),(uint32_t)(1 << (EXTI_Line & 0x1F)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->D3PMR1)) +((EXTI_Line >> 5 ) * 0x20)), (uint32_t)(1 << (EXTI_Line & 0x1F)));
|
||||
}
|
||||
|
||||
|
||||
if ( (EXTI_Line>>4)%2 ==0)
|
||||
{
|
||||
MODIFY_REG(*(__IO uint32_t *) (((uint32_t) &(EXTI->D3PCR1L)) + ((EXTI_Line >> 5 ) * 0x20)), \
|
||||
(uint32_t)(3 << ((EXTI_Line*2) & 0x1F)), (uint32_t)(EXTI_ClearSrc << ((EXTI_Line*2) & 0x1F))) ;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
MODIFY_REG(*(__IO uint32_t *) (((uint32_t) &(EXTI->D3PCR1H)) + ((EXTI_Line >> 5 ) * 0x20)), \
|
||||
(uint32_t)(3 << ((EXTI_Line*2) & 0x1F)), (uint32_t)(EXTI_ClearSrc << ((EXTI_Line*2) & 0x1F))) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+3260
File diff suppressed because it is too large
Load Diff
+2539
File diff suppressed because it is too large
Load Diff
+665
@@ -0,0 +1,665 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_cec.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief CEC HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the High Definition Multimedia Interface
|
||||
* Consumer Electronics Control Peripheral (CEC).
|
||||
* + Initialization and de-initialization function
|
||||
* + IO operation function
|
||||
* + Peripheral Control function
|
||||
*
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
The CEC HAL driver can be used as follow:
|
||||
|
||||
(#) Declare a CEC_HandleTypeDef handle structure.
|
||||
(#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API:
|
||||
(##) Enable the CEC interface clock.
|
||||
(##) CEC pins configuration:
|
||||
(+++) Enable the clock for the CEC GPIOs.
|
||||
(+++) Configure these CEC pins as alternate function pull-up.
|
||||
(##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT()
|
||||
and HAL_CEC_Receive_IT() APIs):
|
||||
(+++) Configure the CEC interrupt priority.
|
||||
(+++) Enable the NVIC CEC IRQ handle.
|
||||
(+++) The specific CEC interrupts (Transmission complete interrupt,
|
||||
RXNE interrupt and Error Interrupts) will be managed using the macros
|
||||
__HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit
|
||||
and receive process.
|
||||
|
||||
(#) Program the Signal Free Time (SFT) and SFT option, Tolerance, reception stop in
|
||||
in case of Bit Rising Error, Error-Bit generation conditions, device logical
|
||||
address and Listen mode in the hcec Init structure.
|
||||
|
||||
(#) Initialize the CEC registers by calling the HAL_CEC_Init() API.
|
||||
|
||||
[..]
|
||||
(@) This API (HAL_CEC_Init()) configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc)
|
||||
by calling the customed HAL_CEC_MspInit() API.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CEC CEC
|
||||
* @brief HAL CEC module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_CEC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup CEC_Private_Constants CEC Private Constants
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup CEC_Private_Functions CEC Private Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup CEC_Exported_Functions CEC Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and Configuration functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to initialize the CEC
|
||||
(+) The following parameters need to be configured:
|
||||
(++) SignalFreeTime
|
||||
(++) Tolerance
|
||||
(++) BRERxStop (RX stopped or not upon Bit Rising Error)
|
||||
(++) BREErrorBitGen (Error-Bit generation in case of Bit Rising Error)
|
||||
(++) LBPEErrorBitGen (Error-Bit generation in case of Long Bit Period Error)
|
||||
(++) BroadcastMsgNoErrorBitGen (Error-bit generation in case of broadcast message error)
|
||||
(++) SignalFreeTimeOption (SFT Timer start definition)
|
||||
(++) OwnAddress (CEC device address)
|
||||
(++) ListenMode
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the CEC mode according to the specified
|
||||
* parameters in the CEC_InitTypeDef and creates the associated handle.
|
||||
* @param hcec: CEC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
/* Check the CEC handle allocation */
|
||||
if((hcec == NULL) ||(hcec->Init.RxBuffer == NULL))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
|
||||
assert_param(IS_CEC_SIGNALFREETIME(hcec->Init.SignalFreeTime));
|
||||
assert_param(IS_CEC_TOLERANCE(hcec->Init.Tolerance));
|
||||
assert_param(IS_CEC_BRERXSTOP(hcec->Init.BRERxStop));
|
||||
assert_param(IS_CEC_BREERRORBITGEN(hcec->Init.BREErrorBitGen));
|
||||
assert_param(IS_CEC_LBPEERRORBITGEN(hcec->Init.LBPEErrorBitGen));
|
||||
assert_param(IS_CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION(hcec->Init.BroadcastMsgNoErrorBitGen));
|
||||
assert_param(IS_CEC_SFTOP(hcec->Init.SignalFreeTimeOption));
|
||||
assert_param(IS_CEC_LISTENING_MODE(hcec->Init.ListenMode));
|
||||
assert_param(IS_CEC_OWN_ADDRESS(hcec->Init.OwnAddress));
|
||||
|
||||
if(hcec->gState == HAL_CEC_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hcec->Lock = HAL_UNLOCKED;
|
||||
/* Init the low level hardware : GPIO, CLOCK */
|
||||
HAL_CEC_MspInit(hcec);
|
||||
}
|
||||
hcec->gState = HAL_CEC_STATE_BUSY;
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_CEC_DISABLE(hcec);
|
||||
|
||||
/* Write to CEC Control Register */
|
||||
hcec->Instance->CFGR = hcec->Init.SignalFreeTime | hcec->Init.Tolerance | hcec->Init.BRERxStop|\
|
||||
hcec->Init.BREErrorBitGen | hcec->Init.LBPEErrorBitGen | hcec->Init.BroadcastMsgNoErrorBitGen |\
|
||||
hcec->Init.SignalFreeTimeOption |((uint32_t)(hcec->Init.OwnAddress)<<16U) |\
|
||||
hcec->Init.ListenMode;
|
||||
|
||||
/* Enable the following CEC Transmission/Reception interrupts as
|
||||
* well as the following CEC Transmission/Reception Errors interrupts
|
||||
* Rx Byte Received IT
|
||||
* End of Reception IT
|
||||
* Rx overrun
|
||||
* Rx bit rising error
|
||||
* Rx short bit period error
|
||||
* Rx long bit period error
|
||||
* Rx missing acknowledge
|
||||
* Tx Byte Request IT
|
||||
* End of Transmission IT
|
||||
* Tx Missing Acknowledge IT
|
||||
* Tx-Error IT
|
||||
* Tx-Buffer Underrun IT
|
||||
* Tx arbitration lost */
|
||||
__HAL_CEC_ENABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR);
|
||||
|
||||
/* Enable the CEC Peripheral */
|
||||
__HAL_CEC_ENABLE(hcec);
|
||||
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_NONE;
|
||||
hcec->gState = HAL_CEC_STATE_READY;
|
||||
hcec->RxState = HAL_CEC_STATE_READY;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the CEC peripheral
|
||||
* @param hcec: CEC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
/* Check the CEC handle allocation */
|
||||
if(hcec == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
|
||||
|
||||
hcec->gState = HAL_CEC_STATE_BUSY;
|
||||
|
||||
/* DeInit the low level hardware */
|
||||
HAL_CEC_MspDeInit(hcec);
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_CEC_DISABLE(hcec);
|
||||
|
||||
/* Clear Flags */
|
||||
__HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXEND|CEC_FLAG_TXBR|CEC_FLAG_RXBR|CEC_FLAG_RXEND|CEC_ISR_ALL_ERROR);
|
||||
|
||||
/* Disable the following CEC Transmission/Reception interrupts as
|
||||
* well as the following CEC Transmission/Reception Errors interrupts
|
||||
* Rx Byte Received IT
|
||||
* End of Reception IT
|
||||
* Rx overrun
|
||||
* Rx bit rising error
|
||||
* Rx short bit period error
|
||||
* Rx long bit period error
|
||||
* Rx missing acknowledge
|
||||
* Tx Byte Request IT
|
||||
* End of Transmission IT
|
||||
* Tx Missing Acknowledge IT
|
||||
* Tx-Error IT
|
||||
* Tx-Buffer Underrun IT
|
||||
* Tx arbitration lost */
|
||||
__HAL_CEC_DISABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR);
|
||||
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_NONE;
|
||||
hcec->gState = HAL_CEC_STATE_RESET;
|
||||
hcec->RxState = HAL_CEC_STATE_RESET;
|
||||
|
||||
/* Process Unlock */
|
||||
__HAL_UNLOCK(hcec);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the Own Address of the CEC device
|
||||
* @param hcec: CEC handle
|
||||
* @param CEC_OwnAddress: The CEC own address.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress));
|
||||
|
||||
if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY))
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hcec);
|
||||
|
||||
hcec->gState = HAL_CEC_STATE_BUSY;
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_CEC_DISABLE(hcec);
|
||||
|
||||
if(CEC_OwnAddress != CEC_OWN_ADDRESS_NONE)
|
||||
{
|
||||
hcec->Instance->CFGR |= ((uint32_t)CEC_OwnAddress<<16);
|
||||
}
|
||||
else
|
||||
{
|
||||
hcec->Instance->CFGR &= ~(CEC_CFGR_OAR);
|
||||
}
|
||||
|
||||
hcec->gState = HAL_CEC_STATE_READY;
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_NONE;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hcec);
|
||||
|
||||
/* Enable the Peripheral */
|
||||
__HAL_CEC_ENABLE(hcec);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CEC MSP Init
|
||||
* @param hcec: CEC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcec);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_CEC_MspInit can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CEC MSP DeInit
|
||||
* @param hcec: CEC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcec);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_CEC_MspDeInit can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions
|
||||
* @brief CEC Transmit/Receive functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
This subsection provides a set of functions allowing to manage the CEC data transfers.
|
||||
|
||||
(#) The CEC handle must contain the initiator (TX side) and the destination (RX side)
|
||||
logical addresses (4-bit long addresses, 0xF for broadcast messages destination)
|
||||
|
||||
(#) The communication is performed using Interrupts.
|
||||
These API's return the HAL status.
|
||||
The end of the data processing will be indicated through the
|
||||
dedicated CEC IRQ when using Interrupt mode.
|
||||
The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks
|
||||
will be executed respectively at the end of the transmit or Receive process
|
||||
The HAL_CEC_ErrorCallback() user callback will be executed when a communication
|
||||
error is detected
|
||||
|
||||
(#) API's with Interrupt are :
|
||||
(+) HAL_CEC_Transmit_IT()
|
||||
(+) HAL_CEC_IRQHandler()
|
||||
|
||||
(#) A set of User Callbacks are provided:
|
||||
(+) HAL_CEC_TxCpltCallback()
|
||||
(+) HAL_CEC_RxCpltCallback()
|
||||
(+) HAL_CEC_ErrorCallback()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Send data in interrupt mode
|
||||
* @param hcec: CEC handle
|
||||
* @param InitiatorAddress: Initiator address
|
||||
* @param DestinationAddress: destination logical address
|
||||
* @param pData: pointer to input byte data buffer
|
||||
* @param Size: amount of data to be sent in bytes (without counting the header).
|
||||
* 0 means only the header is sent (ping operation).
|
||||
* Maximum TX size is 15 bytes (1 opcode and up to 14 operands).
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress,uint8_t DestinationAddress, uint8_t *pData, uint32_t Size)
|
||||
{
|
||||
/* if the IP isn't already busy and if there is no previous transmission
|
||||
already pending due to arbitration lost */
|
||||
if (hcec->gState == HAL_CEC_STATE_READY)
|
||||
{
|
||||
if((pData == NULL ) && (Size > 0))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
assert_param(IS_CEC_ADDRESS(DestinationAddress));
|
||||
assert_param(IS_CEC_ADDRESS(InitiatorAddress));
|
||||
assert_param(IS_CEC_MSGSIZE(Size));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hcec);
|
||||
hcec->pTxBuffPtr = pData;
|
||||
hcec->gState = HAL_CEC_STATE_BUSY_TX;
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_NONE;
|
||||
|
||||
/* initialize the number of bytes to send,
|
||||
* 0 means only one header is sent (ping operation) */
|
||||
hcec->TxXferCount = Size;
|
||||
|
||||
/* in case of no payload (Size = 0), sender is only pinging the system;
|
||||
Set TX End of Message (TXEOM) bit, must be set before writing data to TXDR */
|
||||
if (Size == 0)
|
||||
{
|
||||
__HAL_CEC_LAST_BYTE_TX_SET(hcec);
|
||||
}
|
||||
/* send header block */
|
||||
hcec->Instance->TXDR = ((uint8_t)(InitiatorAddress << CEC_INITIATOR_LSB_POS) |(uint8_t) DestinationAddress);
|
||||
/* Set TX Start of Message (TXSOM) bit */
|
||||
__HAL_CEC_FIRST_BYTE_TX_SET(hcec);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hcec);
|
||||
|
||||
return HAL_OK;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get size of the received frame.
|
||||
* @param hcec: CEC handle
|
||||
* @retval Frame size
|
||||
*/
|
||||
uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
return hcec->RxXferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Change Rx Buffer.
|
||||
* @param hcec: CEC handle
|
||||
* @param Rxbuffer: Rx Buffer
|
||||
* @note This function can be called only inside the HAL_CEC_RxCpltCallback()
|
||||
* @retval Frame size
|
||||
*/
|
||||
void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer)
|
||||
{
|
||||
hcec->Init.RxBuffer = Rxbuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CEC interrupt requests.
|
||||
* @param hcec: CEC handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
/* save interrupts register for further error or interrupts handling purposes */
|
||||
uint32_t reg = 0;
|
||||
reg = hcec->Instance->ISR;
|
||||
|
||||
/*----------------------- Arbitration Lost Management ----------------------*/
|
||||
/* CEC TX arbitration error interrupt occurred -----------------------------*/
|
||||
if((reg & CEC_FLAG_ARBLST) != RESET)
|
||||
{
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_ARBLST;
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_ARBLST);
|
||||
}
|
||||
|
||||
/*------------------------------ Rx Management -----------------------------*/
|
||||
/* CEC RX byte received interrupt -----------------------------------------*/
|
||||
if((reg & CEC_FLAG_RXBR) != RESET)
|
||||
{
|
||||
/* reception is starting */
|
||||
hcec->RxState = HAL_CEC_STATE_BUSY_RX;
|
||||
hcec->RxXferSize++;
|
||||
/* read received byte */
|
||||
*hcec->Init.RxBuffer++ = hcec->Instance->RXDR;
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXBR);
|
||||
}
|
||||
|
||||
/* CEC RX end received interrupt ------------------------------------------*/
|
||||
if((reg & CEC_FLAG_RXEND) != RESET)
|
||||
{
|
||||
/* clear IT */
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXEND);
|
||||
|
||||
/* Rx process is completed, restore hcec->RxState to Ready */
|
||||
hcec->RxState = HAL_CEC_STATE_READY;
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_NONE;
|
||||
hcec->Init.RxBuffer-=hcec->RxXferSize;
|
||||
HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize);
|
||||
hcec->RxXferSize = 0;
|
||||
}
|
||||
|
||||
/*------------------------------ Tx Management -----------------------------*/
|
||||
/* CEC TX byte request interrupt -------------------------------------------*/
|
||||
if((reg & CEC_FLAG_TXBR) != RESET)
|
||||
{
|
||||
if (hcec->TxXferCount == 0)
|
||||
{
|
||||
/* if this is the last byte transmission, set TX End of Message (TXEOM) bit */
|
||||
__HAL_CEC_LAST_BYTE_TX_SET(hcec);
|
||||
hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
|
||||
hcec->TxXferCount--;
|
||||
}
|
||||
/* clear Tx-Byte request flag */
|
||||
__HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXBR);
|
||||
}
|
||||
|
||||
/* CEC TX end interrupt ----------------------------------------------------*/
|
||||
if((reg & CEC_FLAG_TXEND) != RESET)
|
||||
{
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXEND);
|
||||
|
||||
/* Tx process is ended, restore hcec->gState to Ready */
|
||||
hcec->gState = HAL_CEC_STATE_READY;
|
||||
/* Call the Process Unlocked before calling the Tx call back API to give the
|
||||
possibility to start again the Transmission under the Tx call back API */
|
||||
__HAL_UNLOCK(hcec);
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_NONE;
|
||||
HAL_CEC_TxCpltCallback(hcec);
|
||||
}
|
||||
|
||||
/*------------------------- Rx/Tx Error Management -------------------------*/
|
||||
if ((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE|CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != 0)
|
||||
{
|
||||
hcec->ErrorCode = reg;
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, HAL_CEC_ERROR_RXOVR|HAL_CEC_ERROR_BRE|CEC_FLAG_LBPE|CEC_FLAG_SBPE|HAL_CEC_ERROR_RXACKE|HAL_CEC_ERROR_TXUDR|HAL_CEC_ERROR_TXERR|HAL_CEC_ERROR_TXACKE);
|
||||
|
||||
if((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE)) != RESET)
|
||||
{
|
||||
hcec->Init.RxBuffer-=hcec->RxXferSize;
|
||||
hcec->RxXferSize = 0;
|
||||
hcec->RxState = HAL_CEC_STATE_READY;
|
||||
}
|
||||
else if (((reg & (CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != RESET) && ((reg & CEC_ISR_ARBLST) == RESET))
|
||||
{
|
||||
/* Set the CEC state ready to be able to start again the process */
|
||||
hcec->gState = HAL_CEC_STATE_READY;
|
||||
}
|
||||
|
||||
/* Error Call Back */
|
||||
HAL_CEC_ErrorCallback(hcec);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Transfer completed callback
|
||||
* @param hcec: CEC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcec);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_CEC_TxCpltCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Transfer completed callback
|
||||
* @param hcec: CEC handle
|
||||
* @param RxFrameSize: Size of frame
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcec);
|
||||
UNUSED(RxFrameSize);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_CEC_RxCpltCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CEC error callbacks
|
||||
* @param hcec: CEC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcec);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_CEC_ErrorCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CEC_Exported_Functions_Group3 Peripheral Control function
|
||||
* @brief CEC control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control function #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the CEC.
|
||||
(+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral.
|
||||
(+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief return the CEC state
|
||||
* @param hcec: pointer to a CEC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified CEC module.
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
uint32_t temp1= 0x00U, temp2 = 0x00U;
|
||||
temp1 = hcec->gState;
|
||||
temp2 = hcec->RxState;
|
||||
|
||||
return (HAL_CEC_StateTypeDef)(temp1 | temp2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the CEC error code
|
||||
* @param hcec : pointer to a CEC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified CEC.
|
||||
* @retval CEC Error Code
|
||||
*/
|
||||
uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
return hcec->ErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_CEC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+850
@@ -0,0 +1,850 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_comp.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief COMP HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the COMP peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + Start/Stop operation functions in polling mode
|
||||
* + Start/Stop operation functions in interrupt mode
|
||||
* + Peripheral control functions
|
||||
* + Peripheral state functions
|
||||
@verbatim
|
||||
================================================================================
|
||||
##### COMP Peripheral features #####
|
||||
================================================================================
|
||||
|
||||
[..]
|
||||
The STM32H7xx device family integrates two analog comparators instances
|
||||
COMP1 and COMP2:
|
||||
(#) The COMP input minus (inverting input) and input plus (non inverting input)
|
||||
can be set to internal references or to GPIO pins
|
||||
(refer to GPIO list in reference manual).
|
||||
|
||||
(#) The COMP output level is available using HAL_COMP_GetOutputLevel()
|
||||
and can be redirected to other peripherals: GPIO pins (in mode
|
||||
alternate functions for comparator), timers.
|
||||
(refer to GPIO list in reference manual).
|
||||
|
||||
(#) Pairs of comparators instances can be combined in window mode
|
||||
(2 consecutive instances odd and even COMP<x> and COMP<x+1>).
|
||||
|
||||
(#) The comparators have interrupt capability through the EXTI controller
|
||||
with wake-up from sleep and stop modes:
|
||||
(++) COMP1 is internally connected to EXTI Line 20
|
||||
(++) COMP2 is internally connected to EXTI Line 21
|
||||
|
||||
[..]
|
||||
From the corresponding IRQ handler, the right interrupt source can be retrieved
|
||||
using macro __HAL_COMP_COMP1_EXTI_GET_FLAG() and __HAL_COMP_COMP2_EXTI_GET_FLAG().
|
||||
|
||||
|
||||
|
||||
##### How to use this driver #####
|
||||
================================================================================
|
||||
[..]
|
||||
This driver provides functions to configure and program the comparator instances of
|
||||
STM32H7xx devices.
|
||||
|
||||
To use the comparator, perform the following steps:
|
||||
|
||||
(#) Initialize the COMP low level resources by implementing the HAL_COMP_MspInit():
|
||||
(++) Configure the GPIO connected to comparator inputs plus and minus in analog mode
|
||||
using HAL_GPIO_Init().
|
||||
(++) If needed, configure the GPIO connected to comparator output in alternate function mode
|
||||
using HAL_GPIO_Init().
|
||||
(++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and
|
||||
selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
|
||||
interrupt vector using HAL_NVIC_EnableIRQ() function.
|
||||
|
||||
(#) Configure the comparator using HAL_COMP_Init() function:
|
||||
(++) Select the input minus (inverting input)
|
||||
(++) Select the input plus (non-inverting input)
|
||||
(++) Select the hysteresis
|
||||
(++) Select the blanking source
|
||||
(++) Select the output polarity
|
||||
(++) Select the power mode
|
||||
(++) Select the window mode
|
||||
-@@- HAL_COMP_Init() calls internally __HAL_RCC_SYSCFG_CLK_ENABLE()
|
||||
to enable internal control clock of the comparators.
|
||||
However, this is a legacy strategy.
|
||||
Therefore, for compatibility anticipation, it is recommended to
|
||||
implement __HAL_RCC_SYSCFG_CLK_ENABLE() in "HAL_COMP_MspInit()".
|
||||
In STM32H7,COMP clock enable __HAL_RCC_COMP12_CLK_ENABLE() must
|
||||
be implemented by user in "HAL_COMP_MspInit()".
|
||||
(#) Reconfiguration on-the-fly of comparator can be done by calling again
|
||||
function HAL_COMP_Init() with new input structure parameters values.
|
||||
|
||||
(#) Enable the comparator using HAL_COMP_Start() or HAL_COMP_Start_IT()to be enabled
|
||||
with the interrupt through NVIC of the CPU.
|
||||
Note: HAL_COMP_Start_IT() must be called after each interrupt otherwise the interrupt
|
||||
mode will stay disabled.
|
||||
|
||||
(#) Use HAL_COMP_GetOutputLevel() or HAL_COMP_TriggerCallback()
|
||||
functions to manage comparator outputs(output level or events)
|
||||
|
||||
(#) Disable the comparator using HAL_COMP_Stop() or HAL_COMP_Stop_IT()
|
||||
to disable the interrupt too.
|
||||
|
||||
(#) De-initialize the comparator using HAL_COMP_DeInit() function.
|
||||
|
||||
(#) For safety purpose, comparator configuration can be locked using HAL_COMP_Lock() function.
|
||||
The only way to unlock the comparator is a device hardware reset.
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
|
||||
Table 1. COMP inputs and output for STM32H7xx devices
|
||||
+---------------------------------------------------------+
|
||||
| | | COMP1 | COMP2 |
|
||||
|----------------|----------------|-----------|-----------|
|
||||
| | IO1 | PB0 | PE9 |
|
||||
| Input plus | IO2 | PB2 | PE11 |
|
||||
| | | | |
|
||||
|----------------|----------------|-----------------------|
|
||||
| | 1/4 VrefInt | Available | Available |
|
||||
| | 1/2 VrefInt | Available | Available |
|
||||
| | 3/4 VrefInt | Available | Available |
|
||||
| Input minus | VrefInt | Available | Available |
|
||||
| | DAC1 channel 1 | Available | Available |
|
||||
| | DAC1 channel 2 | Available | Available |
|
||||
| | IO1 | PB1 | PE10 |
|
||||
| | IO2 | PC4 | PE7 |
|
||||
| | | | |
|
||||
| | | | |
|
||||
| | | | |
|
||||
+---------------------------------------------------------+
|
||||
| Output | | PC5 (1) | PE8 (1) |
|
||||
| | | PE12 (1) | PE13 (1) |
|
||||
| | | TIM (2) | TIM (2) |
|
||||
+---------------------------------------------------------+
|
||||
(1) GPIO must be set to alternate function for comparator
|
||||
(2) Comparators output to timers is set in timers instances.
|
||||
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup COMP COMP
|
||||
* @brief COMP HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_COMP_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @addtogroup COMP_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Delay for COMP startup time. */
|
||||
/* Note: Delay required to reach propagation delay specification. */
|
||||
/* Literal set to maximum value (refer to device datasheet, */
|
||||
/* parameter "tSTART"). */
|
||||
/* Unit: us */
|
||||
#define COMP_DELAY_STARTUP_US ((uint32_t) 80U) /*!< Delay for COMP startup time */
|
||||
|
||||
/* Delay for COMP voltage scaler stabilization time. */
|
||||
/* Literal set to maximum value (refer to device datasheet, */
|
||||
/* parameter "tSTART_SCALER"). */
|
||||
/* Unit: us */
|
||||
#define COMP_DELAY_VOLTAGE_SCALER_STAB_US ((uint32_t) 200U) /*!< Delay for COMP voltage scaler stabilization time */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup COMP_Exported_Functions COMP Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions
|
||||
* @brief Initialization and de-initialization functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions to initialize and de-initialize comparators
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the COMP according to the specified
|
||||
* parameters in the COMP_InitTypeDef and initialize the associated handle.
|
||||
* @note If the selected comparator is locked, initialization can't be performed.
|
||||
* To unlock the configuration, perform a system reset.
|
||||
* @param hcomp: COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
uint32_t tmp_csr = 0;
|
||||
uint32_t exti_line = 0;
|
||||
uint32_t comp_voltage_scaler_not_initialized = 0;
|
||||
__IO uint32_t wait_loop_index = 0;
|
||||
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the COMP handle allocation and lock status */
|
||||
if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
assert_param(IS_COMP_INPUT_PLUS(hcomp->Instance, hcomp->Init.NonInvertingInput));
|
||||
assert_param(IS_COMP_INPUT_MINUS(hcomp->Instance, hcomp->Init.InvertingInput));
|
||||
assert_param(IS_COMP_OUTPUTPOL(hcomp->Init.OutputPol));
|
||||
assert_param(IS_COMP_POWERMODE(hcomp->Init.Mode));
|
||||
assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis));
|
||||
assert_param(IS_COMP_BLANKINGSRCE(hcomp->Init.BlankingSrce));
|
||||
assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
|
||||
assert_param(IS_COMP_WINDOWMODE(hcomp->Init.WindowMode));
|
||||
|
||||
if(hcomp->State == HAL_COMP_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hcomp->Lock = HAL_UNLOCKED;
|
||||
|
||||
/* Init the low level hardware */
|
||||
HAL_COMP_MspInit(hcomp);
|
||||
}
|
||||
/* Memorize voltage scaler state before initialization */
|
||||
comp_voltage_scaler_not_initialized = (READ_BIT(hcomp->Instance->CFGR, COMP_CFGRx_SCALEN) == 0);
|
||||
|
||||
/* Set COMP parameters */
|
||||
/* Set INMSEL bits according to hcomp->Init.InvertingInput value */
|
||||
/* Set INPSEL bits according to hcomp->Init.NonInvertingInput value */
|
||||
/* Set BLANKING bits according to hcomp->Init.BlankingSrce value */
|
||||
/* Set HYST bits according to hcomp->Init.Hysteresis value */
|
||||
/* Set POLARITY bit according to hcomp->Init.OutputPol value */
|
||||
/* Set POWERMODE bits according to hcomp->Init.Mode value */
|
||||
|
||||
tmp_csr = (hcomp->Init.InvertingInput | \
|
||||
hcomp->Init.NonInvertingInput | \
|
||||
hcomp->Init.BlankingSrce | \
|
||||
hcomp->Init.Hysteresis | \
|
||||
hcomp->Init.OutputPol | \
|
||||
hcomp->Init.Mode );
|
||||
|
||||
/* Set parameters in COMP register */
|
||||
/* Note: Update all bits except read-only, lock and enable bits */
|
||||
MODIFY_REG(hcomp->Instance->CFGR,
|
||||
COMP_CFGRx_PWRMODE | COMP_CFGRx_INMSEL | COMP_CFGRx_INPSEL |
|
||||
COMP_CFGRx_WINMODE | COMP_CFGRx_POLARITY | COMP_CFGRx_HYST |
|
||||
COMP_CFGRx_BLANKING | COMP_CFGRx_BRGEN | COMP_CFGRx_SCALEN,
|
||||
tmp_csr
|
||||
);
|
||||
|
||||
/* Set window mode */
|
||||
/* Note: Window mode bit is located into 1 out of the 2 pairs of COMP */
|
||||
/* instances. Therefore, this function can update another COMP */
|
||||
/* instance that the one currently selected. */
|
||||
if(hcomp->Init.WindowMode == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)
|
||||
{
|
||||
SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_WINMODE);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLEAR_BIT(hcomp->Instance->CFGR, COMP_CFGRx_WINMODE);
|
||||
}
|
||||
/* Delay for COMP scaler bridge voltage stabilization */
|
||||
/* Apply the delay if voltage scaler bridge is enabled for the first time */
|
||||
if ((READ_BIT(hcomp->Instance->CFGR, COMP_CFGRx_SCALEN) != 0) &&
|
||||
(comp_voltage_scaler_not_initialized != 0) )
|
||||
{
|
||||
/* Wait loop initialization and execution */
|
||||
/* Note: Variable divided by 2 to compensate partially */
|
||||
/* CPU processing cycles.*/
|
||||
|
||||
wait_loop_index = (COMP_DELAY_VOLTAGE_SCALER_STAB_US * (SystemCoreClock / (1000000 * 2)));
|
||||
|
||||
while(wait_loop_index != 0)
|
||||
{
|
||||
wait_loop_index --;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the EXTI line corresponding to the selected COMP instance */
|
||||
exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
|
||||
|
||||
/* Manage EXTI settings */
|
||||
if((hcomp->Init.TriggerMode & (COMP_EXTI_IT | COMP_EXTI_EVENT)) != RESET)
|
||||
{
|
||||
/* Configure EXTI rising edge */
|
||||
if((hcomp->Init.TriggerMode & COMP_EXTI_RISING) != RESET)
|
||||
{
|
||||
SET_BIT(EXTI->RTSR1, exti_line);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLEAR_BIT(EXTI->RTSR1, exti_line);
|
||||
}
|
||||
|
||||
/* Configure EXTI falling edge */
|
||||
if((hcomp->Init.TriggerMode & COMP_EXTI_FALLING) != RESET)
|
||||
{
|
||||
SET_BIT(EXTI->FTSR1, exti_line);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLEAR_BIT(EXTI->FTSR1, exti_line);
|
||||
}
|
||||
/* Clear COMP EXTI pending bit (if any) */
|
||||
WRITE_REG(EXTI_D1->PR1, exti_line);
|
||||
|
||||
/* Configure EXTI event mode */
|
||||
if((hcomp->Init.TriggerMode & COMP_EXTI_EVENT) != RESET)
|
||||
{
|
||||
SET_BIT(EXTI_D1->EMR1, exti_line);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLEAR_BIT(EXTI_D1->EMR1, exti_line);
|
||||
}
|
||||
|
||||
/* Configure EXTI interrupt mode */
|
||||
if((hcomp->Init.TriggerMode & COMP_EXTI_IT) != RESET)
|
||||
{
|
||||
SET_BIT(EXTI_D1->IMR1, exti_line);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLEAR_BIT(EXTI_D1->IMR1, exti_line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable EXTI event mode */
|
||||
CLEAR_BIT(EXTI_D1->EMR1, exti_line);
|
||||
|
||||
/* Disable EXTI interrupt mode */
|
||||
CLEAR_BIT(EXTI_D1->IMR1, exti_line);
|
||||
}
|
||||
/* Set HAL COMP handle state */
|
||||
/* Note: Transition from state reset to state ready, */
|
||||
/* otherwise (coming from state ready or busy) no state update. */
|
||||
if (hcomp->State == HAL_COMP_STATE_RESET)
|
||||
{
|
||||
|
||||
hcomp->State = HAL_COMP_STATE_READY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the COMP peripheral.
|
||||
* @note Deinitialization cannot be performed if the COMP configuration is locked.
|
||||
* To unlock the configuration, perform a system reset.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the COMP handle allocation and lock status */
|
||||
if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
|
||||
/* Set COMP_CFGR register to reset value */
|
||||
WRITE_REG(hcomp->Instance->CFGR, 0x00000000);
|
||||
|
||||
/* DeInit the low level hardware */
|
||||
HAL_COMP_MspDeInit(hcomp);
|
||||
|
||||
/* Set HAL COMP handle state */
|
||||
hcomp->State = HAL_COMP_STATE_RESET;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hcomp);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the COMP MSP.
|
||||
* @param hcomp COMP handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcomp);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_COMP_MspInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the COMP MSP.
|
||||
* @param hcomp COMP handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcomp);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_COMP_MspDeInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup COMP_Exported_Functions_Group2 Start-Stop operation functions
|
||||
* @brief Start-Stop operation functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Start a Comparator instance without interrupt.
|
||||
(+) Stop a Comparator instance without interrupt.
|
||||
(+) Start a Comparator instance with interrupt generation.
|
||||
(+) Stop a Comparator instance with interrupt generation.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Start the comparator.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
__IO uint32_t wait_loop_index = 0;
|
||||
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the COMP handle allocation and lock status */
|
||||
if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
|
||||
if(hcomp->State == HAL_COMP_STATE_READY)
|
||||
{
|
||||
/* Enable the selected comparator */
|
||||
SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_EN);
|
||||
|
||||
/* Set HAL COMP handle state */
|
||||
hcomp->State = HAL_COMP_STATE_BUSY;
|
||||
|
||||
/* Delay for COMP startup time */
|
||||
/* Wait loop initialization and execution */
|
||||
/* Note: Variable divided by 2 to compensate partially */
|
||||
/* CPU processing cycles. */
|
||||
|
||||
wait_loop_index = (COMP_DELAY_STARTUP_US * (SystemCoreClock / (1000000 * 2)));
|
||||
while(wait_loop_index != 0)
|
||||
{
|
||||
wait_loop_index--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the comparator.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the COMP handle allocation and lock status */
|
||||
if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
|
||||
if((hcomp->State == HAL_COMP_STATE_BUSY) ||
|
||||
(hcomp->State == HAL_COMP_STATE_READY) )
|
||||
{
|
||||
|
||||
/* Disable the selected comparator */
|
||||
CLEAR_BIT(hcomp->Instance->CFGR, COMP_CFGRx_EN);
|
||||
|
||||
/* Set HAL COMP handle state */
|
||||
hcomp->State = HAL_COMP_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the interrupt and start the comparator.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
|
||||
__IO uint32_t wait_loop_index = 0;
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the COMP handle allocation and lock status */
|
||||
if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
/* Set HAL COMP handle state */
|
||||
if(hcomp->State == HAL_COMP_STATE_READY)
|
||||
{
|
||||
|
||||
/* Enable the selected comparator */
|
||||
SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_EN);
|
||||
/* Enable the Interrupt comparator */
|
||||
SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_ITEN);
|
||||
|
||||
hcomp->State = HAL_COMP_STATE_BUSY;
|
||||
/* Delay for COMP startup time */
|
||||
/* Wait loop initialization and execution */
|
||||
/* Note: Variable divided by 2 to compensate partially */
|
||||
/* CPU processing cycles. */
|
||||
|
||||
wait_loop_index = (COMP_DELAY_STARTUP_US * (SystemCoreClock / (1000000 * 2)));
|
||||
while(wait_loop_index != 0)
|
||||
{
|
||||
wait_loop_index--;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the interrupt and Stop the comparator.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
/* Disable the EXTI Line interrupt mode */
|
||||
CLEAR_BIT(EXTI_D1->IMR1, COMP_GET_EXTI_LINE(hcomp->Instance));
|
||||
/* Disable the Interrupt comparator */
|
||||
CLEAR_BIT(hcomp->Instance->CFGR, COMP_CFGRx_ITEN);
|
||||
|
||||
status = HAL_COMP_Stop(hcomp);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Comparator IRQ Handler.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
/* Get the EXTI line corresponding to the selected COMP instance */
|
||||
uint32_t exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
|
||||
|
||||
|
||||
/* Check COMP EXTI flag */
|
||||
if(READ_BIT(EXTI_D1->PR1, exti_line) != RESET)
|
||||
{
|
||||
/* Check whether comparator is in independent or window mode */
|
||||
if(READ_BIT(COMP12_COMMON->CFGR, COMP_CFGRx_WINMODE) != RESET)
|
||||
{
|
||||
/* Clear COMP EXTI line pending bit of the pair of comparators */
|
||||
/* in window mode. */
|
||||
/* Note: Pair of comparators in window mode can both trig IRQ when */
|
||||
/* input voltage is changing from "out of window" area */
|
||||
/* (low or high ) to the other "out of window" area (high or low).*/
|
||||
/* Both flags must be cleared to call comparator trigger */
|
||||
/* callback is called once. */
|
||||
WRITE_REG(EXTI_D1->PR1, (COMP_EXTI_LINE_COMP1 | COMP_EXTI_LINE_COMP2));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear COMP EXTI line pending bit */
|
||||
WRITE_REG(EXTI_D1->PR1, exti_line);
|
||||
}
|
||||
|
||||
/* COMP trigger user callback */
|
||||
HAL_COMP_TriggerCallback(hcomp);
|
||||
}
|
||||
|
||||
/* Get COMP interrupt source */
|
||||
if (__HAL_COMP_GET_IT_SOURCE(hcomp, COMP_IT_EN) != RESET)
|
||||
{
|
||||
|
||||
if((__HAL_COMP_GET_FLAG( COMP_FLAG_C1I)) != RESET)
|
||||
{
|
||||
/* Clear the COMP channel 1 interrupt flag */
|
||||
__HAL_COMP_CLEAR_C1IFLAG();
|
||||
|
||||
/* Disable COMP interrupt */
|
||||
__HAL_COMP_DISABLE_IT(hcomp,COMP_IT_EN);
|
||||
|
||||
}
|
||||
if((__HAL_COMP_GET_FLAG( COMP_FLAG_C2I)) != RESET)
|
||||
{
|
||||
/* Clear the COMP channel 2 interrupt flag */
|
||||
__HAL_COMP_CLEAR_C2IFLAG();
|
||||
|
||||
/* Disable COMP interrupt */
|
||||
__HAL_COMP_DISABLE_IT(hcomp,COMP_IT_EN);
|
||||
|
||||
}
|
||||
|
||||
/* Change COMP state */
|
||||
hcomp->State = HAL_COMP_STATE_READY;
|
||||
|
||||
/* COMP trigger user callback */
|
||||
HAL_COMP_TriggerCallback(hcomp);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions
|
||||
* @brief Management functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the comparators.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Lock the selected comparator configuration.
|
||||
* @note A system reset is required to unlock the comparator configuration.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the COMP handle allocation and lock status */
|
||||
if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
/* Set HAL COMP handle state */
|
||||
hcomp->State = ((HAL_COMP_StateTypeDef)(hcomp->State | COMP_STATE_BITFIELD_LOCK));
|
||||
}
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
/* Set the lock bit corresponding to selected comparator */
|
||||
__HAL_COMP_LOCK(hcomp);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the output level (high or low) of the selected comparator.
|
||||
* @note The output level depends on the selected polarity.
|
||||
* If the polarity is not inverted:
|
||||
* - Comparator output is low when the input plus is at a lower
|
||||
* voltage than the input minus
|
||||
* - Comparator output is high when the input plus is at a higher
|
||||
* voltage than the input minus
|
||||
* If the polarity is inverted:
|
||||
* - Comparator output is high when the input plus is at a lower
|
||||
* voltage than the input minus
|
||||
* - Comparator output is low when the input plus is at a higher
|
||||
* voltage than the input minus
|
||||
* @param hcomp COMP handle
|
||||
* @retval Returns the selected comparator output level:
|
||||
* @arg @ref COMP_OUTPUT_LEVEL_LOW
|
||||
* @arg @ref COMP_OUTPUT_LEVEL_HIGH
|
||||
*
|
||||
*/
|
||||
uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
|
||||
if (hcomp->Instance == COMP1)
|
||||
{
|
||||
return (uint32_t)(READ_BIT(COMP12->SR, COMP_SR_C1VAL));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint32_t)((READ_BIT(COMP12->SR, COMP_SR_C2VAL))>> 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Comparator callback.
|
||||
* @param hcomp COMP handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcomp);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_COMP_TriggerCallback should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions
|
||||
* @brief Peripheral State functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral State functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection permit to get in run-time the status of the peripheral.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the COMP handle state.
|
||||
* @param hcomp COMP handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
|
||||
{
|
||||
/* Check the COMP handle allocation */
|
||||
if(hcomp == NULL)
|
||||
{
|
||||
return HAL_COMP_STATE_RESET;
|
||||
}
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
|
||||
|
||||
/* Return HAL COMP handle state */
|
||||
return hcomp->State;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+492
@@ -0,0 +1,492 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_cortex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @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
|
||||
*
|
||||
@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 Clock source to be HCLK_Div8 by calling the macro
|
||||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
|
||||
HAL_SYSTICK_Config() function call. The HAL_SYSTICK_CLKSourceConfig() macro is defined
|
||||
inside the stm32h7xx_hal_cortex.h file.
|
||||
|
||||
(+) You can change the SysTick IRQ priority by calling the
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function
|
||||
call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
|
||||
|
||||
(+) To adjust the SysTick time base, use the following formula:
|
||||
|
||||
Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
|
||||
(++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
|
||||
(++) Reload Value should not exceed 0xFFFFFF
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_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 (stm32h7xxxx.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 (stm32h7xxxx.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 (stm32h7xxxx.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 (stm32h7xxxx.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 (stm32h7xxxx.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 (stm32h7xxxx.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 (stm32h7xxxx.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 (stm32h7xxxx.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 Configures the SysTick clock source.
|
||||
* @param CLKSource: specifies the SysTick clock source.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
|
||||
* @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
|
||||
if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
|
||||
{
|
||||
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
|
||||
}
|
||||
else
|
||||
{
|
||||
SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the current CPU ID.
|
||||
* @retval CPU identifier
|
||||
*/
|
||||
uint32_t HAL_GetCurrentCPUID(void)
|
||||
{
|
||||
return CM7_CPUID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+525
@@ -0,0 +1,525 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_crc.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief CRC HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Cyclic Redundancy Check (CRC) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + Peripheral Control functions
|
||||
* + Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### CRC How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
|
||||
(#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
|
||||
|
||||
(#) Initialize CRC calculator
|
||||
(++) specify generating polynomial (IP default or non-default one)
|
||||
(++) specify initialization value (IP default or non-default one)
|
||||
(++) specify input data format
|
||||
(++) specify input or output data inversion mode if any
|
||||
|
||||
(#) Use HAL_CRC_Accumulate() function to compute the CRC value of the
|
||||
input data buffer starting with the previously computed CRC as
|
||||
initialization value
|
||||
|
||||
(#) Use HAL_CRC_Calculate() function to compute the CRC value of the
|
||||
input data buffer starting with the defined initialization value
|
||||
(default or non-default) to initiate CRC calculation
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CRC CRC
|
||||
* @brief CRC HAL module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength);
|
||||
static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength);
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup CRC_Exported_Functions CRC Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_CRC_Group1 Initialization/de-initialization functions
|
||||
* @brief Initialization and Configuration functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Initialize the CRC according to the specified parameters
|
||||
in the CRC_InitTypeDef and create the associated handle
|
||||
(+) DeInitialize the CRC peripheral
|
||||
(+) Initialize the CRC MSP
|
||||
(+) DeInitialize CRC MSP
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the CRC according to the specified
|
||||
* parameters in the CRC_InitTypeDef and create the associated handle.
|
||||
* @param hcrc: CRC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
|
||||
{
|
||||
/* Check the CRC handle allocation */
|
||||
if(hcrc == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
|
||||
|
||||
if(hcrc->State == HAL_CRC_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hcrc->Lock = HAL_UNLOCKED;
|
||||
/* Init the low level hardware */
|
||||
HAL_CRC_MspInit(hcrc);
|
||||
}
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_BUSY;
|
||||
|
||||
/* check whether or not non-default generating polynomial has been
|
||||
* picked up by user */
|
||||
assert_param(IS_DEFAULT_POLYNOMIAL(hcrc->Init.DefaultPolynomialUse));
|
||||
if(hcrc->Init.DefaultPolynomialUse == DEFAULT_POLYNOMIAL_ENABLE)
|
||||
{
|
||||
/* initialize IP with default generating polynomial */
|
||||
WRITE_REG(hcrc->Instance->POL, DEFAULT_CRC32_POLY);
|
||||
MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, CRC_POLYLENGTH_32B);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* initialize CRC IP with generating polynomial defined by user */
|
||||
if(HAL_CRCEx_Polynomial_Set(hcrc, hcrc->Init.GeneratingPolynomial, hcrc->Init.CRCLength) != HAL_OK)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* check whether or not non-default CRC initial value has been
|
||||
* picked up by user */
|
||||
assert_param(IS_DEFAULT_INIT_VALUE(hcrc->Init.DefaultInitValueUse));
|
||||
if(hcrc->Init.DefaultInitValueUse == DEFAULT_INIT_VALUE_ENABLE)
|
||||
{
|
||||
WRITE_REG(hcrc->Instance->INIT, DEFAULT_CRC_INITVALUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE_REG(hcrc->Instance->INIT, hcrc->Init.InitValue);
|
||||
}
|
||||
|
||||
|
||||
/* set input data inversion mode */
|
||||
assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(hcrc->Init.InputDataInversionMode));
|
||||
MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, hcrc->Init.InputDataInversionMode);
|
||||
|
||||
/* set output data inversion mode */
|
||||
assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(hcrc->Init.OutputDataInversionMode));
|
||||
MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, hcrc->Init.OutputDataInversionMode);
|
||||
|
||||
/* makes sure the input data format (bytes, halfwords or words stream)
|
||||
* is properly specified by user */
|
||||
assert_param(IS_CRC_INPUTDATA_FORMAT(hcrc->InputDataFormat));
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_READY;
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the CRC peripheral.
|
||||
* @param hcrc: CRC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
|
||||
{
|
||||
/* Check the CRC handle allocation */
|
||||
if(hcrc == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
|
||||
|
||||
/* Check the CRC peripheral state */
|
||||
if(hcrc->State == HAL_CRC_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_BUSY;
|
||||
|
||||
/* Reset CRC calculation unit */
|
||||
__HAL_CRC_DR_RESET(hcrc);
|
||||
|
||||
/* Reset IDR register content */
|
||||
CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR);
|
||||
|
||||
/* DeInit the low level hardware */
|
||||
HAL_CRC_MspDeInit(hcrc);
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_RESET;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcrc);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the CRC MSP.
|
||||
* @param hcrc: CRC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcrc);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_CRC_MspInit can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the CRC MSP.
|
||||
* @param hcrc: CRC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hcrc);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_CRC_MspDeInit can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_CRC_Group2 Peripheral Control functions
|
||||
* @brief Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
|
||||
using combination of the previous CRC value and the new one.
|
||||
|
||||
or
|
||||
|
||||
(+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
|
||||
independently of the previous CRC value.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
|
||||
* starting with the previously computed CRC as initialization value.
|
||||
* @param hcrc: CRC handle
|
||||
* @param pBuffer: pointer to the input data buffer, exact input data format is
|
||||
* provided by hcrc->InputDataFormat.
|
||||
* @param BufferLength: input data buffer length (number of bytes if pBuffer
|
||||
* type is * uint8_t, number of half-words if pBuffer type is * uint16_t,
|
||||
* number of words if pBuffer type is * uint32_t).
|
||||
* @note By default, the API expects a uint32_t pointer as input buffer parameter.
|
||||
* Input buffer pointers with other types simply need to be cast in uint32_t
|
||||
* and the API will internally adjust its input data processing based on the
|
||||
* handle field hcrc->InputDataFormat.
|
||||
* @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
|
||||
*/
|
||||
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
|
||||
{
|
||||
uint32_t index = 0; /* CRC input data buffer index */
|
||||
uint32_t temp = 0; /* CRC output (read from hcrc->Instance->DR register) */
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcrc);
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_BUSY;
|
||||
|
||||
switch (hcrc->InputDataFormat)
|
||||
{
|
||||
case CRC_INPUTDATA_FORMAT_WORDS:
|
||||
/* Enter Data to the CRC calculator */
|
||||
for(index = 0; index < BufferLength; index++)
|
||||
{
|
||||
hcrc->Instance->DR = pBuffer[index];
|
||||
}
|
||||
temp = hcrc->Instance->DR;
|
||||
break;
|
||||
|
||||
case CRC_INPUTDATA_FORMAT_BYTES:
|
||||
temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
|
||||
break;
|
||||
|
||||
case CRC_INPUTDATA_FORMAT_HALFWORDS:
|
||||
temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcrc);
|
||||
|
||||
/* Return the CRC computed value */
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
|
||||
* starting with hcrc->Instance->INIT as initialization value.
|
||||
* @param hcrc: CRC handle
|
||||
* @param pBuffer: pointer to the input data buffer, exact input data format is
|
||||
* provided by hcrc->InputDataFormat.
|
||||
* @param BufferLength: input data buffer length (number of bytes if pBuffer
|
||||
* type is * uint8_t, number of half-words if pBuffer type is * uint16_t,
|
||||
* number of words if pBuffer type is * uint32_t).
|
||||
* @note By default, the API expects a uint32_t pointer as input buffer parameter.
|
||||
* Input buffer pointers with other types simply need to be cast in uint32_t
|
||||
* and the API will internally adjust its input data processing based on the
|
||||
* handle field hcrc->InputDataFormat.
|
||||
* @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
|
||||
*/
|
||||
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
|
||||
{
|
||||
uint32_t index = 0; /* CRC input data buffer index */
|
||||
uint32_t temp = 0; /* CRC output (read from hcrc->Instance->DR register) */
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcrc);
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_BUSY;
|
||||
|
||||
/* Reset CRC Calculation Unit (hcrc->Instance->INIT is
|
||||
* written in hcrc->Instance->DR) */
|
||||
__HAL_CRC_DR_RESET(hcrc);
|
||||
|
||||
switch (hcrc->InputDataFormat)
|
||||
{
|
||||
case CRC_INPUTDATA_FORMAT_WORDS:
|
||||
/* Enter 32-bit input data to the CRC calculator */
|
||||
for(index = 0; index < BufferLength; index++)
|
||||
{
|
||||
hcrc->Instance->DR = pBuffer[index];
|
||||
}
|
||||
temp = hcrc->Instance->DR;
|
||||
break;
|
||||
|
||||
case CRC_INPUTDATA_FORMAT_BYTES:
|
||||
/* Specific 8-bit input data handling */
|
||||
temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
|
||||
break;
|
||||
|
||||
case CRC_INPUTDATA_FORMAT_HALFWORDS:
|
||||
/* Specific 16-bit input data handling */
|
||||
temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcrc);
|
||||
|
||||
/* Return the CRC computed value */
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter 8-bit input data to the CRC calculator.
|
||||
* Specific data handling to optimize processing time.
|
||||
* @param hcrc: CRC handle
|
||||
* @param pBuffer: pointer to the input data buffer
|
||||
* @param BufferLength: input data buffer length
|
||||
* @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
|
||||
*/
|
||||
static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
|
||||
{
|
||||
uint32_t i = 0; /* input data buffer index */
|
||||
|
||||
/* Processing time optimization: 4 bytes are entered in a row with a single word write,
|
||||
* last bytes must be carefully fed to the CRC calculator to ensure a correct type
|
||||
* handling by the IP */
|
||||
for(i = 0; i < (BufferLength/4); i++)
|
||||
{
|
||||
hcrc->Instance->DR = (uint32_t)(((uint32_t)(pBuffer[4*i])<<24) | ((uint32_t)(pBuffer[4*i+1])<<16) | ((uint32_t)(pBuffer[4*i+2])<<8) | (uint32_t)(pBuffer[4*i+3]));
|
||||
}
|
||||
/* last bytes specific handling */
|
||||
if((BufferLength%4) != 0)
|
||||
{
|
||||
if(BufferLength%4 == 1)
|
||||
{
|
||||
*(__IO uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i];
|
||||
}
|
||||
if(BufferLength%4 == 2)
|
||||
{
|
||||
*(__IO uint16_t*) (&hcrc->Instance->DR) = (uint16_t)((uint16_t)((uint16_t)(pBuffer[4*i])<<8) | (uint16_t)(pBuffer[4*i+1]));
|
||||
}
|
||||
if(BufferLength%4 == 3)
|
||||
{
|
||||
*(__IO uint16_t*) (&hcrc->Instance->DR) = (uint16_t)((uint16_t)((uint16_t)(pBuffer[4*i])<<8) | (uint16_t)(pBuffer[4*i+1]));
|
||||
*(__IO uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i+2];
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the CRC computed value */
|
||||
return hcrc->Instance->DR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter 16-bit input data to the CRC calculator.
|
||||
* Specific data handling to optimize processing time.
|
||||
* @param hcrc: CRC handle
|
||||
* @param pBuffer: pointer to the input data buffer
|
||||
* @param BufferLength: input data buffer length
|
||||
* @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
|
||||
*/
|
||||
static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)
|
||||
{
|
||||
uint32_t i = 0; /* input data buffer index */
|
||||
|
||||
/* Processing time optimization: 2 HalfWords are entered in a row with a single word write,
|
||||
* in case of odd length, last HalfWord must be carefully fed to the CRC calculator to ensure
|
||||
* a correct type handling by the IP */
|
||||
for(i = 0; i < (BufferLength/2); i++)
|
||||
{
|
||||
hcrc->Instance->DR = (((uint32_t)(pBuffer[2*i])<<16) | (uint32_t)(pBuffer[2*i+1]));
|
||||
}
|
||||
if((BufferLength%2) != 0)
|
||||
{
|
||||
*(__IO uint16_t*) (&hcrc->Instance->DR) = pBuffer[2*i];
|
||||
}
|
||||
|
||||
/* Return the CRC computed value */
|
||||
return hcrc->Instance->DR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_CRC_Group3 Peripheral State functions
|
||||
* @brief Peripheral State functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Peripheral State functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This subsection permits to get in run-time the status of the peripheral
|
||||
and the data flow.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the CRC state.
|
||||
* @param hcrc: CRC handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
|
||||
{
|
||||
return hcrc->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_crc_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief Extended CRC HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the CRC peripheral:
|
||||
* + Initialization/de-initialization functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### CRC specific features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) Polynomial configuration.
|
||||
(#) Input data reverse mode.
|
||||
(#) Output data reverse mode.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CRCEx
|
||||
* @brief CRC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup CRCEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CRCEx_Exported_Functions_Group1
|
||||
* @brief Extended CRC features functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### CRC Extended features functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides function allowing to:
|
||||
(+) Set CRC polynomial if different from default one.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes the CRC polynomial if different from default one.
|
||||
* @param hcrc: CRC handle
|
||||
* @param Pol: CRC generating polynomial (7, 8, 16 or 32-bit long)
|
||||
* This parameter is written in normal representation, e.g.
|
||||
* for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
|
||||
* for a polynomial of degree 16, X^16 + X^12 + X^5 + 1 is written 0x1021
|
||||
* @param PolyLength: CRC polynomial length
|
||||
* This parameter can be one of the following values:
|
||||
* @arg CRC_POLYLENGTH_7B: 7-bit long CRC (generating polynomial of degree 7)
|
||||
* @arg CRC_POLYLENGTH_8B: 8-bit long CRC (generating polynomial of degree 8)
|
||||
* @arg CRC_POLYLENGTH_16B: 16-bit long CRC (generating polynomial of degree 16)
|
||||
* @arg CRC_POLYLENGTH_32B: 32-bit long CRC (generating polynomial of degree 32)
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength)
|
||||
{
|
||||
uint32_t msb = 31; /* polynomial degree is 32 at most, so msb is initialized to max value */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CRC_POL_LENGTH(PolyLength));
|
||||
|
||||
/* check polynomial definition vs polynomial size:
|
||||
* polynomial length must be aligned with polynomial
|
||||
* definition. HAL_ERROR is reported if Pol degree is
|
||||
* larger than that indicated by PolyLength.
|
||||
* Look for MSB position: msb will contain the degree of
|
||||
* the second to the largest polynomial member. E.g., for
|
||||
* X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */
|
||||
while (((Pol & ((uint32_t)(0x1) << msb)) == 0) && (msb-- > 0))
|
||||
{
|
||||
}
|
||||
|
||||
switch (PolyLength)
|
||||
{
|
||||
case CRC_POLYLENGTH_7B:
|
||||
if (msb >= HAL_CRC_LENGTH_7B)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
break;
|
||||
case CRC_POLYLENGTH_8B:
|
||||
if (msb >= HAL_CRC_LENGTH_8B)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
break;
|
||||
case CRC_POLYLENGTH_16B:
|
||||
if (msb >= HAL_CRC_LENGTH_16B)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
break;
|
||||
case CRC_POLYLENGTH_32B:
|
||||
/* no polynomial definition vs. polynomial length issue possible */
|
||||
break;
|
||||
default:
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* set generating polynomial */
|
||||
WRITE_REG(hcrc->Instance->POL, Pol);
|
||||
|
||||
/* set generating polynomial size */
|
||||
MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, PolyLength);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Reverse Input data mode.
|
||||
* @param hcrc: CRC handle
|
||||
* @param InputReverseMode: Input Data inversion mode
|
||||
* This parameter can be one of the following values:
|
||||
* @arg CRC_INPUTDATA_INVERSION_NONE: no change in bit order (default value)
|
||||
* @arg CRC_INPUTDATA_INVERSION_BYTE: Byte-wise bit reversal
|
||||
* @arg CRC_INPUTDATA_INVERSION_HALFWORD: HalfWord-wise bit reversal
|
||||
* @arg CRC_INPUTDATA_INVERSION_WORD: Word-wise bit reversal
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode));
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_BUSY;
|
||||
|
||||
/* set input data inversion mode */
|
||||
MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, InputReverseMode);
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_READY;
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Reverse Output data mode.
|
||||
* @param hcrc: CRC handle
|
||||
* @param OutputReverseMode: Output Data inversion mode
|
||||
* This parameter can be one of the following values:
|
||||
* @arg CRC_OUTPUTDATA_INVERSION_DISABLE: no CRC inversion (default value)
|
||||
* @arg CRC_OUTPUTDATA_INVERSION_ENABLE: bit-level inversion (e.g for a 8-bit CRC: 0xB5 becomes 0xAD)
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode));
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_BUSY;
|
||||
|
||||
/* set output data inversion mode */
|
||||
MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, OutputReverseMode);
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_READY;
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+3709
File diff suppressed because it is too large
Load Diff
+429
@@ -0,0 +1,429 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_cryp_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief Extended CRYP HAL module driver
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of CRYP extension peripheral:
|
||||
* + Extended AES processing functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The CRYP extension HAL driver can be used after AES-GCM or AES-CCM
|
||||
Encryption/Decryption to get the authentication messages.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
#if defined (CRYP)
|
||||
/** @defgroup CRYPEx CRYPEx
|
||||
* @brief CRYP Extension HAL module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @addtogroup CRYPEx_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define CRYP_PHASE_INIT 0x00000000U
|
||||
#define CRYP_PHASE_HEADER CRYP_CR_GCM_CCMPH_0
|
||||
#define CRYP_PHASE_PAYLOAD CRYP_CR_GCM_CCMPH_1
|
||||
#define CRYP_PHASE_FINAL CRYP_CR_GCM_CCMPH
|
||||
|
||||
#define CRYP_OPERATINGMODE_ENCRYPT 0x00000000U
|
||||
#define CRYP_OPERATINGMODE_DECRYPT CRYP_CR_ALGODIR
|
||||
|
||||
#define CRYPEx_PHASE_PROCESS 0x02U /*!< CRYP peripheral is in processing phase */
|
||||
#define CRYPEx_PHASE_FINAL 0x03U /*!< CRYP peripheral is in final phase this is relevant only with CCM and GCM modes */
|
||||
|
||||
/* CTR0 information to use in CCM algorithm */
|
||||
#define CRYP_CCM_CTR0_0 0x07FFFFFFU
|
||||
#define CRYP_CCM_CTR0_3 0xFFFFFF00U
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
/* Exported functions---------------------------------------------------------*/
|
||||
/** @addtogroup CRYPEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CRYPEx_Exported_Functions_Group1 Extended AES processing functions
|
||||
* @brief CRYPEx Extended processing functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Extended AES processing functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to generate the authentication
|
||||
TAG in Polling mode
|
||||
(+)HAL_CRYPEx_AESGCM_GenerateAuthTAG
|
||||
(+)HAL_CRYPEx_AESCCM_GenerateAuthTAG
|
||||
they should be used after Encrypt/Decrypt operation.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief generate the GCM authentication TAG.
|
||||
* @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
|
||||
* the configuration information for CRYP module
|
||||
* @param AuthTag: Pointer to the authentication buffer
|
||||
* @param Timeout: Timeout duration
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, uint32_t *AuthTag, uint32_t Timeout)
|
||||
{
|
||||
uint32_t tickstart = 0U;
|
||||
uint64_t headerlength = hcryp->Init.HeaderSize * 32U; /* Header length in bits */
|
||||
uint64_t inputlength = (hcryp->Size) * 32U; /* input length in bits */
|
||||
uint32_t tagaddr = (uint32_t)AuthTag;
|
||||
|
||||
if(hcryp->State == HAL_CRYP_STATE_READY)
|
||||
{
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcryp);
|
||||
|
||||
/* Change the CRYP peripheral state */
|
||||
hcryp->State = HAL_CRYP_STATE_BUSY;
|
||||
|
||||
/* Check if initialization phase has already been performed */
|
||||
if(hcryp->Phase == CRYPEx_PHASE_PROCESS)
|
||||
{
|
||||
/* Change the CRYP phase */
|
||||
hcryp->Phase = CRYPEx_PHASE_FINAL;
|
||||
}
|
||||
else /* Initialization phase has not been performed*/
|
||||
{
|
||||
/* Disable the Peripheral */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
|
||||
/* Sequence error code field */
|
||||
hcryp->ErrorCode |= HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE;
|
||||
|
||||
/* Change the CRYP peripheral state */
|
||||
hcryp->State = HAL_CRYP_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcryp);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Disable CRYP to start the final phase */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
|
||||
/* Select final phase */
|
||||
MODIFY_REG(hcryp->Instance->CR, CRYP_CR_GCM_CCMPH, CRYP_PHASE_FINAL);
|
||||
|
||||
/*ALGODIR bit must be set to ‘0’.*/
|
||||
hcryp->Instance->CR &= ~CRYP_CR_ALGODIR;
|
||||
|
||||
/* Enable the CRYP peripheral */
|
||||
__HAL_CRYP_ENABLE(hcryp);
|
||||
|
||||
/* Write the number of bits in header (64 bits) followed by the number of bits
|
||||
in the payload */
|
||||
if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
|
||||
{
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = __RBIT((uint32_t)(headerlength));
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = __RBIT((uint32_t)(inputlength));
|
||||
}
|
||||
else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
|
||||
{
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = __REV((uint32_t)(headerlength));
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = __REV((uint32_t)(inputlength));
|
||||
}
|
||||
else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
|
||||
{
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = __ROR((uint32_t)headerlength, 16U);
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = __ROR((uint32_t)inputlength, 16U);
|
||||
}
|
||||
else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
|
||||
{
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = (uint32_t)(headerlength);
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = (uint32_t)(inputlength);
|
||||
}
|
||||
|
||||
/* Wait for OFNE flag to be raised */
|
||||
tickstart = HAL_GetTick();
|
||||
while(HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE))
|
||||
{
|
||||
/* Check for the Timeout */
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
|
||||
{
|
||||
/* Disable the CRYP Peripheral Clock */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
|
||||
/* Change state */
|
||||
hcryp->ErrorCode |= HAL_CRYP_ERROR_TIMEOUT;
|
||||
hcryp->State = HAL_CRYP_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcryp);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the authentication TAG in the output FIFO */
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
tagaddr+=4U;
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
tagaddr+=4U;
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
tagaddr+=4U;
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
|
||||
/* Disable the peripheral */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
|
||||
/* Change the CRYP peripheral state */
|
||||
hcryp->State = HAL_CRYP_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcryp);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Busy error code field */
|
||||
hcryp->ErrorCode |= HAL_CRYP_ERROR_BUSY;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AES CCM Authentication TAG generation.
|
||||
* @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
|
||||
* the configuration information for CRYP module
|
||||
* @param AuthTag: Pointer to the authentication buffer
|
||||
* @param Timeout: Timeout duration
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, uint32_t *AuthTag, uint32_t Timeout)
|
||||
{
|
||||
uint32_t tagaddr = (uint32_t)AuthTag;
|
||||
uint32_t ctr0 [4]={0};
|
||||
uint32_t ctr0addr = (uint32_t)ctr0;
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
if(hcryp->State == HAL_CRYP_STATE_READY)
|
||||
{
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcryp);
|
||||
|
||||
/* Change the CRYP peripheral state */
|
||||
hcryp->State = HAL_CRYP_STATE_BUSY;
|
||||
|
||||
/* Check if initialization phase has already been performed */
|
||||
if(hcryp->Phase == CRYPEx_PHASE_PROCESS)
|
||||
{
|
||||
/* Change the CRYP phase */
|
||||
hcryp->Phase = CRYPEx_PHASE_FINAL;
|
||||
}
|
||||
else /* Initialization phase has not been performed*/
|
||||
{
|
||||
/* Disable the peripheral */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
|
||||
/* Sequence error code field */
|
||||
hcryp->ErrorCode |= HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE;
|
||||
|
||||
/* Change the CRYP peripheral state */
|
||||
hcryp->State = HAL_CRYP_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcryp);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Disable CRYP to start the final phase */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
|
||||
/* Select final phase & ALGODIR bit must be set to ‘0’. */
|
||||
MODIFY_REG(hcryp->Instance->CR, CRYP_CR_GCM_CCMPH|CRYP_CR_ALGODIR, CRYP_PHASE_FINAL|CRYP_OPERATINGMODE_ENCRYPT);
|
||||
|
||||
/* Enable the CRYP peripheral */
|
||||
__HAL_CRYP_ENABLE(hcryp);
|
||||
|
||||
/* Write the counter block in the IN FIFO, CTR0 information from B0
|
||||
data has to be swapped according to the DATATYPE*/
|
||||
ctr0[0]=(hcryp->Init.B0[0]) & CRYP_CCM_CTR0_0;
|
||||
ctr0[1]=hcryp->Init.B0[1];
|
||||
ctr0[2]=hcryp->Init.B0[2];
|
||||
ctr0[3]=hcryp->Init.B0[3] & CRYP_CCM_CTR0_3;
|
||||
|
||||
if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
|
||||
{
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t*)(ctr0addr));
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t*)(ctr0addr));
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t*)(ctr0addr));
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t*)(ctr0addr));
|
||||
}
|
||||
else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
|
||||
{
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t*)(ctr0addr), 16U);
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t*)(ctr0addr), 16U);
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t*)(ctr0addr), 16U);
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t*)(ctr0addr), 16U);
|
||||
}
|
||||
else if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
|
||||
{
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t*)(ctr0addr));
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t*)(ctr0addr));
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t*)(ctr0addr));
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t*)(ctr0addr));
|
||||
}
|
||||
else
|
||||
{
|
||||
hcryp->Instance->DIN = *(uint32_t*)(ctr0addr);
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = *(uint32_t*)(ctr0addr);
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = *(uint32_t*)(ctr0addr);
|
||||
ctr0addr+=4;
|
||||
hcryp->Instance->DIN = *(uint32_t*)(ctr0addr);;
|
||||
}
|
||||
/* Wait for OFNE flag to be raised */
|
||||
tickstart = HAL_GetTick();
|
||||
while(HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE))
|
||||
{
|
||||
/* Check for the Timeout */
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
|
||||
{
|
||||
/* Disable the CRYP peripheral Clock */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
|
||||
/* Change state */
|
||||
hcryp->ErrorCode |= HAL_CRYP_ERROR_TIMEOUT;
|
||||
hcryp->State = HAL_CRYP_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcryp);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the Auth TAG in the IN FIFO */
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
tagaddr+=4U;
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
tagaddr+=4U;
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
tagaddr+=4U;
|
||||
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUT;
|
||||
|
||||
/* Change the CRYP peripheral state */
|
||||
hcryp->State = HAL_CRYP_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hcryp);
|
||||
|
||||
/* Disable CRYP */
|
||||
__HAL_CRYP_DISABLE(hcryp);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Busy error code field */
|
||||
hcryp->ErrorCode = HAL_CRYP_ERROR_BUSY;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* CRYP*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1178
File diff suppressed because it is too large
Load Diff
+632
@@ -0,0 +1,632 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_dac_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief Extended DAC HAL module driver.
|
||||
* This file provides firmware functions to manage the extended
|
||||
* functionalities of DAC peripheral.
|
||||
*
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) When Dual mode is enabled (i.e DAC Channel1 and Channel2 are used simultaneously) :
|
||||
Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
|
||||
HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2.
|
||||
(+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
|
||||
(+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
|
||||
|
||||
(+) HAL_DACEx_SelfCalibrate to calibrate one DAC channel.
|
||||
(+) HAL_DACEx_SetUserTrimming to set user trimming value.
|
||||
(+) HAL_DACEx_GetTrimOffset to retrieve trimming value (factory setting
|
||||
after reset, user setting if HAL_DACEx_SetUserTrimming have been used
|
||||
at least one time after reset).
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DACEx DACEx
|
||||
* @brief DAC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup DACEx_Exported_Functions DACEx Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
|
||||
* @brief Extended IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Extended features functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Start conversion with triangle wave generation.
|
||||
(+) Start conversion with noise wave generation.
|
||||
(+) Start self calibration.
|
||||
(+) Set user trimming mode.
|
||||
(+) Get result of dual mode conversion.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable or disable the selected DAC channel wave generation.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @param Channel: The selected DAC channel.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
||||
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
||||
* @param Amplitude: Select max triangle amplitude.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
|
||||
* @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdac);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_BUSY;
|
||||
|
||||
/* Enable the triangle wave generation for the selected DAC channel */
|
||||
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hdac);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable the selected DAC channel wave generation.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @param Channel: The selected DAC channel.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
||||
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
||||
* @param Amplitude: Unmask DAC channel LFSR for noise wave generation.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
|
||||
* @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdac);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_BUSY;
|
||||
|
||||
/* Enable the noise wave generation for the selected DAC channel */
|
||||
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hdac);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the specified data holding register value for dual DAC channel.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @param Alignment: Specifies the data alignment for dual channel DAC.
|
||||
* This parameter can be one of the following values:
|
||||
* DAC_ALIGN_8B_R: 8bit right data alignment selected
|
||||
* DAC_ALIGN_12B_L: 12bit left data alignment selected
|
||||
* DAC_ALIGN_12B_R: 12bit right data alignment selected
|
||||
* @param Data1: Data for DAC Channel2 to be loaded in the selected data holding register.
|
||||
* @param Data2: Data for DAC Channel1 to be loaded in the selected data holding register.
|
||||
* @note In dual mode, a unique register access is required to write in both
|
||||
* DAC channels at the same time.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
|
||||
{
|
||||
uint32_t data = 0, tmp = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DAC_ALIGN(Alignment));
|
||||
assert_param(IS_DAC_DATA(Data1));
|
||||
assert_param(IS_DAC_DATA(Data2));
|
||||
|
||||
/* Calculate and set dual DAC data holding register value */
|
||||
if (Alignment == DAC_ALIGN_8B_R)
|
||||
{
|
||||
data = ((uint32_t)Data2 << 8) | Data1;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = ((uint32_t)Data2 << 16) | Data1;
|
||||
}
|
||||
|
||||
tmp = (uint32_t)hdac->Instance;
|
||||
tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
|
||||
|
||||
/* Set the dual DAC selected data holding register */
|
||||
*(__IO uint32_t *)tmp = data;
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Conversion complete callback in non-blocking mode for Channel2.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdac);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Conversion half DMA transfer callback in non-blocking mode for Channel2.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdac);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Error DAC callback for Channel2.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdac);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA underrun DAC callback for channel2.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdac);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Run the self calibration of one DAC channel.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @param sConfig: DAC channel configuration structure.
|
||||
* @param Channel: The selected DAC channel.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
||||
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
||||
* @retval Updates DAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming
|
||||
* @retval HAL status
|
||||
* @note Calibration runs about 7 ms.
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
__IO uint32_t tmp = 0;
|
||||
uint32_t trimmingvalue = 0;
|
||||
uint32_t delta;
|
||||
|
||||
/* store/restore channel configuration structure purpose */
|
||||
uint32_t oldmodeconfiguration = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
|
||||
/* Check the DAC handle allocation */
|
||||
/* Check if DAC running */
|
||||
if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_BUSY))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdac);
|
||||
|
||||
/* Store configuration */
|
||||
oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << Channel));
|
||||
|
||||
/* Disable the selected DAC channel */
|
||||
CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_EN1 << Channel));
|
||||
|
||||
/* Set mode in MCR for calibration */
|
||||
MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), 0);
|
||||
|
||||
/* Set DAC Channel1 DHR register to the middle value */
|
||||
|
||||
tmp = (uint32_t)hdac->Instance;
|
||||
if(Channel == DAC_CHANNEL_1)
|
||||
{
|
||||
tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R);
|
||||
}
|
||||
*(__IO uint32_t *) tmp = 0x0800;
|
||||
|
||||
/* Enable the selected DAC channel calibration */
|
||||
/* i.e. set DAC_CR_CENx bit */
|
||||
SET_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
|
||||
|
||||
/* Init trimming counter */
|
||||
/* Medium value */
|
||||
trimmingvalue = 16;
|
||||
delta = 8;
|
||||
while (delta != 0)
|
||||
{
|
||||
/* Set candidate trimming */
|
||||
MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
|
||||
|
||||
/* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
|
||||
/* i.e. minimum time needed between two calibration steps */
|
||||
HAL_Delay(1);
|
||||
|
||||
if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == (DAC_SR_CAL_FLAG1<<Channel))
|
||||
{
|
||||
/* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
|
||||
trimmingvalue -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DAC_SR_CAL_FLAGx is LOW try lower trimming */
|
||||
trimmingvalue += delta;
|
||||
|
||||
}
|
||||
delta >>= 1;
|
||||
}
|
||||
|
||||
/* Still need to check if right calibration is current value or one step below */
|
||||
/* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */
|
||||
/* Set candidate trimming */
|
||||
MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
|
||||
|
||||
/* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
|
||||
/* i.e. minimum time needed between two calibration steps */
|
||||
HAL_Delay(1);
|
||||
|
||||
if (!(hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)))
|
||||
{
|
||||
/* Trimming is actually one value more */
|
||||
trimmingvalue ++;
|
||||
/* Set right trimming */
|
||||
MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
|
||||
}
|
||||
|
||||
/* Disable the selected DAC channel calibration */
|
||||
/* i.e. clear DAC_CR_CENx bit */
|
||||
CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
|
||||
|
||||
sConfig->DAC_TrimmingValue = trimmingvalue;
|
||||
sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
|
||||
|
||||
/* Restore configuration */
|
||||
MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), oldmodeconfiguration);
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hdac);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set the trimming mode and trimming value (user trimming mode applied).
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @param sConfig: DAC configuration structure updated with new DAC trimming value.
|
||||
* @param Channel: The selected DAC channel.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
||||
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
||||
* @param NewTrimmingValue: DAC new trimming value
|
||||
* @retval HAL status
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel, uint32_t NewTrimmingValue)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue));
|
||||
|
||||
/* Check the DAC handle allocation */
|
||||
if(hdac == NULL)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdac);
|
||||
|
||||
/* Set new trimming */
|
||||
MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (NewTrimmingValue<<Channel));
|
||||
|
||||
/* Update trimming mode */
|
||||
sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
|
||||
sConfig->DAC_TrimmingValue = NewTrimmingValue;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hdac);
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the DAC trimming value.
|
||||
* @param hdac : DAC handle
|
||||
* @param Channel: The selected DAC channel.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
||||
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
||||
* @retval Trimming value : range: 0->31
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
|
||||
{
|
||||
uint32_t trimmingvalue = 0;
|
||||
|
||||
/* Check the DAC handle allocation */
|
||||
/* And not in Reset state */
|
||||
if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_RESET))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
|
||||
/* Retrieve trimming */
|
||||
trimmingvalue = ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << Channel)) >> Channel);
|
||||
}
|
||||
return trimmingvalue;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
|
||||
* @brief Extended Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure channels.
|
||||
(+) Set the specified data holding register value for DAC channel.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the last data output value of the selected DAC channel.
|
||||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @retval The selected DAC channel data output value.
|
||||
*/
|
||||
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
|
||||
{
|
||||
uint32_t tmp = 0;
|
||||
|
||||
tmp |= hdac->Instance->DOR1;
|
||||
|
||||
tmp |= hdac->Instance->DOR2 << 16;
|
||||
|
||||
/* Returns the DAC channel data output register value */
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/** @defgroup DACEx_Private_Functions DACEx private functions
|
||||
* @brief Extended private functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief DMA conversion complete callback.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
||||
|
||||
HAL_DACEx_ConvCpltCallbackCh2(hdac);
|
||||
|
||||
hdac->State= HAL_DAC_STATE_READY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA half transfer complete callback.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
||||
/* Conversion complete callback */
|
||||
HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA error callback.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
||||
|
||||
/* Set DAC error code to DMA error */
|
||||
hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
|
||||
|
||||
HAL_DACEx_ErrorCallbackCh2(hdac);
|
||||
|
||||
hdac->State= HAL_DAC_STATE_READY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+903
@@ -0,0 +1,903 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_dcmi.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief DCMI HAL module driver
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Digital Camera Interface (DCMI) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + IO operation functions
|
||||
* + Peripheral Control functions
|
||||
* + Peripheral State and Error functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The sequence below describes how to use this driver to capture image
|
||||
from a camera module connected to the DCMI Interface.
|
||||
This sequence does not take into account the configuration of the
|
||||
camera module, which should be made before to configure and enable
|
||||
the DCMI to capture images.
|
||||
|
||||
(#) Program the required configuration through following parameters:
|
||||
horizontal and vertical polarity, pixel clock polarity, Capture Rate,
|
||||
Synchronization Mode, code of the frame delimiter and data width
|
||||
using HAL_DCMI_Init() function.
|
||||
|
||||
(#) Configure the selected DMA stream to transfer Data from DCMI DR
|
||||
register to the destination memory buffer.
|
||||
|
||||
(#) Program the required configuration through following parameters:
|
||||
DCMI mode, destination memory Buffer address and the data length
|
||||
and enable capture using HAL_DCMI_Start_DMA() function.
|
||||
|
||||
(#) Optionally, configure and Enable the CROP feature to select a rectangular
|
||||
window from the received image using HAL_DCMI_ConfigCrop()
|
||||
and HAL_DCMI_EnableCrop() functions
|
||||
|
||||
(#) The capture can be stopped using HAL_DCMI_Stop() function.
|
||||
|
||||
(#) To control DCMI state you can use the function HAL_DCMI_GetState().
|
||||
|
||||
*** DCMI HAL driver macros list ***
|
||||
=============================================
|
||||
[..]
|
||||
Below the list of most used macros in DCMI HAL driver.
|
||||
|
||||
(+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.
|
||||
(+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.
|
||||
(+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.
|
||||
(+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.
|
||||
(+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.
|
||||
(+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.
|
||||
(+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.
|
||||
|
||||
[..]
|
||||
(@) You can refer to the DCMI HAL driver header file for more useful macros
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
/** @defgroup DCMI DCMI
|
||||
* @brief DCMI HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_DCMI_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define HAL_TIMEOUT_DCMI_STOP ((uint32_t)1000) /* Set timeout to 1s */
|
||||
|
||||
#define DCMI_POSITION_CWSIZE_VLINE (uint32_t)POSITION_VAL(DCMI_CWSIZE_VLINE) /*!< Required left shift to set crop window vertical line count */
|
||||
#define DCMI_POSITION_CWSTRT_VST (uint32_t)POSITION_VAL(DCMI_CWSTRT_VST) /*!< Required left shift to set crop window vertical start line count */
|
||||
|
||||
#define DCMI_POSITION_ESCR_LSC (uint32_t)POSITION_VAL(DCMI_ESCR_LSC) /*!< Required left shift to set line start delimiter */
|
||||
#define DCMI_POSITION_ESCR_LEC (uint32_t)POSITION_VAL(DCMI_ESCR_LEC) /*!< Required left shift to set line end delimiter */
|
||||
#define DCMI_POSITION_ESCR_FEC (uint32_t)POSITION_VAL(DCMI_ESCR_FEC) /*!< Required left shift to set frame end delimiter */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma);
|
||||
static void DCMI_DMAError(DMA_HandleTypeDef *hdma);
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup DCMI_Exported_Functions DCMI Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and Configuration functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Initialize and configure the DCMI
|
||||
(+) De-initialize the DCMI
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the DCMI according to the specified
|
||||
* parameters in the DCMI_InitTypeDef and create the associated handle.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* Check the DCMI peripheral state */
|
||||
if(hdcmi == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check function parameters */
|
||||
assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
|
||||
assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
|
||||
assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
|
||||
assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
|
||||
assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
|
||||
assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
|
||||
assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
|
||||
assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
|
||||
|
||||
assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
|
||||
assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
|
||||
assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
|
||||
assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
|
||||
|
||||
if(hdcmi->State == HAL_DCMI_STATE_RESET)
|
||||
{
|
||||
/* Init the low level hardware */
|
||||
HAL_DCMI_MspInit(hdcmi);
|
||||
}
|
||||
|
||||
/* Change the DCMI state */
|
||||
hdcmi->State = HAL_DCMI_STATE_BUSY;
|
||||
/* Configures the HS, VS, DE and PC polarity */
|
||||
hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |\
|
||||
DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |\
|
||||
DCMI_CR_ESS | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\
|
||||
DCMI_CR_LSM | DCMI_CR_OELS);
|
||||
|
||||
hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\
|
||||
hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity |\
|
||||
hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\
|
||||
hdcmi->Init.JPEGMode | hdcmi->Init.ByteSelectMode |\
|
||||
hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\
|
||||
hdcmi->Init.LineSelectStart);
|
||||
|
||||
if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
|
||||
{
|
||||
hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |\
|
||||
((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|\
|
||||
((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |\
|
||||
((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
|
||||
|
||||
}
|
||||
|
||||
/* Enable the Line, Vsync, Error and Overrun interrupts */
|
||||
__HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
|
||||
|
||||
/* Update error code */
|
||||
hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
|
||||
|
||||
/* Initialize the DCMI state*/
|
||||
hdcmi->State = HAL_DCMI_STATE_READY;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitializes the DCMI peripheral registers to their default reset
|
||||
* values.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL status
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* DeInit the low level hardware */
|
||||
HAL_DCMI_MspDeInit(hdcmi);
|
||||
|
||||
/* Update error code */
|
||||
hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
|
||||
|
||||
/* Initialize the DCMI state*/
|
||||
hdcmi->State = HAL_DCMI_STATE_RESET;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the DCMI MSP.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdcmi);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_DCMI_MspInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the DCMI MSP.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdcmi);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_DCMI_MspDeInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
|
||||
* @brief IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure destination address and data length and
|
||||
Enables DCMI DMA request and enables DCMI capture
|
||||
(+) Stop the DCMI capture.
|
||||
(+) Handles DCMI interrupt request.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enables DCMI DMA request and enables DCMI capture
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @param DCMI_Mode: DCMI capture mode snapshot or continuous grab.
|
||||
* @param pData: The destination memory Buffer address (LCD Frame buffer).
|
||||
* @param Length: The length of capture to be transferred.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
|
||||
{
|
||||
/* Initialize the second memory address */
|
||||
uint32_t SecondMemAddress = 0;
|
||||
|
||||
/* Check function parameters */
|
||||
assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdcmi);
|
||||
|
||||
/* Lock the DCMI peripheral state */
|
||||
hdcmi->State = HAL_DCMI_STATE_BUSY;
|
||||
|
||||
/* Enable DCMI by setting DCMIEN bit */
|
||||
__HAL_DCMI_ENABLE(hdcmi);
|
||||
|
||||
/* Configure the DCMI Mode */
|
||||
hdcmi->Instance->CR &= ~(DCMI_CR_CM);
|
||||
hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
|
||||
|
||||
/* Set the DMA memory0 conversion complete callback */
|
||||
hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt;
|
||||
|
||||
/* Set the DMA error callback */
|
||||
hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
|
||||
|
||||
/* Set the dma abort callback */
|
||||
hdcmi->DMA_Handle->XferAbortCallback = NULL;
|
||||
|
||||
/* Reset transfer counters value */
|
||||
hdcmi->XferCount = 0;
|
||||
hdcmi->XferTransferNumber = 0;
|
||||
|
||||
if(Length <= 0xFFFF)
|
||||
{
|
||||
/* Enable the DMA Stream */
|
||||
HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length);
|
||||
}
|
||||
else /* DCMI_DOUBLE_BUFFER Mode */
|
||||
{
|
||||
/* Set the DMA memory1 conversion complete callback */
|
||||
hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt;
|
||||
|
||||
/* Initialize transfer parameters */
|
||||
hdcmi->XferCount = 1;
|
||||
hdcmi->XferSize = Length;
|
||||
hdcmi->pBuffPtr = pData;
|
||||
|
||||
/* Get the number of buffer */
|
||||
while(hdcmi->XferSize > 0xFFFF)
|
||||
{
|
||||
hdcmi->XferSize = (hdcmi->XferSize/2);
|
||||
hdcmi->XferCount = hdcmi->XferCount*2;
|
||||
}
|
||||
|
||||
/* Update DCMI counter and transfer number*/
|
||||
hdcmi->XferCount = (hdcmi->XferCount - 2);
|
||||
hdcmi->XferTransferNumber = hdcmi->XferCount;
|
||||
|
||||
/* Update second memory address */
|
||||
SecondMemAddress = (uint32_t)(pData + (4*hdcmi->XferSize));
|
||||
|
||||
/* Start DMA multi buffer transfer */
|
||||
HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize);
|
||||
}
|
||||
|
||||
/* Enable Capture */
|
||||
hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable DCMI DMA request and Disable DCMI capture
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
|
||||
{
|
||||
register uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock /8/1000);
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdcmi);
|
||||
|
||||
/* Lock the DCMI peripheral state */
|
||||
hdcmi->State = HAL_DCMI_STATE_BUSY;
|
||||
|
||||
/* Disable Capture */
|
||||
hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
|
||||
|
||||
/* Check if the DCMI capture effectively disabled */
|
||||
do
|
||||
{
|
||||
if (count-- == 0)
|
||||
{
|
||||
/* Update error code */
|
||||
hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
|
||||
|
||||
status = HAL_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0);
|
||||
|
||||
/* Disable the DCMI */
|
||||
__HAL_DCMI_DISABLE(hdcmi);
|
||||
|
||||
/* Disable the DMA */
|
||||
HAL_DMA_Abort(hdcmi->DMA_Handle);
|
||||
|
||||
/* Update error code */
|
||||
hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
|
||||
|
||||
/* Change DCMI state */
|
||||
hdcmi->State = HAL_DCMI_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend DCMI capture
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi)
|
||||
{
|
||||
register uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock /8/1000);
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdcmi);
|
||||
|
||||
if(hdcmi->State == HAL_DCMI_STATE_BUSY)
|
||||
{
|
||||
/* Change DCMI state */
|
||||
hdcmi->State = HAL_DCMI_STATE_SUSPENDED;
|
||||
|
||||
/* Disable Capture */
|
||||
hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
|
||||
|
||||
/* Check if the DCMI capture effectively disabled */
|
||||
do
|
||||
{
|
||||
if (count-- == 0)
|
||||
{
|
||||
/* Update error code */
|
||||
hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
|
||||
|
||||
/* Change DCMI state */
|
||||
hdcmi->State = HAL_DCMI_STATE_READY;
|
||||
|
||||
status = HAL_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0);
|
||||
}
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume DCMI capture
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef* hdcmi)
|
||||
{
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdcmi);
|
||||
|
||||
if(hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
|
||||
{
|
||||
/* Change DCMI state */
|
||||
hdcmi->State = HAL_DCMI_STATE_BUSY;
|
||||
|
||||
/* Disable Capture */
|
||||
hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
|
||||
}
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handles DCMI interrupt request.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for the DCMI.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
uint32_t isr_value = READ_REG(hdcmi->Instance->MISR);
|
||||
|
||||
/* Synchronization error interrupt management *******************************/
|
||||
if((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI)
|
||||
{
|
||||
/* Clear the Synchronization error flag */
|
||||
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
|
||||
|
||||
/* Update error code */
|
||||
hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
|
||||
|
||||
/* Change DCMI state */
|
||||
hdcmi->State = HAL_DCMI_STATE_ERROR;
|
||||
|
||||
/* Set the synchronization error callback */
|
||||
hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
|
||||
|
||||
/* Abort the DMA Transfer */
|
||||
HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
|
||||
}
|
||||
/* Overflow interrupt management ********************************************/
|
||||
if((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI)
|
||||
{
|
||||
/* Clear the Overflow flag */
|
||||
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
|
||||
|
||||
/* Update error code */
|
||||
hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
|
||||
|
||||
/* Change DCMI state */
|
||||
hdcmi->State = HAL_DCMI_STATE_ERROR;
|
||||
|
||||
/* Set the overflow callback */
|
||||
hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
|
||||
|
||||
/* Abort the DMA Transfer */
|
||||
HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
|
||||
}
|
||||
/* Line Interrupt management ************************************************/
|
||||
if((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI)
|
||||
{
|
||||
/* Clear the Line interrupt flag */
|
||||
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
|
||||
|
||||
/* Line interrupt Callback */
|
||||
HAL_DCMI_LineEventCallback(hdcmi);
|
||||
}
|
||||
/* VSYNC interrupt management ***********************************************/
|
||||
if((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI)
|
||||
{
|
||||
/* Clear the VSYNC flag */
|
||||
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
|
||||
|
||||
/* VSYNC Callback */
|
||||
HAL_DCMI_VsyncEventCallback(hdcmi);
|
||||
}
|
||||
/* FRAME interrupt management ***********************************************/
|
||||
if((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI)
|
||||
{
|
||||
/* When snapshot mode, disable Vsync, Error and Overrun interrupts */
|
||||
if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
|
||||
{
|
||||
/* Disable the Line, Vsync, Error and Overrun interrupts */
|
||||
__HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
|
||||
}
|
||||
|
||||
/* Disable the Frame interrupt */
|
||||
__HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
|
||||
|
||||
/* Clear the End of Frame flag */
|
||||
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
|
||||
|
||||
/* Frame Callback */
|
||||
HAL_DCMI_FrameEventCallback(hdcmi);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Error DCMI callback.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdcmi);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_DCMI_ErrorCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Line Event callback.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_DCMI_LineEventCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VSYNC Event callback.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdcmi);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_DCMI_VsyncEventCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Frame Event callback.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdcmi);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_DCMI_FrameEventCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
|
||||
* @brief Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure the CROP feature.
|
||||
(+) Enable/Disable the CROP feature.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure the DCMI CROP coordinate.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @param YSize: DCMI Line number
|
||||
* @param XSize: DCMI Pixel per line
|
||||
* @param X0: DCMI window X offset
|
||||
* @param Y0: DCMI window Y offset
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdcmi);
|
||||
|
||||
/* Lock the DCMI peripheral state */
|
||||
hdcmi->State = HAL_DCMI_STATE_BUSY;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
|
||||
assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));
|
||||
assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
|
||||
assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));
|
||||
|
||||
/* Configure CROP */
|
||||
hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_POSITION_CWSIZE_VLINE));
|
||||
hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_POSITION_CWSTRT_VST));
|
||||
|
||||
/* Initialize the DCMI state*/
|
||||
hdcmi->State = HAL_DCMI_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Crop feature.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdcmi);
|
||||
|
||||
/* Lock the DCMI peripheral state */
|
||||
hdcmi->State = HAL_DCMI_STATE_BUSY;
|
||||
|
||||
/* Disable DCMI Crop feature */
|
||||
hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP;
|
||||
|
||||
/* Change the DCMI state*/
|
||||
hdcmi->State = HAL_DCMI_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Crop feature.
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdcmi);
|
||||
|
||||
/* Lock the DCMI peripheral state */
|
||||
hdcmi->State = HAL_DCMI_STATE_BUSY;
|
||||
|
||||
/* Enable DCMI Crop feature */
|
||||
hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP;
|
||||
|
||||
/* Change the DCMI state*/
|
||||
hdcmi->State = HAL_DCMI_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdcmi);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
|
||||
* @brief Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral State and Errors functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides functions allowing to
|
||||
(+) Check the DCMI state.
|
||||
(+) Get the specific DCMI error flag.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the DCMI state
|
||||
* @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
return hdcmi->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the DCMI error code
|
||||
* @param hdcmi : pointer to a DCMI_HandleTypeDef structure that contains
|
||||
* the configuration information for DCMI.
|
||||
* @retval DCMI Error Code
|
||||
*/
|
||||
uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
|
||||
{
|
||||
return hdcmi->ErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/** @defgroup DCMI_Private_Functions DCMI Private Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief DMA conversion complete callback.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
uint32_t tmp = 0;
|
||||
|
||||
DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
||||
|
||||
if(hdcmi->XferCount != 0)
|
||||
{
|
||||
/* Update memory 0 address location */
|
||||
tmp = ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR) & DMA_SxCR_CT);
|
||||
if(((hdcmi->XferCount % 2) == 0) && (tmp != 0))
|
||||
{
|
||||
tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR;
|
||||
HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY0);
|
||||
hdcmi->XferCount--;
|
||||
}
|
||||
/* Update memory 1 address location */
|
||||
else if((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0)
|
||||
{
|
||||
tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR;
|
||||
HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY1);
|
||||
hdcmi->XferCount--;
|
||||
}
|
||||
}
|
||||
/* Update memory 0 address location */
|
||||
else if((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) != 0)
|
||||
{
|
||||
((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR = hdcmi->pBuffPtr;
|
||||
}
|
||||
/* Update memory 1 address location */
|
||||
else if((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0)
|
||||
{
|
||||
tmp = hdcmi->pBuffPtr;
|
||||
((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR = (tmp + (4*hdcmi->XferSize));
|
||||
hdcmi->XferCount = hdcmi->XferTransferNumber;
|
||||
}
|
||||
|
||||
/* Check if the frame is transferred */
|
||||
if(hdcmi->XferCount == hdcmi->XferTransferNumber)
|
||||
{
|
||||
/* Enable the Frame interrupt */
|
||||
__HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
|
||||
|
||||
/* When snapshot mode, set dcmi state to ready */
|
||||
if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
|
||||
{
|
||||
hdcmi->State= HAL_DCMI_STATE_READY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA error callback
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
||||
|
||||
if(hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE)
|
||||
{
|
||||
/* Initialize the DCMI state*/
|
||||
hdcmi->State = HAL_DCMI_STATE_READY;
|
||||
|
||||
/* Set DCMI Error Code */
|
||||
hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
|
||||
}
|
||||
|
||||
/* DCMI error Callback */
|
||||
HAL_DCMI_ErrorCallback(hdcmi);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_DCMI_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+3016
File diff suppressed because it is too large
Load Diff
+1939
File diff suppressed because it is too large
Load Diff
+1752
File diff suppressed because it is too large
Load Diff
+638
@@ -0,0 +1,638 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_dma_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief DMA Extension HAL module driver
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the DMA Extension peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
@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
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DMAEx DMAEx
|
||||
* @brief DMA Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private Constants ---------------------------------------------------------*/
|
||||
#define DMAMUX_POSITION_CxCR_SE (uint32_t)POSITION_VAL(DMAMUX_CxCR_SE) /*!< Required for left shift of the DMAMUX SYNC enable/disable */
|
||||
#define DMAMUX_POSITION_CxCR_EGE (uint32_t)POSITION_VAL(DMAMUX_CxCR_EGE) /*!< Required for left shift of the DMAMUX SYNC EVENT enable/disable */
|
||||
/* 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 = NULL; /* DMA Stream Interrupt Clear register */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
|
||||
|
||||
/* Memory-to-memory transfer not supported in double buffering mode */
|
||||
/* double buffering mode not supported for BDMA (D3 DMA) */
|
||||
if ( (IS_D2_DMA_INSTANCE(hdma) == 0U) || (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 = 0x3FU << hdma->StreamIndex;
|
||||
|
||||
/* 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 = NULL; /* DMA Stream Interrupt Clear register */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
|
||||
|
||||
/* Memory-to-memory transfer not supported in double buffering mode */
|
||||
/* double buffering mode not supported for BDMA (D3 DMA) */
|
||||
if( (IS_D2_DMA_INSTANCE(hdma) == 0U) || (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 = 0x3FU << hdma->StreamIndex;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/*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) != 0)
|
||||
{
|
||||
/* 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));
|
||||
|
||||
if(IS_D2_DMA_INSTANCE(hdma) != 0U)
|
||||
{
|
||||
assert_param(IS_D2_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_D3_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 << POSITION_VAL(DMAMUX_CxCR_SYNC_ID)) | \
|
||||
((pSyncConfig->RequestNumber - 1U) << POSITION_VAL(DMAMUX_CxCR_NBREQ)) | \
|
||||
syncPolarity | (pSyncConfig->SyncEnable << DMAMUX_POSITION_CxCR_SE) | \
|
||||
(pSyncConfig->EventEnable << DMAMUX_POSITION_CxCR_EGE));
|
||||
|
||||
/* 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_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
if(IS_D2_DMA_INSTANCE(hdma) != 0U)
|
||||
{
|
||||
assert_param(IS_D2_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_D3_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->State == HAL_DMA_STATE_READY) && ((hdma->DMAmuxRequestGen->RGCR & DMAMUX_RGxCR_GE) == 0))
|
||||
{
|
||||
/* 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) << POSITION_VAL(DMAMUX_RGxCR_NBREQ))| \
|
||||
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)
|
||||
{
|
||||
/* 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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+2603
File diff suppressed because it is too large
Load Diff
+571
@@ -0,0 +1,571 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_eth_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief ETH HAL Extended module driver.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup ETHEx ETHEx
|
||||
* @brief ETH HAL Extended module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_ETH_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup ETHEx_Private_Constants ETHEx Private Constants
|
||||
* @{
|
||||
*/
|
||||
#define ETH_MACL4CR_MASK (ETH_MACL3L4CR_L4PEN | ETH_MACL3L4CR_L4SPM | \
|
||||
ETH_MACL3L4CR_L4SPIM | ETH_MACL3L4CR_L4DPM | \
|
||||
ETH_MACL3L4CR_L4DPIM)
|
||||
|
||||
#define ETH_MACL3CR_MASK (ETH_MACL3L4CR_L3PEN | ETH_MACL3L4CR_L3SAM | \
|
||||
ETH_MACL3L4CR_L3SAIM | ETH_MACL3L4CR_L3DAM | \
|
||||
ETH_MACL3L4CR_L3DAIM | ETH_MACL3L4CR_L3HSBM | \
|
||||
ETH_MACL3L4CR_L3HDBM)
|
||||
|
||||
#define ETH_MACRXVLAN_MASK (ETH_MACVTR_EIVLRXS | ETH_MACVTR_EIVLS | \
|
||||
ETH_MACVTR_ERIVLT | ETH_MACVTR_EDVLP | \
|
||||
ETH_MACVTR_VTHM | ETH_MACVTR_EVLRXS | \
|
||||
ETH_MACVTR_EVLS | ETH_MACVTR_DOVLTC | \
|
||||
ETH_MACVTR_ERSVLM | ETH_MACVTR_ESVL | \
|
||||
ETH_MACVTR_VTIM | ETH_MACVTR_ETV)
|
||||
|
||||
#define ETH_MACTXVLAN_MASK (ETH_MACVIR_VLTI | ETH_MACVIR_CSVL | \
|
||||
ETH_MACVIR_VLP | ETH_MACVIR_VLC)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions ---------------------------------------------------------*/
|
||||
/** @defgroup ETHEx_Exported_Functions ETH Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup ETHEx_Exported_Functions_Group1 Extended features functions
|
||||
* @brief Extended features functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended features functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure ARP offload module
|
||||
(+) Configure L3 and L4 filters
|
||||
(+) Configure Extended VLAN features
|
||||
(+) Configure Energy Efficient Ethernet module
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enables ARP Offload.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETHEx_EnableARPOffload(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
SET_BIT(heth->Instance->MACCR, ETH_MACCR_ARP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables ARP Offload.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETHEx_DisableARPOffload(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_ARP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the ARP Match IP address
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param IpAddress: IP Address to be matched for incoming ARP requests
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETHEx_SetARPAddressMatch(ETH_HandleTypeDef *heth, uint32_t IpAddress)
|
||||
{
|
||||
WRITE_REG(heth->Instance->MACARPAR, IpAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the L4 Filter, this function allow to:
|
||||
* set the layer 4 protocol to be matched (TCP or UDP)
|
||||
* enable/disable L4 source/destination port perfect/inverse match.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param Filter: L4 filter to configured, this parameter must be one of the following
|
||||
* ETH_L4_FILTER_0
|
||||
* ETH_L4_FILTER_1
|
||||
* @param pL4FilterConfig: pointer to a ETH_L4FilterConfigTypeDef structure
|
||||
* that contains L4 filter configuration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_SetL4FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter , ETH_L4FilterConfigTypeDef *pL4FilterConfig)
|
||||
{
|
||||
__IO uint32_t *configreg = ((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter));
|
||||
|
||||
if(pL4FilterConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Write configuration to (MACL3L4C0R + filter )register */
|
||||
MODIFY_REG(*configreg, ETH_MACL4CR_MASK ,(pL4FilterConfig->Protocol |
|
||||
pL4FilterConfig->SrcPortFilterMatch |
|
||||
pL4FilterConfig->DestPortFilterMatch));
|
||||
|
||||
configreg = ((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter));
|
||||
|
||||
/* Write configuration to (MACL4A0R + filter )register */
|
||||
MODIFY_REG(*configreg, (ETH_MACL4AR_L4DP | ETH_MACL4AR_L4SP) , (pL4FilterConfig->SourcePort |
|
||||
(pL4FilterConfig->DestinationPort << 16)));
|
||||
|
||||
/* Enable L4 filter */
|
||||
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the L4 Filter, this function allow to:
|
||||
* set the layer 4 protocol to be matched (TCP or UDP)
|
||||
* enable/disable L4 source/destination port perfect/inverse match.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param Filter: L4 filter to configured, this parameter must be one of the following
|
||||
* ETH_L4_FILTER_0
|
||||
* ETH_L4_FILTER_1
|
||||
* @param pL4FilterConfig: pointer to a ETH_L4FilterConfigTypeDef structure
|
||||
* that contains L4 filter configuration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_GetL4FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter, ETH_L4FilterConfigTypeDef *pL4FilterConfig)
|
||||
{
|
||||
if(pL4FilterConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Get configuration to (MACL3L4C0R + filter )register */
|
||||
pL4FilterConfig->Protocol = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L4PEN);
|
||||
pL4FilterConfig->DestPortFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L4DPM | ETH_MACL3L4CR_L4DPIM));
|
||||
pL4FilterConfig->SrcPortFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L4SPM | ETH_MACL3L4CR_L4SPIM));
|
||||
|
||||
/* Get configuration to (MACL3L4C0R + filter )register */
|
||||
pL4FilterConfig->DestinationPort = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter)), ETH_MACL4AR_L4DP) >> 16);
|
||||
pL4FilterConfig->SourcePort = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter)), ETH_MACL4AR_L4SP);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the L3 Filter, this function allow to:
|
||||
* set the layer 3 protocol to be matched (IPv4 or IPv6)
|
||||
* enable/disable L3 source/destination port perfect/inverse match.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param Filter: L3 filter to configured, this parameter must be one of the following
|
||||
* ETH_L3_FILTER_0
|
||||
* ETH_L3_FILTER_1
|
||||
* @param pL3FilterConfig: pointer to a ETH_L3FilterConfigTypeDef structure
|
||||
* that contains L3 filter configuration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter, ETH_L3FilterConfigTypeDef *pL3FilterConfig)
|
||||
{
|
||||
__IO uint32_t *configreg = ((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter));
|
||||
|
||||
if(pL3FilterConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Write configuration to (MACL3L4C0R + filter )register */
|
||||
MODIFY_REG(*configreg, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
|
||||
pL3FilterConfig->SrcAddrFilterMatch |
|
||||
pL3FilterConfig->DestAddrFilterMatch |
|
||||
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
|
||||
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
|
||||
|
||||
/* Check if IPv6 protocol is selected */
|
||||
if(pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
|
||||
{
|
||||
/* Set the IPv6 address match */
|
||||
/* Set Bits[31:0] of 128-bit IP addr */
|
||||
*((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter)) = pL3FilterConfig->Ip6Addr[0];
|
||||
/* Set Bits[63:32] of 128-bit IP addr */
|
||||
*((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter)) = pL3FilterConfig->Ip6Addr[1];
|
||||
/* update Bits[95:64] of 128-bit IP addr */
|
||||
*((__IO uint32_t *)(&(heth->Instance->MACL3A2R0R) + Filter)) = pL3FilterConfig->Ip6Addr[2];
|
||||
/* update Bits[127:96] of 128-bit IP addr */
|
||||
*((__IO uint32_t *)(&(heth->Instance->MACL3A3R0R) + Filter)) = pL3FilterConfig->Ip6Addr[3];
|
||||
}
|
||||
else /* IPv4 protocol is selected */
|
||||
{
|
||||
/* Set the IPv4 source address match */
|
||||
*((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter)) = pL3FilterConfig->Ip4SrcAddr;
|
||||
/* Set the IPv4 destination address match */
|
||||
*((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter)) = pL3FilterConfig->Ip4DestAddr;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the L3 Filter, this function allow to:
|
||||
* set the layer 3 protocol to be matched (IPv4 or IPv6)
|
||||
* enable/disable L3 source/destination port perfect/inverse match.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param Filter: L3 filter to configured, this parameter must be one of the following
|
||||
* ETH_L3_FILTER_0
|
||||
* ETH_L3_FILTER_1
|
||||
* @param pL3FilterConfig: pointer to a ETH_L3FilterConfigTypeDef structure
|
||||
* that will contain the L3 filter configuration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_GetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter, ETH_L3FilterConfigTypeDef *pL3FilterConfig)
|
||||
{
|
||||
if(pL3FilterConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
pL3FilterConfig->Protocol = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L3PEN);
|
||||
pL3FilterConfig->SrcAddrFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L3SAM | ETH_MACL3L4CR_L3SAIM));
|
||||
pL3FilterConfig->DestAddrFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), (ETH_MACL3L4CR_L3DAM | ETH_MACL3L4CR_L3DAIM));
|
||||
pL3FilterConfig->SrcAddrHigherBitsMatch = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L3HSBM) >> 6);
|
||||
pL3FilterConfig->DestAddrHigherBitsMatch = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)), ETH_MACL3L4CR_L3HDBM) >> 11);
|
||||
|
||||
if(pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
|
||||
{
|
||||
pL3FilterConfig->Ip6Addr[0] = *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter));
|
||||
pL3FilterConfig->Ip6Addr[1] = *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter));
|
||||
pL3FilterConfig->Ip6Addr[2] = *((__IO uint32_t *)(&(heth->Instance->MACL3A2R0R) + Filter));
|
||||
pL3FilterConfig->Ip6Addr[3] = *((__IO uint32_t *)(&(heth->Instance->MACL3A3R0R) + Filter));
|
||||
}
|
||||
else
|
||||
{
|
||||
pL3FilterConfig->Ip4SrcAddr = *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter));
|
||||
pL3FilterConfig->Ip4DestAddr = *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter));
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables L3 and L4 filtering process.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_ETHEx_EnableL3L4Filtering(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
/* Enable L3/L4 filter */
|
||||
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables L3 and L4 filtering process.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_ETHEx_DisableL3L4Filtering(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
/* Disable L3/L4 filter */
|
||||
CLEAR_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the VLAN Configuration for Receive Packets.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param pVlanConfig: pointer to a ETH_RxVLANConfigTypeDef structure
|
||||
* that will contain the VLAN filter configuration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_GetRxVLANConfig(ETH_HandleTypeDef *heth, ETH_RxVLANConfigTypeDef *pVlanConfig)
|
||||
{
|
||||
if(pVlanConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
pVlanConfig->InnerVLANTagInStatus = (FunctionalState)(READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLRXS) >> 31);
|
||||
pVlanConfig->StripInnerVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLS);
|
||||
pVlanConfig->InnerVLANTag = (FunctionalState)(READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_ERIVLT) >> 27);
|
||||
pVlanConfig->DoubleVLANProcessing = (FunctionalState)(READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EDVLP) >> 26);
|
||||
pVlanConfig->VLANTagHashTableMatch = (FunctionalState)(READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTHM) >> 25);
|
||||
pVlanConfig->VLANTagInStatus = (FunctionalState)(READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EVLRXS) >> 24);
|
||||
pVlanConfig->StripVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EVLS);
|
||||
pVlanConfig->VLANTypeCheck = READ_BIT(heth->Instance->MACVTR, (ETH_MACVTR_DOVLTC | ETH_MACVTR_ERSVLM | ETH_MACVTR_ESVL));
|
||||
pVlanConfig->VLANTagInverceMatch = (FunctionalState)(READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTIM) >> 17);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the VLAN Configuration for Receive Packets.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param pVlanConfig: pointer to a ETH_RxVLANConfigTypeDef structure
|
||||
* that contains VLAN filter configuration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_SetRxVLANConfig(ETH_HandleTypeDef *heth, ETH_RxVLANConfigTypeDef *pVlanConfig)
|
||||
{
|
||||
if(pVlanConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Write config to MACVTR */
|
||||
MODIFY_REG(heth->Instance->MACVTR, ETH_MACRXVLAN_MASK, ((uint32_t)(pVlanConfig->InnerVLANTagInStatus << 31) |
|
||||
pVlanConfig->StripInnerVLANTag |
|
||||
(uint32_t)(pVlanConfig->InnerVLANTag << 27) |
|
||||
(uint32_t)(pVlanConfig->DoubleVLANProcessing << 26) |
|
||||
(uint32_t)(pVlanConfig->VLANTagHashTableMatch << 25) |
|
||||
(uint32_t)(pVlanConfig->VLANTagInStatus << 24) |
|
||||
pVlanConfig->StripVLANTag |
|
||||
pVlanConfig->VLANTypeCheck |
|
||||
(uint32_t)(pVlanConfig->VLANTagInverceMatch << 17)));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the VLAN Hash Table
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param VLANHashTable: VLAN hash table 16 bit value
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETHEx_SetVLANHashTable(ETH_HandleTypeDef *heth, uint32_t VLANHashTable)
|
||||
{
|
||||
MODIFY_REG(heth->Instance->MACVHTR, ETH_MACVHTR_VLHT, VLANHashTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the VLAN Configuration for Transmit Packets.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param VLANTag: Selects the vlan tag, this parameter must be one of the following
|
||||
* ETH_OUTER_TX_VLANTAG
|
||||
* ETH_INNER_TX_VLANTAG
|
||||
* @param pVlanConfig: pointer to a ETH_TxVLANConfigTypeDef structure
|
||||
* that will contain the Tx VLAN filter configuration.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_GetTxVLANConfig(ETH_HandleTypeDef *heth, uint32_t VLANTag ,ETH_TxVLANConfigTypeDef *pVlanConfig)
|
||||
{
|
||||
if (pVlanConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if(VLANTag == ETH_INNER_TX_VLANTAG)
|
||||
{
|
||||
pVlanConfig->SourceTxDesc = (FunctionalState)(READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_VLTI) >> 20);
|
||||
pVlanConfig->SVLANType = (FunctionalState)(READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_CSVL) >> 19);
|
||||
pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACIVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVlanConfig->SourceTxDesc = (FunctionalState)(READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_VLTI) >> 20);
|
||||
pVlanConfig->SVLANType = (FunctionalState)(READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_CSVL) >> 19);
|
||||
pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
|
||||
}
|
||||
|
||||
return HAL_OK;;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the VLAN Configuration for Transmit Packets.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param VLANTag: Selects the vlan tag, this parameter must be one of the following
|
||||
* ETH_OUTER_TX_VLANTAG
|
||||
* ETH_INNER_TX_VLANTAG
|
||||
* @param pVlanConfig: pointer to a ETH_TxVLANConfigTypeDef structure
|
||||
* that contains Tx VLAN filter configuration.
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ETHEx_SetTxVLANConfig(ETH_HandleTypeDef *heth, uint32_t VLANTag ,ETH_TxVLANConfigTypeDef *pVlanConfig)
|
||||
{
|
||||
if(VLANTag == ETH_INNER_TX_VLANTAG)
|
||||
{
|
||||
MODIFY_REG(heth->Instance->MACIVIR, ETH_MACTXVLAN_MASK, ((uint32_t)(pVlanConfig->SourceTxDesc << 20) |
|
||||
(uint32_t)(pVlanConfig->SVLANType << 19) |
|
||||
pVlanConfig->VLANTagControl));
|
||||
/* Enable Double VLAN processing */
|
||||
SET_BIT(heth->Instance->MACVTR, ETH_MACVTR_EDVLP);
|
||||
}
|
||||
else
|
||||
{
|
||||
MODIFY_REG(heth->Instance->MACVIR, ETH_MACTXVLAN_MASK, ((uint32_t)(pVlanConfig->SourceTxDesc << 20) |
|
||||
(uint32_t)(pVlanConfig->SVLANType << 19) |
|
||||
pVlanConfig->VLANTagControl));
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the VLAN Tag Identifier for Transmit Packets.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param VLANTag: Selects the vlan tag, this parameter must be one of the following
|
||||
* ETH_OUTER_TX_VLANTAG
|
||||
* ETH_INNER_TX_VLANTAG
|
||||
* @param VLANIdentifier: VLAN Identifier 16 bit value
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETHEx_SetTxVLANIdentifier(ETH_HandleTypeDef *heth, uint32_t VLANTag ,uint32_t VLANIdentifier)
|
||||
{
|
||||
if(VLANTag == ETH_INNER_TX_VLANTAG)
|
||||
{
|
||||
MODIFY_REG(heth->Instance->MACIVIR, ETH_MACVIR_VLT, VLANIdentifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
MODIFY_REG(heth->Instance->MACVIR, ETH_MACVIR_VLT, VLANIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the VLAN Tag Filtering process.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_ETHEx_EnableVLANProcessing(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
/* Enable VLAN processing */
|
||||
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_VTFE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables the VLAN Tag Filtering process.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_ETHEx_DisableVLANProcessing(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
/* Disable VLAN processing */
|
||||
CLEAR_BIT(heth->Instance->MACPFR, ETH_MACPFR_VTFE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enters the Low Power Idle (LPI) mode
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @param TxAutomate: Enable/Disbale automate enter/exit LPI mode.
|
||||
* @param TxClockStop: Enable/Disbale Tx clock stop in LPI mode.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETHEx_EnterLPIMode(ETH_HandleTypeDef *heth, FunctionalState TxAutomate, FunctionalState TxClockStop)
|
||||
{
|
||||
/* Enable LPI Interrupts */
|
||||
__HAL_ETH_MAC_ENABLE_IT(heth, ETH_MACIER_LPIIE);
|
||||
|
||||
/* Write to LPI Control register: Enter low power mode */
|
||||
MODIFY_REG(heth->Instance->MACLCSR, (ETH_MACLCSR_LPIEN | ETH_MACLCSR_LPITXA | ETH_MACLCSR_LPITCSE), (((uint32_t)TxAutomate << 19) |
|
||||
((uint32_t)TxClockStop << 21) |
|
||||
ETH_MACLCSR_LPIEN));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Exits the Low Power Idle (LPI) mode.
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETHEx_ExitLPIMode(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
/* Clear the LPI Config and exit low power mode */
|
||||
CLEAR_BIT(heth->Instance->MACLCSR, (ETH_MACLCSR_LPIEN | ETH_MACLCSR_LPITXA | ETH_MACLCSR_LPITCSE));
|
||||
|
||||
/* Enable LPI Interrupts */
|
||||
__HAL_ETH_MAC_DISABLE_IT(heth, ETH_MACIER_LPIIE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the ETH MAC LPI event
|
||||
* @param heth: pointer to a ETH_HandleTypeDef structure that contains
|
||||
* the configuration information for ETHERNET module
|
||||
* @retval ETH MAC WakeUp event
|
||||
*/
|
||||
uint32_t HAL_ETHEx_GetMACLPIEvent(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
return heth->MACLPIEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_ETH_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+4775
File diff suppressed because it is too large
Load Diff
+948
@@ -0,0 +1,948 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_flash.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief FLASH HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the internal FLASH memory:
|
||||
* + Program operations functions
|
||||
* + Memory Control functions
|
||||
* + Peripheral Errors functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### FLASH peripheral features #####
|
||||
==============================================================================
|
||||
|
||||
[..] The Flash memory interface manages CPU AXI I-Code and D-Code accesses
|
||||
to the Flash memory. It implements the erase and program Flash memory operations
|
||||
and the read and write protection mechanisms.
|
||||
|
||||
|
||||
|
||||
[..] The FLASH main features are:
|
||||
(+) Flash memory read operations
|
||||
(+) Flash memory program/erase operations
|
||||
(+) Read / write protections
|
||||
(+) Option bytes programming
|
||||
(+) Error code correction (ECC) : Data in flash are 266-bits word
|
||||
(10 bits added per double word)
|
||||
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This driver provides functions and macros to configure and program the FLASH
|
||||
memory of all STM32H7xx devices.
|
||||
|
||||
(#) FLASH Memory IO Programming functions:
|
||||
(++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
|
||||
HAL_FLASH_Lock() functions
|
||||
(++) Program functions: double word only
|
||||
(++) There Two modes of programming :
|
||||
(+++) Polling mode using HAL_FLASH_Program() function
|
||||
(+++) Interrupt mode using HAL_FLASH_Program_IT() function
|
||||
|
||||
(#) Interrupts and flags management functions :
|
||||
(++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
|
||||
(++) Callback functions are called when the flash operations are finished :
|
||||
HAL_FLASH_EndOfOperationCallback() when everything is ok, otherwise
|
||||
HAL_FLASH_OperationErrorCallback()
|
||||
(++) Get error flag status by calling HAL_FLASH_GetError()
|
||||
|
||||
(#) Option bytes management functions :
|
||||
(++) Lock and Unlock the option bytes using HAL_FLASH_OB_Unlock() and
|
||||
HAL_FLASH_OB_Lock() functions
|
||||
(++) Launch the reload of the option bytes using HAL_FLASH_Launch() function.
|
||||
In this case, a reset is generated
|
||||
[..]
|
||||
In addition to these functions, this driver includes a set of macros allowing
|
||||
to handle the following operations:
|
||||
(+) Set the latency
|
||||
(+) Enable/Disable the FLASH interrupts
|
||||
(+) Monitor the FLASH flags status
|
||||
[..]
|
||||
(@) For any Flash memory program operation (erase or program), the CPU clock frequency
|
||||
(HCLK) must be at least 1MHz.
|
||||
(@) The contents of the Flash memory are not guaranteed if a device reset occurs during
|
||||
a Flash memory operation.
|
||||
(@) Any attempt to read the Flash memory while it is being written or erased, causes the
|
||||
bus to stall. Read operations are processed correctly once the program operation has
|
||||
completed. This means that code or data fetches cannot be performed while a write/erase
|
||||
operation is ongoing
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH FLASH
|
||||
* @brief FLASH HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @addtogroup FLASH_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
#define FLASH_TIMEOUT_VALUE ((uint32_t)50000U)/* 50 s */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
FLASH_ProcessTypeDef pFlash;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void FLASH_SetErrorCode(uint32_t Bank);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup FLASH_Private_Functions FLASH Private functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH_Group1 Programming operation functions
|
||||
* @brief Programming operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Programming operation functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to manage the FLASH
|
||||
program operations.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Program flash word of 256 bits at a specified address
|
||||
* @param TypeProgram Indicate the way to program at a specified address.
|
||||
* This parameter can be a value of @ref FLASH_Type_Program
|
||||
* @param FlashAddress specifies the address to be programmed.
|
||||
* @param DataAddress specifies the address of data (256 bits) to be programmed
|
||||
*
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t FlashAddress, uint64_t DataAddress)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
__IO uint64_t *dest_addr = (__IO uint64_t *)FlashAddress;
|
||||
__IO uint64_t *src_addr = (__IO uint64_t*)((uint32_t)DataAddress);
|
||||
uint32_t bank;
|
||||
uint8_t row_index = 4;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(&pFlash);
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
|
||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(FlashAddress));
|
||||
|
||||
if(IS_FLASH_PROGRAM_ADDRESS_BANK1(FlashAddress))
|
||||
{
|
||||
bank = FLASH_BANK_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bank = FLASH_BANK_2;
|
||||
}
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, bank);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if(bank == FLASH_BANK_1)
|
||||
{
|
||||
/* Clear bank 1 pending flags (if any) */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_QW_BANK1 | FLASH_FLAG_WBNE_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK1);
|
||||
|
||||
/* Set PG bit */
|
||||
SET_BIT(FLASH->CR1, FLASH_CR_PG);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear bank 2 pending flags (if any) */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_QW_BANK2 | FLASH_FLAG_WBNE_BANK2 | FLASH_FLAG_ALL_ERRORS_BANK2);
|
||||
|
||||
/* Set PG bit */
|
||||
SET_BIT(FLASH->CR2, FLASH_CR_PG);
|
||||
}
|
||||
|
||||
/* Program the 256 bits flash word */
|
||||
do
|
||||
{
|
||||
*dest_addr++ = *src_addr++;
|
||||
} while (--row_index != 0);
|
||||
|
||||
__DSB();
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, bank);
|
||||
|
||||
if(bank == FLASH_BANK_1)
|
||||
{
|
||||
/* Check FLASH End of Operation flag */
|
||||
if (__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_EOP_BANK1))
|
||||
{
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1);
|
||||
}
|
||||
|
||||
/* If the program operation is completed, disable the PG*/
|
||||
CLEAR_BIT(FLASH->CR1, FLASH_CR_PG);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check FLASH End of Operation flag */
|
||||
if (__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_EOP_BANK2))
|
||||
{
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2);
|
||||
}
|
||||
|
||||
/* If the program operation is completed, disable the PG */
|
||||
CLEAR_BIT(FLASH->CR2, FLASH_CR_PG);
|
||||
}
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Program flash words of 256 bits at a specified address with interrupt enabled.
|
||||
* @param TypeProgram Indicate the way to program at a specified address.
|
||||
* This parameter can be a value of @ref FLASH_Type_Program
|
||||
* @param FlashAddress specifies the address to be programmed.
|
||||
* @param DataAddress specifies the address of data (256 bits) to be programmed
|
||||
*
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t FlashAddress, uint64_t DataAddress)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint64_t *dest_addr = (__IO uint64_t*)FlashAddress;
|
||||
__IO uint64_t *src_addr = (__IO uint64_t*)((uint32_t)DataAddress);
|
||||
uint32_t bank;
|
||||
uint8_t row_index = 4;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(&pFlash);
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
|
||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(FlashAddress));
|
||||
|
||||
if(IS_FLASH_PROGRAM_ADDRESS_BANK1(FlashAddress))
|
||||
{
|
||||
bank = FLASH_BANK_1;
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM_BANK1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bank = FLASH_BANK_2;
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM_BANK2;
|
||||
}
|
||||
|
||||
/* Set internal variables used by the IRQ handler */
|
||||
pFlash.Address = FlashAddress;
|
||||
|
||||
if(bank == FLASH_BANK_1)
|
||||
{
|
||||
/* Clear bank 1 pending flags (if any) */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK1);
|
||||
|
||||
/* Set PG bit */
|
||||
SET_BIT(FLASH->CR1, FLASH_CR_PG);
|
||||
|
||||
/* Enable End of Operation and Error interrupts for Bank 1 */
|
||||
__HAL_FLASH_ENABLE_IT_BANK1(FLASH_IT_EOP_BANK1 | FLASH_IT_WRPERR_BANK1 | FLASH_IT_PGSERR_BANK1 | \
|
||||
FLASH_IT_STRBERR_BANK1 | FLASH_IT_INCERR_BANK1 | FLASH_IT_OPERR_BANK1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear bank 2 pending flags (if any) */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_ALL_ERRORS_BANK2);
|
||||
|
||||
/* Set PG bit */
|
||||
SET_BIT(FLASH->CR2, FLASH_CR_PG);
|
||||
|
||||
/* Enable End of Operation and Error interrupts for Bank2*/
|
||||
__HAL_FLASH_ENABLE_IT_BANK2(FLASH_IT_EOP_BANK2 | FLASH_IT_WRPERR_BANK2 | FLASH_IT_PGSERR_BANK2 | \
|
||||
FLASH_IT_STRBERR_BANK2 | FLASH_IT_INCERR_BANK2 | FLASH_IT_OPERR_BANK2);
|
||||
}
|
||||
|
||||
/* Program the 256 bits flash word */
|
||||
do
|
||||
{
|
||||
*dest_addr++ = *src_addr++;
|
||||
} while (--row_index != 0);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles FLASH interrupt request.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_FLASH_IRQHandler(void)
|
||||
{
|
||||
uint32_t temp;
|
||||
|
||||
/* Check FLASH Bank1 End of Operation flag */
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_SR_EOP) != RESET)
|
||||
{
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK1)
|
||||
{
|
||||
/*Nb of sector to erased can be decreased*/
|
||||
pFlash.NbSectorsToErase--;
|
||||
|
||||
/* Check if there are still sectors to erase*/
|
||||
if(pFlash.NbSectorsToErase != 0)
|
||||
{
|
||||
temp = pFlash.Sector;
|
||||
/*Indicate user which sector has been erased*/
|
||||
HAL_FLASH_EndOfOperationCallback(temp);
|
||||
|
||||
/* Clear pending flags (if any) */
|
||||
/* Clear bank 1 pending flags (if any) */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK1);
|
||||
|
||||
/*Increment sector number*/
|
||||
temp = ++pFlash.Sector;
|
||||
FLASH_Erase_Sector(temp, FLASH_BANK_1/*pFlash.Bank*/, pFlash.VoltageForErase);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*No more sectors to Erase, user callback can be called.*/
|
||||
/*Reset Sector and stop Erase sectors procedure*/
|
||||
pFlash.Sector = temp = 0xFFFFFFFF;
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(temp);
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK1) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
|
||||
{
|
||||
/*MassErase ended. Return the selected bank*/
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(FLASH_BANK_1);
|
||||
}
|
||||
else if(pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM_BANK1)
|
||||
{
|
||||
/*Program ended. Return the selected address*/
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||
}
|
||||
|
||||
if((pFlash.ProcedureOnGoing != FLASH_PROC_SECTERASE_BANK2) && \
|
||||
(pFlash.ProcedureOnGoing != FLASH_PROC_MASSERASE_BANK2)&& \
|
||||
(pFlash.ProcedureOnGoing != FLASH_PROC_PROGRAM_BANK2))
|
||||
{
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check FLASH Bank2 End of Operation flag */
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_SR_EOP) != RESET)
|
||||
{
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK2)
|
||||
{
|
||||
/*Nb of sector to erased can be decreased*/
|
||||
pFlash.NbSectorsToErase--;
|
||||
|
||||
/* Check if there are still sectors to erase*/
|
||||
if(pFlash.NbSectorsToErase != 0)
|
||||
{
|
||||
temp = pFlash.Sector;
|
||||
/*Indicate user which sector has been erased*/
|
||||
HAL_FLASH_EndOfOperationCallback(temp);
|
||||
|
||||
/* Clear pending flags (if any) */
|
||||
/* Clear bank 2 pending flags (if any) */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_ALL_ERRORS_BANK2);
|
||||
|
||||
/*Increment sector number*/
|
||||
temp = ++pFlash.Sector;
|
||||
FLASH_Erase_Sector(temp, FLASH_BANK_2 /*pFlash.Bank*/, pFlash.VoltageForErase);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*No more sectors to Erase, user callback can be called.*/
|
||||
/*Reset Sector and stop Erase sectors procedure*/
|
||||
pFlash.Sector = temp = 0xFFFFFFFF;
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(temp);
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK2) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
|
||||
{
|
||||
/*MassErase ended. Return the selected bank*/
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(FLASH_BANK_2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*Program ended. Return the selected address*/
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||
}
|
||||
|
||||
if((pFlash.ProcedureOnGoing != FLASH_PROC_SECTERASE_BANK1) && \
|
||||
(pFlash.ProcedureOnGoing != FLASH_PROC_MASSERASE_BANK1)&& \
|
||||
(pFlash.ProcedureOnGoing != FLASH_PROC_PROGRAM_BANK1))
|
||||
{
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check FLASH Bank1 operation error flags */
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1((FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_WRPERR_BANK1 | FLASH_FLAG_PGSERR_BANK1 | \
|
||||
FLASH_FLAG_STRBER_BANK1R | FLASH_FLAG_INCERR_BANK1 | FLASH_FLAG_OPERR_BANK1)) != RESET)
|
||||
{
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK1)
|
||||
{
|
||||
/*return the faulty sector*/
|
||||
temp = pFlash.Sector;
|
||||
pFlash.Sector = 0xFFFFFFFF;
|
||||
}
|
||||
else if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK1) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
|
||||
{
|
||||
/*return the faulty bank*/
|
||||
temp = FLASH_BANK_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*return the faulty address*/
|
||||
temp = pFlash.Address;
|
||||
}
|
||||
|
||||
/*Save the Error code*/
|
||||
FLASH_SetErrorCode(FLASH_BANK_1);
|
||||
|
||||
/* FLASH error interrupt user callback */
|
||||
HAL_FLASH_OperationErrorCallback(temp);
|
||||
/* Clear FLASH error pending bits */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK1((FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_WRPERR_BANK1 | FLASH_FLAG_PGSERR_BANK1 | \
|
||||
FLASH_FLAG_STRBER_BANK1R | FLASH_FLAG_INCERR_BANK1 | FLASH_FLAG_OPERR_BANK1));
|
||||
|
||||
/*Stop the procedure ongoing*/
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||
}
|
||||
|
||||
/* Check FLASH Bank2 operation error flags */
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2((FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGSERR_BANK2 | \
|
||||
FLASH_FLAG_STRBER_BANK2R | FLASH_FLAG_INCERR_BANK2 | FLASH_FLAG_OPERR_BANK2)) != RESET)
|
||||
|
||||
{
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK2)
|
||||
{
|
||||
/*return the faulty sector*/
|
||||
temp = pFlash.Sector;
|
||||
pFlash.Sector = 0xFFFFFFFF;
|
||||
}
|
||||
else if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK2) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
|
||||
{
|
||||
/*return the faulty bank*/
|
||||
temp = FLASH_BANK_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*return the faulty address*/
|
||||
temp = pFlash.Address;
|
||||
}
|
||||
|
||||
/*Save the Error code*/
|
||||
FLASH_SetErrorCode(FLASH_BANK_2);
|
||||
|
||||
/* FLASH error interrupt user callback */
|
||||
HAL_FLASH_OperationErrorCallback(temp);
|
||||
/* Clear FLASH error pending bits */
|
||||
__HAL_FLASH_CLEAR_FLAG_BANK2((FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGSERR_BANK2 | \
|
||||
FLASH_FLAG_STRBER_BANK2R | FLASH_FLAG_INCERR_BANK2 | FLASH_FLAG_OPERR_BANK2));
|
||||
|
||||
/*Stop the procedure ongoing*/
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||
}
|
||||
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
|
||||
{
|
||||
/* Disable Bank1 Operation and Error source interrupt */
|
||||
__HAL_FLASH_DISABLE_IT_BANK1(FLASH_IT_EOP_BANK1 | FLASH_IT_WRPERR_BANK1 | FLASH_IT_PGSERR_BANK1 | \
|
||||
FLASH_IT_STRBERR_BANK1 | FLASH_IT_INCERR_BANK1 | FLASH_IT_OPERR_BANK1);
|
||||
|
||||
/* Disable Bank2 Operation and Error source interrupt */
|
||||
__HAL_FLASH_DISABLE_IT_BANK2(FLASH_IT_EOP_BANK2 | FLASH_IT_WRPERR_BANK2 | FLASH_IT_PGSERR_BANK2 | \
|
||||
FLASH_IT_STRBERR_BANK2 | FLASH_IT_INCERR_BANK2 | FLASH_IT_OPERR_BANK2);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FLASH end of operation interrupt callback
|
||||
* @param ReturnValue The value saved in this parameter depends on the ongoing procedure
|
||||
* Mass Erase Bank number which has been requested to erase
|
||||
* Sectors Erase: Sector which has been erased
|
||||
* (if 0xFFFFFFFF, it means that all the selected sectors have been erased)
|
||||
* Program Address which was selected for data program
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FLASH operation error interrupt callback
|
||||
* @param ReturnValue The value saved in this parameter depends on the ongoing procedure
|
||||
* Mass Erase: Bank number which has been requested to erase
|
||||
* Sectors Erase: Sector number which returned an error
|
||||
* Program: Address which was selected for data program
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
|
||||
{
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_FLASH_OperationErrorCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH_Group2 Peripheral Control functions
|
||||
* @brief management functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the FLASH
|
||||
memory operations.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Unlock the FLASH control registers access
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
|
||||
{
|
||||
if((READ_BIT(FLASH->CR1, FLASH_CR_LOCK) != RESET) && (READ_BIT(FLASH->CR2, FLASH_CR_LOCK) != RESET))
|
||||
{
|
||||
/* Authorize the FLASH A Registers access */
|
||||
WRITE_REG(FLASH->KEYR1, FLASH_KEY1);
|
||||
WRITE_REG(FLASH->KEYR1, FLASH_KEY2);
|
||||
|
||||
/* Authorize the FLASH B Registers access */
|
||||
WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
|
||||
WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Locks the FLASH control registers access
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Lock(void)
|
||||
{
|
||||
/* Set the LOCK Bit to lock the FLASH A Registers access */
|
||||
SET_BIT(FLASH->CR1, FLASH_CR_LOCK);
|
||||
|
||||
/* Set the LOCK Bit to lock the FLASH B Registers access */
|
||||
SET_BIT(FLASH->CR2, FLASH_CR_LOCK);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlock the FLASH Option Control Registers access.
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
|
||||
{
|
||||
if(READ_BIT(FLASH->OPTCR, FLASH_OPTCR_OPTLOCK) != RESET)
|
||||
{
|
||||
/* Authorizes the Option Byte register programming */
|
||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPT_KEY1);
|
||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPT_KEY2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock the FLASH Option Control Registers access.
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
|
||||
{
|
||||
/* Set the OPTLOCK Bit to lock the FLASH A and B Option Byte Registers access */
|
||||
SET_BIT(FLASH->OPTCR, FLASH_OPTCR_OPTLOCK);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Launch the option byte loading.
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
|
||||
/* Set OPTSTRT Bit */
|
||||
SET_BIT(FLASH->OPTCR, FLASH_OPTCR_OPTSTART);
|
||||
|
||||
/* Wait for OB change operation to be completed */
|
||||
status = FLASH_OB_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup FLASH_Group3 Peripheral State and Errors functions
|
||||
* @brief Peripheral Errors functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Errors functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection permits to get in run-time Errors of the FLASH peripheral.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the specific FLASH error flag.
|
||||
* @retval HAL_FLASH_ERRORCode The returned value can be:
|
||||
* @arg HAL_FLASH_ERROR_NONE: No error set
|
||||
*
|
||||
* @arg HAL_FLASH_ERROR_WRP_BANK1: Write Protection Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_PGS_BANK1 : Program Sequence Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_STRB_BANK1 : Strobe Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_INC_BANK1 : Inconsistency Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_OPE_BANK1 : Operation Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_RDP_BANK1 : Read Protection Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_RDS_BANK1 : Read Secured Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_SNECC_BANK1: SNECC Error on Bank 1
|
||||
* @arg HAL_FLASH_ERROR_DBECC_BANK1: Double Detection ECC on Bank 1
|
||||
*
|
||||
* @arg HAL_FLASH_ERROR_WRP_BANK2 : Write Protection Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_PGS_BANK2 : Program Sequence Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_STRB_BANK2 : Strobe Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_INC_BANK2 : Inconsistency Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_OPE_BANK2 : Operation Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_RDP_BANK2 : Read Protection Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_RDS_BANK2 : Read Secured Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_SNECC_BANK2: SNECC Error on Bank 2
|
||||
* @arg HAL_FLASH_ERROR_DBECC_BANK2: Double Detection ECC on Bank 2
|
||||
*/
|
||||
|
||||
uint32_t HAL_FLASH_GetError(void)
|
||||
{
|
||||
return pFlash.ErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Wait for a FLASH operation to complete.
|
||||
* @param Timeout maximum flash operation timeout
|
||||
* @param Bank flash FLASH_BANK_1 or FLASH_BANK_2
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout, uint32_t Bank)
|
||||
{
|
||||
/* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
|
||||
Even if the FLASH operation fails, the BUSY flag will be reset and an error
|
||||
flag will be set */
|
||||
|
||||
uint32_t bsyflag, errorflag = 0;
|
||||
uint32_t timeout = HAL_GetTick() + Timeout;
|
||||
|
||||
assert_param(IS_FLASH_BANK_EXCLUSIVE(Bank));
|
||||
|
||||
if(Bank == FLASH_BANK_1)
|
||||
{
|
||||
bsyflag = FLASH_FLAG_BSY_BANK1 | FLASH_FLAG_QW_BANK1;
|
||||
|
||||
if((FLASH->OPTCR & FLASH_OPTCR_SWAP_BANK) == 0)
|
||||
{
|
||||
bsyflag |= FLASH_FLAG_WBNE_BANK1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bsyflag |= FLASH_FLAG_WBNE_BANK2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bsyflag = FLASH_FLAG_BSY_BANK2 | FLASH_FLAG_QW_BANK2;
|
||||
|
||||
if((FLASH->OPTCR & FLASH_OPTCR_SWAP_BANK) == 0)
|
||||
{
|
||||
bsyflag |= FLASH_FLAG_WBNE_BANK2;
|
||||
}
|
||||
else
|
||||
{
|
||||
bsyflag |= FLASH_FLAG_WBNE_BANK1;
|
||||
}
|
||||
}
|
||||
|
||||
while(__HAL_FLASH_GET_FLAG(bsyflag))
|
||||
{
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if(HAL_GetTick() >= timeout)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((Bank == FLASH_BANK_1) && ((FLASH->SR1 & FLASH_FLAG_ALL_ERRORS_BANK1) != RESET))
|
||||
{
|
||||
errorflag = FLASH_FLAG_ALL_ERRORS_BANK1;
|
||||
}
|
||||
else if((Bank == FLASH_BANK_2) && ((FLASH->SR2 & FLASH_FLAG_ALL_ERRORS_BANK2 & 0x7FFFFFFF) != RESET))
|
||||
{
|
||||
errorflag = FLASH_FLAG_ALL_ERRORS_BANK2;
|
||||
}
|
||||
|
||||
if(errorflag != 0)
|
||||
{
|
||||
/*Save the error code*/
|
||||
FLASH_SetErrorCode(Bank);
|
||||
|
||||
/* Clear error programming flags */
|
||||
__HAL_FLASH_CLEAR_FLAG(errorflag);
|
||||
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* If there is an error flag set */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait for a FLASH Option Bytes change operation to complete.
|
||||
* @param Timeout maximum flash operation timeout
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef FLASH_OB_WaitForLastOperation(uint32_t Timeout)
|
||||
{
|
||||
uint32_t timeout = HAL_GetTick() + Timeout;
|
||||
|
||||
/* Wait for the FLASH Option Bytes change operation to complete by polling on OPT_BUSY flag to be reset.*/
|
||||
while(FLASH->OPTSR_CUR & FLASH_OPTSR_OPT_BUSY)
|
||||
{
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if(HAL_GetTick() >= timeout)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(FLASH->OPTSR_CUR & FLASH_OPTSR_OPTCHANGEERR)
|
||||
{
|
||||
/*Save the error code*/
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_OB_CHANGE;
|
||||
|
||||
/*Clear the OB error flag*/
|
||||
FLASH->OPTCCR |= FLASH_OPTCCR_CLR_OPTCHANGEERR;
|
||||
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* If there is an error flag set */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the specific FLASH error flag.
|
||||
* @retval None
|
||||
*/
|
||||
static void FLASH_SetErrorCode(uint32_t Bank)
|
||||
{
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
if(Bank == FLASH_BANK_1)
|
||||
{
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_WRPERR_BANK1))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_PGSERR_BANK1))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_PGS_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_STRBER_BANK1R))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_STRB_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_INCERR_BANK1))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_INC_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_OPERR_BANK1))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_OPE_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_RDPERR_BANK1))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_RDP_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_RDSERR_BANK1))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_RDS_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_SNECCE_BANK1RR))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_SNECC_BANK1;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_DBECCE_BANK1RR))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_DBECC_BANK1;
|
||||
}
|
||||
}
|
||||
else if(Bank == FLASH_BANK_2)
|
||||
{
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_WRPERR_BANK2))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_PGSERR_BANK2))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_PGS_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_STRBER_BANK2R))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_STRB_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_INCERR_BANK2))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_INC_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_OPERR_BANK2))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_OPE_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_RDPERR_BANK2))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_RDP_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_RDSERR_BANK2))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_RDS_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_SNECCE_BANK2RR))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_SNECC_BANK2;
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_DBECCE_BANK2RR))
|
||||
{
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_DBECC_BANK2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1374
File diff suppressed because it is too large
Load Diff
+551
@@ -0,0 +1,551 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_gpio.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @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
|
||||
*
|
||||
@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
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_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 ANALOG_MODE ((uint32_t)0x00000008)
|
||||
#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 = 0x00;
|
||||
uint32_t ioposition = 0x00;
|
||||
uint32_t iocurrent = 0x00;
|
||||
uint32_t temp = 0x00;
|
||||
EXTI_Core_TypeDef * EXTI_Ptr = EXTI_D1;
|
||||
|
||||
|
||||
/* 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_OSPEEDER_OSPEEDR0 << (position * 2));
|
||||
temp |= (GPIO_Init->Speed << (position * 2));
|
||||
GPIOx->OSPEEDR = temp;
|
||||
|
||||
/* Configure the IO Output Type */
|
||||
temp = GPIOx->OTYPER;
|
||||
temp &= ~(GPIO_OTYPER_OT_0 << 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)
|
||||
{
|
||||
/* Enable SYSCFG Clock */
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
temp = SYSCFG->EXTICR[position >> 2];
|
||||
temp &= ~(((uint32_t)0x0F) << (4 * (position & 0x03)));
|
||||
temp |= ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (4 * (position & 0x03)));
|
||||
SYSCFG->EXTICR[position >> 2] = temp;
|
||||
|
||||
/* Clear EXTI line configuration */
|
||||
temp = EXTI_Ptr->IMR1;
|
||||
temp &= ~((uint32_t)iocurrent);
|
||||
if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI_Ptr->IMR1 = temp;
|
||||
|
||||
temp = EXTI_Ptr->EMR1;
|
||||
temp &= ~((uint32_t)iocurrent);
|
||||
if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI_Ptr->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..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).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
||||
{
|
||||
uint32_t position;
|
||||
uint32_t ioposition = 0x00;
|
||||
uint32_t iocurrent = 0x00;
|
||||
uint32_t tmp = 0x00;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/*------------------------- 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_OSPEEDER_OSPEEDR0 << (position * 2));
|
||||
|
||||
/* Configure the default value IO Output Type */
|
||||
GPIOx->OTYPER &= ~(GPIO_OTYPER_OT_0 << position) ;
|
||||
|
||||
/* Deactivate the Pull-up and Pull-down resistor for the current IO */
|
||||
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
|
||||
|
||||
/*------------------------- EXTI Mode Configuration --------------------*/
|
||||
tmp = SYSCFG->EXTICR[position >> 2];
|
||||
tmp &= (((uint32_t)0x0F) << (4 * (position & 0x03)));
|
||||
if(tmp == ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (4 * (position & 0x03))))
|
||||
{
|
||||
/* Configure the External Interrupt or event for the current IO */
|
||||
tmp = ((uint32_t)0x0F) << (4 * (position & 0x03));
|
||||
SYSCFG->EXTICR[position >> 2] &= ~tmp;
|
||||
|
||||
/* Clear EXTI line configuration */
|
||||
EXTI_D1->IMR1 &= ~((uint32_t)iocurrent);
|
||||
EXTI_D1->EMR1 &= ~((uint32_t)iocurrent);
|
||||
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
EXTI->RTSR1 &= ~((uint32_t)iocurrent);
|
||||
EXTI->FTSR1 &= ~((uint32_t)iocurrent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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->BSRRL = GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BSRRH = GPIO_Pin ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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));
|
||||
|
||||
GPIOx->ODR ^= 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 for STM32H7 family
|
||||
* @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 bit*/
|
||||
tmp = GPIOx->LCKR;
|
||||
|
||||
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_IT(GPIO_Pin) != RESET)
|
||||
{
|
||||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_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_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_Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+2663
File diff suppressed because it is too large
Load Diff
+932
@@ -0,0 +1,932 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_hash_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief Extended HASH HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the HASH peripheral for SHA-224 and SHA-256
|
||||
* alogrithms:
|
||||
* + HASH or HMAC processing in polling mode
|
||||
* + HASH or HMAC processing in interrupt mode
|
||||
* + HASH or HMAC processing in DMA mode
|
||||
* Additionally, this file provides functions to manage HMAC
|
||||
* multi-buffer DMA-based processing for MD-5, SHA-1, SHA-224
|
||||
* and SHA-256.
|
||||
*
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### HASH peripheral extended features #####
|
||||
===============================================================================
|
||||
[..]
|
||||
The SHA-224 and SHA-256 HASH and HMAC processing can be carried out exactly
|
||||
the same way as for SHA-1 or MD-5 algorithms.
|
||||
(#) Three modes are available.
|
||||
(##) Polling mode: processing APIs are blocking functions
|
||||
i.e. they process the data and wait till the digest computation is finished,
|
||||
e.g. HAL_HASHEx_xxx_Start()
|
||||
(##) Interrupt mode: processing APIs are not blocking functions
|
||||
i.e. they process the data under interrupt,
|
||||
e.g. HAL_HASHEx_xxx_Start_IT()
|
||||
(##) DMA mode: processing APIs are not blocking functions and the CPU is
|
||||
not used for data transfer i.e. the data transfer is ensured by DMA,
|
||||
e.g. HAL_HASHEx_xxx_Start_DMA(). Note that in DMA mode, a call to
|
||||
HAL_HASHEx_xxx_Finish() is then required to retrieve the digest.
|
||||
|
||||
(#)Multi-buffer processing is possible in polling and DMA mode.
|
||||
(##) In polling mode, only multi-buffer HASH processing is possible.
|
||||
API HAL_HASHEx_xxx_Accumulate() must be called for each input buffer, except for the last one.
|
||||
User must resort to HAL_HASHEx_xxx_Start() to enter the last one and retrieve as
|
||||
well the computed digest.
|
||||
|
||||
(##) In DMA mode, multi-buffer HASH and HMAC processing are possible.
|
||||
|
||||
(+++) HASH processing: once initialization is done, MDMAT bit must be set thru __HAL_HASH_SET_MDMAT() macro.
|
||||
From that point, each buffer can be fed to the IP thru HAL_HASHEx_xxx_Start_DMA() API.
|
||||
Before entering the last buffer, reset the MDMAT bit with __HAL_HASH_RESET_MDMAT()
|
||||
macro then wrap-up the HASH processing in feeding the last input buffer thru the
|
||||
same API HAL_HASHEx_xxx_Start_DMA(). The digest can then be retrieved with a call to
|
||||
API HAL_HASHEx_xxx_Finish().
|
||||
|
||||
(+++) HMAC processing (MD-5, SHA-1, SHA-224 and SHA-256 must all resort to
|
||||
extended functions): after initialization, the key and the first input buffer are entered
|
||||
in the IP with the API HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and
|
||||
starts step 2.
|
||||
The following buffers are next entered with the API HAL_HMACEx_xxx_Step2_DMA(). At this
|
||||
point, the HMAC processing is still carrying out step 2.
|
||||
Then, step 2 for the last input buffer and step 3 are carried out by a single call
|
||||
to HAL_HMACEx_xxx_Step2_3_DMA().
|
||||
|
||||
The digest can finally be retrieved with a call to API HAL_HASH_xxx_Finish() for
|
||||
MD-5 and SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 and SHA-256.
|
||||
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
|
||||
#if defined (HASH)
|
||||
|
||||
/** @defgroup HASHEx HASHEx
|
||||
* @brief HASH HAL extended module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions HASH Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group1 HASH extended processing functions in polling mode
|
||||
* @brief HASH extended processing functions using polling mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Polling mode HASH extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in polling mode
|
||||
the hash value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HASHEx_SHA224_Start()
|
||||
(++) HAL_HASHEx_SHA224_Accumulate()
|
||||
(+) SHA256
|
||||
(++) HAL_HASHEx_SHA256_Start()
|
||||
(++) HAL_HASHEx_SHA256_Accumulate()
|
||||
|
||||
[..] For a single buffer to be hashed, user can resort to HAL_HASH_xxx_Start().
|
||||
|
||||
[..] In case of multi-buffer HASH processing (a single digest is computed while
|
||||
several buffers are fed to the IP), the user can resort to successive calls
|
||||
to HAL_HASHEx_xxx_Accumulate() and wrap-up the digest computation by a call
|
||||
to HAL_HASHEx_xxx_Start().
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @param Timeout: Timeout value
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief If not already done, initialize the HASH peripheral in SHA224 mode then
|
||||
* processes pInBuffer.
|
||||
* @note Consecutive calls to HAL_HASHEx_SHA224_Accumulate() can be used to feed
|
||||
* several input buffers back-to-back to the IP that will yield a single
|
||||
* HASH signature once all buffers have been entered. Wrap-up of input
|
||||
* buffers feeding and retrieval of digest is done by a call to
|
||||
* HAL_HASHEx_SHA224_Start().
|
||||
* @note Field hhash->Phase of HASH handle is tested to check whether or not
|
||||
* the IP has already been initialized.
|
||||
* @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA224_Start()
|
||||
* to read it, feeding at the same time the last input buffer to the IP.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Start() is able
|
||||
* to manage the ending buffer with a length in bytes not a multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes, must be a multiple of 4.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Accumulate(hhash, pInBuffer, Size,HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @param Timeout: Timeout value
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief If not already done, initialize the HASH peripheral in SHA256 mode then
|
||||
* processes pInBuffer.
|
||||
* @note Consecutive calls to HAL_HASHEx_SHA256_Accumulate() can be used to feed
|
||||
* several input buffers back-to-back to the IP that will yield a single
|
||||
* HASH signature once all buffers have been entered. Wrap-up of input
|
||||
* buffers feeding and retrieval of digest is done by a call to
|
||||
* HAL_HASHEx_SHA256_Start().
|
||||
* @note Field hhash->Phase of HASH handle is tested to check whether or not
|
||||
* the IP has already been initialized.
|
||||
* @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA256_Start()
|
||||
* to read it, feeding at the same time the last input buffer to the IP.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Start() is able
|
||||
* to manage the ending buffer with a length in bytes not a multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes, must be a multiple of 4.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Accumulate(hhash, pInBuffer, Size,HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group2 HASH extended processing functions in interrupt mode
|
||||
* @brief HASH extended processing functions using interrupt mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Interruption mode HASH extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in interrupt mode
|
||||
the hash value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HASHEx_SHA224_Start_IT()
|
||||
(+) SHA256
|
||||
(++) HAL_HASHEx_SHA256_Start_IT()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest in interruption mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer,HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest in interruption mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer,HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group3 HASH extended processing functions in DMA mode
|
||||
* @brief HASH extended processing functions using DMA mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### DMA mode HASH extended processing functionss #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in DMA mode
|
||||
the hash value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HASHEx_SHA224_Start_DMA()
|
||||
(++) HAL_HASHEx_SHA224_Finish()
|
||||
(+) SHA256
|
||||
(++) HAL_HASHEx_SHA256_Start_DMA()
|
||||
(++) HAL_HASHEx_SHA256_Finish()
|
||||
|
||||
[..] When resorting to DMA mode to enter the data in the IP, user must resort
|
||||
to HAL_HASHEx_xxx_Start_DMA() then read the resulting digest with
|
||||
HAL_HASHEx_xxx_Finish().
|
||||
|
||||
[..] In case of multi-buffer HASH processing, MDMAT bit must first be set before
|
||||
the successive calls to HAL_HASHEx_xxx_Start_DMA(). Then, MDMAT bit needs to be
|
||||
reset before the last call to HAL_HASHEx_xxx_Start_DMA(). Digest is finally
|
||||
retrieved thanks to HAL_HASHEx_xxx_Finish().
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA224 mode then initiate a DMA transfer
|
||||
* to feed the input buffer to the IP.
|
||||
* @note Once the DMA transfer is finished, HAL_HASHEx_SHA224_Finish() API must
|
||||
* be called to retrieve the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the computed digest in SHA224 mode.
|
||||
* @note The API waits for DCIS to be set then reads the computed digest.
|
||||
* @note HAL_HASHEx_SHA224_Finish() can be used as well to retrieve the digest in
|
||||
* HMAC SHA224 mode.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Finish(hhash, pOutBuffer, Timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA256 mode then initiate a DMA transfer
|
||||
* to feed the input buffer to the IP.
|
||||
* @note Once the DMA transfer is finished, HAL_HASHEx_SHA256_Finish() API must
|
||||
* be called to retrieve the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the computed digest in SHA256 mode.
|
||||
* @note The API waits for DCIS to be set then reads the computed digest.
|
||||
* @note HAL_HASHEx_SHA256_Finish() can be used as well to retrieve the digest in
|
||||
* HMAC SHA256 mode.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Finish(hhash, pOutBuffer, Timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group4 HMAC extended processing functions in polling mode
|
||||
* @brief HMAC extended processing functions using polling mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Polling mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in polling mode
|
||||
the HMAC value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HMACEx_SHA224_Start()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Start()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group5 HMAC extended processing functions in interrupt mode
|
||||
* @brief HMAC extended processing functions using interruption mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Interrupt mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in interrupt mode
|
||||
the HMAC value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HMACEx_SHA224_Start_IT()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Start_IT()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest in interrupt mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest in interrupt mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group6 HMAC extended processing functions in DMA mode
|
||||
* @brief HMAC extended processing functions using DMA mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### DMA mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in DMA mode
|
||||
the HMAC value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HMACEx_SHA224_Start_DMA()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Start_DMA()
|
||||
|
||||
[..] When resorting to DMA mode to enter the data in the IP for HMAC processing,
|
||||
user must resort to HAL_HMACEx_xxx_Start_DMA() then read the resulting digest
|
||||
with HAL_HASHEx_xxx_Finish().
|
||||
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
|
||||
* DMA transfers to feed the key and the input buffer to the IP.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA224_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note If MDMAT bit is set before calling this function (multi-buffer
|
||||
* HASH processing case), the input buffer size (in bytes) must be
|
||||
* a multiple of 4 otherwise, the HASH digest computation is corrupted.
|
||||
* For the processing of the last buffer of the thread, MDMAT bit must
|
||||
* be reset and the buffer length (in bytes) doesn't have to be a
|
||||
* multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
|
||||
* DMA transfers to feed the key and the input buffer to the IP.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note If MDMAT bit is set before calling this function (multi-buffer
|
||||
* HASH processing case), the input buffer size (in bytes) must be
|
||||
* a multiple of 4 otherwise, the HASH digest computation is corrupted.
|
||||
* For the processing of the last buffer of the thread, MDMAT bit must
|
||||
* be reset and the buffer length (in bytes) doesn't have to be a
|
||||
* multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group7 Multi-buffer HMAC extended processing functions in DMA mode
|
||||
* @brief HMAC extended processing functions in multi-buffer DMA mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Multi-buffer DMA mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions to manage HMAC multi-buffer
|
||||
DMA-based processing for MD5, SHA1, SHA224 and SHA256 algorithms.
|
||||
(+) MD5
|
||||
(++) HAL_HMACEx_MD5_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_MD5_Step2_DMA()
|
||||
(++) HAL_HMACEx_MD5_Step2_3_DMA()
|
||||
(+) SHA1
|
||||
(++) HAL_HMACEx_SHA1_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_SHA1_Step2_DMA()
|
||||
(++) HAL_HMACEx_SHA1_Step2_3_DMA()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA224_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_SHA224_Step2_DMA()
|
||||
(++) HAL_HMACEx_SHA224_Step2_3_DMA()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_SHA256_Step2_DMA()
|
||||
(++) HAL_HMACEx_SHA256_Step2_3_DMA()
|
||||
|
||||
[..] User must first start-up the multi-buffer DMA-based HMAC computation in
|
||||
calling HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and
|
||||
intiates step 2 with the first input buffer.
|
||||
|
||||
[..] The following buffers are next fed to the IP with a call to the API
|
||||
HAL_HMACEx_xxx_Step2_DMA(). There may be several consecutive calls
|
||||
to this API.
|
||||
|
||||
[..] Multi-buffer DMA-based HMAC computation is wrapped up by a call to
|
||||
HAL_HMACEx_xxx_Step2_3_DMA(). This finishes step 2 in feeding the last input
|
||||
buffer to the IP then carries out step 3.
|
||||
|
||||
[..] Digest is retrieved by a call to HAL_HASH_xxx_Finish() for MD-5 or
|
||||
SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 or SHA-256.
|
||||
|
||||
[..] If only two buffers need to be consecutively processed, a call to
|
||||
HAL_HMACEx_xxx_Step1_2_DMA() followed by a call to HAL_HMACEx_xxx_Step2_3_DMA()
|
||||
is sufficient.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief MD5 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MD5 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MD5 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief SHA1 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA1 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA1 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA224 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA224 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA224 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA256 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA256 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA256 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HASH */
|
||||
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1234
File diff suppressed because it is too large
Load Diff
+7838
File diff suppressed because it is too large
Load Diff
+374
@@ -0,0 +1,374 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_hsem.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @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
|
||||
*
|
||||
*
|
||||
@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
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM HSEM
|
||||
* @brief HSEM HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_HSEM_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* 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));
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* 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));
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release All semaphore used by a given Master .
|
||||
* @param Key: Semaphore Key , value from 0 to 0xFFFF
|
||||
* @param MasterID: MasterID of the CPU that is using semaphores to be Released
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t MasterID)
|
||||
{
|
||||
assert_param(IS_HSEM_KEY(Key));
|
||||
assert_param(IS_HSEM_MASTERID(MasterID));
|
||||
|
||||
HSEM->CR = (((Key << POSITION_VAL(HSEM_KEYR_KEY)) & HSEM_CR_KEY ) | ((MasterID << POSITION_VAL(HSEM_CR_MASTERID)) & HSEM_CR_MASTERID));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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 << POSITION_VAL(HSEM_KEYR_KEY)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get semaphore Key .
|
||||
* @retval Semaphore Key , value from 0 to 0xFFFF
|
||||
*/
|
||||
uint32_t HAL_HSEM_GetClearKey(void)
|
||||
{
|
||||
return (HSEM->KEYR >> POSITION_VAL(HSEM_KEYR_KEY));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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)
|
||||
{
|
||||
/*Activate interrupt for CM7 Master */
|
||||
HSEM->IER |= SemMask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
|
||||
/*Deactivate interrupt for CM7 Master */
|
||||
HSEM->IER &= ~SemMask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles HSEM interrupt request.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_IRQHandler(void)
|
||||
{
|
||||
uint32_t statusreg = 0U;
|
||||
|
||||
/* Get the list of masked freed semaphores*/
|
||||
statusreg = HSEM->MISR;
|
||||
|
||||
/*Disable Interrupts*/
|
||||
HSEM->IER &= ~((uint32_t)statusreg);
|
||||
|
||||
/*Clear Flags*/
|
||||
HSEM->ICR |= ((uint32_t)statusreg);
|
||||
|
||||
|
||||
/* 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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+4839
File diff suppressed because it is too large
Load Diff
+335
@@ -0,0 +1,335 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_i2c_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief I2C Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of I2C Extended peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### I2C peripheral Extended features #####
|
||||
==============================================================================
|
||||
|
||||
[..] Comparing to other previous devices, the I2C interface for STM32H7XX
|
||||
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 modes
|
||||
(+) 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
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_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 Extended features functions
|
||||
* @brief Extended features functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended features functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Noise Filters
|
||||
(+) Configure Wake Up Feature
|
||||
(+) Configure Fast Mode Plus
|
||||
|
||||
@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 0x00 and 0x0F.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
|
||||
{
|
||||
uint32_t tmpreg = 0U;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable I2C wakeup from stop mode.
|
||||
* @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.
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @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->PMCR, (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
|
||||
* @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 */
|
||||
CLEAR_BIT(SYSCFG->PMCR, (uint32_t)ConfigFastModePlus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1843
File diff suppressed because it is too large
Load Diff
+929
@@ -0,0 +1,929 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_i2s_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief I2S HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of I2S extension peripheral:
|
||||
* + IO operation functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### I2S Extension features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) In I2S full duplex mode, SPI2S peripheral is able to manage sending and receiving
|
||||
data simultaneously using two data lines.
|
||||
@endverbatim
|
||||
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
Three operation modes are available within this driver :
|
||||
|
||||
*** Polling mode IO operation ***
|
||||
=================================
|
||||
[..]
|
||||
(+) Send and receive in the same time an amount of data in blocking mode using HAL_I2SEx_TransmitReceive()
|
||||
|
||||
*** Interrupt mode IO operation ***
|
||||
===================================
|
||||
[..]
|
||||
(+) Send and receive in the same time an amount of data in non blocking mode using HAL_I2SEx_TransmitReceive_IT()
|
||||
(+) At full duplex transfer end of half transfer HAL_I2SEx_TxRxHalfCpltCallback is executed and user can
|
||||
add his own code by customization of function pointer HAL_I2SEx_TxRxHalfCpltCallback
|
||||
(+) At full duplex transfer end of transfer HAL_I2SEx_TxRxCpltCallback is executed and user can
|
||||
add his own code by customization of function pointer HAL_I2SEx_TxRxCpltCallback
|
||||
(+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
|
||||
add his own code by customization of function pointer HAL_I2S_ErrorCallback
|
||||
|
||||
*** DMA mode IO operation ***
|
||||
==============================
|
||||
[..]
|
||||
(+) Send and receive an amount of data in non blocking mode (DMA) using HAL_I2SEx_TransmitReceive_DMA()
|
||||
(+) At the end of half transfer HAL_I2SEx_TxRxHalfCpltCallback is executed and user can
|
||||
add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback
|
||||
(+) At the end of transfer HAL_I2S_TxRxCpltCallback is executed and user can
|
||||
add his own code by customization of function pointer HAL_I2S_TxCpltCallback
|
||||
(+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
|
||||
add his own code by customization of function pointer HAL_I2S_ErrorCallback
|
||||
(+) Pause the DMA Transfer using HAL_I2S_DMAPause()
|
||||
(+) Resume the DMA Transfer using HAL_I2S_DMAResume()
|
||||
(+) Stop the DMA Transfer using HAL_I2S_DMAStop()
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
/** @defgroup I2SEx I2SEx
|
||||
* @brief I2S Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/** @defgroup I2SEx_Private_Typedef I2S Extended Private Typedef
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
I2S_USE_I2S = 0x00U, /*!< I2Sx should be used */
|
||||
I2S_USE_I2SEXT = 0x01U, /*!< I2Sx_ext should be used */
|
||||
}I2S_UseTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup I2SEx_Private_Functions I2S Extended Private Functions
|
||||
* @{
|
||||
*/
|
||||
static void I2SEx_DMATxRxCplt(DMA_HandleTypeDef *hdma);
|
||||
static void I2SEx_DMATxRxHalfCplt(DMA_HandleTypeDef *hdma);
|
||||
static void I2SEx_TxRxDMAError(DMA_HandleTypeDef *hdma);
|
||||
|
||||
static void I2SEx_2linesTxISR_16BIT(struct __I2S_HandleTypeDef *hi2s);
|
||||
static void I2SEx_2linesTxISR_32BIT(struct __I2S_HandleTypeDef *hi2s);
|
||||
static void I2SEx_2linesRxISR_16BIT(struct __I2S_HandleTypeDef *hi2s);
|
||||
static void I2SEx_2linesRxISR_32BIT(struct __I2S_HandleTypeDef *hi2s);
|
||||
static void I2SEx_CloseRxTx_ISR(I2S_HandleTypeDef *hi2s);
|
||||
|
||||
static HAL_StatusTypeDef I2SEx_WaitFlagStateUntilTimeout(I2S_HandleTypeDef *hi2s, uint32_t Flag, uint32_t State, uint32_t Timeout);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup I2SEx_Exported_Functions I2S Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup I2SEx_Exported_Functions_Group1 I2S Extended IO operation functions
|
||||
* @brief I2SEx IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions#####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to manage the I2S data
|
||||
transfers.
|
||||
|
||||
(#) There are two modes of transfer:
|
||||
(++) Blocking mode : The communication is performed in the polling mode.
|
||||
The status of all data processing is returned by the same function
|
||||
after finishing transfer.
|
||||
(++) No-Blocking mode : The communication is performed using Interrupts
|
||||
or DMA. These functions return the status of the transfer startup.
|
||||
The end of the data processing will be indicated through the
|
||||
dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when
|
||||
using DMA mode.
|
||||
|
||||
(#) Blocking mode functions are :
|
||||
(++) HAL_I2SEx_TransmitReceive()
|
||||
|
||||
(#) No-Blocking mode functions with Interrupt are :
|
||||
(++) HAL_I2SEx_TransmitReceive_IT()
|
||||
|
||||
(#) No-Blocking mode functions with DMA are :
|
||||
(++) HAL_I2SEx_TransmitReceive_DMA()
|
||||
|
||||
(#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
|
||||
(++) HAL_I2SEx_TxRxCpltCallback()
|
||||
(++) HAL_I2SEx_TxRxErrorCallback()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Transmit and Receive an amount of data in blocking mode
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module
|
||||
* @param pTxData: a 16-bit pointer to the Transmit data buffer
|
||||
* @param pRxData: a 16-bit pointer to the Receive data buffer
|
||||
* @param Size: number of frames to be sent
|
||||
* @param Timeout: Timeout duration
|
||||
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
|
||||
* between Master and Slave(example: audio streaming).
|
||||
* @note This function can use an Audio Frequency up to 48KHz when I2S Clock Source is 32MHz
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2SEx_TransmitReceive(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size, uint32_t Timeout)
|
||||
{
|
||||
uint32_t tickstart = 0U;
|
||||
uint32_t isDataFormat16B = 2U;
|
||||
|
||||
/* Check Mode parameter */
|
||||
assert_param(IS_I2S_FD_MODE(hi2s->Init.Mode));
|
||||
|
||||
if((pTxData == NULL ) || (Size == 0U))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2s);
|
||||
|
||||
/* Init tickstart for timeout management*/
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
if(hi2s->State == HAL_I2S_STATE_READY)
|
||||
{
|
||||
/* Check the Data Format value */
|
||||
if (((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B) ||
|
||||
((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B))
|
||||
{
|
||||
isDataFormat16B = 0U;
|
||||
}
|
||||
else
|
||||
{
|
||||
isDataFormat16B = 1U;
|
||||
}
|
||||
|
||||
if(!isDataFormat16B)
|
||||
{
|
||||
hi2s->TxXferSize = (Size << 1U);
|
||||
hi2s->TxXferCount = (Size << 1U);
|
||||
|
||||
hi2s->RxXferSize = (Size << 1U);
|
||||
hi2s->RxXferCount = (Size << 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
hi2s->TxXferSize = Size;
|
||||
hi2s->TxXferCount = Size;
|
||||
|
||||
hi2s->RxXferSize = Size;
|
||||
hi2s->RxXferCount = Size;
|
||||
}
|
||||
|
||||
/* Set state and reset error code */
|
||||
hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
|
||||
hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
|
||||
hi2s->pTxBuffPtr = pTxData;
|
||||
hi2s->pRxBuffPtr = pRxData;
|
||||
|
||||
/* Check if the SPI2S is already enabled */
|
||||
if((hi2s->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Enable I2S peripheral */
|
||||
__HAL_I2S_ENABLE(hi2s);
|
||||
}
|
||||
|
||||
if(IS_I2S_MASTER(hi2s->Init.Mode))
|
||||
{
|
||||
hi2s->Instance->CR1 |= SPI_CR1_CSTART;
|
||||
}
|
||||
|
||||
/* Transmit and Receive data in 32 Bit mode */
|
||||
if (!isDataFormat16B)
|
||||
{
|
||||
while ((hi2s->TxXferCount > 0U) || (hi2s->RxXferCount > 0U))
|
||||
{
|
||||
/* Check TXE flag */
|
||||
if ((hi2s->TxXferCount > 0U) && (__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE)))
|
||||
{
|
||||
*((__IO uint32_t *)&hi2s->Instance->TXDR) = *((uint32_t *)hi2s->pTxBuffPtr);
|
||||
hi2s->pTxBuffPtr += sizeof(uint32_t);
|
||||
hi2s->TxXferCount --;
|
||||
}
|
||||
|
||||
/* Check RXNE flag */
|
||||
if ((hi2s->RxXferCount > 0U) && (__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE)))
|
||||
{
|
||||
*((uint32_t *)hi2s->pRxBuffPtr) = *((__IO uint32_t *)&hi2s->Instance->RXDR);
|
||||
hi2s->pRxBuffPtr += sizeof(uint32_t);
|
||||
hi2s->RxXferCount --;
|
||||
}
|
||||
|
||||
/* Timeout Management */
|
||||
if ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick() - tickstart) >= Timeout))
|
||||
{
|
||||
/* Set the error code and execute error callback*/
|
||||
SET_BIT(hi2s->ErrorCode, HAL_I2S_ERROR_TIMEOUT);
|
||||
HAL_I2S_ErrorCallback(hi2s);
|
||||
|
||||
/* Set the I2S State ready */
|
||||
hi2s->State = HAL_I2S_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Transmit and Receive data in 16 Bit mode */
|
||||
else
|
||||
{
|
||||
while ((hi2s->TxXferCount > 0U) || (hi2s->RxXferCount > 0U))
|
||||
{
|
||||
/* Check TXE flag */
|
||||
if ((hi2s->TxXferCount > 0U) && (__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE)))
|
||||
{
|
||||
if ( (hi2s->TxXferCount > 1U) && (hi2s->Init.FifoThreshold > SPI_FIFO_THRESHOLD_01DATA))
|
||||
{
|
||||
*((__IO uint32_t *)&hi2s->Instance->TXDR) = *((uint32_t *)hi2s->pTxBuffPtr);
|
||||
hi2s->pTxBuffPtr += sizeof(uint32_t);
|
||||
hi2s->TxXferCount-=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*((__IO uint16_t *)&hi2s->Instance->TXDR) = *((uint16_t *)hi2s->pTxBuffPtr);
|
||||
hi2s->pTxBuffPtr += sizeof(uint16_t);
|
||||
hi2s->TxXferCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check RXNE flag */
|
||||
if ((hi2s->RxXferCount > 0U) && (__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE)))
|
||||
{
|
||||
if (hi2s->Instance->SR & I2S_FLAG_RXWNE)
|
||||
{
|
||||
*((uint32_t *)hi2s->pRxBuffPtr) = *((__IO uint32_t *)&hi2s->Instance->RXDR);
|
||||
hi2s->pRxBuffPtr += sizeof(uint32_t);
|
||||
hi2s->RxXferCount-=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)hi2s->pRxBuffPtr) = *((__IO uint16_t *)&hi2s->Instance->RXDR);
|
||||
hi2s->pRxBuffPtr += sizeof(uint16_t);
|
||||
hi2s->RxXferCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Timeout Management */
|
||||
if ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick() - tickstart) >= Timeout))
|
||||
{
|
||||
/* Set the error code and execute error callback*/
|
||||
SET_BIT(hi2s->ErrorCode, HAL_I2S_ERROR_TIMEOUT);
|
||||
HAL_I2S_ErrorCallback(hi2s);
|
||||
|
||||
/* Set the I2S State ready */
|
||||
hi2s->State = HAL_I2S_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait until TXE flag is set, to confirm the end of the transaction */
|
||||
if (I2SEx_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_TXE, RESET, Timeout) != HAL_OK)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
|
||||
hi2s->State = HAL_I2S_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transmit and Receive an amount of data in non-blocking mode with Interrupt
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module
|
||||
* @param pTxData: a 16-bit pointer to the Transmit data buffer.
|
||||
* @param pRxData: a 16-bit pointer to the Receive data buffer.
|
||||
* @param Size: number of data sample to be sent:
|
||||
* @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
|
||||
* configuration phase, the Size parameter means the number of 16-bit data length
|
||||
* in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
|
||||
* the Size parameter means the number of 16-bit data length.
|
||||
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
|
||||
* between Master and Slave(example: audio streaming).
|
||||
* @note This function can use an Audio Frequency up to 48KHz when I2S Clock Source is 32MHz
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size)
|
||||
{
|
||||
/* Check Mode parameter */
|
||||
assert_param(IS_I2S_FD_MODE(hi2s->Init.Mode));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2s);
|
||||
|
||||
if((pTxData == NULL) || (pRxData == NULL) || (Size == 0U))
|
||||
{
|
||||
__HAL_UNLOCK(hi2s);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (hi2s->State == HAL_I2S_STATE_READY)
|
||||
{
|
||||
__HAL_UNLOCK(hi2s);
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
/* Set the transaction information */
|
||||
hi2s->State = HAL_I2S_STATE_BUSY_TX;
|
||||
hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
|
||||
hi2s->pTxBuffPtr = pTxData;
|
||||
hi2s->TxXferSize = Size;
|
||||
hi2s->TxXferCount = Size;
|
||||
|
||||
/* Init field not used in handle to zero */
|
||||
hi2s->pRxBuffPtr = pRxData;
|
||||
hi2s->RxXferSize = Size;
|
||||
hi2s->RxXferCount = Size;
|
||||
|
||||
/* Set the function for IT treatment */
|
||||
if (hi2s->Init.DataFormat > I2S_DATAFORMAT_16B)
|
||||
{
|
||||
hi2s->RxISR = I2SEx_2linesRxISR_32BIT;
|
||||
hi2s->TxISR = I2SEx_2linesTxISR_32BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
hi2s->RxISR = I2SEx_2linesRxISR_16BIT;
|
||||
hi2s->TxISR = I2SEx_2linesTxISR_16BIT;
|
||||
}
|
||||
|
||||
/* Check if the I2S is already enabled */
|
||||
if ((hi2s->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_I2S_ENABLE(hi2s);
|
||||
}
|
||||
|
||||
if (IS_I2S_MASTER(hi2s->Init.Mode))
|
||||
{
|
||||
/* Master transfer start */
|
||||
SET_BIT(hi2s->Instance->CR1, SPI_CR1_CSTART);
|
||||
}
|
||||
|
||||
/* Enable TXE and ERR interrupt */
|
||||
__HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_RXNE | I2S_IT_ERR));
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transmit and Receive an amount of data in non-blocking mode with DMA
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module
|
||||
* @param pTxData: a 16-bit pointer to the Transmit data buffer.
|
||||
* @param pRxData: a 16-bit pointer to the Receive data buffer.
|
||||
* @param Size: number of frames to be sent.
|
||||
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
|
||||
* between Master and Slave(example: audio streaming).
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size)
|
||||
{
|
||||
/* Check Mode parameter */
|
||||
assert_param(IS_I2S_FD_MODE(hi2s->Init.Mode));
|
||||
|
||||
if((pTxData == NULL) || (Size == 0U))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2s);
|
||||
|
||||
if(hi2s->State == HAL_I2S_STATE_READY)
|
||||
{
|
||||
hi2s->pTxBuffPtr = pTxData;
|
||||
hi2s->pRxBuffPtr = pRxData;
|
||||
hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
|
||||
hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
|
||||
|
||||
if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\
|
||||
((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B))
|
||||
{
|
||||
hi2s->TxXferSize = (Size << 1U);
|
||||
hi2s->TxXferCount = (Size << 1U);
|
||||
|
||||
hi2s->RxXferSize = (Size << 1U);
|
||||
hi2s->RxXferCount = (Size << 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
hi2s->TxXferSize = Size;
|
||||
hi2s->TxXferCount = Size;
|
||||
|
||||
hi2s->RxXferSize = Size;
|
||||
hi2s->RxXferCount = Size;
|
||||
}
|
||||
|
||||
/* Set the I2S Rx DMA Half transfert complete callback */
|
||||
hi2s->hdmarx->XferHalfCpltCallback = I2SEx_DMATxRxHalfCplt;
|
||||
|
||||
/* Set the I2S Rx DMA transfert complete callback */
|
||||
hi2s->hdmarx->XferCpltCallback = I2SEx_DMATxRxCplt;
|
||||
|
||||
/* Set the DMA error callback */
|
||||
hi2s->hdmarx->XferErrorCallback = I2SEx_TxRxDMAError;
|
||||
|
||||
/* Enable the Rx DMA Channel */
|
||||
HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&hi2s->Instance->RXDR, (uint32_t)hi2s->pRxBuffPtr, hi2s->RxXferSize);
|
||||
|
||||
/* Check if the I2S Rx requests are already enabled */
|
||||
if(HAL_IS_BIT_CLR(hi2s->Instance->CFG1, SPI_CFG1_RXDMAEN))
|
||||
{
|
||||
/* Check if the SPI2S is disabled to edit CFG1 register */
|
||||
if ((hi2s->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Enable Rx DMA Request */
|
||||
SET_BIT(hi2s->Instance->CFG1, SPI_CFG1_RXDMAEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_I2S_DISABLE(hi2s);
|
||||
|
||||
/* Enable Rx DMA Request */
|
||||
SET_BIT(hi2s->Instance->CFG1, SPI_CFG1_RXDMAEN);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_I2S_ENABLE(hi2s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the I2S Tx DMA transfer callbacks as NULL because the communication closing
|
||||
is performed in DMA reception callbacks */
|
||||
hi2s->hdmatx->XferHalfCpltCallback = NULL;
|
||||
hi2s->hdmatx->XferCpltCallback = NULL;
|
||||
hi2s->hdmatx->XferErrorCallback = NULL;
|
||||
|
||||
/* Enable the Tx DMA Channel */
|
||||
HAL_DMA_Start_IT(hi2s->hdmatx, (uint32_t)hi2s->pTxBuffPtr, (uint32_t)&hi2s->Instance->TXDR, hi2s->TxXferSize);
|
||||
|
||||
/* Check if the I2S Tx requests are already enabled */
|
||||
if(HAL_IS_BIT_CLR(hi2s->Instance->CFG1, SPI_CFG1_TXDMAEN))
|
||||
{
|
||||
/* Check if the SPI2S is disabled to edit CFG1 register */
|
||||
if ((hi2s->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Enable Tx DMA Request */
|
||||
SET_BIT(hi2s->Instance->CFG1, SPI_CFG1_TXDMAEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_I2S_DISABLE(hi2s);
|
||||
|
||||
/* Enable Tx/Rx DMA Request */
|
||||
SET_BIT(hi2s->Instance->CFG1, SPI_CFG1_TXDMAEN);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_I2S_ENABLE(hi2s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx/Rx Transfer half completed callbacks
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_I2SEx_TxRxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hi2s);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_I2S_RxHalfCpltCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx/Rx Transfer completed callbacks
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_I2SEx_TxRxCpltCallback(I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hi2s);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_I2S_RxCpltCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup I2SEx_Private_Functions I2S Extended Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief DMA I2S transmit receive process complete callback
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_DMATxRxCplt(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
|
||||
|
||||
if(((((DMA_Stream_TypeDef *)hdma->Instance)->CR) & DMA_SxCR_CIRC) == 0U)
|
||||
{
|
||||
/* Check if the SPI2S is disabled to edit CFG1 register */
|
||||
if ((hi2s->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Disable Tx/Rx DMA Request */
|
||||
CLEAR_BIT(hi2s->Instance->CFG1, SPI_CFG1_RXDMAEN | SPI_CFG1_TXDMAEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_I2S_DISABLE(hi2s);
|
||||
|
||||
/* Disable Rx DMA Request */
|
||||
CLEAR_BIT(hi2s->Instance->CFG1, SPI_CFG1_RXDMAEN | SPI_CFG1_TXDMAEN);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_I2S_ENABLE(hi2s);
|
||||
}
|
||||
|
||||
hi2s->TxXferCount = 0U;
|
||||
hi2s->RxXferCount = 0U;
|
||||
hi2s->State = HAL_I2S_STATE_READY;
|
||||
|
||||
if (hi2s->ErrorCode != HAL_I2S_ERROR_NONE)
|
||||
{
|
||||
HAL_I2S_ErrorCallback(hi2s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
HAL_I2SEx_TxRxCpltCallback(hi2s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA I2S transmit receive process half complete callback
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_DMATxRxHalfCplt(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
|
||||
|
||||
HAL_I2SEx_TxRxHalfCpltCallback(hi2s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA I2S communication error callback
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_TxRxDMAError(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
|
||||
|
||||
/* Check if the SPI2S is disabled to edit CFG1 register */
|
||||
if ((hi2s->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Disable Rx and Tx DMA Request */
|
||||
CLEAR_BIT(hi2s->Instance->CFG1, (SPI_CFG1_RXDMAEN | SPI_CFG1_TXDMAEN));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_I2S_DISABLE(hi2s);
|
||||
|
||||
/* Disable Rx and Tx DMA Request */
|
||||
CLEAR_BIT(hi2s->Instance->CFG1, (SPI_CFG1_RXDMAEN | SPI_CFG1_TXDMAEN));
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_I2S_ENABLE(hi2s);
|
||||
}
|
||||
|
||||
hi2s->TxXferCount = 0U;
|
||||
hi2s->RxXferCount = 0U;
|
||||
|
||||
hi2s->State= HAL_I2S_STATE_READY;
|
||||
|
||||
/* Set the error code and execute error callback*/
|
||||
SET_BIT(hi2s->ErrorCode, HAL_I2S_ERROR_DMA);
|
||||
HAL_I2S_ErrorCallback(hi2s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx 16-bit handler for Transmit and Receive in Interrupt mode.
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_2linesRxISR_16BIT(struct __I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Receive data in 16 Bit mode */
|
||||
*((uint16_t *)hi2s->pRxBuffPtr) = hi2s->Instance->RXDR;
|
||||
hi2s->pRxBuffPtr += sizeof(uint16_t);
|
||||
hi2s->RxXferCount--;
|
||||
|
||||
if (hi2s->RxXferCount == 0U)
|
||||
{
|
||||
/* Disable RXNE interrupt */
|
||||
__HAL_I2S_DISABLE_IT(hi2s, I2S_IT_RXNE);
|
||||
|
||||
if (hi2s->TxXferCount == 0U)
|
||||
{
|
||||
I2SEx_CloseRxTx_ISR(hi2s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx 32-bit handler for Transmit and Receive in Interrupt mode.
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_2linesRxISR_32BIT(struct __I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Receive data in 32 Bit mode */
|
||||
*((uint32_t *)hi2s->pRxBuffPtr) = hi2s->Instance->RXDR;
|
||||
hi2s->pRxBuffPtr += sizeof(uint32_t);
|
||||
hi2s->RxXferCount--;
|
||||
|
||||
if (hi2s->RxXferCount == 0U)
|
||||
{
|
||||
/* Disable RXNE interrupt */
|
||||
__HAL_I2S_DISABLE_IT(hi2s, I2S_IT_RXNE);
|
||||
|
||||
if (hi2s->TxXferCount == 0U)
|
||||
{
|
||||
I2SEx_CloseRxTx_ISR(hi2s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx 16-bit handler for Transmit and Receive in Interrupt mode.
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_2linesTxISR_16BIT(struct __I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Transmit data in 16 Bit mode */
|
||||
*((__IO uint16_t *)&hi2s->Instance->TXDR) = *((uint16_t *)hi2s->pTxBuffPtr);
|
||||
hi2s->pTxBuffPtr += sizeof(uint16_t);
|
||||
hi2s->TxXferCount--;
|
||||
|
||||
/* Enable CRC Transmission */
|
||||
if (hi2s->TxXferCount == 0U)
|
||||
{
|
||||
/* Disable TXE interrupt */
|
||||
__HAL_I2S_DISABLE_IT(hi2s, I2S_IT_TXE);
|
||||
|
||||
if (hi2s->RxXferCount == 0U)
|
||||
{
|
||||
I2SEx_CloseRxTx_ISR(hi2s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx 32-bit handler for Transmit and Receive in Interrupt mode.
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_2linesTxISR_32BIT(struct __I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Transmit data in 32 Bit mode */
|
||||
*((__IO uint32_t *)&hi2s->Instance->TXDR) = *((uint32_t *)hi2s->pTxBuffPtr);
|
||||
hi2s->pTxBuffPtr += sizeof(uint32_t);
|
||||
hi2s->TxXferCount--;
|
||||
|
||||
/* Enable CRC Transmission */
|
||||
if (hi2s->TxXferCount == 0U)
|
||||
{
|
||||
/* Disable TXE interrupt */
|
||||
__HAL_I2S_DISABLE_IT(hi2s, I2S_IT_TXE);
|
||||
|
||||
if (hi2s->RxXferCount == 0U)
|
||||
{
|
||||
I2SEx_CloseRxTx_ISR(hi2s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle the end of the RXTX transaction.
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module.
|
||||
* @retval None
|
||||
*/
|
||||
static void I2SEx_CloseRxTx_ISR(I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Disable ERR interrupt */
|
||||
__HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_TXE | I2S_IT_ERR));
|
||||
|
||||
if (hi2s->ErrorCode == HAL_I2S_ERROR_NONE)
|
||||
{
|
||||
if (hi2s->State == HAL_I2S_STATE_BUSY_RX)
|
||||
{
|
||||
hi2s->State = HAL_I2S_STATE_READY;
|
||||
HAL_I2S_RxCpltCallback(hi2s);
|
||||
}
|
||||
else
|
||||
{
|
||||
hi2s->State = HAL_I2S_STATE_READY;
|
||||
HAL_I2SEx_TxRxCpltCallback(hi2s);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hi2s->State = HAL_I2S_STATE_READY;
|
||||
HAL_I2S_ErrorCallback(hi2s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles I2S Communication Timeout.
|
||||
* @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
|
||||
* the configuration information for I2S module
|
||||
* @param Flag: Flag checked
|
||||
* @param State: Value of the flag expected
|
||||
* @param Timeout: Duration of the timeout
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef I2SEx_WaitFlagStateUntilTimeout(I2S_HandleTypeDef *hi2s, uint32_t Flag, uint32_t State, uint32_t Timeout)
|
||||
{
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait until flag is set */
|
||||
if(State == RESET)
|
||||
{
|
||||
while(__HAL_I2S_GET_FLAG(hi2s, Flag) == RESET)
|
||||
{
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
|
||||
{
|
||||
/* Set the I2S State ready */
|
||||
hi2s->State= HAL_I2S_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(__HAL_I2S_GET_FLAG(hi2s, Flag) != RESET)
|
||||
{
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
|
||||
{
|
||||
/* Set the I2S State ready */
|
||||
hi2s->State= HAL_I2S_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2s);
|
||||
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+2285
File diff suppressed because it is too large
Load Diff
+282
@@ -0,0 +1,282 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_iwdg.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief IWDG HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Independent Watchdog (IWDG) peripheral:
|
||||
* + Initialization and Start functions
|
||||
* + IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### IWDG Generic features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) The IWDG can be started by either software or hardware (configurable
|
||||
through option byte).
|
||||
|
||||
(+) The IWDG is clocked by Low-Speed clock (LSI) and thus stays active even
|
||||
if the main clock fails.
|
||||
|
||||
(+) Once the IWDG is started, the LSI is forced ON and both can not be
|
||||
disabled. The counter starts counting down from the reset value (0xFFF).
|
||||
When it reaches the end of count value (0x000) a reset signal is
|
||||
generated (IWDG reset).
|
||||
|
||||
(+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register,
|
||||
the IWDG_RLR value is reloaded in the counter and the watchdog reset is
|
||||
prevented.
|
||||
|
||||
(+) The IWDG is implemented in the VDD voltage domain that is still functional
|
||||
in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
|
||||
IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
|
||||
reset occurs.
|
||||
|
||||
(+) Debug mode : When the microcontroller enters debug mode (core halted),
|
||||
the IWDG counter either continues to work normally or stops, depending
|
||||
on DBG_IWDG_STOP configuration bit in DBG module, accessible through
|
||||
__HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros
|
||||
|
||||
[..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
|
||||
The IWDG timeout may vary due to LSI frequency dispersion. STM32H7xx
|
||||
devices provide the capability to measure the LSI frequency (LSI clock
|
||||
connected internally to TIM16 CH1 input capture). The measured value
|
||||
can be used to have an IWDG timeout with an acceptable accuracy.
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) Use IWDG using HAL_IWDG_Init() function to :
|
||||
(++) Enable instance by writing Start keyword in IWDG_KEY register. LSI
|
||||
clock is forced ON and IWDG counter starts downcounting.
|
||||
(++) Enable write access to configuration register: IWDG_PR, IWDG_RLR &
|
||||
IWDG_WINR.
|
||||
(++) Configure the IWDG prescaler and counter reload value. This reload
|
||||
value will be loaded in the IWDG counter each time the watchdog is
|
||||
reloaded, then the IWDG will start counting down from this value.
|
||||
(++) Wait for status flags to be reset
|
||||
(++) Depending on window parameter:
|
||||
(+++) If Window Init parameter is same as Window register value,
|
||||
nothing more is done but reload counter value in order to exit
|
||||
function withy exact time base.
|
||||
(+++) Else modify Window register. This will automatically reload
|
||||
watchdog counter.
|
||||
|
||||
(#) Then the application program must refresh the IWDG counter at regular
|
||||
intervals during normal operation to prevent an MCU reset, using
|
||||
HAL_IWDG_Refresh() function.
|
||||
|
||||
*** IWDG HAL driver macros list ***
|
||||
====================================
|
||||
[..]
|
||||
Below the list of most used macros in IWDG HAL driver:
|
||||
(+) __HAL_IWDG_START: Enable the IWDG peripheral
|
||||
(+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in
|
||||
the reload register
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
/** @addtogroup IWDG
|
||||
* @brief IWDG HAL module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup IWDG_Private_Defines IWDG Private Defines
|
||||
* @{
|
||||
*/
|
||||
/* Status register need 5 RC LSI divided by prescaler clock to be updated. With
|
||||
higher prescaler (256), and according to LSI variation, we need to wait at
|
||||
least 6 cycles so 48 ms. */
|
||||
#define HAL_IWDG_DEFAULT_TIMEOUT 48u
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup IWDG_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup IWDG_Exported_Functions_Group1
|
||||
* @brief Initialization and Start functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and Start functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Initialize the IWDG according to the specified parameters in the
|
||||
IWDG_InitTypeDef of associated handle.
|
||||
(+) Manage Window option.
|
||||
(+) Once initialization is performed in HAL_IWDG_Init function, Watchdog
|
||||
is reloaded in order to exit function with correct time base.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the IWDG according to the specified parameters in the
|
||||
* IWDG_InitTypeDef and start watchdog. Before exiting function,
|
||||
* watchdog is refreshed in order to have correct time base.
|
||||
* @param hiwdg pointer to a IWDG_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified IWDG module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
|
||||
{
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Check the IWDG handle allocation */
|
||||
if(hiwdg == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
|
||||
assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
|
||||
assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
|
||||
assert_param(IS_IWDG_WINDOW(hiwdg->Init.Window));
|
||||
|
||||
/* Enable IWDG. LSI is turned on automaticaly */
|
||||
__HAL_IWDG_START(hiwdg);
|
||||
|
||||
/* Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers by writing
|
||||
0x5555 in KR */
|
||||
IWDG_ENABLE_WRITE_ACCESS(hiwdg);
|
||||
|
||||
/* Write to IWDG registers the Prescaler & Reload values to work with */
|
||||
hiwdg->Instance->PR = hiwdg->Init.Prescaler;
|
||||
hiwdg->Instance->RLR = hiwdg->Init.Reload;
|
||||
|
||||
/* Check pending flag, if previous update not done, return timeout */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for register to be updated */
|
||||
while(hiwdg->Instance->SR != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
/* If window parameter is different than current value, modify window
|
||||
register */
|
||||
if(hiwdg->Instance->WINR != hiwdg->Init.Window)
|
||||
{
|
||||
/* Write to IWDG WINR the IWDG_Window value to compare with. In any case,
|
||||
even if window feature is disabled, Watchdog will be reloaded by writing
|
||||
windows register */
|
||||
hiwdg->Instance->WINR = hiwdg->Init.Window;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Reload IWDG counter with value defined in the reload register */
|
||||
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup IWDG_Exported_Functions_Group2
|
||||
* @brief IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Refresh the IWDG.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Refresh the IWDG.
|
||||
* @param hiwdg pointer to a IWDG_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified IWDG module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
|
||||
{
|
||||
/* Reload IWDG counter with value defined in the reload register */
|
||||
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+3461
File diff suppressed because it is too large
Load Diff
+1675
File diff suppressed because it is too large
Load Diff
+1895
File diff suppressed because it is too large
Load Diff
+625
@@ -0,0 +1,625 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_mdios.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief MDIOS HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the MDIOS Peripheral.
|
||||
* + Initialization and de-initialization functions
|
||||
* + IO operation functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
The MDIOS HAL driver can be used as follow:
|
||||
|
||||
(#) Declare a MDIOS_HandleTypeDef handle structure.
|
||||
|
||||
(#) Initialize the MDIOS low level resources by implementing the HAL_MDIOS_MspInit() API:
|
||||
(##) Enable the MDIOS interface clock.
|
||||
(##) MDIOS pins configuration:
|
||||
(+++) Enable clocks for the MDIOS GPIOs.
|
||||
(+++) Configure the MDIOS pins as alternate function.
|
||||
(##) NVIC configuration if you need to use interrupt process:
|
||||
(+++) Configure the MDIOS interrupt priority.
|
||||
(+++) Enable the NVIC MDIOS IRQ handle.
|
||||
|
||||
(#) Program the Port Address and the Preamble Check in the Init structure.
|
||||
|
||||
(#) Initialize the MDIOS registers by calling the HAL_MDIOS_Init() API.
|
||||
|
||||
(#) Perform direct slave read/write operations using the following APIs:
|
||||
(##) Read the value of a DINn register: HAL_MDIOS_ReadReg()
|
||||
(##) Write a value to a DOUTn register: HAL_MDIOS_WriteReg()
|
||||
|
||||
(#) Get the Master read/write operations flags using the following APIs:
|
||||
(##) Bit map of DOUTn registers read by Master: HAL_MDIOS_GetReadRegAddress()
|
||||
(##) Bit map of DINn registers written by Master : HAL_MDIOS_GetWrittenRegAddress()
|
||||
|
||||
(#) Clear the read/write flags using the following APIs:
|
||||
(##) Clear read flags of a set of registers: HAL_MDIOS_ClearReadRegAddress()
|
||||
(##) Clear write flags of a set of registers: HAL_MDIOS_ClearWriteRegAddress()
|
||||
|
||||
(#) Enable interrupts on events using HAL_MDIOS_EnableEvents(), when called
|
||||
the MDIOS will generate an interrupt in the following cases:
|
||||
(##) a DINn register written by the Master
|
||||
(##) a DOUTn register read by the Master
|
||||
(##) an error occur
|
||||
|
||||
(@) A callback is executed for each genereted interrupt, so the driver provide the following
|
||||
HAL_MDIOS_WriteCpltCallback(), HAL_MDIOS_ReadCpltCallback() and HAL_MDIOS_ErrorCallback()
|
||||
(@) HAL_MDIOS_IRQHandler() must be called from the MDIOS IRQ Handler, to handle the interrupt
|
||||
and execute the previous callbacks
|
||||
|
||||
(#) Reset the MDIOS peripheral and all related ressources by calling the HAL_MDIOS_DeInit() API.
|
||||
(##) HAL_MDIOS_MspDeInit() must be implemented to reset low level ressources
|
||||
(GPIO, Clocks, NVIC configuration ...)
|
||||
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
/** @defgroup MDIOS MDIOS
|
||||
* @brief HAL MDIOS module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_MDIOS_MODULE_ENABLED
|
||||
|
||||
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define MDIOS_PORT_ADDRESS_SHIFT ((uint32_t)8)
|
||||
#define MDIOS_ALL_REG_FLAG ((uint32_t)0xFFFFFFFFU)
|
||||
#define MDIOS_ALL_ERRORS_FLAG ((uint32_t)(MDIOS_SR_PERF | MDIOS_SR_SERF | MDIOS_SR_TERF))
|
||||
|
||||
#define MDIOS_DIN_BASE_ADDR (MDIOS_BASE + 0x100)
|
||||
#define MDIOS_DOUT_BASE_ADDR (MDIOS_BASE + 0x180)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup MDIOS_Exported_Functions MDIOS Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MDIOS_Exported_Functions_Group1 Initialization/de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and Configuration functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to initialize the MDIOS
|
||||
(+) The following parameters can be configured:
|
||||
(++) Port Address
|
||||
(++) Preamble Check
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the MDIOS according to the specified parameters in
|
||||
* the MDIOS_InitTypeDef and creates the associated handle .
|
||||
* @param hmdios: pointer to a MDIOS_HandleTypeDef structure that contains
|
||||
* the configuration information for MDIOS module
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_Init(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
uint32_t tmpcr = 0;
|
||||
|
||||
/* Check the MDIOS handle allocation */
|
||||
if(hmdios == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MDIOS_ALL_INSTANCE(hmdios->Instance));
|
||||
assert_param(IS_MDIOS_PORTADDRESS(hmdios->Init.PortAddress));
|
||||
assert_param(IS_MDIOS_PREAMBLECHECK(hmdios->Init.PreambleCheck));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
if(hmdios->State == HAL_MDIOS_STATE_RESET)
|
||||
{
|
||||
/* Init the low level hardware */
|
||||
HAL_MDIOS_MspInit(hmdios);
|
||||
}
|
||||
|
||||
/* Change the MDIOS state */
|
||||
hmdios->State = HAL_MDIOS_STATE_BUSY;
|
||||
|
||||
/* Get the MDIOS CR value */
|
||||
tmpcr = hmdios->Instance->CR;
|
||||
|
||||
/* Clear PORT_ADDRESS, DPC and EN bits */
|
||||
tmpcr &= ((uint32_t)~(MDIOS_CR_EN | MDIOS_CR_DPC | MDIOS_CR_PORT_ADDRESS));
|
||||
|
||||
/* Set MDIOS control parametrs and enable the peripheral */
|
||||
tmpcr |= (uint32_t)(((hmdios->Init.PortAddress) << MDIOS_PORT_ADDRESS_SHIFT) |\
|
||||
(hmdios->Init.PreambleCheck) | \
|
||||
(MDIOS_CR_EN));
|
||||
|
||||
/* Write the MDIOS CR */
|
||||
hmdios->Instance->CR = tmpcr;
|
||||
|
||||
/* Change the MDIOS state */
|
||||
hmdios->State = HAL_MDIOS_STATE_READY;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the MDIOS peripheral.
|
||||
* @param hmdios: MDIOS handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_DeInit(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Check the MDIOS handle allocation */
|
||||
if(hmdios == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MDIOS_ALL_INSTANCE(hmdios->Instance));
|
||||
|
||||
/* Change the MDIOS state */
|
||||
hmdios->State = HAL_MDIOS_STATE_BUSY;
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_MDIOS_DISABLE(hmdios);
|
||||
|
||||
/* DeInit the low level hardware */
|
||||
HAL_MDIOS_MspDeInit(hmdios);
|
||||
|
||||
/* Change the MDIOS state */
|
||||
hmdios->State = HAL_MDIOS_STATE_RESET;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MDIOS MSP Init
|
||||
* @param hmdios: mdios handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MDIOS_MspInit(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdios);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_MDIOS_MspInit can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MDIOS MSP DeInit
|
||||
* @param hmdios: mdios handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MDIOS_MspDeInit(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdios);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_MDIOS_MspDeInit can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/** @defgroup MDIOS_Exported_Functions_Group2 IO operation functions
|
||||
* @brief MDIOS Read/Write functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
This subsection provides a set of functions allowing to manage the MDIOS
|
||||
read and write operations.
|
||||
|
||||
(#) APIs that allow to the MDIOS to read/write from/to the
|
||||
values of one of the DINn/DOUTn registers:
|
||||
(+) Read the value of a DINn register: HAL_MDIOS_ReadReg()
|
||||
(+) Write a value to a DOUTn register: HAL_MDIOS_WriteReg()
|
||||
|
||||
(#) APIs that provide if there are some Slave registres have been
|
||||
read or written by the Master:
|
||||
(+) DOUTn registers read by Master: HAL_MDIOS_GetReadRegAddress()
|
||||
(+) DINn registers written by Master : HAL_MDIOS_GetWrittenRegAddress()
|
||||
|
||||
(#) APIs that Clear the read/write flags:
|
||||
(+) Clear read registers flags: HAL_MDIOS_ClearReadRegAddress()
|
||||
(+) Clear write registers flags: HAL_MDIOS_ClearWriteRegAddress()
|
||||
|
||||
(#) A set of Callbacks are provided:
|
||||
(+) HAL_MDIOS_WriteCpltCallback()
|
||||
(+) HAL_MDIOS_ReadCpltCallback()
|
||||
(+) HAL_MDIOS_ErrorCallback()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Writes to an MDIOS output register
|
||||
* @param hmdios: mdios handle
|
||||
* @param RegNum: MDIOS output register address
|
||||
* @param Data: Data to write
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_WriteReg(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum, uint16_t Data)
|
||||
{
|
||||
uint32_t tmpreg;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MDIOS_REGISTER(RegNum));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
/* Get the addr of output register to be written by the MDIOS */
|
||||
tmpreg = MDIOS_DOUT_BASE_ADDR + (4 * RegNum);
|
||||
|
||||
/* Write to DOUTn register */
|
||||
*((uint32_t *)tmpreg) = Data;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads an MDIOS input register
|
||||
* @param hmdios: mdios handle
|
||||
* @param RegNum: MDIOS input register address
|
||||
* @param pData: pointer to Data
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_ReadReg(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum, uint16_t *pData)
|
||||
{
|
||||
uint32_t tmpreg;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MDIOS_REGISTER(RegNum));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
/* Get the addr of input register to be read by the MDIOS */
|
||||
tmpreg = MDIOS_DIN_BASE_ADDR + (4 * RegNum);
|
||||
|
||||
/* Read DINn register */
|
||||
*pData = (uint16_t)(*((uint32_t *)tmpreg));
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Written registers by MDIO master
|
||||
* @param hmdios: mdios handle
|
||||
* @retval bit map of written registers addresses
|
||||
*/
|
||||
uint32_t HAL_MDIOS_GetWrittenRegAddress(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
return hmdios->Instance->WRFR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Read registers by MDIO master
|
||||
* @param hmdios: mdios handle
|
||||
* @retval bit map of read registers addresses
|
||||
*/
|
||||
uint32_t HAL_MDIOS_GetReadRegAddress(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
return hmdios->Instance->RDFR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears Write registers flag
|
||||
* @param hmdios: mdios handle
|
||||
* @param RegNum: registers addresses to be cleared
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_ClearWriteRegAddress(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MDIOS_REGISTER(RegNum));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
/* Clear write registers flags */
|
||||
hmdios->Instance->CWRFR |= (RegNum);
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears Read register flag
|
||||
* @param hmdios: mdios handle
|
||||
* @param RegNum: registers addresses to be cleared
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_ClearReadRegAddress(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MDIOS_REGISTER(RegNum));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
/* Clear read registers flags */
|
||||
hmdios->Instance->CRDFR |= (RegNum);
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables Events for MDIOS peripheral
|
||||
* @param hmdios: mdios handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_EnableEvents(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
/* Enable MDIOS interrupts: Register Write, Register Read and Error ITs */
|
||||
__HAL_MDIOS_ENABLE_IT(hmdios, (MDIOS_IT_WRITE | MDIOS_IT_READ | MDIOS_IT_ERROR));
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles MDIOS interrupt request.
|
||||
* @param hmdios: MDIOS handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MDIOS_IRQHandler(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Write Register Interrupt enabled ? */
|
||||
if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_WRITE) != RESET)
|
||||
{
|
||||
/* Write register flag */
|
||||
if(HAL_MDIOS_GetWrittenRegAddress(hmdios) != RESET)
|
||||
{
|
||||
/* Write callback function */
|
||||
HAL_MDIOS_WriteCpltCallback(hmdios);
|
||||
|
||||
/* Clear write register flag */
|
||||
HAL_MDIOS_ClearWriteRegAddress(hmdios, MDIOS_ALL_REG_FLAG);
|
||||
}
|
||||
}
|
||||
|
||||
/* Read Register Interrupt enabled ? */
|
||||
if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_READ) != RESET)
|
||||
{
|
||||
/* Read register flag */
|
||||
if(HAL_MDIOS_GetReadRegAddress(hmdios) != RESET)
|
||||
{
|
||||
/* Read callback function */
|
||||
HAL_MDIOS_ReadCpltCallback(hmdios);
|
||||
|
||||
/* Clear read register flag */
|
||||
HAL_MDIOS_ClearReadRegAddress(hmdios, MDIOS_ALL_REG_FLAG);
|
||||
}
|
||||
}
|
||||
|
||||
/* Error Interrupt enabled ? */
|
||||
if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_ERROR) != RESET)
|
||||
{
|
||||
/* All Errors Flag */
|
||||
if(__HAL_MDIOS_GET_ERROR_FLAG(hmdios, MDIOS_ALL_ERRORS_FLAG) !=RESET)
|
||||
{
|
||||
/* Error Callback */
|
||||
HAL_MDIOS_ErrorCallback(hmdios);
|
||||
|
||||
/* Clear errors flag */
|
||||
__HAL_MDIOS_CLEAR_ERROR_FLAG(hmdios, MDIOS_ALL_ERRORS_FLAG);
|
||||
}
|
||||
}
|
||||
/* check MDIOS WAKEUP exti flag */
|
||||
if(__HAL_MDIOS_WAKEUP_EXTI_GET_FLAG(MDIOS_WAKEUP_EXTI_LINE) != RESET)
|
||||
{
|
||||
/* Clear MDIOS WAKEUP Exti pending bit */
|
||||
__HAL_MDIOS_WAKEUP_EXTI_CLEAR_FLAG(MDIOS_WAKEUP_EXTI_LINE);
|
||||
/* MDIOS WAKEUP interrupt user callback */
|
||||
HAL_MDIOS_WakeUpCallback(hmdios);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write Complete Callback
|
||||
* @param hmdios: mdios handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MDIOS_WriteCpltCallback(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdios);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_MDIOS_WriteCpltCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read Complete Callback
|
||||
* @param hmdios: mdios handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MDIOS_ReadCpltCallback(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdios);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_MDIOS_ReadCpltCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Error Callback
|
||||
* @param hmdios: mdios handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MDIOS_ErrorCallback(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdios);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_MDIOS_ErrorCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MDIOS WAKEUP interrupt callback
|
||||
* @param hmdios: mdios handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MDIOS_WakeUpCallback(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdios);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_MDIOS_WakeUpCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup MDIOS_Exported_Functions_Group3 Peripheral Control functions
|
||||
* @brief MDIOS control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the MDIOS.
|
||||
(+) HAL_MDIOS_GetState() API, helpful to check in run-time the state.
|
||||
(+) HAL_MDIOS_GetError() API, returns the errors occured during data transfer.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Gets MDIOS error flags
|
||||
* @param hmdios: mdios handle
|
||||
* @retval bit map of occured errors
|
||||
*/
|
||||
uint32_t HAL_MDIOS_GetError(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* return errors flags on status register */
|
||||
return hmdios->Instance->SR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the MDIOS HAL state
|
||||
* @param hmdios: mdios handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_MDIOS_StateTypeDef HAL_MDIOS_GetState(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Return MDIOS state */
|
||||
return hmdios->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_MDIOS_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1908
File diff suppressed because it is too large
Load Diff
+2437
File diff suppressed because it is too large
Load Diff
+313
@@ -0,0 +1,313 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_mmc_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief MMC card Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Secure Digital (MMC) peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The MMC Extension HAL driver can be used as follows:
|
||||
(+) Configure Buffer0 and Buffer1 start address and Buffer size using HAL_MMCEx_ConfigDMAMultiBuffer() function.
|
||||
|
||||
(+) Start Read and Write for multibuffer mode using HAL_MMCEx_ReadBlocksDMAMultiBuffer() and HAL_MMCEx_WriteBlocksDMAMultiBuffer() functions.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MMCEx MMCEx
|
||||
* @brief MMC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup MMCEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MMCEx_Exported_Functions_Group1
|
||||
* @brief Multibuffer functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Multibuffer functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to configure the multibuffer mode and start read and write
|
||||
multibuffer mode for MMC HAL driver.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure DMA Dual Buffer mode. The Data transfer is managed by an Internal DMA.
|
||||
* @param hmmc: MMC handle
|
||||
* @param pDataBuffer0: Pointer to the buffer0 that will contain/receive the transfered data
|
||||
* @param pDataBuffer1: Pointer to the buffer1 that will contain/receive the transfered data
|
||||
* @param BufferSize: Size of Buffer0 in Blocks. Buffer0 and Buffer1 must have the same size.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_ConfigDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t * pDataBuffer0, uint32_t * pDataBuffer1, uint32_t BufferSize)
|
||||
{
|
||||
if(hmmc->State == HAL_MMC_STATE_READY)
|
||||
{
|
||||
hmmc->Instance->IDMABASE0= (uint32_t) pDataBuffer0 ;
|
||||
hmmc->Instance->IDMABASE1= (uint32_t) pDataBuffer1 ;
|
||||
hmmc->Instance->IDMABSIZE= (uint32_t) BufferSize;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in a card. The received Data will be stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_MMCEx_ConfigDMAMultiBuffer before call this function.
|
||||
* @param hmmc: MMC handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_ReadBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate = HAL_MMC_ERROR_NONE;
|
||||
|
||||
if(hmmc->State == HAL_MMC_STATE_READY)
|
||||
{
|
||||
if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
|
||||
{
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((hmmc->Instance->IDMABASE0 == 0) || (hmmc->Instance->IDMABASE1 == 0) || (hmmc->Instance->IDMABSIZE == 0))
|
||||
{
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hmmc->Instance->DCTRL = 0;
|
||||
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
|
||||
hmmc->State = HAL_MMC_STATE_BUSY;
|
||||
|
||||
if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
|
||||
{
|
||||
BlockAdd *= 512;
|
||||
}
|
||||
|
||||
/* Configure the MMC DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
SDMMC_ConfigData(hmmc->Instance, &config);
|
||||
|
||||
hmmc->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
|
||||
|
||||
hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
__HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND | SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
/* Read Blocks in DMA mode */
|
||||
hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
|
||||
|
||||
/* Read Multi Block command */
|
||||
errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, BlockAdd);
|
||||
if(errorstate != HAL_MMC_ERROR_NONE)
|
||||
{
|
||||
hmmc->State = HAL_MMC_STATE_READY;
|
||||
hmmc->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write block(s) to a specified address in a card. The transfered Data are stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_MMCEx_ConfigDMAMultiBuffer before call this function.
|
||||
* @param hmmc: MMC handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_WriteBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate = HAL_MMC_ERROR_NONE;
|
||||
|
||||
if(hmmc->State == HAL_MMC_STATE_READY)
|
||||
{
|
||||
if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
|
||||
{
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((hmmc->Instance->IDMABASE0 == 0) || (hmmc->Instance->IDMABASE1 == 0) || (hmmc->Instance->IDMABSIZE == 0))
|
||||
{
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hmmc->Instance->DCTRL = 0;
|
||||
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
|
||||
|
||||
hmmc->State = HAL_MMC_STATE_BUSY;
|
||||
|
||||
if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
|
||||
{
|
||||
BlockAdd *= 512;
|
||||
}
|
||||
|
||||
/* Configure the MMC DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_CARD;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
SDMMC_ConfigData(hmmc->Instance, &config);
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
|
||||
|
||||
hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
__HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND | SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
/* Write Blocks in DMA mode */
|
||||
hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
|
||||
|
||||
/* Write Multi Block command */
|
||||
errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, BlockAdd);
|
||||
if(errorstate != HAL_MMC_ERROR_NONE)
|
||||
{
|
||||
hmmc->State = HAL_MMC_STATE_READY;
|
||||
hmmc->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Change the DMA Buffer0 or Buffer1 address on the fly.
|
||||
* @param hmmc: pointer to a MMC_HandleTypeDef structure.
|
||||
* @param Buffer: the buffer to be changed, This parameter can be one of
|
||||
* the following values: MMC_DMA_BUFFER0 or MMC_DMA_BUFFER1
|
||||
* @param pDataBuffer: The new address
|
||||
* @note The BUFFER0 address can be changed only when the current transfer use
|
||||
* BUFFER1 and the BUFFER1 address can be changed only when the current
|
||||
* transfer use BUFFER0.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_ChangeDMABuffer(MMC_HandleTypeDef *hmmc, HAL_MMCEx_DMABuffer_MemoryTypeDef Buffer, uint32_t *pDataBuffer)
|
||||
{
|
||||
if(Buffer == MMC_DMA_BUFFER0)
|
||||
{
|
||||
/* change the buffer0 address */
|
||||
hmmc->Instance->IDMABASE0 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* change the memory1 address */
|
||||
hmmc->Instance->IDMABASE1 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1862
File diff suppressed because it is too large
Load Diff
+1047
File diff suppressed because it is too large
Load Diff
+992
@@ -0,0 +1,992 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_opamp.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief OPAMP HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the operational amplifier(s) peripheral:
|
||||
* + OPAMP configuration
|
||||
* + OPAMP calibration
|
||||
* Thanks to
|
||||
* + Initialization and de-initialization functions
|
||||
* + IO operation functions
|
||||
* + Peripheral Control functions
|
||||
* + Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
================================================================================
|
||||
##### OPAMP Peripheral Features #####
|
||||
================================================================================
|
||||
|
||||
[..] The device integrates 2 operational amplifiers OPAMP1 & OPAMP2
|
||||
|
||||
(#) The OPAMP(s) provides several exclusive running modes.
|
||||
(++) Standalone mode
|
||||
(++) Programmable Gain Amplifier (PGA) modes
|
||||
(++) Follower mode
|
||||
|
||||
(#) Each OPAMP(s) can be configured in normal and high speed mode.
|
||||
|
||||
(#) The OPAMP(s) provide(s) calibration capabilities.
|
||||
(++) Calibration aims at correcting some offset for running mode.
|
||||
(++) The OPAMP uses either factory calibration settings OR user defined
|
||||
calibration (trimming) settings (i.e. trimming mode).
|
||||
(++) The user defined settings can be figured out using self calibration
|
||||
handled by HAL_OPAMP_SelfCalibrate, HAL_OPAMPEx_SelfCalibrateAll
|
||||
(++) HAL_OPAMP_SelfCalibrate:
|
||||
(+++) Runs automatically the calibration in 2 steps.
|
||||
(90% of VDDA for NMOS transistors, 10% of VDDA for PMOS transistors).
|
||||
(As OPAMP is Rail-to-rail input/output, these 2 steps calibration is
|
||||
appropriate and enough in most cases).
|
||||
(+++) Runs automatically the calibration.
|
||||
(+++) Enables the user trimming mode
|
||||
(+++) Updates the init structure with trimming values with fresh calibration
|
||||
results.
|
||||
The user may store the calibration results for larger
|
||||
(ex monitoring the trimming as a function of temperature
|
||||
for instance)
|
||||
(+++) HAL_OPAMPEx_SelfCalibrateAll
|
||||
runs calibration of all OPAMPs in parallel to save search time.
|
||||
|
||||
(#) Running mode: Standalone mode
|
||||
(++) Gain is set externally (gain depends on external loads).
|
||||
(++) Follower mode also possible externally by connecting the inverting input to
|
||||
the output.
|
||||
|
||||
(#) Running mode: Follower mode
|
||||
(++) No Inverting Input is connected.
|
||||
|
||||
(#) Running mode: Programmable Gain Amplifier (PGA) mode
|
||||
(Resistor feedback output)
|
||||
(#) The OPAMP(s) output(s) can be internally connected to resistor feedback
|
||||
output.
|
||||
(#) OPAMP gain can be selected as :
|
||||
|
||||
(##) Gain of x2, x4, x8 or x16 for non inverting mode with:
|
||||
(+++) VREF- referenced.
|
||||
(+++) Filtering on VINM0, VREF- referenced.
|
||||
(+++) VINM0 node for bias voltage and VINP0 for input signal.
|
||||
(+++) VINM0 node for bias voltage and VINP0 for input signal, VINM1 node for filtering.
|
||||
|
||||
(##) Gain of x-1, x-3, x-7 or x-15 for inverting mode with:
|
||||
(+++) VINM0 node for input signal and VINP0 for bias.
|
||||
(+++) VINM0 node for input signal and VINP0 for bias voltage, VINM1 node for filtering.
|
||||
|
||||
(#) The OPAMPs inverting input can be selected according to the Reference Manual
|
||||
"OPAMP functional description" chapter.
|
||||
|
||||
(#) The OPAMPs non inverting input can be selected according to the Reference Manual
|
||||
"OPAMP functional description" chapter.
|
||||
|
||||
|
||||
##### How to use this driver #####
|
||||
================================================================================
|
||||
[..]
|
||||
|
||||
*** High speed / normal power mode ***
|
||||
============================================
|
||||
[..] To run in high speed mode:
|
||||
|
||||
(#) Configure the OPAMP using HAL_OPAMP_Init() function:
|
||||
(++) Select OPAMP_POWERMODE_HIGHSPEED
|
||||
(++) Otherwise select OPAMP_POWERMODE_NORMAL
|
||||
|
||||
*** Calibration ***
|
||||
============================================
|
||||
[..] To run the OPAMP calibration self calibration:
|
||||
|
||||
(#) Start calibration using HAL_OPAMP_SelfCalibrate.
|
||||
Store the calibration results.
|
||||
|
||||
*** Running mode ***
|
||||
============================================
|
||||
|
||||
[..] To use the OPAMP, perform the following steps:
|
||||
|
||||
(#) Fill in the HAL_OPAMP_MspInit() to
|
||||
(++) Enable the OPAMP Peripheral clock using macro __HAL_RCC_OPAMP_CLK_ENABLE()
|
||||
(++) Configure the OPAMP input AND output in analog mode using
|
||||
HAL_GPIO_Init() to map the OPAMP output to the GPIO pin.
|
||||
|
||||
(#) Configure the OPAMP using HAL_OPAMP_Init() function:
|
||||
(++) Select the mode
|
||||
(++) Select the inverting input
|
||||
(++) Select the non-inverting input
|
||||
(++) If PGA mode is enabled, Select if inverting input is connected.
|
||||
(++) Select either factory or user defined trimming mode.
|
||||
(++) If the user-defined trimming mode is enabled, select PMOS & NMOS trimming values
|
||||
(typically values set by HAL_OPAMP_SelfCalibrate function).
|
||||
|
||||
(#) Enable the OPAMP using HAL_OPAMP_Start() function.
|
||||
|
||||
(#) Disable the OPAMP using HAL_OPAMP_Stop() function.
|
||||
|
||||
(#) Lock the OPAMP in running mode using HAL_OPAMP_Lock() function.
|
||||
Caution: On STM32H7, HAL OPAMP lock is software lock only (not
|
||||
hardware lock as on some other STM32 devices)
|
||||
|
||||
(#) If needed, unlock the OPAMP using HAL_OPAMPEx_Unlock() function.
|
||||
|
||||
*** Running mode: change of configuration while OPAMP ON ***
|
||||
============================================
|
||||
[..] To Re-configure OPAMP when OPAMP is ON (change on the fly)
|
||||
(#) If needed, fill in the HAL_OPAMP_MspInit()
|
||||
(++) This is the case for instance if you wish to use new OPAMP I/O
|
||||
|
||||
(#) Configure the OPAMP using HAL_OPAMP_Init() function:
|
||||
(++) As in configure case, select first the parameters you wish to modify.
|
||||
|
||||
(#) Change from high speed mode to normal power mode (& vice versa) requires
|
||||
first HAL_OPAMP_DeInit() (force OPAMP OFF) and then HAL_OPAMP_Init().
|
||||
In other words, of OPAMP is ON, HAL_OPAMP_Init can NOT change power mode
|
||||
alone.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
Table 1. OPAMPs inverting/non-inverting inputs for the STM32H7 devices:
|
||||
|
||||
+------------------------------------------------------------------------|
|
||||
| | | OPAMP1 | OPAMP2 |
|
||||
|-----------------|---------|----------------------|---------------------|
|
||||
| Inverting Input | VM_SEL | VINM0-> PC5 | VINM0-> PE8 |
|
||||
| | | VINM1-> PA7 | VINM1-> PG1 |
|
||||
| | | Internal: | Internal: |
|
||||
| | | ADC1_IN9 | OPAMP2_OUT |
|
||||
| | | ADC2_IN9 | PGA mode |
|
||||
| | | OPAMP1_OUT | |
|
||||
| | | PGA mode | |
|
||||
|-----------------|---------|----------------------|---------------------|
|
||||
| Non Inverting | VP_SEL | | |
|
||||
| | | VP0 -> PB0 (GPIO) | VP0 -> PE9 (GPIO) |
|
||||
| | | Internal: | Internal: |
|
||||
| Input | | DAC1_int | DAC2_int |
|
||||
| | | ADC1_IN8 | COMP2_INP |
|
||||
| | | ADC2_IN8 | |
|
||||
| | | COMP1_INP | |
|
||||
+------------------------------------------------------------------------|
|
||||
|
||||
|
||||
[..] Table 2. OPAMPs outputs for the STM32H7 devices:
|
||||
|
||||
+-------------------------------------------------------------------------
|
||||
| | | OPAMP1 | OPAMP2 |
|
||||
|-----------------|--------|-----------------------|---------------------|
|
||||
| Output | VOUT | PC4 | PE7 |
|
||||
| | | & ADC1_IN4| | & COMP2_INN7 if |
|
||||
| | | ADC2_IN4 |connected internally |
|
||||
| | | COMP1_INN7 if | |
|
||||
| | | connected internally | |
|
||||
|-----------------|--------|-----------------------|---------------------|
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup OPAMP OPAMP
|
||||
* @brief OPAMP module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_OPAMP_MODULE_ENABLED
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup OPAMP_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* CSR register reset value */
|
||||
#define OPAMP_CSR_RESET_VALUE ((uint32_t)0x00000000)
|
||||
|
||||
|
||||
#define OPAMP_CSR_RESET_BITS (OPAMP_CSR_OPAMPxEN | OPAMP_CSR_OPAHSM | OPAMP_CSR_VMSEL \
|
||||
| OPAMP_CSR_PGGAIN | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL \
|
||||
| OPAMP_CSR_CALON | OPAMP_CSR_USERTRIM)
|
||||
/* CSR Init masks */
|
||||
|
||||
#define OPAMP_CSR_INIT_MASK_PGA (OPAMP_CSR_OPAHSM | OPAMP_CSR_VMSEL | OPAMP_CSR_PGGAIN | OPAMP_CSR_PGGAIN \
|
||||
| OPAMP_CSR_VPSEL | OPAMP_CSR_USERTRIM)
|
||||
|
||||
|
||||
#define OPAMP_CSR_INIT_MASK_FOLLOWER (OPAMP_CSR_OPAHSM | OPAMP_CSR_VMSEL| OPAMP_CSR_VPSEL \
|
||||
| OPAMP_CSR_USERTRIM)
|
||||
|
||||
|
||||
#define OPAMP_CSR_INIT_MASK_STANDALONE (OPAMP_CSR_OPAHSM | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL \
|
||||
| OPAMP_CSR_VMSEL | OPAMP_CSR_USERTRIM)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup OPAMP_Exported_Functions OPAMP Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup OPAMP_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
==============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the OPAMP according to the specified
|
||||
* parameters in the OPAMP_InitTypeDef and initialize the associated handle.
|
||||
* @note If the selected opamp is locked, initialization can't be performed.
|
||||
* To unlock the configuration, perform a system reset.
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint32_t updateotrlpotr = 0;
|
||||
|
||||
/* Check the OPAMP handle allocation and lock status */
|
||||
/* Init not allowed if calibration is ongoing */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
/* Set OPAMP parameters */
|
||||
assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
|
||||
assert_param(IS_OPAMP_FUNCTIONAL_NORMALMODE(hopamp->Init.Mode));
|
||||
assert_param(IS_OPAMP_NONINVERTING_INPUT(hopamp->Init.NonInvertingInput));
|
||||
|
||||
if ((hopamp->Init.Mode) == OPAMP_STANDALONE_MODE)
|
||||
{
|
||||
assert_param(IS_OPAMP_INVERTING_INPUT_STANDALONE(hopamp->Init.InvertingInput));
|
||||
}
|
||||
|
||||
if ((hopamp->Init.Mode) == OPAMP_PGA_MODE)
|
||||
{
|
||||
assert_param(IS_OPAMP_PGA_GAIN(hopamp->Init.PgaGain));
|
||||
assert_param(IS_OPAMP_PGACONNECT(hopamp->Init.PgaConnect));
|
||||
}
|
||||
|
||||
|
||||
assert_param(IS_OPAMP_TRIMMING(hopamp->Init.UserTrimming));
|
||||
|
||||
if ((hopamp->Init.UserTrimming) == OPAMP_TRIMMING_USER)
|
||||
{
|
||||
if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
|
||||
{
|
||||
assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueP));
|
||||
assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueN));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValuePHighSpeed));
|
||||
assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueNHighSpeed));
|
||||
}
|
||||
}
|
||||
|
||||
if(hopamp->State == HAL_OPAMP_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hopamp->Lock = HAL_UNLOCKED;
|
||||
}
|
||||
|
||||
/* Call MSP init function */
|
||||
HAL_OPAMP_MspInit(hopamp);
|
||||
|
||||
/* Set operating mode */
|
||||
CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALON);
|
||||
/* In PGA mode InvertingInput is Not Applicable */
|
||||
if (hopamp->Init.Mode == OPAMP_PGA_MODE)
|
||||
{
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_PGA, \
|
||||
hopamp->Init.PowerMode | \
|
||||
hopamp->Init.Mode | \
|
||||
hopamp->Init.PgaGain | \
|
||||
hopamp->Init.PgaConnect | \
|
||||
hopamp->Init.NonInvertingInput | \
|
||||
hopamp->Init.UserTrimming);
|
||||
}
|
||||
|
||||
if (hopamp->Init.Mode == OPAMP_FOLLOWER_MODE)
|
||||
{
|
||||
/* In Follower mode InvertingInput is Not Applicable */
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_FOLLOWER, \
|
||||
hopamp->Init.PowerMode | \
|
||||
hopamp->Init.Mode | \
|
||||
hopamp->Init.NonInvertingInput | \
|
||||
hopamp->Init.UserTrimming);
|
||||
}
|
||||
|
||||
if (hopamp->Init.Mode == OPAMP_STANDALONE_MODE)
|
||||
{
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_STANDALONE, \
|
||||
hopamp->Init.PowerMode | \
|
||||
hopamp->Init.Mode | \
|
||||
hopamp->Init.InvertingInput | \
|
||||
hopamp->Init.NonInvertingInput | \
|
||||
hopamp->Init.UserTrimming);
|
||||
}
|
||||
|
||||
if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
|
||||
{
|
||||
/* Set power mode and associated calibration parameters */
|
||||
if (hopamp->Init.PowerMode != OPAMP_POWERMODE_HIGHSPEED)
|
||||
{
|
||||
/* OPAMP_POWERMODE_NORMAL */
|
||||
/* Set calibration mode (factory or user) and values for */
|
||||
/* transistors differential pair high (PMOS) and low (NMOS) for */
|
||||
/* normal mode. */
|
||||
updateotrlpotr = (((hopamp->Init.TrimmingValueP) << (OPAMP_INPUT_NONINVERTING)) \
|
||||
| (hopamp->Init.TrimmingValueN));
|
||||
MODIFY_REG(hopamp->Instance->OTR, OPAMP_OTR_TRIMOFFSETN | OPAMP_OTR_TRIMOFFSETP, updateotrlpotr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_POWERMODE_HIGHSPEED*/
|
||||
/* transistors differential pair high (PMOS) and low (NMOS) for */
|
||||
/* high speed mode. */
|
||||
updateotrlpotr = (((hopamp->Init.TrimmingValuePHighSpeed) << (OPAMP_INPUT_NONINVERTING)) \
|
||||
| (hopamp->Init.TrimmingValueNHighSpeed));
|
||||
MODIFY_REG(hopamp->Instance->HSOTR, OPAMP_OTR_TRIMOFFSETN | OPAMP_OTR_TRIMOFFSETP, updateotrlpotr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the OPAMP state*/
|
||||
if (hopamp->State == HAL_OPAMP_STATE_RESET)
|
||||
{
|
||||
/* From RESET state to READY State */
|
||||
hopamp->State = HAL_OPAMP_STATE_READY;
|
||||
}
|
||||
/* else: remain in READY or BUSY state (no update) */
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the OPAMP peripheral
|
||||
* @note Deinitialization can be performed if the OPAMP configuration is locked.
|
||||
* (the lock is SW in H7)
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* DeInit not allowed if calibration is on going */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
/* Set OPAMP_CSR register to reset value */
|
||||
/* OPAMP shall be disabled first separately */
|
||||
|
||||
CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_RESET_BITS, OPAMP_CSR_RESET_VALUE);
|
||||
|
||||
/* DeInit the low level hardware: GPIO, CLOCK and NVIC */
|
||||
HAL_OPAMP_MspDeInit(hopamp);
|
||||
|
||||
/* Update the OPAMP state*/
|
||||
hopamp->State = HAL_OPAMP_STATE_RESET;
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hopamp);
|
||||
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the OPAMP MSP.
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hopamp);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the function "HAL_OPAMP_MspInit()" must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize OPAMP MSP.
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hopamp);
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the function "HAL_OPAMP_MspDeInit()" must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup OPAMP_Exported_Functions_Group2 IO operation functions
|
||||
* @brief IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to manage the OPAMP
|
||||
start, stop and calibration actions.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Start the OPAMP.
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* Check if OPAMP locked */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
if(hopamp->State == HAL_OPAMP_STATE_READY)
|
||||
{
|
||||
/* Enable the selected opamp */
|
||||
SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
|
||||
/* Update the OPAMP state*/
|
||||
/* From HAL_OPAMP_STATE_READY to HAL_OPAMP_STATE_BUSY */
|
||||
hopamp->State = HAL_OPAMP_STATE_BUSY;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the OPAMP.
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* Check if OPAMP locked */
|
||||
/* Check if OPAMP calibration ongoing */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED) \
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
if(hopamp->State == HAL_OPAMP_STATE_BUSY)
|
||||
{
|
||||
/* Disable the selected opamp */
|
||||
CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
|
||||
/* Update the OPAMP state*/
|
||||
/* From HAL_OPAMP_STATE_BUSY to HAL_OPAMP_STATE_READY*/
|
||||
hopamp->State = HAL_OPAMP_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Run the self calibration of one OPAMP.
|
||||
* @note Calibration is performed in the mode specified in OPAMP init
|
||||
* structure (mode normal or high-speed). To perform calibration for
|
||||
* both modes, repeat this function twice after OPAMP init structure
|
||||
* accordingly updated.
|
||||
* @param hopamp handle
|
||||
* @retval Updated offset trimming values (PMOS & NMOS), user trimming is enabled
|
||||
* @retval HAL status
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
uint32_t trimmingvaluen = 0;
|
||||
uint32_t trimmingvaluep = 0;
|
||||
uint32_t delta;
|
||||
uint32_t opampmode;
|
||||
|
||||
__IO uint32_t* tmp_opamp_reg_trimming; /* Selection of register of trimming depending on power mode: OTR or HSOTR */
|
||||
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* Check if OPAMP locked */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Check if OPAMP in calibration mode and calibration not yet enable */
|
||||
if(hopamp->State == HAL_OPAMP_STATE_READY)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
|
||||
|
||||
opampmode = READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_VMSEL);
|
||||
|
||||
/* Use of standalone mode */
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_VMSEL, OPAMP_STANDALONE_MODE);
|
||||
/* user trimming values are used for offset calibration */
|
||||
SET_BIT(hopamp->Instance->CSR, OPAMP_CSR_USERTRIM);
|
||||
|
||||
/* Select trimming settings depending on power mode */
|
||||
if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
|
||||
{
|
||||
tmp_opamp_reg_trimming = &hopamp->Instance->OTR;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* high speed Mode */
|
||||
tmp_opamp_reg_trimming = &hopamp->Instance->HSOTR;
|
||||
}
|
||||
|
||||
|
||||
/* Enable calibration */
|
||||
SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON);
|
||||
|
||||
/* Force internal reference on VP */
|
||||
SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_FORCEVP);
|
||||
|
||||
/* 1st calibration - N */
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_90VDDA);
|
||||
|
||||
/* Enable the selected opamp */
|
||||
SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
|
||||
/* Init trimming counter */
|
||||
/* Medium value */
|
||||
trimmingvaluen = 16;
|
||||
delta = 8;
|
||||
|
||||
while (delta != 0)
|
||||
{
|
||||
/* Set candidate trimming */
|
||||
/* OPAMP_POWERMODE_NORMAL */
|
||||
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != RESET)
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is HIGH try higher trimming */
|
||||
trimmingvaluen += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is LOW try lower trimming */
|
||||
trimmingvaluen -= delta;
|
||||
}
|
||||
/* Divide range by 2 to continue dichotomy sweep */
|
||||
delta >>= 1;
|
||||
}
|
||||
|
||||
/* Still need to check if right calibration is current value or one step below */
|
||||
/* Indeed the first value that causes the OUTCAL bit to change from 1 to 0 */
|
||||
|
||||
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if ((READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT)) != 0)
|
||||
{
|
||||
/* Trimming value is actually one value more */
|
||||
trimmingvaluen++;
|
||||
/* Set right trimming */
|
||||
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
|
||||
}
|
||||
|
||||
/* 2nd calibration - P */
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_10VDDA);
|
||||
|
||||
/* Init trimming counter */
|
||||
/* Medium value */
|
||||
trimmingvaluep = 16;
|
||||
delta = 8;
|
||||
|
||||
while (delta != 0)
|
||||
{
|
||||
/* Set candidate trimming */
|
||||
/* OPAMP_POWERMODE_NORMAL */
|
||||
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT)!= RESET)
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is HIGH try higher trimming */
|
||||
trimmingvaluep += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is LOW try lower trimming */
|
||||
trimmingvaluep -= delta;
|
||||
}
|
||||
|
||||
/* Divide range by 2 to continue dichotomy sweep */
|
||||
delta >>= 1;
|
||||
}
|
||||
|
||||
/* Still need to check if right calibration is current value or one step below */
|
||||
/* Indeed the first value that causes the OUTCAL bit to change from 1 to 0 */
|
||||
/* Set candidate trimming */
|
||||
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != RESET)
|
||||
{
|
||||
/* Trimming value is actually one value more */
|
||||
trimmingvaluep++;
|
||||
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
|
||||
}
|
||||
|
||||
/* Disable calibration & set normal mode (operating mode) */
|
||||
CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON);
|
||||
|
||||
/* Disable the OPAMP */
|
||||
CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
|
||||
/* Set operating mode back */
|
||||
CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_FORCEVP);
|
||||
|
||||
/* Self calibration is successful */
|
||||
/* Store calibration(user trimming) results in init structure. */
|
||||
|
||||
/* Set user trimming mode */
|
||||
hopamp->Init.UserTrimming = OPAMP_TRIMMING_USER;
|
||||
|
||||
/* Affect calibration parameters depending on mode normal/high speed */
|
||||
if (hopamp->Init.PowerMode != OPAMP_POWERMODE_HIGHSPEED)
|
||||
{
|
||||
/* Write calibration result N */
|
||||
hopamp->Init.TrimmingValueN = trimmingvaluen;
|
||||
/* Write calibration result P */
|
||||
hopamp->Init.TrimmingValueP = trimmingvaluep;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Write calibration result N */
|
||||
hopamp->Init.TrimmingValueNHighSpeed = trimmingvaluen;
|
||||
/* Write calibration result P */
|
||||
hopamp->Init.TrimmingValuePHighSpeed = trimmingvaluep;
|
||||
}
|
||||
/* Restore OPAMP mode after calibration */
|
||||
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_VMSEL, opampmode);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* OPAMP can not be calibrated from this mode */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup OPAMP_Exported_Functions_Group3 Peripheral Control functions
|
||||
* @brief Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the OPAMP data
|
||||
transfers.
|
||||
|
||||
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Lock the selected OPAMP configuration.
|
||||
* @note On STM32H7, HAL OPAMP lock is software lock only (in
|
||||
* contrast of hardware lock available on some other STM32
|
||||
* devices)
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* Check if OPAMP locked */
|
||||
/* OPAMP can be locked when enabled and running in normal mode */
|
||||
/* It is meaningless otherwise */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_RESET) \
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_READY) \
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)\
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
|
||||
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
/* OPAMP state changed to locked */
|
||||
hopamp->State = HAL_OPAMP_STATE_BUSYLOCKED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the OPAMP factory trimming value.
|
||||
* @note On STM32H7 OPAMP, user can retrieve factory trimming if
|
||||
* OPAMP has never been set to user trimming before.
|
||||
* Therefore, this function must be called when OPAMP init
|
||||
* parameter "UserTrimming" is set to trimming factory,
|
||||
* and before OPAMP calibration (function
|
||||
* "HAL_OPAMP_SelfCalibrate()").
|
||||
* Otherwise, factory trimming value cannot be retrieved and
|
||||
* error status is returned.
|
||||
* @param hopamp : OPAMP handle
|
||||
* @param trimmingoffset : Trimming offset (P or N)
|
||||
* This parameter must be a value of @ref OPAMP_FactoryTrimming
|
||||
* @note Calibration parameter retrieved is corresponding to the mode
|
||||
* specified in OPAMP init structure (mode normal or high-speed).
|
||||
* To retrieve calibration parameters for both modes, repeat this
|
||||
* function after OPAMP init structure accordingly updated.
|
||||
* @retval Trimming value (P or N): range: 0->31
|
||||
* or OPAMP_FACTORYTRIMMING_DUMMY if trimming value is not available
|
||||
*
|
||||
*/
|
||||
|
||||
HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset)
|
||||
{
|
||||
HAL_OPAMP_TrimmingValueTypeDef trimmingvalue;
|
||||
__IO uint32_t* tmp_opamp_reg_trimming; /* Selection of register of trimming depending on power mode: OTR or LPOTR */
|
||||
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* Value can be retrieved in HAL_OPAMP_STATE_READY state */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_RESET) \
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_BUSY) \
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)\
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
|
||||
{
|
||||
return OPAMP_FACTORYTRIMMING_DUMMY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
assert_param(IS_OPAMP_FACTORYTRIMMING(trimmingoffset));
|
||||
assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
|
||||
|
||||
/* Check the trimming mode */
|
||||
if (READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_USERTRIM)!= RESET)
|
||||
{
|
||||
/* This function must called when OPAMP init parameter "UserTrimming" */
|
||||
/* is set to trimming factory, and before OPAMP calibration (function */
|
||||
/* "HAL_OPAMP_SelfCalibrate()"). */
|
||||
/* Otherwise, factory trimming value cannot be retrieved and error */
|
||||
/* status is returned. */
|
||||
trimmingvalue = OPAMP_FACTORYTRIMMING_DUMMY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Select trimming settings depending on power mode */
|
||||
if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
|
||||
{
|
||||
tmp_opamp_reg_trimming = &hopamp->Instance->OTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_opamp_reg_trimming = &hopamp->Instance->HSOTR;
|
||||
}
|
||||
|
||||
/* Get factory trimming */
|
||||
if (trimmingoffset == OPAMP_FACTORYTRIMMING_P)
|
||||
{
|
||||
/* OPAMP_FACTORYTRIMMING_P */
|
||||
trimmingvalue = ((*tmp_opamp_reg_trimming) & OPAMP_OTR_TRIMOFFSETP) >> OPAMP_INPUT_NONINVERTING;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_FACTORYTRIMMING_N */
|
||||
trimmingvalue = (*tmp_opamp_reg_trimming) & OPAMP_OTR_TRIMOFFSETN;
|
||||
}
|
||||
}
|
||||
}
|
||||
return trimmingvalue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup OPAMP_Exported_Functions_Group4 Peripheral State functions
|
||||
* @brief Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral State functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection permits to get in run-time the status of the peripheral.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the OPAMP handle state.
|
||||
* @param hopamp : OPAMP handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp)
|
||||
{
|
||||
/* Check the OPAMP handle allocation */
|
||||
if(hopamp == NULL)
|
||||
{
|
||||
return HAL_OPAMP_STATE_RESET;
|
||||
}
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
/* Return OPAMP handle state */
|
||||
return hopamp->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+450
@@ -0,0 +1,450 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_opamp_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief Extended OPAMP HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the operational amplifier(s)(OPAMP1, OPAMP2 etc)
|
||||
* peripheral:
|
||||
* + Extended Initialization and de-initialization functions
|
||||
* + Extended Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup OPAMPEx OPAMPEx
|
||||
* @brief OPAMP Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_OPAMP_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup OPAMPEx_Exported_Functions OPAMP Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup OPAMPEx_Exported_Functions_Group1 Extended Input and Output operation functions
|
||||
* @brief Extended operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended IO operation functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
(+) OPAMP Self calibration.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Run the self calibration of 2 OPAMPs in parallel.
|
||||
* @note Trimming values (PMOS & NMOS) are updated and user trimming is
|
||||
* enabled is calibration is successful.
|
||||
* @note Calibration is performed in the mode specified in OPAMP init
|
||||
* structure (mode normal or low power). To perform calibration for
|
||||
* both modes, repeat this function twice after OPAMP init structure
|
||||
* accordingly updated.
|
||||
* @param hopamp1 handle
|
||||
* @param hopamp2 handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_OPAMPEx_SelfCalibrateAll(OPAMP_HandleTypeDef *hopamp1, OPAMP_HandleTypeDef *hopamp2)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
uint32_t trimmingvaluen1 = 0;
|
||||
uint32_t trimmingvaluep1 = 0;
|
||||
uint32_t trimmingvaluen2 = 0;
|
||||
uint32_t trimmingvaluep2 = 0;
|
||||
|
||||
/* Selection of register of trimming depending on power mode: OTR or HSOTR */
|
||||
__IO uint32_t* tmp_opamp1_reg_trimming;
|
||||
__IO uint32_t* tmp_opamp2_reg_trimming;
|
||||
|
||||
uint32_t delta;
|
||||
uint32_t opampmode1;
|
||||
uint32_t opampmode2;
|
||||
|
||||
if((hopamp1 == NULL) || (hopamp1->State == HAL_OPAMP_STATE_BUSYLOCKED) || \
|
||||
(hopamp2 == NULL) || (hopamp2->State == HAL_OPAMP_STATE_BUSYLOCKED))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check if OPAMP in calibration mode and calibration not yet enable */
|
||||
if((hopamp1->State == HAL_OPAMP_STATE_READY) && (hopamp2->State == HAL_OPAMP_STATE_READY))
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp1->Instance));
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp2->Instance));
|
||||
|
||||
assert_param(IS_OPAMP_POWERMODE(hopamp1->Init.PowerMode));
|
||||
assert_param(IS_OPAMP_POWERMODE(hopamp2->Init.PowerMode));
|
||||
|
||||
/* Set Calibration mode */
|
||||
/* Non-inverting input connected to calibration reference voltage. */
|
||||
SET_BIT(hopamp1->Instance->CSR, OPAMP_CSR_FORCEVP);
|
||||
SET_BIT(hopamp2->Instance->CSR, OPAMP_CSR_FORCEVP);
|
||||
|
||||
/* Save OPAMP mode */
|
||||
opampmode1 = READ_BIT(hopamp1->Instance->CSR,OPAMP_CSR_VMSEL);
|
||||
opampmode2 = READ_BIT(hopamp2->Instance->CSR,OPAMP_CSR_VMSEL);
|
||||
|
||||
/* Use of standalone mode */
|
||||
MODIFY_REG(hopamp1->Instance->CSR, OPAMP_CSR_VMSEL, OPAMP_STANDALONE_MODE);
|
||||
MODIFY_REG(hopamp2->Instance->CSR, OPAMP_CSR_VMSEL, OPAMP_STANDALONE_MODE);
|
||||
|
||||
/* user trimming values are used for offset calibration */
|
||||
SET_BIT(hopamp1->Instance->CSR, OPAMP_CSR_USERTRIM);
|
||||
SET_BIT(hopamp2->Instance->CSR, OPAMP_CSR_USERTRIM);
|
||||
|
||||
/* Select trimming settings depending on power mode */
|
||||
if (hopamp1->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
|
||||
{
|
||||
tmp_opamp1_reg_trimming = &OPAMP1->OTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_opamp1_reg_trimming = &OPAMP1->HSOTR;
|
||||
}
|
||||
|
||||
if (hopamp2->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
|
||||
{
|
||||
tmp_opamp2_reg_trimming = &OPAMP2->OTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_opamp2_reg_trimming = &OPAMP2->HSOTR;
|
||||
}
|
||||
|
||||
/* Enable calibration */
|
||||
SET_BIT (hopamp1->Instance->CSR, OPAMP_CSR_CALON);
|
||||
SET_BIT (hopamp2->Instance->CSR, OPAMP_CSR_CALON);
|
||||
|
||||
/* 1st calibration - N */
|
||||
/* Select 90U% VREF */
|
||||
MODIFY_REG(hopamp1->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_90VDDA);
|
||||
MODIFY_REG(hopamp2->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_90VDDA);
|
||||
|
||||
/* Enable the selected opamp */
|
||||
SET_BIT (hopamp1->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
SET_BIT (hopamp2->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
|
||||
/* Init trimming counter */
|
||||
/* Medium value */
|
||||
trimmingvaluen1 = 16;
|
||||
trimmingvaluen2 = 16;
|
||||
delta = 8;
|
||||
|
||||
while (delta != 0)
|
||||
{
|
||||
/* Set candidate trimming */
|
||||
/* OPAMP_POWERMODE_NORMAL */
|
||||
MODIFY_REG(*tmp_opamp1_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen1);
|
||||
MODIFY_REG(*tmp_opamp2_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen2);
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if (READ_BIT(hopamp1->Instance->CSR, OPAMP_CSR_CALOUT)!= RESET)
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is Low try higher trimming */
|
||||
trimmingvaluen1 += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is High try lower trimming */
|
||||
trimmingvaluen1 -= delta;
|
||||
}
|
||||
|
||||
if (READ_BIT(hopamp2->Instance->CSR, OPAMP_CSR_CALOUT)!= RESET)
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is Low try higher trimming */
|
||||
trimmingvaluen2 += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is High try lower trimming */
|
||||
trimmingvaluen2 -= delta;
|
||||
}
|
||||
/* Divide range by 2 to continue dichotomy sweep */
|
||||
delta >>= 1;
|
||||
}
|
||||
|
||||
/* Still need to check if right calibration is current value or one step below */
|
||||
/* Indeed the first value that causes the OUTCAL bit to change from 0 to 1 */
|
||||
/* Set candidate trimming */
|
||||
MODIFY_REG(*tmp_opamp1_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen1);
|
||||
MODIFY_REG(*tmp_opamp2_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen2);
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if ((READ_BIT(hopamp1->Instance->CSR, OPAMP_CSR_CALOUT)) != 0)
|
||||
{
|
||||
/* Trimming value is actually one value more */
|
||||
trimmingvaluen1++;
|
||||
MODIFY_REG(*tmp_opamp1_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen1);
|
||||
}
|
||||
|
||||
if ((READ_BIT(hopamp2->Instance->CSR, OPAMP_CSR_CALOUT)) != 0)
|
||||
{
|
||||
/* Trimming value is actually one value more */
|
||||
trimmingvaluen2++;
|
||||
MODIFY_REG(*tmp_opamp2_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen2);
|
||||
}
|
||||
|
||||
/* 2nd calibration - P */
|
||||
/* Select 10U% VREF */
|
||||
MODIFY_REG(hopamp1->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_10VDDA);
|
||||
MODIFY_REG(hopamp2->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_10VDDA);
|
||||
|
||||
/* Init trimming counter */
|
||||
/* Medium value */
|
||||
trimmingvaluep1 = 16;
|
||||
trimmingvaluep2 = 16;
|
||||
delta = 8;
|
||||
|
||||
while (delta != 0)
|
||||
{
|
||||
/* Set candidate trimming */
|
||||
/* OPAMP_POWERMODE_NORMAL */
|
||||
MODIFY_REG(*tmp_opamp1_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep1<<OPAMP_INPUT_NONINVERTING));
|
||||
MODIFY_REG(*tmp_opamp2_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep2<<OPAMP_INPUT_NONINVERTING));
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if (READ_BIT(hopamp1->Instance->CSR, OPAMP_CSR_CALOUT)!= RESET)
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is Low try higher trimming */
|
||||
trimmingvaluep1 += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is HIGH try lower trimming */
|
||||
trimmingvaluep1 -= delta;
|
||||
}
|
||||
|
||||
if (READ_BIT(hopamp2->Instance->CSR, OPAMP_CSR_CALOUT)!= RESET)
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is Low try higher trimming */
|
||||
trimmingvaluep2 += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OPAMP_CSR_CALOUT is High try lower trimming */
|
||||
trimmingvaluep2 -= delta;
|
||||
}
|
||||
/* Divide range by 2 to continue dichotomy sweep */
|
||||
delta >>= 1;
|
||||
}
|
||||
|
||||
/* Still need to check if right calibration is current value or one step below */
|
||||
/* Indeed the first value that causes the OUTCAL bit to change from 1 to 0 */
|
||||
/* Set candidate trimming */
|
||||
MODIFY_REG(*tmp_opamp1_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep1<<OPAMP_INPUT_NONINVERTING));
|
||||
MODIFY_REG(*tmp_opamp2_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep2<<OPAMP_INPUT_NONINVERTING));
|
||||
|
||||
/* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */
|
||||
/* Offset trim time: during calibration, minimum time needed between */
|
||||
/* two steps to have 1 mV accuracy */
|
||||
HAL_Delay(OPAMP_TRIMMING_DELAY);
|
||||
|
||||
if (READ_BIT(hopamp1->Instance->CSR, OPAMP_CSR_CALOUT)!= RESET)
|
||||
{
|
||||
/* Trimming value is actually one value more */
|
||||
trimmingvaluep1++;
|
||||
MODIFY_REG(*tmp_opamp1_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep1<<OPAMP_INPUT_NONINVERTING));
|
||||
}
|
||||
|
||||
if (READ_BIT(hopamp2->Instance->CSR, OPAMP_CSR_CALOUT)!= RESET)
|
||||
{
|
||||
/* Trimming value is actually one value more */
|
||||
trimmingvaluep2++;
|
||||
MODIFY_REG(*tmp_opamp2_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep2<<OPAMP_INPUT_NONINVERTING));
|
||||
}
|
||||
|
||||
/* Disable calibration & set normal mode (operating mode) */
|
||||
CLEAR_BIT (hopamp1->Instance->CSR, OPAMP_CSR_CALON);
|
||||
CLEAR_BIT (hopamp2->Instance->CSR, OPAMP_CSR_CALON);
|
||||
|
||||
/* Disable the OPAMPs */
|
||||
CLEAR_BIT (hopamp1->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
CLEAR_BIT (hopamp2->Instance->CSR, OPAMP_CSR_OPAMPxEN);
|
||||
|
||||
/* Self calibration is successful */
|
||||
/* Store calibration (user trimming) results in init structure. */
|
||||
|
||||
/* Set user trimming mode */
|
||||
hopamp1->Init.UserTrimming = OPAMP_TRIMMING_USER;
|
||||
hopamp2->Init.UserTrimming = OPAMP_TRIMMING_USER;
|
||||
|
||||
/* Affect calibration parameters depending on mode normal/high speed */
|
||||
if (hopamp1->Init.PowerMode != OPAMP_POWERMODE_HIGHSPEED)
|
||||
{
|
||||
/* Write calibration result N */
|
||||
hopamp1->Init.TrimmingValueN = trimmingvaluen1;
|
||||
/* Write calibration result P */
|
||||
hopamp1->Init.TrimmingValueP = trimmingvaluep1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Write calibration result N */
|
||||
hopamp1->Init.TrimmingValueNHighSpeed = trimmingvaluen1;
|
||||
/* Write calibration result P */
|
||||
hopamp1->Init.TrimmingValuePHighSpeed = trimmingvaluep1;
|
||||
}
|
||||
|
||||
if (hopamp2->Init.PowerMode != OPAMP_POWERMODE_HIGHSPEED)
|
||||
{
|
||||
/* Write calibration result N */
|
||||
hopamp2->Init.TrimmingValueN = trimmingvaluen2;
|
||||
/* Write calibration result P */
|
||||
hopamp2->Init.TrimmingValueP = trimmingvaluep2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Write calibration result N */
|
||||
hopamp2->Init.TrimmingValueNHighSpeed = trimmingvaluen2;
|
||||
/* Write calibration result P */
|
||||
hopamp2->Init.TrimmingValuePHighSpeed = trimmingvaluep2;
|
||||
|
||||
}
|
||||
/* Update OPAMP state */
|
||||
hopamp1->State = HAL_OPAMP_STATE_READY;
|
||||
hopamp2->State = HAL_OPAMP_STATE_READY;
|
||||
|
||||
/* Restore OPAMP mode after calibration */
|
||||
MODIFY_REG(hopamp1->Instance->CSR, OPAMP_CSR_VMSEL, opampmode1);
|
||||
MODIFY_REG(hopamp2->Instance->CSR, OPAMP_CSR_VMSEL, opampmode2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* At least one OPAMP can not be calibrated */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup OPAMPEx_Exported_Functions_Group2 Peripheral Control functions
|
||||
* @brief Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
(+) OPAMP unlock.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Unlock the selected OPAMP configuration.
|
||||
* @note This function must be called only when OPAMP is in state "locked".
|
||||
* @param hopamp: OPAMP handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_OPAMPEx_Unlock(OPAMP_HandleTypeDef* hopamp)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* Check if OPAMP locked */
|
||||
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_RESET)
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_READY)
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
|
||||
|| (hopamp->State == HAL_OPAMP_STATE_BUSY))
|
||||
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
/* OPAMP state changed to locked */
|
||||
hopamp->State = HAL_OPAMP_STATE_BUSY;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1350
File diff suppressed because it is too large
Load Diff
+324
@@ -0,0 +1,324 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_pcd_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief PCD HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the USB Peripheral Controller:
|
||||
* + Extended features functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PCDEx PCDEx
|
||||
* @brief PCD Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
|
||||
* @brief PCDEx control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended features functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Update FIFO configuration
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set Tx FIFO.
|
||||
* @param hpcd: PCD handle
|
||||
* @param fifo: The number of Tx fifo
|
||||
* @param size: Fifo size
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint32_t Tx_Offset = 0;
|
||||
|
||||
/* TXn min size = 16 words. (n : Transmit FIFO index)
|
||||
When a TxFIFO is not used, the Configuration should be as follows:
|
||||
case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
|
||||
--> Txm can use the space allocated for Txn.
|
||||
case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
|
||||
--> Txn should be configured with the minimum space of 16 words
|
||||
The FIFO is used optimally when used TxFIFOs are allocated in the top
|
||||
of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
|
||||
When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
|
||||
|
||||
Tx_Offset = hpcd->Instance->GRXFSIZ;
|
||||
|
||||
if(fifo == 0)
|
||||
{
|
||||
hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((uint32_t)size << 16) | Tx_Offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
|
||||
for (i = 0; i < (fifo - 1); i++)
|
||||
{
|
||||
Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
|
||||
}
|
||||
|
||||
/* Multiply Tx_Size by 2 to get higher performance */
|
||||
hpcd->Instance->DIEPTXF[fifo - 1] = (uint32_t)(((uint32_t)size << 16) | Tx_Offset);
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Rx FIFO.
|
||||
* @param hpcd: PCD handle
|
||||
* @param size: Size of Rx fifo
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
|
||||
{
|
||||
hpcd->Instance->GRXFSIZ = size;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Activate LPM Feature.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||
|
||||
hpcd->lpm_active = ENABLE;
|
||||
hpcd->LPM_State = LPM_L0;
|
||||
USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM;
|
||||
USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-activate LPM feature.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||
|
||||
hpcd->lpm_active = DISABLE;
|
||||
USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM;
|
||||
USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
#if defined (USB_OTG_GCCFG_BCDEN)
|
||||
/**
|
||||
* @brief Handle Battery Charging Process.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
|
||||
/* Start BCD When device is connected */
|
||||
if (USBx_DEVICE->DCTL & USB_OTG_DCTL_SDIS)
|
||||
{
|
||||
/* Enable DCD : Data Contact Detect */
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_DCDEN;
|
||||
|
||||
/* Wait Detect flag or a timeout is happen*/
|
||||
while ((USBx->GCCFG & USB_OTG_GCCFG_DCDET) == 0)
|
||||
{
|
||||
/* Check for the Timeout */
|
||||
if((HAL_GetTick() - tickstart ) > 1000)
|
||||
{
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_ERROR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Right response got */
|
||||
HAL_Delay(100);
|
||||
|
||||
/* Check Detect flag*/
|
||||
if (USBx->GCCFG & USB_OTG_GCCFG_DCDET)
|
||||
{
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CONTACT_DETECTION);
|
||||
}
|
||||
|
||||
/*Primary detection: checks if connected to Standard Downstream Port
|
||||
(without charging capability) */
|
||||
USBx->GCCFG &=~ USB_OTG_GCCFG_DCDEN;
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_PDEN;
|
||||
HAL_Delay(100);
|
||||
|
||||
if (!(USBx->GCCFG & USB_OTG_GCCFG_PDET))
|
||||
{
|
||||
/* Case of Standard Downstream Port */
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* start secondary detection to check connection to Charging Downstream
|
||||
Port or Dedicated Charging Port */
|
||||
USBx->GCCFG &=~ USB_OTG_GCCFG_PDEN;
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_SDEN;
|
||||
HAL_Delay(100);
|
||||
|
||||
if ((USBx->GCCFG) & USB_OTG_GCCFG_SDET)
|
||||
{
|
||||
/* case Dedicated Charging Port */
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* case Charging Downstream Port */
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT);
|
||||
}
|
||||
}
|
||||
/* Battery Charging capability discovery finished */
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Activate BatteryCharging feature.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||
|
||||
hpcd->battery_charging_active = ENABLE;
|
||||
USBx->GCCFG |= (USB_OTG_GCCFG_BCDEN);
|
||||
|
||||
/* Enable DCD : Data Contact Detect */
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_DCDEN;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deactivate BatteryCharging feature.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||
hpcd->battery_charging_active = DISABLE;
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_BCDEN);
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send BatteryCharging message to user layer callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @param msg: LPM message
|
||||
* @retval HAL status
|
||||
*/
|
||||
__weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hpcd);
|
||||
UNUSED(msg);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_PCDEx_BCD_Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
#endif /* USB_OTG_GCCFG_BCDEN */
|
||||
|
||||
/**
|
||||
* @brief Send LPM message to user layer callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @param msg: LPM message
|
||||
* @retval HAL status
|
||||
*/
|
||||
__weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hpcd);
|
||||
UNUSED(msg);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_PCDEx_LPM_Callback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+610
@@ -0,0 +1,610 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_pwr.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @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
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_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_MODE_EVT ((uint32_t)0x00020000U)
|
||||
#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_Exported_Functions PWR Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PWR_Exported_Functions_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 the Power Controller (PWR) APB1 interface clock using the
|
||||
__HAL_RCC_PWR_CLK_ENABLE() macro.
|
||||
(+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the HAL PWR peripheral registers to their default reset values.
|
||||
* @note This functionality is not available in this product.
|
||||
* The prototype is kept just to maintain compatibility with other products.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DeInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable 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_EnableBkUpAccess(void)
|
||||
{
|
||||
/* Enable access to RTC and backup registers */
|
||||
SET_BIT(PWR->CR1, PWR_CR1_DBP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable 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_Exported_Functions_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[7:0] bits in the PWR_CR1 register).
|
||||
(+) A PVDO flag is available to indicate if VDD is higher or lower
|
||||
than the PVD threshold. This event is internally connected to the EXTI
|
||||
line 16 to generate an interrupt if enabled.
|
||||
It is configurable through __HAL_PWR_PVD_EXTI_ENABLE_IT() macro.
|
||||
(+) The PVD is stopped in Standby mode.
|
||||
|
||||
*** Wake-up pin configuration ***
|
||||
================================
|
||||
[..]
|
||||
(+) Wake-up pin is used to wake up the system from Standby mode.
|
||||
The pin pull is configurable through the WKUPEPR register to be in No pull-up, Pull-up and Pull-down.
|
||||
The pin polarity is configurable through the WKUPEPR register to be active on rising or falling edges.
|
||||
(+) There are up to six Wake-up pin in the STM32H7 devices family.
|
||||
|
||||
*** Low Power modes configuration ***
|
||||
=====================================
|
||||
[..]
|
||||
The device present 3 principles low-power modes features:
|
||||
(+) SLEEP mode: Cortex-M7 core stopped and D1, D2 and D3 peripherals kept running.
|
||||
(+) STOP mode: all clocks are stoppedand the regulator running in main or low power mode.
|
||||
(+) STANDBY mode: D1, D2 and D3 domains enter DSTANDBY mode and the VCORE supply
|
||||
regulator is powered off.
|
||||
|
||||
*** SLEEP mode ***
|
||||
==================
|
||||
[..]
|
||||
(+) Entry:
|
||||
The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(Regulator, SLEEPEntry)
|
||||
function.
|
||||
|
||||
(++) 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 STM32H7 family
|
||||
and is kept as parameter just to maintain compatibility with the
|
||||
lower power families (STM32L).
|
||||
(+) Exit:
|
||||
Any peripheral interrupt acknowledged by the nested vectored interrupt
|
||||
controller (NVIC) can wake up the device from Sleep mode.
|
||||
|
||||
*** STOP mode ***
|
||||
=================
|
||||
[..]
|
||||
In system Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI,
|
||||
and the HSE RC oscillators are disabled. Internal SRAM and register contents
|
||||
are preserved.
|
||||
The voltage regulator can be configured either in normal or low-power mode.
|
||||
To minimize the consumption In Stop mode, FLASH can be powered off before
|
||||
entering the Stop mode using the HAL_PWREx_EnableFlashPowerDown() function.
|
||||
It can be switched on again by software after exiting the Stop mode using
|
||||
the HAL_PWREx_DisableFlashPowerDown() function.
|
||||
|
||||
(+) Entry:
|
||||
The Stop mode is entered using the HAL_PWR_EnterSTOPMode(Regulator, 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:
|
||||
Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
|
||||
|
||||
*** STANDBY mode ***
|
||||
====================
|
||||
[..]
|
||||
(+)
|
||||
The system Standby mode allows to achieve the lowest power consumption. It is based
|
||||
on the Cortex-M7 deep sleep mode, with the voltage regulator disabled.
|
||||
The system is consequently powered off. The PLL, 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.
|
||||
[..]
|
||||
The voltage regulator is OFF.
|
||||
(++) Entry:
|
||||
(+++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function.
|
||||
(++) Exit:
|
||||
(+++) WKUP pin rising or falling edge, RTC alarm (Alarm A and Alarm B), RTC
|
||||
wakeup, tamper event, time stamp event, external reset in NRST pin, IWDG reset.
|
||||
|
||||
*** Auto-wakeup (AWU) from low-power mode ***
|
||||
=============================================
|
||||
[..]
|
||||
(+) The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
|
||||
Wakeup event, a tamper event or a time-stamp event, without depending on
|
||||
an external interrupt (Auto-wakeup mode).
|
||||
(+) RTC auto-wakeup (AWU) from the STOP and STANDBY modes
|
||||
(++) To wake up from the Stop mode with an RTC alarm event, it is necessary to
|
||||
configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.
|
||||
(++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
|
||||
is necessary to configure the RTC to detect the tamper or time stamp event using the
|
||||
HAL_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_SetTamper_IT() functions.
|
||||
(++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to
|
||||
configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer_IT() function.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure 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 */
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_EVENT();
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_IT();
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
|
||||
|
||||
/* Configure interrupt mode */
|
||||
if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_IT();
|
||||
}
|
||||
|
||||
/* Configure event mode */
|
||||
if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_EVENT();
|
||||
}
|
||||
|
||||
/* Configure the edge */
|
||||
if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
|
||||
}
|
||||
|
||||
if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable 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 Disable 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 values where
|
||||
* the user can explicitly states the enabled pin and the chosen polarity.
|
||||
* @arg PWR_WAKEUP_PIN1_HIGH or PWR_WAKEUP_PIN1_LOW
|
||||
* @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.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)
|
||||
{
|
||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity));
|
||||
|
||||
/* Enable and Specify the Wake-Up pin polarity and the pull configuration
|
||||
for the event detection (rising or falling edge) */
|
||||
MODIFY_REG(PWR->WKUPEPR, PWR_EWUP_MASK, WakeUpPinPolarity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable 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));
|
||||
|
||||
CLEAR_BIT(PWR->WKUPEPR, WakeUpPinx);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter CM7 core to Sleep mode.
|
||||
* @param Regulator: Specifies the regulator state in SLEEP mode.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON
|
||||
* @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON
|
||||
* @note This parameter is not used for the STM32H7 family and is kept as parameter
|
||||
* just to maintain compatibility with the lower power families.
|
||||
* @param SLEEPEntry: Specifies if SLEEP mode in entered with WFI or WFE instruction.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
|
||||
* @arg PWR_SLEEPENTRY_WFE: enter SLEEP 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));
|
||||
|
||||
/* Clear SLEEPDEEP bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||
|
||||
/* Select SLEEP mode entry */
|
||||
if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
|
||||
{
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Request Wait For Event */
|
||||
__SEV();
|
||||
__WFE();
|
||||
__WFE();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter the system to STOP mode.
|
||||
* @note In System Stop mode, all I/O pins keep the same state as in Run mode.
|
||||
* @note When exiting System Stop mode by issuing an interrupt or a wakeup event,
|
||||
* the HSI RC oscillator is selected as default system wakeup clock.
|
||||
* @note In System STOP mode, when the voltage regulator operates in low power mode,
|
||||
* an additional startup delay is incurred when the system is waking up.
|
||||
* 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 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 Stop mode in entered with WFI or WFE instruction.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction
|
||||
* @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
||||
{
|
||||
uint32_t tmpreg = 0;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PWR_REGULATOR(Regulator));
|
||||
assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
|
||||
|
||||
/* Select the regulator state in Stop mode */
|
||||
tmpreg = PWR->CR1;
|
||||
/* Clear PDDS and LPDS bits */
|
||||
tmpreg &= (uint32_t)~(PWR_CR1_LPDS);
|
||||
|
||||
/* Set LPDS bit according to Regulator value */
|
||||
tmpreg |= Regulator;
|
||||
|
||||
/* Store the new value */
|
||||
PWR->CR1 = tmpreg;
|
||||
|
||||
/* Keep DSTOP mode when D1 domain enters Deepsleep */
|
||||
CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D1);
|
||||
|
||||
/* Keep DSTOP mode when D2 domain enters Deepsleep */
|
||||
CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D2);
|
||||
|
||||
/* Keep DSTOP mode when D3 domain enters Deepsleep */
|
||||
CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D3);
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
/* Ensure that all instructions done before entering STOP mode */
|
||||
__DSB();
|
||||
__ISB();
|
||||
|
||||
/* Select Stop mode entry */
|
||||
if(STOPEntry == PWR_STOPENTRY_WFI)
|
||||
{
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Request Wait For Event */
|
||||
__SEV();
|
||||
__WFE();
|
||||
__WFE();
|
||||
}
|
||||
/* Reset SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter the system to STANDBY mode.
|
||||
* @note The system enters Standby mode only when the D1, D2 and D3 domains are in DStandby.
|
||||
* @note When the System exit STANDBY mode by issuing an interrupt or a wakeup event,
|
||||
* the HSI RC oscillator is selected as system clock.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_EnterSTANDBYMode(void)
|
||||
{
|
||||
/* Keep DSTANDBY mode when D1 domain enters Deepsleep */
|
||||
SET_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D1);
|
||||
|
||||
/* Keep DSTANDBY mode when D2 domain enters Deepsleep */
|
||||
SET_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D2);
|
||||
|
||||
/* Keep DSTANDBY mode when D3 domain enters Deepsleep */
|
||||
SET_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D3);
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
/* This option is used to ensure that store operations are completed */
|
||||
#if defined ( __CC_ARM)
|
||||
__force_stores();
|
||||
#endif
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Indicate 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 SLEEP 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)
|
||||
{
|
||||
/* Set SLEEPONEXIT bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disable 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 SLEEP mode when an interruption handling is over.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableSleepOnExit(void)
|
||||
{
|
||||
/* Clear SLEEPONEXIT bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable 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)
|
||||
{
|
||||
/* Set SEVONPEND bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable 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)
|
||||
{
|
||||
/* Clear SEVONPEND bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles the PWR PVD interrupt request.
|
||||
* @note This API should be called under the PVD_IRQHandler().
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_PVD_IRQHandler(void)
|
||||
{
|
||||
/* PVD EXTI line interrupt detected */
|
||||
if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
|
||||
{
|
||||
/* PWR PVD interrupt user callback */
|
||||
HAL_PWR_PVDCallback();
|
||||
|
||||
/* Clear PWR EXTI pending bit */
|
||||
__HAL_PWR_PVD_EXTI_CLEAR_FLAG();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1293
File diff suppressed because it is too large
Load Diff
+2207
File diff suppressed because it is too large
Load Diff
+1358
File diff suppressed because it is too large
Load Diff
+4039
File diff suppressed because it is too large
Load Diff
+475
@@ -0,0 +1,475 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_rng.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief RNG HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Random Number Generator (RNG) peripheral:
|
||||
* + Initialization/de-initialization functions
|
||||
* + Peripheral Control functions
|
||||
* + Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The RNG HAL driver can be used as follows:
|
||||
|
||||
(#) Enable the RNG controller clock using __HAL_RCC_RNG_CLK_ENABLE() macro
|
||||
in HAL_RNG_MspInit().
|
||||
(#) Activate the RNG peripheral using HAL_RNG_Init() function.
|
||||
(#) Wait until the 32 bit Random Number Generator contains a valid
|
||||
random data using (polling/interrupt) mode.
|
||||
(#) Get the 32 bit random number using HAL_RNG_GenerateRandomNumber() function.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup RNG
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup RNG_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
#define RNG_TIMEOUT_VALUE 2U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions prototypes ----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup RNG_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup RNG_Exported_Functions_Group1
|
||||
* @brief Initialization and de-initialization functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Initialize the RNG according to the specified parameters
|
||||
in the RNG_InitTypeDef and create the associated handle
|
||||
(+) DeInitialize the RNG peripheral
|
||||
(+) Initialize the RNG MSP
|
||||
(+) DeInitialize RNG MSP
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the RNG peripheral and creates the associated handle.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
/* Check the RNG handle allocation */
|
||||
if(hrng == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RNG_ALL_INSTANCE(hrng->Instance));
|
||||
assert_param(IS_RNG_CED(hrng->Init.ClockErrorDetection));
|
||||
|
||||
if(hrng->State == HAL_RNG_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hrng->Lock = HAL_UNLOCKED;
|
||||
/* Init the low level hardware */
|
||||
HAL_RNG_MspInit(hrng);
|
||||
}
|
||||
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_BUSY;
|
||||
|
||||
/* CED Configuration */
|
||||
MODIFY_REG(hrng->Instance->CR, RNG_CR_CED, hrng->Init.ClockErrorDetection);
|
||||
|
||||
/* Enable the RNG Peripheral */
|
||||
__HAL_RNG_ENABLE(hrng);
|
||||
|
||||
/* Initialize the RNG state */
|
||||
hrng->State = HAL_RNG_STATE_READY;
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the RNG peripheral.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
/* Check the RNG handle allocation */
|
||||
if(hrng == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Disable the RNG Peripheral */
|
||||
CLEAR_BIT(hrng->Instance->CR, RNG_CR_IE | RNG_CR_RNGEN |RNG_CR_CED);
|
||||
|
||||
/* Clear RNG interrupt status flags */
|
||||
CLEAR_BIT(hrng->Instance->SR, RNG_SR_CEIS | RNG_SR_SEIS);
|
||||
|
||||
/* DeInit the low level hardware */
|
||||
HAL_RNG_MspDeInit(hrng);
|
||||
|
||||
/* Update the RNG state */
|
||||
hrng->State = HAL_RNG_STATE_RESET;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hrng);
|
||||
|
||||
/* Return the function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the RNG MSP.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hrng);
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_RNG_MspInit must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the RNG MSP.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hrng);
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_RNG_MspDeInit must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup RNG_Exported_Functions_Group2
|
||||
* @brief Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Get the 32 bit Random number
|
||||
(+) Get the 32 bit Random number with interrupt enabled
|
||||
(+) Handle RNG interrupt request
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Generates a 32-bit random number.
|
||||
* @note Each time the random number data is read the RNG_FLAG_DRDY flag
|
||||
* is automatically cleared.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @param random32bit: pointer to generated random number variable if successful.
|
||||
* @retval HAL status
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit)
|
||||
{
|
||||
uint32_t tickstart = 0U;
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hrng);
|
||||
|
||||
/* Check RNG peripheral state */
|
||||
if(hrng->State == HAL_RNG_STATE_READY)
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_BUSY;
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Check if data register contains valid random data */
|
||||
while(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > RNG_TIMEOUT_VALUE)
|
||||
{
|
||||
hrng->State = HAL_RNG_STATE_ERROR;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hrng);
|
||||
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a 32bit Random number */
|
||||
hrng->RandomNumber = hrng->Instance->DR;
|
||||
*random32bit = hrng->RandomNumber;
|
||||
|
||||
hrng->State = HAL_RNG_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hrng);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generates a 32-bit random number in interrupt mode.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hrng);
|
||||
|
||||
/* Check RNG peripheral state */
|
||||
if(hrng->State == HAL_RNG_STATE_READY)
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_BUSY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hrng);
|
||||
|
||||
/* Enable the RNG Interrupts: Data Ready, Clock error, Seed error */
|
||||
__HAL_RNG_ENABLE_IT(hrng);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hrng);
|
||||
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handles RNG interrupt request.
|
||||
* @note In the case of a clock error, the RNG is no more able to generate
|
||||
* random numbers because the PLL48CLK clock is not correct. User has
|
||||
* to check that the clock controller is correctly configured to provide
|
||||
* the RNG clock and clear the CEIS bit using __HAL_RNG_CLEAR_IT().
|
||||
* The clock error has no impact on the previously generated
|
||||
* random numbers, and the RNG_DR register contents can be used.
|
||||
* @note In the case of a seed error, the generation of random numbers is
|
||||
* interrupted as long as the SECS bit is '1'. If a number is
|
||||
* available in the RNG_DR register, it must not be used because it may
|
||||
* not have enough entropy. In this case, it is recommended to clear the
|
||||
* SEIS bit using __HAL_RNG_CLEAR_IT(), then disable and enable
|
||||
* the RNG peripheral to reinitialize and restart the RNG.
|
||||
* @note User-written HAL_RNG_ErrorCallback() API is called once whether SEIS
|
||||
* or CEIS are set.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval None
|
||||
|
||||
*/
|
||||
void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
/* RNG clock error interrupt occurred */
|
||||
if((__HAL_RNG_GET_IT(hrng, RNG_IT_CEI) != RESET) || (__HAL_RNG_GET_IT(hrng, RNG_IT_SEI) != RESET))
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_ERROR;
|
||||
|
||||
HAL_RNG_ErrorCallback(hrng);
|
||||
|
||||
/* Clear the clock error flag */
|
||||
__HAL_RNG_CLEAR_IT(hrng, RNG_IT_CEI|RNG_IT_SEI);
|
||||
|
||||
}
|
||||
|
||||
/* Check RNG data ready interrupt occurred */
|
||||
if(__HAL_RNG_GET_IT(hrng, RNG_IT_DRDY) != RESET)
|
||||
{
|
||||
/* Generate random number once, so disable the IT */
|
||||
__HAL_RNG_DISABLE_IT(hrng);
|
||||
|
||||
/* Get the 32bit Random number (DRDY flag automatically cleared) */
|
||||
hrng->RandomNumber = hrng->Instance->DR;
|
||||
|
||||
if(hrng->State != HAL_RNG_STATE_ERROR)
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_READY;
|
||||
|
||||
/* Data Ready callback */
|
||||
HAL_RNG_ReadyDataCallback(hrng, hrng->RandomNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read latest generated random number.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval random value
|
||||
*/
|
||||
uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
return(hrng->RandomNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Data Ready callback in non-blocking mode.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @param random32bit: generated random number.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hrng);
|
||||
UNUSED(random32bit);
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_RNG_ReadyDataCallback must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RNG error callbacks.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hrng);
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_RNG_ErrorCallback must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup RNG_Exported_Functions_Group3
|
||||
* @brief Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral State functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection permits to get in run-time the status of the peripheral
|
||||
and the data flow.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Returns the RNG state.
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
return hrng->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1531
File diff suppressed because it is too large
Load Diff
+1830
File diff suppressed because it is too large
Load Diff
+2332
File diff suppressed because it is too large
Load Diff
+140
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_sai_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief SAI Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionality of the SAI Peripheral Controller:
|
||||
* + Modify PDM microphone delays.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_SAI_MODULE_ENABLED
|
||||
|
||||
/** @defgroup SAIEx SAIEx
|
||||
* @brief SAI Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
|
||||
#define SAI_PDM_DELAY_MASK 0x77U
|
||||
#define SAI_PDM_DELAY_OFFSET 8U
|
||||
#define SAI_PDM_RIGHT_DELAY_OFFSET 4U
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup SAIEx_Exported_Functions SAIEx Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SAIEx_Exported_Functions_Group1 Peripheral Control functions
|
||||
* @brief SAIEx control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended features functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Modify PDM microphone delays
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure PDM microphone delays.
|
||||
* @param hsai SAI handle.
|
||||
* @param pdmMicDelay Microphone delays configuration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
SAI_TypeDef *SaiBaseAddress = NULL;
|
||||
|
||||
/* Get the SAI base address according to the SAI handle */
|
||||
SaiBaseAddress = (hsai->Instance == SAI1_Block_A) ? SAI1 : \
|
||||
((hsai->Instance == SAI2_Block_A) ? SAI2 : \
|
||||
((hsai->Instance == SAI3_Block_A) ? SAI3 : \
|
||||
((hsai->Instance == SAI4_Block_A) ? SAI4 : \
|
||||
NULL)));
|
||||
if((SaiBaseAddress != NULL) && (hsai->State != HAL_SAI_STATE_RESET))
|
||||
{
|
||||
/* Check microphone delay parameters */
|
||||
assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
|
||||
assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
|
||||
assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
|
||||
|
||||
/* Reset current delays for specified microphone */
|
||||
SaiBaseAddress->PDMDLY &= ~(SAI_PDM_DELAY_MASK << (SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1)));
|
||||
|
||||
/* Apply new microphone delays */
|
||||
SaiBaseAddress->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << \
|
||||
(SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+2952
File diff suppressed because it is too large
Load Diff
+313
@@ -0,0 +1,313 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_sd_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief SD card Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Secure Digital (SD) peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The SD Extension HAL driver can be used as follows:
|
||||
(+) Configure Buffer0 and Buffer1 start address and Buffer size using HAL_SDEx_ConfigDMAMultiBuffer() function.
|
||||
|
||||
(+) Start Read and Write for multibuffer mode using HAL_SDEx_ReadBlocksDMAMultiBuffer() and HAL_SDEx_WriteBlocksDMAMultiBuffer() functions.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SDEx SDEx
|
||||
* @brief SD Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup SDEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup SDEx_Exported_Functions_Group1
|
||||
* @brief Multibuffer functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Multibuffer functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to configure the multibuffer mode and start read and write
|
||||
multibuffer mode for SD HAL driver.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure DMA Dual Buffer mode. The Data transfer is managed by an Internal DMA.
|
||||
* @param hsd: SD handle
|
||||
* @param pDataBuffer0: Pointer to the buffer0 that will contain/receive the transfered data
|
||||
* @param pDataBuffer1: Pointer to the buffer1 that will contain/receive the transfered data
|
||||
* @param BufferSize: Size of Buffer0 in Blocks. Buffer0 and Buffer1 must have the same size.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_ConfigDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t * pDataBuffer0, uint32_t * pDataBuffer1, uint32_t BufferSize)
|
||||
{
|
||||
if(hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
hsd->Instance->IDMABASE0= (uint32_t) pDataBuffer0 ;
|
||||
hsd->Instance->IDMABASE1= (uint32_t) pDataBuffer1 ;
|
||||
hsd->Instance->IDMABSIZE= (uint32_t) BufferSize;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in a card. The received Data will be stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_SDEx_ConfigDMAMultiBuffer before call this function.
|
||||
* @param hsd: SD handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_ReadBlocksDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t BlockAdd, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate = HAL_SD_ERROR_NONE;
|
||||
|
||||
if(hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
if((BlockAdd + NumberOfBlocks) > (hsd->SdCard.LogBlockNbr))
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((hsd->Instance->IDMABASE0 == 0) || (hsd->Instance->IDMABASE1 == 0) || (hsd->Instance->IDMABSIZE == 0))
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
|
||||
hsd->ErrorCode = HAL_SD_ERROR_NONE;
|
||||
hsd->State = HAL_SD_STATE_BUSY;
|
||||
|
||||
if(hsd->SdCard.CardType != CARD_SDHC_SDXC)
|
||||
{
|
||||
BlockAdd *= 512;
|
||||
}
|
||||
|
||||
/* Configure the SD DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
SDMMC_ConfigData(hsd->Instance, &config);
|
||||
|
||||
hsd->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE( hsd->Instance);
|
||||
|
||||
hsd->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
__HAL_SD_ENABLE_IT(hsd, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND | SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
/* Read Blocks in DMA mode */
|
||||
hsd->Context = (SD_CONTEXT_READ_MULTIPLE_BLOCK | SD_CONTEXT_DMA);
|
||||
|
||||
/* Read Multi Block command */
|
||||
errorstate = SDMMC_CmdReadMultiBlock(hsd->Instance, BlockAdd);
|
||||
if(errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
hsd->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write block(s) to a specified address in a card. The transfered Data are stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_SDEx_ConfigDMAMultiBuffer before call this function.
|
||||
* @param hsd: SD handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_WriteBlocksDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t BlockAdd, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate = HAL_SD_ERROR_NONE;
|
||||
|
||||
if(hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
if((BlockAdd + NumberOfBlocks) > (hsd->SdCard.LogBlockNbr))
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((hsd->Instance->IDMABASE0 == 0) || (hsd->Instance->IDMABASE1 == 0) || (hsd->Instance->IDMABSIZE == 0))
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
|
||||
hsd->ErrorCode = HAL_SD_ERROR_NONE;
|
||||
|
||||
hsd->State = HAL_SD_STATE_BUSY;
|
||||
|
||||
if(hsd->SdCard.CardType != CARD_SDHC_SDXC)
|
||||
{
|
||||
BlockAdd *= 512;
|
||||
}
|
||||
|
||||
/* Configure the SD DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_CARD;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
SDMMC_ConfigData(hsd->Instance, &config);
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE( hsd->Instance);
|
||||
|
||||
hsd->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
__HAL_SD_ENABLE_IT(hsd, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND | SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
/* Write Blocks in DMA mode */
|
||||
hsd->Context = (SD_CONTEXT_WRITE_MULTIPLE_BLOCK | SD_CONTEXT_DMA);
|
||||
|
||||
/* Write Multi Block command */
|
||||
errorstate = SDMMC_CmdWriteMultiBlock(hsd->Instance, BlockAdd);
|
||||
if(errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
hsd->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Change the DMA Buffer0 or Buffer1 address on the fly.
|
||||
* @param hsd: pointer to a SD_HandleTypeDef structure.
|
||||
* @param Buffer: the buffer to be changed, This parameter can be one of
|
||||
* the following values: SD_DMA_BUFFER0 or SD_DMA_BUFFER1
|
||||
* @param pDataBuffer: The new address
|
||||
* @note The BUFFER0 address can be changed only when the current transfer use
|
||||
* BUFFER1 and the BUFFER1 address can be changed only when the current
|
||||
* transfer use BUFFER0.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_ChangeDMABuffer(SD_HandleTypeDef *hsd, HAL_SDEx_DMABuffer_MemoryTypeDef Buffer, uint32_t *pDataBuffer)
|
||||
{
|
||||
if(Buffer == SD_DMA_BUFFER0)
|
||||
{
|
||||
/* change the buffer0 address */
|
||||
hsd->Instance->IDMABASE0 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* change the memory1 address */
|
||||
hsd->Instance->IDMABASE1 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+862
@@ -0,0 +1,862 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_sdram.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief SDRAM HAL module driver.
|
||||
* This file provides a generic firmware to drive SDRAM memories mounted
|
||||
* as external device.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This driver is a generic layered driver which contains a set of APIs used to
|
||||
control SDRAM memories. It uses the FMC layer functions to interface
|
||||
with SDRAM devices.
|
||||
The following sequence should be followed to configure the FMC to interface
|
||||
with SDRAM memories:
|
||||
|
||||
(#) Declare a SDRAM_HandleTypeDef handle structure, for example:
|
||||
SDRAM_HandleTypeDef hdsram
|
||||
|
||||
(++) Fill the SDRAM_HandleTypeDef handle "Init" field with the allowed
|
||||
values of the structure member.
|
||||
|
||||
(++) Fill the SDRAM_HandleTypeDef handle "Instance" field with a predefined
|
||||
base register instance for NOR or SDRAM device
|
||||
|
||||
(#) Declare a FMC_SDRAM_TimingTypeDef structure; for example:
|
||||
FMC_SDRAM_TimingTypeDef Timing;
|
||||
and fill its fields with the allowed values of the structure member.
|
||||
|
||||
(#) Initialize the SDRAM Controller by calling the function HAL_SDRAM_Init(). This function
|
||||
performs the following sequence:
|
||||
|
||||
(##) MSP hardware layer configuration using the function HAL_SDRAM_MspInit()
|
||||
(##) Control register configuration using the FMC SDRAM interface function
|
||||
FMC_SDRAM_Init()
|
||||
(##) Timing register configuration using the FMC SDRAM interface function
|
||||
FMC_SDRAM_Timing_Init()
|
||||
(##) Program the SDRAM external device by applying its initialization sequence
|
||||
according to the device plugged in your hardware. This step is mandatory
|
||||
for accessing the SDRAM device.
|
||||
|
||||
(#) At this stage you can perform read/write accesses from/to the memory connected
|
||||
to the SDRAM Bank. You can perform either polling or DMA transfer using the
|
||||
following APIs:
|
||||
(++) HAL_SDRAM_Read()/HAL_SDRAM_Write() for polling read/write access
|
||||
(++) HAL_SDRAM_Read_DMA()/HAL_SDRAM_Write_DMA() for DMA read/write transfer
|
||||
|
||||
(#) You can also control the SDRAM device by calling the control APIs HAL_SDRAM_WriteOperation_Enable()/
|
||||
HAL_SDRAM_WriteOperation_Disable() to respectively enable/disable the SDRAM write operation or
|
||||
the function HAL_SDRAM_SendCommand() to send a specified command to the SDRAM
|
||||
device. The command to be sent must be configured with the FMC_SDRAM_CommandTypeDef
|
||||
structure.
|
||||
|
||||
(#) You can continuously monitor the SDRAM device HAL state by calling the function
|
||||
HAL_SDRAM_GetState()
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SDRAM SDRAM
|
||||
* @brief SDRAM driver modules
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_SDRAM_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup SDRAM_Exported_Functions SDRAM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SDRAM_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SDRAM Initialization and de_initialization functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to initialize/de-initialize
|
||||
the SDRAM memory
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Performs the SDRAM device initialization sequence.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param Timing: Pointer to SDRAM control timing structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Init(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_TimingTypeDef *Timing)
|
||||
{
|
||||
/* Check the SDRAM handle parameter */
|
||||
if(hsdram == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if(hsdram->State == HAL_SDRAM_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hsdram->Lock = HAL_UNLOCKED;
|
||||
/* Initialize the low level hardware (MSP) */
|
||||
HAL_SDRAM_MspInit(hsdram);
|
||||
}
|
||||
|
||||
/* Initialize the SDRAM controller state */
|
||||
hsdram->State = HAL_SDRAM_STATE_BUSY;
|
||||
|
||||
/* Initialize SDRAM control Interface */
|
||||
FMC_SDRAM_Init(hsdram->Instance, &(hsdram->Init));
|
||||
|
||||
/* Initialize SDRAM timing Interface */
|
||||
FMC_SDRAM_Timing_Init(hsdram->Instance, Timing, hsdram->Init.SDBank);
|
||||
|
||||
/* Enable FMC IP */
|
||||
__FMC_ENABLE();
|
||||
|
||||
/* Update the SDRAM controller state */
|
||||
hsdram->State = HAL_SDRAM_STATE_READY;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Perform the SDRAM device initialization sequence.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_DeInit(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Initialize the low level hardware (MSP) */
|
||||
HAL_SDRAM_MspDeInit(hsdram);
|
||||
|
||||
/* Configure the SDRAM registers with their reset values */
|
||||
FMC_SDRAM_DeInit(hsdram->Instance, hsdram->Init.SDBank);
|
||||
|
||||
/* Reset the SDRAM controller state */
|
||||
hsdram->State = HAL_SDRAM_STATE_RESET;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SDRAM MSP Init.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hsdram);
|
||||
|
||||
/* NOTE: This function Should not be modified, when the callback is needed,
|
||||
the HAL_SDRAM_MspInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SDRAM MSP DeInit.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SDRAM_MspDeInit(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hsdram);
|
||||
|
||||
/* NOTE: This function Should not be modified, when the callback is needed,
|
||||
the HAL_SDRAM_MspDeInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SDRAM refresh error interrupt request.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
void HAL_SDRAM_IRQHandler(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Check SDRAM interrupt Rising edge flag */
|
||||
if(__FMC_SDRAM_GET_FLAG(hsdram->Instance, FMC_SDRAM_FLAG_REFRESH_IT))
|
||||
{
|
||||
/* SDRAM refresh error interrupt callback */
|
||||
HAL_SDRAM_RefreshErrorCallback(hsdram);
|
||||
|
||||
/* Clear SDRAM refresh error interrupt pending bit */
|
||||
__FMC_SDRAM_CLEAR_FLAG(hsdram->Instance, FMC_SDRAM_FLAG_REFRESH_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SDRAM Refresh error callback.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SDRAM_RefreshErrorCallback(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hsdram);
|
||||
|
||||
/* NOTE: This function Should not be modified, when the callback is needed,
|
||||
the HAL_SDRAM_RefreshErrorCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA transfer complete callback.
|
||||
* @param hmdma: pointer to a MDMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SDRAM_DMA_XferCpltCallback(MDMA_HandleTypeDef *hmdma)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdma);
|
||||
|
||||
/* NOTE: This function Should not be modified, when the callback is needed,
|
||||
the HAL_SDRAM_DMA_XferCpltCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA transfer complete error callback.
|
||||
* @param hmdma: DMA handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SDRAM_DMA_XferErrorCallback(MDMA_HandleTypeDef *hmdma)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdma);
|
||||
|
||||
/* NOTE: This function Should not be modified, when the callback is needed,
|
||||
the HAL_SDRAM_DMA_XferErrorCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SDRAM_Exported_Functions_Group2 Input and Output functions
|
||||
* @brief Input Output and memory control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SDRAM Input and Output functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to use and control the SDRAM memory
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Reads 8-bit data buffer from the SDRAM memory.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Read_8b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint8_t *pSdramAddress = (uint8_t *)pAddress;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if(hsdram->State == HAL_SDRAM_STATE_PRECHARGED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Read data from source */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*pDstBuffer = *(__IO uint8_t *)pSdramAddress;
|
||||
pDstBuffer++;
|
||||
pSdramAddress++;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Writes 8-bit data buffer to SDRAM memory.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Write_8b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint8_t *pSdramAddress = (uint8_t *)pAddress;
|
||||
uint32_t tmp = 0;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
tmp = hsdram->State;
|
||||
|
||||
if(tmp == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Write data to memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint8_t *)pSdramAddress = *pSrcBuffer;
|
||||
pSrcBuffer++;
|
||||
pSdramAddress++;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads 16-bit data buffer from the SDRAM memory.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Read_16b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint16_t *pSdramAddress = (uint16_t *)pAddress;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if(hsdram->State == HAL_SDRAM_STATE_PRECHARGED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Read data from source */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*pDstBuffer = *(__IO uint16_t *)pSdramAddress;
|
||||
pDstBuffer++;
|
||||
pSdramAddress++;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes 16-bit data buffer to SDRAM memory.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Write_16b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint16_t *pSdramAddress = (uint16_t *)pAddress;
|
||||
uint32_t tmp = 0;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
tmp = hsdram->State;
|
||||
|
||||
if(tmp == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Write data to memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint16_t *)pSdramAddress = *pSrcBuffer;
|
||||
pSrcBuffer++;
|
||||
pSdramAddress++;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads 32-bit data buffer from the SDRAM memory.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Read_32b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint32_t *pSdramAddress = (uint32_t *)pAddress;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if(hsdram->State == HAL_SDRAM_STATE_PRECHARGED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Read data from source */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*pDstBuffer = *(__IO uint32_t *)pSdramAddress;
|
||||
pDstBuffer++;
|
||||
pSdramAddress++;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes 32-bit data buffer to SDRAM memory.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Write_32b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint32_t *pSdramAddress = (uint32_t *)pAddress;
|
||||
uint32_t tmp = 0;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
tmp = hsdram->State;
|
||||
|
||||
if(tmp == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Write data to memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint32_t *)pSdramAddress = *pSrcBuffer;
|
||||
pSrcBuffer++;
|
||||
pSdramAddress++;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a Words data from the SDRAM memory using DMA transfer.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Read_DMA(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
uint32_t tmp = 0;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
tmp = hsdram->State;
|
||||
|
||||
if(tmp == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if(tmp == HAL_SDRAM_STATE_PRECHARGED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Configure DMA user callbacks */
|
||||
hsdram->hmdma->XferCpltCallback = HAL_SDRAM_DMA_XferCpltCallback;
|
||||
hsdram->hmdma->XferErrorCallback = HAL_SDRAM_DMA_XferErrorCallback;
|
||||
|
||||
/* Enable the DMA Stream */
|
||||
HAL_MDMA_Start_IT(hsdram->hmdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)(BufferSize * 4), 1);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a Words data buffer to SDRAM memory using DMA transfer.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_Write_DMA(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
uint32_t tmp = 0;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsdram);
|
||||
|
||||
/* Check the SDRAM controller state */
|
||||
tmp = hsdram->State;
|
||||
|
||||
if(tmp == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Configure DMA user callbacks */
|
||||
hsdram->hmdma->XferCpltCallback = HAL_SDRAM_DMA_XferCpltCallback;
|
||||
hsdram->hmdma->XferErrorCallback = HAL_SDRAM_DMA_XferErrorCallback;
|
||||
|
||||
/* Enable the DMA Stream */
|
||||
HAL_MDMA_Start_IT(hsdram->hmdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)(BufferSize * 4), 1);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsdram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SDRAM_Exported_Functions_Group3 Control functions
|
||||
* @brief management functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SDRAM Control functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control dynamically
|
||||
the SDRAM interface.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enables dynamically SDRAM write protection.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_WriteProtection_Enable(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_BUSY;
|
||||
|
||||
/* Enable write protection */
|
||||
FMC_SDRAM_WriteProtection_Enable(hsdram->Instance, hsdram->Init.SDBank);
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_WRITE_PROTECTED;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables dynamically SDRAM write protection.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_WriteProtection_Disable(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_BUSY;
|
||||
|
||||
/* Disable write protection */
|
||||
FMC_SDRAM_WriteProtection_Disable(hsdram->Instance, hsdram->Init.SDBank);
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_READY;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sends Command to the SDRAM bank.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param Command: SDRAM command structure
|
||||
* @param Timeout: Timeout duration
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_SendCommand(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command, uint32_t Timeout)
|
||||
{
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_BUSY;
|
||||
|
||||
/* Send SDRAM command */
|
||||
FMC_SDRAM_SendCommand(hsdram->Instance, Command, Timeout);
|
||||
|
||||
/* Update the SDRAM controller state state */
|
||||
if(Command->CommandMode == FMC_SDRAM_CMD_PALL)
|
||||
{
|
||||
hsdram->State = HAL_SDRAM_STATE_PRECHARGED;
|
||||
}
|
||||
else
|
||||
{
|
||||
hsdram->State = HAL_SDRAM_STATE_READY;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Programs the SDRAM Memory Refresh rate.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param RefreshRate: The SDRAM refresh rate value
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_ProgramRefreshRate(SDRAM_HandleTypeDef *hsdram, uint32_t RefreshRate)
|
||||
{
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_BUSY;
|
||||
|
||||
/* Program the refresh rate */
|
||||
FMC_SDRAM_ProgramRefreshRate(hsdram->Instance ,RefreshRate);
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_READY;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the Number of consecutive SDRAM Memory auto Refresh commands.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @param AutoRefreshNumber: The SDRAM auto Refresh number
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDRAM_SetAutoRefreshNumber(SDRAM_HandleTypeDef *hsdram, uint32_t AutoRefreshNumber)
|
||||
{
|
||||
/* Check the SDRAM controller state */
|
||||
if(hsdram->State == HAL_SDRAM_STATE_BUSY)
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_BUSY;
|
||||
|
||||
/* Set the Auto-Refresh number */
|
||||
FMC_SDRAM_SetAutoRefreshNumber(hsdram->Instance ,AutoRefreshNumber);
|
||||
|
||||
/* Update the SDRAM state */
|
||||
hsdram->State = HAL_SDRAM_STATE_READY;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the SDRAM memory current mode.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval The SDRAM memory mode.
|
||||
*/
|
||||
uint32_t HAL_SDRAM_GetModeStatus(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
/* Return the SDRAM memory current mode */
|
||||
return(FMC_SDRAM_GetModeStatus(hsdram->Instance, hsdram->Init.SDBank));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SDRAM_Exported_Functions_Group4 State functions
|
||||
* @brief Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SDRAM State functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This subsection permits to get in run-time the status of the SDRAM controller
|
||||
and the data flow.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Returns the SDRAM state.
|
||||
* @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SDRAM module.
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_SDRAM_StateTypeDef HAL_SDRAM_GetState(SDRAM_HandleTypeDef *hsdram)
|
||||
{
|
||||
return hsdram->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_SDRAM_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+2343
File diff suppressed because it is too large
Load Diff
+208
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_smartcard_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief SMARTCARD HAL module driver.
|
||||
* This file provides extended firmware functions to manage the following
|
||||
* functionalities of the SmartCard.
|
||||
* + Initialization and de-initialization functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
*
|
||||
@verbatim
|
||||
=============================================================================
|
||||
##### SMARTCARD peripheral extended features #####
|
||||
=============================================================================
|
||||
[..]
|
||||
The Extended SMARTCARD HAL driver can be used as follows:
|
||||
|
||||
(#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
|
||||
then program SMARTCARD advanced features if required (TX/RX pins swap, TimeOut,
|
||||
auto-retry counter,...) in the hsmartcard AdvancedInit structure.
|
||||
|
||||
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SMARTCARDEx SMARTCARDEx
|
||||
* @brief SMARTCARD Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
|
||||
* @brief Extended control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to initialize the SMARTCARD.
|
||||
(+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
|
||||
(+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
|
||||
(+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
|
||||
(+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Update on the fly the SMARTCARD block length in RTOR register.
|
||||
* @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMARTCARD module.
|
||||
* @param BlockLength: SMARTCARD block length (8-bit long at most)
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
|
||||
{
|
||||
MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update on the fly the receiver timeout value in RTOR register.
|
||||
* @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMARTCARD module.
|
||||
* @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout
|
||||
* value must be less or equal to 0x00FFFFFF.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
|
||||
{
|
||||
assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
|
||||
MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the SMARTCARD receiver timeout feature.
|
||||
* @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMARTCARD module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
|
||||
{
|
||||
|
||||
if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmartcard);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
||||
|
||||
/* Set the USART RTOEN bit */
|
||||
SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmartcard);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the SMARTCARD receiver timeout feature.
|
||||
* @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMARTCARD module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
|
||||
{
|
||||
|
||||
if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmartcard);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
||||
|
||||
/* Clear the USART RTOEN bit */
|
||||
CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmartcard);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+2039
File diff suppressed because it is too large
Load Diff
+1266
File diff suppressed because it is too large
Load Diff
+3139
File diff suppressed because it is too large
Load Diff
+245
@@ -0,0 +1,245 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_spi_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief Extended SPI HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* SPI peripheral extended functionalities :
|
||||
* + IO operation functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SPIEx SPIEx
|
||||
* @brief SPI Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
|
||||
* @brief Data transfers functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of extended functions to manage the SPI
|
||||
data transfers.
|
||||
|
||||
(#) SPIEx function:
|
||||
(++) HAL_SPIEx_FlushRxFifo()
|
||||
(++) HAL_SPIEx_FlushRxFifo()
|
||||
(++) HAL_SPIEx_EnableLockConfiguration()
|
||||
(++) HAL_SPIEx_ConfigureUnderrun()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Flush the RX fifo.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SPI module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
__IO uint32_t tmpreg;
|
||||
uint8_t count = 0;
|
||||
while ( ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY) || ((hspi->Instance->SR & SPI_FLAG_RXWNE) == SPI_FLAG_RXWNE))
|
||||
{
|
||||
count+=4;
|
||||
tmpreg = hspi->Instance->RXDR;
|
||||
UNUSED(tmpreg); /* To avoid GCC warning */
|
||||
|
||||
if (IS_SPI_HIGHEND_INSTANCE(hspi->Instance))
|
||||
{
|
||||
if(count > SPI_HIGHEND_FIFO_SIZE)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(count > SPI_LOWEND_FIFO_SIZE)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Lock for the AF configuration of associated IOs
|
||||
* and write protect the Content of Configuartion register 2
|
||||
* when SPI is enabled
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_EnableLockConfiguration(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
HAL_StatusTypeDef errorcode = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hspi);
|
||||
|
||||
if (hspi->State != HAL_SPI_STATE_READY)
|
||||
{
|
||||
errorcode = HAL_BUSY;
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/* Check if the SPI is disabled to edit IOLOCK bit */
|
||||
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
SET_BIT(hspi->Instance->CR1 , SPI_CR1_IOLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_SPI_DISABLE(hspi);
|
||||
|
||||
SET_BIT(hspi->Instance->CR1 , SPI_CR1_IOLOCK);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_SPI_ENABLE(hspi);
|
||||
}
|
||||
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the UNDERRUN condition and behavior of slave transmitter.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @param UnderrunDetection : Detection of underrun condition at slave transmitter
|
||||
* This parameter can be a value of @ref SPI_Underrun_Detection.
|
||||
* @param UnderrunBehaviour : Behavior of slave transmitter at underrun condition
|
||||
* This parameter can be a value of @ref SPI_Underrun_Behaviour.
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_ConfigureUnderrun(SPI_HandleTypeDef *hspi, uint32_t UnderrunDetection, uint32_t UnderrunBehaviour)
|
||||
{
|
||||
HAL_StatusTypeDef errorcode = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hspi);
|
||||
|
||||
/* Check State and Insure that Underrun configuration is managed only by Salve */
|
||||
if ((hspi->State != HAL_SPI_STATE_READY) || (hspi->Init.Mode != SPI_MODE_SLAVE))
|
||||
{
|
||||
errorcode = HAL_BUSY;
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SPI_UNDERRUN_DETECTION(UnderrunDetection));
|
||||
assert_param(IS_SPI_UNDERRUN_BEHAVIOUR(UnderrunBehaviour));
|
||||
|
||||
/* Check if the SPI is disabled to edit CFG1 register */
|
||||
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
/* Configure Underrun fields */
|
||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRDET, UnderrunDetection);
|
||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRCFG, UnderrunBehaviour);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_SPI_DISABLE(hspi);
|
||||
|
||||
/* Configure Underrun fields */
|
||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRDET, UnderrunDetection);
|
||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRCFG, UnderrunBehaviour);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_SPI_ENABLE(hspi);
|
||||
}
|
||||
|
||||
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+693
@@ -0,0 +1,693 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_sram.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief SRAM HAL module driver.
|
||||
* This file provides a generic firmware to drive SRAM memories
|
||||
* mounted as external device.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This driver is a generic layered driver which contains a set of APIs used to
|
||||
control SRAM memories. It uses the FMC layer functions to interface
|
||||
with SRAM devices.
|
||||
The following sequence should be followed to configure the FMC to interface
|
||||
with SRAM/PSRAM memories:
|
||||
|
||||
(#) Declare a SRAM_HandleTypeDef handle structure, for example:
|
||||
SRAM_HandleTypeDef hsram; and:
|
||||
|
||||
(++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed
|
||||
values of the structure member.
|
||||
|
||||
(++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined
|
||||
base register instance for NOR or SRAM device
|
||||
|
||||
(++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined
|
||||
base register instance for NOR or SRAM extended mode
|
||||
|
||||
(#) Declare two FMC_NORSRAM_TimingTypeDef structures, for both normal and extended
|
||||
mode timings; for example:
|
||||
FMC_NORSRAM_TimingTypeDef Timing and FMC_NORSRAM_TimingTypeDef ExTiming;
|
||||
and fill its fields with the allowed values of the structure member.
|
||||
|
||||
(#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function
|
||||
performs the following sequence:
|
||||
|
||||
(##) MSP hardware layer configuration using the function HAL_SRAM_MspInit()
|
||||
(##) Control register configuration using the FMC NORSRAM interface function
|
||||
FMC_NORSRAM_Init()
|
||||
(##) Timing register configuration using the FMC NORSRAM interface function
|
||||
FMC_NORSRAM_Timing_Init()
|
||||
(##) Extended mode Timing register configuration using the FMC NORSRAM interface function
|
||||
FMC_NORSRAM_Extended_Timing_Init()
|
||||
(##) Enable the SRAM device using the macro __FMC_NORSRAM_ENABLE()
|
||||
|
||||
(#) At this stage you can perform read/write accesses from/to the memory connected
|
||||
to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the
|
||||
following APIs:
|
||||
(++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access
|
||||
(++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer
|
||||
|
||||
(#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/
|
||||
HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation
|
||||
|
||||
(#) You can continuously monitor the SRAM device HAL state by calling the function
|
||||
HAL_SRAM_GetState()
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SRAM SRAM
|
||||
* @brief SRAM driver modules
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup SRAM_Exported_Functions SRAM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and Configuration functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SRAM Initialization and de_initialization functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to initialize/de-initialize
|
||||
the SRAM memory
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Performs the SRAM device initialization sequence
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param Timing: Pointer to SRAM control timing structure
|
||||
* @param ExtTiming: Pointer to SRAM extended mode timing structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
|
||||
{
|
||||
/* Check the SRAM handle parameter */
|
||||
if(hsram == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if(hsram->State == HAL_SRAM_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hsram->Lock = HAL_UNLOCKED;
|
||||
/* Initialize the low level hardware (MSP) */
|
||||
HAL_SRAM_MspInit(hsram);
|
||||
}
|
||||
|
||||
/* Initialize SRAM control Interface */
|
||||
FMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
|
||||
|
||||
/* Initialize SRAM timing Interface */
|
||||
FMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
|
||||
|
||||
/* Initialize SRAM extended mode timing Interface */
|
||||
FMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank, hsram->Init.ExtendedMode);
|
||||
|
||||
/* Enable the NORSRAM device */
|
||||
__FMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
|
||||
|
||||
/* Enable FMC IP */
|
||||
__FMC_ENABLE();
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Performs the SRAM device De-initialization sequence.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
|
||||
{
|
||||
/* De-Initialize the low level hardware (MSP) */
|
||||
HAL_SRAM_MspDeInit(hsram);
|
||||
|
||||
/* Configure the SRAM registers with their reset values */
|
||||
FMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
|
||||
|
||||
hsram->State = HAL_SRAM_STATE_RESET;
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SRAM MSP Init.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hsram);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_SRAM_MspInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SRAM MSP DeInit.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hsram);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_SRAM_MspDeInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA transfer complete callback.
|
||||
* @param hmdma: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SRAM_DMA_XferCpltCallback(MDMA_HandleTypeDef *hmdma)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdma);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA transfer complete error callback.
|
||||
* @param hmdma: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SRAM_DMA_XferErrorCallback(MDMA_HandleTypeDef *hmdma)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hmdma);
|
||||
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
|
||||
* @brief Input Output and memory control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SRAM Input and Output functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to use and control the SRAM memory
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Reads 8-bit buffer from SRAM memory.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint8_t * psramaddress = (uint8_t *)pAddress;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Read data from memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*pDstBuffer = *(__IO uint8_t *)psramaddress;
|
||||
pDstBuffer++;
|
||||
psramaddress++;
|
||||
}
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes 8-bit buffer to SRAM memory.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint8_t * psramaddress = (uint8_t *)pAddress;
|
||||
|
||||
/* Check the SRAM controller state */
|
||||
if(hsram->State == HAL_SRAM_STATE_PROTECTED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Write data to memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint8_t *)psramaddress = *pSrcBuffer;
|
||||
pSrcBuffer++;
|
||||
psramaddress++;
|
||||
}
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads 16-bit buffer from SRAM memory.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint16_t * psramaddress = (uint16_t *)pAddress;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Read data from memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*pDstBuffer = *(__IO uint16_t *)psramaddress;
|
||||
pDstBuffer++;
|
||||
psramaddress++;
|
||||
}
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes 16-bit buffer to SRAM memory.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
__IO uint16_t * psramaddress = (uint16_t *)pAddress;
|
||||
|
||||
/* Check the SRAM controller state */
|
||||
if(hsram->State == HAL_SRAM_STATE_PROTECTED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Write data to memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint16_t *)psramaddress = *pSrcBuffer;
|
||||
pSrcBuffer++;
|
||||
psramaddress++;
|
||||
}
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads 32-bit buffer from SRAM memory.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Read data from memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*pDstBuffer = *(__IO uint32_t *)pAddress;
|
||||
pDstBuffer++;
|
||||
pAddress++;
|
||||
}
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes 32-bit buffer to SRAM memory.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
/* Check the SRAM controller state */
|
||||
if(hsram->State == HAL_SRAM_STATE_PROTECTED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Write data to memory */
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint32_t *)pAddress = *pSrcBuffer;
|
||||
pSrcBuffer++;
|
||||
pAddress++;
|
||||
}
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a Words data from the SRAM memory using DMA transfer.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to read start address
|
||||
* @param pDstBuffer: Pointer to destination buffer
|
||||
* @param BufferSize: Size of the buffer to read from memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Configure DMA user callbacks */
|
||||
hsram->hmdma->XferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
|
||||
hsram->hmdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
|
||||
|
||||
/* Enable the DMA Stream */
|
||||
HAL_MDMA_Start_IT(hsram->hmdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)(BufferSize * 4), 1);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a Words data buffer to SRAM memory using DMA transfer.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @param pAddress: Pointer to write start address
|
||||
* @param pSrcBuffer: Pointer to source buffer to write
|
||||
* @param BufferSize: Size of the buffer to write to memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
|
||||
{
|
||||
/* Check the SRAM controller state */
|
||||
if(hsram->State == HAL_SRAM_STATE_PROTECTED)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Configure DMA user callbacks */
|
||||
hsram->hmdma->XferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
|
||||
hsram->hmdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
|
||||
|
||||
/* Enable the DMA Stream */
|
||||
HAL_MDMA_Start_IT(hsram->hmdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)(BufferSize * 4), 1);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SRAM_Exported_Functions_Group3 Control functions
|
||||
* @brief Control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SRAM Control functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control dynamically
|
||||
the SRAM interface.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enables dynamically SRAM write operation.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Enable write operation */
|
||||
FMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables dynamically SRAM write operation.
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsram);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_BUSY;
|
||||
|
||||
/* Disable write operation */
|
||||
FMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank);
|
||||
|
||||
/* Update the SRAM controller state */
|
||||
hsram->State = HAL_SRAM_STATE_PROTECTED;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hsram);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
|
||||
* @brief Peripheral State functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SRAM State functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This subsection permits to get in run-time the status of the SRAM controller
|
||||
and the data flow.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Returns the SRAM controller state
|
||||
* @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
|
||||
* the configuration information for SRAM module.
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
|
||||
{
|
||||
return hsram->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1534
File diff suppressed because it is too large
Load Diff
+5706
File diff suppressed because it is too large
Load Diff
+2090
File diff suppressed because it is too large
Load Diff
+2916
File diff suppressed because it is too large
Load Diff
+506
@@ -0,0 +1,506 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_uart_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @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
|
||||
*
|
||||
*
|
||||
@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.
|
||||
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup UARTEx UARTEx
|
||||
* @brief UART Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* 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);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* 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 UART_DE_POLARITY_HIGH: DE signal is active high
|
||||
* @arg 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 = 0x0U;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Init the low level hardware : GPIO, CLOCK, CORTEX */
|
||||
HAL_UART_MspInit(huart);
|
||||
}
|
||||
|
||||
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_Group3 Peripheral Control functions
|
||||
* @brief Extended Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..] This section provides the following functions:
|
||||
(+) HAL_UARTEx_EnableClockStopMode() API enables the UART clock (HSI or LSE only) during stop mode
|
||||
(+) HAL_UARTEx_DisableClockStopMode() API disables the above functionality
|
||||
(+) 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_WakeupCallback() called upon UART wakeup interrupt
|
||||
|
||||
|
||||
@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 UART_ADDRESS_DETECT_4B: 4-bit long address
|
||||
* @arg 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.
|
||||
* @param huart: UART handle.
|
||||
* @param WakeUpSelection: address match, Start Bit detection, RXNE bit status
|
||||
* or RX/TX FIFO related event.
|
||||
* 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
|
||||
* @arg @ref UART_WAKEUP_ON_RXFIFO_THRESHOLD
|
||||
* @arg @ref UART_WAKEUP_ON_RXFIFO_FULL
|
||||
* @arg @ref UART_WAKEUP_ON_TXFIFO_THRESHOLD
|
||||
* @arg @ref UART_WAKEUP_ON_TXFIFO_EMPTY
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* 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;
|
||||
|
||||
switch (WakeUpSelection.WakeUpEvent)
|
||||
{
|
||||
case UART_WAKEUP_ON_ADDRESS:
|
||||
case UART_WAKEUP_ON_STARTBIT:
|
||||
case UART_WAKEUP_ON_READDATA_NONEMPTY:
|
||||
/* 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;
|
||||
}
|
||||
break;
|
||||
|
||||
case UART_WAKEUP_ON_RXFIFO_THRESHOLD:
|
||||
/* Enable RXFT interrupt */
|
||||
SET_BIT(huart->Instance->CR3, USART_CR3_RXFTIE);
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
break;
|
||||
|
||||
case UART_WAKEUP_ON_RXFIFO_FULL:
|
||||
/* Enable RXFF interrupt */
|
||||
SET_BIT(huart->Instance->CR1, USART_CR1_RXFFIE);
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
break;
|
||||
|
||||
case UART_WAKEUP_ON_TXFIFO_THRESHOLD:
|
||||
/* Enable TXFT interrupt */
|
||||
SET_BIT(huart->Instance->CR3, USART_CR3_TXFTIE);
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
break;
|
||||
|
||||
case UART_WAKEUP_ON_TXFIFO_EMPTY:
|
||||
/* Enable TXFE interrupt */
|
||||
SET_BIT(huart->Instance->CR1, USART_CR1_TXFEIE);
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable UART Stop Mode.
|
||||
* @note The UART is able to wake up the MCU from Stop 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);
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Set UESM bit */
|
||||
SET_BIT(huart->Instance->CR1, USART_CR1_UESM);
|
||||
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
|
||||
/* 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);
|
||||
|
||||
huart->gState = HAL_UART_STATE_BUSY;
|
||||
|
||||
/* Clear UESM bit */
|
||||
CLEAR_BIT(huart->Instance->CR1, USART_CR1_UESM);
|
||||
|
||||
huart->gState = HAL_UART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(huart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+2432
File diff suppressed because it is too large
Load Diff
+322
@@ -0,0 +1,322 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_wwdg.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief WWDG HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Window Watchdog (WWDG) peripheral:
|
||||
* + Initialization and Configuration function
|
||||
* + IO operation functions
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### WWDG specific features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
Once enabled the WWDG generates a system reset on expiry of a programmed
|
||||
time period, unless the program refreshes the counter (T[6;0] downcounter)
|
||||
before reaching 0x3F value (i.e. a reset is generated when the counter
|
||||
value rolls over from 0x40 to 0x3F).
|
||||
|
||||
(+) An MCU reset is also generated if the counter value is refreshed
|
||||
before the counter has reached the refresh window value. This
|
||||
implies that the counter must be refreshed in a limited window.
|
||||
|
||||
(+) Once enabled the WWDG cannot be disabled except by a system reset.
|
||||
|
||||
(+) WWDGRST flag in RCC_CSR register informs when a WWDG reset has
|
||||
occurred (check available with __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)).
|
||||
|
||||
(+) The WWDG downcounter input clock is derived from the APB clock divided
|
||||
by a programmable prescaler.
|
||||
|
||||
(+) WWDG downcounter clock (Hz) = PCLK1 / (4096 * Prescaler)
|
||||
|
||||
(+) WWDG timeout (ms) = (1000 * (T[5;0] + 1)) / (WWDG downcounter clock)
|
||||
where T[5;0] are the lowest 6 bits of downcounter.
|
||||
|
||||
(+) WWDG Counter refresh is allowed between the following limits :
|
||||
(++) min time (ms) = (1000 * (T[5;0] - Window)) / (WWDG downcounter clock)
|
||||
(++) max time (ms) = (1000 * (T[5;0] - 0x40)) / (WWDG downcounter clock)
|
||||
|
||||
(+) Min-max timeout value @80 MHz(PCLK1): ~51.2 us / ~26.22 ms
|
||||
|
||||
(+) The Early Wakeup Interrupt (EWI) can be used if specific safety
|
||||
operations or data logging must be performed before the actual reset is
|
||||
generated. When the downcounter reaches the value 0x40, an EWI interrupt
|
||||
is generated and the corresponding interrupt service routine (ISR) can
|
||||
be used to trigger specific actions (such as communications or data
|
||||
logging), before resetting the device.
|
||||
In some applications, the EWI interrupt can be used to manage a software
|
||||
system check and/or system recovery/graceful degradation, without
|
||||
generating a WWDG reset. In this case, the corresponding interrupt
|
||||
service routine (ISR) should reload the WWDG counter to avoid the WWDG
|
||||
reset, then trigger the required actions.
|
||||
Note:When the EWI interrupt cannot be served, e.g. due to a system lock
|
||||
in a higher priority task, the WWDG reset will eventually be generated.
|
||||
|
||||
(+) Debug mode : When the microcontroller enters debug mode (core halted),
|
||||
the WWDG counter either continues to work normally or stops, depending
|
||||
on DBG_WWDG_STOP configuration bit in DBG module, accessible through
|
||||
__HAL_DBGMCU_FREEZE_WWDG() and __HAL_DBGMCU_UNFREEZE_WWDG() macros
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE().
|
||||
|
||||
(+) Set the WWDG prescaler, refresh window, counter value and Early Wakeup
|
||||
Interrupt mode using using HAL_WWDG_Init() function.
|
||||
This enables WWDG peripheral and the downcounter starts downcounting
|
||||
from given counter value.
|
||||
Init function can be called again to modify all watchdog parameters,
|
||||
however if EWI mode has been set once, it can't be clear until next
|
||||
reset.
|
||||
|
||||
(+) The application program must refresh the WWDG counter at regular
|
||||
intervals during normal operation to prevent an MCU reset using
|
||||
HAL_WWDG_Refresh() function. This operation must occur only when
|
||||
the counter is lower than the window value already programmed.
|
||||
|
||||
(+) if Early Wakeup Interrupt mode is enable an interrupt is generated when
|
||||
the counter reaches 0x40. User can add his own code in weak function
|
||||
HAL_WWDG_EarlyWakeupCallback().
|
||||
|
||||
*** WWDG HAL driver macros list ***
|
||||
==================================
|
||||
[..]
|
||||
Below the list of most used macros in WWDG HAL driver.
|
||||
|
||||
(+) __HAL_WWDG_GET_IT_SOURCE: Check the selected WWDG's interrupt source.
|
||||
(+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status.
|
||||
(+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
/** @defgroup WWDG WWDG
|
||||
* @brief WWDG HAL module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup WWDG_Exported_Functions WWDG Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup WWDG_Exported_Functions_Group1 Initialization and Configuration functions
|
||||
* @brief Initialization and Configuration functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Initialization and Configuration functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to:
|
||||
(+) Initialize and start the WWDG according to the specified parameters
|
||||
in the WWDG_InitTypeDef of associated handle.
|
||||
(+) Initialize the WWDG MSP.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the WWDG according to the specified.
|
||||
* parameters in the WWDG_InitTypeDef of associated handle.
|
||||
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified WWDG module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
|
||||
{
|
||||
/* Check the WWDG handle allocation */
|
||||
if(hwwdg == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
|
||||
assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
|
||||
assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
|
||||
assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
|
||||
assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode));
|
||||
|
||||
/* Init the low level hardware */
|
||||
HAL_WWDG_MspInit(hwwdg);
|
||||
|
||||
/* Set WWDG Counter */
|
||||
WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter));
|
||||
|
||||
/* Set WWDG Prescaler and Window */
|
||||
WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window));
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the WWDG MSP.
|
||||
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified WWDG module.
|
||||
* @note When rewriting this function in user file, mechanism may be added
|
||||
* to avoid multiple initialize when HAL_WWDG_Init function is called
|
||||
* again to change parameters.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hwwdg);
|
||||
|
||||
/* NOTE: This function should not be modified, when the callback is needed,
|
||||
the HAL_WWDG_MspInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup WWDG_Exported_Functions_Group2 IO operation functions
|
||||
* @brief IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### IO operation functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to:
|
||||
(+) Refresh the WWDG.
|
||||
(+) Handle WWDG interrupt request and associated function callback.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Refresh the WWDG.
|
||||
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified WWDG module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
|
||||
{
|
||||
/* Write to WWDG CR the WWDG Counter value to refresh with */
|
||||
WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter));
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle WWDG interrupt request.
|
||||
* @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations
|
||||
* or data logging must be performed before the actual reset is generated.
|
||||
* The EWI interrupt is enabled by calling HAL_WWDG_Init function with
|
||||
* EWIMode set to WWDG_EWI_ENABLE.
|
||||
* When the downcounter reaches the value 0x40, and EWI interrupt is
|
||||
* generated and the corresponding Interrupt Service Routine (ISR) can
|
||||
* be used to trigger specific actions (such as communications or data
|
||||
* logging), before resetting the device.
|
||||
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified WWDG module.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
|
||||
{
|
||||
/* Check if Early Wakeup Interrupt is enable */
|
||||
if(__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET)
|
||||
{
|
||||
/* Check if WWDG Early Wakeup Interrupt occurred */
|
||||
if(__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET)
|
||||
{
|
||||
/* Clear the WWDG Early Wakeup flag */
|
||||
__HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);
|
||||
|
||||
/* Early Wakeup callback */
|
||||
HAL_WWDG_EarlyWakeupCallback(hwwdg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief WWDG Early Wakeup callback.
|
||||
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified WWDG module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef* hwwdg)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hwwdg);
|
||||
|
||||
/* NOTE: This function should not be modified, when the callback is needed,
|
||||
the HAL_WWDG_EarlyWakeupCallback could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_ll_delayblock.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief DelayBlock Low Layer HAL module driver.
|
||||
*
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Delay Block peripheral:
|
||||
* + input clock frequency range 25MHz to 208MHz
|
||||
* + up to 12 oversampling phases
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### DelayBlock peripheral features #####
|
||||
==============================================================================
|
||||
[..] The Delay block is used to generate an Output clock which is de-phased from the Input
|
||||
clock. The phase of the Output clock is programmed by FW. The Output clock is then used
|
||||
to clock the receive data in i.e. a SDMMC or QSPI interface.
|
||||
The delay is Voltage and Temperature dependent, which may require FW to do re-tuning
|
||||
and recenter the Output clock phase to the receive data.
|
||||
|
||||
[..] The Delay Block features include the following:
|
||||
(+) Input clock frequency range 25MHz to 208MHz.
|
||||
(+) Up to 12 oversampling phases.
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This driver is a considered as a driver of service for external devices drivers
|
||||
that interfaces with the DELAY peripheral.
|
||||
The DelayBlock_Enable() function, enables the DelayBlock instance, configure the delay line length
|
||||
and configure the Output clock phase.
|
||||
The DelayBlock_Disable() function, disables the DelayBlock instance by setting DEN flag to 0.
|
||||
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DELAYBLOCK_LL DELAYBLOCK_LL
|
||||
* @brief Low layer module for Delay Block
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(HAL_SD_MODULE_ENABLED) || defined(HAL_QSPI_MODULE_ENABLED)
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup DelayBlock_LL_Exported_Functions Delay Block Low Layer Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_DELAY_LL_Group1 Initialization de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Delay Block instance.
|
||||
* @param DLYBx: Pointer to DLYB instance.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef DelayBlock_Enable(DLYB_TypeDef *DLYBx)
|
||||
{
|
||||
uint32_t i=0,N=0, lng=0, tuningOn = 1;
|
||||
|
||||
assert_param(IS_DLYB_ALL_INSTANCE(DLYBx));
|
||||
|
||||
DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN;
|
||||
|
||||
while((tuningOn != 0) && (i < DLYB_MAX_UNIT))
|
||||
{
|
||||
|
||||
DLYBx->CFGR = 12 | (i << 8);
|
||||
HAL_Delay(1);
|
||||
if(((DLYBx->CFGR & DLYB_CFGR_LNGF) != 0)
|
||||
&& ((DLYBx->CFGR & DLYB_CFGR_LNG) != 0)
|
||||
&& ((DLYBx->CFGR & DLYB_CFGR_LNG) != (DLYB_CFGR_LNG_11 | DLYB_CFGR_LNG_10)))
|
||||
{
|
||||
tuningOn = 0;
|
||||
}
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
if(DLYB_MAX_UNIT != i)
|
||||
{
|
||||
|
||||
lng = (DLYBx->CFGR & DLYB_CFGR_LNG) >> 16;
|
||||
N = 10;
|
||||
while((N>0) && ((lng >> N) == 0))
|
||||
{
|
||||
N--;
|
||||
}
|
||||
if(0 != N)
|
||||
{
|
||||
MODIFY_REG(DLYBx->CFGR, DLYB_CFGR_SEL, ((N/2)+1));
|
||||
|
||||
/* Disable Selection phase */
|
||||
DLYBx->CR = DLYB_CR_DEN;
|
||||
return HAL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable DLYB */
|
||||
DelayBlock_Disable(DLYBx);
|
||||
return HAL_ERROR;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Delay Block instance.
|
||||
* @param DLYBx: Pointer to DLYB instance.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef DelayBlock_Disable(DLYB_TypeDef *DLYBx)
|
||||
{
|
||||
/* Disable DLYB */
|
||||
DLYBx->CR = 0;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* (HAL_SD_MODULE_ENABLED) & (HAL_QSPI_MODULE_ENABLED)*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1099
File diff suppressed because it is too large
Load Diff
+1544
File diff suppressed because it is too large
Load Diff
+1699
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user