Sync inav to Gitea
Make sure docs are updated / settings_md (push) Canceled after 0s
Build firmware / test (push) Canceled after 0s
Build firmware / build-SITL-Windows (push) Canceled after 0s
Build firmware / build-SITL-Mac (push) Canceled after 0s
Build firmware / build-SITL-Linux (push) Canceled after 0s
Build firmware / build-SITL-Linux-arm64 (push) Canceled after 0s
Build firmware / upload-artifacts (push) Canceled after 0s
Build firmware / build-single-target (push) Canceled after 0s
Build firmware / build (9) (push) Canceled after 0s
Build firmware / build (8) (push) Canceled after 0s
Build firmware / build (7) (push) Canceled after 0s
Build firmware / build (6) (push) Canceled after 0s
Build firmware / build (5) (push) Canceled after 0s
Build firmware / build (4) (push) Canceled after 0s
Build firmware / build (3) (push) Canceled after 0s
Build firmware / build (2) (push) Canceled after 0s
Build firmware / build (14) (push) Canceled after 0s
Build firmware / build (13) (push) Canceled after 0s
Build firmware / build (12) (push) Canceled after 0s
Build firmware / build (11) (push) Canceled after 0s
Build firmware / build (10) (push) Canceled after 0s
Build firmware / build (1) (push) Canceled after 0s
Build firmware / build (0) (push) Canceled after 0s
Build firmware / detect (push) Canceled after 0s
Build pre-release / build (push) Canceled after 0s
Build pre-release / Release (push) Canceled after 0s
Make sure docs are updated / settings_md (push) Canceled after 0s
Build firmware / test (push) Canceled after 0s
Build firmware / build-SITL-Windows (push) Canceled after 0s
Build firmware / build-SITL-Mac (push) Canceled after 0s
Build firmware / build-SITL-Linux (push) Canceled after 0s
Build firmware / build-SITL-Linux-arm64 (push) Canceled after 0s
Build firmware / upload-artifacts (push) Canceled after 0s
Build firmware / build-single-target (push) Canceled after 0s
Build firmware / build (9) (push) Canceled after 0s
Build firmware / build (8) (push) Canceled after 0s
Build firmware / build (7) (push) Canceled after 0s
Build firmware / build (6) (push) Canceled after 0s
Build firmware / build (5) (push) Canceled after 0s
Build firmware / build (4) (push) Canceled after 0s
Build firmware / build (3) (push) Canceled after 0s
Build firmware / build (2) (push) Canceled after 0s
Build firmware / build (14) (push) Canceled after 0s
Build firmware / build (13) (push) Canceled after 0s
Build firmware / build (12) (push) Canceled after 0s
Build firmware / build (11) (push) Canceled after 0s
Build firmware / build (10) (push) Canceled after 0s
Build firmware / build (1) (push) Canceled after 0s
Build firmware / build (0) (push) Canceled after 0s
Build firmware / detect (push) Canceled after 0s
Build pre-release / build (push) Canceled after 0s
Build pre-release / Release (push) Canceled after 0s
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,556 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_eth_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief ETH HAL Extended module driver.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_ETH_LEGACY_MODULE_ENABLED
|
||||
|
||||
#if defined(ETH)
|
||||
|
||||
/** @defgroup ETHEx ETHEx
|
||||
* @brief ETH HAL Extended module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* 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 = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLRXS) >> 31) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->StripInnerVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLS);
|
||||
pVlanConfig->InnerVLANTag = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_ERIVLT) >> 27) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->DoubleVLANProcessing = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EDVLP) >> 26) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->VLANTagHashTableMatch = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTHM) >> 25) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->VLANTagInStatus = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EVLRXS) >> 24) == 0U) ? DISABLE : ENABLE;
|
||||
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 = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTIM) >> 17) == 0U) ? DISABLE : ENABLE;
|
||||
|
||||
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 = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACIVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVlanConfig->SourceTxDesc = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
|
||||
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/Disable automate enter/exit LPI mode.
|
||||
* @param TxClockStop: Enable/Disable 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 /* ETH */
|
||||
|
||||
#endif /* HAL_ETH_LEGACY_MODULE_ENABLED*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,997 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_cec.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
The 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.
|
||||
*** Callback registration ***
|
||||
=============================================
|
||||
|
||||
The compilation define USE_HAL_CEC_REGISTER_CALLBACKS when set to 1
|
||||
allows the user to configure dynamically the driver callbacks.
|
||||
Use Functions HAL_CEC_RegisterCallback() or HAL_CEC_RegisterXXXCallback()
|
||||
to register an interrupt callback.
|
||||
|
||||
Function HAL_CEC_RegisterCallback() allows to register following callbacks:
|
||||
(+) TxCpltCallback : Tx Transfer completed callback.
|
||||
(+) ErrorCallback : callback for error detection.
|
||||
(+) MspInitCallback : CEC MspInit.
|
||||
(+) MspDeInitCallback : CEC MspDeInit.
|
||||
This function takes as parameters the HAL peripheral handle, the Callback ID
|
||||
and a pointer to the user callback function.
|
||||
|
||||
For specific callback HAL_CEC_RxCpltCallback use dedicated register callbacks
|
||||
HAL_CEC_RegisterRxCpltCallback().
|
||||
|
||||
Use function HAL_CEC_UnRegisterCallback() to reset a callback to the default
|
||||
weak function.
|
||||
HAL_CEC_UnRegisterCallback() takes as parameters the HAL peripheral handle,
|
||||
and the Callback ID.
|
||||
This function allows to reset following callbacks:
|
||||
(+) TxCpltCallback : Tx Transfer completed callback.
|
||||
(+) ErrorCallback : callback for error detection.
|
||||
(+) MspInitCallback : CEC MspInit.
|
||||
(+) MspDeInitCallback : CEC MspDeInit.
|
||||
|
||||
For callback HAL_CEC_RxCpltCallback use dedicated unregister callback :
|
||||
HAL_CEC_UnRegisterRxCpltCallback().
|
||||
|
||||
By default, after the HAL_CEC_Init() and when the state is HAL_CEC_STATE_RESET
|
||||
all callbacks are set to the corresponding weak functions :
|
||||
examples HAL_CEC_TxCpltCallback() , HAL_CEC_RxCpltCallback().
|
||||
Exception done for MspInit and MspDeInit functions that are
|
||||
reset to the legacy weak function in the HAL_CEC_Init()/ HAL_CEC_DeInit() only when
|
||||
these callbacks are null (not registered beforehand).
|
||||
if not, MspInit or MspDeInit are not null, the HAL_CEC_Init() / HAL_CEC_DeInit()
|
||||
keep and use the user MspInit/MspDeInit functions (registered beforehand)
|
||||
|
||||
Callbacks can be registered/unregistered in HAL_CEC_STATE_READY state only.
|
||||
Exception done MspInit/MspDeInit callbacks that can be registered/unregistered
|
||||
in HAL_CEC_STATE_READY or HAL_CEC_STATE_RESET state,
|
||||
thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
|
||||
In that case first register the MspInit/MspDeInit user callbacks
|
||||
using HAL_CEC_RegisterCallback() before calling HAL_CEC_DeInit()
|
||||
or HAL_CEC_Init() function.
|
||||
|
||||
When the compilation define USE_HAL_CEC_REGISTER_CALLBACKS is set to 0 or
|
||||
not defined, the callback registration feature is not available and all callbacks
|
||||
are set to the corresponding weak functions.
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CEC CEC
|
||||
* @brief HAL CEC module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_CEC_MODULE_ENABLED
|
||||
#if defined (CEC)
|
||||
|
||||
/* 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 (USE_HAL_CEC_REGISTER_CALLBACKS == 1)
|
||||
if (hcec->gState == HAL_CEC_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
hcec->Lock = HAL_UNLOCKED;
|
||||
|
||||
hcec->TxCpltCallback = HAL_CEC_TxCpltCallback; /* Legacy weak TxCpltCallback */
|
||||
hcec->RxCpltCallback = HAL_CEC_RxCpltCallback; /* Legacy weak RxCpltCallback */
|
||||
hcec->ErrorCallback = HAL_CEC_ErrorCallback; /* Legacy weak ErrorCallback */
|
||||
|
||||
if (hcec->MspInitCallback == NULL)
|
||||
{
|
||||
hcec->MspInitCallback = HAL_CEC_MspInit; /* Legacy weak MspInit */
|
||||
}
|
||||
|
||||
/* Init the low level hardware */
|
||||
hcec->MspInitCallback(hcec);
|
||||
}
|
||||
#else
|
||||
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);
|
||||
}
|
||||
#endif /* USE_HAL_CEC_REGISTER_CALLBACKS */
|
||||
|
||||
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;
|
||||
|
||||
#if (USE_HAL_CEC_REGISTER_CALLBACKS == 1)
|
||||
if (hcec->MspDeInitCallback == NULL)
|
||||
{
|
||||
hcec->MspDeInitCallback = HAL_CEC_MspDeInit; /* Legacy weak MspDeInit */
|
||||
}
|
||||
|
||||
/* DeInit the low level hardware */
|
||||
hcec->MspDeInitCallback(hcec);
|
||||
|
||||
#else
|
||||
/* DeInit the low level hardware */
|
||||
HAL_CEC_MspDeInit(hcec);
|
||||
#endif /* USE_HAL_CEC_REGISTER_CALLBACKS */
|
||||
|
||||
/* 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
|
||||
*/
|
||||
}
|
||||
#if (USE_HAL_CEC_REGISTER_CALLBACKS == 1)
|
||||
/**
|
||||
* @brief Register a User CEC Callback
|
||||
* To be used instead of the weak predefined callback
|
||||
* @param hcec CEC handle
|
||||
* @param CallbackID ID of the callback to be registered
|
||||
* This parameter can be one of the following values:
|
||||
* @arg HAL_CEC_TX_CPLT_CB_ID Tx Complete callback ID
|
||||
* @arg HAL_CEC_ERROR_CB_ID Error callback ID
|
||||
* @arg HAL_CEC_MSPINIT_CB_ID MspInit callback ID
|
||||
* @arg HAL_CEC_MSPDEINIT_CB_ID MspDeInit callback ID
|
||||
* @param pCallback pointer to the Callback function
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_RegisterCallback(CEC_HandleTypeDef *hcec, HAL_CEC_CallbackIDTypeDef CallbackID,
|
||||
pCEC_CallbackTypeDef pCallback)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if (pCallback == NULL)
|
||||
{
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcec);
|
||||
|
||||
if (hcec->gState == HAL_CEC_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_CEC_TX_CPLT_CB_ID :
|
||||
hcec->TxCpltCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_CEC_ERROR_CB_ID :
|
||||
hcec->ErrorCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_CEC_MSPINIT_CB_ID :
|
||||
hcec->MspInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_CEC_MSPDEINIT_CB_ID :
|
||||
hcec->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (hcec->gState == HAL_CEC_STATE_RESET)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_CEC_MSPINIT_CB_ID :
|
||||
hcec->MspInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_CEC_MSPDEINIT_CB_ID :
|
||||
hcec->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hcec);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister an CEC Callback
|
||||
* CEC callback is redirected to the weak predefined callback
|
||||
* @param hcec uart handle
|
||||
* @param CallbackID ID of the callback to be unregistered
|
||||
* This parameter can be one of the following values:
|
||||
* @arg HAL_CEC_TX_CPLT_CB_ID Tx Complete callback ID
|
||||
* @arg HAL_CEC_ERROR_CB_ID Error callback ID
|
||||
* @arg HAL_CEC_MSPINIT_CB_ID MspInit callback ID
|
||||
* @arg HAL_CEC_MSPDEINIT_CB_ID MspDeInit callback ID
|
||||
* @retval status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_UnRegisterCallback(CEC_HandleTypeDef *hcec, HAL_CEC_CallbackIDTypeDef CallbackID)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcec);
|
||||
|
||||
if (hcec->gState == HAL_CEC_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_CEC_TX_CPLT_CB_ID :
|
||||
hcec->TxCpltCallback = HAL_CEC_TxCpltCallback; /* Legacy weak TxCpltCallback */
|
||||
break;
|
||||
|
||||
case HAL_CEC_ERROR_CB_ID :
|
||||
hcec->ErrorCallback = HAL_CEC_ErrorCallback; /* Legacy weak ErrorCallback */
|
||||
break;
|
||||
|
||||
case HAL_CEC_MSPINIT_CB_ID :
|
||||
hcec->MspInitCallback = HAL_CEC_MspInit;
|
||||
break;
|
||||
|
||||
case HAL_CEC_MSPDEINIT_CB_ID :
|
||||
hcec->MspDeInitCallback = HAL_CEC_MspDeInit;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (hcec->gState == HAL_CEC_STATE_RESET)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_CEC_MSPINIT_CB_ID :
|
||||
hcec->MspInitCallback = HAL_CEC_MspInit;
|
||||
break;
|
||||
|
||||
case HAL_CEC_MSPDEINIT_CB_ID :
|
||||
hcec->MspDeInitCallback = HAL_CEC_MspDeInit;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hcec);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register CEC RX complete Callback
|
||||
* To be used instead of the weak HAL_CEC_RxCpltCallback() predefined callback
|
||||
* @param hcec CEC handle
|
||||
* @param pCallback pointer to the Rx transfer compelete Callback function
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_RegisterRxCpltCallback(CEC_HandleTypeDef *hcec, pCEC_RxCallbackTypeDef pCallback)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if (pCallback == NULL)
|
||||
{
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcec);
|
||||
|
||||
if (HAL_CEC_STATE_READY == hcec->RxState)
|
||||
{
|
||||
hcec->RxCpltCallback = pCallback;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hcec);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UnRegister CEC RX complete Callback
|
||||
* CEC RX complete Callback is redirected to the weak HAL_CEC_RxCpltCallback() predefined callback
|
||||
* @param hcec CEC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CEC_UnRegisterRxCpltCallback(CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hcec);
|
||||
|
||||
if (HAL_CEC_STATE_READY == hcec->RxState)
|
||||
{
|
||||
hcec->RxCpltCallback = HAL_CEC_RxCpltCallback; /* Legacy weak CEC RxCpltCallback */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hcec);
|
||||
return status;
|
||||
}
|
||||
#endif /* USE_HAL_CEC_REGISTER_CALLBACKS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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,
|
||||
const uint8_t *pData, uint32_t Size)
|
||||
{
|
||||
/* if the peripheral 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 > 0U))
|
||||
{
|
||||
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 = (uint16_t)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 == 0U)
|
||||
{
|
||||
__HAL_CEC_LAST_BYTE_TX_SET(hcec);
|
||||
}
|
||||
|
||||
/* send header block */
|
||||
hcec->Instance->TXDR = (uint32_t)(((uint32_t)InitiatorAddress << CEC_INITIATOR_LSB_POS) | 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(const 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 itflag;
|
||||
itflag = hcec->Instance->ISR;
|
||||
|
||||
|
||||
/* ----------------------------Arbitration Lost Management----------------------------------*/
|
||||
/* CEC TX arbitration error interrupt occurred --------------------------------------*/
|
||||
if (HAL_IS_BIT_SET(itflag, CEC_FLAG_ARBLST))
|
||||
{
|
||||
hcec->ErrorCode = HAL_CEC_ERROR_ARBLST;
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_ARBLST);
|
||||
}
|
||||
|
||||
/* ----------------------------Rx Management----------------------------------*/
|
||||
/* CEC RX byte received interrupt ---------------------------------------------------*/
|
||||
if (HAL_IS_BIT_SET(itflag, CEC_FLAG_RXBR))
|
||||
{
|
||||
/* reception is starting */
|
||||
hcec->RxState = HAL_CEC_STATE_BUSY_RX;
|
||||
hcec->RxXferSize++;
|
||||
/* read received byte */
|
||||
*hcec->Init.RxBuffer = (uint8_t) hcec->Instance->RXDR;
|
||||
hcec->Init.RxBuffer++;
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXBR);
|
||||
}
|
||||
|
||||
/* CEC RX end received interrupt ---------------------------------------------------*/
|
||||
if (HAL_IS_BIT_SET(itflag, CEC_FLAG_RXEND))
|
||||
{
|
||||
/* 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;
|
||||
#if (USE_HAL_CEC_REGISTER_CALLBACKS == 1U)
|
||||
hcec->RxCpltCallback(hcec, hcec->RxXferSize);
|
||||
#else
|
||||
HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize);
|
||||
#endif /* USE_HAL_CEC_REGISTER_CALLBACKS */
|
||||
hcec->RxXferSize = 0U;
|
||||
}
|
||||
|
||||
/* ----------------------------Tx Management----------------------------------*/
|
||||
/* CEC TX byte request interrupt ------------------------------------------------*/
|
||||
if (HAL_IS_BIT_SET(itflag, CEC_FLAG_TXBR))
|
||||
{
|
||||
--hcec->TxXferCount;
|
||||
if (hcec->TxXferCount == 0U)
|
||||
{
|
||||
/* if this is the last byte transmission, set TX End of Message (TXEOM) bit */
|
||||
__HAL_CEC_LAST_BYTE_TX_SET(hcec);
|
||||
}
|
||||
/* In all cases transmit the byte */
|
||||
hcec->Instance->TXDR = (uint8_t) * hcec->pTxBuffPtr;
|
||||
hcec->pTxBuffPtr++;
|
||||
/* clear Tx-Byte request flag */
|
||||
__HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXBR);
|
||||
}
|
||||
|
||||
/* CEC TX end interrupt ------------------------------------------------*/
|
||||
if (HAL_IS_BIT_SET(itflag, CEC_FLAG_TXEND))
|
||||
{
|
||||
__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;
|
||||
#if (USE_HAL_CEC_REGISTER_CALLBACKS == 1U)
|
||||
hcec->TxCpltCallback(hcec);
|
||||
#else
|
||||
HAL_CEC_TxCpltCallback(hcec);
|
||||
#endif /* USE_HAL_CEC_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* ----------------------------Rx/Tx Error Management----------------------------------*/
|
||||
if ((itflag & (CEC_ISR_RXOVR | CEC_ISR_BRE | CEC_ISR_SBPE | CEC_ISR_LBPE | CEC_ISR_RXACKE | CEC_ISR_TXUDR |
|
||||
CEC_ISR_TXERR | CEC_ISR_TXACKE)) != 0U)
|
||||
{
|
||||
hcec->ErrorCode = itflag;
|
||||
__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 ((itflag & (CEC_ISR_RXOVR | CEC_ISR_BRE | CEC_ISR_SBPE | CEC_ISR_LBPE | CEC_ISR_RXACKE)) != 0U)
|
||||
{
|
||||
hcec->Init.RxBuffer -= hcec->RxXferSize;
|
||||
hcec->RxXferSize = 0U;
|
||||
hcec->RxState = HAL_CEC_STATE_READY;
|
||||
}
|
||||
else if (((itflag & CEC_ISR_ARBLST) == 0U) && ((itflag & (CEC_ISR_TXUDR | CEC_ISR_TXERR | CEC_ISR_TXACKE)) != 0U))
|
||||
{
|
||||
/* Set the CEC state ready to be able to start again the process */
|
||||
hcec->gState = HAL_CEC_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Nothing todo*/
|
||||
}
|
||||
#if (USE_HAL_CEC_REGISTER_CALLBACKS == 1U)
|
||||
hcec->ErrorCallback(hcec);
|
||||
#else
|
||||
/* Error Call Back */
|
||||
HAL_CEC_ErrorCallback(hcec);
|
||||
#endif /* USE_HAL_CEC_REGISTER_CALLBACKS */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Nothing todo*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(const CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
uint32_t temp1;
|
||||
uint32_t temp2;
|
||||
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(const CEC_HandleTypeDef *hcec)
|
||||
{
|
||||
return hcec->ErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* CEC */
|
||||
#endif /* HAL_CEC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,558 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_cortex.c
|
||||
* @author MCD Application Team
|
||||
* @brief CORTEX HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the CORTEX:
|
||||
* + Initialization and de-initialization functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
@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
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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;
|
||||
|
||||
/* 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 Disables the MPU
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Disable(void)
|
||||
{
|
||||
/* Make sure outstanding transfers are done */
|
||||
__DMB();
|
||||
|
||||
/* Disable fault exceptions */
|
||||
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
|
||||
/* Disable the MPU and clear the control register*/
|
||||
MPU->CTRL = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the MPU
|
||||
* @param MPU_Control Specifies the control mode of the MPU during hard fault,
|
||||
* NMI, FAULTMASK and privileged access to the default memory
|
||||
* This parameter can be one of the following values:
|
||||
* @arg MPU_HFNMI_PRIVDEF_NONE
|
||||
* @arg MPU_HARDFAULT_NMI
|
||||
* @arg MPU_PRIVILEGED_DEFAULT
|
||||
* @arg MPU_HFNMI_PRIVDEF
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Enable(uint32_t MPU_Control)
|
||||
{
|
||||
/* Enable the MPU */
|
||||
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||
|
||||
/* Enable fault exceptions */
|
||||
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
|
||||
/* Ensure MPU setting take effects */
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the MPU Region.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_EnableRegion(uint32_t RegionNumber)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU->RNR = RegionNumber;
|
||||
|
||||
/* Enable the Region */
|
||||
SET_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables the MPU Region.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_DisableRegion(uint32_t RegionNumber)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(RegionNumber));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU->RNR = RegionNumber;
|
||||
|
||||
/* Disable the Region */
|
||||
CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(const 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));
|
||||
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));
|
||||
|
||||
/* Set the Region number */
|
||||
MPU->RNR = MPU_Init->Number;
|
||||
|
||||
/* Disable the Region */
|
||||
CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
|
||||
|
||||
/* Apply configuration */
|
||||
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);
|
||||
}
|
||||
#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
|
||||
*/
|
||||
}
|
||||
|
||||
#if defined(DUAL_CORE)
|
||||
|
||||
/**
|
||||
* @brief Returns the current CPU ID.
|
||||
* @retval CPU identifier
|
||||
*/
|
||||
uint32_t HAL_GetCurrentCPUID(void)
|
||||
{
|
||||
if (((SCB->CPUID & 0x000000F0U) >> 4 )== 0x7U)
|
||||
{
|
||||
return CM7_CPUID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CM4_CPUID;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* @brief Returns the current CPU ID.
|
||||
* @retval CPU identifier
|
||||
*/
|
||||
uint32_t HAL_GetCurrentCPUID(void)
|
||||
{
|
||||
return CM7_CPUID;
|
||||
}
|
||||
|
||||
#endif /*DUAL_CORE*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,516 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_crc.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
(+) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
|
||||
(+) Initialize CRC calculator
|
||||
(++) specify generating polynomial (peripheral default or non-default one)
|
||||
(++) specify initialization value (peripheral 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
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* 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 -----------------------------------------------*/
|
||||
/** @defgroup CRC_Private_Functions CRC Private Functions
|
||||
* @{
|
||||
*/
|
||||
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 CRC_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 the CRC according to the specified parameters
|
||||
in the CRC_InitTypeDef and create the associated handle
|
||||
(+) DeInitialize the CRC peripheral
|
||||
(+) Initialize the CRC MSP (MCU Specific Package)
|
||||
(+) DeInitialize the 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);
|
||||
}
|
||||
|
||||
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 peripheral 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 peripheral 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_REG(hcrc->Instance->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 Initializes 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 CRC_Exported_Functions_Group2 Peripheral Control functions
|
||||
* @brief management 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; /* CRC input data buffer index */
|
||||
uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
|
||||
|
||||
/* 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 = 0U; 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 *)(void *)pBuffer, BufferLength); /* Derogation MisraC2012 R.11.5 */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_READY;
|
||||
|
||||
/* 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; /* CRC input data buffer index */
|
||||
uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
|
||||
|
||||
/* 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 = 0U; 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 *)(void *)pBuffer, BufferLength); /* Derogation MisraC2012 R.11.5 */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Change CRC peripheral state */
|
||||
hcrc->State = HAL_CRC_STATE_READY;
|
||||
|
||||
/* Return the CRC computed value */
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CRC_Exported_Functions_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.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the CRC handle state.
|
||||
* @param hcrc CRC handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_CRC_StateTypeDef HAL_CRC_GetState(const CRC_HandleTypeDef *hcrc)
|
||||
{
|
||||
/* Return CRC handle state */
|
||||
return hcrc->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup CRC_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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; /* input data buffer index */
|
||||
uint16_t data;
|
||||
__IO uint16_t *pReg;
|
||||
|
||||
/* 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 peripheral */
|
||||
for (i = 0U; i < (BufferLength / 4U); i++)
|
||||
{
|
||||
hcrc->Instance->DR = ((uint32_t)pBuffer[4U * i] << 24U) | \
|
||||
((uint32_t)pBuffer[(4U * i) + 1U] << 16U) | \
|
||||
((uint32_t)pBuffer[(4U * i) + 2U] << 8U) | \
|
||||
(uint32_t)pBuffer[(4U * i) + 3U];
|
||||
}
|
||||
/* last bytes specific handling */
|
||||
if ((BufferLength % 4U) != 0U)
|
||||
{
|
||||
if ((BufferLength % 4U) == 1U)
|
||||
{
|
||||
*(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[4U * i]; /* Derogation MisraC2012 R.11.5 */
|
||||
}
|
||||
if ((BufferLength % 4U) == 2U)
|
||||
{
|
||||
data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
|
||||
pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
|
||||
*pReg = data;
|
||||
}
|
||||
if ((BufferLength % 4U) == 3U)
|
||||
{
|
||||
data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
|
||||
pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
|
||||
*pReg = data;
|
||||
|
||||
*(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[(4U * i) + 2U]; /* Derogation MisraC2012 R.11.5 */
|
||||
}
|
||||
}
|
||||
|
||||
/* 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; /* input data buffer index */
|
||||
__IO uint16_t *pReg;
|
||||
|
||||
/* 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 peripheral */
|
||||
for (i = 0U; i < (BufferLength / 2U); i++)
|
||||
{
|
||||
hcrc->Instance->DR = ((uint32_t)pBuffer[2U * i] << 16U) | (uint32_t)pBuffer[(2U * i) + 1U];
|
||||
}
|
||||
if ((BufferLength % 2U) != 0U)
|
||||
{
|
||||
pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
|
||||
*pReg = pBuffer[2U * i];
|
||||
}
|
||||
|
||||
/* Return the CRC computed value */
|
||||
return hcrc->Instance->DR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_crc_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended CRC HAL module driver.
|
||||
* This file provides firmware functions to manage the extended
|
||||
* functionalities of the CRC peripheral.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
================================================================================
|
||||
##### How to use this driver #####
|
||||
================================================================================
|
||||
[..]
|
||||
(+) Set user-defined generating polynomial through HAL_CRCEx_Polynomial_Set()
|
||||
(+) Configure Input or Output data inversion
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CRCEx CRCEx
|
||||
* @brief CRC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup CRCEx_Exported_Functions CRC Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CRCEx_Exported_Functions_Group1 Extended Initialization/de-initialization functions
|
||||
* @brief Extended Initialization and Configuration functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended configuration functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure the generating polynomial
|
||||
(+) Configure the input data inversion
|
||||
(+) Configure the output data inversion
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize 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.
|
||||
* @arg for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
|
||||
* @arg 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 @ref CRC_POLYLENGTH_7B 7-bit long CRC (generating polynomial of degree 7)
|
||||
* @arg @ref CRC_POLYLENGTH_8B 8-bit long CRC (generating polynomial of degree 8)
|
||||
* @arg @ref CRC_POLYLENGTH_16B 16-bit long CRC (generating polynomial of degree 16)
|
||||
* @arg @ref 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)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint32_t msb = 31U; /* polynomial degree is 32 at most, so msb is initialized to max value */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CRC_POL_LENGTH(PolyLength));
|
||||
|
||||
/* Ensure that the generating polynomial is odd */
|
||||
if ((Pol & (uint32_t)(0x1U)) == 0U)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 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 ((msb-- > 0U) && ((Pol & ((uint32_t)(0x1U) << (msb & 0x1FU))) == 0U))
|
||||
{
|
||||
}
|
||||
|
||||
switch (PolyLength)
|
||||
{
|
||||
|
||||
case CRC_POLYLENGTH_7B:
|
||||
if (msb >= HAL_CRC_LENGTH_7B)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
break;
|
||||
case CRC_POLYLENGTH_8B:
|
||||
if (msb >= HAL_CRC_LENGTH_8B)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
break;
|
||||
case CRC_POLYLENGTH_16B:
|
||||
if (msb >= HAL_CRC_LENGTH_16B)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case CRC_POLYLENGTH_32B:
|
||||
/* no polynomial definition vs. polynomial length issue possible */
|
||||
break;
|
||||
default:
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* 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 status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 @ref CRC_INPUTDATA_INVERSION_NONE no change in bit order (default value)
|
||||
* @arg @ref CRC_INPUTDATA_INVERSION_BYTE Byte-wise bit reversal
|
||||
* @arg @ref CRC_INPUTDATA_INVERSION_HALFWORD HalfWord-wise bit reversal
|
||||
* @arg @ref 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 @ref CRC_OUTPUTDATA_INVERSION_DISABLE no CRC inversion (default value)
|
||||
* @arg @ref 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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,456 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_cryp_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended CRYP HAL module driver
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of CRYP extension peripheral:
|
||||
* + Extended AES processing functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The CRYP extension HAL driver can be used after AES-GCM or AES-CCM
|
||||
Encryption/Decryption to get the authentication messages.
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* 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
|
||||
* the AuthTag generated here is 128bits length, if the TAG length is
|
||||
* less than 128bits, user should consider only the valid part of AuthTag
|
||||
* buffer which correspond exactly to TAG length.
|
||||
* @param Timeout: Timeout duration
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, const uint32_t *AuthTag, uint32_t Timeout)
|
||||
{
|
||||
uint32_t tickstart;
|
||||
uint64_t headerlength = (uint64_t)(hcryp->Init.HeaderSize) * 32U; /* Header length in bits */
|
||||
uint64_t inputlength = (uint64_t)hcryp->SizesSum * 8U; /* Input length in bits */
|
||||
uint32_t tagaddr = (uint32_t)AuthTag;
|
||||
|
||||
/* Correct header length if Init.HeaderSize is actually in bytes */
|
||||
if (hcryp->Init.HeaderWidthUnit == CRYP_HEADERWIDTHUNIT_BYTE)
|
||||
{
|
||||
headerlength /= 4U;
|
||||
}
|
||||
|
||||
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 !defined (CRYP_VER_2_2)
|
||||
/* STM32H7 rev.B and above : data has to be inserted normally (no swapping)*/
|
||||
if (hcryp->Version >= REV_ID_B)
|
||||
#endif /*End of not defined CRYP_VER_2_2*/
|
||||
{
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = (uint32_t)(headerlength);
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = (uint32_t)(inputlength);
|
||||
}
|
||||
#if !defined (CRYP_VER_2_2)
|
||||
else/* data has to be swapped according to the DATATYPE */
|
||||
{
|
||||
if (hcryp->Init.DataType == CRYP_BIT_SWAP)
|
||||
{
|
||||
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_BYTE_SWAP)
|
||||
{
|
||||
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_HALFWORD_SWAP)
|
||||
{
|
||||
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_NO_SWAP)
|
||||
{
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = (uint32_t)(headerlength);
|
||||
hcryp->Instance->DIN = 0U;
|
||||
hcryp->Instance->DIN = (uint32_t)(inputlength);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
}
|
||||
#endif /*End of not defined CRYP_VER_2_2*/
|
||||
/* 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 (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
/* 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
|
||||
* the AuthTag generated here is 128bits length, if the TAG length is
|
||||
* less than 128bits, user should consider only the valid part of AuthTag
|
||||
* buffer which correspond exactly to TAG length.
|
||||
* @param Timeout: Timeout duration
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, const 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;
|
||||
|
||||
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 !defined (CRYP_VER_2_2)
|
||||
/*STM32H7 rev.B and above : data has to be inserted normally (no swapping)*/
|
||||
if (hcryp->Version >= REV_ID_B)
|
||||
#endif /*End of not defined CRYP_VER_2_2*/
|
||||
{
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
}
|
||||
#if !defined (CRYP_VER_2_2)
|
||||
else /* data has to be swapped according to the DATATYPE */
|
||||
{
|
||||
if (hcryp->Init.DataType == CRYP_BYTE_SWAP)
|
||||
{
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr));
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr));
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr));
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr));
|
||||
}
|
||||
else if (hcryp->Init.DataType == CRYP_HALFWORD_SWAP)
|
||||
{
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U);
|
||||
}
|
||||
else if (hcryp->Init.DataType == CRYP_BIT_SWAP)
|
||||
{
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr));
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr));
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr));
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr));
|
||||
}
|
||||
else
|
||||
{
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
ctr0addr += 4U;
|
||||
hcryp->Instance->DIN = *(uint32_t *)(ctr0addr);
|
||||
}
|
||||
}
|
||||
#endif /*End of not defined CRYP_VER_2_2*/
|
||||
/* 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 (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
/* 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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,930 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_dac_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended DAC HAL module driver.
|
||||
* This file provides firmware functions to manage the extended
|
||||
* functionalities of the DAC peripheral.
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
*** Dual mode IO operation ***
|
||||
==============================
|
||||
[..]
|
||||
(+) Use HAL_DACEx_DualStart() to enable both channel and start conversion
|
||||
for dual mode operation.
|
||||
If software trigger is selected, using HAL_DACEx_DualStart() will start
|
||||
the conversion of the value previously set by HAL_DACEx_DualSetValue().
|
||||
(+) Use HAL_DACEx_DualStop() to disable both channel and stop conversion
|
||||
for dual mode operation.
|
||||
(+) Use HAL_DACEx_DualStart_DMA() to enable both channel and start conversion
|
||||
for dual mode operation using DMA to feed DAC converters.
|
||||
First issued trigger will start the conversion of the value previously
|
||||
set by HAL_DACEx_DualSetValue().
|
||||
The same callbacks that are used in single mode are called in dual mode to notify
|
||||
transfer completion (half complete or complete), errors or underrun.
|
||||
(+) Use HAL_DACEx_DualStop_DMA() to disable both channel and stop conversion
|
||||
for dual mode operation using DMA to feed DAC converters.
|
||||
(+) 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.
|
||||
*** Signal generation operation ***
|
||||
===================================
|
||||
[..]
|
||||
(+) 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
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
|
||||
#if defined(DAC1) || defined(DAC2)
|
||||
|
||||
/** @defgroup DACEx DACEx
|
||||
* @brief DAC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Delay for DAC minimum trimming time. */
|
||||
/* Note: minimum time needed between two calibration steps */
|
||||
/* The delay below is specified under conditions: */
|
||||
/* - DAC channel output buffer enabled */
|
||||
/* Literal set to maximum value (refer to device datasheet, */
|
||||
/* electrical characteristics, parameter "tTRIM"). */
|
||||
/* Unit: us */
|
||||
#define DAC_DELAY_TRIM_US (50UL) /*!< Delay for DAC minimum trimming time */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* 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.
|
||||
(+) Stop conversion.
|
||||
(+) Start conversion and enable DMA transfer.
|
||||
(+) Stop conversion and disable DMA transfer.
|
||||
(+) Get result of conversion.
|
||||
(+) Get result of dual mode conversion.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables DAC and starts conversion of both channels.
|
||||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac)
|
||||
{
|
||||
uint32_t tmp_swtrig = 0UL;
|
||||
|
||||
/* Check the DAC peripheral handle */
|
||||
if (hdac == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdac);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_BUSY;
|
||||
|
||||
/* Enable the Peripheral */
|
||||
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_1);
|
||||
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_2);
|
||||
|
||||
/* Check if software trigger enabled */
|
||||
if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE)
|
||||
{
|
||||
tmp_swtrig |= DAC_SWTRIGR_SWTRIG1;
|
||||
}
|
||||
if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (DAC_CHANNEL_2 & 0x10UL)))
|
||||
{
|
||||
tmp_swtrig |= DAC_SWTRIGR_SWTRIG2;
|
||||
}
|
||||
/* Enable the selected DAC software conversion*/
|
||||
SET_BIT(hdac->Instance->SWTRIGR, tmp_swtrig);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_READY;
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hdac);
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables DAC and stop conversion of both channels.
|
||||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac)
|
||||
{
|
||||
/* Check the DAC peripheral handle */
|
||||
if (hdac == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_1);
|
||||
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_READY;
|
||||
|
||||
/* Return function status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables DAC and starts conversion of both channel 1 and 2 of the same DAC.
|
||||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @param Channel The DAC channel that will request data from DMA.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
||||
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
||||
* @param pData The destination peripheral Buffer address.
|
||||
* @param Length The length of data to be transferred from memory to DAC peripheral
|
||||
* @param Alignment Specifies the data alignment for DAC channel.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
|
||||
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
|
||||
* @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DACEx_DualStart_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel,
|
||||
const uint32_t *pData, uint32_t Length, uint32_t Alignment)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
uint32_t tmpreg = 0UL;
|
||||
|
||||
/* Check the DAC peripheral handle */
|
||||
if (hdac == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
assert_param(IS_DAC_ALIGN(Alignment));
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdac);
|
||||
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_BUSY;
|
||||
|
||||
if (Channel == DAC_CHANNEL_1)
|
||||
{
|
||||
/* Set the DMA transfer complete callback for channel1 */
|
||||
hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
|
||||
|
||||
/* Set the DMA half transfer complete callback for channel1 */
|
||||
hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
|
||||
|
||||
/* Set the DMA error callback for channel1 */
|
||||
hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
|
||||
|
||||
/* Enable the selected DAC channel1 DMA request */
|
||||
SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the DMA transfer complete callback for channel2 */
|
||||
hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2;
|
||||
|
||||
/* Set the DMA half transfer complete callback for channel2 */
|
||||
hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2;
|
||||
|
||||
/* Set the DMA error callback for channel2 */
|
||||
hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2;
|
||||
|
||||
/* Enable the selected DAC channel2 DMA request */
|
||||
SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2);
|
||||
}
|
||||
|
||||
switch (Alignment)
|
||||
{
|
||||
case DAC_ALIGN_12B_R:
|
||||
/* Get DHR12R1 address */
|
||||
tmpreg = (uint32_t)&hdac->Instance->DHR12RD;
|
||||
break;
|
||||
case DAC_ALIGN_12B_L:
|
||||
/* Get DHR12L1 address */
|
||||
tmpreg = (uint32_t)&hdac->Instance->DHR12LD;
|
||||
break;
|
||||
case DAC_ALIGN_8B_R:
|
||||
/* Get DHR8R1 address */
|
||||
tmpreg = (uint32_t)&hdac->Instance->DHR8RD;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Enable the DMA channel */
|
||||
if (Channel == DAC_CHANNEL_1)
|
||||
{
|
||||
/* Enable the DAC DMA underrun interrupt */
|
||||
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
|
||||
|
||||
/* Enable the DMA channel */
|
||||
status = HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Enable the DAC DMA underrun interrupt */
|
||||
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
|
||||
|
||||
/* Enable the DMA channel */
|
||||
status = HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
|
||||
}
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdac);
|
||||
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable the Peripheral */
|
||||
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_1);
|
||||
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_2);
|
||||
}
|
||||
else
|
||||
{
|
||||
hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables DAC and stop conversion both channel.
|
||||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DAC.
|
||||
* @param Channel The DAC channel that requests data from DMA.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
||||
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DACEx_DualStop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
/* Check the DAC peripheral handle */
|
||||
if (hdac == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Disable the selected DAC channel DMA request */
|
||||
CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN2 | DAC_CR_DMAEN1);
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_1);
|
||||
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2);
|
||||
|
||||
/* Disable the DMA channel */
|
||||
|
||||
/* Channel1 is used */
|
||||
if (Channel == DAC_CHANNEL_1)
|
||||
{
|
||||
/* Disable the DMA channel */
|
||||
status = HAL_DMA_Abort(hdac->DMA_Handle1);
|
||||
|
||||
/* Disable the DAC DMA underrun interrupt */
|
||||
__HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the DMA channel */
|
||||
status = HAL_DMA_Abort(hdac->DMA_Handle2);
|
||||
|
||||
/* Disable the DAC DMA underrun interrupt */
|
||||
__HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR2);
|
||||
}
|
||||
|
||||
/* Check if DMA Channel effectively disabled */
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
/* Update DAC state machine to error */
|
||||
hdac->State = HAL_DAC_STATE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Change DAC state */
|
||||
hdac->State = HAL_DAC_STATE_READY;
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 DAC peripheral handle */
|
||||
if (hdac == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* 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 & 0x10UL),
|
||||
(DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL));
|
||||
|
||||
/* 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 DAC peripheral handle */
|
||||
if (hdac == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* 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 & 0x10UL),
|
||||
(DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL));
|
||||
|
||||
/* 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 Channel1 to be loaded in the selected data holding register.
|
||||
* @param Data2 Data for DAC Channel2 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;
|
||||
uint32_t tmp;
|
||||
|
||||
/* Check the DAC peripheral handle */
|
||||
if (hdac == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* 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 << 8U) | Data1;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = ((uint32_t)Data2 << 16U) | 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;
|
||||
|
||||
uint32_t trimmingvalue;
|
||||
uint32_t delta;
|
||||
__IO uint32_t wait_loop_index;
|
||||
|
||||
/* store/restore channel configuration structure purpose */
|
||||
uint32_t oldmodeconfiguration;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
|
||||
/* Check the DAC handle allocation */
|
||||
/* Check if DAC running */
|
||||
if ((hdac == NULL) || (sConfig == NULL))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else if (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 & 0x10UL)));
|
||||
|
||||
/* Disable the selected DAC channel */
|
||||
CLEAR_BIT((hdac->Instance->CR), (DAC_CR_EN1 << (Channel & 0x10UL)));
|
||||
|
||||
/* Set mode in MCR for calibration */
|
||||
MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), 0U);
|
||||
|
||||
/* Enable the selected DAC channel calibration */
|
||||
/* i.e. set DAC_CR_CENx bit */
|
||||
SET_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
|
||||
|
||||
/* Init trimming counter */
|
||||
/* Medium value */
|
||||
trimmingvalue = 0x10UL;
|
||||
delta = 0x08UL;
|
||||
while (delta != 0UL)
|
||||
{
|
||||
/* Set candidate trimming */
|
||||
MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
|
||||
|
||||
/* Wait minimum time needed between two calibration steps (OTRIM) */
|
||||
/* Wait loop initialization and execution */
|
||||
/* Note: Variable divided by 2 to compensate partially CPU processing cycles, scaling in us split to not exceed */
|
||||
/* 32 bits register capacity and handle low frequency. */
|
||||
wait_loop_index = ((DAC_DELAY_TRIM_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
|
||||
while (wait_loop_index != 0UL)
|
||||
{
|
||||
wait_loop_index--;
|
||||
}
|
||||
|
||||
if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL)))
|
||||
{
|
||||
/* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
|
||||
trimmingvalue -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DAC_SR_CAL_FLAGx is LOW try lower trimming */
|
||||
trimmingvalue += delta;
|
||||
}
|
||||
delta >>= 1UL;
|
||||
}
|
||||
|
||||
/* 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 & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
|
||||
|
||||
/* Wait minimum time needed between two calibration steps (OTRIM) */
|
||||
/* Wait loop initialization and execution */
|
||||
/* Note: Variable divided by 2 to compensate partially CPU processing cycles, scaling in us split to not exceed */
|
||||
/* 32 bits register capacity and handle low frequency. */
|
||||
wait_loop_index = ((DAC_DELAY_TRIM_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
|
||||
while (wait_loop_index != 0UL)
|
||||
{
|
||||
wait_loop_index--;
|
||||
}
|
||||
|
||||
if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == 0UL)
|
||||
{
|
||||
/* Check trimming value below maximum */
|
||||
if (trimmingvalue < 0x1FU)
|
||||
{
|
||||
/* Trimming is actually one value more */
|
||||
trimmingvalue++;
|
||||
}
|
||||
/* Set right trimming */
|
||||
MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
|
||||
}
|
||||
|
||||
/* Disable the selected DAC channel calibration */
|
||||
/* i.e. clear DAC_CR_CENx bit */
|
||||
CLEAR_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
|
||||
|
||||
sConfig->DAC_TrimmingValue = trimmingvalue;
|
||||
sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
|
||||
|
||||
/* Restore configuration */
|
||||
MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), 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 and channel configuration struct allocation */
|
||||
if ((hdac == NULL) || (sConfig == NULL))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdac);
|
||||
|
||||
/* Set new trimming */
|
||||
MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (NewTrimmingValue << (Channel & 0x10UL)));
|
||||
|
||||
/* 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 TrimmingValue Value between Min_Data=0x00 and Max_Data=0x1F
|
||||
*/
|
||||
uint32_t HAL_DACEx_GetTrimOffset(const DAC_HandleTypeDef *hdac, uint32_t Channel)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_DAC_CHANNEL(Channel));
|
||||
|
||||
/* Retrieve trimming */
|
||||
return ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << (Channel & 0x10UL))) >> (Channel & 0x10UL));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
|
||||
* @brief Extended Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) 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(const DAC_HandleTypeDef *hdac)
|
||||
{
|
||||
uint32_t tmp = 0UL;
|
||||
|
||||
tmp |= hdac->Instance->DOR1;
|
||||
|
||||
tmp |= hdac->Instance->DOR2 << 16UL;
|
||||
|
||||
/* 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;
|
||||
|
||||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
|
||||
hdac->ConvCpltCallbackCh2(hdac);
|
||||
#else
|
||||
HAL_DACEx_ConvCpltCallbackCh2(hdac);
|
||||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
|
||||
|
||||
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 */
|
||||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
|
||||
hdac->ConvHalfCpltCallbackCh2(hdac);
|
||||
#else
|
||||
HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
|
||||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
|
||||
hdac->ErrorCallbackCh2(hdac);
|
||||
#else
|
||||
HAL_DACEx_ErrorCallbackCh2(hdac);
|
||||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
|
||||
|
||||
hdac->State = HAL_DAC_STATE_READY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* DAC1 || DAC2 */
|
||||
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_dfsdm_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief DFSDM Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionality of the DFSDM Peripheral Controller:
|
||||
* + Set and get pulses skipping on channel.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_DFSDM_MODULE_ENABLED
|
||||
|
||||
#if defined(DFSDM_CHDLYR_PLSSKP)
|
||||
|
||||
/** @defgroup DFSDMEx DFSDMEx
|
||||
* @brief DFSDM Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup DFSDMEx_Exported_Functions DFSDM Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DFSDMEx_Exported_Functions_Group1_Channel Extended channel operation functions
|
||||
* @brief DFSDM extended channel operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended channel operation functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Set and get value of pulses skipping on channel
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set value of pulses skipping.
|
||||
* @param hdfsdm_channel DFSDM channel handle.
|
||||
* @param PulsesValue Value of pulses to be skipped.
|
||||
* This parameter must be a number between Min_Data = 0 and Max_Data = 63.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DFDSMEx_ChannelSetPulsesSkipping(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, uint32_t PulsesValue)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check pulses value */
|
||||
assert_param(IS_DFSDM_CHANNEL_SKIPPING_VALUE(PulsesValue));
|
||||
|
||||
/* Check DFSDM channel state */
|
||||
if (hdfsdm_channel->State == HAL_DFSDM_CHANNEL_STATE_READY)
|
||||
{
|
||||
/* Set new value of pulses skipping */
|
||||
hdfsdm_channel->Instance->CHDLYR = (PulsesValue & DFSDM_CHDLYR_PLSSKP);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get value of pulses skipping.
|
||||
* @param hdfsdm_channel DFSDM channel handle.
|
||||
* @param PulsesValue Value of pulses to be skipped.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DFDSMEx_ChannelGetPulsesSkipping(const DFSDM_Channel_HandleTypeDef *hdfsdm_channel, uint32_t *PulsesValue)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check DFSDM channel state */
|
||||
if (hdfsdm_channel->State == HAL_DFSDM_CHANNEL_STATE_READY)
|
||||
{
|
||||
/* Get value of remaining pulses to be skipped */
|
||||
*PulsesValue = (hdfsdm_channel->Instance->CHDLYR & DFSDM_CHDLYR_PLSSKP);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* DFSDM_CHDLYR_PLSSKP */
|
||||
|
||||
#endif /* HAL_DFSDM_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,712 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_dma_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief DMA Extension HAL module driver
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the DMA Extension peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
@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 possible with DMA and BDMA instances.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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 ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/** @addtogroup DMAEx_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions ---------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup DMAEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup DMAEx_Exported_Functions_Group1
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Extended features functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure the source, destination address and data length and
|
||||
Start MultiBuffer DMA transfer
|
||||
(+) Configure the source, destination address and data length and
|
||||
Start MultiBuffer DMA transfer with interrupt
|
||||
(+) Change on the fly the memory0 or memory1 address.
|
||||
(+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
|
||||
(+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
|
||||
(+) Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
|
||||
to respectively enable/disable the request generator.
|
||||
(+) Handle DMAMUX interrupts using HAL_DMAEx_MUX_IRQHandler : should be called from
|
||||
the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler or DMAMUX2_OVR_IRQHandler
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Starts the multi_buffer DMA Transfer.
|
||||
* @param hdma : pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param SrcAddress: The source memory Buffer address
|
||||
* @param DstAddress: The destination memory Buffer address
|
||||
* @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint32_t *ifcRegister_Base; /* DMA Stream Interrupt Clear register */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
|
||||
assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
/* Memory-to-memory transfer not supported in double buffering mode */
|
||||
if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
|
||||
{
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if(HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
/* Change DMA peripheral state */
|
||||
hdma->State = HAL_DMA_STATE_BUSY;
|
||||
|
||||
/* Initialize the error code */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||
|
||||
if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
|
||||
{
|
||||
/* Enable the Double buffer mode */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_SxCR_DBM;
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
|
||||
|
||||
/* Calculate the interrupt clear flag register (IFCR) base address */
|
||||
ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
|
||||
|
||||
/* Clear all flags */
|
||||
*ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);
|
||||
}
|
||||
else /* BDMA instance(s) */
|
||||
{
|
||||
/* Enable the Double buffer mode */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CCR |= (BDMA_CCR_DBM | BDMA_CCR_CIRC);
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CM1AR = SecondMemAddress;
|
||||
|
||||
/* Calculate the interrupt clear flag register (IFCR) base address */
|
||||
ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 4U));
|
||||
|
||||
/* Clear all flags */
|
||||
*ifcRegister_Base = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);
|
||||
}
|
||||
|
||||
if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
|
||||
{
|
||||
/* Configure the source, destination address and the data length */
|
||||
DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
|
||||
|
||||
/* Clear the DMAMUX synchro overrun flag */
|
||||
hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
|
||||
|
||||
if(hdma->DMAmuxRequestGen != 0U)
|
||||
{
|
||||
/* Clear the DMAMUX request generator overrun flag */
|
||||
hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable the peripheral */
|
||||
__HAL_DMA_ENABLE(hdma);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts the multi_buffer DMA Transfer with interrupt enabled.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param SrcAddress: The source memory Buffer address
|
||||
* @param DstAddress: The destination memory Buffer address
|
||||
* @param SecondMemAddress: The second memory Buffer address in case of multi buffer Transfer
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
__IO uint32_t *ifcRegister_Base; /* DMA Stream Interrupt Clear register */
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
|
||||
assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
/* Memory-to-memory transfer not supported in double buffering mode */
|
||||
if(hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
|
||||
{
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if(HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
/* Change DMA peripheral state */
|
||||
hdma->State = HAL_DMA_STATE_BUSY;
|
||||
|
||||
/* Initialize the error code */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||
|
||||
if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
|
||||
{
|
||||
/* Enable the Double buffer mode */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_SxCR_DBM;
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
|
||||
|
||||
/* Calculate the interrupt clear flag register (IFCR) base address */
|
||||
ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
|
||||
|
||||
/* Clear all flags */
|
||||
*ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);
|
||||
}
|
||||
else /* BDMA instance(s) */
|
||||
{
|
||||
/* Enable the Double buffer mode */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CCR |= (BDMA_CCR_DBM | BDMA_CCR_CIRC);
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CM1AR = SecondMemAddress;
|
||||
|
||||
/* Calculate the interrupt clear flag register (IFCR) base address */
|
||||
ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 4U));
|
||||
|
||||
/* Clear all flags */
|
||||
*ifcRegister_Base = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);
|
||||
}
|
||||
|
||||
/* Configure the source, destination address and the data length */
|
||||
DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
|
||||
|
||||
if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
|
||||
{
|
||||
/* Enable Common interrupts*/
|
||||
MODIFY_REG(((DMA_Stream_TypeDef *)hdma->Instance)->CR, (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT), (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME));
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->FCR |= DMA_IT_FE;
|
||||
|
||||
if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
|
||||
{
|
||||
/*Enable Half Transfer IT if corresponding Callback is set*/
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_IT_HT;
|
||||
}
|
||||
}
|
||||
else /* BDMA instance(s) */
|
||||
{
|
||||
/* Enable Common interrupts*/
|
||||
MODIFY_REG(((BDMA_Channel_TypeDef *)hdma->Instance)->CCR, (BDMA_CCR_TCIE | BDMA_CCR_HTIE | BDMA_CCR_TEIE), (BDMA_CCR_TCIE | BDMA_CCR_TEIE));
|
||||
|
||||
if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
|
||||
{
|
||||
/*Enable Half Transfer IT if corresponding Callback is set*/
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CCR |= BDMA_CCR_HTIE;
|
||||
}
|
||||
}
|
||||
|
||||
if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U) /* No DMAMUX available for BDMA1 */
|
||||
{
|
||||
/* Check if DMAMUX Synchronization is enabled*/
|
||||
if((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)
|
||||
{
|
||||
/* Enable DMAMUX sync overrun IT*/
|
||||
hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;
|
||||
}
|
||||
|
||||
if(hdma->DMAmuxRequestGen != 0U)
|
||||
{
|
||||
/* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/
|
||||
/* enable the request gen overrun IT*/
|
||||
hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable the peripheral */
|
||||
__HAL_DMA_ENABLE(hdma);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Change the memory0 or memory1 address on the fly.
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param Address: The new address
|
||||
* @param memory: the memory to be changed, This parameter can be one of
|
||||
* the following values:
|
||||
* MEMORY0 /
|
||||
* MEMORY1
|
||||
* @note The MEMORY0 address can be changed only when the current transfer use
|
||||
* MEMORY1 and the MEMORY1 address can be changed only when the current
|
||||
* transfer use MEMORY0.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
|
||||
{
|
||||
if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
else /* BDMA instance(s) */
|
||||
{
|
||||
if(memory == MEMORY0)
|
||||
{
|
||||
/* change the memory0 address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = Address;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* change the memory1 address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CM1AR = 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_DMAMUX_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_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
|
||||
{
|
||||
assert_param(IS_DMA_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_BDMA_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
|
||||
}
|
||||
syncSignalID = pSyncConfig->SyncSignalID;
|
||||
syncPolarity = pSyncConfig->SyncPolarity;
|
||||
}
|
||||
|
||||
/*Check if the DMA state is ready */
|
||||
if(hdma->State == HAL_DMA_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
/* Disable the synchronization and event generation before applying a new config */
|
||||
CLEAR_BIT(hdma->DMAmuxChannel->CCR,(DMAMUX_CxCR_SE | DMAMUX_CxCR_EGE));
|
||||
|
||||
/* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
|
||||
MODIFY_REG( hdma->DMAmuxChannel->CCR, \
|
||||
(~DMAMUX_CxCR_DMAREQ_ID) , \
|
||||
(syncSignalID << DMAMUX_CxCR_SYNC_ID_Pos) | \
|
||||
((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
|
||||
syncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
|
||||
((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* Return error status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the DMAMUX request generator block used by the given DMA stream (instance).
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
|
||||
* contains the request generator parameters.
|
||||
*
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
HAL_DMA_StateTypeDef temp_state = hdma->State;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));
|
||||
|
||||
if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
|
||||
{
|
||||
assert_param(IS_DMA_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_param(IS_BDMA_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
|
||||
}
|
||||
|
||||
|
||||
assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
|
||||
assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
|
||||
|
||||
/* check if the DMA state is ready
|
||||
and DMA is using a DMAMUX request generator block
|
||||
*/
|
||||
if(hdma->DMAmuxRequestGen == 0U)
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_PARAM;
|
||||
|
||||
/* error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else if(((hdma->DMAmuxRequestGen->RGCR & DMAMUX_RGxCR_GE) == 0U) && (temp_state == HAL_DMA_STATE_READY))
|
||||
{
|
||||
/* RequestGenerator must be disable prior to the configuration i.e GE bit is 0 */
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
/* Set the request generator new parameters */
|
||||
hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
|
||||
((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \
|
||||
pRequestGeneratorConfig->Polarity;
|
||||
/* Process Locked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the error code to busy */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
|
||||
|
||||
/* error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the DMAMUX request generator block used by the given DMA stream (instance).
|
||||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified DMA Stream.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DMA_DMAMUX_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_DMAMUX_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)
|
||||
{
|
||||
if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U) /* DMA1 or DMA2 instance */
|
||||
{
|
||||
/* Configure DMA Stream data length */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->NDTR = DataLength;
|
||||
|
||||
/* Peripheral to Memory */
|
||||
if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
|
||||
{
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->PAR = DstAddress;
|
||||
|
||||
/* Configure DMA Stream source address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = SrcAddress;
|
||||
}
|
||||
/* Memory to Peripheral */
|
||||
else
|
||||
{
|
||||
/* Configure DMA Stream source address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->PAR = SrcAddress;
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = DstAddress;
|
||||
}
|
||||
}
|
||||
else /* BDMA instance(s) */
|
||||
{
|
||||
/* Configure DMA Stream data length */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CNDTR = DataLength;
|
||||
|
||||
/* Peripheral to Memory */
|
||||
if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
|
||||
{
|
||||
/* Configure DMA Stream destination address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CPAR = DstAddress;
|
||||
|
||||
/* Configure DMA Stream source address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = SrcAddress;
|
||||
}
|
||||
/* Memory to Peripheral */
|
||||
else
|
||||
{
|
||||
/* Configure DMA Stream source address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CPAR = SrcAddress;
|
||||
|
||||
/* Configure DMA Stream destination address */
|
||||
((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = DstAddress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,981 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_dts.c
|
||||
* @author MCD Application Team
|
||||
* @brief DTS HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the DTS 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
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
================================================================================
|
||||
##### DTS Peripheral features #####
|
||||
================================================================================
|
||||
|
||||
[..]
|
||||
The STM32h7xx device family integrate one DTS sensor interface :
|
||||
|
||||
|
||||
##### How to use this driver #####
|
||||
================================================================================
|
||||
[..]
|
||||
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_DTS_MODULE_ENABLED
|
||||
|
||||
#if defined(DTS)
|
||||
|
||||
/** @defgroup DTS DTS
|
||||
* @brief DTS HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @addtogroup DTS_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* @brief Delay for DTS startup time
|
||||
* @note Delay required to get ready for DTS Block.
|
||||
* @note Unit: ms
|
||||
*/
|
||||
#define DTS_DELAY_STARTUP (1UL)
|
||||
|
||||
/* @brief DTS measure ready flag time out value.
|
||||
* @note Maximal measurement time is when LSE is selected as ref_clock and
|
||||
* maximal sampling time is used, taking calibration into account this
|
||||
* is equivalent to ~620 us. Use 5 ms as arbitrary timeout
|
||||
* @note Unit: ms
|
||||
*/
|
||||
#define TS_TIMEOUT_MS (5UL)
|
||||
|
||||
/* @brief DTS factory temperatures
|
||||
* @note Unit: degree Celsius
|
||||
*/
|
||||
#define DTS_FACTORY_TEMPERATURE1 (30UL)
|
||||
#define DTS_FACTORY_TEMPERATURE2 (130UL)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup DTS_Exported_Functions DTS Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DTS_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 DTS according to the specified
|
||||
* parameters in the DTS_InitTypeDef and initialize the associated handle.
|
||||
* @param hdts DTS handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_Init(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Check the DTS handle allocation */
|
||||
if (hdts == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_DTS_ALL_INSTANCE(hdts->Instance));
|
||||
assert_param(IS_DTS_QUICKMEAS(hdts->Init.QuickMeasure));
|
||||
assert_param(IS_DTS_REFCLK(hdts->Init.RefClock));
|
||||
assert_param(IS_DTS_TRIGGERINPUT(hdts->Init.TriggerInput));
|
||||
assert_param(IS_DTS_SAMPLINGTIME(hdts->Init.SamplingTime));
|
||||
assert_param(IS_DTS_THRESHOLD(hdts->Init.HighThreshold));
|
||||
assert_param(IS_DTS_THRESHOLD(hdts->Init.LowThreshold));
|
||||
|
||||
if (hdts->State == HAL_DTS_STATE_RESET)
|
||||
{
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
/* Reset the DTS callback to the legacy weak callbacks */
|
||||
hdts->EndCallback = HAL_DTS_EndCallback; /* End measure Callback */
|
||||
hdts->LowCallback = HAL_DTS_LowCallback; /* low threshold Callback */
|
||||
hdts->HighCallback = HAL_DTS_HighCallback; /* high threshold Callback */
|
||||
hdts->AsyncEndCallback = HAL_DTS_AsyncEndCallback; /* Asynchronous end of measure Callback */
|
||||
hdts->AsyncLowCallback = HAL_DTS_AsyncLowCallback; /* Asynchronous low threshold Callback */
|
||||
hdts->AsyncHighCallback = HAL_DTS_AsyncHighCallback; /* Asynchronous high threshold Callback */
|
||||
|
||||
if (hdts->MspInitCallback == NULL)
|
||||
{
|
||||
hdts->MspInitCallback = HAL_DTS_MspInit;
|
||||
}
|
||||
|
||||
/* Init the low level hardware : GPIO, CLOCK, NVIC */
|
||||
hdts->MspInitCallback(hdts);
|
||||
#else
|
||||
/* Init the low level hardware : GPIO, CLOCK, NVIC */
|
||||
HAL_DTS_MspInit(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* Change the DTS state */
|
||||
hdts->State = HAL_DTS_STATE_BUSY;
|
||||
|
||||
/* Check ramp coefficient */
|
||||
if (hdts->Instance->RAMPVALR == 0UL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check factory calibration temperature */
|
||||
if (hdts->Instance->T0VALR1 == 0UL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check Quick Measure option is enabled or disabled */
|
||||
if (hdts->Init.QuickMeasure == DTS_QUICKMEAS_DISABLE)
|
||||
{
|
||||
/* Check Reference clock selection */
|
||||
if (hdts->Init.RefClock == DTS_REFCLKSEL_PCLK)
|
||||
{
|
||||
assert_param(IS_DTS_DIVIDER_RATIO_NUMBER(hdts->Init.Divider));
|
||||
}
|
||||
/* Quick measurement mode disabled */
|
||||
CLEAR_BIT(hdts->Instance->CFGR1, DTS_CFGR1_Q_MEAS_OPT);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DTS_QUICKMEAS_ENABLE shall be used only when the LSE clock is
|
||||
selected as reference clock */
|
||||
if (hdts->Init.RefClock != DTS_REFCLKSEL_LSE)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Quick measurement mode enabled - no calibration needed */
|
||||
SET_BIT(hdts->Instance->CFGR1, DTS_CFGR1_Q_MEAS_OPT);
|
||||
}
|
||||
|
||||
/* set the DTS clk source */
|
||||
if (hdts->Init.RefClock == DTS_REFCLKSEL_LSE)
|
||||
{
|
||||
SET_BIT(hdts->Instance->CFGR1, DTS_CFGR1_REFCLK_SEL);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLEAR_BIT(hdts->Instance->CFGR1, DTS_CFGR1_REFCLK_SEL);
|
||||
}
|
||||
|
||||
MODIFY_REG(hdts->Instance->CFGR1, DTS_CFGR1_HSREF_CLK_DIV, (hdts->Init.Divider << DTS_CFGR1_HSREF_CLK_DIV_Pos));
|
||||
MODIFY_REG(hdts->Instance->CFGR1, DTS_CFGR1_TS1_SMP_TIME, hdts->Init.SamplingTime);
|
||||
MODIFY_REG(hdts->Instance->CFGR1, DTS_CFGR1_TS1_INTRIG_SEL, hdts->Init.TriggerInput);
|
||||
MODIFY_REG(hdts->Instance->ITR1, DTS_ITR1_TS1_HITTHD, (hdts->Init.HighThreshold << DTS_ITR1_TS1_HITTHD_Pos));
|
||||
MODIFY_REG(hdts->Instance->ITR1, DTS_ITR1_TS1_LITTHD, hdts->Init.LowThreshold);
|
||||
|
||||
/* Change the DTS state */
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the DTS peripheral.
|
||||
* @note Deinitialization cannot be performed if the DTS configuration is locked.
|
||||
* To unlock the configuration, perform a system reset.
|
||||
* @param hdts DTS handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_DeInit(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Check the DTS handle allocation */
|
||||
if (hdts == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_DTS_ALL_INSTANCE(hdts->Instance));
|
||||
|
||||
/* Set DTS_CFGR register to reset value */
|
||||
CLEAR_REG(hdts->Instance->CFGR1);
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
if (hdts->MspDeInitCallback == NULL)
|
||||
{
|
||||
hdts->MspDeInitCallback = HAL_DTS_MspDeInit;
|
||||
}
|
||||
|
||||
/* DeInit the low level hardware: CLOCK, NVIC.*/
|
||||
hdts->MspDeInitCallback(hdts);
|
||||
#else
|
||||
/* DeInit the low level hardware: CLOCK, NVIC.*/
|
||||
HAL_DTS_MspDeInit(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
|
||||
hdts->State = HAL_DTS_STATE_RESET;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the DTS MSP.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_MspInit(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_MspInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the DTS MSP.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_MspDeInit(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_MspDeInit could be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
/**
|
||||
* @brief Register a user DTS callback to be used instead of the weak predefined callback.
|
||||
* @param hdts DTS handle.
|
||||
* @param CallbackID ID of the callback to be registered.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_DTS_MEAS_COMPLETE_CB_ID measure complete callback ID.
|
||||
* @arg @ref HAL_DTS_ASYNC_MEAS_COMPLETE_CB_ID asynchronous measure complete callback ID.
|
||||
* @arg @ref HAL_DTS_LOW_THRESHOLD_CB_ID low threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_ASYNC_LOW_THRESHOLD_CB_ID asynchronous low threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_HIGH_THRESHOLD_CB_ID high threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_ASYNC_HIGH_THRESHOLD_CB_ID asynchronous high threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_MSPINIT_CB_ID MSP init callback ID.
|
||||
* @arg @ref HAL_DTS_MSPDEINIT_CB_ID MSP de-init callback ID.
|
||||
* @param pCallback pointer to the callback function.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_RegisterCallback(DTS_HandleTypeDef *hdts,
|
||||
HAL_DTS_CallbackIDTypeDef CallbackID,
|
||||
pDTS_CallbackTypeDef pCallback)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check parameters */
|
||||
if (pCallback == NULL)
|
||||
{
|
||||
/* Update status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hdts->State == HAL_DTS_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_DTS_MEAS_COMPLETE_CB_ID :
|
||||
hdts->EndCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_ASYNC_MEAS_COMPLETE_CB_ID :
|
||||
hdts->AsyncEndCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_LOW_THRESHOLD_CB_ID :
|
||||
hdts->LowCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_ASYNC_LOW_THRESHOLD_CB_ID :
|
||||
hdts->AsyncLowCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_HIGH_THRESHOLD_CB_ID :
|
||||
hdts->HighCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_ASYNC_HIGH_THRESHOLD_CB_ID :
|
||||
hdts->AsyncHighCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_MSPINIT_CB_ID :
|
||||
hdts->MspInitCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_MSPDEINIT_CB_ID :
|
||||
hdts->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
default :
|
||||
/* Update status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (hdts->State == HAL_DTS_STATE_RESET)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_DTS_MSPINIT_CB_ID :
|
||||
hdts->MspInitCallback = pCallback;
|
||||
break;
|
||||
case HAL_DTS_MSPDEINIT_CB_ID :
|
||||
hdts->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
default :
|
||||
/* Update status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister a user DTS callback.
|
||||
* DTS callback is redirected to the weak predefined callback.
|
||||
* @param hdts DTS handle.
|
||||
* @param CallbackID ID of the callback to be unregistered.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_DTS_MEAS_COMPLETE_CB_ID measure complete callback ID.
|
||||
* @arg @ref HAL_DTS_ASYNC_MEAS_COMPLETE_CB_ID asynchronous measure complete callback ID.
|
||||
* @arg @ref HAL_DTS_LOW_THRESHOLD_CB_ID low threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_ASYNC_LOW_THRESHOLD_CB_ID asynchronous low threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_HIGH_THRESHOLD_CB_ID high threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_ASYNC_HIGH_THRESHOLD_CB_ID asynchronous high threshold detection callback ID.
|
||||
* @arg @ref HAL_DTS_MSPINIT_CB_ID MSP init callback ID.
|
||||
* @arg @ref HAL_DTS_MSPDEINIT_CB_ID MSP de-init callback ID.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_UnRegisterCallback(DTS_HandleTypeDef *hdts,
|
||||
HAL_DTS_CallbackIDTypeDef CallbackID)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if (hdts->State == HAL_DTS_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_DTS_MEAS_COMPLETE_CB_ID :
|
||||
hdts->EndCallback = HAL_DTS_EndCallback;
|
||||
break;
|
||||
case HAL_DTS_ASYNC_MEAS_COMPLETE_CB_ID :
|
||||
hdts->AsyncEndCallback = HAL_DTS_AsyncEndCallback;
|
||||
break;
|
||||
case HAL_DTS_LOW_THRESHOLD_CB_ID :
|
||||
hdts->LowCallback = HAL_DTS_LowCallback;
|
||||
break;
|
||||
case HAL_DTS_ASYNC_LOW_THRESHOLD_CB_ID :
|
||||
hdts->AsyncLowCallback = HAL_DTS_AsyncLowCallback;
|
||||
break;
|
||||
case HAL_DTS_HIGH_THRESHOLD_CB_ID :
|
||||
hdts->HighCallback = HAL_DTS_HighCallback;
|
||||
break;
|
||||
case HAL_DTS_ASYNC_HIGH_THRESHOLD_CB_ID :
|
||||
hdts->AsyncHighCallback = HAL_DTS_AsyncHighCallback;
|
||||
break;
|
||||
case HAL_DTS_MSPINIT_CB_ID :
|
||||
hdts->MspInitCallback = HAL_DTS_MspInit;
|
||||
break;
|
||||
case HAL_DTS_MSPDEINIT_CB_ID :
|
||||
hdts->MspDeInitCallback = HAL_DTS_MspDeInit;
|
||||
break;
|
||||
default :
|
||||
/* Update status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (hdts->State == HAL_DTS_STATE_RESET)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_DTS_MSPINIT_CB_ID :
|
||||
hdts->MspInitCallback = HAL_DTS_MspInit;
|
||||
break;
|
||||
case HAL_DTS_MSPDEINIT_CB_ID :
|
||||
hdts->MspDeInitCallback = HAL_DTS_MspDeInit;
|
||||
break;
|
||||
default :
|
||||
/* Update status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup DTS_Exported_Functions_Group2 Start-Stop operation functions
|
||||
* @brief Start-Stop operation functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### DTS Start Stop operation functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Start a DTS Sensor without interrupt.
|
||||
(+) Stop a DTS Sensor without interrupt.
|
||||
(+) Start a DTS Sensor with interrupt generation.
|
||||
(+) Stop a DTS Sensor with interrupt generation.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Start the DTS sensor.
|
||||
* @param hdts DTS handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_Start(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
uint32_t Ref_Time;
|
||||
|
||||
/* Check the DTS handle allocation */
|
||||
if (hdts == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (hdts->State == HAL_DTS_STATE_READY)
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_BUSY;
|
||||
|
||||
/* Enable DTS sensor */
|
||||
__HAL_DTS_ENABLE(hdts);
|
||||
|
||||
/* Get Start Tick*/
|
||||
Ref_Time = HAL_GetTick();
|
||||
|
||||
/* Wait till TS1_RDY flag is set */
|
||||
while (__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_RDY) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - Ref_Time) > DTS_DELAY_STARTUP)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
if (__HAL_DTS_GET_TRIGGER(hdts) == DTS_TRIGGER_HW_NONE)
|
||||
{
|
||||
/* Start continuous measures */
|
||||
SET_BIT(hdts->Instance->CFGR1, DTS_CFGR1_TS1_START);
|
||||
|
||||
/* Ensure start is taken into account */
|
||||
HAL_Delay(TS_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the DTS Sensor.
|
||||
* @param hdts DTS handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_Stop(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Check the DTS handle allocation */
|
||||
if (hdts == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (hdts->State == HAL_DTS_STATE_READY)
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_BUSY;
|
||||
|
||||
if (__HAL_DTS_GET_TRIGGER(hdts) == DTS_TRIGGER_HW_NONE)
|
||||
{
|
||||
CLEAR_BIT(hdts->Instance->CFGR1, DTS_CFGR1_TS1_START);
|
||||
}
|
||||
|
||||
/* Disable the selected DTS sensor */
|
||||
__HAL_DTS_DISABLE(hdts);
|
||||
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the interrupt(s) and start the DTS sensor
|
||||
* @param hdts DTS handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_Start_IT(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
uint32_t Ref_Time;
|
||||
|
||||
/* Check the DTS handle allocation */
|
||||
if (hdts == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (hdts->State == HAL_DTS_STATE_READY)
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_BUSY;
|
||||
|
||||
/* On Asynchronous mode enable the asynchronous IT */
|
||||
if (hdts->Init.RefClock == DTS_REFCLKSEL_LSE)
|
||||
{
|
||||
__HAL_DTS_ENABLE_IT(hdts, DTS_IT_TS1_AITE | DTS_IT_TS1_AITL | DTS_IT_TS1_AITH);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Enable the IT(s) */
|
||||
__HAL_DTS_ENABLE_IT(hdts, DTS_IT_TS1_ITE | DTS_IT_TS1_ITL | DTS_IT_TS1_ITH);
|
||||
}
|
||||
|
||||
/* Enable the selected DTS sensor */
|
||||
__HAL_DTS_ENABLE(hdts);
|
||||
|
||||
/* Get Start Tick*/
|
||||
Ref_Time = HAL_GetTick();
|
||||
|
||||
/* Wait till TS1_RDY flag is set */
|
||||
while (__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_RDY) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - Ref_Time) > DTS_DELAY_STARTUP)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
if (__HAL_DTS_GET_TRIGGER(hdts) == DTS_TRIGGER_HW_NONE)
|
||||
{
|
||||
/* Start continuous measures */
|
||||
SET_BIT(hdts->Instance->CFGR1, DTS_CFGR1_TS1_START);
|
||||
|
||||
/* Ensure start is taken into account */
|
||||
HAL_Delay(TS_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the interrupt(s) and stop the DTS sensor.
|
||||
* @param hdts DTS handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_Stop_IT(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Check the DTS handle allocation */
|
||||
if (hdts == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (hdts->State == HAL_DTS_STATE_READY)
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_BUSY;
|
||||
|
||||
/* On Asynchronous mode disable the asynchronous IT */
|
||||
if (hdts->Init.RefClock == DTS_REFCLKSEL_LSE)
|
||||
{
|
||||
__HAL_DTS_DISABLE_IT(hdts, DTS_IT_TS1_AITE | DTS_IT_TS1_AITL | DTS_IT_TS1_AITH);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the IT(s) */
|
||||
__HAL_DTS_DISABLE_IT(hdts, DTS_IT_TS1_ITE | DTS_IT_TS1_ITL | DTS_IT_TS1_ITH);
|
||||
}
|
||||
|
||||
if (__HAL_DTS_GET_TRIGGER(hdts) == DTS_TRIGGER_HW_NONE)
|
||||
{
|
||||
CLEAR_BIT(hdts->Instance->CFGR1, DTS_CFGR1_TS1_START);
|
||||
}
|
||||
|
||||
/* Disable the selected DTS sensor */
|
||||
__HAL_DTS_DISABLE(hdts);
|
||||
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get temperature from DTS
|
||||
* @param hdts DTS handle
|
||||
* @param Temperature Temperature in deg C
|
||||
* @note This function retrieves latest available measure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DTS_GetTemperature(DTS_HandleTypeDef *hdts, int32_t *Temperature)
|
||||
{
|
||||
uint32_t freq_meas;
|
||||
uint32_t samples;
|
||||
uint32_t t0_temp;
|
||||
uint32_t t0_freq;
|
||||
uint32_t ramp_coeff;
|
||||
|
||||
if (hdts->State == HAL_DTS_STATE_READY)
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_BUSY;
|
||||
|
||||
/* Get the total number of samples */
|
||||
samples = (hdts->Instance->DR & DTS_DR_TS1_MFREQ);
|
||||
|
||||
if ((hdts->Init.SamplingTime == 0UL) || (samples == 0UL))
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((hdts->Init.RefClock) == DTS_REFCLKSEL_LSE)
|
||||
{
|
||||
freq_meas = (LSE_VALUE * samples) / (hdts->Init.SamplingTime >> DTS_CFGR1_TS1_SMP_TIME_Pos); /* On Hz */
|
||||
}
|
||||
else
|
||||
{
|
||||
freq_meas = (HAL_RCCEx_GetD3PCLK1Freq() * (hdts->Init.SamplingTime >> DTS_CFGR1_TS1_SMP_TIME_Pos)) / samples; /* On Hz */
|
||||
}
|
||||
|
||||
/* Read factory settings */
|
||||
t0_temp = hdts->Instance->T0VALR1 >> DTS_T0VALR1_TS1_T0_Pos;
|
||||
|
||||
if (t0_temp == 0UL)
|
||||
{
|
||||
t0_temp = DTS_FACTORY_TEMPERATURE1; /* 30 deg C */
|
||||
}
|
||||
else if (t0_temp == 1UL)
|
||||
{
|
||||
t0_temp = DTS_FACTORY_TEMPERATURE2; /* 130 deg C */
|
||||
}
|
||||
else
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
t0_freq = (hdts->Instance->T0VALR1 & DTS_T0VALR1_TS1_FMT0) * 100UL; /* Hz */
|
||||
|
||||
ramp_coeff = hdts->Instance->RAMPVALR & DTS_RAMPVALR_TS1_RAMP_COEFF; /* deg C/Hz */
|
||||
|
||||
if (ramp_coeff == 0UL)
|
||||
{
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Figure out the temperature deg C */
|
||||
*Temperature = (int32_t)t0_temp + (((int32_t)freq_meas - (int32_t)t0_freq) / (int32_t)ramp_coeff);
|
||||
|
||||
hdts->State = HAL_DTS_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DTS sensor IRQ Handler.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DTS_IRQHandler(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Check end of measure Asynchronous IT */
|
||||
if ((__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_AITE)) != RESET)
|
||||
{
|
||||
__HAL_DTS_CLEAR_FLAG(hdts, DTS_FLAG_TS1_AITE);
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
hdts->AsyncEndCallback(hdts);
|
||||
#else
|
||||
HAL_DTS_AsyncEndCallback(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* Check low threshold Asynchronous IT */
|
||||
if ((__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_AITL)) != RESET)
|
||||
{
|
||||
__HAL_DTS_CLEAR_FLAG(hdts, DTS_FLAG_TS1_AITL);
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
hdts->AsyncLowCallback(hdts);
|
||||
#else
|
||||
HAL_DTS_AsyncLowCallback(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* Check high threshold Asynchronous IT */
|
||||
if ((__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_AITH)) != RESET)
|
||||
{
|
||||
__HAL_DTS_CLEAR_FLAG(hdts, DTS_FLAG_TS1_AITH);
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
hdts->AsyncHighCallback(hdts);
|
||||
#else
|
||||
HAL_DTS_AsyncHighCallback(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* Check end of measure IT */
|
||||
if ((__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_ITE)) != RESET)
|
||||
{
|
||||
__HAL_DTS_CLEAR_FLAG(hdts, DTS_FLAG_TS1_ITE);
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
hdts->EndCallback(hdts);
|
||||
#else
|
||||
HAL_DTS_EndCallback(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* Check low threshold IT */
|
||||
if ((__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_ITL)) != RESET)
|
||||
{
|
||||
__HAL_DTS_CLEAR_FLAG(hdts, DTS_FLAG_TS1_ITL);
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
hdts->LowCallback(hdts);
|
||||
#else
|
||||
HAL_DTS_LowCallback(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* Check high threshold IT */
|
||||
if ((__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_ITH)) != RESET)
|
||||
{
|
||||
__HAL_DTS_CLEAR_FLAG(hdts, DTS_FLAG_TS1_ITH);
|
||||
|
||||
#if (USE_HAL_DTS_REGISTER_CALLBACKS == 1)
|
||||
hdts->HighCallback(hdts);
|
||||
#else
|
||||
HAL_DTS_HighCallback(hdts);
|
||||
#endif /* USE_HAL_DTS_REGISTER_CALLBACKS */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DTS Sensor End measure callback.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_EndCallback(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_EndCallback should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DTS Sensor low threshold measure callback.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_LowCallback(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_LowCallback should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DTS Sensor high threshold measure callback.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_HighCallback(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_HighCallback should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DTS Sensor asynchronous end measure callback.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_AsyncEndCallback(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_AsyncEndCallback should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DTS Sensor asynchronous low threshold measure callback.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_AsyncLowCallback(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_AsyncLowCallback should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DTS Sensor asynchronous high threshold measure callback.
|
||||
* @param hdts DTS handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_DTS_AsyncHighCallback(DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hdts);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_DTS_AsyncHighCallback should be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup DTS_Exported_Functions_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.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the DTS handle state.
|
||||
* @param hdts DTS handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_DTS_StateTypeDef HAL_DTS_GetState(const DTS_HandleTypeDef *hdts)
|
||||
{
|
||||
/* Check the DTS handle allocation */
|
||||
if (hdts == NULL)
|
||||
{
|
||||
return HAL_DTS_STATE_RESET;
|
||||
}
|
||||
|
||||
/* Return DTS handle state */
|
||||
return hdts->State;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* DTS */
|
||||
|
||||
#endif /* HAL_DTS_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,660 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_eth_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief ETH HAL Extended module driver.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_ETH_MODULE_ENABLED
|
||||
|
||||
#if defined(ETH)
|
||||
|
||||
/** @defgroup ETHEx ETHEx
|
||||
* @brief ETH HAL Extended module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* 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)
|
||||
|
||||
#define ETH_MAC_L4_SRSP_MASK 0x0000FFFFU
|
||||
#define ETH_MAC_L4_DSTP_MASK 0xFFFF0000U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* 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,
|
||||
const ETH_L4FilterConfigTypeDef *pL4FilterConfig)
|
||||
{
|
||||
if (pL4FilterConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (Filter == ETH_L4_FILTER_0)
|
||||
{
|
||||
/* Write configuration to MACL3L4C0R register */
|
||||
MODIFY_REG(heth->Instance->MACL3L4C0R, ETH_MACL4CR_MASK, (pL4FilterConfig->Protocol |
|
||||
pL4FilterConfig->SrcPortFilterMatch |
|
||||
pL4FilterConfig->DestPortFilterMatch));
|
||||
|
||||
/* Write configuration to MACL4A0R register */
|
||||
WRITE_REG(heth->Instance->MACL4A0R, (pL4FilterConfig->SourcePort | (pL4FilterConfig->DestinationPort << 16)));
|
||||
|
||||
}
|
||||
else /* Filter == ETH_L4_FILTER_1 */
|
||||
{
|
||||
/* Write configuration to MACL3L4C1R register */
|
||||
MODIFY_REG(heth->Instance->MACL3L4C1R, ETH_MACL4CR_MASK, (pL4FilterConfig->Protocol |
|
||||
pL4FilterConfig->SrcPortFilterMatch |
|
||||
pL4FilterConfig->DestPortFilterMatch));
|
||||
|
||||
/* Write configuration to MACL4A1R register */
|
||||
WRITE_REG(heth->Instance->MACL4A1R, (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(const ETH_HandleTypeDef *heth, uint32_t Filter,
|
||||
ETH_L4FilterConfigTypeDef *pL4FilterConfig)
|
||||
{
|
||||
if (pL4FilterConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (Filter == ETH_L4_FILTER_0)
|
||||
{
|
||||
/* Get configuration from MACL3L4C0R register */
|
||||
pL4FilterConfig->Protocol = READ_BIT(heth->Instance->MACL3L4C0R, ETH_MACL3L4CR_L4PEN);
|
||||
pL4FilterConfig->DestPortFilterMatch = READ_BIT(heth->Instance->MACL3L4C0R,
|
||||
(ETH_MACL3L4CR_L4DPM | ETH_MACL3L4CR_L4DPIM));
|
||||
pL4FilterConfig->SrcPortFilterMatch = READ_BIT(heth->Instance->MACL3L4C0R,
|
||||
(ETH_MACL3L4CR_L4SPM | ETH_MACL3L4CR_L4SPIM));
|
||||
|
||||
/* Get configuration from MACL4A0R register */
|
||||
pL4FilterConfig->DestinationPort = (READ_BIT(heth->Instance->MACL4A0R, ETH_MAC_L4_DSTP_MASK) >> 16);
|
||||
pL4FilterConfig->SourcePort = READ_BIT(heth->Instance->MACL4A0R, ETH_MAC_L4_SRSP_MASK);
|
||||
}
|
||||
else /* Filter == ETH_L4_FILTER_1 */
|
||||
{
|
||||
/* Get configuration from MACL3L4C1R register */
|
||||
pL4FilterConfig->Protocol = READ_BIT(heth->Instance->MACL3L4C1R, ETH_MACL3L4CR_L4PEN);
|
||||
pL4FilterConfig->DestPortFilterMatch = READ_BIT(heth->Instance->MACL3L4C1R,
|
||||
(ETH_MACL3L4CR_L4DPM | ETH_MACL3L4CR_L4DPIM));
|
||||
pL4FilterConfig->SrcPortFilterMatch = READ_BIT(heth->Instance->MACL3L4C1R,
|
||||
(ETH_MACL3L4CR_L4SPM | ETH_MACL3L4CR_L4SPIM));
|
||||
|
||||
/* Get configuration from MACL4A1R register */
|
||||
pL4FilterConfig->DestinationPort = (READ_BIT(heth->Instance->MACL4A1R, ETH_MAC_L4_DSTP_MASK) >> 16);
|
||||
pL4FilterConfig->SourcePort = READ_BIT(heth->Instance->MACL4A1R, ETH_MAC_L4_SRSP_MASK);
|
||||
}
|
||||
|
||||
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,
|
||||
const ETH_L3FilterConfigTypeDef *pL3FilterConfig)
|
||||
{
|
||||
if (pL3FilterConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (Filter == ETH_L3_FILTER_0)
|
||||
{
|
||||
/* Write configuration to MACL3L4C0R register */
|
||||
MODIFY_REG(heth->Instance->MACL3L4C0R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
|
||||
pL3FilterConfig->SrcAddrFilterMatch |
|
||||
pL3FilterConfig->DestAddrFilterMatch |
|
||||
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
|
||||
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
|
||||
}
|
||||
else /* Filter == ETH_L3_FILTER_1 */
|
||||
{
|
||||
/* Write configuration to MACL3L4C1R register */
|
||||
MODIFY_REG(heth->Instance->MACL3L4C1R, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
|
||||
pL3FilterConfig->SrcAddrFilterMatch |
|
||||
pL3FilterConfig->DestAddrFilterMatch |
|
||||
(pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
|
||||
(pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
|
||||
}
|
||||
|
||||
if (Filter == ETH_L3_FILTER_0)
|
||||
{
|
||||
/* 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 */
|
||||
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip6Addr[0]);
|
||||
/* Set Bits[63:32] of 128-bit IP addr */
|
||||
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip6Addr[1]);
|
||||
/* update Bits[95:64] of 128-bit IP addr */
|
||||
WRITE_REG(heth->Instance->MACL3A2R0R, pL3FilterConfig->Ip6Addr[2]);
|
||||
/* update Bits[127:96] of 128-bit IP addr */
|
||||
WRITE_REG(heth->Instance->MACL3A3R0R, pL3FilterConfig->Ip6Addr[3]);
|
||||
}
|
||||
else /* IPv4 protocol is selected */
|
||||
{
|
||||
/* Set the IPv4 source address match */
|
||||
WRITE_REG(heth->Instance->MACL3A0R0R, pL3FilterConfig->Ip4SrcAddr);
|
||||
/* Set the IPv4 destination address match */
|
||||
WRITE_REG(heth->Instance->MACL3A1R0R, pL3FilterConfig->Ip4DestAddr);
|
||||
}
|
||||
}
|
||||
else /* Filter == ETH_L3_FILTER_1 */
|
||||
{
|
||||
/* 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 */
|
||||
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip6Addr[0]);
|
||||
/* Set Bits[63:32] of 128-bit IP addr */
|
||||
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[1]);
|
||||
/* update Bits[95:64] of 128-bit IP addr */
|
||||
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[2]);
|
||||
/* update Bits[127:96] of 128-bit IP addr */
|
||||
WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[3]);
|
||||
}
|
||||
else /* IPv4 protocol is selected */
|
||||
{
|
||||
/* Set the IPv4 source address match */
|
||||
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4SrcAddr);
|
||||
/* Set the IPv4 destination address match */
|
||||
WRITE_REG(heth->Instance->MACL3A0R1R, pL3FilterConfig->Ip4DestAddr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable L3 filter */
|
||||
SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
|
||||
|
||||
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(const 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 (Filter == ETH_L3_FILTER_0)
|
||||
{
|
||||
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
|
||||
{
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[0], heth->Instance->MACL3A0R0R);
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[1], heth->Instance->MACL3A1R0R);
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[2], heth->Instance->MACL3A2R0R);
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[3], heth->Instance->MACL3A3R0R);
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE_REG(pL3FilterConfig->Ip4SrcAddr, heth->Instance->MACL3A0R0R);
|
||||
WRITE_REG(pL3FilterConfig->Ip4DestAddr, heth->Instance->MACL3A1R0R);
|
||||
}
|
||||
}
|
||||
else /* ETH_L3_FILTER_1 */
|
||||
{
|
||||
if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
|
||||
{
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[0], heth->Instance->MACL3A0R1R);
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[1], heth->Instance->MACL3A1R1R);
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[2], heth->Instance->MACL3A2R1R);
|
||||
WRITE_REG(pL3FilterConfig->Ip6Addr[3], heth->Instance->MACL3A3R1R);
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE_REG(pL3FilterConfig->Ip4SrcAddr, heth->Instance->MACL3A0R1R);
|
||||
WRITE_REG(pL3FilterConfig->Ip4DestAddr, heth->Instance->MACL3A1R1R);
|
||||
}
|
||||
}
|
||||
|
||||
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(const ETH_HandleTypeDef *heth, ETH_RxVLANConfigTypeDef *pVlanConfig)
|
||||
{
|
||||
if (pVlanConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
pVlanConfig->InnerVLANTagInStatus = ((READ_BIT(heth->Instance->MACVTR,
|
||||
ETH_MACVTR_EIVLRXS) >> 31) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->StripInnerVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLS);
|
||||
pVlanConfig->InnerVLANTag = ((READ_BIT(heth->Instance->MACVTR,
|
||||
ETH_MACVTR_ERIVLT) >> 27) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->DoubleVLANProcessing = ((READ_BIT(heth->Instance->MACVTR,
|
||||
ETH_MACVTR_EDVLP) >> 26) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->VLANTagHashTableMatch = ((READ_BIT(heth->Instance->MACVTR,
|
||||
ETH_MACVTR_VTHM) >> 25) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->VLANTagInStatus = ((READ_BIT(heth->Instance->MACVTR,
|
||||
ETH_MACVTR_EVLRXS) >> 24) == 0U) ? DISABLE : ENABLE;
|
||||
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 = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTIM) >> 17) == 0U)
|
||||
? DISABLE : ENABLE;
|
||||
|
||||
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(const ETH_HandleTypeDef *heth, uint32_t VLANTag,
|
||||
ETH_TxVLANConfigTypeDef *pVlanConfig)
|
||||
{
|
||||
if (pVlanConfig == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (VLANTag == ETH_INNER_TX_VLANTAG)
|
||||
{
|
||||
pVlanConfig->SourceTxDesc = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACIVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVlanConfig->SourceTxDesc = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
|
||||
pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
|
||||
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,
|
||||
const 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/Disable automate enter/exit LPI mode.
|
||||
* @param TxClockStop: Enable/Disable 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(const ETH_HandleTypeDef *heth)
|
||||
{
|
||||
return heth->MACLPIEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ETH */
|
||||
|
||||
#endif /* HAL_ETH_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,865 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_exti.c
|
||||
* @author MCD Application Team
|
||||
* @brief EXTI HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the General Purpose Input/Output (EXTI) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + IO operation functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### EXTI Peripheral features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) Each Exti line can be configured within this driver.
|
||||
|
||||
(+) Exti line can be configured in 3 different modes
|
||||
(++) Interrupt (CORE1 or CORE2 in case of dual core line )
|
||||
(++) Event (CORE1 or CORE2 in case of dual core line )
|
||||
(++) a combination of the previous
|
||||
|
||||
(+) Configurable Exti lines can be configured with 3 different triggers
|
||||
(++) Rising
|
||||
(++) Falling
|
||||
(++) Both of them
|
||||
|
||||
(+) When set in interrupt mode, configurable Exti lines have two diffenrents
|
||||
interrupt pending registers which allow to distinguish which transition
|
||||
occurs:
|
||||
(++) Rising edge pending interrupt
|
||||
(++) Falling
|
||||
|
||||
(+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can
|
||||
be selected through multiplexer.
|
||||
|
||||
(+) PendClearSource used to set the D3 Smart Run Domain autoamtic pend clear source.
|
||||
It is applicable for line with wkaeup target is Any (CPU1 , CPU2 and D3 smart run domain).
|
||||
Value can be one of the following:
|
||||
(++) EXTI_D3_PENDCLR_SRC_NONE : no pend clear source is selected :
|
||||
In this case corresponding bit of D2PMRx register is set to 0
|
||||
(+++) On a configurable Line : the D3 domain wakeup signal is
|
||||
automatically cleared after after the Delay + Rising Edge detect
|
||||
(+++) On a direct Line : the D3 domain wakeup signal is
|
||||
cleared after the direct event input signal is cleared
|
||||
|
||||
(++) EXTI_D3_PENDCLR_SRC_DMACH6 : no pend clear source is selected :
|
||||
In this case corresponding bit of D2PMRx register is set to 1
|
||||
and corresponding bits(2) of D3PCRxL/H is set to b00 :
|
||||
DMA ch6 event selected as D3 domain pendclear source
|
||||
|
||||
(++) EXTI_D3_PENDCLR_SRC_DMACH7 : no pend clear source is selected :
|
||||
In this case corresponding bit of D2PMRx register is set to 1
|
||||
and corresponding bits(2) of D3PCRxL/H is set to b01 :
|
||||
DMA ch7 event selected as D3 domain pendclear source
|
||||
|
||||
(++) EXTI_D3_PENDCLR_SRC_LPTIM4 : no pend clear source is selected :
|
||||
In this case corresponding bit of D2PMRx register is set to 1
|
||||
and corresponding bits(2) of D3PCRxL/H is set to b10 :
|
||||
LPTIM4 out selected as D3 domain pendclear source
|
||||
|
||||
(++) EXTI_D3_PENDCLR_SRC_LPTIM5 : no pend clear source is selected :
|
||||
In this case corresponding bit of D2PMRx register is set to 1
|
||||
and corresponding bits(2) of D3PCRxL/H is set to b11 :
|
||||
LPTIM5 out selected as D3 domain pendclear source
|
||||
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
|
||||
(#) Configure the EXTI line using HAL_EXTI_SetConfigLine().
|
||||
(++) Choose the interrupt line number by setting "Line" member from
|
||||
EXTI_ConfigTypeDef structure.
|
||||
(++) Configure the interrupt and/or event mode using "Mode" member from
|
||||
EXTI_ConfigTypeDef structure.
|
||||
(++) For configurable lines, configure rising and/or falling trigger
|
||||
"Trigger" member from EXTI_ConfigTypeDef structure.
|
||||
(++) For Exti lines linked to gpio, choose gpio port using "GPIOSel"
|
||||
member from GPIO_InitTypeDef structure.
|
||||
(++) For Exti lines with wkaeup target is Any (CPU1 , CPU2 and D3 smart run domain),
|
||||
choose gpio D3 PendClearSource using PendClearSource
|
||||
member from EXTI_PendClear_Source structure.
|
||||
|
||||
(#) Get current Exti configuration of a dedicated line using
|
||||
HAL_EXTI_GetConfigLine().
|
||||
(++) Provide exiting handle as parameter.
|
||||
(++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter.
|
||||
|
||||
(#) Clear Exti configuration of a dedicated line using HAL_EXTI_ClearConfigLine().
|
||||
(++) Provide exiting handle as parameter.
|
||||
|
||||
(#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback().
|
||||
(++) Provide exiting handle as first parameter.
|
||||
(++) Provide which callback will be registered using one value from
|
||||
EXTI_CallbackIDTypeDef.
|
||||
(++) Provide callback function pointer.
|
||||
|
||||
(#) Get interrupt pending bit using HAL_EXTI_GetPending().
|
||||
|
||||
(#) Clear interrupt pending bit using HAL_EXTI_ClearPending().
|
||||
|
||||
(#) Generate software interrupt using HAL_EXTI_GenerateSWI().
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private defines ------------------------------------------------------------*/
|
||||
/** @defgroup EXTI_Private_Constants EXTI Private Constants
|
||||
* @{
|
||||
*/
|
||||
#define EXTI_MODE_OFFSET 0x04U /* 0x10: offset between CPU IMR/EMR registers */
|
||||
#define EXTI_CONFIG_OFFSET 0x08U /* 0x20: offset between CPU Rising/Falling configuration registers */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup EXTI_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI_Exported_Functions_Group1
|
||||
* @brief Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Configuration functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set configuration of a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @param pExtiConfig Pointer on EXTI configuration to be set.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
uint32_t pcrlinepos;
|
||||
|
||||
/* Check null pointer */
|
||||
if ((hexti == NULL) || (pExtiConfig == NULL))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(pExtiConfig->Line));
|
||||
assert_param(IS_EXTI_MODE(pExtiConfig->Mode));
|
||||
|
||||
/* Assign line number to handle */
|
||||
hexti->Line = pExtiConfig->Line;
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* Configure triggers for configurable lines */
|
||||
if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00U)
|
||||
{
|
||||
assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
|
||||
|
||||
/* Configure rising trigger */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x00U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store rising trigger mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* Configure falling trigger */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x00U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store falling trigger mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* Configure gpio port selection in case of gpio exti line */
|
||||
if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
|
||||
{
|
||||
assert_param(IS_EXTI_GPIO_PORT(pExtiConfig->GPIOSel));
|
||||
assert_param(IS_EXTI_GPIO_PIN(linepos));
|
||||
|
||||
regval = SYSCFG->EXTICR[(linepos >> 2U) & 0x03UL];
|
||||
regval &= ~(SYSCFG_EXTICR1_EXTI0 << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
|
||||
regval |= (pExtiConfig->GPIOSel << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
|
||||
SYSCFG->EXTICR[(linepos >> 2U) & 0x03UL] = regval;
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure interrupt mode : read current mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x00U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store interrupt mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* The event mode cannot be configured if the line does not support it */
|
||||
assert_param(((pExtiConfig->Line & EXTI_EVENT) == EXTI_EVENT) || ((pExtiConfig->Mode & EXTI_MODE_EVENT) != EXTI_MODE_EVENT));
|
||||
|
||||
/* Configure event mode : read current mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0x00U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store event mode */
|
||||
*regaddr = regval;
|
||||
|
||||
#if defined (DUAL_CORE)
|
||||
/* Configure interrupt mode for Core2 : read current mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_CORE2_INTERRUPT) != 0x00U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store interrupt mode */
|
||||
*regaddr = regval;
|
||||
|
||||
/* The event mode cannot be configured if the line does not support it */
|
||||
assert_param(((pExtiConfig->Line & EXTI_EVENT) == EXTI_EVENT) || ((pExtiConfig->Mode & EXTI_MODE_CORE2_EVENT) != EXTI_MODE_CORE2_EVENT));
|
||||
|
||||
/* Configure event mode : read current mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Mask or set line */
|
||||
if ((pExtiConfig->Mode & EXTI_MODE_CORE2_EVENT) != 0x00U)
|
||||
{
|
||||
regval |= maskline;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~maskline;
|
||||
}
|
||||
|
||||
/* Store event mode */
|
||||
*regaddr = regval;
|
||||
#endif /* DUAL_CORE */
|
||||
|
||||
/* Configure the D3 PendClear source in case of Wakeup target is Any */
|
||||
if ((pExtiConfig->Line & EXTI_TARGET_MASK) == EXTI_TARGET_MSK_ALL)
|
||||
{
|
||||
assert_param(IS_EXTI_D3_PENDCLR_SRC(pExtiConfig->PendClearSource));
|
||||
|
||||
/*Calc the PMR register address for the given line */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PMR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
if(pExtiConfig->PendClearSource == EXTI_D3_PENDCLR_SRC_NONE)
|
||||
{
|
||||
/* Clear D3PMRx register for the given line */
|
||||
regval &= ~maskline;
|
||||
/* Store D3PMRx register value */
|
||||
*regaddr = regval;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set D3PMRx register to 1 for the given line */
|
||||
regval |= maskline;
|
||||
/* Store D3PMRx register value */
|
||||
*regaddr = regval;
|
||||
|
||||
if(linepos < 16UL)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PCR1L + (EXTI_CONFIG_OFFSET * offset));
|
||||
pcrlinepos = 1UL << linepos;
|
||||
}
|
||||
else
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PCR1H + (EXTI_CONFIG_OFFSET * offset));
|
||||
pcrlinepos = 1UL << (linepos - 16UL);
|
||||
}
|
||||
|
||||
regval = (*regaddr & (~(pcrlinepos * pcrlinepos * 3UL))) | (pcrlinepos * pcrlinepos * (pExtiConfig->PendClearSource - 1UL));
|
||||
*regaddr = regval;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get configuration of a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @param pExtiConfig Pointer on structure to store Exti configuration.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
uint32_t pcrlinepos;
|
||||
|
||||
/* Check null pointer */
|
||||
if ((hexti == NULL) || (pExtiConfig == NULL))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
|
||||
/* Store handle line number to configuration structure */
|
||||
pExtiConfig->Line = hexti->Line;
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* 1] Get core mode : interrupt */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
pExtiConfig->Mode = EXTI_MODE_NONE;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0x00U)
|
||||
{
|
||||
pExtiConfig->Mode = EXTI_MODE_INTERRUPT;
|
||||
}
|
||||
|
||||
/* Get event mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0x00U)
|
||||
{
|
||||
pExtiConfig->Mode |= EXTI_MODE_EVENT;
|
||||
}
|
||||
#if defined (DUAL_CORE)
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0x00U)
|
||||
{
|
||||
pExtiConfig->Mode = EXTI_MODE_CORE2_INTERRUPT;
|
||||
}
|
||||
|
||||
/* Get event mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if selected line is enable */
|
||||
if ((regval & maskline) != 0x00U)
|
||||
{
|
||||
pExtiConfig->Mode |= EXTI_MODE_CORE2_EVENT;
|
||||
}
|
||||
#endif /*DUAL_CORE*/
|
||||
|
||||
/* Get default Trigger and GPIOSel configuration */
|
||||
pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
|
||||
pExtiConfig->GPIOSel = 0x00U;
|
||||
|
||||
/* 2] Get trigger for configurable lines : rising */
|
||||
if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00U)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if configuration of selected line is enable */
|
||||
if ((regval & maskline) != 0x00U)
|
||||
{
|
||||
pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
|
||||
}
|
||||
|
||||
/* Get falling configuration */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = *regaddr;
|
||||
|
||||
/* Check if configuration of selected line is enable */
|
||||
if ((regval & maskline) != 0x00U)
|
||||
{
|
||||
pExtiConfig->Trigger |= EXTI_TRIGGER_FALLING;
|
||||
}
|
||||
|
||||
/* Get Gpio port selection for gpio lines */
|
||||
if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
|
||||
{
|
||||
assert_param(IS_EXTI_GPIO_PIN(linepos));
|
||||
|
||||
regval = SYSCFG->EXTICR[(linepos >> 2U) & 0x03UL];
|
||||
pExtiConfig->GPIOSel = (regval >> (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u))) & SYSCFG_EXTICR1_EXTI0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get default Pend Clear Source */
|
||||
pExtiConfig->PendClearSource = EXTI_D3_PENDCLR_SRC_NONE;
|
||||
|
||||
/* 3] Get D3 Pend Clear source */
|
||||
if ((pExtiConfig->Line & EXTI_TARGET_MASK) == EXTI_TARGET_MSK_ALL)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PMR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
if(((*regaddr) & linepos) != 0UL)
|
||||
{
|
||||
/* if wakeup target is any and PMR set, the read pend clear source from D3PCRxL/H */
|
||||
if(linepos < 16UL)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PCR1L + (EXTI_CONFIG_OFFSET * offset));
|
||||
pcrlinepos = 1UL << linepos;
|
||||
}
|
||||
else
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PCR1H + (EXTI_CONFIG_OFFSET * offset));
|
||||
pcrlinepos = 1UL << (linepos - 16UL);
|
||||
}
|
||||
|
||||
pExtiConfig->PendClearSource = 1UL + ((*regaddr & (pcrlinepos * pcrlinepos * 3UL)) / (pcrlinepos * pcrlinepos));
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear whole configuration of a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(const EXTI_HandleTypeDef *hexti)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
uint32_t pcrlinepos;
|
||||
|
||||
/* Check null pointer */
|
||||
if (hexti == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameter */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (hexti->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
/* 1] Clear interrupt mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* 2] Clear event mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
#if defined (DUAL_CORE)
|
||||
/* 1] Clear CM4 interrupt mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2IMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* 2] Clear CM4 event mode */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2EMR1 + (EXTI_MODE_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
#endif /* DUAL_CORE */
|
||||
|
||||
/* 3] Clear triggers in case of configurable lines */
|
||||
if ((hexti->Line & EXTI_CONFIG) != 0x00U)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
regaddr = (__IO uint32_t *)(&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
regval = (*regaddr & ~maskline);
|
||||
*regaddr = regval;
|
||||
|
||||
/* Get Gpio port selection for gpio lines */
|
||||
if ((hexti->Line & EXTI_GPIO) == EXTI_GPIO)
|
||||
{
|
||||
assert_param(IS_EXTI_GPIO_PIN(linepos));
|
||||
|
||||
regval = SYSCFG->EXTICR[(linepos >> 2U) & 0x03UL];
|
||||
regval &= ~(SYSCFG_EXTICR1_EXTI0 << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03UL)));
|
||||
SYSCFG->EXTICR[(linepos >> 2U) & 0x03UL] = regval;
|
||||
}
|
||||
}
|
||||
|
||||
/* 4] Clear D3 Config lines */
|
||||
if ((hexti->Line & EXTI_TARGET_MASK) == EXTI_TARGET_MSK_ALL)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PMR1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
*regaddr = (*regaddr & ~maskline);
|
||||
|
||||
if(linepos < 16UL)
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PCR1L + (EXTI_CONFIG_OFFSET * offset));
|
||||
pcrlinepos = 1UL << linepos;
|
||||
}
|
||||
else
|
||||
{
|
||||
regaddr = (__IO uint32_t *)(&EXTI->D3PCR1H + (EXTI_CONFIG_OFFSET * offset));
|
||||
pcrlinepos = 1UL << (linepos - 16UL);
|
||||
}
|
||||
|
||||
/*Clear D3 PendClear source */
|
||||
*regaddr &= (~(pcrlinepos * pcrlinepos * 3UL));
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Register callback for a dedicated Exti line.
|
||||
* @param hexti Exti handle.
|
||||
* @param CallbackID User callback identifier.
|
||||
* This parameter can be one of @arg @ref EXTI_CallbackIDTypeDef values.
|
||||
* @param pPendingCbfn function pointer to be stored as callback.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void))
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check null pointer */
|
||||
if (hexti == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_EXTI_COMMON_CB_ID:
|
||||
hexti->PendingCallback = pPendingCbfn;
|
||||
break;
|
||||
|
||||
default:
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Store line number as handle private field.
|
||||
* @param hexti Exti handle.
|
||||
* @param ExtiLine Exti line number.
|
||||
* This parameter can be from 0 to @ref EXTI_LINE_NB.
|
||||
* @retval HAL Status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_EXTI_LINE(ExtiLine));
|
||||
|
||||
/* Check null pointer */
|
||||
if (hexti == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Store line number as handle private field */
|
||||
hexti->Line = ExtiLine;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI_Exported_Functions_Group2
|
||||
* @brief EXTI IO functions.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Handle EXTI interrupt request.
|
||||
* @param hexti Exti handle.
|
||||
* @retval none.
|
||||
*/
|
||||
void HAL_EXTI_IRQHandler(const EXTI_HandleTypeDef *hexti)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
|
||||
|
||||
#if defined(DUAL_CORE)
|
||||
if (HAL_GetCurrentCPUID() == CM7_CPUID)
|
||||
{
|
||||
/* Get pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
}
|
||||
else /* Cortex-M4*/
|
||||
{
|
||||
/* Get pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
}
|
||||
#else
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
#endif /* DUAL_CORE */
|
||||
|
||||
/* Get pending bit */
|
||||
regval = (*regaddr & maskline);
|
||||
|
||||
if (regval != 0x00U)
|
||||
{
|
||||
/* Clear pending bit */
|
||||
*regaddr = maskline;
|
||||
|
||||
/* Call callback */
|
||||
if (hexti->PendingCallback != NULL)
|
||||
{
|
||||
hexti->PendingCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get interrupt pending bit of a dedicated line.
|
||||
* @param hexti Exti handle.
|
||||
* @param Edge Specify which pending edge as to be checked.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref EXTI_TRIGGER_RISING_FALLING
|
||||
* This parameter is kept for compatibility with other series.
|
||||
* @retval 1 if interrupt is pending else 0.
|
||||
*/
|
||||
uint32_t HAL_EXTI_GetPending(const EXTI_HandleTypeDef *hexti, uint32_t Edge)
|
||||
{
|
||||
const __IO uint32_t *regaddr;
|
||||
uint32_t regval;
|
||||
uint32_t linepos;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(Edge);
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_PENDING_EDGE(Edge));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
linepos = (hexti->Line & EXTI_PIN_MASK);
|
||||
maskline = (1UL << linepos);
|
||||
|
||||
#if defined(DUAL_CORE)
|
||||
if (HAL_GetCurrentCPUID() == CM7_CPUID)
|
||||
{
|
||||
/* Get pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
}
|
||||
else /* Cortex-M4 */
|
||||
{
|
||||
/* Get pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
}
|
||||
#else
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
#endif /* DUAL_CORE */
|
||||
|
||||
/* return 1 if bit is set else 0 */
|
||||
regval = ((*regaddr & maskline) >> linepos);
|
||||
return regval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear interrupt pending bit of a dedicated line.
|
||||
* @param hexti Exti handle.
|
||||
* @param Edge Specify which pending edge as to be clear.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref EXTI_TRIGGER_RISING_FALLING
|
||||
* This parameter is kept for compatibility with other series.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_EXTI_ClearPending(const EXTI_HandleTypeDef *hexti, uint32_t Edge)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(Edge);
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_PENDING_EDGE(Edge));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
|
||||
|
||||
#if defined(DUAL_CORE)
|
||||
if (HAL_GetCurrentCPUID() == CM7_CPUID)
|
||||
{
|
||||
/* Get pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
}
|
||||
else /* Cortex-M4 */
|
||||
{
|
||||
/* Get pending register address */
|
||||
regaddr = (__IO uint32_t *)(&EXTI->C2PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
}
|
||||
#else
|
||||
regaddr = (__IO uint32_t *)(&EXTI->PR1 + (EXTI_MODE_OFFSET * offset));
|
||||
#endif /* DUAL_CORE */
|
||||
|
||||
/* Clear Pending bit */
|
||||
*regaddr = maskline;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate a software interrupt for a dedicated line.
|
||||
* @param hexti Exti handle.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_EXTI_GenerateSWI(const EXTI_HandleTypeDef *hexti)
|
||||
{
|
||||
__IO uint32_t *regaddr;
|
||||
uint32_t maskline;
|
||||
uint32_t offset;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_EXTI_LINE(hexti->Line));
|
||||
assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
|
||||
|
||||
/* compute line register offset and line mask */
|
||||
offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
|
||||
maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
|
||||
|
||||
regaddr = (__IO uint32_t *)(&EXTI->SWIER1 + (EXTI_CONFIG_OFFSET * offset));
|
||||
*regaddr = maskline;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,892 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_gfxmmu.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides firmware functions to manage the following
|
||||
* functionalities of the Graphic MMU (GFXMMU) peripheral:
|
||||
* + Initialization and De-initialization.
|
||||
* + LUT configuration.
|
||||
* + Force flush and/or invalidate of cache.
|
||||
* + Modify physical buffer addresses.
|
||||
* + Modify cache and pre-fetch parameters.
|
||||
* + Error management.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
*** Initialization ***
|
||||
======================
|
||||
[..]
|
||||
(#) As prerequisite, fill in the HAL_GFXMMU_MspInit() :
|
||||
(++) Enable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
|
||||
(++) If interrupts are used, enable and configure GFXMMU global
|
||||
interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
|
||||
(#) Configure the number of blocks per line, default value, physical
|
||||
buffer addresses, cache and pre-fetch parameters and interrupts
|
||||
using the HAL_GFXMMU_Init() function.
|
||||
|
||||
*** LUT configuration ***
|
||||
=========================
|
||||
[..]
|
||||
(#) Use HAL_GFXMMU_DisableLutLines() to deactivate all LUT lines (or a
|
||||
range of lines).
|
||||
(#) Use HAL_GFXMMU_ConfigLut() to copy LUT from flash to look up RAM.
|
||||
(#) Use HAL_GFXMMU_ConfigLutLine() to configure one line of LUT.
|
||||
|
||||
*** Force flush and/or invalidate of cache ***
|
||||
==============================================
|
||||
[..]
|
||||
(#) Use HAL_GFXMMU_ConfigForceCache() to flush and/or invalidate cache.
|
||||
|
||||
*** Modify physical buffer addresses ***
|
||||
=======================================
|
||||
[..]
|
||||
(#) Use HAL_GFXMMU_ModifyBuffers() to modify physical buffer addresses.
|
||||
|
||||
*** Modify cache and pre-fetch parameters ***
|
||||
=============================================
|
||||
[..]
|
||||
(#) Use HAL_GFXMMU_ModifyCachePrefetch() to modify cache and pre-fetch
|
||||
parameters.
|
||||
|
||||
*** Error management ***
|
||||
========================
|
||||
[..]
|
||||
(#) If interrupts are used, HAL_GFXMMU_IRQHandler() will be called when
|
||||
an error occurs. This function will call HAL_GFXMMU_ErrorCallback().
|
||||
Use HAL_GFXMMU_GetError() to get the error code.
|
||||
|
||||
*** De-initialization ***
|
||||
=========================
|
||||
[..]
|
||||
(#) As prerequisite, fill in the HAL_GFXMMU_MspDeInit() :
|
||||
(++) Disable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
|
||||
(++) If interrupts has been used, disable GFXMMU global interrupt with
|
||||
HAL_NVIC_DisableIRQ().
|
||||
(#) De-initialize GFXMMU using the HAL_GFXMMU_DeInit() function.
|
||||
|
||||
*** Callback registration ***
|
||||
=============================
|
||||
|
||||
[..]
|
||||
The compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS when set to 1
|
||||
allows the user to configure dynamically the driver callbacks.
|
||||
Use functions HAL_GFXMMU_RegisterCallback() to register a user callback.
|
||||
|
||||
[..]
|
||||
Function HAL_GFXMMU_RegisterCallback() allows to register following callbacks:
|
||||
(+) ErrorCallback : GFXMMU error.
|
||||
(+) MspInitCallback : GFXMMU MspInit.
|
||||
(+) MspDeInitCallback : GFXMMU MspDeInit.
|
||||
[..]
|
||||
This function takes as parameters the HAL peripheral handle, the callback ID
|
||||
and a pointer to the user callback function.
|
||||
|
||||
[..]
|
||||
Use function HAL_GFXMMU_UnRegisterCallback() to reset a callback to the default
|
||||
weak (surcharged) function.
|
||||
HAL_GFXMMU_UnRegisterCallback() takes as parameters the HAL peripheral handle,
|
||||
and the callback ID.
|
||||
[..]
|
||||
This function allows to reset following callbacks:
|
||||
(+) ErrorCallback : GFXMMU error.
|
||||
(+) MspInitCallback : GFXMMU MspInit.
|
||||
(+) MspDeInitCallback : GFXMMU MspDeInit.
|
||||
|
||||
[..]
|
||||
By default, after the HAL_GFXMMU_Init and if the state is HAL_GFXMMU_STATE_RESET
|
||||
all callbacks are reset to the corresponding legacy weak (surcharged) functions:
|
||||
examples HAL_GFXMMU_ErrorCallback().
|
||||
Exception done for MspInit and MspDeInit callbacks that are respectively
|
||||
reset to the legacy weak (surcharged) functions in the HAL_GFXMMU_Init
|
||||
and HAL_GFXMMU_DeInit only when these callbacks are null (not registered beforehand).
|
||||
If not, MspInit or MspDeInit are not null, the HAL_GFXMMU_Init and HAL_GFXMMU_DeInit
|
||||
keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
|
||||
|
||||
[..]
|
||||
Callbacks can be registered/unregistered in READY state only.
|
||||
Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
|
||||
in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
|
||||
during the Init/DeInit.
|
||||
In that case first register the MspInit/MspDeInit user callbacks
|
||||
using HAL_GFXMMU_RegisterCallback before calling HAL_GFXMMU_DeInit
|
||||
or HAL_GFXMMU_Init function.
|
||||
|
||||
[..]
|
||||
When the compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS is set to 0 or
|
||||
not defined, the callback registering feature is not available
|
||||
and weak (surcharged) callbacks are used.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_GFXMMU_MODULE_ENABLED
|
||||
#if defined(GFXMMU)
|
||||
/** @defgroup GFXMMU GFXMMU
|
||||
* @brief GFXMMU HAL driver module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define GFXMMU_LUTXL_FVB_OFFSET 8U
|
||||
#define GFXMMU_LUTXL_LVB_OFFSET 16U
|
||||
#define GFXMMU_CR_ITS_MASK 0x1FU
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup GFXMMU_Exported_Functions GFXMMU Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup GFXMMU_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and de-initialization functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Initialize the GFXMMU.
|
||||
(+) De-initialize the GFXMMU.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the GFXMMU according to the specified parameters in the
|
||||
* GFXMMU_InitTypeDef structure and initialize the associated handle.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_Init(GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check GFXMMU handle */
|
||||
if(hgfxmmu == NULL)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
assert_param(IS_GFXMMU_BLOCKS_PER_LINE(hgfxmmu->Init.BlocksPerLine));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf0Address));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf1Address));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf2Address));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf3Address));
|
||||
assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.CachePrefetch.Activation));
|
||||
assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.Interrupts.Activation));
|
||||
|
||||
#if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
|
||||
/* Reset callback pointers to the weak predefined callbacks */
|
||||
hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
|
||||
|
||||
/* Call GFXMMU MSP init function */
|
||||
if(hgfxmmu->MspInitCallback == NULL)
|
||||
{
|
||||
hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
|
||||
}
|
||||
hgfxmmu->MspInitCallback(hgfxmmu);
|
||||
#else
|
||||
/* Call GFXMMU MSP init function */
|
||||
HAL_GFXMMU_MspInit(hgfxmmu);
|
||||
#endif
|
||||
|
||||
/* Configure blocks per line, cache and interrupts parameters on GFXMMU_CR register */
|
||||
hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
|
||||
GFXMMU_CR_AMEIE | GFXMMU_CR_192BM | GFXMMU_CR_CE | GFXMMU_CR_CL |
|
||||
GFXMMU_CR_CLB | GFXMMU_CR_FC | GFXMMU_CR_PD | GFXMMU_CR_OC |
|
||||
GFXMMU_CR_OB);
|
||||
hgfxmmu->Instance->CR |= (hgfxmmu->Init.BlocksPerLine);
|
||||
if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
|
||||
{
|
||||
assert_param(IS_GFXMMU_CACHE_LOCK(hgfxmmu->Init.CachePrefetch.CacheLock));
|
||||
assert_param(IS_GFXMMU_PREFETCH(hgfxmmu->Init.CachePrefetch.Prefetch));
|
||||
assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(hgfxmmu->Init.CachePrefetch.OutterBufferability));
|
||||
assert_param(IS_GFXMMU_OUTTER_CACHABILITY(hgfxmmu->Init.CachePrefetch.OutterCachability));
|
||||
hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
|
||||
hgfxmmu->Init.CachePrefetch.CacheLock |
|
||||
hgfxmmu->Init.CachePrefetch.Prefetch |
|
||||
hgfxmmu->Init.CachePrefetch.OutterBufferability |
|
||||
hgfxmmu->Init.CachePrefetch.OutterCachability);
|
||||
if(hgfxmmu->Init.CachePrefetch.CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
|
||||
{
|
||||
assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(hgfxmmu->Init.CachePrefetch.CacheLockBuffer));
|
||||
assert_param(IS_GFXMMU_CACHE_FORCE(hgfxmmu->Init.CachePrefetch.CacheForce));
|
||||
hgfxmmu->Instance->CR |= (hgfxmmu->Init.CachePrefetch.CacheLockBuffer |
|
||||
hgfxmmu->Init.CachePrefetch.CacheForce);
|
||||
}
|
||||
}
|
||||
if(hgfxmmu->Init.Interrupts.Activation == ENABLE)
|
||||
{
|
||||
assert_param(IS_GFXMMU_INTERRUPTS(hgfxmmu->Init.Interrupts.UsedInterrupts));
|
||||
hgfxmmu->Instance->CR |= hgfxmmu->Init.Interrupts.UsedInterrupts;
|
||||
}
|
||||
|
||||
/* Configure default value on GFXMMU_DVR register */
|
||||
hgfxmmu->Instance->DVR = hgfxmmu->Init.DefaultValue;
|
||||
|
||||
/* Configure physical buffer addresses on GFXMMU_BxCR registers */
|
||||
hgfxmmu->Instance->B0CR = hgfxmmu->Init.Buffers.Buf0Address;
|
||||
hgfxmmu->Instance->B1CR = hgfxmmu->Init.Buffers.Buf1Address;
|
||||
hgfxmmu->Instance->B2CR = hgfxmmu->Init.Buffers.Buf2Address;
|
||||
hgfxmmu->Instance->B3CR = hgfxmmu->Init.Buffers.Buf3Address;
|
||||
|
||||
/* Force invalidate cache if cache is enabled */
|
||||
if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
|
||||
{
|
||||
hgfxmmu->Instance->CCR |= GFXMMU_CACHE_FORCE_INVALIDATE;
|
||||
}
|
||||
|
||||
/* Reset GFXMMU error code */
|
||||
hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
|
||||
|
||||
/* Set GFXMMU to ready state */
|
||||
hgfxmmu->State = HAL_GFXMMU_STATE_READY;
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-initialize the GFXMMU.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check GFXMMU handle */
|
||||
if(hgfxmmu == NULL)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
|
||||
/* Disable all interrupts on GFXMMU_CR register */
|
||||
hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
|
||||
GFXMMU_CR_AMEIE);
|
||||
|
||||
/* Call GFXMMU MSP de-init function */
|
||||
#if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
|
||||
if(hgfxmmu->MspDeInitCallback == NULL)
|
||||
{
|
||||
hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
|
||||
}
|
||||
hgfxmmu->MspDeInitCallback(hgfxmmu);
|
||||
#else
|
||||
HAL_GFXMMU_MspDeInit(hgfxmmu);
|
||||
#endif
|
||||
|
||||
/* Set GFXMMU to reset state */
|
||||
hgfxmmu->State = HAL_GFXMMU_STATE_RESET;
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the GFXMMU MSP.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval None.
|
||||
*/
|
||||
__weak void HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hgfxmmu);
|
||||
|
||||
/* NOTE : This function should not be modified, when the function is needed,
|
||||
the HAL_GFXMMU_MspInit could be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-initialize the GFXMMU MSP.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval None.
|
||||
*/
|
||||
__weak void HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hgfxmmu);
|
||||
|
||||
/* NOTE : This function should not be modified, when the function is needed,
|
||||
the HAL_GFXMMU_MspDeInit could be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
#if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
|
||||
/**
|
||||
* @brief Register a user GFXMMU callback
|
||||
* to be used instead of the weak predefined callback.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param CallbackID ID of the callback to be registered.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
|
||||
* @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
|
||||
* @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
|
||||
* @param pCallback pointer to the callback function.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef *hgfxmmu,
|
||||
HAL_GFXMMU_CallbackIDTypeDef CallbackID,
|
||||
pGFXMMU_CallbackTypeDef pCallback)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if(pCallback == NULL)
|
||||
{
|
||||
/* update the error code */
|
||||
hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
|
||||
/* update return status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_GFXMMU_ERROR_CB_ID :
|
||||
hgfxmmu->ErrorCallback = pCallback;
|
||||
break;
|
||||
case HAL_GFXMMU_MSPINIT_CB_ID :
|
||||
hgfxmmu->MspInitCallback = pCallback;
|
||||
break;
|
||||
case HAL_GFXMMU_MSPDEINIT_CB_ID :
|
||||
hgfxmmu->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
default :
|
||||
/* update the error code */
|
||||
hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
|
||||
/* update return status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_GFXMMU_MSPINIT_CB_ID :
|
||||
hgfxmmu->MspInitCallback = pCallback;
|
||||
break;
|
||||
case HAL_GFXMMU_MSPDEINIT_CB_ID :
|
||||
hgfxmmu->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
default :
|
||||
/* update the error code */
|
||||
hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
|
||||
/* update return status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* update the error code */
|
||||
hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
|
||||
/* update return status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister a user GFXMMU callback.
|
||||
* GFXMMU callback is redirected to the weak predefined callback.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param CallbackID ID of the callback to be unregistered.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
|
||||
* @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
|
||||
* @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef *hgfxmmu,
|
||||
HAL_GFXMMU_CallbackIDTypeDef CallbackID)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_GFXMMU_ERROR_CB_ID :
|
||||
hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
|
||||
break;
|
||||
case HAL_GFXMMU_MSPINIT_CB_ID :
|
||||
hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
|
||||
break;
|
||||
case HAL_GFXMMU_MSPDEINIT_CB_ID :
|
||||
hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
|
||||
break;
|
||||
default :
|
||||
/* update the error code */
|
||||
hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
|
||||
/* update return status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_GFXMMU_MSPINIT_CB_ID :
|
||||
hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
|
||||
break;
|
||||
case HAL_GFXMMU_MSPDEINIT_CB_ID :
|
||||
hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
|
||||
break;
|
||||
default :
|
||||
/* update the error code */
|
||||
hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
|
||||
/* update return status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* update the error code */
|
||||
hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
|
||||
/* update return status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
#endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup GFXMMU_Exported_Functions_Group2 Operations functions
|
||||
* @brief GFXMMU operation functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Operation functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure LUT.
|
||||
(+) Force flush and/or invalidate of cache.
|
||||
(+) Modify physical buffer addresses.
|
||||
(+) Modify cache and pre-fetch parameters.
|
||||
(+) Manage error.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function allows to copy LUT from flash to look up RAM.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param FirstLine First line enabled on LUT.
|
||||
* This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
|
||||
* @param LinesNumber Number of lines enabled on LUT.
|
||||
* This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
|
||||
* @param Address Start address of LUT in flash.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_ConfigLut(const GFXMMU_HandleTypeDef *hgfxmmu,
|
||||
uint32_t FirstLine,
|
||||
uint32_t LinesNumber,
|
||||
uint32_t Address)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
|
||||
assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
|
||||
|
||||
/* Check GFXMMU state and coherent parameters */
|
||||
if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t current_address, current_line, lutxl_address, lutxh_address;
|
||||
|
||||
/* Initialize local variables */
|
||||
current_address = Address;
|
||||
current_line = 0U;
|
||||
lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
|
||||
lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
|
||||
|
||||
/* Copy LUT from flash to look up RAM */
|
||||
while(current_line < LinesNumber)
|
||||
{
|
||||
*((uint32_t *)lutxl_address) = *((uint32_t *)current_address);
|
||||
current_address += 4U;
|
||||
*((uint32_t *)lutxh_address) = *((uint32_t *)current_address);
|
||||
current_address += 4U;
|
||||
lutxl_address += 8U;
|
||||
lutxh_address += 8U;
|
||||
current_line++;
|
||||
}
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function allows to disable a range of LUT lines.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param FirstLine First line to disable on LUT.
|
||||
* This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
|
||||
* @param LinesNumber Number of lines to disable on LUT.
|
||||
* This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_DisableLutLines(const GFXMMU_HandleTypeDef *hgfxmmu,
|
||||
uint32_t FirstLine,
|
||||
uint32_t LinesNumber)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
|
||||
assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
|
||||
|
||||
/* Check GFXMMU state and coherent parameters */
|
||||
if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t current_line, lutxl_address, lutxh_address;
|
||||
|
||||
/* Initialize local variables */
|
||||
current_line = 0U;
|
||||
lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
|
||||
lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
|
||||
|
||||
/* Disable LUT lines */
|
||||
while(current_line < LinesNumber)
|
||||
{
|
||||
*((uint32_t *)lutxl_address) = 0U;
|
||||
*((uint32_t *)lutxh_address) = 0U;
|
||||
lutxl_address += 8U;
|
||||
lutxh_address += 8U;
|
||||
current_line++;
|
||||
}
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function allows to configure one line of LUT.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param lutLine LUT line parameters.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_ConfigLutLine(const GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_LutLineTypeDef *lutLine)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
assert_param(IS_GFXMMU_LUT_LINE(lutLine->LineNumber));
|
||||
assert_param(IS_GFXMMU_LUT_LINE_STATUS(lutLine->LineStatus));
|
||||
assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->FirstVisibleBlock));
|
||||
assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->LastVisibleBlock));
|
||||
assert_param(IS_GFXMMU_LUT_LINE_OFFSET(lutLine->LineOffset));
|
||||
|
||||
/* Check GFXMMU state */
|
||||
if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t lutxl_address, lutxh_address;
|
||||
|
||||
/* Initialize local variables */
|
||||
lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * lutLine->LineNumber]);
|
||||
lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * lutLine->LineNumber) + 1U]);
|
||||
|
||||
/* Configure LUT line */
|
||||
if(lutLine->LineStatus == GFXMMU_LUT_LINE_ENABLE)
|
||||
{
|
||||
/* Enable and configure LUT line */
|
||||
*((uint32_t *)lutxl_address) = (lutLine->LineStatus |
|
||||
(lutLine->FirstVisibleBlock << GFXMMU_LUTXL_FVB_OFFSET) |
|
||||
(lutLine->LastVisibleBlock << GFXMMU_LUTXL_LVB_OFFSET));
|
||||
*((uint32_t *)lutxh_address) = (uint32_t) lutLine->LineOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable LUT line */
|
||||
*((uint32_t *)lutxl_address) = 0U;
|
||||
*((uint32_t *)lutxh_address) = 0U;
|
||||
}
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function allows to force flush and/or invalidate of cache.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param ForceParam Force cache parameter.
|
||||
* This parameter can be a values combination of @ref GFXMMU_CacheForceParam.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef *hgfxmmu, uint32_t ForceParam)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
assert_param(IS_GFXMMU_CACHE_FORCE_ACTION(ForceParam));
|
||||
|
||||
/* Check GFXMMU state and cache status */
|
||||
if(((hgfxmmu->Instance->CR & GFXMMU_CR_CE) != GFXMMU_CR_CE) || (hgfxmmu->State != HAL_GFXMMU_STATE_READY))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Force flush and/or invalidate cache on GFXMMU_CCR register */
|
||||
hgfxmmu->Instance->CCR |= ForceParam;
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function allows to modify physical buffer addresses.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param Buffers Buffers parameters.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_BuffersTypeDef *Buffers)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf0Address));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf1Address));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf2Address));
|
||||
assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf3Address));
|
||||
|
||||
/* Check GFXMMU state */
|
||||
if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Modify physical buffer addresses on GFXMMU_BxCR registers */
|
||||
hgfxmmu->Instance->B0CR = Buffers->Buf0Address;
|
||||
hgfxmmu->Instance->B1CR = Buffers->Buf1Address;
|
||||
hgfxmmu->Instance->B2CR = Buffers->Buf2Address;
|
||||
hgfxmmu->Instance->B3CR = Buffers->Buf3Address;
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function allows to modify cache and pre-fetch parameters.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @param CachePrefetch Cache and pre-fetch parameters.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef *hgfxmmu,
|
||||
GFXMMU_CachePrefetchTypeDef *CachePrefetch)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
assert_param(IS_FUNCTIONAL_STATE(CachePrefetch->Activation));
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
|
||||
|
||||
/* Check GFXMMU state */
|
||||
if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Modify cache and pre-fetch parameters on GFXMMU_CR register */
|
||||
hgfxmmu->Instance->CR &= ~(GFXMMU_CR_CE | GFXMMU_CR_CL | GFXMMU_CR_CLB | GFXMMU_CR_FC |
|
||||
GFXMMU_CR_PD | GFXMMU_CR_OC | GFXMMU_CR_OB);
|
||||
if(CachePrefetch->Activation == ENABLE)
|
||||
{
|
||||
assert_param(IS_GFXMMU_CACHE_LOCK(CachePrefetch->CacheLock));
|
||||
assert_param(IS_GFXMMU_PREFETCH(CachePrefetch->Prefetch));
|
||||
assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(CachePrefetch->OutterBufferability));
|
||||
assert_param(IS_GFXMMU_OUTTER_CACHABILITY(CachePrefetch->OutterCachability));
|
||||
hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
|
||||
CachePrefetch->CacheLock |
|
||||
CachePrefetch->Prefetch |
|
||||
CachePrefetch->OutterBufferability |
|
||||
CachePrefetch->OutterCachability);
|
||||
if(CachePrefetch->CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
|
||||
{
|
||||
assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(CachePrefetch->CacheLockBuffer));
|
||||
assert_param(IS_GFXMMU_CACHE_FORCE(CachePrefetch->CacheForce));
|
||||
hgfxmmu->Instance->CR |= (CachePrefetch->CacheLockBuffer |
|
||||
CachePrefetch->CacheForce);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles the GFXMMU interrupts.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
uint32_t flags, interrupts, error;
|
||||
|
||||
/* Read current flags and interrupts and determine which error occurs */
|
||||
flags = hgfxmmu->Instance->SR;
|
||||
interrupts = (hgfxmmu->Instance->CR & GFXMMU_CR_ITS_MASK);
|
||||
error = (flags & interrupts);
|
||||
|
||||
if(error != 0U)
|
||||
{
|
||||
/* Clear flags on GFXMMU_FCR register */
|
||||
hgfxmmu->Instance->FCR = error;
|
||||
|
||||
/* Update GFXMMU error code */
|
||||
hgfxmmu->ErrorCode |= error;
|
||||
|
||||
/* Call GFXMMU error callback */
|
||||
#if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
|
||||
hgfxmmu->ErrorCallback(hgfxmmu);
|
||||
#else
|
||||
HAL_GFXMMU_ErrorCallback(hgfxmmu);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Error callback.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval None.
|
||||
*/
|
||||
__weak void HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hgfxmmu);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_GFXMMU_ErrorCallback could be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup GFXMMU_Exported_Functions_Group3 State functions
|
||||
* @brief GFXMMU state functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### State functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Get GFXMMU handle state.
|
||||
(+) Get GFXMMU error code.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function allows to get the current GFXMMU handle state.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval GFXMMU state.
|
||||
*/
|
||||
HAL_GFXMMU_StateTypeDef HAL_GFXMMU_GetState(const GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
/* Return GFXMMU handle state */
|
||||
return hgfxmmu->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function allows to get the current GFXMMU error code.
|
||||
* @param hgfxmmu GFXMMU handle.
|
||||
* @retval GFXMMU error code.
|
||||
*/
|
||||
uint32_t HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef *hgfxmmu)
|
||||
{
|
||||
uint32_t error_code;
|
||||
|
||||
/* Enter in critical section */
|
||||
__disable_irq();
|
||||
|
||||
/* Store and reset GFXMMU error code */
|
||||
error_code = hgfxmmu->ErrorCode;
|
||||
hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
|
||||
|
||||
/* Exit from critical section */
|
||||
__enable_irq();
|
||||
|
||||
/* Return GFXMMU error code */
|
||||
return error_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* End of exported functions -------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* End of private functions --------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* GFXMMU */
|
||||
#endif /* HAL_GFXMMU_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,555 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_gpio.c
|
||||
* @author MCD Application Team
|
||||
* @brief GPIO HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the General Purpose Input/Output (GPIO) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + IO operation functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### GPIO Peripheral features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) Each port bit of the general-purpose I/O (GPIO) ports can be individually
|
||||
configured by software in several modes:
|
||||
(++) Input mode
|
||||
(++) Analog mode
|
||||
(++) Output mode
|
||||
(++) Alternate function mode
|
||||
(++) External interrupt/event lines
|
||||
|
||||
(+) During and just after reset, the alternate functions and external interrupt
|
||||
lines are not active and the I/O ports are configured in 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.
|
||||
|
||||
(+) The microcontroller IO pins are connected to onboard peripherals/modules through a
|
||||
multiplexer that allows only one peripheral alternate function (AF) connected
|
||||
to an IO pin at a time. In this way, there can be no conflict between peripherals
|
||||
sharing the same IO pin.
|
||||
|
||||
(+) All ports have external interrupt/event capability. To use external interrupt
|
||||
lines, the port must be configured in input mode. All available GPIO pins are
|
||||
connected to the 16 external interrupt/event lines from EXTI0 to EXTI15.
|
||||
|
||||
The external interrupt/event controller consists of up to 23 edge detectors
|
||||
(16 lines are connected to GPIO) for generating event/interrupt requests (each
|
||||
input line can be independently configured to select the type (interrupt or event)
|
||||
and the corresponding trigger event (rising or falling or both). Each line can
|
||||
also be masked independently.
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) Enable the GPIO AHB clock using the following function: __HAL_RCC_GPIOx_CLK_ENABLE().
|
||||
|
||||
(#) Configure the GPIO pin(s) using HAL_GPIO_Init().
|
||||
(++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
|
||||
(++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef
|
||||
structure.
|
||||
(++) In case of Output or alternate function mode selection: the speed is
|
||||
configured through "Speed" member from GPIO_InitTypeDef structure.
|
||||
(++) In alternate mode is selection, the alternate function connected to the IO
|
||||
is configured through "Alternate" member from GPIO_InitTypeDef structure.
|
||||
(++) Analog mode is required when a pin is to be used as ADC channel
|
||||
or DAC output.
|
||||
(++) In case of external interrupt/event selection the "Mode" member from
|
||||
GPIO_InitTypeDef structure select the type (interrupt or event) and
|
||||
the corresponding trigger event (rising or falling or both).
|
||||
|
||||
(#) In case of external interrupt/event mode selection, configure NVIC IRQ priority
|
||||
mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
|
||||
HAL_NVIC_EnableIRQ().
|
||||
|
||||
(#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
|
||||
|
||||
(#) To set/reset the level of a pin configured in output mode use
|
||||
HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
|
||||
|
||||
(#) To lock pin configuration until next reset use HAL_GPIO_LockPin().
|
||||
|
||||
|
||||
(#) During and just after reset, the alternate functions are not
|
||||
active and the GPIO pins are configured in input floating mode (except JTAG
|
||||
pins).
|
||||
|
||||
(#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
|
||||
(PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
|
||||
priority over the GPIO function.
|
||||
|
||||
(#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
|
||||
general purpose PH0 and PH1, respectively, when the HSE oscillator is off.
|
||||
The HSE has priority over the GPIO function.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(DUAL_CORE)
|
||||
#define EXTI_CPU1 (0x01000000U)
|
||||
#define EXTI_CPU2 (0x02000000U)
|
||||
#endif /*DUAL_CORE*/
|
||||
#define GPIO_NUMBER (16U)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* 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, const GPIO_InitTypeDef *GPIO_Init)
|
||||
{
|
||||
uint32_t position = 0x00U;
|
||||
uint32_t iocurrent;
|
||||
uint32_t temp;
|
||||
EXTI_Core_TypeDef *EXTI_CurrentCPU;
|
||||
|
||||
#if defined(DUAL_CORE) && defined(CORE_CM4)
|
||||
EXTI_CurrentCPU = EXTI_D2; /* EXTI for CM4 CPU */
|
||||
#else
|
||||
EXTI_CurrentCPU = EXTI_D1; /* EXTI for CM7 CPU */
|
||||
#endif
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
|
||||
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
|
||||
|
||||
/* Configure the port pins */
|
||||
while (((GPIO_Init->Pin) >> position) != 0x00U)
|
||||
{
|
||||
/* Get current io position */
|
||||
iocurrent = (GPIO_Init->Pin) & (1UL << position);
|
||||
|
||||
if (iocurrent != 0x00U)
|
||||
{
|
||||
/*--------------------- GPIO Mode Configuration ------------------------*/
|
||||
/* In case of Output or Alternate function mode selection */
|
||||
if (((GPIO_Init->Mode & GPIO_MODE) == MODE_OUTPUT) || ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF))
|
||||
{
|
||||
/* Check the Speed parameter */
|
||||
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
|
||||
|
||||
/* Configure the IO Speed */
|
||||
temp = GPIOx->OSPEEDR;
|
||||
temp &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2U));
|
||||
temp |= (GPIO_Init->Speed << (position * 2U));
|
||||
GPIOx->OSPEEDR = temp;
|
||||
|
||||
/* Configure the IO Output Type */
|
||||
temp = GPIOx->OTYPER;
|
||||
temp &= ~(GPIO_OTYPER_OT0 << position) ;
|
||||
temp |= (((GPIO_Init->Mode & OUTPUT_TYPE) >> OUTPUT_TYPE_Pos) << position);
|
||||
GPIOx->OTYPER = temp;
|
||||
}
|
||||
|
||||
if ((GPIO_Init->Mode & GPIO_MODE) != MODE_ANALOG)
|
||||
{
|
||||
/* Check the Pull parameter */
|
||||
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
|
||||
|
||||
/* Activate the Pull-up or Pull down resistor for the current IO */
|
||||
temp = GPIOx->PUPDR;
|
||||
temp &= ~(GPIO_PUPDR_PUPD0 << (position * 2U));
|
||||
temp |= ((GPIO_Init->Pull) << (position * 2U));
|
||||
GPIOx->PUPDR = temp;
|
||||
}
|
||||
|
||||
/* In case of Alternate function mode selection */
|
||||
if ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF)
|
||||
{
|
||||
/* Check the Alternate function parameters */
|
||||
assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
|
||||
|
||||
/* Configure Alternate function mapped with the current IO */
|
||||
temp = GPIOx->AFR[position >> 3U];
|
||||
temp &= ~(0xFU << ((position & 0x07U) * 4U));
|
||||
temp |= ((GPIO_Init->Alternate) << ((position & 0x07U) * 4U));
|
||||
GPIOx->AFR[position >> 3U] = temp;
|
||||
}
|
||||
|
||||
/* Configure IO Direction mode (Input, Output, Alternate or Analog) */
|
||||
temp = GPIOx->MODER;
|
||||
temp &= ~(GPIO_MODER_MODE0 << (position * 2U));
|
||||
temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2U));
|
||||
GPIOx->MODER = temp;
|
||||
|
||||
/*--------------------- EXTI Mode Configuration ------------------------*/
|
||||
/* Configure the External Interrupt or event for the current IO */
|
||||
if ((GPIO_Init->Mode & EXTI_MODE) != 0x00U)
|
||||
{
|
||||
/* Enable SYSCFG Clock */
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
temp = SYSCFG->EXTICR[position >> 2U];
|
||||
temp &= ~(0x0FUL << (4U * (position & 0x03U)));
|
||||
temp |= (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U)));
|
||||
SYSCFG->EXTICR[position >> 2U] = temp;
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
temp = EXTI->RTSR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & TRIGGER_RISING) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->RTSR1 = temp;
|
||||
|
||||
temp = EXTI->FTSR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & TRIGGER_FALLING) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI->FTSR1 = temp;
|
||||
|
||||
temp = EXTI_CurrentCPU->EMR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & EXTI_EVT) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI_CurrentCPU->EMR1 = temp;
|
||||
|
||||
/* Clear EXTI line configuration */
|
||||
temp = EXTI_CurrentCPU->IMR1;
|
||||
temp &= ~(iocurrent);
|
||||
if ((GPIO_Init->Mode & EXTI_IT) != 0x00U)
|
||||
{
|
||||
temp |= iocurrent;
|
||||
}
|
||||
EXTI_CurrentCPU->IMR1 = temp;
|
||||
}
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = 0x00U;
|
||||
uint32_t iocurrent;
|
||||
uint32_t tmp;
|
||||
EXTI_Core_TypeDef *EXTI_CurrentCPU;
|
||||
|
||||
#if defined(DUAL_CORE) && defined(CORE_CM4)
|
||||
EXTI_CurrentCPU = EXTI_D2; /* EXTI for CM4 CPU */
|
||||
#else
|
||||
EXTI_CurrentCPU = EXTI_D1; /* EXTI for CM7 CPU */
|
||||
#endif
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
/* Configure the port pins */
|
||||
while ((GPIO_Pin >> position) != 0x00U)
|
||||
{
|
||||
/* Get current io position */
|
||||
iocurrent = GPIO_Pin & (1UL << position) ;
|
||||
|
||||
if (iocurrent != 0x00U)
|
||||
{
|
||||
/*------------------------- EXTI Mode Configuration --------------------*/
|
||||
/* Clear the External Interrupt or Event for the current IO */
|
||||
tmp = SYSCFG->EXTICR[position >> 2U];
|
||||
tmp &= (0x0FUL << (4U * (position & 0x03U)));
|
||||
if (tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U))))
|
||||
{
|
||||
/* Clear EXTI line configuration for Current CPU */
|
||||
EXTI_CurrentCPU->IMR1 &= ~(iocurrent);
|
||||
EXTI_CurrentCPU->EMR1 &= ~(iocurrent);
|
||||
|
||||
/* Clear Rising Falling edge configuration */
|
||||
EXTI->FTSR1 &= ~(iocurrent);
|
||||
EXTI->RTSR1 &= ~(iocurrent);
|
||||
|
||||
tmp = 0x0FUL << (4U * (position & 0x03U));
|
||||
SYSCFG->EXTICR[position >> 2U] &= ~tmp;
|
||||
}
|
||||
|
||||
/*------------------------- GPIO Mode Configuration --------------------*/
|
||||
/* Configure IO in Analog Mode */
|
||||
GPIOx->MODER |= (GPIO_MODER_MODE0 << (position * 2U));
|
||||
|
||||
/* Configure the default Alternate Function in current IO */
|
||||
GPIOx->AFR[position >> 3U] &= ~(0xFU << ((position & 0x07U) * 4U)) ;
|
||||
|
||||
/* Deactivate the Pull-up and Pull-down resistor for the current IO */
|
||||
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPD0 << (position * 2U));
|
||||
|
||||
/* Configure the default value IO Output Type */
|
||||
GPIOx->OTYPER &= ~(GPIO_OTYPER_OT0 << position) ;
|
||||
|
||||
/* Configure the default value for IO Speed */
|
||||
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2U));
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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(const GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
GPIO_PinState bitstatus;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
if ((GPIOx->IDR & GPIO_Pin) != 0x00U)
|
||||
{
|
||||
bitstatus = GPIO_PIN_SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitstatus = GPIO_PIN_RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets or clears the selected data port bit.
|
||||
*
|
||||
* @note This function uses GPIOx_BSRR register to allow atomic read/modify
|
||||
* accesses. In this way, there is no risk of an IRQ occurring between
|
||||
* the read and the modify access.
|
||||
*
|
||||
* @param GPIOx: where x can be (A..K) to select the GPIO peripheral.
|
||||
* @param GPIO_Pin: specifies the port bit to be written.
|
||||
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
||||
* @param PinState: specifies the value to be written to the selected bit.
|
||||
* This parameter can be one of the GPIO_PinState enum values:
|
||||
* @arg GPIO_PIN_RESET: to clear the port pin
|
||||
* @arg GPIO_PIN_SET: to set the port pin
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_PIN_ACTION(PinState));
|
||||
|
||||
if (PinState != GPIO_PIN_RESET)
|
||||
{
|
||||
GPIOx->BSRR = GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BSRR = (uint32_t)GPIO_Pin << GPIO_NUMBER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the specified GPIO pins.
|
||||
* @param GPIOx: Where x can be (A..K) to select the GPIO peripheral.
|
||||
* @param GPIO_Pin: Specifies the pins to be toggled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
uint32_t odr;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
/* get current Output Data Register value */
|
||||
odr = GPIOx->ODR;
|
||||
|
||||
/* Set selected pins that were at low level, and reset ones that were high */
|
||||
GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 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 register. This read is mandatory to complete key lock sequence*/
|
||||
tmp = GPIOx->LCKR;
|
||||
|
||||
/* read again in order to confirm lock is active */
|
||||
if ((GPIOx->LCKR & GPIO_LCKR_LCKK) != 0x00U)
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 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)
|
||||
{
|
||||
#if defined(DUAL_CORE) && defined(CORE_CM4)
|
||||
if (__HAL_GPIO_EXTID2_GET_IT(GPIO_Pin) != 0x00U)
|
||||
{
|
||||
__HAL_GPIO_EXTID2_CLEAR_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_Callback(GPIO_Pin);
|
||||
}
|
||||
#else
|
||||
/* EXTI line interrupt detected */
|
||||
if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00U)
|
||||
{
|
||||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_Callback(GPIO_Pin);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,447 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_hsem.c
|
||||
* @author MCD Application Team
|
||||
* @brief HSEM HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the semaphore peripheral:
|
||||
* + Semaphore Take function (2-Step Procedure) , non blocking
|
||||
* + Semaphore FastTake function (1-Step Procedure) , non blocking
|
||||
* + Semaphore Status check
|
||||
* + Semaphore Clear Key Set and Get
|
||||
* + Release and release all functions
|
||||
* + Semaphore notification enabling and disabling and callnack functions
|
||||
* + IRQ handler management
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#)Take a semaphore In 2-Step mode Using function HAL_HSEM_Take. This function takes as parameters :
|
||||
(++) the semaphore ID from 0 to 31
|
||||
(++) the process ID from 0 to 255
|
||||
(#) Fast Take semaphore In 1-Step mode Using function HAL_HSEM_FastTake. This function takes as parameter :
|
||||
(++) the semaphore ID from 0_ID to 31. Note that the process ID value is implicitly assumed as zero
|
||||
(#) Check if a semaphore is Taken using function HAL_HSEM_IsSemTaken. This function takes as parameter :
|
||||
(++) the semaphore ID from 0_ID to 31
|
||||
(++) It returns 1 if the given semaphore is taken otherwise (Free) zero
|
||||
(#)Release a semaphore using function with HAL_HSEM_Release. This function takes as parameters :
|
||||
(++) the semaphore ID from 0 to 31
|
||||
(++) the process ID from 0 to 255:
|
||||
(++) Note: If ProcessID and MasterID match, semaphore is freed, and an interrupt
|
||||
may be generated when enabled (notification activated). If ProcessID or MasterID does not match,
|
||||
semaphore remains taken (locked)
|
||||
|
||||
(#)Release all semaphores at once taken by a given Master using function HAL_HSEM_Release_All
|
||||
This function takes as parameters :
|
||||
(++) the Release Key (value from 0 to 0xFFFF) can be Set or Get respectively by
|
||||
HAL_HSEM_SetClearKey() or HAL_HSEM_GetClearKey functions
|
||||
(++) the Master ID:
|
||||
(++) Note: If the Key and MasterID match, all semaphores taken by the given CPU that corresponds
|
||||
to MasterID will be freed, and an interrupt may be generated when enabled (notification activated). If the
|
||||
Key or the MasterID doesn't match, semaphores remains taken (locked)
|
||||
|
||||
(#)Semaphores Release all key functions:
|
||||
(++) HAL_HSEM_SetClearKey() to set semaphore release all Key
|
||||
(++) HAL_HSEM_GetClearKey() to get release all Key
|
||||
(#)Semaphores notification functions :
|
||||
(++) HAL_HSEM_ActivateNotification to activate a notification callback on
|
||||
a given semaphores Mask (bitfield). When one or more semaphores defined by the mask are released
|
||||
the callback HAL_HSEM_FreeCallback will be asserted giving as parameters a mask of the released
|
||||
semaphores (bitfield).
|
||||
|
||||
(++) HAL_HSEM_DeactivateNotification to deactivate the notification of a given semaphores Mask (bitfield).
|
||||
(++) See the description of the macro __HAL_HSEM_SEMID_TO_MASK to check how to calculate a semaphore mask
|
||||
Used by the notification functions
|
||||
*** HSEM HAL driver macros list ***
|
||||
=============================================
|
||||
[..] Below the list of most used macros in HSEM HAL driver.
|
||||
|
||||
(+) __HAL_HSEM_SEMID_TO_MASK: Helper macro to convert a Semaphore ID to a Mask.
|
||||
[..] Example of use :
|
||||
[..] mask = __HAL_HSEM_SEMID_TO_MASK(8) | __HAL_HSEM_SEMID_TO_MASK(21) | __HAL_HSEM_SEMID_TO_MASK(25).
|
||||
[..] All next macros take as parameter a semaphore Mask (bitfiled) that can be constructed using __HAL_HSEM_SEMID_TO_MASK as the above example.
|
||||
(+) __HAL_HSEM_ENABLE_IT: Enable the specified semaphores Mask interrupts.
|
||||
(+) __HAL_HSEM_DISABLE_IT: Disable the specified semaphores Mask interrupts.
|
||||
(+) __HAL_HSEM_GET_IT: Checks whether the specified semaphore interrupt has occurred or not.
|
||||
(+) __HAL_HSEM_GET_FLAG: Get the semaphores status release flags.
|
||||
(+) __HAL_HSEM_CLEAR_FLAG: Clear the semaphores status release flags.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM HSEM
|
||||
* @brief HSEM HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_HSEM_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#if defined(DUAL_CORE)
|
||||
/** @defgroup HSEM_Private_Constants HSEM Private Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef HSEM_R_MASTERID
|
||||
#define HSEM_R_MASTERID HSEM_R_COREID
|
||||
#endif
|
||||
|
||||
#ifndef HSEM_RLR_MASTERID
|
||||
#define HSEM_RLR_MASTERID HSEM_RLR_COREID
|
||||
#endif
|
||||
|
||||
#ifndef HSEM_CR_MASTERID
|
||||
#define HSEM_CR_MASTERID HSEM_CR_COREID
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* DUAL_CORE */
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions HSEM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions_Group1 Take and Release functions
|
||||
* @brief HSEM Take and Release functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### HSEM Take and Release functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Take a semaphore with 2 Step method
|
||||
(+) Fast Take a semaphore with 1 Step method
|
||||
(+) Check semaphore state Taken or not
|
||||
(+) Release a semaphore
|
||||
(+) Release all semaphore at once
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Take a semaphore in 2 Step mode.
|
||||
* @param SemID: semaphore ID from 0 to 31
|
||||
* @param ProcessID: Process ID from 0 to 255
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_HSEM_SEMID(SemID));
|
||||
assert_param(IS_HSEM_PROCESSID(ProcessID));
|
||||
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/* First step write R register with MasterID, processID and take bit=1*/
|
||||
HSEM->R[SemID] = ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK);
|
||||
|
||||
/* second step : read the R register . Take achieved if MasterID and processID match and take bit set to 1 */
|
||||
if (HSEM->R[SemID] == ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK))
|
||||
{
|
||||
/*take success when MasterID and ProcessID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#else
|
||||
/* First step write R register with MasterID, processID and take bit=1*/
|
||||
HSEM->R[SemID] = (ProcessID | HSEM_CR_COREID_CURRENT | HSEM_R_LOCK);
|
||||
|
||||
/* second step : read the R register . Take achieved if MasterID and processID match and take bit set to 1 */
|
||||
if (HSEM->R[SemID] == (ProcessID | HSEM_CR_COREID_CURRENT | HSEM_R_LOCK))
|
||||
{
|
||||
/*take success when MasterID and ProcessID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Semaphore take fails*/
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fast Take a semaphore with 1 Step mode.
|
||||
* @param SemID: semaphore ID from 0 to 31
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HSEM_FastTake(uint32_t SemID)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_HSEM_SEMID(SemID));
|
||||
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/* Read the RLR register to take the semaphore */
|
||||
if (HSEM->RLR[SemID] == (((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_RLR_MASTERID) | HSEM_RLR_LOCK))
|
||||
{
|
||||
/*take success when MasterID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#else
|
||||
/* Read the RLR register to take the semaphore */
|
||||
if (HSEM->RLR[SemID] == (HSEM_CR_COREID_CURRENT | HSEM_RLR_LOCK))
|
||||
{
|
||||
/*take success when MasterID match and take bit set*/
|
||||
return HAL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Semaphore take fails */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/**
|
||||
* @brief Check semaphore state Taken or not.
|
||||
* @param SemID: semaphore ID
|
||||
* @retval HAL HSEM state
|
||||
*/
|
||||
uint32_t HAL_HSEM_IsSemTaken(uint32_t SemID)
|
||||
{
|
||||
return (((HSEM->R[SemID] & HSEM_R_LOCK) != 0U) ? 1UL : 0UL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Release a semaphore.
|
||||
* @param SemID: semaphore ID from 0 to 31
|
||||
* @param ProcessID: Process ID from 0 to 255
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_Release(uint32_t SemID, uint32_t ProcessID)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_HSEM_SEMID(SemID));
|
||||
assert_param(IS_HSEM_PROCESSID(ProcessID));
|
||||
|
||||
/* Clear the semaphore by writing to the R register : the MasterID , the processID and take bit = 0 */
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
HSEM->R[SemID] = (ProcessID | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID));
|
||||
#else
|
||||
HSEM->R[SemID] = (ProcessID | HSEM_CR_COREID_CURRENT);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release All semaphore used by a given Master .
|
||||
* @param Key: Semaphore Key , value from 0 to 0xFFFF
|
||||
* @param CoreID: CoreID of the CPU that is using semaphores to be released
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t CoreID)
|
||||
{
|
||||
assert_param(IS_HSEM_KEY(Key));
|
||||
assert_param(IS_HSEM_COREID(CoreID));
|
||||
|
||||
HSEM->CR = ((Key << HSEM_CR_KEY_Pos) | (CoreID << HSEM_CR_COREID_Pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions_Group2 HSEM Set and Get Key functions
|
||||
* @brief HSEM Set and Get Key functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### HSEM Set and Get Key functions #####
|
||||
==============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Set semaphore Key
|
||||
(+) Get semaphore Key
|
||||
@endverbatim
|
||||
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Set semaphore Key .
|
||||
* @param Key: Semaphore Key , value from 0 to 0xFFFF
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_SetClearKey(uint32_t Key)
|
||||
{
|
||||
assert_param(IS_HSEM_KEY(Key));
|
||||
|
||||
MODIFY_REG(HSEM->KEYR, HSEM_KEYR_KEY, (Key << HSEM_KEYR_KEY_Pos));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get semaphore Key .
|
||||
* @retval Semaphore Key , value from 0 to 0xFFFF
|
||||
*/
|
||||
uint32_t HAL_HSEM_GetClearKey(void)
|
||||
{
|
||||
return (HSEM->KEYR >> HSEM_KEYR_KEY_Pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HSEM_Exported_Functions_Group3 HSEM IRQ handler management
|
||||
* @brief HSEM Notification functions.
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### HSEM IRQ handler management and Notification functions #####
|
||||
==============================================================================
|
||||
[..] This section provides HSEM IRQ handler and Notification function.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Activate Semaphore release Notification for a given Semaphores Mask .
|
||||
* @param SemMask: Mask of Released semaphores
|
||||
* @retval Semaphore Key
|
||||
*/
|
||||
void HAL_HSEM_ActivateNotification(uint32_t SemMask)
|
||||
{
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/*enable the semaphore mask interrupts */
|
||||
if (HAL_GetCurrentCPUID() == HSEM_CPU1_COREID)
|
||||
{
|
||||
/*Use interrupt line 0 for CPU1 Master */
|
||||
HSEM->C1IER |= SemMask;
|
||||
}
|
||||
else /* HSEM_CPU2_COREID */
|
||||
{
|
||||
/*Use interrupt line 1 for CPU2 Master*/
|
||||
HSEM->C2IER |= SemMask;
|
||||
}
|
||||
#else
|
||||
HSEM_COMMON->IER |= SemMask;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deactivate Semaphore release Notification for a given Semaphores Mask .
|
||||
* @param SemMask: Mask of Released semaphores
|
||||
* @retval Semaphore Key
|
||||
*/
|
||||
void HAL_HSEM_DeactivateNotification(uint32_t SemMask)
|
||||
{
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
/*enable the semaphore mask interrupts */
|
||||
if (HAL_GetCurrentCPUID() == HSEM_CPU1_COREID)
|
||||
{
|
||||
/*Use interrupt line 0 for CPU1 Master */
|
||||
HSEM->C1IER &= ~SemMask;
|
||||
}
|
||||
else /* HSEM_CPU2_COREID */
|
||||
{
|
||||
/*Use interrupt line 1 for CPU2 Master*/
|
||||
HSEM->C2IER &= ~SemMask;
|
||||
}
|
||||
#else
|
||||
HSEM_COMMON->IER &= ~SemMask;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles HSEM interrupt request
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_HSEM_IRQHandler(void)
|
||||
{
|
||||
uint32_t statusreg;
|
||||
#if USE_MULTI_CORE_SHARED_CODE != 0U
|
||||
if (HAL_GetCurrentCPUID() == HSEM_CPU1_COREID)
|
||||
{
|
||||
/* Get the list of masked freed semaphores*/
|
||||
statusreg = HSEM->C1MISR; /*Use interrupt line 0 for CPU1 Master*/
|
||||
|
||||
/*Disable Interrupts*/
|
||||
HSEM->C1IER &= ~((uint32_t)statusreg);
|
||||
|
||||
/*Clear Flags*/
|
||||
HSEM->C1ICR = ((uint32_t)statusreg);
|
||||
}
|
||||
else /* HSEM_CPU2_COREID */
|
||||
{
|
||||
/* Get the list of masked freed semaphores*/
|
||||
statusreg = HSEM->C2MISR;/*Use interrupt line 1 for CPU2 Master*/
|
||||
|
||||
/*Disable Interrupts*/
|
||||
HSEM->C2IER &= ~((uint32_t)statusreg);
|
||||
|
||||
/*Clear Flags*/
|
||||
HSEM->C2ICR = ((uint32_t)statusreg);
|
||||
}
|
||||
#else
|
||||
/* Get the list of masked freed semaphores*/
|
||||
statusreg = HSEM_COMMON->MISR;
|
||||
|
||||
/*Disable Interrupts*/
|
||||
HSEM_COMMON->IER &= ~((uint32_t)statusreg);
|
||||
|
||||
/*Clear Flags*/
|
||||
HSEM_COMMON->ICR = ((uint32_t)statusreg);
|
||||
|
||||
#endif
|
||||
/* Call FreeCallback */
|
||||
HAL_HSEM_FreeCallback(statusreg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Semaphore Released Callback.
|
||||
* @param SemMask: Mask of Released semaphores
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_HSEM_FreeCallback(uint32_t SemMask)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(SemMask);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_HSEM_FreeCallback can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_HSEM_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_i2c_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief I2C Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of I2C Extended peripheral:
|
||||
* + Filter Mode Functions
|
||||
* + WakeUp Mode Functions
|
||||
* + FastModePlus Functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### I2C peripheral Extended features #####
|
||||
==============================================================================
|
||||
|
||||
[..] Comparing to other previous devices, the I2C interface for 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 mode(s)
|
||||
(+) Disable or enable Fast Mode Plus
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..] This driver provides functions to configure Noise Filter and Wake Up Feature
|
||||
(#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()
|
||||
(#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()
|
||||
(#) Configure the enable or disable of I2C Wake Up Mode using the functions :
|
||||
(++) HAL_I2CEx_EnableWakeUp()
|
||||
(++) HAL_I2CEx_DisableWakeUp()
|
||||
(#) Configure the enable or disable of fast mode plus driving capability using the functions :
|
||||
(++) HAL_I2CEx_EnableFastModePlus()
|
||||
(++) HAL_I2CEx_DisableFastModePlus()
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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 Filter Mode Functions
|
||||
* @brief Filter Mode Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Filter Mode Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Noise Filters
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure I2C Analog noise filter.
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @param AnalogFilter New state of the Analog filter.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
|
||||
assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Reset I2Cx ANOFF bit */
|
||||
hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
|
||||
|
||||
/* Set analog filter bit*/
|
||||
hi2c->Instance->CR1 |= AnalogFilter;
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure I2C Digital noise filter.
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
|
||||
{
|
||||
uint32_t tmpreg;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
|
||||
assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Get the old register value */
|
||||
tmpreg = hi2c->Instance->CR1;
|
||||
|
||||
/* Reset I2Cx DNF bits [11:8] */
|
||||
tmpreg &= ~(I2C_CR1_DNF);
|
||||
|
||||
/* Set I2Cx DNF coefficient */
|
||||
tmpreg |= DigitalFilter << 8U;
|
||||
|
||||
/* Store the new register value */
|
||||
hi2c->Instance->CR1 = tmpreg;
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup I2CEx_Exported_Functions_Group2 WakeUp Mode Functions
|
||||
* @brief WakeUp Mode Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### WakeUp Mode Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Wake Up Feature
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable I2C wakeup from Stop mode(s).
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Enable wakeup from stop mode */
|
||||
hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable I2C wakeup from Stop mode(s).
|
||||
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified I2Cx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_BUSY;
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
__HAL_I2C_DISABLE(hi2c);
|
||||
|
||||
/* Enable wakeup from stop mode */
|
||||
hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
|
||||
|
||||
__HAL_I2C_ENABLE(hi2c);
|
||||
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hi2c);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup I2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
|
||||
* @brief Fast Mode Plus Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Fast Mode Plus Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Fast Mode Plus
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable the I2C fast mode plus driving capability.
|
||||
* @param ConfigFastModePlus Selects the pin.
|
||||
* This parameter can be one of the @ref I2CEx_FastModePlus values
|
||||
* @note For I2C1, fast mode plus driving capability can be enabled on all selected
|
||||
* I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
|
||||
* on each one of the following pins PB6, PB7, PB8 and PB9.
|
||||
* @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
|
||||
* can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
|
||||
* @note For all I2C2 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C2 parameter.
|
||||
* @note For all I2C3 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C3 parameter.
|
||||
* @note For all I2C4 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C4 parameter.
|
||||
* @note For all I2C5 pins fast mode plus driving capability can be enabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C5 parameter.
|
||||
* @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
|
||||
* @note For I2C1, fast mode plus driving capability can be disabled on all selected
|
||||
* I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
|
||||
* on each one of the following pins PB6, PB7, PB8 and PB9.
|
||||
* @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
|
||||
* can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
|
||||
* @note For all I2C2 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C2 parameter.
|
||||
* @note For all I2C3 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C3 parameter.
|
||||
* @note For all I2C4 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C4 parameter.
|
||||
* @note For all I2C5 pins fast mode plus driving capability can be disabled
|
||||
* only by using I2C_FASTMODEPLUS_I2C5 parameter.
|
||||
* @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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_i2s_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief I2S HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of I2S extension peripheral:
|
||||
* + Extension features Functions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
===== I2S FULL DUPLEX FEATURE =====
|
||||
I2S Full Duplex APIs are available in stm32h7xx_hal_i2s.c/.h
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,284 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_iwdg.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### IWDG Generic features #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(+) The IWDG can be started by either software or hardware (configurable
|
||||
through option byte).
|
||||
|
||||
(+) The IWDG is clocked by the Low-Speed Internal clock (LSI) and thus stays
|
||||
active even if the main clock fails.
|
||||
|
||||
(+) Once the IWDG is started, the LSI is forced ON and both cannot 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 into 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 the CPU 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_IWDG1() or __HAL_DBGMCU_FREEZE2_IWDG2() and
|
||||
__HAL_DBGMCU_UnFreeze_IWDG1 or __HAL_DBGMCU_UnFreeze2_IWDG2() macros.
|
||||
|
||||
[..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
|
||||
The IWDG timeout may vary due to LSI clock frequency dispersion.
|
||||
STM32H7xx devices provide the capability to measure the LSI clock
|
||||
frequency (LSI clock is internally connected to TIM16 CH1 input capture).
|
||||
The measured value can be used to have an IWDG timeout with an
|
||||
acceptable accuracy.
|
||||
|
||||
[..] Default timeout value (necessary for IWDG_SR status register update):
|
||||
Constant LSI_VALUE is defined based on the nominal LSI clock frequency.
|
||||
This frequency being subject to variations as mentioned above, the
|
||||
default timeout value (defined through constant HAL_IWDG_DEFAULT_TIMEOUT
|
||||
below) may become too short or too long.
|
||||
In such cases, this default timeout value can be tuned by redefining
|
||||
the constant LSI_VALUE at user-application level (based, for instance,
|
||||
on the measured LSI clock frequency as explained above).
|
||||
|
||||
##### 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 counting down.
|
||||
(++) Enable write access to configuration registers:
|
||||
IWDG_PR, IWDG_RLR and 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.
|
||||
(++) 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 with exact time base.
|
||||
(+++) Else modify Window register. This will automatically reload
|
||||
watchdog counter.
|
||||
(++) Wait for status flags to be reset.
|
||||
|
||||
(#) 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
|
||||
*/
|
||||
|
||||
/* 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 needs up to 5 LSI clock periods divided by the clock
|
||||
prescaler to be updated. The number of LSI clock periods is upper-rounded to
|
||||
6 for the timeout value calculation.
|
||||
The timeout value is calculated using the highest prescaler (256) and
|
||||
the LSI_VALUE constant. The value of this constant can be changed by the user
|
||||
to take into account possible LSI clock period variations.
|
||||
The timeout value is multiplied by 1000 to be converted in milliseconds.
|
||||
LSI startup time is also considered here by adding LSI_STARTUP_TIME
|
||||
converted in milliseconds. */
|
||||
#define HAL_IWDG_DEFAULT_TIMEOUT (((6UL * 256UL * 1000UL) / (LSI_VALUE / 128U)) + \
|
||||
((LSI_STARTUP_TIME / 1000UL) + 1UL))
|
||||
#define IWDG_KERNEL_UPDATE_FLAGS (IWDG_SR_WVU | IWDG_SR_RVU | IWDG_SR_PVU)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* 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 automatically */
|
||||
__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 & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
|
||||
{
|
||||
if ((hiwdg->Instance->SR & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u)
|
||||
{
|
||||
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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_ltdc_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief LTDC Extension HAL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(HAL_LTDC_MODULE_ENABLED) && defined(HAL_DSI_MODULE_ENABLED)
|
||||
|
||||
#if defined (LTDC) && defined (DSI)
|
||||
|
||||
/** @defgroup LTDCEx LTDCEx
|
||||
* @brief LTDC HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup LTDCEx_Exported_Functions LTDC Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup LTDCEx_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 LTDC
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Retrieve common parameters from DSI Video mode configuration structure
|
||||
* @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
|
||||
* the configuration information for the LTDC.
|
||||
* @param VidCfg pointer to a DSI_VidCfgTypeDef structure that contains
|
||||
* the DSI video mode configuration parameters
|
||||
* @note The implementation of this function is taking into account the LTDC
|
||||
* polarities inversion as described in the current LTDC specification
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_LTDCEx_StructInitFromVideoConfig(LTDC_HandleTypeDef *hltdc, DSI_VidCfgTypeDef *VidCfg)
|
||||
{
|
||||
/* Retrieve signal polarities from DSI */
|
||||
|
||||
/* The following polarity is inverted:
|
||||
LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH */
|
||||
|
||||
#if !defined(POLARITIES_INVERSION_UPDATED)
|
||||
/* Note 1 : Code in line w/ Current LTDC specification */
|
||||
hltdc->Init.DEPolarity = (VidCfg->DEPolarity == \
|
||||
DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
|
||||
hltdc->Init.VSPolarity = (VidCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AH : LTDC_VSPOLARITY_AL;
|
||||
hltdc->Init.HSPolarity = (VidCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AH : LTDC_HSPOLARITY_AL;
|
||||
#else
|
||||
/* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
|
||||
hltdc->Init.DEPolarity = VidCfg->DEPolarity << 29;
|
||||
hltdc->Init.VSPolarity = VidCfg->VSPolarity << 29;
|
||||
hltdc->Init.HSPolarity = VidCfg->HSPolarity << 29;
|
||||
#endif /* POLARITIES_INVERSION_UPDATED */
|
||||
|
||||
/* Retrieve vertical timing parameters from DSI */
|
||||
hltdc->Init.VerticalSync = VidCfg->VerticalSyncActive - 1U;
|
||||
hltdc->Init.AccumulatedVBP = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch - 1U;
|
||||
hltdc->Init.AccumulatedActiveH = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + \
|
||||
VidCfg->VerticalActive - 1U;
|
||||
hltdc->Init.TotalHeigh = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + \
|
||||
VidCfg->VerticalActive + VidCfg->VerticalFrontPorch - 1U;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieve common parameters from DSI Adapted command mode configuration structure
|
||||
* @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
|
||||
* the configuration information for the LTDC.
|
||||
* @param CmdCfg pointer to a DSI_CmdCfgTypeDef structure that contains
|
||||
* the DSI command mode configuration parameters
|
||||
* @note The implementation of this function is taking into account the LTDC
|
||||
* polarities inversion as described in the current LTDC specification
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_LTDCEx_StructInitFromAdaptedCommandConfig(LTDC_HandleTypeDef *hltdc, DSI_CmdCfgTypeDef *CmdCfg)
|
||||
{
|
||||
/* Retrieve signal polarities from DSI */
|
||||
|
||||
/* The following polarities are inverted:
|
||||
LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH
|
||||
LTDC_VSPOLARITY_AL <-> LTDC_VSPOLARITY_AH
|
||||
LTDC_HSPOLARITY_AL <-> LTDC_HSPOLARITY_AH)*/
|
||||
|
||||
#if !defined(POLARITIES_INVERSION_UPDATED)
|
||||
/* Note 1 : Code in line w/ Current LTDC specification */
|
||||
hltdc->Init.DEPolarity = (CmdCfg->DEPolarity == \
|
||||
DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
|
||||
hltdc->Init.VSPolarity = (CmdCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AL : LTDC_VSPOLARITY_AH;
|
||||
hltdc->Init.HSPolarity = (CmdCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AL : LTDC_HSPOLARITY_AH;
|
||||
#else
|
||||
/* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
|
||||
hltdc->Init.DEPolarity = CmdCfg->DEPolarity << 29;
|
||||
hltdc->Init.VSPolarity = CmdCfg->VSPolarity << 29;
|
||||
hltdc->Init.HSPolarity = CmdCfg->HSPolarity << 29;
|
||||
#endif /* POLARITIES_INVERSION_UPDATED */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* LTDC && DSI */
|
||||
|
||||
#endif /* HAL_LTCD_MODULE_ENABLED && HAL_DSI_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,968 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_mdios.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
The 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 resources by calling the HAL_MDIOS_DeInit() API.
|
||||
(##) HAL_MDIOS_MspDeInit() must be implemented to reset low level resources
|
||||
(GPIO, Clocks, NVIC configuration ...)
|
||||
|
||||
*** Callback registration ***
|
||||
=============================================
|
||||
|
||||
The compilation define USE_HAL_MDIOS_REGISTER_CALLBACKS when set to 1
|
||||
allows the user to configure dynamically the driver callbacks.
|
||||
Use Function @ref HAL_MDIOS_RegisterCallback() to register an interrupt callback.
|
||||
|
||||
Function @ref HAL_MDIOS_RegisterCallback() allows to register following callbacks:
|
||||
(+) WriteCpltCallback : Write Complete Callback.
|
||||
(+) ReadCpltCallback : Read Complete Callback.
|
||||
(+) ErrorCallback : Error Callback.
|
||||
(+) WakeUpCallback : Wake UP Callback
|
||||
(+) MspInitCallback : MspInit Callback.
|
||||
(+) MspDeInitCallback : MspDeInit Callback.
|
||||
|
||||
This function takes as parameters the HAL peripheral handle, the Callback ID
|
||||
and a pointer to the user callback function.
|
||||
|
||||
Use function @ref HAL_MDIOS_UnRegisterCallback() to reset a callback to the default
|
||||
weak function.
|
||||
@ref HAL_MDIOS_UnRegisterCallback takes as parameters the HAL peripheral handle,
|
||||
and the Callback ID.
|
||||
This function allows to reset following callbacks:
|
||||
(+) WriteCpltCallback : Write Complete Callback.
|
||||
(+) ReadCpltCallback : Read Complete Callback.
|
||||
(+) ErrorCallback : Error Callback.
|
||||
(+) WakeUpCallback : Wake UP Callback
|
||||
(+) MspInitCallback : MspInit Callback.
|
||||
(+) MspDeInitCallback : MspDeInit Callback.
|
||||
|
||||
By default, after the HAL_MDIOS_Init and when the state is HAL_MDIOS_STATE_RESET
|
||||
all callbacks are set to the corresponding weak functions:
|
||||
examples @ref HAL_MDIOS_WriteCpltCallback(), @ref HAL_MDIOS_ReadCpltCallback().
|
||||
Exception done for MspInit and MspDeInit functions that are
|
||||
reset to the legacy weak function in the HAL_MDIOS_Init/ @ref HAL_MDIOS_DeInit only when
|
||||
these callbacks are null (not registered beforehand).
|
||||
if not, MspInit or MspDeInit are not null, the HAL_MDIOS_Init/ @ref HAL_MDIOS_DeInit
|
||||
keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
|
||||
|
||||
Callbacks can be registered/unregistered in HAL_MDIOS_STATE_READY state only.
|
||||
Exception done MspInit/MspDeInit that can be registered/unregistered
|
||||
in HAL_MDIOS_STATE_READY or HAL_MDIOS_STATE_RESET state,
|
||||
thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
|
||||
In that case first register the MspInit/MspDeInit user callbacks
|
||||
using @ref HAL_MDIOS_RegisterCallback() before calling @ref HAL_MDIOS_DeInit
|
||||
or HAL_MDIOS_Init function.
|
||||
|
||||
When The compilation define USE_HAL_MDIOS_REGISTER_CALLBACKS is set to 0 or
|
||||
not defined, the callback registration feature is not available and all callbacks
|
||||
are set to the corresponding weak functions.
|
||||
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
#if defined (MDIOS)
|
||||
/** @defgroup MDIOS MDIOS
|
||||
* @brief HAL MDIOS module driver
|
||||
* @{
|
||||
*/
|
||||
#ifdef HAL_MDIOS_MODULE_ENABLED
|
||||
|
||||
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup MDIOS_Private_Define MDIOS 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 + 0x100U)
|
||||
#define MDIOS_DOUT_BASE_ADDR (MDIOS_BASE + 0x180U)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/** @defgroup MDIOS_Private_Functions MDIOS Private Functions
|
||||
* @{
|
||||
*/
|
||||
static void MDIOS_InitCallbacksToDefault(MDIOS_HandleTypeDef *hmdios);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
/* 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;
|
||||
|
||||
/* 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));
|
||||
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
|
||||
if(hmdios->State == HAL_MDIOS_STATE_RESET)
|
||||
{
|
||||
MDIOS_InitCallbacksToDefault(hmdios);
|
||||
|
||||
if(hmdios->MspInitCallback == NULL)
|
||||
{
|
||||
hmdios->MspInitCallback = HAL_MDIOS_MspInit;
|
||||
}
|
||||
|
||||
/* Init the low level hardware */
|
||||
hmdios->MspInitCallback(hmdios);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if(hmdios->State == HAL_MDIOS_STATE_RESET)
|
||||
{
|
||||
/* Init the low level hardware */
|
||||
HAL_MDIOS_MspInit(hmdios);
|
||||
}
|
||||
|
||||
#endif /* (USE_HAL_MDIOS_REGISTER_CALLBACKS) */
|
||||
|
||||
/* 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;
|
||||
|
||||
hmdios->ErrorCode = HAL_MDIOS_ERROR_NONE;
|
||||
|
||||
/* 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);
|
||||
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
|
||||
if(hmdios->MspDeInitCallback == NULL)
|
||||
{
|
||||
hmdios->MspDeInitCallback = HAL_MDIOS_MspDeInit;
|
||||
}
|
||||
/* DeInit the low level hardware */
|
||||
hmdios->MspDeInitCallback(hmdios);
|
||||
#else
|
||||
|
||||
/* DeInit the low level hardware */
|
||||
HAL_MDIOS_MspDeInit(hmdios);
|
||||
|
||||
#endif /* (USE_HAL_MDIOS_REGISTER_CALLBACKS) */
|
||||
|
||||
/* 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
|
||||
*/
|
||||
}
|
||||
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/**
|
||||
* @brief Register a User MDIOS Callback
|
||||
* To be used instead of the weak predefined callback
|
||||
* @param hmdios mdios handle
|
||||
* @param CallbackID ID of the callback to be registered
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_MDIOS_WRITE_COMPLETE_CB_ID Write Complete Callback ID
|
||||
* @arg @ref HAL_MDIOS_READ_COMPLETE_CB_ID Read Complete Callback ID
|
||||
* @arg @ref HAL_MDIOS_ERROR_CB_ID Error Callback ID
|
||||
* @arg @ref HAL_MDIOS_WAKEUP_CB_ID Wake Up Callback ID
|
||||
* @arg @ref HAL_MDIOS_MSPINIT_CB_ID MspInit callback ID
|
||||
* @arg @ref HAL_MDIOS_MSPDEINIT_CB_ID MspDeInit callback ID
|
||||
* @param pCallback pointer to the Callback function
|
||||
* @retval status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_RegisterCallback(MDIOS_HandleTypeDef *hmdios, HAL_MDIOS_CallbackIDTypeDef CallbackID, pMDIOS_CallbackTypeDef pCallback)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if(pCallback == NULL)
|
||||
{
|
||||
/* Update the error code */
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
|
||||
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
if(hmdios->State == HAL_MDIOS_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_MDIOS_WRITE_COMPLETE_CB_ID :
|
||||
hmdios->WriteCpltCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_READ_COMPLETE_CB_ID :
|
||||
hmdios->ReadCpltCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_ERROR_CB_ID :
|
||||
hmdios->ErrorCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_WAKEUP_CB_ID :
|
||||
hmdios->WakeUpCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_MSPINIT_CB_ID :
|
||||
hmdios->MspInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_MSPDEINIT_CB_ID :
|
||||
hmdios->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(hmdios->State == HAL_MDIOS_STATE_RESET)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_MDIOS_MSPINIT_CB_ID :
|
||||
hmdios->MspInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_MSPDEINIT_CB_ID :
|
||||
hmdios->MspDeInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister an MDIOS Callback
|
||||
* MDIOS callback is redirected to the weak predefined callback
|
||||
* @param hmdios mdios handle
|
||||
* @param CallbackID ID of the callback to be unregistered
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_MDIOS_WRITE_COMPLETE_CB_ID Write Complete Callback ID
|
||||
* @arg @ref HAL_MDIOS_READ_COMPLETE_CB_ID Read Complete Callback ID
|
||||
* @arg @ref HAL_MDIOS_ERROR_CB_ID Error Callback ID
|
||||
* @arg @ref HAL_MDIOS_WAKEUP_CB_ID Wake Up Callback ID
|
||||
* @arg @ref HAL_MDIOS_MSPINIT_CB_ID MspInit callback ID
|
||||
* @arg @ref HAL_MDIOS_MSPDEINIT_CB_ID MspDeInit callback ID
|
||||
* @retval status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MDIOS_UnRegisterCallback(MDIOS_HandleTypeDef *hmdios, HAL_MDIOS_CallbackIDTypeDef CallbackID)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hmdios);
|
||||
|
||||
if(hmdios->State == HAL_MDIOS_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_MDIOS_WRITE_COMPLETE_CB_ID :
|
||||
hmdios->WriteCpltCallback = HAL_MDIOS_WriteCpltCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_READ_COMPLETE_CB_ID :
|
||||
hmdios->ReadCpltCallback = HAL_MDIOS_ReadCpltCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_ERROR_CB_ID :
|
||||
hmdios->ErrorCallback = HAL_MDIOS_ErrorCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_WAKEUP_CB_ID :
|
||||
hmdios->WakeUpCallback = HAL_MDIOS_WakeUpCallback;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_MSPINIT_CB_ID :
|
||||
hmdios->MspInitCallback = HAL_MDIOS_MspInit;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_MSPDEINIT_CB_ID :
|
||||
hmdios->MspDeInitCallback = HAL_MDIOS_MspDeInit;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(hmdios->State == HAL_MDIOS_STATE_RESET)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_MDIOS_MSPINIT_CB_ID :
|
||||
hmdios->MspInitCallback = HAL_MDIOS_MspInit;
|
||||
break;
|
||||
|
||||
case HAL_MDIOS_MSPDEINIT_CB_ID :
|
||||
hmdios->MspDeInitCallback = HAL_MDIOS_MspDeInit;
|
||||
break;
|
||||
|
||||
default :
|
||||
/* Update the error code */
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
|
||||
/* Return error status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hmdios);
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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 + (4U * 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 + (4U * 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(const 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(const 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) != (uint32_t)RESET)
|
||||
{
|
||||
/* Write register flag */
|
||||
if(HAL_MDIOS_GetWrittenRegAddress(hmdios) != (uint32_t)RESET)
|
||||
{
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/*Call registered Write complete callback*/
|
||||
hmdios->WriteCpltCallback(hmdios);
|
||||
#else
|
||||
/* Write callback function */
|
||||
HAL_MDIOS_WriteCpltCallback(hmdios);
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
|
||||
/* Clear write register flag */
|
||||
hmdios->Instance->CWRFR |= MDIOS_ALL_REG_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read Register Interrupt enabled ? */
|
||||
if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_READ) != (uint32_t)RESET)
|
||||
{
|
||||
/* Read register flag */
|
||||
if(HAL_MDIOS_GetReadRegAddress(hmdios) != (uint32_t)RESET)
|
||||
{
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/*Call registered Read complete callback*/
|
||||
hmdios->ReadCpltCallback(hmdios);
|
||||
#else
|
||||
/* Read callback function */
|
||||
HAL_MDIOS_ReadCpltCallback(hmdios);
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
|
||||
/* Clear read register flag */
|
||||
hmdios->Instance->CRDFR |= MDIOS_ALL_REG_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
/* Error Interrupt enabled ? */
|
||||
if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_ERROR) != (uint32_t)RESET)
|
||||
{
|
||||
/* All Errors Flag */
|
||||
if(__HAL_MDIOS_GET_ERROR_FLAG(hmdios, MDIOS_ALL_ERRORS_FLAG) != (uint32_t)RESET)
|
||||
{
|
||||
hmdios->ErrorCode |= HAL_MDIOS_ERROR_DATA;
|
||||
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/*Call registered Error callback*/
|
||||
hmdios->ErrorCallback(hmdios);
|
||||
#else
|
||||
/* Error Callback */
|
||||
HAL_MDIOS_ErrorCallback(hmdios);
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
|
||||
/* Clear errors flag */
|
||||
__HAL_MDIOS_CLEAR_ERROR_FLAG(hmdios, MDIOS_ALL_ERRORS_FLAG);
|
||||
}
|
||||
hmdios->ErrorCode = HAL_MDIOS_ERROR_NONE;
|
||||
}
|
||||
#if defined(DUAL_CORE)
|
||||
|
||||
if (HAL_GetCurrentCPUID() == CM7_CPUID)
|
||||
{
|
||||
if(__HAL_MDIOS_WAKEUP_EXTI_GET_FLAG(MDIOS_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
|
||||
{
|
||||
/* Clear MDIOS WAKEUP Exti pending bit */
|
||||
__HAL_MDIOS_WAKEUP_EXTI_CLEAR_FLAG(MDIOS_WAKEUP_EXTI_LINE);
|
||||
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/*Call registered WakeUp callback*/
|
||||
hmdios->WakeUpCallback(hmdios);
|
||||
#else
|
||||
/* MDIOS WAKEUP callback */
|
||||
HAL_MDIOS_WakeUpCallback(hmdios);
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(__HAL_MDIOS_WAKEUP_EXTID2_GET_FLAG(MDIOS_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
|
||||
{
|
||||
/* Clear MDIOS WAKEUP Exti D2 pending bit */
|
||||
__HAL_MDIOS_WAKEUP_EXTID2_CLEAR_FLAG(MDIOS_WAKEUP_EXTI_LINE);
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/*Call registered WakeUp callback*/
|
||||
hmdios->WakeUpCallback(hmdios);
|
||||
#else
|
||||
/* MDIOS WAKEUP callback */
|
||||
HAL_MDIOS_WakeUpCallback(hmdios);
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* check MDIOS WAKEUP exti flag */
|
||||
if(__HAL_MDIOS_WAKEUP_EXTI_GET_FLAG(MDIOS_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
|
||||
{
|
||||
/* Clear MDIOS WAKEUP Exti pending bit */
|
||||
__HAL_MDIOS_WAKEUP_EXTI_CLEAR_FLAG(MDIOS_WAKEUP_EXTI_LINE);
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/*Call registered WakeUp callback*/
|
||||
hmdios->WakeUpCallback(hmdios);
|
||||
#else
|
||||
/* MDIOS WAKEUP callback */
|
||||
HAL_MDIOS_WakeUpCallback(hmdios);
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 code of the HAL state machine.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Gets MDIOS error code
|
||||
* @param hmdios: mdios handle
|
||||
* @retval mdios error code
|
||||
*/
|
||||
uint32_t HAL_MDIOS_GetError(const MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* return the error code */
|
||||
return hmdios->ErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the MDIOS HAL state
|
||||
* @param hmdios: mdios handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_MDIOS_StateTypeDef HAL_MDIOS_GetState(const MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Return MDIOS state */
|
||||
return hmdios->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
|
||||
/** @addtogroup MDIOS_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
static void MDIOS_InitCallbacksToDefault(MDIOS_HandleTypeDef *hmdios)
|
||||
{
|
||||
/* Init the MDIOS Callback settings */
|
||||
hmdios->WriteCpltCallback = HAL_MDIOS_WriteCpltCallback; /* Legacy weak WriteCpltCallback */
|
||||
hmdios->ReadCpltCallback = HAL_MDIOS_ReadCpltCallback; /* Legacy weak ReadCpltCallback */
|
||||
hmdios->ErrorCallback = HAL_MDIOS_ErrorCallback; /* Legacy weak ErrorCallback */
|
||||
hmdios->WakeUpCallback = HAL_MDIOS_WakeUpCallback; /* Legacy weak WakeUpCallback */
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
|
||||
#endif /* HAL_MDIOS_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* MDIOS */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,353 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_mmc_ex.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The 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
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MMCEx MMCEx
|
||||
* @brief MMC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (SDMMC1) || defined (SDMMC2)
|
||||
#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 transferred data
|
||||
* @param pDataBuffer1: Pointer to the buffer1 that will contain/receive the transferred 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)(MMC_BLOCKSIZE * 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 DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t errorstate;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* Check the case of 4kB blocks (field DATA SECTOR SIZE of extended CSD register) */
|
||||
if (((hmmc->Ext_CSD[(MMC_EXT_CSD_DATA_SEC_SIZE_INDEX / 4)] >> MMC_EXT_CSD_DATA_SEC_SIZE_POS) & 0x000000FFU) != 0x0U)
|
||||
{
|
||||
if ((NumberOfBlocks % 8U) != 0U)
|
||||
{
|
||||
/* The number of blocks should be a multiple of 8 sectors of 512 bytes = 4 KBytes */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_BLOCK_LEN_ERR;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((BlockAdd % 8U) != 0U)
|
||||
{
|
||||
/* The address should be aligned to 8 (corresponding to 4 KBytes blocks) */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_MISALIGNED;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
DmaBase0_reg = hmmc->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hmmc->Instance->IDMABASE1;
|
||||
|
||||
if ((hmmc->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
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)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* Configure the MMC DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = MMC_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;
|
||||
(void)SDMMC_ConfigData(hmmc->Instance, &config);
|
||||
|
||||
hmmc->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hmmc->Instance);
|
||||
|
||||
hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Read Blocks in DMA mode */
|
||||
hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
|
||||
|
||||
/* Read Multi Block command */
|
||||
errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, add);
|
||||
if (errorstate != HAL_MMC_ERROR_NONE)
|
||||
{
|
||||
hmmc->State = HAL_MMC_STATE_READY;
|
||||
hmmc->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write block(s) to a specified address in a card. The transferred 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;
|
||||
uint32_t DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* Check the case of 4kB blocks (field DATA SECTOR SIZE of extended CSD register) */
|
||||
if (((hmmc->Ext_CSD[(MMC_EXT_CSD_DATA_SEC_SIZE_INDEX / 4)] >> MMC_EXT_CSD_DATA_SEC_SIZE_POS) & 0x000000FFU) != 0x0U)
|
||||
{
|
||||
if ((NumberOfBlocks % 8U) != 0U)
|
||||
{
|
||||
/* The number of blocks should be a multiple of 8 sectors of 512 bytes = 4 KBytes */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_BLOCK_LEN_ERR;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((BlockAdd % 8U) != 0U)
|
||||
{
|
||||
/* The address should be aligned to 8 (corresponding to 4 KBytes blocks) */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_MISALIGNED;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
DmaBase0_reg = hmmc->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hmmc->Instance->IDMABASE1;
|
||||
|
||||
if ((hmmc->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
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)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* Configure the MMC DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = MMC_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;
|
||||
(void)SDMMC_ConfigData(hmmc->Instance, &config);
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hmmc->Instance);
|
||||
|
||||
hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Write Blocks in DMA mode */
|
||||
hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
|
||||
|
||||
/* Write Multi Block command */
|
||||
errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add);
|
||||
if (errorstate != HAL_MMC_ERROR_NONE)
|
||||
{
|
||||
hmmc->State = HAL_MMC_STATE_READY;
|
||||
hmmc->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
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 */
|
||||
#endif /* SDMMC1 || SDMMC2 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_msp_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief HAL MSP module.
|
||||
* This file template is located in the HAL folder and should be copied
|
||||
* to the user folder.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### How to use this driver #####
|
||||
===============================================================================
|
||||
[..]
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_MSP HAL MSP
|
||||
* @brief HAL MSP module.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup HAL_MSP_Private_Functions HAL MSP Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the Global MSP.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the Global MSP.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MspDeInit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the PPP MSP.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PPP_MspInit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the PPP MSP.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PPP_MspDeInit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,433 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_opamp_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended OPAMP HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the operational amplifier(s) peripheral:
|
||||
* + Extended Initialization and de-initialization functions
|
||||
* + Extended Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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;
|
||||
uint32_t trimmingvaluep1;
|
||||
uint32_t trimmingvaluen2;
|
||||
uint32_t trimmingvaluep2;
|
||||
|
||||
/* 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) || (hopamp2 == NULL))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
/* Check if OPAMP in calibration mode and calibration not yet enable */
|
||||
else if(hopamp1->State != HAL_OPAMP_STATE_READY)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else if(hopamp2->State != HAL_OPAMP_STATE_READY)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 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 = 16U;
|
||||
trimmingvaluen2 = 16U;
|
||||
delta = 8U;
|
||||
|
||||
while (delta != 0U)
|
||||
{
|
||||
/* 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)!= 0U)
|
||||
{
|
||||
/* 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)!= 0U)
|
||||
{
|
||||
/* 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 >>= 1U;
|
||||
}
|
||||
|
||||
/* 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)) != 0U)
|
||||
{
|
||||
/* 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)) != 0U)
|
||||
{
|
||||
/* 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 = 16U;
|
||||
trimmingvaluep2 = 16U;
|
||||
delta = 8U;
|
||||
|
||||
while (delta != 0U)
|
||||
{
|
||||
/* 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)!= 0U)
|
||||
{
|
||||
/* 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)!= 0U)
|
||||
{
|
||||
/* 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 >>= 1U;
|
||||
}
|
||||
|
||||
/* 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)!= 0U)
|
||||
{
|
||||
/* 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)!= 0U)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
/* Check the OPAMP handle allocation */
|
||||
/* Check if OPAMP locked */
|
||||
else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
|
||||
|
||||
/* OPAMP state changed to locked */
|
||||
hopamp->State = HAL_OPAMP_STATE_BUSY;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,341 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_pcd_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief PCD Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the USB Peripheral Controller:
|
||||
* + Extended features functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup PCDEx PCDEx
|
||||
* @brief PCD Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
|
||||
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||
/* 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
|
||||
* @{
|
||||
*/
|
||||
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||
/**
|
||||
* @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;
|
||||
uint32_t Tx_Offset;
|
||||
|
||||
/* 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 == 0U)
|
||||
{
|
||||
hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
|
||||
for (i = 0U; i < (fifo - 1U); i++)
|
||||
{
|
||||
Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
|
||||
}
|
||||
|
||||
/* Multiply Tx_Size by 2 to get higher performance */
|
||||
hpcd->Instance->DIEPTXF[fifo - 1U] = ((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 = 1U;
|
||||
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 Deactivate 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 = 0U;
|
||||
USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM;
|
||||
USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle BatteryCharging 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();
|
||||
|
||||
/* Enable DCD : Data Contact Detect */
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_DCDEN;
|
||||
|
||||
/* Wait for Min DCD Timeout */
|
||||
HAL_Delay(300U);
|
||||
|
||||
/* Check Detect flag */
|
||||
if ((USBx->GCCFG & USB_OTG_GCCFG_DCDET) == USB_OTG_GCCFG_DCDET)
|
||||
{
|
||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||
hpcd->BCDCallback(hpcd, PCD_BCD_CONTACT_DETECTION);
|
||||
#else
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CONTACT_DETECTION);
|
||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/* Primary detection: checks if connected to Standard Downstream Port
|
||||
(without charging capability) */
|
||||
USBx->GCCFG &= ~USB_OTG_GCCFG_DCDEN;
|
||||
HAL_Delay(50U);
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_PDEN;
|
||||
HAL_Delay(50U);
|
||||
|
||||
if ((USBx->GCCFG & USB_OTG_GCCFG_PDET) == 0U)
|
||||
{
|
||||
/* Case of Standard Downstream Port */
|
||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||
hpcd->BCDCallback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT);
|
||||
#else
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT);
|
||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* start secondary detection to check connection to Charging Downstream
|
||||
Port or Dedicated Charging Port */
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_PDEN);
|
||||
HAL_Delay(50U);
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_SDEN;
|
||||
HAL_Delay(50U);
|
||||
|
||||
if ((USBx->GCCFG & USB_OTG_GCCFG_SDET) == USB_OTG_GCCFG_SDET)
|
||||
{
|
||||
/* case Dedicated Charging Port */
|
||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||
hpcd->BCDCallback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT);
|
||||
#else
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT);
|
||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* case Charging Downstream Port */
|
||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||
hpcd->BCDCallback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT);
|
||||
#else
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT);
|
||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||
}
|
||||
}
|
||||
|
||||
/* Battery Charging capability discovery finished */
|
||||
(void)HAL_PCDEx_DeActivateBCD(hpcd);
|
||||
|
||||
/* Check for the Timeout, else start USB Device */
|
||||
if ((HAL_GetTick() - tickstart) > 1000U)
|
||||
{
|
||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||
hpcd->BCDCallback(hpcd, PCD_BCD_ERROR);
|
||||
#else
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_ERROR);
|
||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||
hpcd->BCDCallback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
|
||||
#else
|
||||
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
|
||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_PDEN);
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_SDEN);
|
||||
|
||||
/* Power Down USB transceiver */
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
|
||||
|
||||
/* Enable Battery charging */
|
||||
USBx->GCCFG |= USB_OTG_GCCFG_BCDEN;
|
||||
|
||||
hpcd->battery_charging_active = 1U;
|
||||
|
||||
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;
|
||||
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_SDEN);
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_PDEN);
|
||||
|
||||
/* Disable Battery charging */
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_BCDEN);
|
||||
|
||||
hpcd->battery_charging_active = 0U;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,876 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_pwr.c
|
||||
* @author MCD Application Team
|
||||
* @brief PWR HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Power Controller (PWR) peripheral:
|
||||
* + Initialization and de-initialization functions.
|
||||
* + Peripheral Control functions.
|
||||
* + Interrupt Handling functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### PWR peripheral overview #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) The Power control (PWR) provides an overview of the supply architecture
|
||||
for the different power domains and of the supply configuration
|
||||
controller.
|
||||
In the H7 family, the number of power domains is different between
|
||||
device lines. This difference is due to characteristics of each device.
|
||||
|
||||
(#) Domain architecture overview for the different H7 lines:
|
||||
(+) Dual core lines are STM32H745, STM32H747, STM32H755 and STM32H757.
|
||||
These devices have 3 power domains (D1, D2 and D3).
|
||||
The domain D1 contains a CPU (Cortex-M7), a Flash memory and some
|
||||
peripherals. The D2 domain contains peripherals and a CPU
|
||||
(Cortex-M4). The D3 domain contains the system control, I/O logic
|
||||
and low-power peripherals.
|
||||
(+) STM32H72x, STM32H73x, STM32H742, STM32H743, STM32H750 and STM32H753
|
||||
devices have 3 power domains (D1, D2 and D3).
|
||||
The domain D1 contains a CPU (Cortex-M7), a Flash memory and some
|
||||
peripherals. The D2 domain contains peripherals. The D3 domains
|
||||
contains the system control, I/O logic and low-power peripherals.
|
||||
(+) STM32H7Axxx and STM32H7Bxxx devices have 2 power domains (CD and SRD).
|
||||
The core domain (CD) contains a CPU (Cortex-M7), a Flash
|
||||
memory and peripherals. The SmartRun domain contains the system
|
||||
control, I/O logic and low-power peripherals.
|
||||
|
||||
(#) Every entity have low power mode as described below :
|
||||
(#) The CPU low power modes are :
|
||||
(+) CPU CRUN.
|
||||
(+) CPU CSLEEP.
|
||||
(+) CPU CSTOP.
|
||||
(#) The domain low power modes are :
|
||||
(+) DRUN.
|
||||
(+) DSTOP.
|
||||
(+) DSTANDBY.
|
||||
(#) The SYSTEM low power modes are :
|
||||
(+) RUN* : The Run* mode is entered after a POR reset and a wakeup from
|
||||
Standby. In Run* mode, the performance is limited and the
|
||||
system supply configuration shall be programmed. The system
|
||||
enters Run mode only when the ACTVOSRDY bit in PWR control
|
||||
status register 1 (PWR_CSR1) is set to 1.
|
||||
(+) RUN.
|
||||
(+) STOP.
|
||||
(+) STANDBY.
|
||||
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) Power management peripheral is active by default at startup level in
|
||||
STM32h7xx lines.
|
||||
|
||||
(#) Call HAL_PWR_EnableBkUpAccess() and HAL_PWR_DisableBkUpAccess() functions
|
||||
to enable/disable access to the backup domain (RTC registers, RTC backup
|
||||
data registers and backup SRAM).
|
||||
|
||||
(#) Call HAL_PWR_ConfigPVD() after setting parameters to be configured (event
|
||||
mode and voltage threshold) in order to set up the Power Voltage Detector,
|
||||
then use HAL_PWR_EnablePVD() and HAL_PWR_DisablePVD() functions to start
|
||||
and stop the PVD detection.
|
||||
(+) PVD level could be one of the following values :
|
||||
(++) 1V95
|
||||
(++) 2V1
|
||||
(++) 2V25
|
||||
(++) 2V4
|
||||
(++) 2V55
|
||||
(++) 2V7
|
||||
(++) 2V85
|
||||
(++) External voltage level
|
||||
|
||||
(#) Call HAL_PWR_EnableWakeUpPin() and HAL_PWR_DisableWakeUpPin() functions
|
||||
with the right parameter to configure the wake up pin polarity (Low or
|
||||
High) and to enable and disable it.
|
||||
|
||||
(#) Call HAL_PWR_EnterSLEEPMode() function to enter the current Core in SLEEP
|
||||
mode. Wake-up from SLEEP mode could be following to an event or an
|
||||
interrupt according to low power mode intrinsic request called (__WFI()
|
||||
or __WFE()).
|
||||
Please ensure to clear all CPU pending events by calling
|
||||
HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx
|
||||
in SLEEP mode with __WFE() entry.
|
||||
|
||||
(#) Call HAL_PWR_EnterSTOPMode() function to enter the whole system to Stop 0
|
||||
mode for single core devices. For dual core devices, this API will enter
|
||||
the domain (containing Cortex-Mx that executing this function) in DSTOP
|
||||
mode. According to the used parameter, user could select the regulator to
|
||||
be kept actif in low power mode and wake-up event type.
|
||||
Please ensure to clear all CPU pending events by calling
|
||||
HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx
|
||||
in CSTOP mode with __WFE() entry.
|
||||
|
||||
(#) Call HAL_PWR_EnterSTANDBYMode() function to enter the whole system in
|
||||
STANDBY mode for single core devices. For dual core devices, this API
|
||||
will enter the domain (containing Cortex-Mx that executing this function)
|
||||
in DSTANDBY mode.
|
||||
|
||||
(#) Call HAL_PWR_EnableSleepOnExit() and HAL_PWR_DisableSleepOnExit() APIs to
|
||||
enable and disable the Cortex-Mx re-entring in SLEEP mode after an
|
||||
interruption handling is over.
|
||||
|
||||
(#) Call HAL_PWR_EnableSEVOnPend() and HAL_PWR_DisableSEVOnPend() functions
|
||||
to configure the Cortex-Mx to wake-up after any pending event / interrupt
|
||||
even if it's disabled or has insufficient priority to cause exception
|
||||
entry.
|
||||
|
||||
(#) Call HAL_PWR_PVD_IRQHandler() function to handle the PWR PVD interrupt
|
||||
request.
|
||||
|
||||
*** PWR HAL driver macros list ***
|
||||
=============================================
|
||||
[..]
|
||||
Below the list of most used macros in PWR HAL driver.
|
||||
|
||||
(+) __HAL_PWR_VOLTAGESCALING_CONFIG() : Configure the main internal
|
||||
regulator output voltage.
|
||||
(+) __HAL_PWR_GET_FLAG() : Get the PWR pending flags.
|
||||
(+) __HAL_PWR_CLEAR_FLAG() : Clear the PWR pending flags.
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* 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
|
||||
* @{
|
||||
*/
|
||||
#if !defined (DUAL_CORE)
|
||||
#define PVD_MODE_IT (0x00010000U)
|
||||
#define PVD_MODE_EVT (0x00020000U)
|
||||
#endif /* !defined (DUAL_CORE) */
|
||||
|
||||
#define PVD_RISING_EDGE (0x00000001U)
|
||||
#define PVD_FALLING_EDGE (0x00000002U)
|
||||
#define PVD_RISING_FALLING_EDGE (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 #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to deinitialize power peripheral.
|
||||
|
||||
[..]
|
||||
After system reset, the backup domain (RTC registers, RTC backup data
|
||||
registers and backup SRAM) is protected against possible unwanted write
|
||||
accesses.
|
||||
The HAL_PWR_EnableBkUpAccess() function enables the access to the backup
|
||||
domain.
|
||||
The HAL_PWR_DisableBkUpAccess() function disables the access to the backup
|
||||
domain.
|
||||
|
||||
@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 Power Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control Functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to control power peripheral.
|
||||
|
||||
*** 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, 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-Mx is stopped and all PWR domains are remaining
|
||||
active (Powered and Clocked).
|
||||
|
||||
(+) STOP mode : Cortex-Mx is stopped, clocks are stopped and the
|
||||
regulator is running. The Main regulator or the LP
|
||||
regulator could be selected.
|
||||
|
||||
(+) STANDBY mode : All PWR 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-Mx 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 event mode and the voltage threshold detected by the
|
||||
* Programmable 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.
|
||||
* @note For dual core devices, please ensure to configure the EXTI lines for
|
||||
* the different Cortex-Mx through PWR_Exported_Macro provided by this
|
||||
* driver. All combination are allowed: wake up only Cortex-M7, wake up
|
||||
* only Cortex-M4 or wake up Cortex-M7 and Cortex-M4.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_ConfigPVD (const PWR_PVDTypeDef *sConfigPVD)
|
||||
{
|
||||
/* Check the PVD configuration parameter */
|
||||
if (sConfigPVD == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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 previous config */
|
||||
#if !defined (DUAL_CORE)
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_EVENT ();
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_IT ();
|
||||
#endif /* !defined (DUAL_CORE) */
|
||||
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE ();
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE ();
|
||||
|
||||
#if !defined (DUAL_CORE)
|
||||
/* Interrupt mode configuration */
|
||||
if ((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_IT ();
|
||||
}
|
||||
|
||||
/* Event mode configuration */
|
||||
if ((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_EVENT ();
|
||||
}
|
||||
#endif /* !defined (DUAL_CORE) */
|
||||
|
||||
/* Rising edge configuration */
|
||||
if ((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE ();
|
||||
}
|
||||
|
||||
/* Falling edge configuration */
|
||||
if ((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
|
||||
{
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the Programmable 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 Programmable 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 (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, PWR_WAKEUP_PIN1_LOW,
|
||||
* PWR_WAKEUP_PIN2_HIGH, PWR_WAKEUP_PIN2_LOW,
|
||||
* PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW,
|
||||
* PWR_WAKEUP_PIN4_HIGH, PWR_WAKEUP_PIN4_LOW,
|
||||
* PWR_WAKEUP_PIN5_HIGH, PWR_WAKEUP_PIN5_LOW,
|
||||
* PWR_WAKEUP_PIN6_HIGH, PWR_WAKEUP_PIN6_LOW.
|
||||
* @note PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent.
|
||||
* @note The PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, PWR_WAKEUP_PIN5_HIGH
|
||||
* and PWR_WAKEUP_PIN5_LOW are available only for devices that includes
|
||||
* GPIOI port.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_EnableWakeUpPin (uint32_t WakeUpPinPolarity)
|
||||
{
|
||||
/* Check the parameters */
|
||||
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, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3,
|
||||
* PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6,
|
||||
* PWR_WAKEUP_PIN1_HIGH, PWR_WAKEUP_PIN1_LOW,
|
||||
* PWR_WAKEUP_PIN2_HIGH, PWR_WAKEUP_PIN2_LOW,
|
||||
* PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW,
|
||||
* PWR_WAKEUP_PIN4_HIGH, PWR_WAKEUP_PIN4_LOW,
|
||||
* PWR_WAKEUP_PIN5_HIGH, PWR_WAKEUP_PIN5_LOW,
|
||||
* PWR_WAKEUP_PIN6_HIGH, PWR_WAKEUP_PIN6_LOW.
|
||||
* @note The PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, PWR_WAKEUP_PIN5_HIGH
|
||||
* and PWR_WAKEUP_PIN5_LOW are available only for devices that includes
|
||||
* GPIOI port.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_DisableWakeUpPin (uint32_t WakeUpPinx)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_PWR_WAKEUP_PIN (WakeUpPinx));
|
||||
|
||||
/* Disable the wake up pin selected */
|
||||
CLEAR_BIT (PWR->WKUPEPR, (PWR_WKUPEPR_WKUPEN & WakeUpPinx));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter the current core in SLEEP mode (CSLEEP).
|
||||
* @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 is entered with WFI or WFE
|
||||
* intrinsic 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.
|
||||
* @note Ensure to clear pending events before calling this API through
|
||||
* HAL_PWREx_ClearPendingEvent() when the SLEEP entry is WFE.
|
||||
* @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));
|
||||
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(Regulator);
|
||||
|
||||
/* Clear SLEEPDEEP bit of Cortex System Control Register */
|
||||
CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
|
||||
|
||||
/* Select SLEEP mode entry */
|
||||
if (SLEEPEntry == PWR_SLEEPENTRY_WFI)
|
||||
{
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI ();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Request Wait For Event */
|
||||
__WFE ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter STOP mode.
|
||||
* @note For single core devices, this API will enter the system in STOP mode
|
||||
* with all domains in DSTOP, if RUN_D3/RUN_SRD bit in CPUCR register is
|
||||
* cleared.
|
||||
* For dual core devices, this API will enter the domain (containing
|
||||
* Cortex-Mx that executing this function) in DSTOP mode. If all
|
||||
* Cortex-Mx domains are in DSTOP and RUN_D3 bit in CPUCR register is
|
||||
* cleared, all the system will enter in STOP mode.
|
||||
* @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
|
||||
* intrinsic 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.
|
||||
* @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.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_EnterSTOPMode (uint32_t Regulator, uint8_t STOPEntry)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_PWR_REGULATOR (Regulator));
|
||||
assert_param (IS_PWR_STOP_ENTRY (STOPEntry));
|
||||
|
||||
/* Select the regulator state in STOP mode */
|
||||
MODIFY_REG (PWR->CR1, PWR_CR1_LPDS, Regulator);
|
||||
|
||||
/* Configure the PWR mode for the different Domains */
|
||||
#if defined (DUAL_CORE)
|
||||
/* Check CPU ID */
|
||||
if (HAL_GetCurrentCPUID () == CM7_CPUID)
|
||||
{
|
||||
/* Keep DSTOP mode when Cortex-M7 enters DEEP-SLEEP */
|
||||
CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Keep DSTOP mode when Cortex-M4 enters DEEP-SLEEP */
|
||||
CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D2 | PWR_CPUCR_PDDS_D3));
|
||||
}
|
||||
#else /* Single core devices */
|
||||
/* Keep DSTOP mode when Cortex-M7 enter in DEEP-SLEEP */
|
||||
CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
|
||||
|
||||
#if defined (PWR_CPUCR_PDDS_D2)
|
||||
/* Keep DSTOP mode when Cortex-M7 enter in DEEP-SLEEP */
|
||||
CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D2);
|
||||
#endif /* PWR_CPUCR_PDDS_D2 */
|
||||
#endif /* defined (DUAL_CORE) */
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
|
||||
|
||||
/* Ensure that all instructions are 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 */
|
||||
__WFE ();
|
||||
}
|
||||
|
||||
/* Clear SLEEPDEEP bit of Cortex-Mx in the System Control Register */
|
||||
CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter STANDBY mode.
|
||||
* @note For single core devices, this API will enter the system in STANDBY
|
||||
* mode with all domains in DSTANDBY, if RUN_D3/RUN_SRD bit in CPUCR
|
||||
* register is cleared.
|
||||
* For dual core devices, this API will enter the domain (containing
|
||||
* Cortex-Mx that executing this function) in DSTANDBY mode. If all
|
||||
* Cortex-Mx domains are in DSTANDBY and RUN_D3 bit in CPUCR register
|
||||
* is cleared, all the system will enter in STANDBY mode.
|
||||
* @note The system enters Standby mode only when all 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.
|
||||
* @note It is recommended to disable all regulators before entring STANDBY
|
||||
* mode for power consumption saving purpose.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_EnterSTANDBYMode (void)
|
||||
{
|
||||
/* Configure the PWR mode for the different Domains */
|
||||
#if defined (DUAL_CORE)
|
||||
/* Check CPU ID */
|
||||
if (HAL_GetCurrentCPUID () == CM7_CPUID)
|
||||
{
|
||||
/* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */
|
||||
SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
|
||||
SET_BIT (PWR->CPU2CR, (PWR_CPU2CR_PDDS_D1 | PWR_CPU2CR_PDDS_D3));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Enter DSTANDBY mode when Cortex-M4 enters DEEP-SLEEP */
|
||||
SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D2 | PWR_CPUCR_PDDS_D3));
|
||||
SET_BIT (PWR->CPU2CR, (PWR_CPU2CR_PDDS_D2 | PWR_CPU2CR_PDDS_D3));
|
||||
}
|
||||
#else /* Single core devices */
|
||||
/* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */
|
||||
SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
|
||||
|
||||
#if defined (PWR_CPUCR_PDDS_D2)
|
||||
/* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */
|
||||
SET_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D2);
|
||||
#endif /* PWR_CPUCR_PDDS_D2 */
|
||||
#endif /* defined (DUAL_CORE) */
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
|
||||
|
||||
/* Ensure that all instructions are done before entering STOP mode */
|
||||
__DSB ();
|
||||
__ISB ();
|
||||
|
||||
/* This option is used to ensure that store operations are completed */
|
||||
#if defined (__CC_ARM)
|
||||
__force_stores();
|
||||
#endif /* defined (__CC_ARM) */
|
||||
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Indicate Sleep-On-Exit feature 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-Mx System Control Register */
|
||||
SET_BIT (SCB->SCR, 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-Mx System Control Register */
|
||||
CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPONEXIT_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable CORTEX SEVONPEND feature.
|
||||
* @note Sets SEVONPEND bit of SCR register. When this bit is set, any
|
||||
* pending event / interrupt even if it's disabled or has insufficient
|
||||
* priority to cause exception entry wakes up the Cortex-Mx.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_EnableSEVOnPend (void)
|
||||
{
|
||||
/* Set SEVONPEND bit of Cortex-Mx System Control Register */
|
||||
SET_BIT (SCB->SCR, SCB_SCR_SEVONPEND_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable CORTEX SEVONPEND feature.
|
||||
* @note Resets SEVONPEND bit of SCR register. When this bit is reset, only
|
||||
* enabled pending causes exception entry wakes up the Cortex-Mx.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_DisableSEVOnPend (void)
|
||||
{
|
||||
/* Clear SEVONPEND bit of Cortex System Control Register */
|
||||
CLEAR_BIT (SCB->SCR, SCB_SCR_SEVONPEND_Msk);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup PWR_Exported_Functions_Group3 Interrupt Handling Functions
|
||||
* @brief Interrupt Handling functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Interrupt Handling Functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to handle the PVD pending
|
||||
interrupts.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function handles the PWR PVD interrupt request.
|
||||
* @note This API should be called under the PVD_AVD_IRQHandler().
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_PWR_PVD_IRQHandler (void)
|
||||
{
|
||||
#if defined (DUAL_CORE)
|
||||
/* Check Cortex-Mx ID */
|
||||
if (HAL_GetCurrentCPUID () == CM7_CPUID)
|
||||
{
|
||||
/* Check PWR EXTI D1 flag */
|
||||
if(__HAL_PWR_PVD_EXTI_GET_FLAG () != 0U)
|
||||
{
|
||||
/* Clear PWR EXTI D1 pending bit */
|
||||
__HAL_PWR_PVD_EXTI_CLEAR_FLAG ();
|
||||
|
||||
/* PWR PVD interrupt user callback */
|
||||
HAL_PWR_PVDCallback ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check PWR EXTI D2 flag */
|
||||
if (__HAL_PWR_PVD_EXTID2_GET_FLAG () != 0U)
|
||||
{
|
||||
/* Clear PWR EXTI D2 pending bit */
|
||||
__HAL_PWR_PVD_EXTID2_CLEAR_FLAG ();
|
||||
|
||||
/* PWR PVD interrupt user callback */
|
||||
HAL_PWR_PVDCallback ();
|
||||
}
|
||||
}
|
||||
#else /* Single core devices */
|
||||
/* PVD EXTI line interrupt detected */
|
||||
if (__HAL_PWR_PVD_EXTI_GET_FLAG () != 0U)
|
||||
{
|
||||
/* Clear PWR EXTI pending bit */
|
||||
__HAL_PWR_PVD_EXTI_CLEAR_FLAG ();
|
||||
|
||||
/* PWR PVD interrupt user callback */
|
||||
HAL_PWR_PVDCallback ();
|
||||
}
|
||||
#endif /* defined (DUAL_CORE) */
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 can be implemented in the user file
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,779 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_ramecc.c
|
||||
* @author MCD Application Team
|
||||
* @brief RAMECC HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the RAM ECC monitoring (RAMECC) peripheral:
|
||||
* + Initialization and de-initialization functions
|
||||
* + Monitoring operation functions
|
||||
* + Error information functions
|
||||
* + State and error functions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) Enable and latch error information through HAL_RAMECC_Init().
|
||||
|
||||
(#) For a given Monitor, enable and disable interrupt through
|
||||
HAL_RAMECC_EnableNotification().
|
||||
To enable a notification for a given RAMECC instance, use global
|
||||
interrupts.
|
||||
To enable a notification for only RAMECC monitor, use monitor interrupts.
|
||||
All possible notifications are defined in the driver header file under
|
||||
RAMECC_Interrupt group.
|
||||
|
||||
*** Silent mode ***
|
||||
===================
|
||||
[..]
|
||||
(+) Use HAL_RAMECC_StartMonitor() to start RAMECC latch failing
|
||||
information without enabling any notification.
|
||||
|
||||
*** Interrupt mode ***
|
||||
======================
|
||||
[..]
|
||||
(+) Use HAL_RAMECC_EnableNotification() to enable interrupts for a
|
||||
given error.
|
||||
(+) Configure the RAMECC interrupt priority using
|
||||
HAL_NVIC_SetPriority().
|
||||
(+) Enable the RAMECC IRQ handler using HAL_NVIC_EnableIRQ().
|
||||
(+) Start RAMECC latch failing information using HAL_RAMECC_StartMonitor().
|
||||
|
||||
*** Failing information ***
|
||||
======================
|
||||
[..]
|
||||
(#) Use HAL_RAMECC_GetFailingAddress() function to return the RAMECC
|
||||
failing address.
|
||||
(#) Use HAL_RAMECC_GetFailingDataLow() function to return the RAMECC
|
||||
failing data low.
|
||||
(#) Use HAL_RAMECC_GetFailingDataHigh() function to return the RAMECC
|
||||
failing data high.
|
||||
(#) Use HAL_RAMECC_GetHammingErrorCode() function to return the RAMECC
|
||||
Hamming bits injected.
|
||||
(#) Use HAL_RAMECC_IsECCSingleErrorDetected() function to check if a single
|
||||
error was detected and corrected.
|
||||
(#) Use HAL_RAMECC_IsECCDoubleErrorDetected() function to check if a double
|
||||
error was dedetected.
|
||||
|
||||
*** RAMECC HAL driver macros list ***
|
||||
=============================================
|
||||
[..]
|
||||
Below the list of used macros in RAMECC HAL driver.
|
||||
|
||||
(+) __HAL_RAMECC_ENABLE_IT : Enable the specified ECCRAM Monitor
|
||||
interrupts.
|
||||
(+) __HAL_RAMECC_DISABLE_IT : Disable the specified ECCRAM Monitor
|
||||
interrupts.
|
||||
(+) __HAL_RAMECC_GET_FLAG : Return the current RAMECC Monitor selected
|
||||
flag.
|
||||
(+) __HAL_RAMECC_CLEAR_FLAG : Clear the current RAMECC Monitor selected
|
||||
flag.
|
||||
|
||||
##### Callback registration #####
|
||||
==================================
|
||||
[..]
|
||||
(#) The compilation define USE_HAL_RAMECC_REGISTER_CALLBACKS when set to 1
|
||||
allows the user to configure dynamically the driver callback.
|
||||
|
||||
[..]
|
||||
(#) Use Function HAL_RAMECC_RegisterCallback() to register a user callback.
|
||||
(#) Function HAL_RAMECC_RegisterCallback() allows to register following callback:
|
||||
(+) RAMECCErrorCode : RAMECC error code detection.
|
||||
(#) This function takes as parameters the HAL peripheral handle
|
||||
and a pointer to the user callback function.
|
||||
|
||||
[..]
|
||||
(#) Use function HAL_RAMECC_UnRegisterCallback() to reset a callback to the default
|
||||
weak function.
|
||||
(#) HAL_RAMECC_UnRegisterCallback() takes as parameters the HAL peripheral handle.
|
||||
(#) This function allows to reset following callback:
|
||||
(+) RAMECCErrorCode : RAMECC error code detection.
|
||||
[..]
|
||||
(#) When The compilation define USE_HAL_RAMECC_REGISTER_CALLBACKS is set to 0 or
|
||||
not defined, the callback registration feature is not available
|
||||
and weak callbacks are used.
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup RAMECC RAMECC
|
||||
* @brief RAMECC HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_RAMECC_MODULE_ENABLED
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup RAMECC_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup RAMECC_Exported_Functions_Group1
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to initialize the RAMECC Monitor.
|
||||
[..]
|
||||
The HAL_RAMECC_Init() function follows the RAMECC configuration procedures
|
||||
as described in reference manual.
|
||||
The HAL_RAMECC_DeInit() function allows to deinitialize the RAMECC monitor.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the RAMECC by clearing flags and disabling interrupts.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_Init(RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the RAMECC peripheral handle */
|
||||
if (hramecc == NULL)
|
||||
{
|
||||
/* Return HAL status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_BUSY;
|
||||
|
||||
/* Disable RAMECC monitor */
|
||||
hramecc->Instance->CR &= ~RAMECC_CR_ECCELEN;
|
||||
|
||||
/* Disable all global interrupts */
|
||||
((RAMECC_TypeDef *)((uint32_t)hramecc->Instance & 0xFFFFFF00U))->IER &= \
|
||||
~(RAMECC_IER_GIE | RAMECC_IER_GECCSEIE | RAMECC_IER_GECCDEIE | RAMECC_IER_GECCDEBWIE);
|
||||
|
||||
/* Disable all interrupts monitor */
|
||||
hramecc->Instance->CR &= ~(RAMECC_CR_ECCSEIE | RAMECC_CR_ECCDEIE | RAMECC_CR_ECCDEBWIE);
|
||||
|
||||
/* Clear RAMECC monitor flags */
|
||||
__HAL_RAMECC_CLEAR_FLAG (hramecc, RAMECC_FLAGS_ALL);
|
||||
|
||||
/* Initialise the RAMECC error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_NONE;
|
||||
|
||||
/* Initialise the RAMECC error detected code */
|
||||
hramecc->RAMECCErrorCode = HAL_RAMECC_NO_ERROR;
|
||||
|
||||
/* Update the RAMECC state */
|
||||
hramecc->State = HAL_RAMECC_STATE_READY;
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the RAMECC peripheral.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_DeInit(RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the RAMECC peripheral handle */
|
||||
if (hramecc == NULL)
|
||||
{
|
||||
/* Return HAL status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Disable RAMECC monitor */
|
||||
hramecc->Instance->CR &= ~RAMECC_CR_ECCELEN;
|
||||
|
||||
/* Disable all global interrupts */
|
||||
((RAMECC_TypeDef *)((uint32_t)hramecc->Instance & 0xFFFFFF00U))->IER &= \
|
||||
~(RAMECC_IER_GIE | RAMECC_IER_GECCSEIE | RAMECC_IER_GECCDEIE | RAMECC_IER_GECCDEBWIE);
|
||||
|
||||
/* Disable all interrupts monitor */
|
||||
hramecc->Instance->CR &= ~(RAMECC_CR_ECCSEIE | RAMECC_CR_ECCDEIE | RAMECC_CR_ECCDEBWIE);
|
||||
|
||||
/* Clear RAMECC monitor flags */
|
||||
__HAL_RAMECC_CLEAR_FLAG (hramecc, RAMECC_FLAGS_ALL);
|
||||
|
||||
#if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
|
||||
/* Clean callback */
|
||||
hramecc->DetectErrorCallback = NULL;
|
||||
#endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
|
||||
|
||||
/* Initialize the RAMECC error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_NONE;
|
||||
|
||||
/* Initialize the RAMECC error detected code */
|
||||
hramecc->RAMECCErrorCode = HAL_RAMECC_NO_ERROR;
|
||||
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_RESET;
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup RAMECC_Exported_Functions_Group2
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Monitoring operation functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure latching error information.
|
||||
(+) Configure RAMECC Global/Monitor interrupts.
|
||||
(+) Register and Unregister RAMECC callbacks
|
||||
(+) Handle RAMECC interrupt request
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Starts the RAMECC latching error information.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_StartMonitor(RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Check RAMECC state */
|
||||
if (hramecc->State == HAL_RAMECC_STATE_READY)
|
||||
{
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_BUSY;
|
||||
|
||||
/* Enable RAMECC monitor */
|
||||
hramecc->Instance->CR |= RAMECC_CR_ECCELEN;
|
||||
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the RAMECC latching error information.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_StopMonitor(RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Check RAMECC state */
|
||||
if (hramecc->State == HAL_RAMECC_STATE_READY)
|
||||
{
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_BUSY;
|
||||
|
||||
/* Disable RAMECC monitor */
|
||||
hramecc->Instance->CR &= ~RAMECC_CR_ECCELEN;
|
||||
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the RAMECC error interrupts.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that
|
||||
* contains the configuration information for the
|
||||
* specified RAMECC Monitor.
|
||||
* @param Notifications Select the notification.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_EnableNotification(RAMECC_HandleTypeDef *hramecc, uint32_t Notifications)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
assert_param (IS_RAMECC_INTERRUPT (Notifications));
|
||||
|
||||
/* Check RAMECC state */
|
||||
if (hramecc->State == HAL_RAMECC_STATE_READY)
|
||||
{
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_BUSY;
|
||||
|
||||
/* Enable RAMECC interrupts */
|
||||
__HAL_RAMECC_ENABLE_IT (hramecc, Notifications);
|
||||
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the RAMECC error interrupts.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that
|
||||
* contains the configuration information for the
|
||||
* specified RAMECC Monitor.
|
||||
* @param Notifications Select the notification.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_DisableNotification(RAMECC_HandleTypeDef *hramecc, uint32_t Notifications)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
assert_param (IS_RAMECC_INTERRUPT (Notifications));
|
||||
|
||||
/* Check RAMECC state */
|
||||
if (hramecc->State == HAL_RAMECC_STATE_READY)
|
||||
{
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_BUSY;
|
||||
|
||||
/* Disable RAMECC interrupts */
|
||||
__HAL_RAMECC_DISABLE_IT (hramecc, Notifications);
|
||||
|
||||
/* Change RAMECC peripheral state */
|
||||
hramecc->State = HAL_RAMECC_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_BUSY;
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup RAMECC_Exported_Functions_Group3
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Handle Interrupt and Callbacks Functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This section provides functions to handle RAMECC interrupts and
|
||||
Register / UnRegister the different callbacks.
|
||||
[..]
|
||||
The HAL_RAMECC_IRQHandler() function allows the user to handle the active RAMECC
|
||||
interrupt request.
|
||||
The HAL_RAMECC_RegisterCallback() function allows the user to register the selected
|
||||
RAMECC callbacks.
|
||||
The HAL_RAMECC_UnRegisterCallback() function allows the user to unregister the
|
||||
selected RAMECC callbacks.
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
|
||||
/**
|
||||
* @brief Register callbacks.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @param pCallback pointer to private callbacsk function which has pointer to
|
||||
* a RAMECC_HandleTypeDef structure as parameter.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_RegisterCallback (RAMECC_HandleTypeDef *hramecc, void (* pCallback)(RAMECC_HandleTypeDef *_hramecc))
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if (pCallback == NULL)
|
||||
{
|
||||
/* Update the error code */
|
||||
hramecc->ErrorCode |= HAL_RAMECC_ERROR_INVALID_CALLBACK;
|
||||
|
||||
/* Return HAL status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Check RAMECC state */
|
||||
if (hramecc->State == HAL_RAMECC_STATE_READY)
|
||||
{
|
||||
hramecc->DetectErrorCallback = pCallback;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_INVALID_CALLBACK;
|
||||
|
||||
/* Update HAL status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return HAL status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UnRegister callbacks.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RAMECC_UnRegisterCallback(RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Check RAMECC state */
|
||||
if (hramecc->State == HAL_RAMECC_STATE_READY)
|
||||
{
|
||||
hramecc->DetectErrorCallback = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the error code */
|
||||
hramecc->ErrorCode = HAL_RAMECC_ERROR_INVALID_CALLBACK;
|
||||
|
||||
/* Update HAL status */
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return HAL status */
|
||||
return status;
|
||||
}
|
||||
#endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
|
||||
|
||||
/**
|
||||
* @brief Handles RAMECC interrupt request.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval None.
|
||||
*/
|
||||
void HAL_RAMECC_IRQHandler(RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
uint32_t ier_reg = ((RAMECC_TypeDef *)((uint32_t)hramecc->Instance & 0xFFFFFF00U))->IER;
|
||||
uint32_t cr_reg = hramecc->Instance->CR >> 1U;
|
||||
uint32_t sr_reg = hramecc->Instance->SR;
|
||||
|
||||
/* Update global interrupt variables */
|
||||
if ((ier_reg & RAMECC_IER_GIE) == RAMECC_IER_GIE)
|
||||
{
|
||||
ier_reg = RAMECC_IT_GLOBAL_ALL;
|
||||
}
|
||||
|
||||
/* Store the ECC Single error detected */
|
||||
if ((sr_reg & RAMECC_SR_SEDCF) == RAMECC_SR_SEDCF)
|
||||
{
|
||||
hramecc->RAMECCErrorCode |= HAL_RAMECC_SINGLEERROR_DETECTED;
|
||||
}
|
||||
|
||||
/* Store the ECC double error detected */
|
||||
if ((sr_reg & (RAMECC_SR_DEDF | RAMECC_SR_DEBWDF)) != 0U)
|
||||
{
|
||||
hramecc->RAMECCErrorCode |= HAL_RAMECC_DOUBLEERROR_DETECTED;
|
||||
}
|
||||
|
||||
/* Clear active flags */
|
||||
__HAL_RAMECC_CLEAR_FLAG (hramecc, (((ier_reg | cr_reg) & (sr_reg << 1U)) >> 1U));
|
||||
|
||||
/* Check if a valid double error callback is registered */
|
||||
#if (USE_HAL_RAMECC_REGISTER_CALLBACKS == 1)
|
||||
/* Check if a valid error callback is registered */
|
||||
if (hramecc->DetectErrorCallback != NULL)
|
||||
{
|
||||
/* Error detection callback */
|
||||
hramecc->DetectErrorCallback(hramecc);
|
||||
}
|
||||
#else
|
||||
HAL_RAMECC_DetectErrorCallback(hramecc);
|
||||
#endif /* USE_HAL_RAMECC_REGISTER_CALLBACKS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RAMECC error detection callback.
|
||||
* @param hramecc : Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC.
|
||||
* @retval None.
|
||||
*/
|
||||
__weak void HAL_RAMECC_DetectErrorCallback(RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hramecc);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_RAMECC_DetectDoubleErrorCallback can be implemented in
|
||||
the user file. */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup RAMECC_Exported_Functions_Group4
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Error information functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Get failing address.
|
||||
(+) Get failing data low.
|
||||
(+) Get failing data high.
|
||||
(+) Get hamming bits injected.
|
||||
(+) Check single error flag.
|
||||
(+) Check double error flag.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return the RAMECC failing address.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval Failing address offset.
|
||||
*/
|
||||
uint32_t HAL_RAMECC_GetFailingAddress(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Return failing address */
|
||||
return hramecc->Instance->FAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the RAMECC data low.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval Failing data low.
|
||||
*/
|
||||
uint32_t HAL_RAMECC_GetFailingDataLow(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Return failing data low */
|
||||
return hramecc->Instance->FDRL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the RAMECC data high.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval Failing data high.
|
||||
*/
|
||||
uint32_t HAL_RAMECC_GetFailingDataHigh(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Return failing data high */
|
||||
return hramecc->Instance->FDRH;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the RAMECC Hamming bits injected.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval Hamming bits injected.
|
||||
*/
|
||||
uint32_t HAL_RAMECC_GetHammingErrorCode(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Return hamming bits injected */
|
||||
return hramecc->Instance->FECR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if an ECC single error was occurred.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval State of bit (1 or 0).
|
||||
*/
|
||||
uint32_t HAL_RAMECC_IsECCSingleErrorDetected(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Return the state of SEDC flag */
|
||||
return ((READ_BIT(hramecc->Instance->SR, RAMECC_SR_SEDCF) == (RAMECC_SR_SEDCF)) ? 1UL : 0UL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if an ECC double error was occurred.
|
||||
* @param hramecc Pointer to a RAMECC_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified RAMECC
|
||||
* Monitor.
|
||||
* @retval State of bit (1 or 0).
|
||||
*/
|
||||
uint32_t HAL_RAMECC_IsECCDoubleErrorDetected(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param (IS_RAMECC_MONITOR_ALL_INSTANCE (hramecc->Instance));
|
||||
|
||||
/* Return the state of DEDF | DEBWDF flags */
|
||||
return ((READ_BIT(hramecc->Instance->SR, (RAMECC_SR_DEDF | RAMECC_SR_DEBWDF)) != 0U) ? 1UL : 0UL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup RAMECC_Exported_Functions_Group5
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### State and Error Functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to check and get the RAMECC state
|
||||
and the error code .
|
||||
[..]
|
||||
The HAL_RAMECC_GetState() function allows to get the RAMECC peripheral
|
||||
state.
|
||||
The HAL_RAMECC_GetError() function allows to Get the RAMECC peripheral error
|
||||
code.
|
||||
The HAL_RAMECC_GetRAMECCError() function allows to Get the RAMECC error code
|
||||
detected.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the RAMECC peripheral state.
|
||||
* @param hramecc : Pointer to a RAMECC_HandleTypeDef structure that
|
||||
* contains the configuration information for the
|
||||
* specified RAMECC instance.
|
||||
* @retval RAMECC state.
|
||||
*/
|
||||
HAL_RAMECC_StateTypeDef HAL_RAMECC_GetState(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Return the RAMECC state */
|
||||
return hramecc->State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the RAMECC peripheral error code.
|
||||
* @param hramecc : Pointer to a RAMECC_HandleTypeDef structure that
|
||||
* contains the configuration information for the
|
||||
* specified RAMECC instance.
|
||||
* @retval RAMECC error code.
|
||||
*/
|
||||
uint32_t HAL_RAMECC_GetError(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Return the RAMECC error code */
|
||||
return hramecc->ErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the RAMECC error code detected.
|
||||
* @param hramecc : Pointer to a RAMECC_HandleTypeDef structure that
|
||||
* contains the configuration information for the
|
||||
* specified RAMECC instance.
|
||||
* @retval RAMECC error code detected.
|
||||
*/
|
||||
uint32_t HAL_RAMECC_GetRAMECCError(const RAMECC_HandleTypeDef *hramecc)
|
||||
{
|
||||
/* Return the RAMECC error code detected*/
|
||||
return hramecc->RAMECCErrorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* HAL_RAMECC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,358 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_rng_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended RNG HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Random Number Generator (RNG) peripheral:
|
||||
* + Lock configuration functions
|
||||
* + Reset the RNG
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(RNG)
|
||||
|
||||
/** @addtogroup RNGEx
|
||||
* @brief RNG Extended HAL module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#if defined(RNG_CR_CONDRST)
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/** @defgroup RNG_Ex_Private_Defines RNGEx Private Defines
|
||||
* @{
|
||||
*/
|
||||
/* Health test control register information to use in CCM algorithm */
|
||||
#define RNG_HTCFG_1 0x17590ABCU /*!< Magic number */
|
||||
#if defined(RNG_VER_3_1) || defined(RNG_VER_3_0)
|
||||
#define RNG_HTCFG 0x000CAA74U /*!< Recommended value for NIST compliance, refer to application note AN4230 */
|
||||
#else /* RNG_VER_3_2 */
|
||||
#define RNG_HTCFG 0x00007274U /*!< Recommended value for NIST compliance, refer to application note AN4230 */
|
||||
#endif /* RNG_VER_3_1 || RNG_VER_3_0 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup RNGEx_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
#define RNG_TIMEOUT_VALUE 2U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private functions prototypes ----------------------------------------------*/
|
||||
/* Private functions --------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup RNGEx_Exported_Functions RNGEx Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup RNGEx_Exported_Functions_Group1 Configuration and lock functions
|
||||
* @brief Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Configuration and lock functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure the RNG with the specified parameters in the RNG_ConfigTypeDef
|
||||
(+) Lock RNG configuration Allows user to lock a configuration until next reset.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure the RNG with the specified parameters in the
|
||||
* RNG_ConfigTypeDef.
|
||||
* @param hrng pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @param pConf pointer to a RNG_ConfigTypeDef structure that contains
|
||||
* the configuration information for RNG module
|
||||
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RNGEx_SetConfig(RNG_HandleTypeDef *hrng, const RNG_ConfigTypeDef *pConf)
|
||||
{
|
||||
uint32_t tickstart;
|
||||
uint32_t cr_value;
|
||||
HAL_StatusTypeDef status ;
|
||||
|
||||
/* Check the RNG handle allocation */
|
||||
if ((hrng == NULL) || (pConf == NULL))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RNG_ALL_INSTANCE(hrng->Instance));
|
||||
assert_param(IS_RNG_CLOCK_DIVIDER(pConf->ClockDivider));
|
||||
assert_param(IS_RNG_NIST_COMPLIANCE(pConf->NistCompliance));
|
||||
assert_param(IS_RNG_CONFIG1(pConf->Config1));
|
||||
assert_param(IS_RNG_CONFIG2(pConf->Config2));
|
||||
assert_param(IS_RNG_CONFIG3(pConf->Config3));
|
||||
|
||||
/* Check RNG peripheral state */
|
||||
if (hrng->State == HAL_RNG_STATE_READY)
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_BUSY;
|
||||
|
||||
/* Disable RNG */
|
||||
__HAL_RNG_DISABLE(hrng);
|
||||
|
||||
/* RNG CR register configuration. Set value in CR register for :
|
||||
- NIST Compliance setting
|
||||
- Clock divider value
|
||||
- CONFIG 1, CONFIG 2 and CONFIG 3 values */
|
||||
|
||||
cr_value = (uint32_t)(pConf->ClockDivider | pConf->NistCompliance
|
||||
| (pConf->Config1 << RNG_CR_RNG_CONFIG1_Pos)
|
||||
| (pConf->Config2 << RNG_CR_RNG_CONFIG2_Pos)
|
||||
| (pConf->Config3 << RNG_CR_RNG_CONFIG3_Pos));
|
||||
|
||||
MODIFY_REG(hrng->Instance->CR, RNG_CR_NISTC | RNG_CR_CLKDIV | RNG_CR_RNG_CONFIG1
|
||||
| RNG_CR_RNG_CONFIG2 | RNG_CR_RNG_CONFIG3,
|
||||
(uint32_t)(RNG_CR_CONDRST | cr_value));
|
||||
|
||||
#if defined(RNG_VER_3_2) || defined(RNG_VER_3_1) || defined(RNG_VER_3_0)
|
||||
/*!< magic number must be written immediately before to RNG_HTCRG */
|
||||
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG_1);
|
||||
/* Recommended value for NIST compliance, refer to application note AN4230 */
|
||||
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG);
|
||||
#endif /* RNG_VER_3_2 || RNG_VER_3_1 || RNG_VER_3_0 */
|
||||
|
||||
/* Writing bit CONDRST=0*/
|
||||
CLEAR_BIT(hrng->Instance->CR, RNG_CR_CONDRST);
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for conditioning reset process to be completed */
|
||||
while (HAL_IS_BIT_SET(hrng->Instance->CR, RNG_CR_CONDRST))
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > RNG_TIMEOUT_VALUE)
|
||||
{
|
||||
/* New check to avoid false timeout detection in case of prememption */
|
||||
if (HAL_IS_BIT_SET(hrng->Instance->CR, RNG_CR_CONDRST))
|
||||
{
|
||||
hrng->State = HAL_RNG_STATE_READY;
|
||||
hrng->ErrorCode = HAL_RNG_ERROR_TIMEOUT;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable RNG */
|
||||
__HAL_RNG_ENABLE(hrng);
|
||||
|
||||
/* Initialize the RNG state */
|
||||
hrng->State = HAL_RNG_STATE_READY;
|
||||
|
||||
/* function status */
|
||||
status = HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
hrng->ErrorCode = HAL_RNG_ERROR_BUSY;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return the function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the RNG Configuration and fill parameters in the
|
||||
* RNG_ConfigTypeDef.
|
||||
* @param hrng pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @param pConf pointer to a RNG_ConfigTypeDef structure that contains
|
||||
* the configuration information for RNG module
|
||||
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RNGEx_GetConfig(RNG_HandleTypeDef *hrng, RNG_ConfigTypeDef *pConf)
|
||||
{
|
||||
|
||||
HAL_StatusTypeDef status ;
|
||||
|
||||
/* Check the RNG handle allocation */
|
||||
if ((hrng == NULL) || (pConf == NULL))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check RNG peripheral state */
|
||||
if (hrng->State == HAL_RNG_STATE_READY)
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_BUSY;
|
||||
|
||||
/* Get RNG parameters */
|
||||
pConf->Config1 = (uint32_t)((hrng->Instance->CR & RNG_CR_RNG_CONFIG1) >> RNG_CR_RNG_CONFIG1_Pos) ;
|
||||
pConf->Config2 = (uint32_t)((hrng->Instance->CR & RNG_CR_RNG_CONFIG2) >> RNG_CR_RNG_CONFIG2_Pos);
|
||||
pConf->Config3 = (uint32_t)((hrng->Instance->CR & RNG_CR_RNG_CONFIG3) >> RNG_CR_RNG_CONFIG3_Pos);
|
||||
pConf->ClockDivider = (hrng->Instance->CR & RNG_CR_CLKDIV);
|
||||
pConf->NistCompliance = (hrng->Instance->CR & RNG_CR_NISTC);
|
||||
|
||||
/* Initialize the RNG state */
|
||||
hrng->State = HAL_RNG_STATE_READY;
|
||||
|
||||
/* function status */
|
||||
status = HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
hrng->ErrorCode |= HAL_RNG_ERROR_BUSY;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return the function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RNG current configuration lock.
|
||||
* @note This function allows to lock RNG peripheral configuration.
|
||||
* Once locked, HW RNG reset has to be performed prior any further
|
||||
* configuration update.
|
||||
* @param hrng pointer to a RNG_HandleTypeDef structure that contains
|
||||
* the configuration information for RNG.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RNGEx_LockConfig(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
/* Check the RNG handle allocation */
|
||||
if (hrng == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check RNG peripheral state */
|
||||
if (hrng->State == HAL_RNG_STATE_READY)
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_BUSY;
|
||||
|
||||
/* Perform RNG configuration Lock */
|
||||
MODIFY_REG(hrng->Instance->CR, RNG_CR_CONFIGLOCK, RNG_CR_CONFIGLOCK);
|
||||
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_READY;
|
||||
|
||||
/* function status */
|
||||
status = HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
hrng->ErrorCode = HAL_RNG_ERROR_BUSY;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return the function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup RNGEx_Exported_Functions_Group2 Recover from seed error function
|
||||
* @brief Recover from seed error function
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Recover from seed error function #####
|
||||
===============================================================================
|
||||
[..] This section provide function allowing to:
|
||||
(+) Recover from a seed error
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief RNG sequence to recover from a seed error
|
||||
* @param hrng: pointer to a RNG_HandleTypeDef structure.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RNGEx_RecoverSeedError(RNG_HandleTypeDef *hrng)
|
||||
{
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
/* Check the RNG handle allocation */
|
||||
if (hrng == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check RNG peripheral state */
|
||||
if (hrng->State == HAL_RNG_STATE_READY)
|
||||
{
|
||||
/* Change RNG peripheral state */
|
||||
hrng->State = HAL_RNG_STATE_BUSY;
|
||||
|
||||
/* sequence to fully recover from a seed error */
|
||||
status = RNG_RecoverSeedError(hrng);
|
||||
if (status == HAL_ERROR)
|
||||
{
|
||||
/* Update the error code */
|
||||
hrng->ErrorCode = HAL_RNG_ERROR_RECOVERSEED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hrng->ErrorCode = HAL_RNG_ERROR_BUSY;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Return the function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* RNG_CR_CONDRST */
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* RNG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_sai_ex.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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(const SAI_HandleTypeDef *hsai,
|
||||
const SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint32_t offset;
|
||||
SAI_TypeDef *SaiBaseAddress;
|
||||
|
||||
/* Get the SAI base address according to the SAI handle */
|
||||
#if defined(SAI4)
|
||||
SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : \
|
||||
(hsai->Instance == SAI4_Block_A) ? SAI4 : \
|
||||
NULL);
|
||||
#else
|
||||
SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : NULL);
|
||||
#endif /* SAI4 */
|
||||
|
||||
/* Check that SAI sub-block is SAI sub-block A */
|
||||
if (SaiBaseAddress == NULL)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 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));
|
||||
|
||||
/* Compute offset on PDMDLY register according mic pair number */
|
||||
offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
|
||||
|
||||
/* Check SAI state and offset */
|
||||
if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
|
||||
{
|
||||
/* Reset current delays for specified microphone */
|
||||
SaiBaseAddress->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
|
||||
|
||||
/* Apply new microphone delays */
|
||||
SaiBaseAddress->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_sd_ex.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The 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
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SDEx SDEx
|
||||
* @brief SD Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (SDMMC1) || defined (SDMMC2)
|
||||
#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 transferred data
|
||||
* @param pDataBuffer1: Pointer to the buffer1 that will contain/receive the transferred 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)(BLOCKSIZE * 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;
|
||||
uint32_t DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
if (hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
if ((add + NumberOfBlocks) > (hsd->SdCard.LogBlockNbr))
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
DmaBase0_reg = hsd->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hsd->Instance->IDMABASE1;
|
||||
|
||||
if ((hsd->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
/* Clear old Flags*/
|
||||
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
|
||||
|
||||
hsd->ErrorCode = HAL_SD_ERROR_NONE;
|
||||
hsd->State = HAL_SD_STATE_BUSY;
|
||||
|
||||
if (hsd->SdCard.CardType != CARD_SDHC_SDXC)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
(void)SDMMC_ConfigData(hsd->Instance, &config);
|
||||
|
||||
hsd->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hsd->Instance);
|
||||
|
||||
hsd->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Read Blocks in DMA mode */
|
||||
hsd->Context = (SD_CONTEXT_READ_MULTIPLE_BLOCK | SD_CONTEXT_DMA);
|
||||
|
||||
/* Read Multi Block command */
|
||||
errorstate = SDMMC_CmdReadMultiBlock(hsd->Instance, add);
|
||||
if (errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
hsd->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_SD_ENABLE_IT(hsd, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_IT_IDMABTC));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write block(s) to a specified address in a card. The transferred 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;
|
||||
uint32_t DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
if (hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
if ((add + NumberOfBlocks) > (hsd->SdCard.LogBlockNbr))
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
DmaBase0_reg = hsd->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hsd->Instance->IDMABASE1;
|
||||
if ((hsd->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
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)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
(void)SDMMC_ConfigData(hsd->Instance, &config);
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hsd->Instance);
|
||||
|
||||
hsd->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Write Blocks in DMA mode */
|
||||
hsd->Context = (SD_CONTEXT_WRITE_MULTIPLE_BLOCK | SD_CONTEXT_DMA);
|
||||
|
||||
/* Write Multi Block command */
|
||||
errorstate = SDMMC_CmdWriteMultiBlock(hsd->Instance, add);
|
||||
if (errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
hsd->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_SD_ENABLE_IT(hsd, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_IT_IDMABTC));
|
||||
|
||||
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 */
|
||||
#endif /* SDMMC1 || SDMMC2 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,495 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_smartcard_ex.c
|
||||
* @author MCD Application Team
|
||||
* @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
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
=============================================================================
|
||||
##### 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.
|
||||
|
||||
(#) FIFO mode enabling/disabling and RX/TX FIFO threshold programming.
|
||||
|
||||
-@- When SMARTCARD operates in FIFO mode, FIFO mode must be enabled prior
|
||||
starting RX/TX transfers. Also RX/TX FIFO thresholds must be
|
||||
configured prior starting RX/TX transfers.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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 ------------------------------------------------------------*/
|
||||
/** @defgroup SMARTCARDEx_Private_Constants SMARTCARD Extended Private Constants
|
||||
* @{
|
||||
*/
|
||||
/* UART RX FIFO depth */
|
||||
#define RX_FIFO_DEPTH 16U
|
||||
|
||||
/* UART TX FIFO depth */
|
||||
#define TX_FIFO_DEPTH 16U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void SMARTCARDEx_SetNbDataToProcess(SMARTCARD_HandleTypeDef *hsmartcard);
|
||||
|
||||
/* 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 << USART_RTOR_BLEN_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 0x0FFFFFFFF.
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SMARTCARDEx_Exported_Functions_Group2 Extended Peripheral IO operation functions
|
||||
* @brief SMARTCARD Transmit and Receive functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of FIFO mode related callback functions.
|
||||
|
||||
(#) TX/RX Fifos Callbacks:
|
||||
(++) HAL_SMARTCARDEx_RxFifoFullCallback()
|
||||
(++) HAL_SMARTCARDEx_TxFifoEmptyCallback()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SMARTCARD RX Fifo full callback.
|
||||
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMARTCARD module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SMARTCARDEx_RxFifoFullCallback(SMARTCARD_HandleTypeDef *hsmartcard)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hsmartcard);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_SMARTCARDEx_RxFifoFullCallback can be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SMARTCARD TX Fifo empty callback.
|
||||
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMARTCARD module.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SMARTCARDEx_TxFifoEmptyCallback(SMARTCARD_HandleTypeDef *hsmartcard)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hsmartcard);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_SMARTCARDEx_TxFifoEmptyCallback can be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SMARTCARDEx_Exported_Functions_Group3 Extended Peripheral FIFO Control functions
|
||||
* @brief SMARTCARD control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral FIFO Control functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
This subsection provides a set of functions allowing to control the SMARTCARD
|
||||
FIFO feature.
|
||||
(+) HAL_SMARTCARDEx_EnableFifoMode() API enables the FIFO mode
|
||||
(+) HAL_SMARTCARDEx_DisableFifoMode() API disables the FIFO mode
|
||||
(+) HAL_SMARTCARDEx_SetTxFifoThreshold() API sets the TX FIFO threshold
|
||||
(+) HAL_SMARTCARDEx_SetRxFifoThreshold() API sets the RX FIFO threshold
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable the FIFO mode.
|
||||
* @param hsmartcard SMARTCARD handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMARTCARDEx_EnableFifoMode(SMARTCARD_HandleTypeDef *hsmartcard)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmartcard);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
||||
|
||||
/* Save actual SMARTCARD configuration */
|
||||
tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
|
||||
|
||||
/* Disable SMARTCARD */
|
||||
__HAL_SMARTCARD_DISABLE(hsmartcard);
|
||||
|
||||
/* Enable FIFO mode */
|
||||
SET_BIT(tmpcr1, USART_CR1_FIFOEN);
|
||||
hsmartcard->FifoMode = SMARTCARD_FIFOMODE_ENABLE;
|
||||
|
||||
/* Restore SMARTCARD configuration */
|
||||
WRITE_REG(hsmartcard->Instance->CR1, tmpcr1);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
SMARTCARDEx_SetNbDataToProcess(hsmartcard);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmartcard);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the FIFO mode.
|
||||
* @param hsmartcard SMARTCARD handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMARTCARDEx_DisableFifoMode(SMARTCARD_HandleTypeDef *hsmartcard)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmartcard);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
||||
|
||||
/* Save actual SMARTCARD configuration */
|
||||
tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
|
||||
|
||||
/* Disable SMARTCARD */
|
||||
__HAL_SMARTCARD_DISABLE(hsmartcard);
|
||||
|
||||
/* Enable FIFO mode */
|
||||
CLEAR_BIT(tmpcr1, USART_CR1_FIFOEN);
|
||||
hsmartcard->FifoMode = SMARTCARD_FIFOMODE_DISABLE;
|
||||
|
||||
/* Restore SMARTCARD configuration */
|
||||
WRITE_REG(hsmartcard->Instance->CR1, tmpcr1);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmartcard);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the TXFIFO threshold.
|
||||
* @param hsmartcard SMARTCARD handle.
|
||||
* @param Threshold TX FIFO threshold value
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref SMARTCARD_TXFIFO_THRESHOLD_1_8
|
||||
* @arg @ref SMARTCARD_TXFIFO_THRESHOLD_1_4
|
||||
* @arg @ref SMARTCARD_TXFIFO_THRESHOLD_1_2
|
||||
* @arg @ref SMARTCARD_TXFIFO_THRESHOLD_3_4
|
||||
* @arg @ref SMARTCARD_TXFIFO_THRESHOLD_7_8
|
||||
* @arg @ref SMARTCARD_TXFIFO_THRESHOLD_8_8
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMARTCARDEx_SetTxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
|
||||
assert_param(IS_SMARTCARD_TXFIFO_THRESHOLD(Threshold));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmartcard);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
||||
|
||||
/* Save actual SMARTCARD configuration */
|
||||
tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
|
||||
|
||||
/* Disable SMARTCARD */
|
||||
__HAL_SMARTCARD_DISABLE(hsmartcard);
|
||||
|
||||
/* Update TX threshold configuration */
|
||||
MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_TXFTCFG, Threshold);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
SMARTCARDEx_SetNbDataToProcess(hsmartcard);
|
||||
|
||||
/* Restore SMARTCARD configuration */
|
||||
MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_UE, tmpcr1);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmartcard);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the RXFIFO threshold.
|
||||
* @param hsmartcard SMARTCARD handle.
|
||||
* @param Threshold RX FIFO threshold value
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref SMARTCARD_RXFIFO_THRESHOLD_1_8
|
||||
* @arg @ref SMARTCARD_RXFIFO_THRESHOLD_1_4
|
||||
* @arg @ref SMARTCARD_RXFIFO_THRESHOLD_1_2
|
||||
* @arg @ref SMARTCARD_RXFIFO_THRESHOLD_3_4
|
||||
* @arg @ref SMARTCARD_RXFIFO_THRESHOLD_7_8
|
||||
* @arg @ref SMARTCARD_RXFIFO_THRESHOLD_8_8
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMARTCARDEx_SetRxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(hsmartcard->Instance));
|
||||
assert_param(IS_SMARTCARD_RXFIFO_THRESHOLD(Threshold));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmartcard);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
||||
|
||||
/* Save actual SMARTCARD configuration */
|
||||
tmpcr1 = READ_REG(hsmartcard->Instance->CR1);
|
||||
|
||||
/* Disable SMARTCARD */
|
||||
__HAL_SMARTCARD_DISABLE(hsmartcard);
|
||||
|
||||
/* Update RX threshold configuration */
|
||||
MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_RXFTCFG, Threshold);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
SMARTCARDEx_SetNbDataToProcess(hsmartcard);
|
||||
|
||||
/* Restore SMARTCARD configuration */
|
||||
MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_UE, tmpcr1);
|
||||
|
||||
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmartcard);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SMARTCARDEx_Private_Functions SMARTCARD Extended Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Calculate the number of data to process in RX/TX ISR.
|
||||
* @note The RX FIFO depth and the TX FIFO depth is extracted from
|
||||
* the USART configuration registers.
|
||||
* @param hsmartcard SMARTCARD handle.
|
||||
* @retval None
|
||||
*/
|
||||
static void SMARTCARDEx_SetNbDataToProcess(SMARTCARD_HandleTypeDef *hsmartcard)
|
||||
{
|
||||
uint8_t rx_fifo_depth;
|
||||
uint8_t tx_fifo_depth;
|
||||
uint8_t rx_fifo_threshold;
|
||||
uint8_t tx_fifo_threshold;
|
||||
/* 2 0U/1U added for MISRAC2012-Rule-18.1_b and MISRAC2012-Rule-18.1_d */
|
||||
static const uint8_t numerator[] = {1U, 1U, 1U, 3U, 7U, 1U, 0U, 0U};
|
||||
static const uint8_t denominator[] = {8U, 4U, 2U, 4U, 8U, 1U, 1U, 1U};
|
||||
|
||||
if (hsmartcard->FifoMode == SMARTCARD_FIFOMODE_DISABLE)
|
||||
{
|
||||
hsmartcard->NbTxDataToProcess = 1U;
|
||||
hsmartcard->NbRxDataToProcess = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx_fifo_depth = RX_FIFO_DEPTH;
|
||||
tx_fifo_depth = TX_FIFO_DEPTH;
|
||||
rx_fifo_threshold = (uint8_t)(READ_BIT(hsmartcard->Instance->CR3, USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos);
|
||||
tx_fifo_threshold = (uint8_t)(READ_BIT(hsmartcard->Instance->CR3, USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos);
|
||||
hsmartcard->NbTxDataToProcess = ((uint16_t)tx_fifo_depth * numerator[tx_fifo_threshold]) / \
|
||||
(uint16_t)denominator[tx_fifo_threshold];
|
||||
hsmartcard->NbRxDataToProcess = ((uint16_t)rx_fifo_depth * numerator[rx_fifo_threshold]) / \
|
||||
(uint16_t)denominator[rx_fifo_threshold];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,260 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_smbus_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief SMBUS Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of SMBUS Extended peripheral:
|
||||
* + Extended features functions
|
||||
* + WakeUp Mode Functions
|
||||
* + FastModePlus Functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### SMBUS peripheral Extended features #####
|
||||
==============================================================================
|
||||
|
||||
[..] Comparing to other previous devices, the SMBUS interface for STM32H7xx
|
||||
devices contains the following additional features
|
||||
|
||||
(+) Disable or enable wakeup from Stop mode(s)
|
||||
(+) Disable or enable Fast Mode Plus
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
(#) Configure the enable or disable of SMBUS Wake Up Mode using the functions :
|
||||
(++) HAL_SMBUSEx_EnableWakeUp()
|
||||
(++) HAL_SMBUSEx_DisableWakeUp()
|
||||
(#) Configure the enable or disable of fast mode plus driving capability using the functions :
|
||||
(++) HAL_SMBUSEx_EnableFastModePlus()
|
||||
(++) HAL_SMBUSEx_DisableFastModePlus()
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SMBUSEx SMBUSEx
|
||||
* @brief SMBUS Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_SMBUS_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup SMBUSEx_Exported_Functions SMBUS Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SMBUSEx_Exported_Functions_Group2 WakeUp Mode Functions
|
||||
* @brief WakeUp Mode Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### WakeUp Mode Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Wake Up Feature
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable SMBUS wakeup from Stop mode(s).
|
||||
* @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMBUSx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMBUSEx_EnableWakeUp(SMBUS_HandleTypeDef *hsmbus)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance));
|
||||
|
||||
if (hsmbus->State == HAL_SMBUS_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmbus);
|
||||
|
||||
hsmbus->State = HAL_SMBUS_STATE_BUSY;
|
||||
|
||||
/* Disable the selected SMBUS peripheral */
|
||||
__HAL_SMBUS_DISABLE(hsmbus);
|
||||
|
||||
/* Enable wakeup from stop mode */
|
||||
hsmbus->Instance->CR1 |= I2C_CR1_WUPEN;
|
||||
|
||||
__HAL_SMBUS_ENABLE(hsmbus);
|
||||
|
||||
hsmbus->State = HAL_SMBUS_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmbus);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable SMBUS wakeup from Stop mode(s).
|
||||
* @param hsmbus Pointer to a SMBUS_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SMBUSx peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SMBUSEx_DisableWakeUp(SMBUS_HandleTypeDef *hsmbus)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hsmbus->Instance));
|
||||
|
||||
if (hsmbus->State == HAL_SMBUS_STATE_READY)
|
||||
{
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hsmbus);
|
||||
|
||||
hsmbus->State = HAL_SMBUS_STATE_BUSY;
|
||||
|
||||
/* Disable the selected SMBUS peripheral */
|
||||
__HAL_SMBUS_DISABLE(hsmbus);
|
||||
|
||||
/* Disable wakeup from stop mode */
|
||||
hsmbus->Instance->CR1 &= ~(I2C_CR1_WUPEN);
|
||||
|
||||
__HAL_SMBUS_ENABLE(hsmbus);
|
||||
|
||||
hsmbus->State = HAL_SMBUS_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hsmbus);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup SMBUSEx_Exported_Functions_Group3 Fast Mode Plus Functions
|
||||
* @brief Fast Mode Plus Functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Fast Mode Plus Functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
(+) Configure Fast Mode Plus
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable the SMBUS fast mode plus driving capability.
|
||||
* @param ConfigFastModePlus Selects the pin.
|
||||
* This parameter can be one of the @ref SMBUSEx_FastModePlus values
|
||||
* @note For I2C1, fast mode plus driving capability can be enabled on all selected
|
||||
* I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently
|
||||
* on each one of the following pins PB6, PB7, PB8 and PB9.
|
||||
* @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
|
||||
* can be enabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter.
|
||||
* @note For all I2C2 pins fast mode plus driving capability can be enabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C2 parameter.
|
||||
* @note For all I2C3 pins fast mode plus driving capability can be enabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C3 parameter.
|
||||
* @note For all I2C4 pins fast mode plus driving capability can be enabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C4 parameter.
|
||||
* @note For all I2C5 pins fast mode plus driving capability can be enabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C5 parameter.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SMBUSEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_SMBUS_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 SMBUS fast mode plus driving capability.
|
||||
* @param ConfigFastModePlus Selects the pin.
|
||||
* This parameter can be one of the @ref SMBUSEx_FastModePlus values
|
||||
* @note For I2C1, fast mode plus driving capability can be disabled on all selected
|
||||
* I2C1 pins using SMBUS_FASTMODEPLUS_I2C1 parameter or independently
|
||||
* on each one of the following pins PB6, PB7, PB8 and PB9.
|
||||
* @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
|
||||
* can be disabled only by using SMBUS_FASTMODEPLUS_I2C1 parameter.
|
||||
* @note For all I2C2 pins fast mode plus driving capability can be disabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C2 parameter.
|
||||
* @note For all I2C3 pins fast mode plus driving capability can be disabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C3 parameter.
|
||||
* @note For all I2C4 pins fast mode plus driving capability can be disabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C4 parameter.
|
||||
* @note For all I2C5 pins fast mode plus driving capability can be disabled
|
||||
* only by using SMBUS_FASTMODEPLUS_I2C5 parameter.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SMBUSEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
|
||||
{
|
||||
/* Check the parameter */
|
||||
assert_param(IS_SMBUS_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_SMBUS_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,226 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_spi_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended SPI HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* SPI peripheral extended functionalities :
|
||||
* + IO operation functions
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "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_EnableLockConfiguration()
|
||||
(++) HAL_SPIEx_ConfigureUnderrun()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Flush the RX fifo.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for the specified SPI module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(const SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint32_t itflag = hspi->Instance->SR;
|
||||
__IO uint32_t tmpreg;
|
||||
|
||||
while (((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_RX_FIFO_0PACKET) || ((itflag & SPI_FLAG_RXWNE) != 0UL))
|
||||
{
|
||||
count += (uint8_t)4UL;
|
||||
tmpreg = hspi->Instance->RXDR;
|
||||
UNUSED(tmpreg); /* To avoid GCC warning */
|
||||
|
||||
if (IS_SPI_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 Configuration register 2
|
||||
* when SPI is enabled
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SPIEx_EnableLockConfiguration(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
HAL_StatusTypeDef errorcode = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(hspi);
|
||||
|
||||
if (hspi->State != HAL_SPI_STATE_READY)
|
||||
{
|
||||
errorcode = HAL_BUSY;
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/* Check if the SPI is disabled to edit IOLOCK bit */
|
||||
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
||||
{
|
||||
SET_BIT(hspi->Instance->CR1, SPI_CR1_IOLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable SPI peripheral */
|
||||
__HAL_SPI_DISABLE(hspi);
|
||||
|
||||
SET_BIT(hspi->Instance->CR1, SPI_CR1_IOLOCK);
|
||||
|
||||
/* Enable SPI peripheral */
|
||||
__HAL_SPI_ENABLE(hspi);
|
||||
}
|
||||
|
||||
hspi->State = HAL_SPI_STATE_READY;
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hspi);
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the UNDERRUN condition and behavior of slave transmitter.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @param UnderrunDetection : Detection of underrun condition at slave transmitter
|
||||
* This parameter 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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+346
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_timebase_rtc_alarm_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief HAL time base based on the hardware RTC_ALARM Template.
|
||||
*
|
||||
* This file override the native HAL time base functions (defined as weak)
|
||||
* to use the RTC ALARM for time base generation:
|
||||
* + Initializes the RTC peripheral to increment the seconds registers each 1ms
|
||||
* + The alarm is configured to assert an interrupt when the RTC reaches 1ms
|
||||
* + HAL_IncTick is called at each Alarm event and the time is reset to 00:00:00
|
||||
* + HSE (default), LSE or LSI can be selected as RTC clock source
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This file must be copied to the application folder and modified as follows:
|
||||
(#) Rename it to 'stm32h7xx_hal_timebase_rtc_alarm.c'
|
||||
(#) Add this file and the RTC HAL drivers to your project and uncomment
|
||||
HAL_RTC_MODULE_ENABLED define in stm32h7xx_hal_conf.h
|
||||
|
||||
[..]
|
||||
(@) HAL RTC alarm and HAL RTC wakeup drivers can not be used with low power modes:
|
||||
The wake up capability of the RTC may be intrusive in case of prior low power mode
|
||||
configuration requiring different wake up sources.
|
||||
Application/Example behavior is no more guaranteed
|
||||
(@) The stm32h7xx_hal_timebase_tim use is recommended for the Applications/Examples
|
||||
requiring low power modes
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_TimeBase_RTC_Alarm_Template HAL TimeBase RTC Alarm Template
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Uncomment the line below to select the appropriate RTC Clock source for your application:
|
||||
+ RTC_CLOCK_SOURCE_HSE: can be selected for applications requiring timing precision.
|
||||
+ RTC_CLOCK_SOURCE_LSE: can be selected for applications with low constraint on timing
|
||||
precision.
|
||||
+ RTC_CLOCK_SOURCE_LSI: can be selected for applications with low constraint on timing
|
||||
precision.
|
||||
*/
|
||||
#define RTC_CLOCK_SOURCE_HSE
|
||||
/* #define RTC_CLOCK_SOURCE_LSE */
|
||||
/* #define RTC_CLOCK_SOURCE_LSI */
|
||||
|
||||
#ifdef RTC_CLOCK_SOURCE_HSE
|
||||
#define RTC_ASYNCH_PREDIV 99U
|
||||
#define RTC_SYNCH_PREDIV 9U
|
||||
#define RCC_RTCCLKSOURCE_1MHZ ((uint32_t)((uint32_t)RCC_BDCR_RTCSEL | (uint32_t)((HSE_VALUE/1000000U) << 12U)))
|
||||
#else /* RTC_CLOCK_SOURCE_LSE || RTC_CLOCK_SOURCE_LSI */
|
||||
#define RTC_ASYNCH_PREDIV 0U
|
||||
#define RTC_SYNCH_PREDIV 31U
|
||||
#endif /* RTC_CLOCK_SOURCE_HSE */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static RTC_HandleTypeDef hRTC_Handle;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void RTC_Alarm_IRQHandler(void);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the RTC_ALARMA as a time base source.
|
||||
* 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 configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
__IO uint32_t counter = 0U;
|
||||
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
#ifdef RTC_CLOCK_SOURCE_LSE
|
||||
/* Configure LSE as RTC clock source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
#elif defined (RTC_CLOCK_SOURCE_LSI)
|
||||
/* Configure LSI as RTC clock source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
|
||||
#elif defined (RTC_CLOCK_SOURCE_HSE)
|
||||
/* Configure HSE as RTC clock source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
/* Ensure that RTC is clocked by 1MHz */
|
||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_1MHZ;
|
||||
#else
|
||||
#error Please select the RTC Clock source
|
||||
#endif /* RTC_CLOCK_SOURCE_LSE */
|
||||
|
||||
status = HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
status = HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable RTC Clock */
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
/* The time base should be 1ms
|
||||
Time base = ((RTC_ASYNCH_PREDIV + 1) * (RTC_SYNCH_PREDIV + 1)) / RTC_CLOCK
|
||||
HSE as RTC clock
|
||||
Time base = ((99 + 1) * (9 + 1)) / 1MHz
|
||||
= 1ms
|
||||
LSE as RTC clock
|
||||
Time base = ((31 + 1) * (0 + 1)) / 32.768KHz
|
||||
= ~1ms
|
||||
LSI as RTC clock
|
||||
Time base = ((31 + 1) * (0 + 1)) / 32KHz
|
||||
= 1ms
|
||||
*/
|
||||
hRTC_Handle.Instance = RTC;
|
||||
hRTC_Handle.Init.HourFormat = RTC_HOURFORMAT_24;
|
||||
hRTC_Handle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
|
||||
hRTC_Handle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
|
||||
hRTC_Handle.Init.OutPut = RTC_OUTPUT_DISABLE;
|
||||
hRTC_Handle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
||||
hRTC_Handle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
||||
status = HAL_RTC_Init(&hRTC_Handle);
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Disable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
||||
|
||||
/* Disable the Alarm A interrupt */
|
||||
__HAL_RTC_ALARMA_DISABLE(&hRTC_Handle);
|
||||
|
||||
/* Clear flag alarm A */
|
||||
__HAL_RTC_ALARM_CLEAR_FLAG(&hRTC_Handle, RTC_FLAG_ALRAF);
|
||||
|
||||
counter = 0U;
|
||||
/* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
|
||||
#if defined(RTC_ICSR_ALRAWF)
|
||||
while ( READ_BIT(hRTC_Handle.Instance->ICSR, RTC_FLAG_ALRAWF) == (uint32_t)RESET)
|
||||
#else
|
||||
while (__HAL_RTC_ALARM_GET_FLAG(&hRTC_Handle, RTC_FLAG_ALRAWF) == (uint32_t)RESET)
|
||||
#endif /* RTC_ICSR_ALRAWF */
|
||||
{
|
||||
if (counter++ == (SystemCoreClock / 48U)) /* Timeout = ~ 1s */
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
hRTC_Handle.Instance->ALRMAR = (uint32_t)0x01U;
|
||||
|
||||
/* Configure the Alarm state: Enable Alarm */
|
||||
__HAL_RTC_ALARMA_ENABLE(&hRTC_Handle);
|
||||
/* Configure the Alarm interrupt */
|
||||
__HAL_RTC_ALARM_ENABLE_IT(&hRTC_Handle, RTC_IT_ALRA);
|
||||
|
||||
/* RTC Alarm Interrupt Configuration: EXTI configuration */
|
||||
__HAL_RTC_ALARM_EXTI_ENABLE_IT();
|
||||
__HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();
|
||||
|
||||
/* Check if the Initialization mode is set */
|
||||
#if defined(RTC_ISR_INITF)
|
||||
if ((hRTC_Handle.Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
|
||||
#else
|
||||
if ((hRTC_Handle.Instance->ICSR & RTC_ICSR_INITF) == (uint32_t)RESET)
|
||||
#endif /* RTC_ISR_INITF */
|
||||
{
|
||||
/* Set the Initialization mode */
|
||||
#if defined(RTC_ISR_INITF)
|
||||
hRTC_Handle.Instance->ISR = (uint32_t)RTC_INIT_MASK;
|
||||
#else
|
||||
hRTC_Handle.Instance->ICSR = (uint32_t)RTC_INIT_MASK;
|
||||
#endif /* RTC_ISR_INITF */
|
||||
counter = 0U;
|
||||
#if defined(RTC_ISR_INITF)
|
||||
while ((hRTC_Handle.Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
|
||||
#else
|
||||
while ((hRTC_Handle.Instance->ICSR & RTC_ICSR_INITF) == (uint32_t)RESET)
|
||||
#endif /* RTC_ISR_INITF */
|
||||
{
|
||||
if (counter++ == (SystemCoreClock / 48U)) /* Timeout = ~ 1s */
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
hRTC_Handle.Instance->DR = 0U;
|
||||
hRTC_Handle.Instance->TR = 0U;
|
||||
|
||||
#if defined(RTC_ISR_INIT)
|
||||
hRTC_Handle.Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
|
||||
#else
|
||||
hRTC_Handle.Instance->ICSR &= (uint32_t)~RTC_ICSR_INIT;
|
||||
#endif /* RTC_ISR_INIT */
|
||||
|
||||
/* Enable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
||||
|
||||
/* Enable the RTC Alarm Interrupt */
|
||||
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
|
||||
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling RTC ALARM interrupt.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
||||
/* Disable RTC ALARM update Interrupt */
|
||||
__HAL_RTC_ALARM_DISABLE_IT(&hRTC_Handle, RTC_IT_ALRA);
|
||||
/* Enable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling RTC ALARM interrupt.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Disable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
||||
/* Enable RTC ALARM Update interrupt */
|
||||
__HAL_RTC_ALARM_ENABLE_IT(&hRTC_Handle, RTC_IT_ALRA);
|
||||
/* Enable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ALARM A Event Callback in non blocking mode
|
||||
* @note This function is called when RTC_ALARM interrupt took place, inside
|
||||
* RTC_ALARM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param hrtc RTC handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
|
||||
{
|
||||
__IO uint32_t counter = 0U;
|
||||
|
||||
HAL_IncTick();
|
||||
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
||||
|
||||
/* Set the Initialization mode */
|
||||
#if defined(RTC_ISR_INIT)
|
||||
hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
|
||||
|
||||
while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
|
||||
#else
|
||||
hrtc->Instance->ICSR = (uint32_t)RTC_INIT_MASK;
|
||||
|
||||
while((hrtc->Instance->ICSR & RTC_ICSR_INITF) == (uint32_t)RESET)
|
||||
#endif /* RTC_ISR_INIT */
|
||||
{
|
||||
if(counter++ == (SystemCoreClock /48U)) /* Timeout = ~ 1s */
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hrtc->Instance->DR = 0U;
|
||||
hrtc->Instance->TR = 0U;
|
||||
#if defined(RTC_ISR_INIT)
|
||||
hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
|
||||
#else
|
||||
hrtc->Instance->ICSR &= (uint32_t)~RTC_ICSR_INIT;
|
||||
#endif /* RTC_ISR_INIT */
|
||||
/* Enable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles RTC ALARM interrupt request.
|
||||
* @retval None
|
||||
*/
|
||||
void RTC_Alarm_IRQHandler(void)
|
||||
{
|
||||
HAL_RTC_AlarmIRQHandler(&hRTC_Handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_timebase_rtc_wakeup_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief HAL time base based on the hardware RTC_WAKEUP Template.
|
||||
*
|
||||
* This file overrides the native HAL time base functions (defined as weak)
|
||||
* to use the RTC WAKEUP for the time base generation:
|
||||
* + Initializes the RTC peripheral and configures the wakeup timer to be
|
||||
* incremented each 1ms
|
||||
* + The wakeup feature is configured to assert an interrupt each 1ms
|
||||
* + HAL_IncTick is called inside the HAL_RTCEx_WakeUpTimerEventCallback
|
||||
* + HSE (default), LSE or LSI can be selected as RTC clock source
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This file must be copied to the application folder and modified as follows:
|
||||
(#) Rename it to 'stm32h7xx_hal_timebase_rtc_wakeup.c'
|
||||
(#) Add this file and the RTC HAL drivers to your project and uncomment
|
||||
HAL_RTC_MODULE_ENABLED define in stm32h7xx_hal_conf.h
|
||||
|
||||
[..]
|
||||
(@) HAL RTC alarm and HAL RTC wakeup drivers can not be used with low power modes:
|
||||
The wake up capability of the RTC may be intrusive in case of prior low power mode
|
||||
configuration requiring different wake up sources.
|
||||
Application/Example behavior is no more guaranteed
|
||||
(@) The stm32h7xx_hal_timebase_tim use is recommended for the Applications/Examples
|
||||
requiring low power modes
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_TimeBase_RTC_WakeUp_Template HAL TimeBase RTC WakeUp Template
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Uncomment the line below to select the appropriate RTC Clock source for your application:
|
||||
+ RTC_CLOCK_SOURCE_HSE: can be selected for applications requiring timing precision.
|
||||
+ RTC_CLOCK_SOURCE_LSE: can be selected for applications with low constraint on timing
|
||||
precision.
|
||||
+ RTC_CLOCK_SOURCE_LSI: can be selected for applications with low constraint on timing
|
||||
precision.
|
||||
*/
|
||||
#define RTC_CLOCK_SOURCE_HSE
|
||||
/* #define RTC_CLOCK_SOURCE_LSE */
|
||||
/* #define RTC_CLOCK_SOURCE_LSI */
|
||||
|
||||
#ifdef RTC_CLOCK_SOURCE_HSE
|
||||
#define RTC_ASYNCH_PREDIV 99U
|
||||
#define RTC_SYNCH_PREDIV 9U
|
||||
#define RCC_RTCCLKSOURCE_1MHZ ((uint32_t)((uint32_t)RCC_BDCR_RTCSEL | (uint32_t)((HSE_VALUE/1000000U) << 12U)))
|
||||
#else /* RTC_CLOCK_SOURCE_LSE || RTC_CLOCK_SOURCE_LSI */
|
||||
#define RTC_ASYNCH_PREDIV 0U
|
||||
#define RTC_SYNCH_PREDIV 31U
|
||||
#endif /* RTC_CLOCK_SOURCE_HSE */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static RTC_HandleTypeDef hRTC_Handle;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void RTC_WKUP_IRQHandler(void);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the RTC_WKUP as a time base source.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* Wakeup Time base = ((RTC_ASYNCH_PREDIV + 1) * (RTC_SYNCH_PREDIV + 1)) / RTC_CLOCK
|
||||
= 1ms
|
||||
* Wakeup Time = WakeupTimebase * WakeUpCounter (0 + 1)
|
||||
= 1 ms
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
|
||||
{
|
||||
__IO uint32_t counter = 0U;
|
||||
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
#ifdef RTC_CLOCK_SOURCE_LSE
|
||||
/* Configure LSE as RTC clock source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
#elif defined (RTC_CLOCK_SOURCE_LSI)
|
||||
/* Configure LSI as RTC clock source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
|
||||
#elif defined (RTC_CLOCK_SOURCE_HSE)
|
||||
/* Configure HSE as RTC clock source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
/* Ensure that RTC is clocked by 1MHz */
|
||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_1MHZ;
|
||||
#else
|
||||
#error Please select the RTC Clock source
|
||||
#endif /* RTC_CLOCK_SOURCE_LSE */
|
||||
|
||||
status = HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
status = HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable RTC Clock */
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
/* The time base should be 1ms
|
||||
Time base = ((RTC_ASYNCH_PREDIV + 1) * (RTC_SYNCH_PREDIV + 1)) / RTC_CLOCK
|
||||
HSE as RTC clock
|
||||
Time base = ((99 + 1) * (9 + 1)) / 1Mhz
|
||||
= 1ms
|
||||
LSE as RTC clock
|
||||
Time base = ((31 + 1) * (0 + 1)) / 32.768Khz
|
||||
= ~1ms
|
||||
LSI as RTC clock
|
||||
Time base = ((31 + 1) * (0 + 1)) / 32Khz
|
||||
= 1ms
|
||||
*/
|
||||
hRTC_Handle.Instance = RTC;
|
||||
hRTC_Handle.Init.HourFormat = RTC_HOURFORMAT_24;
|
||||
hRTC_Handle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
|
||||
hRTC_Handle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
|
||||
hRTC_Handle.Init.OutPut = RTC_OUTPUT_DISABLE;
|
||||
hRTC_Handle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
||||
hRTC_Handle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
||||
status = HAL_RTC_Init(&hRTC_Handle);
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Disable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
||||
|
||||
/* Disable the Wake-up Timer */
|
||||
__HAL_RTC_WAKEUPTIMER_DISABLE(&hRTC_Handle);
|
||||
|
||||
/* In case of interrupt mode is used, the interrupt source must disabled */
|
||||
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&hRTC_Handle, RTC_IT_WUT);
|
||||
|
||||
/* Wait till RTC WUTWF flag is set */
|
||||
#if defined(RTC_ICSR_WUTWF)
|
||||
while (READ_BIT(hRTC_Handle.Instance->ICSR, RTC_FLAG_WUTWF) == (uint32_t)RESET)
|
||||
#else
|
||||
while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(&hRTC_Handle, RTC_FLAG_WUTWF) == (uint32_t)RESET)
|
||||
#endif /* RTC_ICSR_WUTWF */
|
||||
{
|
||||
if (counter++ == (SystemCoreClock / 48U))
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Clear PWR wake up Flag */
|
||||
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
|
||||
|
||||
/* Clear RTC Wake Up timer Flag */
|
||||
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hRTC_Handle, RTC_FLAG_WUTF);
|
||||
|
||||
/* Configure the Wake-up Timer counter */
|
||||
hRTC_Handle.Instance->WUTR = (uint32_t)0U;
|
||||
|
||||
/* Clear the Wake-up Timer clock source bits in CR register */
|
||||
hRTC_Handle.Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
|
||||
|
||||
/* Configure the clock source */
|
||||
hRTC_Handle.Instance->CR |= (uint32_t)RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
|
||||
|
||||
/* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
|
||||
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
|
||||
|
||||
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
|
||||
|
||||
/* Configure the Interrupt in the RTC_CR register */
|
||||
__HAL_RTC_WAKEUPTIMER_ENABLE_IT(&hRTC_Handle,RTC_IT_WUT);
|
||||
|
||||
/* Enable the Wake-up Timer */
|
||||
__HAL_RTC_WAKEUPTIMER_ENABLE(&hRTC_Handle);
|
||||
|
||||
/* Enable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
||||
|
||||
/* Enable the RTC global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
|
||||
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling RTC_WKUP interrupt.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
||||
/* Disable WAKE UP TIMER Interrupt */
|
||||
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&hRTC_Handle, RTC_IT_WUT);
|
||||
/* Enable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling RTC_WKUP interrupt.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Disable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
||||
/* Enable WAKE UP TIMER interrupt */
|
||||
__HAL_RTC_WAKEUPTIMER_ENABLE_IT(&hRTC_Handle, RTC_IT_WUT);
|
||||
/* Enable the write protection for RTC registers */
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wake Up Timer Event Callback in non blocking mode
|
||||
* @note This function is called when RTC_WKUP interrupt took place, inside
|
||||
* RTC_WKUP_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param hrtc RTC handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hrtc);
|
||||
|
||||
HAL_IncTick();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles WAKE UP TIMER interrupt request.
|
||||
* @retval None
|
||||
*/
|
||||
void RTC_WKUP_IRQHandler(void)
|
||||
{
|
||||
HAL_RTCEx_WakeUpTimerIRQHandler(&hRTC_Handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_timebase_tim_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief HAL time base based on the hardware TIM.
|
||||
*
|
||||
* This file overrides the native HAL time base functions (defined as weak)
|
||||
* the TIM time base:
|
||||
* + Initializes the TIM peripheral generate a Period elapsed Event each 1ms
|
||||
* + HAL_IncTick is called inside HAL_TIM_PeriodElapsedCallback ie each 1ms
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This file must be copied to the application folder and modified as follows:
|
||||
(#) Rename it to 'stm32h7xx_hal_timebase_tim.c'
|
||||
(#) Add this file and the TIM HAL drivers to your project and uncomment
|
||||
HAL_TIM_MODULE_ENABLED define in stm32h7xx_hal_conf.h
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static TIM_HandleTypeDef TimHandle;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void TIM6_DAC_IRQHandler(void);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the TIM6 as a time base source.
|
||||
* 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 configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkconfig;
|
||||
uint32_t uwTimclock, uwAPB1Prescaler;
|
||||
uint32_t uwPrescalerValue;
|
||||
uint32_t pFLatency;
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
/* Enable TIM6 clock */
|
||||
__HAL_RCC_TIM6_CLK_ENABLE();
|
||||
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
|
||||
/* Get APB1 prescaler */
|
||||
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
|
||||
|
||||
/* Compute TIM6 clock */
|
||||
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
|
||||
{
|
||||
uwTimclock = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
else
|
||||
{
|
||||
uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
|
||||
/* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM6 */
|
||||
TimHandle.Instance = TIM6;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
+ Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
+ ClockDivision = 0
|
||||
+ Counter direction = Up
|
||||
*/
|
||||
TimHandle.Init.Period = (1000000U / 1000U) - 1U;
|
||||
TimHandle.Init.Prescaler = uwPrescalerValue;
|
||||
TimHandle.Init.ClockDivision = 0U;
|
||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
status = HAL_TIM_Base_Init(&TimHandle);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
status = HAL_TIM_Base_Start_IT(&TimHandle);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable the TIM6 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
|
||||
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
/* Enable the TIM6 global Interrupt */
|
||||
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM6 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&TimHandle, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM6 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM6 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(htim);
|
||||
|
||||
HAL_IncTick();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void TIM6_DAC_IRQHandler(void)
|
||||
{
|
||||
HAL_TIM_IRQHandler(&TimHandle);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,541 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_usart_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief Extended USART HAL module driver.
|
||||
* This file provides firmware functions to manage the following extended
|
||||
* functionalities of the Universal Synchronous Receiver Transmitter Peripheral (USART).
|
||||
* + Peripheral Control functions
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### USART peripheral extended features #####
|
||||
==============================================================================
|
||||
|
||||
(#) FIFO mode enabling/disabling and RX/TX FIFO threshold programming.
|
||||
|
||||
-@- When USART operates in FIFO mode, FIFO mode must be enabled prior
|
||||
starting RX/TX transfers. Also RX/TX FIFO thresholds must be
|
||||
configured prior starting RX/TX transfers.
|
||||
|
||||
(#) Slave mode enabling/disabling and NSS pin configuration.
|
||||
|
||||
-@- When USART operates in Slave mode, Slave mode must be enabled prior
|
||||
starting RX/TX transfers.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USARTEx USARTEx
|
||||
* @brief USART Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/** @defgroup USARTEx_Private_Constants USARTEx Private Constants
|
||||
* @{
|
||||
*/
|
||||
/* USART RX FIFO depth */
|
||||
#define RX_FIFO_DEPTH 16U
|
||||
|
||||
/* USART TX FIFO depth */
|
||||
#define TX_FIFO_DEPTH 16U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup USARTEx_Private_Functions USARTEx Private Functions
|
||||
* @{
|
||||
*/
|
||||
static void USARTEx_SetNbDataToProcess(USART_HandleTypeDef *husart);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup USARTEx_Exported_Functions USARTEx Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USARTEx_Exported_Functions_Group1 IO operation functions
|
||||
* @brief Extended USART Transmit/Receive functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
This subsection provides a set of FIFO mode related callback functions.
|
||||
|
||||
(#) TX/RX Fifos Callbacks:
|
||||
(+) HAL_USARTEx_RxFifoFullCallback()
|
||||
(+) HAL_USARTEx_TxFifoEmptyCallback()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USART RX Fifo full callback.
|
||||
* @param husart USART handle.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_USARTEx_RxFifoFullCallback(USART_HandleTypeDef *husart)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(husart);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_USARTEx_RxFifoFullCallback can be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART TX Fifo empty callback.
|
||||
* @param husart USART handle.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_USARTEx_TxFifoEmptyCallback(USART_HandleTypeDef *husart)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(husart);
|
||||
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_USARTEx_TxFifoEmptyCallback can be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USARTEx_Exported_Functions_Group2 Peripheral Control functions
|
||||
* @brief Extended Peripheral Control functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Peripheral Control functions #####
|
||||
===============================================================================
|
||||
[..] This section provides the following functions:
|
||||
(+) HAL_USARTEx_EnableSPISlaveMode() API enables the SPI slave mode
|
||||
(+) HAL_USARTEx_DisableSPISlaveMode() API disables the SPI slave mode
|
||||
(+) HAL_USARTEx_ConfigNSS API configures the Slave Select input pin (NSS)
|
||||
(+) HAL_USARTEx_EnableFifoMode() API enables the FIFO mode
|
||||
(+) HAL_USARTEx_DisableFifoMode() API disables the FIFO mode
|
||||
(+) HAL_USARTEx_SetTxFifoThreshold() API sets the TX FIFO threshold
|
||||
(+) HAL_USARTEx_SetRxFifoThreshold() API sets the RX FIFO threshold
|
||||
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable the SPI slave mode.
|
||||
* @note When the USART operates in SPI slave mode, it handles data flow using
|
||||
* the serial interface clock derived from the external SCLK signal
|
||||
* provided by the external master SPI device.
|
||||
* @note In SPI slave mode, the USART must be enabled before starting the master
|
||||
* communications (or between frames while the clock is stable). Otherwise,
|
||||
* if the USART slave is enabled while the master is in the middle of a
|
||||
* frame, it will become desynchronized with the master.
|
||||
* @note The data register of the slave needs to be ready before the first edge
|
||||
* of the communication clock or before the end of the ongoing communication,
|
||||
* otherwise the SPI slave will transmit zeros.
|
||||
* @param husart USART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USARTEx_EnableSlaveMode(USART_HandleTypeDef *husart)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_SPI_SLAVE_INSTANCE(husart->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Save actual USART configuration */
|
||||
tmpcr1 = READ_REG(husart->Instance->CR1);
|
||||
|
||||
/* Disable USART */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* In SPI slave mode mode, the following bits must be kept cleared:
|
||||
- LINEN and CLKEN bit in the USART_CR2 register
|
||||
- HDSEL, SCEN and IREN bits in the USART_CR3 register.*/
|
||||
CLEAR_BIT(husart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
|
||||
CLEAR_BIT(husart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
|
||||
|
||||
/* Enable SPI slave mode */
|
||||
SET_BIT(husart->Instance->CR2, USART_CR2_SLVEN);
|
||||
|
||||
/* Restore USART configuration */
|
||||
WRITE_REG(husart->Instance->CR1, tmpcr1);
|
||||
|
||||
husart->SlaveMode = USART_SLAVEMODE_ENABLE;
|
||||
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Enable USART */
|
||||
__HAL_USART_ENABLE(husart);
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the SPI slave mode.
|
||||
* @param husart USART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USARTEx_DisableSlaveMode(USART_HandleTypeDef *husart)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_SPI_SLAVE_INSTANCE(husart->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Save actual USART configuration */
|
||||
tmpcr1 = READ_REG(husart->Instance->CR1);
|
||||
|
||||
/* Disable USART */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* Disable SPI slave mode */
|
||||
CLEAR_BIT(husart->Instance->CR2, USART_CR2_SLVEN);
|
||||
|
||||
/* Restore USART configuration */
|
||||
WRITE_REG(husart->Instance->CR1, tmpcr1);
|
||||
|
||||
husart->SlaveMode = USART_SLAVEMODE_DISABLE;
|
||||
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the Slave Select input pin (NSS).
|
||||
* @note Software NSS management: SPI slave will always be selected and NSS
|
||||
* input pin will be ignored.
|
||||
* @note Hardware NSS management: the SPI slave selection depends on NSS
|
||||
* input pin. The slave is selected when NSS is low and deselected when
|
||||
* NSS is high.
|
||||
* @param husart USART handle.
|
||||
* @param NSSConfig NSS configuration.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref USART_NSS_HARD
|
||||
* @arg @ref USART_NSS_SOFT
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USARTEx_ConfigNSS(USART_HandleTypeDef *husart, uint32_t NSSConfig)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_SPI_SLAVE_INSTANCE(husart->Instance));
|
||||
assert_param(IS_USART_NSS(NSSConfig));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Save actual USART configuration */
|
||||
tmpcr1 = READ_REG(husart->Instance->CR1);
|
||||
|
||||
/* Disable USART */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* Program DIS_NSS bit in the USART_CR2 register */
|
||||
MODIFY_REG(husart->Instance->CR2, USART_CR2_DIS_NSS, NSSConfig);
|
||||
|
||||
/* Restore USART configuration */
|
||||
WRITE_REG(husart->Instance->CR1, tmpcr1);
|
||||
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the FIFO mode.
|
||||
* @param husart USART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USARTEx_EnableFifoMode(USART_HandleTypeDef *husart)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(husart->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Save actual USART configuration */
|
||||
tmpcr1 = READ_REG(husart->Instance->CR1);
|
||||
|
||||
/* Disable USART */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* Enable FIFO mode */
|
||||
SET_BIT(tmpcr1, USART_CR1_FIFOEN);
|
||||
husart->FifoMode = USART_FIFOMODE_ENABLE;
|
||||
|
||||
/* Restore USART configuration */
|
||||
WRITE_REG(husart->Instance->CR1, tmpcr1);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
USARTEx_SetNbDataToProcess(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the FIFO mode.
|
||||
* @param husart USART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USARTEx_DisableFifoMode(USART_HandleTypeDef *husart)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(husart->Instance));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Save actual USART configuration */
|
||||
tmpcr1 = READ_REG(husart->Instance->CR1);
|
||||
|
||||
/* Disable USART */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* Disable FIFO mode */
|
||||
CLEAR_BIT(tmpcr1, USART_CR1_FIFOEN);
|
||||
husart->FifoMode = USART_FIFOMODE_DISABLE;
|
||||
|
||||
/* Restore USART configuration */
|
||||
WRITE_REG(husart->Instance->CR1, tmpcr1);
|
||||
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the TXFIFO threshold.
|
||||
* @param husart USART handle.
|
||||
* @param Threshold TX FIFO threshold value
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref USART_TXFIFO_THRESHOLD_1_8
|
||||
* @arg @ref USART_TXFIFO_THRESHOLD_1_4
|
||||
* @arg @ref USART_TXFIFO_THRESHOLD_1_2
|
||||
* @arg @ref USART_TXFIFO_THRESHOLD_3_4
|
||||
* @arg @ref USART_TXFIFO_THRESHOLD_7_8
|
||||
* @arg @ref USART_TXFIFO_THRESHOLD_8_8
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USARTEx_SetTxFifoThreshold(USART_HandleTypeDef *husart, uint32_t Threshold)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(husart->Instance));
|
||||
assert_param(IS_USART_TXFIFO_THRESHOLD(Threshold));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Save actual USART configuration */
|
||||
tmpcr1 = READ_REG(husart->Instance->CR1);
|
||||
|
||||
/* Disable USART */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* Update TX threshold configuration */
|
||||
MODIFY_REG(husart->Instance->CR3, USART_CR3_TXFTCFG, Threshold);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
USARTEx_SetNbDataToProcess(husart);
|
||||
|
||||
/* Restore USART configuration */
|
||||
WRITE_REG(husart->Instance->CR1, tmpcr1);
|
||||
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the RXFIFO threshold.
|
||||
* @param husart USART handle.
|
||||
* @param Threshold RX FIFO threshold value
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref USART_RXFIFO_THRESHOLD_1_8
|
||||
* @arg @ref USART_RXFIFO_THRESHOLD_1_4
|
||||
* @arg @ref USART_RXFIFO_THRESHOLD_1_2
|
||||
* @arg @ref USART_RXFIFO_THRESHOLD_3_4
|
||||
* @arg @ref USART_RXFIFO_THRESHOLD_7_8
|
||||
* @arg @ref USART_RXFIFO_THRESHOLD_8_8
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USARTEx_SetRxFifoThreshold(USART_HandleTypeDef *husart, uint32_t Threshold)
|
||||
{
|
||||
uint32_t tmpcr1;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_UART_FIFO_INSTANCE(husart->Instance));
|
||||
assert_param(IS_USART_RXFIFO_THRESHOLD(Threshold));
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Save actual USART configuration */
|
||||
tmpcr1 = READ_REG(husart->Instance->CR1);
|
||||
|
||||
/* Disable USART */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* Update RX threshold configuration */
|
||||
MODIFY_REG(husart->Instance->CR3, USART_CR3_RXFTCFG, Threshold);
|
||||
|
||||
/* Determine the number of data to process during RX/TX ISR execution */
|
||||
USARTEx_SetNbDataToProcess(husart);
|
||||
|
||||
/* Restore USART configuration */
|
||||
WRITE_REG(husart->Instance->CR1, tmpcr1);
|
||||
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup USARTEx_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Calculate the number of data to process in RX/TX ISR.
|
||||
* @note The RX FIFO depth and the TX FIFO depth is extracted from
|
||||
* the USART configuration registers.
|
||||
* @param husart USART handle.
|
||||
* @retval None
|
||||
*/
|
||||
static void USARTEx_SetNbDataToProcess(USART_HandleTypeDef *husart)
|
||||
{
|
||||
uint8_t rx_fifo_depth;
|
||||
uint8_t tx_fifo_depth;
|
||||
uint8_t rx_fifo_threshold;
|
||||
uint8_t tx_fifo_threshold;
|
||||
/* 2 0U/1U added for MISRAC2012-Rule-18.1_b and MISRAC2012-Rule-18.1_d */
|
||||
static const uint8_t numerator[] = {1U, 1U, 1U, 3U, 7U, 1U, 0U, 0U};
|
||||
static const uint8_t denominator[] = {8U, 4U, 2U, 4U, 8U, 1U, 1U, 1U};
|
||||
|
||||
if (husart->FifoMode == USART_FIFOMODE_DISABLE)
|
||||
{
|
||||
husart->NbTxDataToProcess = 1U;
|
||||
husart->NbRxDataToProcess = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx_fifo_depth = RX_FIFO_DEPTH;
|
||||
tx_fifo_depth = TX_FIFO_DEPTH;
|
||||
rx_fifo_threshold = (uint8_t)((READ_BIT(husart->Instance->CR3,
|
||||
USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos) & 0xFFU);
|
||||
tx_fifo_threshold = (uint8_t)((READ_BIT(husart->Instance->CR3,
|
||||
USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos) & 0xFFU);
|
||||
husart->NbTxDataToProcess = ((uint16_t)tx_fifo_depth * numerator[tx_fifo_threshold]) /
|
||||
(uint16_t)denominator[tx_fifo_threshold];
|
||||
husart->NbRxDataToProcess = ((uint16_t)rx_fifo_depth * numerator[rx_fifo_threshold]) /
|
||||
(uint16_t)denominator[rx_fifo_threshold];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_wwdg.c
|
||||
* @author MCD Application Team
|
||||
* @brief WWDG HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Window Watchdog (WWDG) peripheral:
|
||||
* + Initialization and Configuration functions
|
||||
* + IO operation functions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### 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 down 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.
|
||||
(+) If required by application, an Early Wakeup Interrupt can be triggered
|
||||
in order to be warned before WWDG expiration. 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 0x40, interrupt occurs. This mechanism requires WWDG interrupt
|
||||
line to be enabled in NVIC. Once enabled, EWI interrupt cannot be
|
||||
disabled except by a system reset.
|
||||
(+) WWDGRST flag in RCC CSR register can be used to inform when a WWDG
|
||||
reset occurs.
|
||||
(+) The WWDG counter input clock is derived from the APB clock divided
|
||||
by a programmable prescaler.
|
||||
(+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler)
|
||||
(+) WWDG timeout (mS) = 1000 * (T[5;0] + 1) / WWDG clock (Hz)
|
||||
where T[5;0] are the lowest 6 bits of Counter.
|
||||
(+) WWDG Counter refresh is allowed between the following limits :
|
||||
(++) min time (mS) = 1000 * (Counter - Window) / WWDG clock
|
||||
(++) max time (mS) = 1000 * (Counter - 0x40) / WWDG clock
|
||||
(+) Typical values (case of STM32H74x/5x devices):
|
||||
(++) Counter min (T[5;0] = 0x00) @100MHz (PCLK1) with zero prescaler:
|
||||
max timeout before reset: approximately 40.96µs
|
||||
(++) Counter max (T[5;0] = 0x3F) @100MHz (PCLK1) with prescaler dividing by 128:
|
||||
max timeout before reset: approximately 335.54ms
|
||||
(+) Typical values (case of STM32H7Ax/Bx devices):
|
||||
(++) Counter min (T[5;0] = 0x00) @140MHz (PCLK1) with zero prescaler:
|
||||
max timeout before reset: approximately 29.25µs
|
||||
(++) Counter max (T[5;0] = 0x3F) @140MHz (PCLK1) with prescaler dividing by 128:
|
||||
max timeout before reset: approximately 239.67ms
|
||||
(+) Typical values (case of STM32H72x/3x devices):
|
||||
(++) Counter min (T[5;0] = 0x00) @125MHz (PCLK1) with zero prescaler:
|
||||
max timeout before reset: approximately 32.76µs
|
||||
(++) Counter max (T[5;0] = 0x3F) @125MHz (PCLK1) with prescaler dividing by 128:
|
||||
max timeout before reset: approximately 268.43ms
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
|
||||
*** Common driver usage ***
|
||||
===========================
|
||||
|
||||
[..]
|
||||
(+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE().
|
||||
(+) Configure the WWDG prescaler, refresh window value, counter value and early
|
||||
interrupt status using HAL_WWDG_Init() function. This will automatically
|
||||
enable WWDG and start its downcounter. Time reference can be taken from
|
||||
function exit. Care must be taken to provide a counter value
|
||||
greater than 0x40 to prevent generation of immediate reset.
|
||||
(+) If the Early Wakeup Interrupt (EWI) feature is enabled, an interrupt is
|
||||
generated when the counter reaches 0x40. When HAL_WWDG_IRQHandler is
|
||||
triggered by the interrupt service routine, flag will be automatically
|
||||
cleared and HAL_WWDG_WakeupCallback user callback will be executed. User
|
||||
can add his own code by customization of callback HAL_WWDG_WakeupCallback.
|
||||
(+) Then 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 refresh window value already programmed.
|
||||
|
||||
*** Callback registration ***
|
||||
=============================
|
||||
|
||||
[..]
|
||||
The compilation define USE_HAL_WWDG_REGISTER_CALLBACKS when set to 1 allows
|
||||
the user to configure dynamically the driver callbacks. Use Functions
|
||||
HAL_WWDG_RegisterCallback() to register a user callback.
|
||||
|
||||
(+) Function HAL_WWDG_RegisterCallback() allows to register following
|
||||
callbacks:
|
||||
(++) EwiCallback : callback for Early WakeUp Interrupt.
|
||||
(++) MspInitCallback : WWDG MspInit.
|
||||
This function takes as parameters the HAL peripheral handle, the Callback ID
|
||||
and a pointer to the user callback function.
|
||||
|
||||
(+) Use function HAL_WWDG_UnRegisterCallback() to reset a callback to
|
||||
the default weak (surcharged) function. HAL_WWDG_UnRegisterCallback()
|
||||
takes as parameters the HAL peripheral handle and the Callback ID.
|
||||
This function allows to reset following callbacks:
|
||||
(++) EwiCallback : callback for Early WakeUp Interrupt.
|
||||
(++) MspInitCallback : WWDG MspInit.
|
||||
|
||||
[..]
|
||||
When calling HAL_WWDG_Init function, callbacks are reset to the
|
||||
corresponding legacy weak (surcharged) functions:
|
||||
HAL_WWDG_EarlyWakeupCallback() and HAL_WWDG_MspInit() only if they have
|
||||
not been registered before.
|
||||
|
||||
[..]
|
||||
When compilation define USE_HAL_WWDG_REGISTER_CALLBACKS is set to 0 or
|
||||
not defined, the callback registering feature is not available
|
||||
and weak (surcharged) callbacks are used.
|
||||
|
||||
*** WWDG HAL driver macros list ***
|
||||
===================================
|
||||
[..]
|
||||
Below the list of available macros in WWDG HAL driver.
|
||||
(+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral
|
||||
(+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status
|
||||
(+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags
|
||||
(+) __HAL_WWDG_ENABLE_IT: Enable the WWDG early wakeup interrupt
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* 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));
|
||||
|
||||
#if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
|
||||
/* Reset Callback pointers */
|
||||
if (hwwdg->EwiCallback == NULL)
|
||||
{
|
||||
hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback;
|
||||
}
|
||||
|
||||
if (hwwdg->MspInitCallback == NULL)
|
||||
{
|
||||
hwwdg->MspInitCallback = HAL_WWDG_MspInit;
|
||||
}
|
||||
|
||||
/* Init the low level hardware */
|
||||
hwwdg->MspInitCallback(hwwdg);
|
||||
#else
|
||||
/* Init the low level hardware */
|
||||
HAL_WWDG_MspInit(hwwdg);
|
||||
#endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
|
||||
|
||||
/* 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
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
|
||||
/**
|
||||
* @brief Register a User WWDG Callback
|
||||
* To be used instead of the weak (surcharged) predefined callback
|
||||
* @param hwwdg WWDG handle
|
||||
* @param CallbackID ID of the callback to be registered
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID
|
||||
* @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID
|
||||
* @param pCallback pointer to the Callback function
|
||||
* @retval status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID,
|
||||
pWWDG_CallbackTypeDef pCallback)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if (pCallback == NULL)
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_WWDG_EWI_CB_ID:
|
||||
hwwdg->EwiCallback = pCallback;
|
||||
break;
|
||||
|
||||
case HAL_WWDG_MSPINIT_CB_ID:
|
||||
hwwdg->MspInitCallback = pCallback;
|
||||
break;
|
||||
|
||||
default:
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Unregister a WWDG Callback
|
||||
* WWDG Callback is redirected to the weak (surcharged) predefined callback
|
||||
* @param hwwdg WWDG handle
|
||||
* @param CallbackID ID of the callback to be registered
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID
|
||||
* @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID
|
||||
* @retval status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
switch (CallbackID)
|
||||
{
|
||||
case HAL_WWDG_EWI_CB_ID:
|
||||
hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback;
|
||||
break;
|
||||
|
||||
case HAL_WWDG_MSPINIT_CB_ID:
|
||||
hwwdg->MspInitCallback = HAL_WWDG_MspInit;
|
||||
break;
|
||||
|
||||
default:
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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);
|
||||
|
||||
#if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
|
||||
/* Early Wakeup registered callback */
|
||||
hwwdg->EwiCallback(hwwdg);
|
||||
#else
|
||||
/* Early Wakeup callback */
|
||||
HAL_WWDG_EarlyWakeupCallback(hwwdg);
|
||||
#endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,359 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_ll_bdma.c
|
||||
* @author MCD Application Team
|
||||
* @brief BDMA LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_ll_bdma.h"
|
||||
#include "stm32h7xx_ll_bus.h"
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32H7xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (BDMA) || defined (BDMA1) || defined (BDMA2)
|
||||
|
||||
/** @addtogroup BDMA_LL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @addtogroup BDMA_LL_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define IS_LL_BDMA_DIRECTION(__VALUE__) (((__VALUE__) == LL_BDMA_DIRECTION_PERIPH_TO_MEMORY) || \
|
||||
((__VALUE__) == LL_BDMA_DIRECTION_MEMORY_TO_PERIPH) || \
|
||||
((__VALUE__) == LL_BDMA_DIRECTION_MEMORY_TO_MEMORY))
|
||||
|
||||
#define IS_LL_BDMA_MODE(__VALUE__) (((__VALUE__) == LL_BDMA_MODE_NORMAL) || \
|
||||
((__VALUE__) == LL_BDMA_MODE_CIRCULAR))
|
||||
|
||||
#define IS_LL_BDMA_PERIPHINCMODE(__VALUE__) (((__VALUE__) == LL_BDMA_PERIPH_INCREMENT) || \
|
||||
((__VALUE__) == LL_BDMA_PERIPH_NOINCREMENT))
|
||||
|
||||
#define IS_LL_BDMA_MEMORYINCMODE(__VALUE__) (((__VALUE__) == LL_BDMA_MEMORY_INCREMENT) || \
|
||||
((__VALUE__) == LL_BDMA_MEMORY_NOINCREMENT))
|
||||
|
||||
#define IS_LL_BDMA_PERIPHDATASIZE(__VALUE__) (((__VALUE__) == LL_BDMA_PDATAALIGN_BYTE) || \
|
||||
((__VALUE__) == LL_BDMA_PDATAALIGN_HALFWORD) || \
|
||||
((__VALUE__) == LL_BDMA_PDATAALIGN_WORD))
|
||||
|
||||
#define IS_LL_BDMA_MEMORYDATASIZE(__VALUE__) (((__VALUE__) == LL_BDMA_MDATAALIGN_BYTE) || \
|
||||
((__VALUE__) == LL_BDMA_MDATAALIGN_HALFWORD) || \
|
||||
((__VALUE__) == LL_BDMA_MDATAALIGN_WORD))
|
||||
|
||||
#define IS_LL_BDMA_NBDATA(__VALUE__) ((__VALUE__) <= 0x0000FFFFU)
|
||||
|
||||
#if defined(ADC3)
|
||||
#define IS_LL_BDMA_PERIPHREQUEST(__VALUE__) ((__VALUE__) <= LL_DMAMUX2_REQ_ADC3)
|
||||
#else
|
||||
#define IS_LL_BDMA_PERIPHREQUEST(__VALUE__) ((__VALUE__) <= LL_DMAMUX2_REQ_DFSDM2_FLT0)
|
||||
#endif /* ADC3 */
|
||||
|
||||
#define IS_LL_BDMA_PRIORITY(__VALUE__) (((__VALUE__) == LL_BDMA_PRIORITY_LOW) || \
|
||||
((__VALUE__) == LL_BDMA_PRIORITY_MEDIUM) || \
|
||||
((__VALUE__) == LL_BDMA_PRIORITY_HIGH) || \
|
||||
((__VALUE__) == LL_BDMA_PRIORITY_VERYHIGH))
|
||||
|
||||
#define IS_LL_BDMA_DOUBLEBUFFER_MODE(__VALUE__) (((__VALUE__) == LL_BDMA_DOUBLEBUFFER_MODE_DISABLE) || \
|
||||
((__VALUE__) == LL_BDMA_DOUBLEBUFFER_MODE_ENABLE))
|
||||
|
||||
#define IS_LL_BDMA_DOUBLEBUFFER_TARGETMEM(__VALUE__) (((__VALUE__) == LL_BDMA_CURRENTTARGETMEM0) || \
|
||||
((__VALUE__) == LL_BDMA_CURRENTTARGETMEM1))
|
||||
|
||||
#define IS_LL_BDMA_ALL_CHANNEL_INSTANCE(INSTANCE, CHANNEL) ((((INSTANCE) == BDMA) && \
|
||||
(((CHANNEL) == LL_BDMA_CHANNEL_0) || \
|
||||
((CHANNEL) == LL_BDMA_CHANNEL_1) || \
|
||||
((CHANNEL) == LL_BDMA_CHANNEL_2) || \
|
||||
((CHANNEL) == LL_BDMA_CHANNEL_3) || \
|
||||
((CHANNEL) == LL_BDMA_CHANNEL_4) || \
|
||||
((CHANNEL) == LL_BDMA_CHANNEL_5) || \
|
||||
((CHANNEL) == LL_BDMA_CHANNEL_6) || \
|
||||
((CHANNEL) == LL_BDMA_CHANNEL_7))))
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup BDMA_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup BDMA_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-initialize the DMA registers to their default reset values.
|
||||
* @param BDMAx BDMAx Instance
|
||||
* @param Channel This parameter can be one of the following values:
|
||||
* @arg @ref LL_BDMA_CHANNEL_0
|
||||
* @arg @ref LL_BDMA_CHANNEL_1
|
||||
* @arg @ref LL_BDMA_CHANNEL_2
|
||||
* @arg @ref LL_BDMA_CHANNEL_3
|
||||
* @arg @ref LL_BDMA_CHANNEL_4
|
||||
* @arg @ref LL_BDMA_CHANNEL_5
|
||||
* @arg @ref LL_BDMA_CHANNEL_6
|
||||
* @arg @ref LL_BDMA_CHANNEL_7
|
||||
* @arg @ref LL_BDMA_CHANNEL_ALL
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: DMA registers are de-initialized
|
||||
* - ERROR: DMA registers are not de-initialized
|
||||
*/
|
||||
uint32_t LL_BDMA_DeInit(BDMA_TypeDef *BDMAx, uint32_t Channel)
|
||||
{
|
||||
BDMA_Channel_TypeDef *tmp ;
|
||||
ErrorStatus status = SUCCESS;
|
||||
|
||||
/* Check the DMA Instance DMAx and Channel parameters */
|
||||
assert_param(IS_LL_BDMA_ALL_CHANNEL_INSTANCE(BDMAx, Channel) || (Channel == LL_BDMA_CHANNEL_ALL));
|
||||
|
||||
if (Channel == LL_BDMA_CHANNEL_ALL)
|
||||
{
|
||||
if (BDMAx == BDMA)
|
||||
{
|
||||
/* Force reset of BDMA clock */
|
||||
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA1);
|
||||
|
||||
/* Release reset of BDMA clock */
|
||||
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA1);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (BDMA_Channel_TypeDef *)(__LL_BDMA_GET_CHANNEL_INSTANCE(BDMAx, Channel));
|
||||
|
||||
/* Disable the selected DMAx_Channely */
|
||||
CLEAR_BIT(tmp->CCR, BDMA_CCR_EN);
|
||||
|
||||
/* Reset DMAx_Channely control register */
|
||||
LL_BDMA_WriteReg(tmp, CCR, 0U);
|
||||
|
||||
/* Reset DMAx_Channely remaining bytes register */
|
||||
LL_BDMA_WriteReg(tmp, CNDTR, 0U);
|
||||
|
||||
/* Reset DMAx_Channely peripheral address register */
|
||||
LL_BDMA_WriteReg(tmp, CPAR, 0U);
|
||||
|
||||
/* Reset DMAx_Channely memory 0 address register */
|
||||
LL_BDMA_WriteReg(tmp, CM0AR, 0U);
|
||||
|
||||
/* Reset DMAx_Channely memory 1 address register */
|
||||
LL_BDMA_WriteReg(tmp, CM1AR, 0U);
|
||||
|
||||
/* Reset Request register field for BDMAx Channel */
|
||||
LL_BDMA_SetPeriphRequest(BDMAx, Channel, LL_DMAMUX2_REQ_MEM2MEM);
|
||||
|
||||
if (Channel == LL_BDMA_CHANNEL_0)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel0 */
|
||||
LL_BDMA_ClearFlag_GI0(BDMAx);
|
||||
}
|
||||
else if (Channel == LL_BDMA_CHANNEL_1)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel1 */
|
||||
LL_BDMA_ClearFlag_GI1(BDMAx);
|
||||
}
|
||||
else if (Channel == LL_BDMA_CHANNEL_2)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel2 */
|
||||
LL_BDMA_ClearFlag_GI2(BDMAx);
|
||||
}
|
||||
else if (Channel == LL_BDMA_CHANNEL_3)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel3 */
|
||||
LL_BDMA_ClearFlag_GI3(BDMAx);
|
||||
}
|
||||
else if (Channel == LL_BDMA_CHANNEL_4)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel4 */
|
||||
LL_BDMA_ClearFlag_GI4(BDMAx);
|
||||
}
|
||||
else if (Channel == LL_BDMA_CHANNEL_5)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel5 */
|
||||
LL_BDMA_ClearFlag_GI5(BDMAx);
|
||||
}
|
||||
|
||||
else if (Channel == LL_BDMA_CHANNEL_6)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel6 */
|
||||
LL_BDMA_ClearFlag_GI6(BDMAx);
|
||||
}
|
||||
else if (Channel == LL_BDMA_CHANNEL_7)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel7 */
|
||||
LL_BDMA_ClearFlag_GI7(BDMAx);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return (uint32_t)status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the BDMA registers according to the specified parameters in BDMA_InitStruct.
|
||||
* @note To convert BDMAx_Channely Instance to BDMAx Instance and Channely, use helper macros :
|
||||
* @arg @ref __LL_BDMA_GET_INSTANCE
|
||||
* @arg @ref __LL_BDMA_GET_CHANNEL
|
||||
* @param BDMAx BDMAx Instance
|
||||
* @param Channel This parameter can be one of the following values:
|
||||
* @arg @ref LL_BDMA_CHANNEL_0
|
||||
* @arg @ref LL_BDMA_CHANNEL_1
|
||||
* @arg @ref LL_BDMA_CHANNEL_2
|
||||
* @arg @ref LL_BDMA_CHANNEL_3
|
||||
* @arg @ref LL_BDMA_CHANNEL_4
|
||||
* @arg @ref LL_BDMA_CHANNEL_5
|
||||
* @arg @ref LL_BDMA_CHANNEL_6
|
||||
* @arg @ref LL_BDMA_CHANNEL_7
|
||||
* @param BDMA_InitStruct pointer to a @ref LL_BDMA_InitTypeDef structure.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: DMA registers are initialized
|
||||
* - ERROR: Not applicable
|
||||
*/
|
||||
uint32_t LL_BDMA_Init(BDMA_TypeDef *BDMAx, uint32_t Channel, LL_BDMA_InitTypeDef *BDMA_InitStruct)
|
||||
{
|
||||
/* Check the DMA Instance DMAx and Channel parameters */
|
||||
assert_param(IS_LL_BDMA_ALL_CHANNEL_INSTANCE(BDMAx, Channel));
|
||||
|
||||
/* Check the DMA parameters from BDMA_InitStruct */
|
||||
assert_param(IS_LL_BDMA_DIRECTION(BDMA_InitStruct->Direction));
|
||||
assert_param(IS_LL_BDMA_MODE(BDMA_InitStruct->Mode));
|
||||
assert_param(IS_LL_BDMA_PERIPHINCMODE(BDMA_InitStruct->PeriphOrM2MSrcIncMode));
|
||||
assert_param(IS_LL_BDMA_MEMORYINCMODE(BDMA_InitStruct->MemoryOrM2MDstIncMode));
|
||||
assert_param(IS_LL_BDMA_PERIPHDATASIZE(BDMA_InitStruct->PeriphOrM2MSrcDataSize));
|
||||
assert_param(IS_LL_BDMA_MEMORYDATASIZE(BDMA_InitStruct->MemoryOrM2MDstDataSize));
|
||||
assert_param(IS_LL_BDMA_NBDATA(BDMA_InitStruct->NbData));
|
||||
assert_param(IS_LL_BDMA_PERIPHREQUEST(BDMA_InitStruct->PeriphRequest));
|
||||
assert_param(IS_LL_BDMA_PRIORITY(BDMA_InitStruct->Priority));
|
||||
assert_param(IS_LL_BDMA_DOUBLEBUFFER_MODE(BDMA_InitStruct->DoubleBufferMode));
|
||||
assert_param(IS_LL_BDMA_DOUBLEBUFFER_TARGETMEM(BDMA_InitStruct->TargetMemInDoubleBufferMode));
|
||||
|
||||
/*---------------------------- DMAx CCR Configuration ------------------------
|
||||
* Configure DMAx_Channely: data transfer direction, data transfer mode,
|
||||
* peripheral and memory increment mode,
|
||||
* data size alignment and priority level with parameters :
|
||||
* - Direction: BDMA_CCR_DIR and BDMA_CCR_MEM2MEM bits
|
||||
* - Mode: BDMA_CCR_CIRC bit
|
||||
* - PeriphOrM2MSrcIncMode: BDMA_CCR_PINC bit
|
||||
* - MemoryOrM2MDstIncMode: BDMA_CCR_MINC bit
|
||||
* - PeriphOrM2MSrcDataSize: BDMA_CCR_PSIZE[1:0] bits
|
||||
* - MemoryOrM2MDstDataSize: BDMA_CCR_MSIZE[1:0] bits
|
||||
* - Priority: BDMA_CCR_PL[1:0] bits
|
||||
* - DoubleBufferMode: BDMA_CCR_DBM bit
|
||||
* - TargetMemInDoubleBufferMode: BDMA_CCR_CT bit
|
||||
*/
|
||||
LL_BDMA_ConfigTransfer(BDMAx, Channel,
|
||||
BDMA_InitStruct->Direction | \
|
||||
BDMA_InitStruct->Mode | \
|
||||
BDMA_InitStruct->PeriphOrM2MSrcIncMode | \
|
||||
BDMA_InitStruct->MemoryOrM2MDstIncMode | \
|
||||
BDMA_InitStruct->PeriphOrM2MSrcDataSize | \
|
||||
BDMA_InitStruct->MemoryOrM2MDstDataSize | \
|
||||
BDMA_InitStruct->Priority | \
|
||||
BDMA_InitStruct->DoubleBufferMode | \
|
||||
BDMA_InitStruct->TargetMemInDoubleBufferMode);
|
||||
|
||||
/*-------------------------- DMAx CMAR Configuration -------------------------
|
||||
* Configure the memory or destination base address with parameter :
|
||||
* - MemoryOrM2MDstAddress: BDMA_CMAR_MA[31:0] bits
|
||||
*/
|
||||
LL_BDMA_SetMemoryAddress(BDMAx, Channel, BDMA_InitStruct->MemoryOrM2MDstAddress);
|
||||
|
||||
/*-------------------------- DMAx CPAR Configuration -------------------------
|
||||
* Configure the peripheral or source base address with parameter :
|
||||
* - PeriphOrM2MSrcAddress: BDMA_CPAR_PA[31:0] bits
|
||||
*/
|
||||
LL_BDMA_SetPeriphAddress(BDMAx, Channel, BDMA_InitStruct->PeriphOrM2MSrcAddress);
|
||||
|
||||
/*--------------------------- DMAx CNDTR Configuration -----------------------
|
||||
* Configure the peripheral base address with parameter :
|
||||
* - NbData: BDMA_CNDTR_NDT[15:0] bits
|
||||
*/
|
||||
LL_BDMA_SetDataLength(BDMAx, Channel, BDMA_InitStruct->NbData);
|
||||
|
||||
/*--------------------------- DMAMUXx CCR Configuration ----------------------
|
||||
* Configure the DMA request for DMA Channels on DMAMUX Channel x with parameter :
|
||||
* - PeriphRequest: BDMA_CxCR[7:0] bits
|
||||
*/
|
||||
LL_BDMA_SetPeriphRequest(BDMAx, Channel, BDMA_InitStruct->PeriphRequest);
|
||||
|
||||
return (uint32_t)SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_BDMA_InitTypeDef field to default value.
|
||||
* @param BDMA_InitStruct Pointer to a @ref LL_BDMA_InitTypeDef structure.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_BDMA_StructInit(LL_BDMA_InitTypeDef *BDMA_InitStruct)
|
||||
{
|
||||
/* Set BDMA_InitStruct fields to default values */
|
||||
BDMA_InitStruct->PeriphOrM2MSrcAddress = 0x00000000U;
|
||||
BDMA_InitStruct->MemoryOrM2MDstAddress = 0x00000000U;
|
||||
BDMA_InitStruct->Direction = LL_BDMA_DIRECTION_PERIPH_TO_MEMORY;
|
||||
BDMA_InitStruct->Mode = LL_BDMA_MODE_NORMAL;
|
||||
BDMA_InitStruct->PeriphOrM2MSrcIncMode = LL_BDMA_PERIPH_NOINCREMENT;
|
||||
BDMA_InitStruct->MemoryOrM2MDstIncMode = LL_BDMA_MEMORY_NOINCREMENT;
|
||||
BDMA_InitStruct->PeriphOrM2MSrcDataSize = LL_BDMA_PDATAALIGN_BYTE;
|
||||
BDMA_InitStruct->MemoryOrM2MDstDataSize = LL_BDMA_MDATAALIGN_BYTE;
|
||||
BDMA_InitStruct->NbData = 0x00000000U;
|
||||
BDMA_InitStruct->PeriphRequest = LL_DMAMUX2_REQ_MEM2MEM;
|
||||
BDMA_InitStruct->Priority = LL_BDMA_PRIORITY_LOW;
|
||||
BDMA_InitStruct->DoubleBufferMode = LL_BDMA_DOUBLEBUFFER_MODE_DISABLE;
|
||||
BDMA_InitStruct->TargetMemInDoubleBufferMode = LL_BDMA_CURRENTTARGETMEM0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* BDMA || BDMA1 || BDMA2 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_ll_comp.c
|
||||
* @author MCD Application Team
|
||||
* @brief COMP LL module driver
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_ll_comp.h"
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32H7xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (COMP1) || defined (COMP2)
|
||||
|
||||
/** @addtogroup COMP_LL COMP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup COMP_LL_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Check of parameters for configuration of COMP hierarchical scope: */
|
||||
/* COMP instance. */
|
||||
|
||||
#define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
|
||||
( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
|
||||
|| ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
|
||||
|| ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
|
||||
)
|
||||
|
||||
/* Note: On this STM32 series, comparator input plus parameters are */
|
||||
/* the same on all COMP instances. */
|
||||
/* However, comparator instance kept as macro parameter for */
|
||||
/* compatibility with other STM32 families. */
|
||||
#if defined (COMP_CFGRx_INP2SEL)
|
||||
#define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
|
||||
( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
|
||||
|| ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
|
||||
|| ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC2_CH1))
|
||||
#else
|
||||
#define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
|
||||
( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
|
||||
|| ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2))
|
||||
#endif
|
||||
|
||||
/* Note: On this STM32 series, comparator input minus parameters are */
|
||||
/* the same on all COMP instances. */
|
||||
/* However, comparator instance kept as macro parameter for */
|
||||
/* compatibility with other STM32 families. */
|
||||
#if defined (COMP_CFGRx_INMSEL_3)
|
||||
#define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
|
||||
( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VBAT_VDDAP))
|
||||
#else
|
||||
#define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
|
||||
( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
|
||||
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2))
|
||||
#endif
|
||||
|
||||
#define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
|
||||
( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
|
||||
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
|
||||
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
|
||||
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
|
||||
)
|
||||
|
||||
#define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
|
||||
( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
|
||||
|| ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
|
||||
)
|
||||
|
||||
#define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__OUTPUT_BLANKING_SOURCE__) \
|
||||
( ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
|
||||
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5) \
|
||||
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3) \
|
||||
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3) \
|
||||
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4) \
|
||||
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5) \
|
||||
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup COMP_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup COMP_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-initialize registers of the selected COMP instance
|
||||
* to their default reset values.
|
||||
* @note If comparator is locked, de-initialization by software is
|
||||
* not possible.
|
||||
* The only way to unlock the comparator is a device hardware reset.
|
||||
* @param COMPx COMP instance
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: COMP registers are de-initialized
|
||||
* - ERROR: COMP registers are not de-initialized
|
||||
*/
|
||||
ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
|
||||
{
|
||||
ErrorStatus status = SUCCESS;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(COMPx));
|
||||
|
||||
/* Note: Hardware constraint (refer to description of this function): */
|
||||
/* COMP instance must not be locked. */
|
||||
if(LL_COMP_IsLocked(COMPx) == 0UL)
|
||||
{
|
||||
LL_COMP_WriteReg((COMPx), CFGR, 0x00000000UL);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Comparator instance is locked: de-initialization by software is */
|
||||
/* not possible. */
|
||||
/* The only way to unlock the comparator is a device hardware reset. */
|
||||
status = ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize some features of COMP instance.
|
||||
* @note This function configures features of the selected COMP instance.
|
||||
* Some features are also available at scope COMP common instance
|
||||
* (common to several COMP instances).
|
||||
* Refer to functions having argument "COMPxy_COMMON" as parameter.
|
||||
* @param COMPx COMP instance
|
||||
* @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: COMP registers are initialized
|
||||
* - ERROR: COMP registers are not initialized
|
||||
*/
|
||||
ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
|
||||
{
|
||||
ErrorStatus status = SUCCESS;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_COMP_ALL_INSTANCE(COMPx));
|
||||
assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
|
||||
assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
|
||||
assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
|
||||
assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
|
||||
assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
|
||||
assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMP_InitStruct->OutputBlankingSource));
|
||||
|
||||
/* Note: Hardware constraint (refer to description of this function) */
|
||||
/* COMP instance must not be locked. */
|
||||
if(LL_COMP_IsLocked(COMPx) == 0UL)
|
||||
{
|
||||
/* Configuration of comparator instance : */
|
||||
/* - PowerMode */
|
||||
/* - InputPlus */
|
||||
/* - InputMinus */
|
||||
/* - InputHysteresis */
|
||||
/* - OutputPolarity */
|
||||
/* - OutputBlankingSource */
|
||||
#if defined (COMP_CFGRx_INP2SEL)
|
||||
MODIFY_REG(COMPx->CFGR,
|
||||
COMP_CFGRx_PWRMODE
|
||||
| COMP_CFGRx_INPSEL
|
||||
| COMP_CFGRx_INP2SEL
|
||||
| COMP_CFGRx_SCALEN
|
||||
| COMP_CFGRx_BRGEN
|
||||
| COMP_CFGRx_INMSEL
|
||||
| COMP_CFGRx_HYST
|
||||
| COMP_CFGRx_POLARITY
|
||||
| COMP_CFGRx_BLANKING
|
||||
,
|
||||
COMP_InitStruct->PowerMode
|
||||
| COMP_InitStruct->InputPlus
|
||||
| COMP_InitStruct->InputMinus
|
||||
| COMP_InitStruct->InputHysteresis
|
||||
| COMP_InitStruct->OutputPolarity
|
||||
| COMP_InitStruct->OutputBlankingSource
|
||||
);
|
||||
#else
|
||||
MODIFY_REG(COMPx->CFGR,
|
||||
COMP_CFGRx_PWRMODE
|
||||
| COMP_CFGRx_INPSEL
|
||||
| COMP_CFGRx_SCALEN
|
||||
| COMP_CFGRx_BRGEN
|
||||
| COMP_CFGRx_INMSEL
|
||||
| COMP_CFGRx_HYST
|
||||
| COMP_CFGRx_POLARITY
|
||||
| COMP_CFGRx_BLANKING
|
||||
,
|
||||
COMP_InitStruct->PowerMode
|
||||
| COMP_InitStruct->InputPlus
|
||||
| COMP_InitStruct->InputMinus
|
||||
| COMP_InitStruct->InputHysteresis
|
||||
| COMP_InitStruct->OutputPolarity
|
||||
| COMP_InitStruct->OutputBlankingSource
|
||||
);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Initialization error: COMP instance is locked. */
|
||||
status = ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_COMP_InitTypeDef field to default value.
|
||||
* @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
|
||||
* whose fields will be set to default values.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
|
||||
{
|
||||
/* Set COMP_InitStruct fields to default values */
|
||||
COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER;
|
||||
COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
|
||||
COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
|
||||
COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
|
||||
COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
|
||||
COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* COMP1 || COMP2 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_ll_cordic.c
|
||||
* @author MCD Application Team
|
||||
* @brief CORDIC LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_ll_cordic.h"
|
||||
#include "stm32h7xx_ll_bus.h"
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/** @addtogroup STM32H7xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(CORDIC)
|
||||
|
||||
/** @addtogroup CORDIC_LL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup CORDIC_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CORDIC_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-Initialize CORDIC peripheral registers to their default reset values.
|
||||
* @param CORDICx CORDIC Instance
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: CORDIC registers are de-initialized
|
||||
* - ERROR: CORDIC registers are not de-initialized
|
||||
*/
|
||||
ErrorStatus LL_CORDIC_DeInit(const CORDIC_TypeDef *CORDICx)
|
||||
{
|
||||
ErrorStatus status = SUCCESS;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CORDIC_ALL_INSTANCE(CORDICx));
|
||||
|
||||
if (CORDICx == CORDIC)
|
||||
{
|
||||
/* Force CORDIC reset */
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_CORDIC);
|
||||
|
||||
/* Release CORDIC reset */
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_CORDIC);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* defined(CORDIC) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user