-
Main Changes
+
Main Changes
- First official release of HAL and LL drivers for
STM32H573xx / STM32H563xx / STM32H562xx / STM32H503xx
devices
-
Known Limitations
+
Known Limitations
-
Backward compatibility
+
Backward compatibility
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/SW_Security_Level.md b/system/Drivers/STM32H5xx_HAL_Driver/SW_Security_Level.md
new file mode 100644
index 0000000000..2a6286a448
--- /dev/null
+++ b/system/Drivers/STM32H5xx_HAL_Driver/SW_Security_Level.md
@@ -0,0 +1,47 @@
+
+
+## Copyright (c) 2026 STMicroelectronics.
+## All rights reserved
+
+
+
+## SW Security Classification
+
+[STM32Trust software security policies](https://wiki.st.com/stm32mcu/wiki/Security:STM32Trust_software_security_policies) define four levels of SW Security classification, each level defines a set of security policies for the applicable SW.
+
+| SW | SW Security Level
+|:--------- |:-------|
+| **STM32H5xx HAL Driver** | Medium|
+
+
+
+
+## IMPORTANT SECURITY NOTICE
+
+The STMicroelectronics group of companies (ST) places a high value on product security, which is why the ST product(s) identified in this documentation may be certified by various security certification bodies and/or may implement our own security measures as set forth herein. However, no level of security certification and/or built-in security measures can guarantee that ST products are resistant to all forms of attacks. As such, it is the responsibility of each of ST's customers to determine if the level of security provided in an ST product meets the customer needs both in relation to the ST product alone, as well as when combined with other components and/or software for the customer end product or application. In particular, take note that:
+
+- ST products may have been certified by one or more security certification bodies, such as Platform Security Architecture (www.psacertified.org) and/or Security Evaluation standard for IoT Platforms (www.trustcb.com). For details concerning whether the ST product(s) referenced herein have received security certification along with the level and current status of such certification, either visit the relevant certification standards website or go to the relevant product page on www.st.com for the most up to date information. As the status and/or level of security certification for an ST product can change from time to time, customers should re-check security certification status/level as needed. If an ST product is not shown to be certified under a particular security standard, customers should not assume it is certified.
+
+- Certification bodies have the right to evaluate, grant and revoke security certification in relation to ST products. These certification bodies are therefore independently responsible for granting or revoking security certification for an ST product, and ST does not take any responsibility for mistakes, evaluations, assessments, testing, or other activity carried out by the certification body with respect to any ST product.
+
+- Industry-based cryptographic algorithms (such as AES, DES, or MD5) and other open standard technologies which may be used in conjunction with an ST product are based on standards which were not developed by ST. ST does not take responsibility for any flaws in such cryptographic algorithms or open technologies or for any methods which have been or may be developed to bypass, decrypt or crack such algorithms or technologies.
+
+- While robust security testing may be done, no level of certification can absolutely guarantee protections against all attacks, including, for example, against advanced attacks which have not been tested for, against new or unidentified forms of attack, or against any form of attack when using an ST product outside of its specification or intended use, or in conjunction with other components or software which are used by customer to create their end product or application. ST is not responsible for resistance against such attacks. As such, regardless of the incorporated security features and/or any information or support that may be provided by ST, each customer is solely responsible for determining if the level of attacks tested for meets their needs, both in relation to the ST product alone and when incorporated into a customer end product or application.
+
+- All security features of ST products (inclusive of any hardware, software, documentation, and the like), including but not limited to any enhanced security features added by ST, are provided on an "AS IS" BASIS.
+
+AS SUCH, TO THE EXTENT PERMITTED BY APPLICABLE LAW, ST DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, unless the applicable written and signed contract terms specifically provide otherwise.
+
+
+
+## IMPORTANT NOTICE - READ CAREFULLY
+
+STMicroelectronics NV and its subsidiaries ("ST") reserve the right to make changes, corrections, enhancements, modifications, and improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST's terms and conditions of sale in place at the time of order acknowledgment.
+
+Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of purchasers' products.
+No license, express or implied, to any intellectual property right is granted by ST herein.
+Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
+ST and the ST logo are trademarks of ST. For additional information about ST trademarks, refer to www.st.com/trademarks. All other product or service names are the property of their respective owners.
+Information in this document supersedes and replaces information previously supplied in any prior versions of this document.
+
+Copyright (c) 2026 STMicroelectronics - All rights reserved
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c
index 13106e882d..19282b8864 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c
@@ -51,7 +51,7 @@
* @brief STM32H5xx HAL Driver version number 1.6.0
*/
#define __STM32H5XX_HAL_VERSION_MAIN (0x01UL) /*!< [31:24] main version */
-#define __STM32H5XX_HAL_VERSION_SUB1 (0x06UL) /*!< [23:16] sub1 version */
+#define __STM32H5XX_HAL_VERSION_SUB1 (0x07UL) /*!< [23:16] sub1 version */
#define __STM32H5XX_HAL_VERSION_SUB2 (0x00UL) /*!< [15:8] sub2 version */
#define __STM32H5XX_HAL_VERSION_RC (0x00UL) /*!< [7:0] release candidate */
#define __STM32H5XX_HAL_VERSION ((__STM32H5XX_HAL_VERSION_MAIN << 24U)\
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_ccb.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_ccb.c
index e166485381..300310f34b 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_ccb.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_ccb.c
@@ -93,7 +93,9 @@
#ifndef HAL_CCB_TIMEOUT_DEFAULT_VALUE
#define HAL_CCB_TIMEOUT_DEFAULT_VALUE 0xFFFFU /* CCB Timeout.*/
#endif /*HAL_CCB_TIMEOUT_DEFAULT_VALUE */
-
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+#define CCB_RNG_TIMEOUT_VALUE 0x00000002U
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/**
* @}
*/
@@ -118,12 +120,12 @@
/** @defgroup CCB_PKA_Mode CCB PKA mode
* @{
*/
-#define CCB_PKA_MODE_MODULAR_EXP_PROTECT (0x00000003U) /*!< PKA Modular exponentiation */
-#define CCB_PKA_ECC_MUL_MODE (0x00000020U) /*!< PKA ECC scalar multiplication */
-#define CCB_PKA_ECDSA_SIGNATURE_MODE (0x00000024U) /*!< PKA ECDSA signature */
-#define CCB_PKA_MODE_ECDSA_VERIFICATION (0x00000026U) /*!< PKA ECDSA verification */
-#define CCB_PKA_ERROR_OPERATION_NONE (0x0000D60DU) /*!< No PKA Hardware operation error */
-#define CCB_PKA_RAM_SIZE (0x00000536U) /*!< CCB PKA Ram Size */
+#define CCB_PKA_MODE_MODULAR_EXP_PROTECT (0x00000003UL) /*!< PKA Modular exponentiation */
+#define CCB_PKA_ECC_MUL_MODE (0x00000020UL) /*!< PKA ECC scalar multiplication */
+#define CCB_PKA_ECDSA_SIGNATURE_MODE (0x00000024UL) /*!< PKA ECDSA signature */
+#define CCB_PKA_MODE_ECDSA_VERIFICATION (0x00000026UL) /*!< PKA ECDSA verification */
+#define CCB_PKA_ERROR_OPERATION_NONE (0x0000D60DUL) /*!< No PKA Hardware operation error */
+#define CCB_PKA_RAM_SIZE (0x00000536UL) /*!< CCB PKA Ram Size */
/**
* @}
@@ -162,14 +164,37 @@
#define HAL_CCB_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->SR)\
& (__FLAG__)) == (__FLAG__)) ? SET : RESET)
-#define HAL_CCB_GET_SAES_FLAG(__FLAG__) (((__FLAG__)>1U) ? \
- (((SAES->SR & (__FLAG__)) == (__FLAG__)) ? SET : RESET) :\
- (((SAES->ISR & (__FLAG__)) == (__FLAG__)) ? SET : RESET) )
-
-#define HAL_CCB_GET_PKA_FLAG(__FLAG__) ((((PKA->SR)\
- & (__FLAG__)) == (__FLAG__)) ? SET : RESET)
-
-#define HAL_CCB_CLEAR_PKA_FLAG(__FLAG__) WRITE_REG(PKA->CLRFR, (__FLAG__))
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#define HAL_CCB_GET_SAES_INSTANCE(__HANDLE__) (((__HANDLE__)->Instance == CCB_S)?\
+ SAES_S : SAES_NS)
+#else
+#define HAL_CCB_GET_SAES_INSTANCE(__HANDLE__) SAES_NS
+#endif /* USE_HAL_SECURE_CHECK_PARAM */
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#define HAL_CCB_GET_PKA_INSTANCE(__HANDLE__) (((__HANDLE__)->Instance == CCB_S)?\
+ PKA_S : PKA_NS)
+#else
+#define HAL_CCB_GET_PKA_INSTANCE(__HANDLE__) PKA_NS
+#endif /* USE_HAL_SECURE_CHECK_PARAM */
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#define HAL_CCB_GET_RNG_INSTANCE(__HANDLE__) (((__HANDLE__)->Instance == CCB_S)?\
+ RNG_S : RNG_NS)
+#else
+#define HAL_CCB_GET_RNG_INSTANCE(__HANDLE__) RNG_NS
+#endif /* USE_HAL_SECURE_CHECK_PARAM */
+
+#define HAL_CCB_GET_SAES_FLAG(__HANDLE__,__FLAG__) (((__FLAG__)>1U) ? \
+ (((HAL_CCB_GET_SAES_INSTANCE(__HANDLE__)->SR\
+ & (__FLAG__)) == (__FLAG__)) ? SET : RESET) :\
+ (((HAL_CCB_GET_SAES_INSTANCE(__HANDLE__)->ISR\
+ & (__FLAG__)) == (__FLAG__)) ? SET : RESET) )
+
+#define HAL_CCB_GET_PKA_FLAG(__HANDLE__,__FLAG__) ((((HAL_CCB_GET_PKA_INSTANCE(__HANDLE__)->SR)\
+ & (__FLAG__)) == (__FLAG__)) ? SET : RESET)
+
+#define HAL_CCB_CLEAR_PKA_FLAG(__HANDLE__,__FLAG__) WRITE_REG(HAL_CCB_GET_PKA_INSTANCE(__HANDLE__)->CLRFR, (__FLAG__))
/**
* @}
@@ -183,8 +208,8 @@
static HAL_StatusTypeDef CCB_WaitOperStep(CCB_HandleTypeDef *hccb, uint32_t step, uint32_t Timeout);
static HAL_StatusTypeDef CCB_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t flag, uint32_t Timeout);
static HAL_StatusTypeDef Protect_PKA_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t flag, uint32_t Timeout);
-static HAL_StatusTypeDef Unprotect_PKA_WaitFLAG(uint32_t flag, uint32_t Timeout);
-static HAL_StatusTypeDef CCB_RNG_Wait_SET_FLAG(uint32_t flag, uint32_t Timeout);
+static HAL_StatusTypeDef Unprotect_PKA_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t flag, uint32_t Timeout);
+static HAL_StatusTypeDef CCB_RNG_Wait_SET_FLAG(CCB_HandleTypeDef *hccb, uint32_t flag, uint32_t Timeout);
static HAL_StatusTypeDef Protect_SAES_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t flag, FlagStatus Status,
uint32_t Timeout);
@@ -197,8 +222,8 @@ static HAL_StatusTypeDef CCB_SetPram(CCB_HandleTypeDef *hccb, uint32_t modulusSi
/* Initialization Private function */
static HAL_StatusTypeDef Protect_PKA_Init(CCB_HandleTypeDef *hccb, uint32_t Operation);
-static HAL_StatusTypeDef Unprotected_PKA_Init(void);
-static HAL_StatusTypeDef CCB_RNG_Init(void);
+static HAL_StatusTypeDef Unprotected_PKA_Init(CCB_HandleTypeDef *hccb);
+static HAL_StatusTypeDef CCB_RNG_Init(CCB_HandleTypeDef *hccb);
/* Wrapping Private function */
static HAL_StatusTypeDef WrappingKeyConfiguration(CCB_HandleTypeDef *hccb, uint32_t Operation,
@@ -225,15 +250,15 @@ static HAL_StatusTypeDef CCB_BlobCreation_FinalPhase(CCB_HandleTypeDef *hccb, ui
static HAL_StatusTypeDef CCB_BlobUse_FinalPhase(CCB_HandleTypeDef *hccb, uint32_t Operation, uint32_t sizeparam);
static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB_ECDSACurveParamTypeDef *pCurveParam,
const uint8_t *pClearPrivateKey,
- CCB_WrappingKeyTypeDef *pWrappingKey,
- uint32_t *pIV, uint32_t *pTag, uint32_t *pWarappedKey,
- uint8_t CCB_Operation);
+ CCB_WrappingKeyTypeDef *pWrappingKey, uint32_t *pIV,
+ uint32_t *pTag, uint32_t *pWarappedKey, uint8_t *pHash,
+ CCB_ECDSASignTypeDef *pSignature, uint8_t CCB_Operation);
static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
CCB_ECCMulCurveParamTypeDef *pCurveParam,
const uint8_t *pClearPrivateKey,
CCB_WrappingKeyTypeDef *pWrappingKey,
uint32_t *pIV, uint32_t *pTag, uint32_t *pWarappedKey,
- uint8_t CCB_Operation);
+ uint32_t PublicKey[2U][20U], uint8_t CCB_Operation);
static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_ECCMulCurveParamTypeDef *pCurveParam,
CCB_WrappingKeyTypeDef *pWrappingKey,
uint32_t *pIV, uint32_t *pTag, uint32_t *pWarappedKey,
@@ -244,27 +269,34 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RSAParamTypeDef *pParam,
const CCB_RSAClearKeyTypeDef *pRSAClearPrivateKey,
CCB_WrappingKeyTypeDef *pWrappingKey, uint32_t *pIV,
- uint32_t *pTag, uint32_t *pWrappedExp, uint32_t *pWrappedPhi);
+ uint32_t *pTag, uint32_t *pWrappedExp, uint32_t *pWrappedPhi,
+ uint8_t *pOperand, uint32_t *pReferenceModularExp);
static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_RSAParamTypeDef *pParam,
CCB_WrappingKeyTypeDef *pWrappingKey, uint32_t *pIV,
uint32_t *pTag, uint32_t *pWrappedExp, uint32_t *pWrappedPhi,
const uint8_t *pOperand, uint8_t *pModularExp,
const uint32_t *pReferenceModularExp, uint8_t VerifOperation);
-static HAL_StatusTypeDef PKA_ECDSASign(CCB_ECDSACurveParamTypeDef *pCurveParam,
+#if defined(SW_SANITY_CHECK_SUPPORT)
+static HAL_StatusTypeDef PKA_ECDSASign(CCB_HandleTypeDef *hccb, CCB_ECDSACurveParamTypeDef *pCurveParam,
const uint8_t *pClearPrivateKey, uint8_t *pInteger, uint8_t *pHash,
CCB_ECDSASignTypeDef *pSignature);
-static HAL_StatusTypeDef PKA_ECC_ComputeScalarMul(CCB_ECCMulCurveParamTypeDef *pCurveParam,
+static HAL_StatusTypeDef PKA_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_ECCMulCurveParamTypeDef *pCurveParam,
const uint8_t *pClearPrivateKey, uint32_t PublicKey[2][20]);
-static HAL_StatusTypeDef PKA_RSA_ComputeModularExp(CCB_RSAParamTypeDef *pParam,
+static HAL_StatusTypeDef PKA_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_RSAParamTypeDef *pParam,
const CCB_RSAClearKeyTypeDef *pRSAClearPrivateKey,
uint8_t *pOp1, uint32_t *pReferenceModularExp);
-static HAL_StatusTypeDef PKA_ECDSAVerif(CCB_ECDSACurveParamTypeDef *pCurveParam,
+static HAL_StatusTypeDef PKA_RAM_Erase(CCB_HandleTypeDef *hccb);
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
+static HAL_StatusTypeDef PKA_ECDSAVerif(CCB_HandleTypeDef *hccb, CCB_ECDSACurveParamTypeDef *pCurveParam,
CCB_ECCMulPointTypeDef *pPublicKeyOut, const uint8_t *pHash,
CCB_ECDSASignTypeDef *pSignature);
-static uint32_t PKA_ECDSAVerif_Result(void);
-static HAL_StatusTypeDef PKA_RAM_Erase(void);
-static void CCB_PKA_RAMReset(void);
+static uint32_t PKA_ECDSAVerif_Result(CCB_HandleTypeDef *hccb);
+static void CCB_PKA_RAMReset(CCB_HandleTypeDef *hccb);
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+HAL_StatusTypeDef CCB_RNG_ResilientRecoverSeedError(CCB_HandleTypeDef *hccb);
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
+
/** @defgroup CCB_Exported_Functions_Group1 Initialization/de-initialization functions
* @brief Initialization and Configuration functions
*
@@ -306,7 +338,7 @@ HAL_StatusTypeDef HAL_CCB_Init(CCB_HandleTypeDef *hccb)
HAL_CCB_MspInit(hccb);
/* PKA RAM RESET*/
- CCB_PKA_RAMReset();
+ CCB_PKA_RAMReset(hccb);
/* Update the CCB state */
hccb->State = HAL_CCB_STATE_READY;
@@ -527,7 +559,10 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
{
uint32_t count;
__IO uint16_t f_count;
+#if defined(SW_SANITY_CHECK_SUPPORT)
uint16_t random0 = 0;
+ uint8_t integer[80U] = {0};
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
uint16_t random1 = 0;
uint16_t random2 = 0;
uint16_t random3 = 0;
@@ -539,7 +574,6 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
uint8_t s_sign[80U] = {0};
uint8_t point_x[80U] = {0};
uint8_t point_y[80U] = {0};
- uint8_t integer[80U] = {0};
uint32_t iv_temp[4] = {0};
uint32_t tag_temp[4] = {0};
uint32_t wrapped_key_temp[80U] = {0};
@@ -547,7 +581,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
CCB_ECDSASignTypeDef signature = {r_sign, s_sign};
CCB_ECCMulPointTypeDef publicKeyOut = {(uint8_t *)point_x, (uint8_t *)point_y};
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -556,7 +590,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
for (count = 0U; count < (pCurveParam->primeOrderSizeByte); count++)
{
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -565,7 +599,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
while (hash[count] == 0U)
{
- hash[count] = (uint8_t)((RNG->DR) & 0x000000FFU);
+ hash[count] = (uint8_t)((HAL_CCB_GET_RNG_INSTANCE(hccb)->DR) & 0x000000FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -574,24 +608,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
- {
- return HAL_ERROR;
- }
-
- tickstart = HAL_GetTick();
-
- while (random0 == 0U)
- {
- random0 = (uint16_t)(RNG->DR & 0x3FFU);
- if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
- {
- /* Set state and return error */
- return HAL_ERROR;
- }
- }
-
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -600,7 +617,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
while (random1 == 0U)
{
- random1 = (uint16_t)(RNG->DR & 0x3FFU);
+ random1 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -608,7 +625,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -617,7 +634,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
while (random2 == 0U)
{
- random2 = (uint16_t)(RNG->DR & 0x3FFU);
+ random2 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -625,7 +642,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -634,21 +651,21 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
while (random3 == 0U)
{
- random3 = (uint16_t)(RNG->DR & 0x3FFU);
+ random3 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
return HAL_ERROR;
}
}
-
- for (count = 0U; count < (pCurveParam->primeOrderSizeByte); count++)
+ if (hccb->State == HAL_CCB_STATE_READY)
{
+#if defined(SW_SANITY_CHECK_SUPPORT)
tickstart = HAL_GetTick();
- while (integer[count] == 0U)
+ while (random0 == 0U)
{
- integer[count] = (uint8_t)((RNG->DR) & 0x000000FFU);
+ random0 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -656,26 +673,42 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
- }
- if (hccb->State == HAL_CCB_STATE_READY)
- {
+ for (count = 0U; count < (pCurveParam->primeOrderSizeByte); count++)
+ {
+ tickstart = HAL_GetTick();
+
+ while (integer[count] == 0U)
+ {
+ integer[count] = (uint8_t)((HAL_CCB_GET_RNG_INSTANCE(hccb)->DR) & 0x000000FFU);
+ if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
+ {
+ /* Set state and return error */
+ return HAL_ERROR;
+ }
+ }
- if (Unprotected_PKA_Init() != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+
+ if (Unprotected_PKA_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
- if (PKA_ECDSASign(pCurveParam, pClearPrivateKey, (uint8_t *)integer, (uint8_t *)hash,
+ if (PKA_ECDSASign(hccb, pCurveParam, pClearPrivateKey, (uint8_t *)integer, (uint8_t *)hash,
&signature) != HAL_OK)
{
- if (PKA_RAM_Erase() != HAL_OK)
+ if (PKA_RAM_Erase(hccb) != HAL_OK)
{
hccb->ErrorCode |= HAL_CCB_ERROR_PKARAM_ERASE;
}
@@ -690,7 +723,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
/* Signature blob creation */
if (CCB_ECDSA_SignBlobCreation(hccb, pCurveParam, pClearPrivateKey, pWrappingKey, iv_temp, tag_temp,
- wrapped_key_temp, CCB_ECDSA_SIGN_CPU_BLOB_CREATION) != HAL_OK)
+ wrapped_key_temp, NULL, NULL, CCB_ECDSA_SIGN_CPU_BLOB_CREATION) != HAL_OK)
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -701,9 +734,17 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
for (uint32_t index = 0U; index < CCB_PKA_RAM_SIZE; index++)
{
/* Clear the content */
- PKA->RAM[index] = 0UL;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[index] = 0UL;
+ }
+#elif defined (HW_SANITY_CHECK_SUPPORT)
+ /* Signature blob creation */
+ if (CCB_ECDSA_SignBlobCreation(hccb, pCurveParam, pClearPrivateKey, pWrappingKey, iv_temp, tag_temp,
+ wrapped_key_temp, hash, &signature, CCB_ECDSA_SIGN_CPU_BLOB_CREATION) != HAL_OK)
+ {
+ return HAL_ERROR;
}
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* Create ECDSA public key */
if (CCB_ECC_ComputeScalarMul(hccb, pCurveParam, pWrappingKey, iv_temp, tag_temp,
wrapped_key_temp, NULL, &publicKeyOut, NULL,
@@ -714,7 +755,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
HAL_CCB_IntrusionCallback(hccb);
}
- if (Unprotected_PKA_Init() != HAL_OK)
+ if (Unprotected_PKA_Init(hccb) != HAL_OK)
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -722,7 +763,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
/* PKA ECDSA valid R & S signature */
- if (PKA_ECDSAVerif(pCurveParam, &publicKeyOut, hash, &signature) != HAL_OK)
+ if (PKA_ECDSAVerif(hccb, pCurveParam, &publicKeyOut, hash, &signature) != HAL_OK)
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -736,7 +777,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
/* Check if it is valid signature and improve robustness against intrusion (intentional) */
- if ((PKA_ECDSAVerif_Result() != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random1) || (f_count == 0U))
+ if ((PKA_ECDSAVerif_Result(hccb) != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random1) || (f_count == 0U))
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -750,7 +791,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
/* Check if it is valid signature and improve robustness against intrusion (intentional) */
- if ((PKA_ECDSAVerif_Result() != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random2) || (f_count == 0U))
+ if ((PKA_ECDSAVerif_Result(hccb) != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random2) || (f_count == 0U))
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -764,7 +805,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECDS
}
/* Check if it is valid signature and improve robustness against intrusion (intentional) */
- if ((PKA_ECDSAVerif_Result() != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random3) || (f_count == 0U))
+ if ((PKA_ECDSAVerif_Result(hccb) != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random3) || (f_count == 0U))
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -812,23 +853,195 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_GenerateWrapPrivateKey(CCB_HandleTypeDef *hccb,
CCB_WrappingKeyTypeDef *pWrappingKey,
CCB_ECDSAKeyBlobTypeDef *pWrappedPrivateKeyBlob)
{
- uint32_t count;
+ uint32_t count;
uint32_t key_size;
uint32_t iv_temp[4] = {0};
uint32_t tag_temp[4] = {0};
uint32_t wrapped_key_temp[80U] = {0};
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ uint32_t tickstart;
+ __IO uint16_t f_count;
+ uint16_t random1 = 0;
+ uint16_t random2 = 0;
+ uint16_t random3 = 0;
+ uint8_t hash[80U] = {0};
+ uint8_t r_sign[80U] = {0};
+ uint8_t s_sign[80U] = {0};
+ uint8_t point_x[80U] = {0};
+ uint8_t point_y[80U] = {0};
+
+ CCB_ECDSASignTypeDef signature = {r_sign, s_sign};
+ CCB_ECCMulPointTypeDef public_key_out = {(uint8_t *)point_x, (uint8_t *)point_y};
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
+
if (hccb->State == HAL_CCB_STATE_READY)
{
+#if defined(SW_SANITY_CHECK_SUPPORT)
+ /* Signature blob creation */
+ if (CCB_ECDSA_SignBlobCreation(hccb, pCurveParam, NULL, pWrappingKey, iv_temp, tag_temp, wrapped_key_temp,
+ NULL, NULL, CCB_ECDSA_SIGN_RNG_BLOB_CREATION) != HAL_OK)
+ {
+ /* Set state, error code and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+#elif defined (HW_SANITY_CHECK_SUPPORT)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
+ {
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+
+ tickstart = HAL_GetTick();
+ while (random1 == 0U)
+ {
+ random1 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
+ if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
+ {
+ /* Set state and return error */
+ return HAL_ERROR;
+ }
+ }
+
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+
+ tickstart = HAL_GetTick();
+
+ while (random2 == 0U)
+ {
+ random2 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
+ if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
+ {
+ /* Set state and return error */
+ return HAL_ERROR;
+ }
+ }
+
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+
+ tickstart = HAL_GetTick();
+
+ while (random3 == 0U)
+ {
+ random3 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
+ if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
+ {
+ /* Set state and return error */
+ return HAL_ERROR;
+ }
+ }
+
+ for (count = 0U; count < (pCurveParam->primeOrderSizeByte); count++)
+ {
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+
+ tickstart = HAL_GetTick();
+
+ while (hash[count] == 0U)
+ {
+ hash[count] = (uint8_t)((HAL_CCB_GET_RNG_INSTANCE(hccb)->DR) & 0x000000FFU);
+ if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
+ {
+ /* Set state and return error */
+ return HAL_ERROR;
+ }
+ }
+ }
/* Signature blob creation */
if (CCB_ECDSA_SignBlobCreation(hccb, pCurveParam, NULL, pWrappingKey, iv_temp, tag_temp, wrapped_key_temp,
- CCB_ECDSA_SIGN_RNG_BLOB_CREATION) != HAL_OK)
+ (uint8_t *)hash,
+ &signature, CCB_ECDSA_SIGN_RNG_BLOB_CREATION) != HAL_OK)
+
{
/* Set state, error code and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
+
+ /* Reset each element in the PKA RAM */
+ for (uint32_t index = 0U; index < CCB_PKA_RAM_SIZE; index++)
+ {
+ /* Clear the content */
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[index] = 0UL;
+ }
+ /* Create ECDSA public key */
+ if (CCB_ECC_ComputeScalarMul(hccb, pCurveParam, pWrappingKey, iv_temp, tag_temp, wrapped_key_temp, NULL,
+ &public_key_out, NULL, CCB_COMPUTE_PUBLIC_KEY) != HAL_OK)
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+
+ if (Unprotected_PKA_Init(hccb) != HAL_OK)
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+
+ /* PKA ECDSA valid R & S signature */
+ if (PKA_ECDSAVerif(hccb, pCurveParam, &public_key_out, hash, &signature) != HAL_OK)
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+
+ f_count = 0;
+ while (f_count < random1)
+ {
+ f_count++;
+ }
+
+ /* Check if it is valid signature and improve robustness against intrusion (intentional) */
+ if ((PKA_ECDSAVerif_Result(hccb) != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random1) || (f_count == 0U))
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+
+ f_count = 0;
+ while (f_count < random2)
+ {
+ f_count++;
+ }
+
+ /* Check if it is valid signature and improve robustness against intrusion (intentional) */
+ if ((PKA_ECDSAVerif_Result(hccb) != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random2) || (f_count == 0U))
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+
+ f_count = 0;
+ while (f_count < random3)
+ {
+ f_count++;
+ }
+
+ /* Check if it is valid signature and improve robustness against intrusion (intentional) */
+ if ((PKA_ECDSAVerif_Result(hccb) != CCB_PKA_ECDSA_VERIF_OK) || (f_count != random3) || (f_count == 0U))
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
}
else
{
@@ -892,7 +1105,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
}
/* Initialize RNG */
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -910,12 +1123,22 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
/* Initialize SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* Disable the SAES peripheral */
- SAES->CR &= ~AES_CR_EN;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ /* Disable the SAES peripheral */
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
- /* Set state and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Update the state */
@@ -952,7 +1175,8 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
}
/* Set Hash message */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_HASH_E ], pHash, pCurveParam->modulusSizeByte);
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_HASH_E ], pHash,
+ pCurveParam->modulusSizeByte);
/* Initial Phase Processing */
if (CCB_BlobUse_InitialPhase(hccb, pWrappedPrivateKeyBlob->pIV, pWrappedPrivateKeyBlob->pTag) != HAL_OK)
@@ -976,7 +1200,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
}
/* Set SAES GCMPH Payload phase and trig OPSTEP that trig OPSTEP transition 0x13 --> 0x14 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x14 */
if (CCB_WaitOperStep(hccb, 0x14, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -988,7 +1212,8 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
/* Write encrypted Key*/
for (offset = 0UL; offset < cipherkey_size; offset++)
{
- WRITE_REG(SAES->DINR, pWrappedPrivateKeyBlob->pWrappedKey[cipherkey_size - (offset + 1UL)]);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR, \
+ pWrappedPrivateKeyBlob->pWrappedKey[cipherkey_size - (offset + 1UL)]);
if ((offset % 4UL) == 0x3UL)
{
@@ -1002,7 +1227,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
/* Write key in PKA RAM */
for (count = 0UL; count < 4UL; count++)
{
- PKA->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + count_block + count] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + count_block + count] = CCB_MAGIC_VALUE;
}
count_block += 4UL;
}
@@ -1010,7 +1235,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + cipherkey_size);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + cipherkey_size);
}
/* Wait until DATAOKF flag is SET in PKA and trig OPSTEP transition 0x14 --> 0x16 */
if (Protect_PKA_WaitFLAG(hccb, PKA_SR_DATAOKF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -1030,16 +1255,16 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
for (offset = 0UL; offset < (operand_size - 2UL); offset++)
{
/* Wait for RNG Data Ready flag */
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
/* return error */
return HAL_ERROR;
}
- PKA->RAM[PKA_ECDSA_SIGN_IN_K + offset] = CCB_FAKE_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_K + offset] = CCB_FAKE_VALUE;
}
/* Padding at zero */
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_K + offset);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_K + offset);
/* Wait for PKA RNGOK flag : GCMPH = 0x3 (final phase) as events that trig OPSTEP transition 0x16 --> 0x17 */
if (Protect_PKA_WaitFLAG(hccb, PKA_SR_RNGOKF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -1070,7 +1295,7 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
}
/* SET PKA START operation bit and trig OPSTEP transition 0x18 --> 0x19 */
- SET_BIT(PKA->CR, PKA_CR_START);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_START);
/* Wait until OPSTEP is set to 0x19 */
if (CCB_WaitOperStep(hccb, 0x19, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -1094,16 +1319,18 @@ HAL_StatusTypeDef HAL_CCB_ECDSA_Sign(CCB_HandleTypeDef *hccb, CCB_ECDSACurvePara
}
/* Check PKA Operation error result */
- if ((PKA->RAM[PKA_ECDSA_SIGN_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
+ if ((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
/* Read r part signature */
- CCB_Memcpy_u32_to_u8(pSignature->pRSign, &PKA->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_R], pCurveParam->modulusSizeByte);
+ CCB_Memcpy_u32_to_u8(pSignature->pRSign, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_R],
+ pCurveParam->modulusSizeByte);
/* Read s part signature */
- CCB_Memcpy_u32_to_u8(pSignature->pSSign, &PKA->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_S], pCurveParam->modulusSizeByte);
+ CCB_Memcpy_u32_to_u8(pSignature->pSSign, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_S],
+ pCurveParam->modulusSizeByte);
/* set CCB IPRST */
@@ -1183,43 +1410,45 @@ HAL_StatusTypeDef HAL_CCB_ECC_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECCMul
const uint8_t *pClearPrivateKey, CCB_WrappingKeyTypeDef *pWrappingKey,
CCB_ECCMulKeyBlobTypeDef *pWrappedPrivateKeyBlob)
{
+#if defined(SW_SANITY_CHECK_SUPPORT)
uint8_t random = 0;
- uint32_t public_key[2][20] = {{0UL}, {0UL}};
__IO uint8_t f_count;
+ uint32_t tickstart;
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
+ uint32_t public_key[2][20] = {{0UL}, {0UL}};
uint32_t count;
uint32_t key_size;
uint32_t iv_temp[4] = {0};
uint32_t tag_temp[4] = {0};
uint32_t wrapped_key_temp[80] = {0};
- uint32_t tickstart;
if (hccb->State == HAL_CCB_STATE_READY)
{
-
- if (Unprotected_PKA_Init() != HAL_OK)
+#if defined(SW_SANITY_CHECK_SUPPORT)
+ if (Unprotected_PKA_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
- if (PKA_ECC_ComputeScalarMul(pCurveParam, pClearPrivateKey, public_key) != HAL_OK)
+ if (PKA_ECC_ComputeScalarMul(hccb, pCurveParam, pClearPrivateKey, public_key) != HAL_OK)
{
- if (PKA_RAM_Erase() != HAL_OK)
+ if (PKA_RAM_Erase(hccb) != HAL_OK)
{
hccb->ErrorCode |= HAL_CCB_ERROR_PKARAM_ERASE;
}
return HAL_ERROR;
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -1228,7 +1457,7 @@ HAL_StatusTypeDef HAL_CCB_ECC_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECCMul
while (random == 0U)
{
- random = (uint8_t)(RNG->DR & 0xFFU);
+ random = (uint8_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0xFFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -1243,7 +1472,7 @@ HAL_StatusTypeDef HAL_CCB_ECC_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECCMul
}
if (CCB_ECC_ScalarMulBlobCreation(hccb, pCurveParam, pClearPrivateKey, pWrappingKey,
- iv_temp, tag_temp, wrapped_key_temp,
+ iv_temp, tag_temp, wrapped_key_temp, NULL,
CCB_ECC_SCALAR_MUL_CPU_BLOB_CREATION) != HAL_OK)
{
/* Set state, and intrusion error */
@@ -1251,6 +1480,16 @@ HAL_StatusTypeDef HAL_CCB_ECC_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_ECCMul
HAL_CCB_IntrusionCallback(hccb);
}
+#elif defined (HW_SANITY_CHECK_SUPPORT)
+ /* CCB ECC generate private wrap key */
+ if (CCB_ECC_ScalarMulBlobCreation(hccb, pCurveParam, pClearPrivateKey, pWrappingKey,
+ iv_temp, tag_temp, wrapped_key_temp, public_key,
+ CCB_ECC_SCALAR_MUL_CPU_BLOB_CREATION) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* Compute CCB public key */
if (CCB_ECC_ComputeScalarMul(hccb, pCurveParam, pWrappingKey, iv_temp, tag_temp, wrapped_key_temp, NULL,
NULL, &public_key[0][0], CCB_VERIF_OPERATION_ENABLED) != HAL_OK)
@@ -1303,17 +1542,43 @@ HAL_StatusTypeDef HAL_CCB_ECC_GenerateWrapPrivateKey(CCB_HandleTypeDef *hccb,
CCB_WrappingKeyTypeDef *pWrappingKey,
CCB_ECCMulKeyBlobTypeDef *pWrappedPrivateKeyBlob)
{
-
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ uint32_t PublicKey[2U][20U] = {0U};
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
+ uint32_t count;
+ uint32_t key_size;
+ uint32_t iv_temp[4] = {0};
+ uint32_t tag_temp[4] = {0};
+ uint32_t wrapped_key_temp[80] = {0};
if (hccb->State == HAL_CCB_STATE_READY)
{
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* CCB ECC generate private wrap key */
+ if (CCB_ECC_ScalarMulBlobCreation(hccb, pCurveParam, NULL, pWrappingKey,
+ iv_temp, tag_temp, wrapped_key_temp, PublicKey,
+ CCB_ECC_SCALAR_MUL_RNG_BLOB_CREATION) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+
+ /* Compute ECC public key */
+ if (CCB_ECC_ComputeScalarMul(hccb, pCurveParam, pWrappingKey, iv_temp, tag_temp, wrapped_key_temp,
+ NULL, NULL, &PublicKey[0][0], CCB_VERIF_OPERATION_ENABLED) != HAL_OK)
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+#elif defined(SW_SANITY_CHECK_SUPPORT)
+
/* CCB ECC generate private wrap key */
if (CCB_ECC_ScalarMulBlobCreation(hccb, pCurveParam, NULL, pWrappingKey,
- pWrappedPrivateKeyBlob->pIV, pWrappedPrivateKeyBlob->pTag,
- pWrappedPrivateKeyBlob->pWrappedKey,
+ iv_temp, tag_temp, wrapped_key_temp, NULL,
CCB_ECC_SCALAR_MUL_RNG_BLOB_CREATION) != HAL_OK)
{
return HAL_ERROR;
}
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
}
else
{
@@ -1325,6 +1590,17 @@ HAL_StatusTypeDef HAL_CCB_ECC_GenerateWrapPrivateKey(CCB_HandleTypeDef *hccb,
/* Update the CCB state */
hccb->State = HAL_CCB_STATE_READY;
+ /* Export created Blob */
+ key_size = CCB_get_cipherkey_size(pCurveParam);
+ for (count = 0U; count < key_size; count++)
+ {
+ if (count < CCB_BLOCK_SIZE)
+ {
+ pWrappedPrivateKeyBlob->pIV[count] = iv_temp[count];
+ pWrappedPrivateKeyBlob->pTag[count] = tag_temp[count];
+ }
+ pWrappedPrivateKeyBlob->pWrappedKey[count] = wrapped_key_temp[count];
+ }
/* Return HAL OK */
return HAL_OK;
@@ -1384,8 +1660,10 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
{
uint8_t exp_base[520U] = {0};
uint32_t count;
+#if defined(SW_SANITY_CHECK_SUPPORT)
__IO uint16_t f_count;
uint16_t random0 = 0;
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
uint32_t modular_exp_ref[520U] = {0};
uint32_t operand_size;
uint32_t cipherkey_size;
@@ -1397,7 +1675,7 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
if (hccb->State == HAL_CCB_STATE_READY)
{
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1406,7 +1684,7 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
for (uint32_t offset = 0U; offset < pParam->modulusSizeByte; offset++)
{
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -1415,7 +1693,7 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
while (exp_base[offset] == 0U)
{
- exp_base[offset] = (uint8_t)(RNG->DR & 0xFFU);
+ exp_base[offset] = (uint8_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0xFFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -1424,7 +1702,8 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+#if defined(SW_SANITY_CHECK_SUPPORT)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -1433,7 +1712,7 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
while (random0 == 0U)
{
- random0 = (uint16_t)(RNG->DR & 0x3FFU);
+ random0 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -1441,30 +1720,23 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
}
}
- if (Unprotected_PKA_Init() != HAL_OK)
+ if (Unprotected_PKA_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
- if (PKA_RSA_ComputeModularExp(pParam, pRSAClearPrivateKey, (uint8_t *)exp_base, modular_exp_ref) != HAL_OK)
+ if (PKA_RSA_ComputeModularExp(hccb, pParam, pRSAClearPrivateKey, (uint8_t *)exp_base, modular_exp_ref) != HAL_OK)
{
- if (PKA_RAM_Erase() != HAL_OK)
+ if (PKA_RAM_Erase(hccb) != HAL_OK)
{
hccb->ErrorCode |= HAL_CCB_ERROR_PKARAM_ERASE;
}
return HAL_ERROR;
}
- if (CCB_RNG_Init() != HAL_OK)
- {
- /* Set state and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
- }
-
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -1476,12 +1748,21 @@ HAL_StatusTypeDef HAL_CCB_RSA_WrapPrivateKey(CCB_HandleTypeDef *hccb, CCB_RSAPar
}
if (CCB_RSA_ExpBlobCreation(hccb, pParam, pRSAClearPrivateKey, pWrappingKey, iv_temp, tag_temp, wrapped_exp,
- wrapped_phi) != HAL_OK)
+ wrapped_phi, NULL, NULL) != HAL_OK)
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
HAL_CCB_IntrusionCallback(hccb);
}
+#elif defined (HW_SANITY_CHECK_SUPPORT)
+ if (CCB_RSA_ExpBlobCreation(hccb, pParam, pRSAClearPrivateKey, pWrappingKey, iv_temp, tag_temp, wrapped_exp,
+ wrapped_phi, (uint8_t *)exp_base, modular_exp_ref) != HAL_OK)
+ {
+ /* Set state, and intrusion error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ HAL_CCB_IntrusionCallback(hccb);
+ }
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
if (CCB_RSA_ComputeModularExp(hccb, pParam, pWrappingKey, iv_temp, tag_temp, wrapped_exp, wrapped_phi,
(uint8_t *)exp_base, NULL, modular_exp_ref,
@@ -1662,11 +1943,11 @@ static HAL_StatusTypeDef Protect_PKA_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t
{
uint32_t tickstart = HAL_GetTick();
- while (HAL_IS_BIT_CLR(PKA->SR, flag))
+ while (HAL_IS_BIT_CLR(HAL_CCB_GET_PKA_INSTANCE(hccb)->SR, flag))
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
- CLEAR_BIT(PKA->CR, PKA_CR_EN);
+ CLEAR_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1675,7 +1956,7 @@ static HAL_StatusTypeDef Protect_PKA_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t
}
/* Clear flag */
- SET_BIT(PKA->CLRFR, flag);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR, flag);
/* Return function status */
return HAL_OK;
@@ -1683,19 +1964,20 @@ static HAL_StatusTypeDef Protect_PKA_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t
/**
* @brief Wait PKA Flag
+ * @param hccb CCB handle
* @param flag Specifies the flag to check
* @param Timeout Timeout duration
* @retval HAL status.
*/
-static HAL_StatusTypeDef Unprotect_PKA_WaitFLAG(uint32_t flag, uint32_t Timeout)
+static HAL_StatusTypeDef Unprotect_PKA_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t flag, uint32_t Timeout)
{
uint32_t tickstart = HAL_GetTick();
- while (HAL_IS_BIT_CLR(PKA->SR, flag))
+ while (HAL_IS_BIT_CLR(HAL_CCB_GET_PKA_INSTANCE(hccb)->SR, flag))
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
- CLEAR_BIT(PKA->CR, PKA_CR_EN);
+ CLEAR_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
/* return error */
return HAL_ERROR;
@@ -1703,7 +1985,7 @@ static HAL_StatusTypeDef Unprotect_PKA_WaitFLAG(uint32_t flag, uint32_t Timeout)
}
/* Clear flag */
- SET_BIT(PKA->CLRFR, flag);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR, flag);
/* Return function status */
return HAL_OK;
@@ -1711,19 +1993,20 @@ static HAL_StatusTypeDef Unprotect_PKA_WaitFLAG(uint32_t flag, uint32_t Timeout)
/**
* @brief Wait RNG Flag
+ * @param hccb CCB handle
* @param flag Specifies the flag to check
* @param Timeout Timeout duration
* @retval HAL status
*/
-static HAL_StatusTypeDef CCB_RNG_Wait_SET_FLAG(uint32_t flag, uint32_t Timeout)
+static HAL_StatusTypeDef CCB_RNG_Wait_SET_FLAG(CCB_HandleTypeDef *hccb, uint32_t flag, uint32_t Timeout)
{
uint32_t tickstart = HAL_GetTick();
- while (HAL_IS_BIT_CLR(RNG->SR, flag))
+ while (HAL_IS_BIT_CLR(HAL_CCB_GET_RNG_INSTANCE(hccb)->SR, flag))
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
- RNG->CR &= ~RNG_CR_RNGEN;
+ HAL_CCB_GET_RNG_INSTANCE(hccb)->CR &= ~RNG_CR_RNGEN;
/* Set state and return error */
return HAL_ERROR;
@@ -1747,11 +2030,11 @@ static HAL_StatusTypeDef Protect_SAES_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t
{
uint32_t tickstart = HAL_GetTick();
- while (HAL_CCB_GET_SAES_FLAG(flag) != Status)
+ while (HAL_CCB_GET_SAES_FLAG(hccb, flag) != Status)
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
- SAES->CR &= ~AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1760,7 +2043,7 @@ static HAL_StatusTypeDef Protect_SAES_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t
}
/* Clear flag */
- SET_BIT(SAES->ICR, flag);
+ SET_BIT(HAL_CCB_GET_SAES_INSTANCE(hccb)->ICR, flag);
/* Return function status */
@@ -1776,9 +2059,9 @@ static HAL_StatusTypeDef Protect_SAES_WaitFLAG(CCB_HandleTypeDef *hccb, uint32_t
static HAL_StatusTypeDef CCB_ECDSASign_SetPram(CCB_HandleTypeDef *hccb, CCB_ECDSACurveParamTypeDef *in)
{
/* Get the prime order n length */
- PKA->RAM[PKA_ECDSA_SIGN_IN_ORDER_NB_BITS]
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_ORDER_NB_BITS]
= GetOptBitSize_u8(in->primeOrderSizeByte, *(in->pPrimeOrder));
- PKA->RAM[PKA_ECDSA_SIGN_IN_ORDER_NB_BITS + 1U] = 0x0U;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_ORDER_NB_BITS + 1U] = 0x0U;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1786,8 +2069,9 @@ static HAL_StatusTypeDef CCB_ECDSASign_SetPram(CCB_HandleTypeDef *hccb, CCB_ECDS
}
/* Get the modulus p length */
- PKA->RAM[PKA_ECDSA_SIGN_IN_MOD_NB_BITS] = GetOptBitSize_u8(in->modulusSizeByte, *(in->pModulus));
- PKA->RAM[PKA_ECDSA_SIGN_IN_MOD_NB_BITS + 1U] = 0x0U;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_MOD_NB_BITS] = GetOptBitSize_u8(in->modulusSizeByte,
+ *(in->pModulus));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_MOD_NB_BITS + 1U] = 0x0U;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1795,8 +2079,8 @@ static HAL_StatusTypeDef CCB_ECDSASign_SetPram(CCB_HandleTypeDef *hccb, CCB_ECDS
}
/* Get the coefficient a sign */
- PKA->RAM[PKA_ECDSA_SIGN_IN_A_COEFF_SIGN] = in->coefSignA;
- PKA->RAM[PKA_ECDSA_SIGN_IN_A_COEFF_SIGN + 1U] = 0x0;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_A_COEFF_SIGN] = in->coefSignA;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_A_COEFF_SIGN + 1U] = 0x0;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1852,9 +2136,9 @@ static HAL_StatusTypeDef CCB_ECDSASign_SetPram(CCB_HandleTypeDef *hccb, CCB_ECDS
static HAL_StatusTypeDef CCB_ECCMul_SetPram(CCB_HandleTypeDef *hccb, CCB_ECCMulCurveParamTypeDef *in)
{
/* Get the prime order n length */
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_EXP_NB_BITS]
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_EXP_NB_BITS]
= GetOptBitSize_u8(in->primeOrderSizeByte, *(in->pPrimeOrder));
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_EXP_NB_BITS + 1U] = 0x0;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_EXP_NB_BITS + 1U] = 0x0;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1862,8 +2146,9 @@ static HAL_StatusTypeDef CCB_ECCMul_SetPram(CCB_HandleTypeDef *hccb, CCB_ECCMulC
}
/* Get the modulus p length */
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_OP_NB_BITS] = GetOptBitSize_u8(in->modulusSizeByte, *(in->pModulus));
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_OP_NB_BITS + 1U] = 0x0;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_OP_NB_BITS] = GetOptBitSize_u8(in->modulusSizeByte,
+ *(in->pModulus));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_OP_NB_BITS + 1U] = 0x0;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1871,8 +2156,8 @@ static HAL_StatusTypeDef CCB_ECCMul_SetPram(CCB_HandleTypeDef *hccb, CCB_ECCMulC
}
/* Get the coefficient a sign */
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF_SIGN] = in->coefSignA;
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF_SIGN + 1U] = 0x0;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF_SIGN] = in->coefSignA;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF_SIGN + 1U] = 0x0;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1916,8 +2201,9 @@ static HAL_StatusTypeDef CCB_ECCMul_SetPram(CCB_HandleTypeDef *hccb, CCB_ECCMulC
static HAL_StatusTypeDef CCB_RSAModExp_SetPram(CCB_HandleTypeDef *hccb, CCB_RSAParamTypeDef *in)
{
/* Get the exp length */
- PKA->RAM[PKA_MODULAR_EXP_IN_EXP_NB_BITS] = GetOptBitSize_u8(in->expSizeByte, *(in->pMod));
- PKA->RAM[PKA_MODULAR_EXP_IN_EXP_NB_BITS + 1U] = 0x0U;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_IN_EXP_NB_BITS] = GetOptBitSize_u8(in->expSizeByte,
+ *(in->pMod));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_IN_EXP_NB_BITS + 1U] = 0x0U;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1925,8 +2211,9 @@ static HAL_StatusTypeDef CCB_RSAModExp_SetPram(CCB_HandleTypeDef *hccb, CCB_RSAP
}
/* Get the modulus n length */
- PKA->RAM[PKA_MODULAR_EXP_IN_OP_NB_BITS] = GetOptBitSize_u8(in->modulusSizeByte, *(in->pMod));
- PKA->RAM[PKA_MODULAR_EXP_IN_OP_NB_BITS + 1U] = 0x0U;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_IN_OP_NB_BITS] = GetOptBitSize_u8(in->modulusSizeByte,
+ *(in->pMod));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_IN_OP_NB_BITS + 1U] = 0x0U;
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1962,7 +2249,7 @@ static HAL_StatusTypeDef CCB_SetPram(CCB_HandleTypeDef *hccb, uint32_t modulusSi
{
for (offset = 0; offset < (operand_size - 4UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[dst_address + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[dst_address + offset],
&src[(modulusSizeByte) - ((offset * 4UL) + 1UL)]);
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
@@ -1971,7 +2258,7 @@ static HAL_StatusTypeDef CCB_SetPram(CCB_HandleTypeDef *hccb, uint32_t modulusSi
}
}
- CCB_Memcpy_Not_Align(&PKA->RAM[dst_address + offset],
+ CCB_Memcpy_Not_Align(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[dst_address + offset],
&src[(modulusSizeByte) - ((offset * 4UL) + 1UL)], modulusSizeByte % 8UL);
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -1979,7 +2266,7 @@ static HAL_StatusTypeDef CCB_SetPram(CCB_HandleTypeDef *hccb, uint32_t modulusSi
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
- RAM_PARAM_END(PKA->RAM, dst_address + ((modulusSizeByte + 7UL) / 4UL));
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, dst_address + ((modulusSizeByte + 7UL) / 4UL));
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
hccb->State = HAL_CCB_STATE_ERROR;
@@ -1991,7 +2278,7 @@ static HAL_StatusTypeDef CCB_SetPram(CCB_HandleTypeDef *hccb, uint32_t modulusSi
{
for (offset = 0; offset < (operand_size - 2UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[dst_address + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[dst_address + offset],
&src[(modulusSizeByte) - ((offset * 4UL) + 1UL)]);
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
@@ -2000,7 +2287,7 @@ static HAL_StatusTypeDef CCB_SetPram(CCB_HandleTypeDef *hccb, uint32_t modulusSi
}
}
- RAM_PARAM_END(PKA->RAM, dst_address
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, dst_address
+ ((modulusSizeByte + 3UL) / 4UL));
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
@@ -2022,23 +2309,34 @@ static HAL_StatusTypeDef CCB_SetPram(CCB_HandleTypeDef *hccb, uint32_t modulusSi
static HAL_StatusTypeDef Protect_PKA_Init(CCB_HandleTypeDef *hccb, uint32_t Operation)
{
/* Reset the control register and enable the PKA */
- PKA->CR = PKA_CR_EN;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CR = PKA_CR_EN;
/* Wait the INITOK flag Setting */
if (Protect_PKA_WaitFLAG(hccb, PKA_SR_INITOK, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- return HAL_ERROR;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Reset any pending flag */
- SET_BIT(PKA->CLRFR, PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR,
+ PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
/* Set the mode and deactivate the interrupts */
if ((Operation == CCB_ECDSA_SIGN_CPU_BLOB_CREATION)
|| (Operation == CCB_ECDSA_SIGN_RNG_BLOB_CREATION)
|| (Operation == CCB_ECDSA_SIGN_BLOB_USE))
{
- MODIFY_REG(PKA->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE
+ MODIFY_REG(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE
| PKA_CR_OPERRIE, CCB_PKA_ECDSA_SIGNATURE_MODE << PKA_CR_MODE_Pos);
}
@@ -2046,14 +2344,14 @@ static HAL_StatusTypeDef Protect_PKA_Init(CCB_HandleTypeDef *hccb, uint32_t Oper
|| (Operation == CCB_ECC_SCALAR_MUL_RNG_BLOB_CREATION)
|| (Operation == CCB_ECC_SCALAR_MUL_BLOB_USE))
{
- MODIFY_REG(PKA->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE
+ MODIFY_REG(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE
| PKA_CR_OPERRIE, CCB_PKA_ECC_MUL_MODE << PKA_CR_MODE_Pos);
}
else if ((Operation == CCB_MODULAR_EXP_CPU_BLOB_CREATION)
|| (Operation == CCB_MODULAR_EXP_BLOB_USE))
{
- MODIFY_REG(PKA->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE
+ MODIFY_REG(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE
| PKA_CR_OPERRIE, CCB_PKA_MODE_MODULAR_EXP_PROTECT << PKA_CR_MODE_Pos);
}
else
@@ -2067,16 +2365,17 @@ static HAL_StatusTypeDef Protect_PKA_Init(CCB_HandleTypeDef *hccb, uint32_t Oper
/**
* @brief Unprotected PKA Initialization
+ * @param hccb CCB handle
* @retval HAL status.
*/
-static HAL_StatusTypeDef Unprotected_PKA_Init(void)
+static HAL_StatusTypeDef Unprotected_PKA_Init(CCB_HandleTypeDef *hccb)
{
uint32_t tickstart = HAL_GetTick();
/* Reset the control register and enable the PKA (wait the end of PKA RAM erase) */
- while ((PKA->CR & PKA_CR_EN) != PKA_CR_EN)
+ while ((HAL_CCB_GET_PKA_INSTANCE(hccb)->CR & PKA_CR_EN) != PKA_CR_EN)
{
- PKA->CR = PKA_CR_EN;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CR = PKA_CR_EN;
/* Check the Timeout */
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
@@ -2086,55 +2385,67 @@ static HAL_StatusTypeDef Unprotected_PKA_Init(void)
}
}
/* Wait the INITOK flag Setting */
- if (Unprotect_PKA_WaitFLAG(PKA_SR_INITOK, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (Unprotect_PKA_WaitFLAG(hccb, PKA_SR_INITOK, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- return HAL_ERROR;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Reset any pending flag */
- SET_BIT(PKA->CLRFR, PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR,
+ PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
return HAL_OK;
}
/**
* @brief Initialize the RNG
+ * @param hccb CCB handle
* @retval HAL status
*/
-static HAL_StatusTypeDef CCB_RNG_Init(void)
+static HAL_StatusTypeDef CCB_RNG_Init(CCB_HandleTypeDef *hccb)
{
uint32_t tickstart;
/* Disable RNG */
- RNG->CR &= ~RNG_CR_RNGEN;
+ HAL_CCB_GET_RNG_INSTANCE(hccb)->CR &= ~RNG_CR_RNGEN;
/* Clock Error Detection Configuration when CONDRT bit is set to 1 */
- MODIFY_REG(RNG->CR, RNG_CR_CONDRST, RNG_CR_CONDRST);
+ MODIFY_REG(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR, RNG_CR_CONDRST, RNG_CR_CONDRST);
#if defined(RNG_CR_NIST_VALUE)
/* Recommended value for NIST compliance, refer to application note AN4230 */
- WRITE_REG(RNG->CR, RNG_CR_NIST_VALUE | RNG_CR_CONDRST);
+ WRITE_REG(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR, RNG_CR_NIST_VALUE | RNG_CR_CONDRST);
#endif /* defined(RNG_CR_NIST_VALUE) */
#if defined(RNG_HTCR_NIST_VALUE)
/* Recommended value for NIST compliance, refer to application note AN4230 */
- WRITE_REG(RNG->HTCR, RNG_HTCR_NIST_VALUE);
+ WRITE_REG(HAL_CCB_GET_RNG_INSTANCE(hccb)->HTCR[0], RNG_HTCR_NIST_VALUE);
#endif /* defined(RNG_HTCR_NIST_VALUE) */
#if defined(RNG_NSCR_NIST_VALUE)
- WRITE_REG(RNG->NSCR, RNG_NSCR_NIST_VALUE);
+ WRITE_REG(HAL_CCB_GET_RNG_INSTANCE(hccb)->NSCR, RNG_NSCR_NIST_VALUE);
#endif /* defined(RNG_NSCR_NIST_VALUE) */
/* Writing bit CONDRST=0 */
- CLEAR_BIT(RNG->CR, RNG_CR_CONDRST);
+ CLEAR_BIT(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR, RNG_CR_CONDRST);
/* Get tick */
tickstart = HAL_GetTick();
/* Wait for conditioning reset process to be completed */
- while (HAL_IS_BIT_SET(RNG->CR, RNG_CR_CONDRST))
+ while (HAL_IS_BIT_SET(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR, RNG_CR_CONDRST))
{
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* New check to avoid false timeout detection in case of preemption */
- if (HAL_IS_BIT_SET(RNG->CR, RNG_CR_CONDRST))
+ if (HAL_IS_BIT_SET(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR, RNG_CR_CONDRST))
{
/* Set state and return error */
return HAL_ERROR;
@@ -2143,19 +2454,32 @@ static HAL_StatusTypeDef CCB_RNG_Init(void)
}
/* Enable the RNG Peripheral */
- RNG->CR |= RNG_CR_RNGEN;
+ HAL_CCB_GET_RNG_INSTANCE(hccb)->CR |= RNG_CR_RNGEN;
- /* verify that no seed error */
- if ((RNG->SR & (RNG_SR_SEIS)) != (uint32_t)RESET)
- {
- /* Set state and return error */
- return HAL_ERROR;
- }
+ tickstart = HAL_GetTick();
/* Check if data register contains valid random data */
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ while (HAL_IS_BIT_CLR(HAL_CCB_GET_RNG_INSTANCE(hccb)->SR, RNG_SR_DRDY))
{
- return HAL_ERROR;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
+
+ if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
+ {
+ HAL_CCB_GET_RNG_INSTANCE(hccb)->CR &= ~RNG_CR_RNGEN;
+
+ /* Set state and return error */
+ return HAL_ERROR;
+ }
}
/* Return function status */
@@ -2189,14 +2513,15 @@ static HAL_StatusTypeDef WrappingKeyConfiguration(CCB_HandleTypeDef *hccb, uint3
|| (Operation == CCB_MODULAR_EXP_CPU_BLOB_CREATION))
{
/* SAES: GCMPH = 0x0 (initial phase) as event that trig OPSTEP 0x1 --> 0x2 */
- WRITE_REG(SAES->CR, AES_CR_KEYSIZE | AES_CR_CHMOD_0 | AES_CR_CHMOD_1);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSIZE
+ | AES_CR_CHMOD_0 | AES_CR_CHMOD_1);
}
else if ((Operation == CCB_ECDSA_SIGN_BLOB_USE) || (Operation == CCB_ECC_SCALAR_MUL_BLOB_USE)
|| (Operation == CCB_MODULAR_EXP_BLOB_USE))
{
/* SAES: GCMPH = 0x0 (initial phase) as event that trig OPSTEP 0x1 --> 0x12 */
- WRITE_REG(SAES->CR, AES_CR_KEYSIZE | AES_CR_CHMOD_0
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSIZE | AES_CR_CHMOD_0
| AES_CR_CHMOD_1 | AES_CR_MODE_1);
}
@@ -2214,16 +2539,16 @@ static HAL_StatusTypeDef WrappingKeyConfiguration(CCB_HandleTypeDef *hccb, uint3
|| (Operation == CCB_MODULAR_EXP_CPU_BLOB_CREATION))
{
/* SAES: GCMPH = 0x0 (initial phase) as event that trig OPSTEP 0x1 --> 0x2 */
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE | AES_CR_CHMOD_0
- | AES_CR_CHMOD_1);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE
+ | AES_CR_CHMOD_0 | AES_CR_CHMOD_1);
}
else if ((Operation == CCB_ECDSA_SIGN_BLOB_USE) || (Operation == CCB_ECC_SCALAR_MUL_BLOB_USE)
|| (Operation == CCB_MODULAR_EXP_BLOB_USE))
{
/* SAES: GCMPH = 0x0 (initial phase) as event that trig OPSTEP 0x1 --> 0x12 */
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE | AES_CR_CHMOD_0
- | AES_CR_CHMOD_1 | AES_CR_MODE_1);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE
+ | AES_CR_CHMOD_0 | AES_CR_CHMOD_1 | AES_CR_MODE_1);
}
else
@@ -2251,16 +2576,16 @@ static HAL_StatusTypeDef WrappingKeyConfiguration(CCB_HandleTypeDef *hccb, uint3
|| (Operation == CCB_MODULAR_EXP_CPU_BLOB_CREATION))
{
/* SAES: GCMPH = 0x0 (initial phase) as event that trig OPSTEP 0x1 --> 0x2 */
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE | AES_CR_CHMOD_0
- | AES_CR_CHMOD_1);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE
+ | AES_CR_CHMOD_0 | AES_CR_CHMOD_1);
}
else if ((Operation == CCB_ECDSA_SIGN_BLOB_USE) || (Operation == CCB_ECC_SCALAR_MUL_BLOB_USE)
|| (Operation == CCB_MODULAR_EXP_BLOB_USE))
{
/* SAES: GCMPH = 0x0 (initial phase) as event that trig OPSTEP 0x1 --> 0x12 */
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE | AES_CR_CHMOD_0 |
- AES_CR_CHMOD_1 | AES_CR_MODE_1);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0 | AES_CR_KEYSIZE
+ | AES_CR_CHMOD_0 | AES_CR_CHMOD_1 | AES_CR_MODE_1);
}
else
@@ -2322,11 +2647,13 @@ static HAL_StatusTypeDef Protect_SAES_UnwrapKey(CCB_HandleTypeDef *hccb, const C
if (pWrappingKey->AES_Algorithm != CCB_AES_ECB)
{
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KMOD_0 | AES_CR_KEYSIZE | AES_CR_CHMOD_0);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0 | AES_CR_KMOD_0
+ | AES_CR_KEYSIZE | AES_CR_CHMOD_0);
}
else
{
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KMOD_0 | AES_CR_KEYSIZE);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0
+ | AES_CR_KMOD_0 | AES_CR_KEYSIZE);
}
/* Wait for Key valid to be set */
@@ -2336,14 +2663,14 @@ static HAL_StatusTypeDef Protect_SAES_UnwrapKey(CCB_HandleTypeDef *hccb, const C
}
/* Disable the SAES peripheral */
- SAES->CR &= ~AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
/* wait for key valid */
- while (HAL_IS_BIT_CLR(SAES->SR, AES_SR_KEYVALID))
+ while (HAL_IS_BIT_CLR(HAL_CCB_GET_SAES_INSTANCE(hccb)->SR, AES_SR_KEYVALID))
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
- SAES->CR &= ~AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -2352,13 +2679,13 @@ static HAL_StatusTypeDef Protect_SAES_UnwrapKey(CCB_HandleTypeDef *hccb, const C
}
/* Set the operating mode*/
- MODIFY_REG(SAES->CR, AES_CR_KMOD, AES_CR_KMOD_0);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KMOD, AES_CR_KMOD_0);
/* key preparation for decryption, operating mode 2*/
- MODIFY_REG(SAES->CR, AES_CR_MODE, AES_CR_MODE_0);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_MODE, AES_CR_MODE_0);
/* Enable SAES */
- SAES->CR |= AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR |= AES_CR_EN;
/* wait CCF in SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -2367,30 +2694,30 @@ static HAL_StatusTypeDef Protect_SAES_UnwrapKey(CCB_HandleTypeDef *hccb, const C
}
/* Return to decryption operating mode(Mode 3)*/
- MODIFY_REG(SAES->CR, AES_CR_MODE, AES_CR_MODE_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_MODE, AES_CR_MODE_1);
if (pWrappingKey->AES_Algorithm != CCB_AES_ECB)
{
/* Set the Initialization Vector */
- SAES->IVR3 = *(uint32_t *)(pWrappingKey->pInitVect);
- SAES->IVR2 = *(uint32_t *)(pWrappingKey->pInitVect + 1U);
- SAES->IVR1 = *(uint32_t *)(pWrappingKey->pInitVect + 2U);
- SAES->IVR0 = *(uint32_t *)(pWrappingKey->pInitVect + 3U);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR3 = *(uint32_t *)(pWrappingKey->pInitVect);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR2 = *(uint32_t *)(pWrappingKey->pInitVect + 1U);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR1 = *(uint32_t *)(pWrappingKey->pInitVect + 2U);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR0 = *(uint32_t *)(pWrappingKey->pInitVect + 3U);
}
/* Enable CRYP */
- SAES->CR |= AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR |= AES_CR_EN;
/* Set the phase */
while (in_count < 8UL) /* symmetric key size is always 256 */
{
/* Write four times to input the key to encrypt */
- SAES->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
in_count++;
- SAES->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
in_count++;
- SAES->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
in_count++;
- SAES->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR = pWrappingKey->pUserWrappedWrappingKey[in_count];
in_count++;
/* wait CCF in SAES */
@@ -2401,8 +2728,8 @@ static HAL_StatusTypeDef Protect_SAES_UnwrapKey(CCB_HandleTypeDef *hccb, const C
}
/* Disable the SAES */
- SAES->CR &= ~AES_CR_EN;
- SAES->ICR |= 0x0EUL;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->ICR |= 0x0EUL;
/* Return function status */
return HAL_OK;
@@ -2659,7 +2986,7 @@ static HAL_StatusTypeDef CCB_WrapSymmetricKey(CCB_HandleTypeDef *hccb, const uin
}
/* Initialize RNG */
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -2669,12 +2996,22 @@ static HAL_StatusTypeDef CCB_WrapSymmetricKey(CCB_HandleTypeDef *hccb, const uin
/* Initialize SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* Disable the SAES peripheral clock */
- SAES->CR &= ~AES_CR_EN;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ /* Disable the SAES peripheral */
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
- /* Set state and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Update the state */
@@ -2682,12 +3019,14 @@ static HAL_StatusTypeDef CCB_WrapSymmetricKey(CCB_HandleTypeDef *hccb, const uin
if (pWrappingKey->AES_Algorithm != CCB_AES_ECB)
{
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KMOD_0 | AES_CR_KEYSIZE | AES_CR_CHMOD_0);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0 | AES_CR_KMOD_0 \
+ | AES_CR_KEYSIZE | AES_CR_CHMOD_0);
}
else
{
- WRITE_REG(SAES->CR, AES_CR_KEYSEL_0 | AES_CR_KMOD_0 | AES_CR_KEYSIZE);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KEYSEL_0 | AES_CR_KMOD_0 \
+ | AES_CR_KEYSIZE);
}
/* Wait for Key valid to be set */
@@ -2697,31 +3036,31 @@ static HAL_StatusTypeDef CCB_WrapSymmetricKey(CCB_HandleTypeDef *hccb, const uin
}
/* Disable the CRYP peripheral clock */
- SAES->CR &= ~AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
/* Set the operating mode*/
- MODIFY_REG(SAES->CR, AES_CR_KMOD, AES_CR_KMOD_0);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_KMOD, AES_CR_KMOD_0);
/* Encryption operating mode(Mode 0)*/
- MODIFY_REG(SAES->CR, AES_CR_MODE, 0x0UL); /*!< Encryption mode */
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_MODE, 0x0UL); /*!< Encryption mode */
if (pWrappingKey->AES_Algorithm != CCB_AES_ECB)
{
/* Set the Initialization Vector */
- SAES->IVR3 = *(uint32_t *)(pWrappingKey->pInitVect);
- SAES->IVR2 = *(uint32_t *)(pWrappingKey->pInitVect + 1U);
- SAES->IVR1 = *(uint32_t *)(pWrappingKey->pInitVect + 2U);
- SAES->IVR0 = *(uint32_t *)(pWrappingKey->pInitVect + 3U);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR3 = *(uint32_t *)(pWrappingKey->pInitVect);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR2 = *(uint32_t *)(pWrappingKey->pInitVect + 1U);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR1 = *(uint32_t *)(pWrappingKey->pInitVect + 2U);
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR0 = *(uint32_t *)(pWrappingKey->pInitVect + 3U);
}
/* Enable CRYP */
- SAES->CR |= AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR |= AES_CR_EN;
while (cryp_in_count < CCB_SIZE_SKEY_INWORD)
{
for (i = 0UL; i < 4UL; i++)
{
- SAES->DINR = pcryp_in_buff[cryp_in_count];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR = pcryp_in_buff[cryp_in_count];
cryp_in_count++;
}
@@ -2732,13 +3071,13 @@ static HAL_StatusTypeDef CCB_WrapSymmetricKey(CCB_HandleTypeDef *hccb, const uin
}
/* Clear CCF Flag */
- SET_BIT(SAES->ICR, AES_ICR_CCF);
+ SET_BIT(HAL_CCB_GET_SAES_INSTANCE(hccb)->ICR, AES_ICR_CCF);
/* Read the output block from the output FIFO and put them in temporary buffer then
get CrypOutBuff from temporary buffer */
for (i = 0UL; i < 4UL; i++)
{
- pcryp_out_buff[cryp_out_count] = SAES->DOUTR;
+ pcryp_out_buff[cryp_out_count] = HAL_CCB_GET_SAES_INSTANCE(hccb)->DOUTR;
cryp_out_count++;
}
}
@@ -2779,33 +3118,33 @@ static HAL_StatusTypeDef CCB_WrapSymmetricKey(CCB_HandleTypeDef *hccb, const uin
static HAL_StatusTypeDef CCB_BlobCreation_InitialPhase(CCB_HandleTypeDef *hccb, uint32_t *pIV)
{
/* Load IVs from RNG to SAES */
- SAES->IVR0 = CCB_IV0_VALUE; /* SAES_IVR0 that must be equal to 0x2 */
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR0 = CCB_IV0_VALUE; /* SAES_IVR0 that must be equal to 0x2 */
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
/* For IV1, IV2 and IV3, random generated values are loaded from RNG to SAES by CCB */
- SAES->IVR1 = CCB_FAKE_VALUE;
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR1 = CCB_FAKE_VALUE;
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
- SAES->IVR2 = CCB_FAKE_VALUE;
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR2 = CCB_FAKE_VALUE;
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
- SAES->IVR3 = CCB_FAKE_VALUE;
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR3 = CCB_FAKE_VALUE;
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
/* if an error occurs, RNGERRF flag is set in PKA */
- if (HAL_CCB_GET_PKA_FLAG(PKA_SR_RNGERRF) == SET)
+ if (HAL_CCB_GET_PKA_FLAG(hccb, PKA_SR_RNGERRF) == SET)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -2815,14 +3154,14 @@ static HAL_StatusTypeDef CCB_BlobCreation_InitialPhase(CCB_HandleTypeDef *hccb,
else
{
/* Read back IVs from SAES */
- pIV[3] = SAES->IVR3;
- pIV[2] = SAES->IVR2;
- pIV[1] = SAES->IVR1;
- pIV[0] = SAES->IVR0;
+ pIV[3] = HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR3;
+ pIV[2] = HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR2;
+ pIV[1] = HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR1;
+ pIV[0] = HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR0;
}
/* Set EN in SAES_CR*/
- SAES->CR |= AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR |= AES_CR_EN;
/* Wait until CCF is SET in SAES_ISR (end of GCM init) */
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -2831,7 +3170,7 @@ static HAL_StatusTypeDef CCB_BlobCreation_InitialPhase(CCB_HandleTypeDef *hccb,
}
/* Set SAES GCMPH Header phase and trig OPSTEP transition 0x2 --> 0x3 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_0 | AES_CR_EN);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH, AES_CR_GCMPH_0 | AES_CR_EN);
/* Return function status */
return HAL_OK;
@@ -2849,13 +3188,13 @@ static HAL_StatusTypeDef CCB_BlobUse_InitialPhase(CCB_HandleTypeDef *hccb, const
uint16_t count;
/* Set IVs from created Blob */
- SAES->IVR0 = pIV[0];
- SAES->IVR1 = pIV[1];
- SAES->IVR2 = pIV[2];
- SAES->IVR3 = pIV[3];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR0 = pIV[0];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR1 = pIV[1];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR2 = pIV[2];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->IVR3 = pIV[3];
/* Set EN in SAES_CR*/
- SAES->CR |= AES_CR_EN;
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR |= AES_CR_EN;
/* Wait until CCF is SET in SAES_ISR (end of GCM init) */
if (Protect_SAES_WaitFLAG(hccb, AES_ISR_CCF, SET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -2870,7 +3209,7 @@ static HAL_StatusTypeDef CCB_BlobUse_InitialPhase(CCB_HandleTypeDef *hccb, const
}
/* Set SAES GCMPH Header phase and trig OPSTEP transition 0x12 --> 0x13 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH | AES_CR_EN,
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH | AES_CR_EN,
AES_CR_GCMPH_0 | AES_CR_EN);
/* Return function status */
@@ -2904,7 +3243,7 @@ static HAL_StatusTypeDef CCB_BlobCreation_FinalPhase(CCB_HandleTypeDef *hccb, ui
cipherkey_size = operand_size;
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Preparing last Block */
if (Operation == CCB_MODULAR_EXP_CPU_BLOB_CREATION)
@@ -2938,7 +3277,7 @@ static HAL_StatusTypeDef CCB_BlobCreation_FinalPhase(CCB_HandleTypeDef *hccb, ui
for (count = 0; count < CCB_BLOCK_SIZE; count++)
{
- SAES->DINR = last_block[count];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR = last_block[count];
}
/* Wait until CCF flag is SET in SAES */
@@ -2950,7 +3289,7 @@ static HAL_StatusTypeDef CCB_BlobCreation_FinalPhase(CCB_HandleTypeDef *hccb, ui
/* Read Authentif Tag */
for (count = 0U; count < CCB_BLOCK_SIZE; count++)
{
- pTag[count] = SAES->DOUTR;
+ pTag[count] = HAL_CCB_GET_SAES_INSTANCE(hccb)->DOUTR;
}
/* Return function status */
@@ -2983,7 +3322,8 @@ static HAL_StatusTypeDef CCB_BlobUse_FinalPhase(CCB_HandleTypeDef *hccb, uint32_
}
/* Set SAES GCMPH final phase */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH,
+ AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
/* Preparing last Block */
if (Operation == CCB_MODULAR_EXP_BLOB_USE)
@@ -3017,7 +3357,7 @@ static HAL_StatusTypeDef CCB_BlobUse_FinalPhase(CCB_HandleTypeDef *hccb, uint32_
for (count = 0U; count < CCB_BLOCK_SIZE; count++)
{
- SAES->DINR = last_block[count];
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR = last_block[count];
}
/* Wait until CCF flag is SET in SAES */
@@ -3029,7 +3369,7 @@ static HAL_StatusTypeDef CCB_BlobUse_FinalPhase(CCB_HandleTypeDef *hccb, uint32_
/* Read Authentif Tag and check integrity of Blob as event that trig OPSTEP transition 0x17 --> 0x18 */
for (count = 0U; count < CCB_BLOCK_SIZE; count++)
{
- if ((SAES->DOUTR) != 0UL)
+ if ((HAL_CCB_GET_SAES_INSTANCE(hccb)->DOUTR) != 0UL)
{
/* Set state, error code and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -3051,13 +3391,16 @@ static HAL_StatusTypeDef CCB_BlobUse_FinalPhase(CCB_HandleTypeDef *hccb, uint32_
* @param pIV pointer to the IV.
* @param pTag pointer to the Tag.
* @param pWarappedKey pointer to the Warapped Key.
+ * @param pHash pointer to the Hash.
+ * @param pSignature pointer to the Signature.
* @param CCB_Operation is the CCB Operations.
* @retval HAL status.
*/
static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB_ECDSACurveParamTypeDef *pCurveParam,
const uint8_t *pClearPrivateKey,
CCB_WrappingKeyTypeDef *pWrappingKey, uint32_t *pIV,
- uint32_t *pTag, uint32_t *pWarappedKey, uint8_t CCB_Operation)
+ uint32_t *pTag, uint32_t *pWarappedKey, uint8_t *pHash,
+ CCB_ECDSASignTypeDef *pSignature, uint8_t CCB_Operation)
{
uint16_t count;
uint32_t countBlock = 0UL;
@@ -3076,7 +3419,7 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
}
/* Initialize RNG */
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -3091,15 +3434,37 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
return HAL_ERROR;
}
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* Move the input hash value to PKA RAM */
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_HASH_E], pHash,
+ pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_HASH_E + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+
+#else
+ /* Prevent unused argument(s) compilation warning */
+ UNUSED(pHash);
+
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* Initialize SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* Disable the SAES peripheral clock */
- SAES->CR &= ~AES_CR_EN;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ /* Disable the SAES peripheral */
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
- /* Set state and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Update the state */
@@ -3156,7 +3521,7 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
}
/* Set SAES GCMPH Payload phase and trig OPSTEP that trig OPSTEP transition 0x3 --> 0x4 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
if (CCB_Operation == CCB_ECDSA_SIGN_CPU_BLOB_CREATION)
{
@@ -3168,31 +3533,31 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Write private Key d by CPU (user key) */
if ((pCurveParam->modulusSizeByte % 8UL) != 0UL)
{
for (offset = 0UL; offset < (operand_size - 4UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset],
&pClearPrivateKey[(pCurveParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- CCB_Memcpy_Not_Align(&PKA->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset],
+ CCB_Memcpy_Not_Align(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset],
&pClearPrivateKey[(pCurveParam->modulusSizeByte) - ((offset * 4UL) + 1UL)],
pCurveParam->modulusSizeByte % 8UL);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset + 2UL);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset + 2UL);
}
else
{
for (offset = 0UL; offset < (operand_size - 2UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset],
&pClearPrivateKey[(pCurveParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset);
}
/* Wait until DATAOKF flag is SET in PKA and trig OPSTEP transition 0x4 --> 0x8 */
if (Protect_PKA_WaitFLAG(hccb, PKA_SR_DATAOKF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -3211,25 +3576,25 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Write private d Key from RNG */
for (offset = 0UL; offset < (operand_size - 2UL); offset++)
{
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
/* return error */
return HAL_ERROR;
}
- PKA->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset] = CCB_FAKE_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset] = CCB_FAKE_VALUE;
}
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D
+ offset);
/* Check RNG Error Flag in PKA */
- if (HAL_CCB_GET_PKA_FLAG(PKA_SR_RNGERRF) != RESET)
+ if (HAL_CCB_GET_PKA_FLAG(hccb, PKA_SR_RNGERRF) != RESET)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -3256,12 +3621,12 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Read clear-text private key d for encryption */
for (offset = 0; offset < cipherkey_size; offset++)
{
- PKA->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + offset] = CCB_MAGIC_VALUE;
if ((offset % 4UL) == 3UL)
{
@@ -3276,7 +3641,7 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
for (count = 0U; count < CCB_BLOCK_SIZE; count++)
{
pWarappedKey[cipherkey_size - (countBlock + count + 1UL)]
- = READ_REG(SAES->DOUTR);
+ = READ_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DOUTR);
}
countBlock += 4UL;
}
@@ -3285,12 +3650,21 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
/* Wait for Galois Filter End of Computation */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* return error */
- return HAL_ERROR;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D
+ cipherkey_size);
}
/* Wait until DATAOKF flag is SET in PKA and trig OPSTEP transition 0x08 --> 0x09 */
@@ -3299,9 +3673,35 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
/* return error */
return HAL_ERROR;
}
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* Wait until OPSTEP is set to 0x9 */
+ if (CCB_WaitOperStep(hccb, 0x09, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Write random k */
+ for (offset = 0U; offset < (operand_size - 2U); offset++)
+ {
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_K + offset] = CCB_MAGIC_VALUE;
+ }
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_K + offset);
+ /* Wait for PKA RNGOK flag : GCMPH = 0x3 (final phase) as events that trig OPSTEP transition 0x09 --> 0x0A */
+ if (Protect_PKA_WaitFLAG(hccb, PKA_SR_RNGOKF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* Set SAES GCMPH final phase */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH,
+ AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x0A */
if (CCB_WaitOperStep(hccb, 0x0A, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -3318,7 +3718,46 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
return HAL_ERROR;
}
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* SET PKA START operation bit and trig OPSTEP transition 0x0A --> 0x19 */
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_START);
+ /* Wait until OPSTEP is set to 0x19 */
+ if (CCB_WaitOperStep(hccb, 0x19, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Wait until end of operation flag is SET in PKA and trig OPSTEP transition 0x19 --> 0x1A */
+ if (Protect_PKA_WaitFLAG(hccb, PKA_SR_PROCENDF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Wait until OPSTEP is set to 0x1A */
+ if (CCB_WaitOperStep(hccb, 0x1A, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Check PKA Operation error result */
+ if ((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
+ {
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ /* Read r part signature */
+ CCB_Memcpy_u32_to_u8(pSignature->pRSign, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_R],
+ pCurveParam->modulusSizeByte);
+ /* Read s part signature */
+ CCB_Memcpy_u32_to_u8(pSignature->pSSign, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_S],
+ pCurveParam->modulusSizeByte);
+
+#else
+ /* Prevent unused argument(s) compilation warning */
+ UNUSED(pSignature);
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* CCB IPRST set */
SET_BIT(hccb->Instance->CR, CCB_CR_IPRST);
@@ -3349,6 +3788,7 @@ static HAL_StatusTypeDef CCB_ECDSA_SignBlobCreation(CCB_HandleTypeDef *hccb, CCB
* @param pIV pointer to the IV.
* @param pTag pointer to the Tag.
* @param pWarappedKey pointer to the Warapped Key.
+ * @param PublicKey is table of two coordinates X and Y of the publicKey.
* @param CCB_Operation is the CCB Operations.
* @retval HAL status.
*/
@@ -3357,7 +3797,7 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
const uint8_t *pClearPrivateKey,
CCB_WrappingKeyTypeDef *pWrappingKey,
uint32_t *pIV, uint32_t *pTag, uint32_t *pWarappedKey,
- uint8_t CCB_Operation)
+ uint32_t PublicKey[2U][20U], uint8_t CCB_Operation)
{
uint16_t count;
uint32_t countBlock = 0UL;
@@ -3378,7 +3818,7 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
}
/* Initialize RNG */
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* return state and error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -3393,15 +3833,38 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
return HAL_ERROR;
}
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* Write point G coordinate */
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X ],
+ pCurveParam->pPointX, pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y ],
+ pCurveParam->pPointY, pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* Initialize SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* Disable the SAES peripheral clock */
- SAES->CR &= ~AES_CR_EN;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ /* Disable the SAES peripheral */
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
- /* Set state and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Update the state */
@@ -3457,7 +3920,7 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
}
/* Set SAES GCMPH Payload phase and trig OPSTEP that trig OPSTEP transition 0x3 --> 0x4 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x04 */
if (CCB_WaitOperStep(hccb, 0x04, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -3467,7 +3930,7 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
if (CCB_Operation == CCB_ECC_SCALAR_MUL_CPU_BLOB_CREATION)
{
@@ -3477,24 +3940,24 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
{
for (offset = 0UL; offset < (operand_size - 4UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset],
&pClearPrivateKey[(pCurveParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- CCB_Memcpy_Not_Align(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset],
+ CCB_Memcpy_Not_Align(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset],
&pClearPrivateKey[(pCurveParam->modulusSizeByte) - ((offset * 4UL) + 1UL)],
pCurveParam->modulusSizeByte % 8UL);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_K + offset + 2UL);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECC_SCALAR_MUL_IN_K + offset + 2UL);
}
else
{
for (offset = 0UL; offset < (operand_size - 2UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset],
&pClearPrivateKey[(pCurveParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_K + offset);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECC_SCALAR_MUL_IN_K + offset);
}
/* Wait until DATAOKF flag is SET in PKA and trig OPSTEP transition 0x4 --> 0x8 */
if (Protect_PKA_WaitFLAG(hccb, PKA_SR_DATAOKF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -3508,17 +3971,17 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
/* Write scalar k when RNG */
for (offset = 0UL; offset < (operand_size - 2UL); offset++)
{
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
/* return error */
return HAL_ERROR;
}
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset] = CCB_FAKE_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset] = CCB_FAKE_VALUE;
}
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_K + offset);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECC_SCALAR_MUL_IN_K + offset);
/* PKA: Check RNG Error Flag */
- if (HAL_CCB_GET_PKA_FLAG(PKA_SR_RNGERRF) != RESET)
+ if (HAL_CCB_GET_PKA_FLAG(hccb, PKA_SR_RNGERRF) != RESET)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -3545,13 +4008,13 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Read clear-text scalar K for encryption */
for (offset = 0; offset < cipherkey_size; offset++)
{
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_K + offset] = CCB_MAGIC_VALUE;
if ((offset % 4UL) == 3UL)
{
@@ -3566,7 +4029,7 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
for (count = 0U; count < CCB_BLOCK_SIZE; count++)
{
pWarappedKey[cipherkey_size - (countBlock + count + 1U)]
- = READ_REG(SAES->DOUTR);
+ = READ_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DOUTR);
}
countBlock += 4UL;
}
@@ -3575,13 +4038,22 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
/* Wait for Galois Filter End of Computation */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* return error */
- return HAL_ERROR;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_K
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECC_SCALAR_MUL_IN_K
+ cipherkey_size);
}
@@ -3593,7 +4065,8 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
}
/* Set SAES GCMPH final phase */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH,
+ AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x0A */
if (CCB_WaitOperStep(hccb, 0x0A, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -3610,7 +4083,45 @@ static HAL_StatusTypeDef CCB_ECC_ScalarMulBlobCreation(CCB_HandleTypeDef *hccb,
return HAL_ERROR;
}
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* SET PKA START operation bit and trig OPSTEP transition 0x0A --> 0x19 */
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_START);
+ /* Wait until OPSTEP is set to 0x19 */
+ if (CCB_WaitOperStep(hccb, 0x19, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Wait until end of operation flag is SET in PKA and trig OPSTEP transition 0x19 --> 0x1A */
+ if (Protect_PKA_WaitFLAG(hccb, PKA_SR_PROCENDF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Wait until OPSTEP is set to 0x1A */
+ if (CCB_WaitOperStep(hccb, 0x1A, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Check PKA Operation error result */
+ if ((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
+ {
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ /* Move the result from appropriate location */
+ CCB_Memcpy_u32_to_u32(PublicKey[0], &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X],
+ ((pCurveParam->modulusSizeByte + 3) / 4));
+ CCB_Memcpy_u32_to_u32(PublicKey[1], &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y],
+ ((pCurveParam->modulusSizeByte + 3) / 4));
+
+#else
+ /* Prevent unused argument(s) compilation warning */
+ UNUSED(PublicKey);
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* CCB IPRST set */
SET_BIT(hccb->Instance->CR, CCB_CR_IPRST);
@@ -3683,14 +4194,14 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
}
/* Initialize RNG */
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -3699,7 +4210,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
while (random1 == 0U)
{
- random1 = (uint16_t)(RNG->DR & 0x3FFU);
+ random1 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -3707,7 +4218,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -3716,7 +4227,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
while (random2 == 0U)
{
- random2 = (uint16_t)(RNG->DR & 0x3FFU);
+ random2 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -3724,7 +4235,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -3733,7 +4244,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
while (random3 == 0U)
{
- random3 = (uint16_t)(RNG->DR & 0x3FFU);
+ random3 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -3753,22 +4264,26 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
if (VerifOperation == CCB_VERIF_OPERATION_DISABLED)
{
/* Write Customized point coordinate */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X ], pInputPoint->pPointX,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y ], pInputPoint->pPointY,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X ],
+ pInputPoint->pPointX, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y ],
+ pInputPoint->pPointY, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
}
else if (VerifOperation == CCB_VERIF_OPERATION_ENABLED)
{
/* Write point G coordinate */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X ], pCurveParam->pPointX,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y ], pCurveParam->pPointY,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X ],
+ pCurveParam->pPointX, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y ],
+ pCurveParam->pPointY, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
}
else
{
@@ -3778,12 +4293,22 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
/* Initialize SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* Disable the SAES peripheral */
- SAES->CR &= ~AES_CR_EN;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ /* Disable the SAES peripheral */
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
- /* Set state and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Update the state */
@@ -3852,7 +4377,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
}
/* Set SAES GCMPH Payload phase and trig OPSTEP that trig OPSTEP transition 0x13 --> 0x14 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x14 */
if (CCB_WaitOperStep(hccb, 0x14, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -3864,7 +4389,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
for (offset = 0UL; offset < cipherkey_size; offset++)
{
/* Write Wrapped scalar k in PKA RAM */
- WRITE_REG(SAES->DINR, pWarappedKey[cipherkey_size - (offset + 1UL)]);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR, pWarappedKey[cipherkey_size - (offset + 1UL)]);
if ((offset % 4UL) == 0x3UL)
{
@@ -3878,14 +4403,14 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
/* Write Unrapped scalar k in PKA RAM */
for (count_ram = 0U; count_ram < 4U; count_ram++)
{
- PKA->RAM[PKA_ECDSA_SIGN_IN_K + (count_block + count_ram)] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_K + (count_block + count_ram)] = CCB_MAGIC_VALUE;
}
count_block += 4UL;
}
}
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_K
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_ECDSA_SIGN_IN_K
+ cipherkey_size);
}
@@ -3922,7 +4447,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
}
/* SET PKA START operation bit and trig OPSTEP transition 0x18 --> 0x19 */
- SET_BIT(PKA->CR, PKA_CR_START);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_START);
/* Wait until OPSTEP is set to 0x19 */
if (CCB_WaitOperStep(hccb, 0x19, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -3946,7 +4471,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
}
/* Check PKA Operation error result */
- if ((PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
+ if ((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -3956,21 +4481,25 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
if (VerifOperation == CCB_VERIF_OPERATION_DISABLED)
{
/* P coordinate x */
- CCB_Memcpy_u32_to_u8(pOutputPoint->pPointX, &PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X],
+ CCB_Memcpy_u32_to_u8(pOutputPoint->pPointX,
+ &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X],
pCurveParam->modulusSizeByte);
/* P coordinate y */
- CCB_Memcpy_u32_to_u8(pOutputPoint->pPointY, &PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y],
+ CCB_Memcpy_u32_to_u8(pOutputPoint->pPointY,
+ &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y],
pCurveParam->modulusSizeByte);
}
else if (VerifOperation == CCB_COMPUTE_PUBLIC_KEY)
{
/* P coordinate x */
- CCB_Memcpy_u32_to_u8(pOutputPoint->pPointX, &PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X],
+ CCB_Memcpy_u32_to_u8(pOutputPoint->pPointX,
+ &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X],
pCurveParam->modulusSizeByte);
/* P coordinate y */
- CCB_Memcpy_u32_to_u8(pOutputPoint->pPointY, &PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y],
+ CCB_Memcpy_u32_to_u8(pOutputPoint->pPointY,
+ &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y],
pCurveParam->modulusSizeByte);
}
else /* (VerifOperation == CCB_VERIF_OPERATION_ENABLED) */
@@ -3985,7 +4514,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
for (offset = 0UL; offset < ((pCurveParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check public key coordinate x and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X + offset] != pPublicKey[offset]) ||
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X + offset] != pPublicKey[offset]) ||
(f_count != random1) || (f_count == 0U)))
{
/* Set state, and intrusion error */
@@ -3999,8 +4528,8 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
for (offset = 0UL; offset < ((pCurveParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check public key coordinate y and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y + offset] != pPublicKey[offset + 20U]) ||
- (f_count != random1) || (f_count == 0U)))
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y + offset]
+ != pPublicKey[offset + 20U]) || (f_count != random1) || (f_count == 0U)))
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -4018,7 +4547,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
for (offset = 0UL; offset < ((pCurveParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check public key coordinate x and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X + offset] != pPublicKey[offset]) ||
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X + offset] != pPublicKey[offset]) ||
(f_count != random2) || (f_count == 0U)))
{
/* Set state, and intrusion error */
@@ -4032,8 +4561,8 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
for (offset = 0UL; offset < ((pCurveParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check public key coordinate y and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y + offset] != pPublicKey[offset + 20U]) ||
- (f_count != random2) || (f_count == 0U)))
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y + offset] !=
+ pPublicKey[offset + 20U]) || (f_count != random2) || (f_count == 0U)))
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -4051,7 +4580,7 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
for (offset = 0UL; offset < ((pCurveParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check public key coordinate x and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X + offset] != pPublicKey[offset]) ||
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X + offset] != pPublicKey[offset]) ||
(f_count != random3) || (f_count == 0U)))
{
/* Set state, and intrusion error */
@@ -4065,8 +4594,8 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
for (offset = 0UL; offset < ((pCurveParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check public key coordinate y and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y + offset] != pPublicKey[offset + 20U]) ||
- (f_count != random3) || (f_count == 0U)))
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y + offset] !=
+ pPublicKey[offset + 20U]) || (f_count != random3) || (f_count == 0U)))
{
/* Set state, and intrusion error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -4104,12 +4633,15 @@ static HAL_StatusTypeDef CCB_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_E
* @param pTag pointer to the Tag.
* @param pWrappedExp pointer to the Warapped Exp.
* @param pWrappedPhi pointer to the Warapped Phi.
+ * @param pOperand pointer to the constant K as operand A.
+ * @param pReferenceModularExp pointer to the output ReferenceModularExp.
* @retval HAL status.
*/
static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RSAParamTypeDef *pParam,
const CCB_RSAClearKeyTypeDef *pRSAClearPrivateKey,
CCB_WrappingKeyTypeDef *pWrappingKey, uint32_t *pIV,
- uint32_t *pTag, uint32_t *pWrappedExp, uint32_t *pWrappedPhi)
+ uint32_t *pTag, uint32_t *pWrappedExp, uint32_t *pWrappedPhi,
+ uint8_t *pOperand, uint32_t *pReferenceModularExp)
{
uint16_t count;
uint32_t countBlock = 0UL;
@@ -4128,7 +4660,7 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
}
/* Initialize RNG */
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -4143,15 +4675,37 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
return HAL_ERROR;
}
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* Write a constant K as operand A (base of exponentiation) in the PKA RAM */
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE ], pOperand,
+ pParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE + ((pParam->modulusSizeByte + 3UL)));
+
+#else
+ /* Prevent unused argument(s) compilation warning */
+ UNUSED(pOperand);
+
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* Initialize SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* Disable the SAES peripheral clock */
- SAES->CR &= ~AES_CR_EN;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ /* Disable the SAES peripheral */
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
- /* Set state, error code and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Update the state */
@@ -4207,7 +4761,7 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
}
/* Set SAES GCMPH Payload phase and trig OPSTEP that trig OPSTEP transition 0x3 --> 0x4 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x04 */
if (CCB_WaitOperStep(hccb, 0x04, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -4217,31 +4771,31 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Write clear-text exponent e */
if ((pParam->modulusSizeByte % 8UL) != 0UL)
{
for (offset = 0UL; offset < (operand_size - 4UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset],
&pRSAClearPrivateKey->pExp[(pParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- CCB_Memcpy_Not_Align(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset],
+ CCB_Memcpy_Not_Align(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset],
&pRSAClearPrivateKey->pExp[(pParam->modulusSizeByte) - ((offset * 4UL) + 1UL)],
pParam->modulusSizeByte % 8UL);
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset + 2UL);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset + 2UL);
}
else
{
for (offset = 0; offset < (operand_size - 2UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset],
&pRSAClearPrivateKey->pExp[(pParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT
+ offset);
}
@@ -4261,31 +4815,31 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Write clear-text phi */
if ((pParam->modulusSizeByte % 8UL) != 0UL)
{
for (offset = 0; offset < (operand_size - 4UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset],
&pRSAClearPrivateKey->pPhi[(pParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- CCB_Memcpy_Not_Align(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset],
+ CCB_Memcpy_Not_Align(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset],
&pRSAClearPrivateKey->pPhi[(pParam->modulusSizeByte) - ((offset * 4UL) + 1UL)],
pParam->modulusSizeByte % 8UL);
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + offset + 2UL);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + offset + 2UL);
}
else
{
for (offset = 0; offset < (operand_size - 2UL); offset += 2UL)
{
- CCB_Memcpy_u8_to_u64(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset],
+ CCB_Memcpy_u8_to_u64(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset],
&pRSAClearPrivateKey->pPhi[(pParam->modulusSizeByte) - ((offset * 4UL) + 1UL)]);
}
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + offset);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + offset);
}
/* Wait until DATAOKF flag is SET in PKA and trig OPSTEP transition 0x5 --> 0x8: */
@@ -4303,13 +4857,13 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
/* Read clear exponent e for encryption */
for (offset = 0UL; offset < cipherkey_size; offset++)
{
- PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + offset] = CCB_MAGIC_VALUE;
if ((offset % 4UL) == 3UL)
{
@@ -4324,7 +4878,7 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
for (count = 0U; count < CCB_BLOCK_SIZE; count++)
{
pWrappedExp[cipherkey_size - (countBlock + count + 1UL)]
- = READ_REG(SAES->DOUTR);
+ = READ_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DOUTR);
}
countBlock += 4UL;
}
@@ -4333,13 +4887,22 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
/* Wait for Galois Filter End of Computation */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* return error */
- return HAL_ERROR;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT
+ cipherkey_size);
}
@@ -4358,7 +4921,7 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
countBlock = 0U;
@@ -4366,7 +4929,7 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
for (offset = 0; offset < cipherkey_size; offset++)
{
- PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + offset] = CCB_MAGIC_VALUE;
if ((offset % 4UL) == 3UL)
{
@@ -4381,7 +4944,7 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
for (count = 0U; count < CCB_BLOCK_SIZE; count++)
{
pWrappedPhi[cipherkey_size - (countBlock + count + 1UL)]
- = READ_REG(SAES->DOUTR);
+ = READ_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DOUTR);
}
countBlock += 4UL;
}
@@ -4390,13 +4953,22 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
/* Wait for Galois Filter End of Computation */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* return error */
- return HAL_ERROR;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI
+ cipherkey_size);
}
@@ -4408,7 +4980,8 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
}
/* Set SAES GCMPH final phase */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH,
+ AES_CR_GCMPH_0 | AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x0A */
if (CCB_WaitOperStep(hccb, 0x0A, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -4425,6 +4998,45 @@ static HAL_StatusTypeDef CCB_RSA_ExpBlobCreation(CCB_HandleTypeDef *hccb, CCB_RS
return HAL_ERROR;
}
+#if defined (HW_SANITY_CHECK_SUPPORT)
+ /* SET PKA START operation bit and trig OPSTEP transition 0x0A --> 0x19 */
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_START);
+ /* Wait until OPSTEP is set to 0x19 */
+ if (CCB_WaitOperStep(hccb, 0x19, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Wait until end of operation flag is SET in PKA and trig OPSTEP transition 0x19 --> 0x1A */
+ if (Protect_PKA_WaitFLAG(hccb, PKA_SR_PROCENDF, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Wait until OPSTEP is set to 0x1A */
+ if (CCB_WaitOperStep(hccb, 0x1A, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ {
+ /* return error */
+ return HAL_ERROR;
+ }
+ /* Check PKA Operation error result */
+ if ((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
+ {
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ /* Read result output */
+ for (offset = 0U; offset < (pParam->modulusSizeByte + 3) / 4; offset++)
+ {
+ pReferenceModularExp[offset] = HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_RESULT + offset];
+ }
+
+#else
+ /* Prevent unused argument(s) compilation warning */
+ UNUSED(pReferenceModularExp);
+
+#endif /* GENERATOR_HW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/* CCB IPRST set */
SET_BIT(hccb->Instance->CR, CCB_CR_IPRST);
@@ -4487,14 +5099,14 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
/* Initialize RNG */
- if (CCB_RNG_Init() != HAL_OK)
+ if (CCB_RNG_Init(hccb) != HAL_OK)
{
/* Set State and return error */
hccb->State = HAL_CCB_STATE_ERROR;
return HAL_ERROR;
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -4503,7 +5115,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
while (random1 == 0U)
{
- random1 = (uint16_t)(RNG->DR & 0x3FFU);
+ random1 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -4511,7 +5123,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -4520,7 +5132,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
while (random2 == 0U)
{
- random2 = (uint16_t)(RNG->DR & 0x3FFU);
+ random2 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -4528,7 +5140,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
}
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -4537,7 +5149,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
while (random3 == 0U)
{
- random3 = (uint16_t)(RNG->DR & 0x3FFU);
+ random3 = (uint16_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0x3FFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -4556,12 +5168,22 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
/* Initialize SAES */
if (Protect_SAES_WaitFLAG(hccb, AES_SR_BUSY, RESET, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
- /* Disable the SAES peripheral */
- SAES->CR &= ~AES_CR_EN;
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CCB_RNG_ResilientRecoverSeedError(hccb) != HAL_OK)
+ {
+ /* Disable the SAES peripheral */
+ HAL_CCB_GET_SAES_INSTANCE(hccb)->CR &= ~AES_CR_EN;
- /* Set state and return error */
- hccb->State = HAL_CCB_STATE_ERROR;
- return HAL_ERROR;
+ /* Set state and return error */
+ hccb->State = HAL_CCB_STATE_ERROR;
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
}
/* Update the state */
@@ -4598,8 +5220,10 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
/* Set Operand A - base of exponentiation */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE ], pOperand, pParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE + ((pParam->modulusSizeByte + 3UL)));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE ], pOperand,
+ pParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE + ((pParam->modulusSizeByte + 3UL)));
/* Initial Phase Processing */
if (CCB_BlobUse_InitialPhase(hccb, pIV, pTag) != HAL_OK)
@@ -4623,7 +5247,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
/* Set SAES GCMPH Payload phase and trig OPSTEP that trig OPSTEP transition 0x13 --> 0x14 */
- MODIFY_REG(SAES->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
+ MODIFY_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->CR, AES_CR_GCMPH, AES_CR_GCMPH_1);
/* Wait until OPSTEP is set to 0x14 */
if (CCB_WaitOperStep(hccb, 0x14, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -4635,7 +5259,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
/* Write encrypted exponent e in DINR of SAES */
for (offset = 0UL; offset < cipherkey_size; offset++)
{
- WRITE_REG(SAES->DINR, pWrappedExp[cipherkey_size - (offset + 1U)]);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR, pWrappedExp[cipherkey_size - (offset + 1U)]);
if ((offset % 4UL) == 0x3UL)
{
@@ -4649,7 +5273,8 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
/* Write key in PKA RAM */
for (count_ram = 0U; count_ram < 4U; count_ram++)
{
- PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + (count_block + count_ram)] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT
+ + (count_block + count_ram)] = CCB_MAGIC_VALUE;
}
count_block += 4UL;
}
@@ -4657,7 +5282,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + cipherkey_size);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + cipherkey_size);
}
/* Wait until DATAOKF flag is SET in PKA and trig OPSTEP transition 0x14 --> 0x15 */
@@ -4674,14 +5299,14 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
/* Clear the CMF flag and the chaining mode status bits in 8 to 15 in PKA_SR */
- HAL_CCB_CLEAR_PKA_FLAG(PKA_CLRFR_CMFC);
+ HAL_CCB_CLEAR_PKA_FLAG(hccb, PKA_CLRFR_CMFC);
count_block = 0UL;
/* Write encrypted phi in DINR of SAES */
for (offset = 0UL; offset < cipherkey_size; offset++)
{
- WRITE_REG(SAES->DINR, pWrappedPhi[cipherkey_size - (offset + 1UL)]);
+ WRITE_REG(HAL_CCB_GET_SAES_INSTANCE(hccb)->DINR, pWrappedPhi[cipherkey_size - (offset + 1UL)]);
if ((offset % 4UL) == 0x3UL)
{
@@ -4695,7 +5320,8 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
/* Write key in PKA RAM */
for (count_ram = 0U; count_ram < 4U; count_ram++)
{
- PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI + (count_block + count_ram)] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI
+ + (count_block + count_ram)] = CCB_MAGIC_VALUE;
}
count_block += 4UL;
}
@@ -4703,7 +5329,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
if ((operand_size % 4UL) != 0UL)
{
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + cipherkey_size);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + cipherkey_size);
}
/* Wait until DATAOKF flag is SET in PKA and trig OPSTEP transition 0x15 --> 0x17 */
@@ -4735,7 +5361,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
/* SET PKA START operation bit and trig OPSTEP transition 0x18 --> 0x19 */
- SET_BIT(PKA->CR, PKA_CR_START);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_START);
/* Wait until OPSTEP is set to 0x19 */
if (CCB_WaitOperStep(hccb, 0x19, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
@@ -4759,7 +5385,7 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
}
/* Check PKA Operation error result */
- if ((PKA->RAM[PKA_MODULAR_EXP_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
+ if ((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_ERROR]) != CCB_PKA_ERROR_OPERATION_NONE)
{
/* Set state and return error */
hccb->State = HAL_CCB_STATE_ERROR;
@@ -4769,7 +5395,8 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
if (VerifOperation == CCB_VERIF_OPERATION_DISABLED)
{
/* Read result output */
- CCB_Memcpy_u32_to_u8(pModularExp, &PKA->RAM[PKA_MODULAR_EXP_OUT_RESULT], pParam->modulusSizeByte);
+ CCB_Memcpy_u32_to_u8(pModularExp, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_RESULT],
+ pParam->modulusSizeByte);
}
else /* CCB_VERIF_OPERATION_ENABLED */
{
@@ -4782,7 +5409,8 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
for (offset = 0UL; offset < ((pParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check Modular Exponentiation and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_MODULAR_EXP_OUT_RESULT + offset] != pReferenceModularExp[offset]) || (f_count != random1) ||
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_RESULT + offset] != pReferenceModularExp[offset])
+ || (f_count != random1) ||
(f_count == 0U)))
{
/* Set state, and intrusion error */
@@ -4801,7 +5429,8 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
for (offset = 0UL; offset < ((pParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check Modular Exponentiation and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_MODULAR_EXP_OUT_RESULT + offset] != pReferenceModularExp[offset]) || (f_count != random2) ||
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_RESULT + offset] != pReferenceModularExp[offset])
+ || (f_count != random2) ||
(f_count == 0U)))
{
/* Set state, and intrusion error */
@@ -4819,7 +5448,8 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
for (offset = 0UL; offset < ((pParam->modulusSizeByte + 3UL) / 4UL); offset++)
{
/* Check Modular Exponentiation and improve robustness against intrusion (intentional) */
- if (((PKA->RAM[PKA_MODULAR_EXP_OUT_RESULT + offset] != pReferenceModularExp[offset]) || (f_count != random3) ||
+ if (((HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_RESULT + offset] != pReferenceModularExp[offset])
+ || (f_count != random3) ||
(f_count == 0U)))
{
/* Set state, and intrusion error */
@@ -4848,32 +5478,34 @@ static HAL_StatusTypeDef CCB_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_
return HAL_OK;
}
+#if defined(SW_SANITY_CHECK_SUPPORT)
/**
* @brief Erase the PKA RAM.
+ * @param hccb CCB handle.
* @retval HAL status.
*/
-static HAL_StatusTypeDef PKA_RAM_Erase(void)
+static HAL_StatusTypeDef PKA_RAM_Erase(CCB_HandleTypeDef *hccb)
{
uint32_t index;
__IO uint8_t random_nbr = 0U;
uint32_t tickstart;
- PKA->RAM[CCB_PKA_RAM_SIZE - 1U] = CCB_MAGIC_VALUE;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[CCB_PKA_RAM_SIZE - 1U] = CCB_MAGIC_VALUE;
/* For each element in the PKA RAM */
for (index = 0; index < CCB_PKA_RAM_SIZE; index++)
{
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
/* Clear the content */
- PKA->RAM[index] = RNG->DR;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[index] = HAL_CCB_GET_RNG_INSTANCE(hccb)->DR;
}
- if (PKA->RAM[CCB_PKA_RAM_SIZE - 1U] == CCB_MAGIC_VALUE)
+ if (HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[CCB_PKA_RAM_SIZE - 1U] == CCB_MAGIC_VALUE)
{
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
@@ -4882,7 +5514,7 @@ static HAL_StatusTypeDef PKA_RAM_Erase(void)
while (random_nbr == 0U)
{
- random_nbr = (uint8_t)(RNG->DR & 0xFFU);
+ random_nbr = (uint8_t)(HAL_CCB_GET_RNG_INSTANCE(hccb)->DR & 0xFFU);
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Set state and return error */
@@ -4898,15 +5530,15 @@ static HAL_StatusTypeDef PKA_RAM_Erase(void)
/* For each element in the PKA RAM */
for (index = 0; index < CCB_PKA_RAM_SIZE; index++)
{
- if (CCB_RNG_Wait_SET_FLAG(RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
+ if (CCB_RNG_Wait_SET_FLAG(hccb, RNG_SR_DRDY, HAL_CCB_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return HAL_ERROR;
}
/* Clear the content */
- PKA->RAM[index] = RNG->DR;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[index] = HAL_CCB_GET_RNG_INSTANCE(hccb)->DR;
}
- if (PKA->RAM[CCB_PKA_RAM_SIZE - 1U] == CCB_MAGIC_VALUE)
+ if (HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[CCB_PKA_RAM_SIZE - 1U] == CCB_MAGIC_VALUE)
{
return HAL_ERROR;
}
@@ -4919,6 +5551,7 @@ static HAL_StatusTypeDef PKA_RAM_Erase(void)
/**
* @brief CCB PKA ECDSA Signature.
+ * @param hccb CCB handle.
* @param pCurveParam pointer to the Curve parameters.
* @param pClearPrivateKey pointer to the clear private key.
* @param pInteger pointer to the integer k.
@@ -4926,7 +5559,7 @@ static HAL_StatusTypeDef PKA_RAM_Erase(void)
* @param pSignature Pointer to output signature
* @retval HAL status.
*/
-static HAL_StatusTypeDef PKA_ECDSASign(CCB_ECDSACurveParamTypeDef *pCurveParam,
+static HAL_StatusTypeDef PKA_ECDSASign(CCB_HandleTypeDef *hccb, CCB_ECDSACurveParamTypeDef *pCurveParam,
const uint8_t *pClearPrivateKey, uint8_t *pInteger, uint8_t *pHash,
CCB_ECDSASignTypeDef *pSignature)
{
@@ -4934,73 +5567,90 @@ static HAL_StatusTypeDef PKA_ECDSASign(CCB_ECDSACurveParamTypeDef *pCurveParam,
uint32_t timeout = HAL_CCB_TIMEOUT_DEFAULT_VALUE;
/* Get the prime order n length */
- PKA->RAM[PKA_ECDSA_SIGN_IN_ORDER_NB_BITS] = GetOptBitSize_u8(pCurveParam->primeOrderSizeByte,
- *(pCurveParam->pPrimeOrder));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_ORDER_NB_BITS] \
+ = GetOptBitSize_u8(pCurveParam->primeOrderSizeByte, *(pCurveParam->pPrimeOrder));
/* Get the modulus p length */
- PKA->RAM[PKA_ECDSA_SIGN_IN_MOD_NB_BITS] = GetOptBitSize_u8(pCurveParam->modulusSizeByte, *(pCurveParam->pModulus));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_MOD_NB_BITS] \
+ = GetOptBitSize_u8(pCurveParam->modulusSizeByte, *(pCurveParam->pModulus));
/* Get the coefficient a sign */
- PKA->RAM[PKA_ECDSA_SIGN_IN_A_COEFF_SIGN] = pCurveParam->coefSignA;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_A_COEFF_SIGN] = pCurveParam->coefSignA;
/* Move the input parameters coefficient |a| to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_A_COEFF], pCurveParam->pAbsCoefA, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_A_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_A_COEFF], pCurveParam->pAbsCoefA,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_A_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters coefficient B to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_B_COEFF], pCurveParam->pCoefB, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_B_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_B_COEFF], pCurveParam->pCoefB,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_B_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters modulus value p to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_MOD_GF], pCurveParam->pModulus, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_MOD_GF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_MOD_GF], pCurveParam->pModulus,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_MOD_GF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters integer k to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_K], pInteger, pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_K + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_K], pInteger,
+ pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_K + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Move the input parameters base point G coordinate x to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_INITIAL_POINT_X], pCurveParam->pPointX,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_INITIAL_POINT_X],
+ pCurveParam->pPointX, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters base point G coordinate y to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_INITIAL_POINT_Y], pCurveParam->pPointY,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_INITIAL_POINT_Y],
+ pCurveParam->pPointY, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters hash of message z to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_HASH_E], pHash, pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_HASH_E + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_HASH_E], pHash,
+ pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_HASH_E + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Move the input parameters private key d to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D], pClearPrivateKey, pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D],
+ pClearPrivateKey, pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_PRIVATE_KEY_D + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Move the input parameters prime order n to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_SIGN_IN_ORDER_N], pCurveParam->pPrimeOrder,
- pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_SIGN_IN_ORDER_N + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_IN_ORDER_N],
+ pCurveParam->pPrimeOrder, pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_SIGN_IN_ORDER_N + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Init tickstart for timeout management*/
tickstart = HAL_GetTick();
/* Set the mode and deactivate the interrupts */
- MODIFY_REG(PKA->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
+ MODIFY_REG(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR,
+ PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
CCB_PKA_ECDSA_SIGNATURE_MODE << PKA_CR_MODE_Pos);
/* Start the computation */
- PKA->CR |= PKA_CR_START;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CR |= PKA_CR_START;
/* Wait for the end of operation or timeout */
- while ((PKA->SR & PKA_SR_PROCENDF) == 0UL)
+ while ((HAL_CCB_GET_PKA_INSTANCE(hccb)->SR & PKA_SR_PROCENDF) == 0UL)
{
if (((HAL_GetTick() - tickstart) > timeout) || (timeout == 0UL))
{
/* Abort any ongoing operation */
- CLEAR_BIT(PKA->CR, PKA_CR_EN);
+ CLEAR_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
/* Make ready for the next operation */
- SET_BIT(PKA->CR, PKA_CR_EN);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
return HAL_TIMEOUT;
}
@@ -5008,12 +5658,15 @@ static HAL_StatusTypeDef PKA_ECDSASign(CCB_ECDSACurveParamTypeDef *pCurveParam,
}
/* Clear all flags */
- PKA->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC
+ | PKA_CLRFR_OPERRFC);
- CCB_Memcpy_u32_to_u8(pSignature->pRSign, &PKA->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_R], pCurveParam->primeOrderSizeByte);
- CCB_Memcpy_u32_to_u8(pSignature->pSSign, &PKA->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_S], pCurveParam->primeOrderSizeByte);
+ CCB_Memcpy_u32_to_u8(pSignature->pRSign, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_R],
+ pCurveParam->primeOrderSizeByte);
+ CCB_Memcpy_u32_to_u8(pSignature->pSSign, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_SIGN_OUT_SIGNATURE_S],
+ pCurveParam->primeOrderSizeByte);
- if (PKA_RAM_Erase() != HAL_OK)
+ if (PKA_RAM_Erase(hccb) != HAL_OK)
{
/* return error */
return HAL_ERROR;
@@ -5024,95 +5677,110 @@ static HAL_StatusTypeDef PKA_ECDSASign(CCB_ECDSACurveParamTypeDef *pCurveParam,
/**
* @brief Blob Usage: ECC Compute Scalar Multiplication.
+ * @param hccb CCB handle.
* @param pCurveParam pointer to the Curve parameters.
* @param pClearPrivateKey pointer to the related wrapped Private Key Blob.
* @param PublicKey is table of two coordinates X and Y of the publicKey.
* @retval HAL status.
*/
-static HAL_StatusTypeDef PKA_ECC_ComputeScalarMul(CCB_ECCMulCurveParamTypeDef *pCurveParam,
+static HAL_StatusTypeDef PKA_ECC_ComputeScalarMul(CCB_HandleTypeDef *hccb, CCB_ECCMulCurveParamTypeDef *pCurveParam,
const uint8_t *pClearPrivateKey, uint32_t PublicKey[2][20])
{
uint32_t tickstart;
uint32_t timeout = HAL_CCB_TIMEOUT_DEFAULT_VALUE;
- /*********************************************************************************** Set input parameter in PKA RAM */
+ /********************************************************************************** Set input parameter in PKA RAM */
/* Get the prime order n length */
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_EXP_NB_BITS] = GetOptBitSize_u8(pCurveParam->primeOrderSizeByte,
- *(pCurveParam->pPrimeOrder));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_EXP_NB_BITS]\
+ = GetOptBitSize_u8(pCurveParam->primeOrderSizeByte, *(pCurveParam->pPrimeOrder));
/* Get the modulus length */
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_OP_NB_BITS] = GetOptBitSize_u8(pCurveParam->modulusSizeByte,
- *(pCurveParam->pModulus));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_OP_NB_BITS]\
+ = GetOptBitSize_u8(pCurveParam->modulusSizeByte, *(pCurveParam->pModulus));
/* Get the coefficient a sign */
- PKA->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF_SIGN] = pCurveParam->coefSignA;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF_SIGN] = pCurveParam->coefSignA;
/* Move the input parameters coefficient |a| to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF], pCurveParam->pAbsCoefA, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_A_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_A_COEFF], pCurveParam->pAbsCoefA,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_A_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters coefficient b to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_B_COEFF], pCurveParam->pCoefB, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_B_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_B_COEFF], pCurveParam->pCoefB,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_B_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters modulus value p to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_MOD_GF], pCurveParam->pModulus, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_MOD_GF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_MOD_GF], pCurveParam->pModulus,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_MOD_GF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters scalar multiplier k to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_K], pClearPrivateKey, pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_K + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_K], pClearPrivateKey,
+ pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_K + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Move the input parameters Point P coordinate x to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X], pCurveParam->pPointX,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X],
+ pCurveParam->pPointX, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters Point P coordinate y to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y], pCurveParam->pPointY,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y],
+ pCurveParam->pPointY, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters curve prime order N to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECC_SCALAR_MUL_IN_N_PRIME_ORDER], pCurveParam->pPrimeOrder,
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_IN_N_PRIME_ORDER],
+ pCurveParam->pPrimeOrder,
pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECC_SCALAR_MUL_IN_N_PRIME_ORDER + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECC_SCALAR_MUL_IN_N_PRIME_ORDER + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
- /********************************************************************************************** Start the operation */
+ /******************************************************************************************** Start the operation */
/* Init tickstart for timeout management*/
tickstart = HAL_GetTick();
/* Set the mode and deactivate the interrupts */
- MODIFY_REG(PKA->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
+ MODIFY_REG(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR,
+ PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
CCB_PKA_ECC_MUL_MODE << PKA_CR_MODE_Pos);
/* Start the computation */
- PKA->CR |= PKA_CR_START;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CR |= PKA_CR_START;
/* Wait for the end of operation or timeout */
- while ((PKA->SR & PKA_SR_PROCENDF) == 0UL)
+ while ((HAL_CCB_GET_PKA_INSTANCE(hccb)->SR & PKA_SR_PROCENDF) == 0UL)
{
if (((HAL_GetTick() - tickstart) > timeout) || (timeout == 0UL))
{
/* Abort any ongoing operation */
- CLEAR_BIT(PKA->CR, PKA_CR_EN);
+ CLEAR_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
/* Make ready for the next operation */
- SET_BIT(PKA->CR, PKA_CR_EN);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
return HAL_TIMEOUT;
}
}
/* Clear all flags */
- PKA->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC
+ | PKA_CLRFR_OPERRFC);
/* get PublicKey result */
/* Move the result from appropriate location (with opprand size in 32bit word ) */
- CCB_Memcpy_u32_to_u32(PublicKey[0], &PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X],
+ CCB_Memcpy_u32_to_u32(PublicKey[0], &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_X],
((pCurveParam->modulusSizeByte + 3UL) / 4UL));
- CCB_Memcpy_u32_to_u32(PublicKey[1], &PKA->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y],
+ CCB_Memcpy_u32_to_u32(PublicKey[1], &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECC_SCALAR_MUL_OUT_RESULT_Y],
((pCurveParam->modulusSizeByte + 3UL) / 4UL));
- if (PKA_RAM_Erase() != HAL_OK)
+ if (PKA_RAM_Erase(hccb) != HAL_OK)
{
/* return error */
return HAL_ERROR;
@@ -5123,69 +5791,80 @@ static HAL_StatusTypeDef PKA_ECC_ComputeScalarMul(CCB_ECCMulCurveParamTypeDef *p
/**
* @brief Compute CCB Modular exponentiation.
+ * @param hccb CCB handle.
* @param pParam pointer to the modular exponatiation parameters.
* @param pRSAClearPrivateKey pointer to the clear Private Key.
* @param pOp1 Pointer to Operand 1 (Array of size elements).
* @param pReferenceModularExp pointer to the ReferenceModularExp computed in modular exponentiation Blob creation.
* @retval HAL status.
*/
-static HAL_StatusTypeDef PKA_RSA_ComputeModularExp(CCB_RSAParamTypeDef *pParam,
+static HAL_StatusTypeDef PKA_RSA_ComputeModularExp(CCB_HandleTypeDef *hccb, CCB_RSAParamTypeDef *pParam,
const CCB_RSAClearKeyTypeDef *pRSAClearPrivateKey,
uint8_t *pOp1, uint32_t *pReferenceModularExp)
{
uint32_t tickstart = HAL_GetTick();
/* Get the number of bit per operand */
- PKA->RAM[PKA_MODULAR_EXP_IN_OP_NB_BITS] = pParam->modulusSizeByte * 8U;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_IN_OP_NB_BITS] = pParam->modulusSizeByte * 8U;
/* Get the number of bit of the exponent */
- PKA->RAM[PKA_MODULAR_EXP_IN_EXP_NB_BITS] = pParam->expSizeByte * 8U;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_IN_EXP_NB_BITS] = pParam->expSizeByte * 8U;
/* Move the input parameters pOp1 to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE], pOp1, pParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE + ((pParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE], pOp1,
+ pParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE + ((pParam->modulusSizeByte + 3UL) / 4UL));
/* Move the exponent to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT], pRSAClearPrivateKey->pExp, pParam->expSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + ((pParam->expSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT],
+ pRSAClearPrivateKey->pExp, pParam->expSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + ((pParam->expSizeByte + 3UL) / 4UL));
/* Move the modulus to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_MODULUS], pParam->pMod, pParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_MODULUS + ((pParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_MODULUS], pParam->pMod,
+ pParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_MODULAR_EXP_PROTECT_IN_MODULUS + ((pParam->modulusSizeByte + 3UL) / 4UL));
/* Move Phi value to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI], pRSAClearPrivateKey->pPhi, pParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + ((pParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI],
+ pRSAClearPrivateKey->pPhi, pParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_MODULAR_EXP_PROTECT_IN_PHI + ((pParam->modulusSizeByte + 3UL) / 4UL));
/* Set the mode and deactivate the interrupts */
- MODIFY_REG(PKA->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
+ MODIFY_REG(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR,
+ PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
CCB_PKA_MODE_MODULAR_EXP_PROTECT << PKA_CR_MODE_Pos);
/* Start the computation */
- PKA->CR |= PKA_CR_START;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CR |= PKA_CR_START;
/* Wait for the end of operation or timeout */
- while ((PKA->SR & PKA_SR_PROCENDF) == 0UL)
+ while ((HAL_CCB_GET_PKA_INSTANCE(hccb)->SR & PKA_SR_PROCENDF) == 0UL)
{
/* Check if timeout is disabled (set to infinite wait) */
if ((HAL_GetTick() - tickstart) > HAL_CCB_TIMEOUT_DEFAULT_VALUE)
{
/* Abort any ongoing operation */
- CLEAR_BIT(PKA->CR, PKA_CR_EN);
+ CLEAR_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
/* Make ready for the next operation */
- SET_BIT(PKA->CR, PKA_CR_EN);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
return HAL_TIMEOUT;
}
}
/* Clear all flags */
- PKA->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC
+ | PKA_CLRFR_OPERRFC);
/* Move the result from appropriate location (with opprand size in 32bit word ) */
- CCB_Memcpy_u32_to_u32(pReferenceModularExp, &PKA->RAM[PKA_MODULAR_EXP_OUT_RESULT],
+ CCB_Memcpy_u32_to_u32(pReferenceModularExp, &HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_MODULAR_EXP_OUT_RESULT],
((pParam->modulusSizeByte + 3UL) / 4UL));
- if (PKA_RAM_Erase() != HAL_OK)
+ if (PKA_RAM_Erase(hccb) != HAL_OK)
{
/* return error */
return HAL_ERROR;
@@ -5194,15 +5873,17 @@ static HAL_StatusTypeDef PKA_RSA_ComputeModularExp(CCB_RSAParamTypeDef *pParam,
return HAL_OK;
}
+#endif /* GENERATOR_SW_SANITY_CHECK_AVAILABLE_ALL_DEVICES */
/**
@brief Verify the validity of a signature using elliptic curves over prime fields in blocking mode.
+ * @param hccb CCB handle.
* @param pCurveParam pointer to the Curve parameters.
* @param pPublicKeyOut pointer to the public key.
* @param pHash pointer to the hash.
* @param pSignature Pointer to input signature
* @retval HAL status.
*/
-static HAL_StatusTypeDef PKA_ECDSAVerif(CCB_ECDSACurveParamTypeDef *pCurveParam,
+static HAL_StatusTypeDef PKA_ECDSAVerif(CCB_HandleTypeDef *hccb, CCB_ECDSACurveParamTypeDef *pCurveParam,
CCB_ECCMulPointTypeDef *pPublicKeyOut, const uint8_t *pHash,
CCB_ECDSASignTypeDef *pSignature)
{
@@ -5211,102 +5892,124 @@ static HAL_StatusTypeDef PKA_ECDSAVerif(CCB_ECDSACurveParamTypeDef *pCurveParam,
/* Set CCB input parameter in PKA RAM */
/* Get the prime order n length */
- PKA->RAM[PKA_ECDSA_VERIF_IN_ORDER_NB_BITS] = GetOptBitSize_u8(pCurveParam->primeOrderSizeByte,
- *(pCurveParam->pPrimeOrder));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_ORDER_NB_BITS] \
+ = GetOptBitSize_u8(pCurveParam->primeOrderSizeByte, *(pCurveParam->pPrimeOrder));
/* Get the modulus p length */
- PKA->RAM[PKA_ECDSA_VERIF_IN_MOD_NB_BITS] = GetOptBitSize_u8(pCurveParam->modulusSizeByte, *(pCurveParam->pModulus));
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_MOD_NB_BITS] \
+ = GetOptBitSize_u8(pCurveParam->modulusSizeByte, *(pCurveParam->pModulus));
/* Get the coefficient a sign */
- PKA->RAM[PKA_ECDSA_VERIF_IN_A_COEFF_SIGN] = pCurveParam->coefSignA;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_A_COEFF_SIGN] = pCurveParam->coefSignA;
/* Move the input parameters coefficient |a| to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_A_COEFF], pCurveParam->pAbsCoefA, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_A_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_A_COEFF], pCurveParam->pAbsCoefA,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_A_COEFF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters modulus value p to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_MOD_GF], pCurveParam->pModulus, pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_MOD_GF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_MOD_GF], pCurveParam->pModulus,
+ pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_MOD_GF + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters base point G coordinate x to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_INITIAL_POINT_X], pCurveParam->pPointX,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_INITIAL_POINT_X],
+ pCurveParam->pPointX, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_INITIAL_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters base point G coordinate y to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_INITIAL_POINT_Y], pCurveParam->pPointY,
- pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_INITIAL_POINT_Y],
+ pCurveParam->pPointY, pCurveParam->modulusSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_INITIAL_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters public-key curve point Q coordinate xQ to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_X], pPublicKeyOut->pPointX,
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_X],
+ pPublicKeyOut->pPointX,
pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_X + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters public-key curve point Q coordinate xQ to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_Y], pPublicKeyOut->pPointY,
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_Y],
+ pPublicKeyOut->pPointY,
pCurveParam->modulusSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_PUBLIC_KEY_POINT_Y + ((pCurveParam->modulusSizeByte + 3UL) / 4UL));
/* Move the input parameters signature part r to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_SIGNATURE_R], pSignature->pRSign, pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_SIGNATURE_R + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_SIGNATURE_R], pSignature->pRSign,
+ pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_SIGNATURE_R + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Move the input parameters signature part s to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_SIGNATURE_S], pSignature->pSSign, pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_SIGNATURE_S + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_SIGNATURE_S], pSignature->pSSign,
+ pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_SIGNATURE_S + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Move the input parameters hash of message z to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_HASH_E], pHash, pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_HASH_E + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_HASH_E], pHash,
+ pCurveParam->primeOrderSizeByte);
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_HASH_E + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Move the input parameters curve prime order n to PKA RAM */
- CCB_Memcpy_u8_to_u32(&PKA->RAM[PKA_ECDSA_VERIF_IN_ORDER_N], pCurveParam->pPrimeOrder,
+ CCB_Memcpy_u8_to_u32(&HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_IN_ORDER_N], pCurveParam->pPrimeOrder,
pCurveParam->primeOrderSizeByte);
- RAM_PARAM_END(PKA->RAM, PKA_ECDSA_VERIF_IN_ORDER_N + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
+ RAM_PARAM_END(HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM,
+ PKA_ECDSA_VERIF_IN_ORDER_N + ((pCurveParam->primeOrderSizeByte + 3UL) / 4UL));
/* Set the mode and deactivate the interrupts */
- MODIFY_REG(PKA->CR, PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
+ MODIFY_REG(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR,
+ PKA_CR_MODE | PKA_CR_PROCENDIE | PKA_CR_RAMERRIE | PKA_CR_ADDRERRIE | PKA_CR_OPERRIE,
CCB_PKA_MODE_ECDSA_VERIFICATION << PKA_CR_MODE_Pos);
/* Start the computation */
- PKA->CR |= PKA_CR_START;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CR |= PKA_CR_START;
tickstart = HAL_GetTick();
/* Wait for the end of operation or timeout */
- while ((PKA->SR & PKA_SR_PROCENDF) == 0UL)
+ while ((HAL_CCB_GET_PKA_INSTANCE(hccb)->SR & PKA_SR_PROCENDF) == 0UL)
{
if (((HAL_GetTick() - tickstart) > timeout) || (timeout == 0UL))
{
/* Abort any ongoing operation */
- CLEAR_BIT(PKA->CR, PKA_CR_EN);
+ CLEAR_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
/* Make ready for the next operation */
- SET_BIT(PKA->CR, PKA_CR_EN);
+ SET_BIT(HAL_CCB_GET_PKA_INSTANCE(hccb)->CR, PKA_CR_EN);
return HAL_TIMEOUT;
}
}
/* Clear all flags */
- PKA->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC | PKA_CLRFR_OPERRFC);
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->CLRFR |= (PKA_CLRFR_PROCENDFC | PKA_CLRFR_RAMERRFC | PKA_CLRFR_ADDRERRFC
+ | PKA_CLRFR_OPERRFC);
return HAL_OK;
}
/**
* @brief Return the result of the ECDSA verification operation.
+ * @param hccb CCB handle.
* @retval 1 if signature is verified, 0 in other case
*/
-static uint32_t PKA_ECDSAVerif_Result(void)
+static uint32_t PKA_ECDSAVerif_Result(CCB_HandleTypeDef *hccb)
{
- return (PKA->RAM[PKA_ECDSA_VERIF_OUT_RESULT]);
+ return (HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[PKA_ECDSA_VERIF_OUT_RESULT]);
}
/**
* @brief Reset the PKA RAM.
+ * @param hccb CCB handle.
* @retval None
*/
-static void CCB_PKA_RAMReset(void)
+static void CCB_PKA_RAMReset(CCB_HandleTypeDef *hccb)
{
uint32_t index;
@@ -5314,9 +6017,191 @@ static void CCB_PKA_RAMReset(void)
for (index = 0; index < CCB_PKA_RAM_SIZE; index++)
{
/* Clear the content */
- PKA->RAM[index] = 0UL;
+ HAL_CCB_GET_PKA_INSTANCE(hccb)->RAM[index] = 0UL;
+ }
+}
+
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+/**
+ * @brief RNG sequence to resilient recover from a seed error
+ * @retval HAL status
+ */
+HAL_StatusTypeDef CCB_RNG_ResilientRecoverSeedError(CCB_HandleTypeDef *hccb)
+{
+ uint32_t timeout;
+ uint32_t htsr_temp = 0U;
+ uint32_t htsr_previous_temp = 0U;
+ uint32_t htsr_count = 0U;
+ uint32_t nsmr_temp = 0U;
+ uint32_t tickstart1 = 0U;
+ uint32_t tickstart2 = 0U;
+ uint32_t tickstart3 = 0U;
+ uint32_t oscillators_count = 0U;
+ uint32_t config_b_fewer_than_6_osc_count = 0U;
+ uint8_t count = 0U;
+
+ /* timeout here is an emperic value */
+ timeout = (1UL + ((1UL << (READ_BIT(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR, RNG_CR_CLKDIV) >> 16UL))
+ * CCB_RNG_TIMEOUT_VALUE / 8UL));
+ LL_RNG_Enable(HAL_CCB_GET_RNG_INSTANCE(hccb));
+
+ tickstart1 = HAL_GetTick();
+
+ /* Check if seed error current status indicates no error and auto-reset succeeded */
+ if (LL_RNG_IsActiveFlag_SECS(HAL_CCB_GET_RNG_INSTANCE(hccb)) == 0U)
+ {
+ /* Clear SEIS flag when automatic reset is activated */
+ LL_RNG_ClearFlag_SEIS(HAL_CCB_GET_RNG_INSTANCE(hccb));
+ }
+
+ else /* Sequence to fully recover from a seed error*/
+ {
+ if (LL_RNG_IsConfigLocked(HAL_CCB_GET_RNG_INSTANCE(hccb)) == 0U)
+ {
+ do
+ {
+ if (LL_RNG_IsActiveFlag_SECS(HAL_CCB_GET_RNG_INSTANCE(hccb)) == 0U)
+ {
+ break;
+ }
+ /* Read oscillator status registers combined */
+ htsr_temp = LL_RNG_GetHealthTestStatus(HAL_CCB_GET_RNG_INSTANCE(hccb), 0U);
+ htsr_temp |= LL_RNG_GetHealthTestStatus(HAL_CCB_GET_RNG_INSTANCE(hccb), 1U);
+ if (htsr_temp > 0U)
+ {
+ /* If any oscillator status bits overlap with previous status, increment counter */
+ if ((htsr_temp & htsr_previous_temp) != 0U)
+ {
+ htsr_count++;
+ }
+
+ if (htsr_count > 3U)
+ {
+ /* if the same repetitive or adaptative error is detected 3 times */
+ nsmr_temp = LL_RNG_GetNoiseSourceMask(HAL_CCB_GET_RNG_INSTANCE(hccb));
+
+ /* deactivate the same osc in each triple oscillator (Mask oscillators with the seed error by
+ clearing bits shifted right by 1) */
+ nsmr_temp = nsmr_temp & ~(htsr_temp >> 1U);
+
+ /* Count the number of active oscillators in nsmr */
+ oscillators_count = 0U;
+ for (count = 0U; count < 9U; count++)
+ {
+ if (((nsmr_temp >> count) & 0x1U) != 0U)
+ {
+ /* increment count1 for each 1 in nsmr */
+ oscillators_count++;
+ }
+ }
+
+ if (oscillators_count < 6U)
+ {
+ /* If fewer than 6 oscillators remain active, unmask all oscillators --> Reset masking */
+ nsmr_temp = LL_RNG_GetOscNoiseSrc(HAL_CCB_GET_RNG_INSTANCE(hccb),
+ LL_RNG_NOISE_SRC_1 | LL_RNG_NOISE_SRC_2 | LL_RNG_NOISE_SRC_3);
+ htsr_previous_temp = 0;
+ htsr_count = 0U;
+ if ((HAL_CCB_GET_RNG_INSTANCE(hccb)->CR & RNG_CR_CLKDIV_Msk) <
+ ((uint32_t)RNG_CAND_NIST_CR_VALUE & RNG_CR_CLKDIV_Msk))
+ {
+ config_b_fewer_than_6_osc_count++;
+ }
+ }
+
+ if (config_b_fewer_than_6_osc_count > 2U)
+ {
+ /* Reset RNG condition */
+ WRITE_REG(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR, (RNG_CR_CONDRST_Msk | (uint32_t)RNG_CAND_NIST_CR_VALUE));
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(HAL_CCB_GET_RNG_INSTANCE(hccb), nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(HAL_CCB_GET_RNG_INSTANCE(hccb));
+ }
+
+ else
+ {
+ /* Reset RNG condition */
+ WRITE_REG(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR,
+ (HAL_CCB_GET_RNG_INSTANCE(hccb)->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(HAL_CCB_GET_RNG_INSTANCE(hccb), nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(HAL_CCB_GET_RNG_INSTANCE(hccb));
+ }
+ }
+
+ else
+ {
+ /* Briefly toggle conditional reset to recover RNG */
+ WRITE_REG(HAL_CCB_GET_RNG_INSTANCE(hccb)->CR,
+ (HAL_CCB_GET_RNG_INSTANCE(hccb)->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* unmask all oscillators to find another working condition */
+ LL_RNG_SetNoiseSourceMask(HAL_CCB_GET_RNG_INSTANCE(hccb),
+ LL_RNG_GetOscNoiseSrc(RNG, LL_RNG_OSC_1 | LL_RNG_OSC_2 | LL_RNG_OSC_3));
+ LL_RNG_DisableCondReset(HAL_CCB_GET_RNG_INSTANCE(hccb));
+ }
+
+ /* Wait until RNG is not busy */
+ tickstart2 = HAL_GetTick();
+ do
+ {
+ if ((HAL_GetTick() - tickstart2) > CCB_RNG_TIMEOUT_VALUE)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ LL_RNG_Disable(HAL_CCB_GET_RNG_INSTANCE(hccb));
+ return HAL_ERROR;
+ }
+ } while (HAL_IS_BIT_SET(HAL_CCB_GET_RNG_INSTANCE(hccb)->SR, RNG_SR_BUSY));
+
+ /* No timeout --> Enable RNG */
+ LL_RNG_Enable(HAL_CCB_GET_RNG_INSTANCE(hccb));
+ tickstart3 = HAL_GetTick();
+ do
+ {
+ if (LL_RNG_IsActiveFlag_DRDY(HAL_CCB_GET_RNG_INSTANCE(hccb)) != 0UL)
+ {
+ break;
+ }
+ if ((HAL_GetTick() - tickstart3) > timeout)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ if (LL_RNG_IsActiveFlag_DRDY(HAL_CCB_GET_RNG_INSTANCE(hccb)) == 0UL)
+ {
+ if (LL_RNG_IsActiveFlag_SECS(HAL_CCB_GET_RNG_INSTANCE(hccb)) == 0UL)
+ {
+ LL_RNG_Disable(HAL_CCB_GET_RNG_INSTANCE(hccb));
+ return HAL_ERROR;
+ }
+ }
+ }
+ } while (LL_RNG_IsActiveFlag_SECS(HAL_CCB_GET_RNG_INSTANCE(hccb)) == 0UL);
+
+ /* Accumulate seed error status bits */
+ htsr_previous_temp = htsr_previous_temp | htsr_temp;
+ }
+ } while ((HAL_GetTick() - tickstart1) <= timeout);
+ }
+ }
+
+ /*Check if seed error current status (SECS)is set */
+ if (LL_RNG_IsActiveFlag_SECS(HAL_CCB_GET_RNG_INSTANCE(hccb)) != 0U)
+ {
+ return HAL_ERROR;
}
+
+ return HAL_OK;
}
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
+
+/**
+ * @}
+ */
/**
* @}
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_crc.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_crc.c
index 0b280ef1ff..cdbfa5a018 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_crc.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_crc.c
@@ -154,11 +154,19 @@ HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
/* set input data inversion mode */
assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(hcrc->Init.InputDataInversionMode));
+#if defined(CRC_CR_RTYPE_OUT)
+ MODIFY_REG(hcrc->Instance->CR, (CRC_CR_RTYPE_IN | CRC_CR_REV_IN), hcrc->Init.InputDataInversionMode);
+#else
MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, hcrc->Init.InputDataInversionMode);
+#endif /* CRC_CR_RTYPE_OUT */
/* set output data inversion mode */
assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(hcrc->Init.OutputDataInversionMode));
+#if defined(CRC_CR_RTYPE_OUT)
+ MODIFY_REG(hcrc->Instance->CR, (CRC_CR_RTYPE_OUT | CRC_CR_REV_OUT), hcrc->Init.OutputDataInversionMode);
+#else
MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, hcrc->Init.OutputDataInversionMode);
+#endif /* CRC_CR_RTYPE_OUT */
/* makes sure the input data format (bytes, halfwords or words stream)
* is properly specified by user */
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_cryp.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_cryp.c
index 96159c23ae..d6f166b0fe 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_cryp.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_cryp.c
@@ -306,6 +306,9 @@
* @{
*/
#define CRYP_GENERAL_TIMEOUT 82U
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+#define CRYP_RNG_TIMEOUT_VALUE 2U
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
#define CRYP_TIMEOUT_KEYPREPARATION 82U /*!< The latency of key preparation operation is 82 clock cycles.*/
#define CRYP_TIMEOUT_GCMCCMINITPHASE 299U /*!< The latency of GCM/CCM init phase to prepare hash subkey
is 299 clock cycles.*/
@@ -383,6 +386,7 @@ static HAL_StatusTypeDef CRYP_AES_Encrypt_IT(CRYP_HandleTypeDef *hcryp);
static HAL_StatusTypeDef CRYP_AES_Decrypt_DMA(CRYP_HandleTypeDef *hcryp);
static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef *hcryp, uint32_t Timeout);
static void CRYP_ClearCCFlagWhenHigh(CRYP_HandleTypeDef *hcryp, uint32_t Timeout);
+static void CRYP_CopyPartialOutputWord(uint32_t *pOutputWord, uint32_t word, uint32_t dataType, uint32_t validBytes);
#if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
static void CRYP_Read_IVRegisters(CRYP_HandleTypeDef *hcryp, const uint32_t *Output);
static void CRYP_Write_IVRegisters(CRYP_HandleTypeDef *hcryp, const uint32_t *Input);
@@ -392,6 +396,52 @@ static void CRYP_Read_KeyRegisters(CRYP_HandleTypeDef *hcryp, const uint32_t *Ou
static void CRYP_Write_KeyRegisters(CRYP_HandleTypeDef *hcryp, const uint32_t *Input, uint32_t KeySize);
static void CRYP_PhaseProcessingResume(CRYP_HandleTypeDef *hcryp);
#endif /* USE_HAL_CRYP_SUSPEND_RESUME */
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+HAL_StatusTypeDef CRYP_RNG_ResilientRecoverSeedError(void);
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
+
+static void CRYP_CopyPartialOutputWord(uint32_t *pOutputWord, uint32_t word, uint32_t dataType, uint32_t validBytes)
+{
+ uint8_t *pDst = (uint8_t *)pOutputWord;
+ uint8_t *pSrc = (uint8_t *)&word;
+ uint32_t dstIndex = 0U;
+ uint32_t index;
+ uint32_t maskValue;
+ /* DataType-dependent byte maps used to keep only valid bytes from the last partial CCM word. */
+ const uint32_t mask[16] = {0x0U, 0xFF000000U, 0xFFFF0000U, 0xFFFFFF00U,
+ 0x0U, 0x0000FF00U, 0x0000FFFFU, 0xFF00FFFFU,
+ 0x0U, 0x000000FFU, 0x0000FFFFU, 0x00FFFFFFU,
+ 0x0U, 0x000000FFU, 0x0000FFFFU, 0x00FFFFFFU
+ };
+
+ if (validBytes >= 4U)
+ {
+ *pOutputWord = word;
+ return;
+ }
+
+ /* Select bytes that are valid for the active DataType, then compact them at output start. */
+ maskValue = mask[(dataType * 2U) + validBytes];
+
+ for (index = 0U; index < 4U; index++)
+ {
+ if ((maskValue & ((uint32_t)0xFFU << (index * 8U))) != 0U)
+ {
+ pDst[dstIndex] = pSrc[index];
+ dstIndex++;
+ if (dstIndex == validBytes)
+ {
+ break;
+ }
+ }
+ }
+
+ for (index = dstIndex; index < 4U; index++)
+ {
+ /* Zero-fill trailing bytes to keep deterministic output for non-aligned payload sizes. */
+ pDst[index] = 0U;
+ }
+}
/**
@@ -494,6 +544,20 @@ HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp)
}
else
{
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (CRYP_RNG_ResilientRecoverSeedError() != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+
+ /* Clear Rng error interrupt flag */
+ SET_BIT(hcryp->Instance->ICR, AES_ICR_RNGEIF);
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/* SAES is initializing, fetching random number from the RNG */
tickstart = HAL_GetTick();
while (HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
@@ -3181,6 +3245,7 @@ static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
uint32_t lastwordsize;
uint32_t temp[4] = {0}; /* Temporary CrypOutBuff */
uint32_t mode;
+ uint32_t crypoutcount;
CRYP_HandleTypeDef *hcryp = (CRYP_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
@@ -3255,7 +3320,17 @@ static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
count = 0U;
while ((hcryp->CrypOutCount < ((hcryp->Size + 3U) / 4U)) && (count < 4U))
{
- *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[count];
+ crypoutcount = hcryp->CrypOutCount;
+ if ((((hcryp->Size % 4U) != 0U) && (crypoutcount == ((((uint32_t)hcryp->Size + 3U) / 4U) - 1U)))
+ && (hcryp->Init.Algorithm == CRYP_AES_CCM))
+ {
+ CRYP_CopyPartialOutputWord(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount, temp[count],
+ hcryp->Init.DataType, (((uint32_t)hcryp->Size) % 4U));
+ }
+ else
+ {
+ *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[count];
+ }
hcryp->CrypOutCount++;
count++;
}
@@ -3503,6 +3578,7 @@ static void CRYP_AES_ProcessData(CRYP_HandleTypeDef *hcryp, uint32_t Timeout)
uint32_t temp[4] = {0}; /* Temporary CrypOutBuff */
uint32_t i;
+ uint32_t crypoutcount;
/* Write the input block in the IN FIFO */
hcryp->Instance->DINR = *(uint32_t *)(hcryp->pCrypInBuffPtr + hcryp->CrypInCount);
@@ -3538,7 +3614,17 @@ static void CRYP_AES_ProcessData(CRYP_HandleTypeDef *hcryp, uint32_t Timeout)
i = 0U;
while ((hcryp->CrypOutCount < ((hcryp->Size + 3U) / 4U)) && (i < 4U))
{
- *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[i];
+ crypoutcount = hcryp->CrypOutCount;
+ if ((((hcryp->Size % 4U) != 0U) && (crypoutcount == ((((uint32_t)hcryp->Size + 3U) / 4U) - 1U)))
+ && (hcryp->Init.Algorithm == CRYP_AES_CCM))
+ {
+ CRYP_CopyPartialOutputWord(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount, temp[i],
+ hcryp->Init.DataType, (((uint32_t)hcryp->Size) % 4U));
+ }
+ else
+ {
+ *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[i];
+ }
hcryp->CrypOutCount++;
i++;
}
@@ -3747,10 +3833,18 @@ static HAL_StatusTypeDef CRYP_AESGCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
uint32_t npblb;
uint32_t temp[4] = {0}; /* Temporary CrypOutBuff */
uint32_t index;
- uint32_t lastwordsize;
+ uint32_t tmp;
+ uint32_t lastwordsize ;
+ uint32_t lastoutputwordsize;
+ uint32_t nolastpaddingbytes;
uint32_t incount; /* Temporary CrypInCount Value */
uint32_t outcount; /* Temporary CrypOutCount Value */
uint32_t dokeyivconfig = 1U; /* By default, carry out peripheral Key and IV configuration */
+ const uint32_t mask[16] = {0x0U, 0xFF000000U, 0xFFFF0000U, 0xFFFFFF00U, /* 32- bit data type */
+ 0x0U, 0x0000FF00U, 0x0000FFFFU, 0xFF00FFFFU, /* 16- bit data type */
+ 0x0U, 0x000000FFU, 0x0000FFFFU, 0x00FFFFFFU, /* 8- bit data type */
+ 0x0U, 0x000000FFU, 0x0000FFFFU, 0x00FFFFFFU, /* 1- bit data type */
+ };
if (hcryp->Init.KeyIVConfigSkip == CRYP_KEYIVCONFIG_ONCE)
{
if (hcryp->KeyIVConfig == 1U)
@@ -3910,14 +4004,8 @@ static HAL_StatusTypeDef CRYP_AESGCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, npblb << 20U);
}
/* Number of valid words (lastwordsize) in last block */
- if ((npblb % 4U) == 0U)
- {
- lastwordsize = (16U - npblb) / 4U;
- }
- else
- {
- lastwordsize = ((16U - npblb) / 4U) + 1U;
- }
+ lastwordsize = (16U - npblb) / 4U;
+
/* last block optionally pad the data with zeros*/
for (index = 0U; index < lastwordsize; index ++)
{
@@ -3925,6 +4013,16 @@ static HAL_StatusTypeDef CRYP_AESGCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
hcryp->Instance->DINR = *(uint32_t *)(hcryp->pCrypInBuffPtr + hcryp->CrypInCount);
hcryp->CrypInCount++;
}
+
+ if ((npblb % 4U) != 0U)
+ {
+ /* Enter last bytes, padded with zeros */
+ tmp = *(uint32_t *)(hcryp->pCrypInBuffPtr + hcryp->CrypInCount);
+ tmp &= mask[((hcryp->Init.DataType) * 2U) + ((16U - npblb) % 4U)];
+ hcryp->Instance->DINR = tmp;
+ index++;
+ }
+
while (index < 4U)
{
/* pad the data with zeros to have a complete block */
@@ -3946,6 +4044,17 @@ static HAL_StatusTypeDef CRYP_AESGCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
/* Clear CCF Flag */
__HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CLEAR_CCF);
+ /* Number of words in last block to read from DOUT*/
+ if ((npblb % 4U) == 0U)
+ {
+ lastoutputwordsize = (16U - npblb) / 4U;
+ }
+ else
+ {
+ lastoutputwordsize = ((16U - npblb) / 4U) + 1U;
+ }
+
+
/*Read the output block from the output FIFO */
for (index = 0U; index < 4U; index++)
{
@@ -3953,9 +4062,20 @@ static HAL_StatusTypeDef CRYP_AESGCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
get CrypOutBuff from temporary buffer */
temp[index] = hcryp->Instance->DOUTR;
}
- for (index = 0U; index < lastwordsize; index++)
+ for (index = 0U; index < lastoutputwordsize; index++)
{
- *(uint32_t *)(hcryp->pCrypOutBuffPtr + (hcryp->CrypOutCount)) = temp[index];
+ if ((index == (lastoutputwordsize - 1U)) && ((npblb % 4U) != 0U)
+ && (hcryp->Init.Algorithm == CRYP_AES_CCM))
+ {
+ nolastpaddingbytes = npblb % 4U;
+ CRYP_CopyPartialOutputWord(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount, temp[index],
+ hcryp->Init.DataType, 4U - nolastpaddingbytes);
+ }
+ else
+ {
+ *(uint32_t *)(hcryp->pCrypOutBuffPtr + (hcryp->CrypOutCount)) = temp[index];
+ }
+
hcryp->CrypOutCount++;
}
}
@@ -4509,10 +4629,17 @@ static HAL_StatusTypeDef CRYP_AESCCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
uint32_t loopcounter;
uint32_t npblb;
uint32_t lastwordsize;
+ uint32_t lastoutputwordsize;
uint32_t temp[4] = {0}; /* Temporary CrypOutBuff */
+ uint32_t tmp;
uint32_t incount; /* Temporary CrypInCount Value */
uint32_t outcount; /* Temporary CrypOutCount Value */
uint32_t dokeyivconfig = 1U; /* By default, carry out peripheral Key and IV configuration */
+ const uint32_t mask[16] = {0x0U, 0xFF000000U, 0xFFFF0000U, 0xFFFFFF00U, /* 32- bit data type */
+ 0x0U, 0x0000FF00U, 0x0000FFFFU, 0xFF00FFFFU, /* 16- bit data type */
+ 0x0U, 0x000000FFU, 0x0000FFFFU, 0x00FFFFFFU, /* 8- bit data type */
+ 0x0U, 0x000000FFU, 0x0000FFFFU, 0x00FFFFFFU, /* 1- bit data type */
+ };
if (hcryp->Init.KeyIVConfigSkip == CRYP_KEYIVCONFIG_ONCE)
{
@@ -4675,14 +4802,7 @@ static HAL_StatusTypeDef CRYP_AESCCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
}
/* Number of valid words (lastwordsize) in last block */
- if ((npblb % 4U) == 0U)
- {
- lastwordsize = (16U - npblb) / 4U;
- }
- else
- {
- lastwordsize = ((16U - npblb) / 4U) + 1U;
- }
+ lastwordsize = (16U - npblb) / 4U;
/* Write the last input block in the IN FIFO */
for (loopcounter = 0U; loopcounter < lastwordsize; loopcounter ++)
@@ -4690,6 +4810,15 @@ static HAL_StatusTypeDef CRYP_AESCCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
hcryp->Instance->DINR = *(uint32_t *)(hcryp->pCrypInBuffPtr + hcryp->CrypInCount);
hcryp->CrypInCount++;
}
+ if ((npblb % 4U) != 0U)
+ {
+ /* Enter last bytes, padded with zeros */
+ tmp = *(uint32_t *)(hcryp->pCrypInBuffPtr + hcryp->CrypInCount);
+ /* Keep only valid bytes of the last partial input word, according to DataType byte ordering. */
+ tmp &= mask[(hcryp->Init.DataType * 2U) + ((16U - npblb) % 4U)];
+ hcryp->Instance->DINR = tmp;
+ loopcounter++;
+ }
/* Pad the data with zeros to have a complete block */
while (loopcounter < 4U)
@@ -4697,6 +4826,15 @@ static HAL_StatusTypeDef CRYP_AESCCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
hcryp->Instance->DINR = 0U;
loopcounter++;
}
+ /* Number of words in last block to read from DOUT*/
+ if ((npblb % 4U) == 0U)
+ {
+ lastoutputwordsize = (16U - npblb) / 4U;
+ }
+ else
+ {
+ lastoutputwordsize = ((16U - npblb) / 4U) + 1U;
+ }
/* just wait for hash computation */
if (CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
{
@@ -4711,9 +4849,17 @@ static HAL_StatusTypeDef CRYP_AESCCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t
get CrypOutBuff from temporary buffer */
temp[loopcounter] = hcryp->Instance->DOUTR;
}
- for (loopcounter = 0U; loopcounter < lastwordsize; loopcounter++)
+ for (loopcounter = 0U; loopcounter < lastoutputwordsize; loopcounter++)
{
- *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[loopcounter];
+ if ((loopcounter == (lastoutputwordsize - 1U)) && ((npblb % 4U) != 0U))
+ {
+ CRYP_CopyPartialOutputWord(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount, temp[loopcounter],
+ hcryp->Init.DataType, 4U - (npblb % 4U));
+ }
+ else
+ {
+ *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[loopcounter];
+ }
hcryp->CrypOutCount++;
}
}
@@ -5266,6 +5412,7 @@ static void CRYP_GCMCCM_SetPayloadPhase_IT(CRYP_HandleTypeDef *hcryp)
uint16_t incount; /* Temporary CrypInCount Value */
uint16_t outcount; /* Temporary CrypOutCount Value */
uint32_t i;
+ uint32_t crypoutcount;
/***************************** Payload phase *******************************/
@@ -5278,7 +5425,17 @@ static void CRYP_GCMCCM_SetPayloadPhase_IT(CRYP_HandleTypeDef *hcryp)
i = 0U;
while ((hcryp->CrypOutCount < ((hcryp->Size + 3U) / 4U)) && (i < 4U))
{
- *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[i];
+ crypoutcount = hcryp->CrypOutCount;
+ if ((((hcryp->Size % 4U) != 0U) && (crypoutcount == ((((uint32_t)hcryp->Size + 3U) / 4U) - 1U)))
+ && (hcryp->Init.Algorithm == CRYP_AES_CCM))
+ {
+ CRYP_CopyPartialOutputWord(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount, temp[i],
+ hcryp->Init.DataType, (((uint32_t)hcryp->Size) % 4U));
+ }
+ else
+ {
+ *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[i];
+ }
hcryp->CrypOutCount++;
i++;
}
@@ -5499,7 +5656,16 @@ static HAL_StatusTypeDef CRYP_GCMCCM_SetPayloadPhase_DMA(CRYP_HandleTypeDef *hcr
}
for (index = 0U; index < lastwordsize; index++)
{
- *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[index];
+ if ((index == (lastwordsize - 1U)) && ((npblb % 4U) != 0U)
+ && (hcryp->Init.Algorithm == CRYP_AES_CCM))
+ {
+ CRYP_CopyPartialOutputWord(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount, temp[index],
+ hcryp->Init.DataType, 4U - (npblb % 4U));
+ }
+ else
+ {
+ *(uint32_t *)(hcryp->pCrypOutBuffPtr + hcryp->CrypOutCount) = temp[index];
+ }
hcryp->CrypOutCount++;
}
@@ -6401,6 +6567,179 @@ static void CRYP_PhaseProcessingResume(CRYP_HandleTypeDef *hcryp)
}
}
#endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+/**
+ * @brief RNG sequence to resilient recover from a seed error
+ * @retval HAL status
+ */
+HAL_StatusTypeDef CRYP_RNG_ResilientRecoverSeedError(void)
+{
+ uint32_t timeout;
+ uint32_t htsr_temp = 0U;
+ uint32_t htsr_previous_temp = 0U;
+ uint32_t htsr_count = 0U;
+ uint32_t nsmr_temp = 0U;
+ uint32_t tickstart1 = 0U;
+ uint32_t tickstart2 = 0U;
+ uint32_t tickstart3 = 0U;
+ uint32_t oscillators_count = 0U;
+ uint32_t config_b_fewer_than_6_osc_count = 0U;
+ uint8_t count = 0U;
+
+ /* timeout here is an emperic value */
+ timeout = (1UL + ((1UL << (READ_BIT(RNG->CR, RNG_CR_CLKDIV) >> 16UL)) * CRYP_RNG_TIMEOUT_VALUE / 8UL));
+ LL_RNG_Enable(RNG);
+
+ tickstart1 = HAL_GetTick();
+
+ /* Check if seed error current status indicates no error and auto-reset succeeded */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) == 0U)
+ {
+ /* Clear SEIS flag when automatic reset is activated */
+ LL_RNG_ClearFlag_SEIS(RNG);
+ }
+
+ else /* Sequence to fully recover from a seed error*/
+ {
+ if (LL_RNG_IsConfigLocked(RNG) == 0U)
+ {
+ do
+ {
+ if (LL_RNG_IsActiveFlag_SECS(RNG) == 0U)
+ {
+ break;
+ }
+ /* Read oscillator status registers combined */
+ htsr_temp = LL_RNG_GetHealthTestStatus(RNG, 0U);
+ htsr_temp |= LL_RNG_GetHealthTestStatus(RNG, 1U);
+ if (htsr_temp > 0U)
+ {
+ /* If any oscillator status bits overlap with previous status, increment counter */
+ if ((htsr_temp & htsr_previous_temp) != 0U)
+ {
+ htsr_count++;
+ }
+
+ if (htsr_count > 3U)
+ {
+ /* if the same repetitive or adaptative error is detected 3 times */
+ nsmr_temp = LL_RNG_GetNoiseSourceMask(RNG);
+
+ /* deactivate the same osc in each triple oscillator (Mask oscillators with the seed error by
+ clearing bits shifted right by 1) */
+ nsmr_temp = nsmr_temp & ~(htsr_temp >> 1U);
+
+ /* Count the number of active oscillators in nsmr */
+ oscillators_count = 0U;
+ for (count = 0U; count < 9U; count++)
+ {
+ if (((nsmr_temp >> count) & 0x1U) != 0U)
+ {
+ /* increment count1 for each 1 in nsmr */
+ oscillators_count++;
+ }
+ }
+
+ if (oscillators_count < 6U)
+ {
+ /* If fewer than 6 oscillators remain active, unmask all oscillators --> Reset masking */
+ nsmr_temp = LL_RNG_GetOscNoiseSrc(RNG, LL_RNG_NOISE_SRC_1 | LL_RNG_NOISE_SRC_2 \
+ | LL_RNG_NOISE_SRC_3);
+ htsr_previous_temp = 0;
+ htsr_count = 0U;
+ if ((RNG->CR & RNG_CR_CLKDIV_Msk) < ((uint32_t)RNG_CAND_NIST_CR_VALUE & RNG_CR_CLKDIV_Msk))
+ {
+ config_b_fewer_than_6_osc_count++;
+ }
+ }
+
+ if (config_b_fewer_than_6_osc_count > 2U)
+ {
+ /* Reset RNG condition */
+ WRITE_REG(RNG->CR, (RNG_CR_CONDRST_Msk | (uint32_t)RNG_CAND_NIST_CR_VALUE));
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(RNG, nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(RNG);
+ }
+
+ else
+ {
+ /* Reset RNG condition */
+ WRITE_REG(RNG->CR, (RNG->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(RNG, nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(RNG);
+ }
+ }
+
+ else
+ {
+ /* Briefly toggle conditional reset to recover RNG */
+ WRITE_REG(RNG->CR, (RNG->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* unmask all oscillators to find another working condition */
+ LL_RNG_SetNoiseSourceMask(RNG, LL_RNG_GetOscNoiseSrc(RNG, LL_RNG_OSC_1\
+ | LL_RNG_OSC_2 | LL_RNG_OSC_3));
+ LL_RNG_DisableCondReset(RNG);
+ }
+
+ /* Wait until RNG is not busy */
+ tickstart2 = HAL_GetTick();
+ do
+ {
+ if ((HAL_GetTick() - tickstart2) > CRYP_RNG_TIMEOUT_VALUE)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ LL_RNG_Disable(RNG);
+ return HAL_ERROR;
+ }
+ } while (HAL_IS_BIT_SET(RNG->SR, RNG_SR_BUSY));
+
+ /* No timeout --> Enable RNG */
+ LL_RNG_Enable(RNG);
+ tickstart3 = HAL_GetTick();
+ do
+ {
+ if (LL_RNG_IsActiveFlag_DRDY(RNG) != 0UL)
+ {
+ break;
+ }
+ if ((HAL_GetTick() - tickstart3) > timeout)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ if (LL_RNG_IsActiveFlag_DRDY(RNG) == 0UL)
+ {
+ if (LL_RNG_IsActiveFlag_SECS(RNG) == 0UL)
+ {
+ LL_RNG_Disable(RNG);
+ return HAL_ERROR;
+ }
+ }
+ }
+ } while (LL_RNG_IsActiveFlag_SECS(RNG) == 0UL);
+
+ /* Accumulate seed error status bits */
+ htsr_previous_temp = htsr_previous_temp | htsr_temp;
+ }
+ } while ((HAL_GetTick() - tickstart1) <= timeout);
+ }
+ }
+
+ /*Check if seed error current status (SECS)is set */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ return HAL_ERROR;
+ }
+
+ return HAL_OK;
+}
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/**
* @}
*/
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma2d.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma2d.c
index 5d378ac36c..87631d3564 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma2d.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma2d.c
@@ -238,7 +238,8 @@
the HAL_DMA2D_CL_AddConfigDownscalingCMD() function for the foreground layer, background layer,
or blender output.
- (#) Optionally, configure the line watermark in using the function HAL_DMA2D_CL_AddLineEventCMD().
+ (#) Optionally, configure the line watermark in using the function
+ HAL_DMA2D_CL_AddProgramLineEventCMD().
[...] Command List Copy ans Data Transfers Enable
Use the following APIs to enable data transfer for the selected operating mode and to copy
@@ -407,6 +408,7 @@ const uint32_t LDM_Decoder[HAL_DMA2D_CL_LDM_REG_NUM] =
#define DMA2D_CL_LDM_WRITE_REG(HANDLE, REG, VALUE) \
((HANDLE)->LDM_Reg_values[(REG)] = (VALUE), \
(HANDLE)->LDM_Instruction |= LDM_Decoder[(REG)])
+#define RBS_TO_RING_BUFFER_SIZE(val) (1UL << ((val) + 6U))
#endif /* USE_DMA2D_COMMAND_LIST_MODE == 1 */
/**
* @}
@@ -2179,8 +2181,8 @@ HAL_StatusTypeDef HAL_DMA2D_ConfigRotation(DMA2D_HandleTypeDef *hdma2d, uint32_t
/**
* @brief Configures the DMA2D Downscaling for the selected source Foreground, Background or Blender output
* @param hdma2d Pointer to DMA2D handle structure.
- * @param Source Specifies the source of the tile buffer.
- * This parameter can be a value from @ref DMA2D_SOURCE
+ * @param Source Specifies the source of the tile buffer.
+ * This parameter can be a value from @ref DMA2D_SOURCE
* @param pDownscalingCfg Pointer to DMA2D_DownscalingCfgTypeDef that contains
* the configuration information for downscaling.
* @retval HAL status
@@ -2188,35 +2190,55 @@ HAL_StatusTypeDef HAL_DMA2D_ConfigRotation(DMA2D_HandleTypeDef *hdma2d, uint32_t
HAL_StatusTypeDef HAL_DMA2D_ConfigDownscaling(DMA2D_HandleTypeDef *hdma2d, uint32_t Source,
DMA2D_DownscalingCfgTypeDef *pDownscalingCfg)
{
- /* HSEP and VSTEP Calculation */
- uint16_t hstep = (4096U / (pDownscalingCfg->HRatio) - 1U);
- uint16_t vstep = (4096U / (pDownscalingCfg->VRatio) - 1U);
+ uint32_t hstep;
+ uint32_t vstep;
+ uint32_t hq12;
+ uint32_t vq12;
/* Check parameters */
+ if ((hdma2d == NULL) || (pDownscalingCfg == NULL))
+ {
+ return HAL_ERROR;
+ }
+
assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));
assert_param(IS_DMA2D_SCALE_SRC(Source));
- assert_param(IS_DMA2D_SCALE_HSTEP(hstep));
- assert_param(IS_DMA2D_SCALE_VSTEP(vstep));
assert_param(IS_DMA2D_SCALE_PIXEL_PER_LINE(pDownscalingCfg->PixelPerLines));
assert_param(IS_DMA2D_SCALE_NUMBER_OF_LINES(pDownscalingCfg->NumberOfLines));
assert_param(IS_DMA2D_SCALE_HPHASE(pDownscalingCfg->HPhase));
assert_param(IS_DMA2D_SCALE_VPHASE(pDownscalingCfg->VPhase));
+ if ((pDownscalingCfg->HRatioDiv == 0U) || (pDownscalingCfg->VRatioDiv == 0U))
+ {
+ return HAL_ERROR;
+ }
+
+ hq12 = (((uint32_t)pDownscalingCfg->HRatio * 4096U) / (uint32_t)pDownscalingCfg->HRatioDiv);
+ vq12 = (((uint32_t)pDownscalingCfg->VRatio * 4096U) / (uint32_t)pDownscalingCfg->VRatioDiv);
+
+ hstep = hq12 - 1U;
+ vstep = vq12 - 1U;
+
+ assert_param(IS_DMA2D_SCALE_HSTEP(hstep));
+ assert_param(IS_DMA2D_SCALE_VSTEP(vstep));
+
/* Config scaling source */
MODIFY_REG(hdma2d->Instance->SCR, DMA2D_SCR_SRC, Source);
- /* Config scaling Height and Width */
- MODIFY_REG(hdma2d->Instance->SNLR, (DMA2D_SNLR_NL | DMA2D_SNLR_PL), (pDownscalingCfg->NumberOfLines |
- (pDownscalingCfg->PixelPerLines <<
- DMA2D_SNLR_PL_Pos)));
+ /* Config scaling height and width */
+ MODIFY_REG(hdma2d->Instance->SNLR,
+ (DMA2D_SNLR_NL | DMA2D_SNLR_PL),
+ (pDownscalingCfg->NumberOfLines |
+ (pDownscalingCfg->PixelPerLines << DMA2D_SNLR_PL_Pos)));
- /* Config scaling HSEP and VSTEP */
- MODIFY_REG(hdma2d->Instance->SSR, (DMA2D_SSR_HSTEP | DMA2D_SSR_VSTEP), (hstep | (((uint32_t)vstep) <<
- DMA2D_SSR_VSTEP_Pos)));
+ /* Config scaling HSTEP and VSTEP */
+ WRITE_REG(hdma2d->Instance->SSR, (hstep | (vstep << DMA2D_SSR_VSTEP_Pos)));
/* Config scaling HPHASE and VPHASE */
- MODIFY_REG(hdma2d->Instance->SPR, (DMA2D_SPR_HPHASE | DMA2D_SPR_VPHASE),
- (pDownscalingCfg->HPhase | (((uint32_t)pDownscalingCfg->VPhase) << DMA2D_SPR_VPHASE_Pos)));
+ MODIFY_REG(hdma2d->Instance->SPR,
+ (DMA2D_SPR_HPHASE | DMA2D_SPR_VPHASE),
+ (pDownscalingCfg->HPhase |
+ ((uint32_t)pDownscalingCfg->VPhase << DMA2D_SPR_VPHASE_Pos)));
return HAL_OK;
}
@@ -2476,6 +2498,32 @@ static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_
}
#endif /* USE_DMA2D_COMMAND_LIST_MODE == 0 */
#if (USE_DMA2D_COMMAND_LIST_MODE == 1)
+/** @defgroup DMA2D_Exported_Functions_Group5 DMA2D Command List (CL) functions
+ * @brief Initialization and IO/Control functions for Command List mode
+ *
+@verbatim
+ ===============================================================================
+ ##### Command List (CL) mode functions #####
+ ===============================================================================
+ [..] This section provides functions allowing to:
+ (+) Initialize and de-initialize the DMA2D in Command List mode
+ using HAL_DMA2D_CL_Init() and HAL_DMA2D_CL_DeInit().
+ (+) Prepare command lists using APIs such as:
+ HAL_DMA2D_CL_Init_CommandList(), HAL_DMA2D_CL_AddConfigLayerCMD(),
+ HAL_DMA2D_CL_AddConfigRotationCMD(), HAL_DMA2D_CL_AddConfigStencilCMD(),
+ HAL_DMA2D_CL_AddConfigDownscalingCMD(),
+ HAL_DMA2D_CL_AddProgramLineEventCMD(), HAL_DMA2D_CL_AddCopyCMD(),
+ HAL_DMA2D_CL_AddBlendingCMD(), HAL_DMA2D_CL_AddCLUTStartLoadCMD().
+ (+) Insert prepared command lists into the ring buffer and start
+ execution using HAL_DMA2D_CL_InsertCommandList(), HAL_DMA2D_CL_Start()
+ and HAL_DMA2D_CL_StartOpt().
+ (+) Handle DMA2D CL interrupts through HAL_DMA2D_CL_IRQHandler() and
+ related callbacks, and control execution using
+ HAL_DMA2D_CL_Suspend(), HAL_DMA2D_CL_Resume() and HAL_DMA2D_CL_Abort().
+
+@endverbatim
+ * @{
+ */
/**
* @brief Initialize the DMA2D CL (Command List) Mode
* This function configures the DMA2D ring buffer according to RingBuffer parameter of DMA2D_CL_HandleTypeDef
@@ -2776,26 +2824,38 @@ HAL_StatusTypeDef HAL_DMA2D_CL_AddConfigRotationCMD(DMA2D_CL_HandleTypeDef *hdma
HAL_StatusTypeDef HAL_DMA2D_CL_AddConfigDownscalingCMD(DMA2D_CL_HandleTypeDef *const hdma2d, uint32_t Source,
DMA2D_DownscalingCfgTypeDef *pDownscalingCfg)
{
- /* HSET and VSTEP Calculation */
- uint16_t hstep = (4096 / (pDownscalingCfg->HRatio) - 1);
- uint16_t vstep = (4096 / (pDownscalingCfg->VRatio) - 1);
+ uint32_t hstep;
+ uint32_t vstep;
+ uint32_t hq12;
+ uint32_t vq12;
- /* Check the DMA2D channel handle parameter */
- if (hdma2d == NULL)
+ /* Check parameters */
+ if ((hdma2d == NULL) || (pDownscalingCfg == NULL))
{
return HAL_ERROR;
}
- /* Check parameters */
assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));
assert_param(IS_DMA2D_SCALE_SRC(Source));
- assert_param(IS_DMA2D_SCALE_HSTEP(hstep));
- assert_param(IS_DMA2D_SCALE_VSTEP(vstep));
assert_param(IS_DMA2D_SCALE_PIXEL_PER_LINE(pDownscalingCfg->PixelPerLines));
assert_param(IS_DMA2D_SCALE_NUMBER_OF_LINES(pDownscalingCfg->NumberOfLines));
assert_param(IS_DMA2D_SCALE_HPHASE(pDownscalingCfg->HPhase));
assert_param(IS_DMA2D_SCALE_VPHASE(pDownscalingCfg->VPhase));
+ if ((pDownscalingCfg->HRatioDiv == 0U) || (pDownscalingCfg->VRatioDiv == 0U))
+ {
+ return HAL_ERROR;
+ }
+
+ hq12 = (((uint32_t)pDownscalingCfg->HRatio * 4096U) / (uint32_t)pDownscalingCfg->HRatioDiv);
+ vq12 = (((uint32_t)pDownscalingCfg->VRatio * 4096U) / (uint32_t)pDownscalingCfg->VRatioDiv);
+
+ hstep = hq12 - 1U;
+ vstep = vq12 - 1U;
+
+ assert_param(IS_DMA2D_SCALE_HSTEP(hstep));
+ assert_param(IS_DMA2D_SCALE_VSTEP(vstep));
+
/* Config scaling source */
DMA2D_CL_LDM_WRITE_REG(hdma2d, DMA2D_CL_SCR_REG, Source);
@@ -2804,7 +2864,7 @@ HAL_StatusTypeDef HAL_DMA2D_CL_AddConfigDownscalingCMD(DMA2D_CL_HandleTypeDef *c
(pDownscalingCfg->PixelPerLines << DMA2D_SNLR_PL_Pos)));
/* Config scaling HSEP and VSTEP */
- DMA2D_CL_LDM_WRITE_REG(hdma2d, DMA2D_CL_SSR_REG, (hstep | (vstep << DMA2D_SSR_VSTEP_Pos)));
+ DMA2D_CL_LDM_WRITE_REG(hdma2d, DMA2D_CL_SSR_REG, (hstep |(vstep << DMA2D_SSR_VSTEP_Pos)));
/* Config scaling HPHASE and VPHASE */
DMA2D_CL_LDM_WRITE_REG(hdma2d, DMA2D_CL_SPR_REG, (pDownscalingCfg->HPhase |
@@ -2862,6 +2922,36 @@ HAL_StatusTypeDef HAL_DMA2D_CL_AddConfigStencilCMD(DMA2D_CL_HandleTypeDef *hdma2
return HAL_OK;
}
+/**
+ * @brief Configure the line watermark in Command List (CL) mode.
+ * @param hdma2d pointer to a DMA2D_CL_HandleTypeDef structure that contains the configuration information
+ * @param Line Line Watermark configuration (maximum 16-bit long value expected).
+ * @note This API programs the line watermark register and enables the transfer watermark interrupt.
+ * @retval HAL status
+ */
+HAL_StatusTypeDef HAL_DMA2D_CL_AddProgramLineEventCMD(DMA2D_CL_HandleTypeDef *hdma2d, uint32_t Line)
+{
+ /* Check the DMA2D channel handle parameter */
+ if (hdma2d == NULL)
+ {
+ return HAL_ERROR;
+ }
+
+ /* Check the parameters */
+ if (Line > DMA2D_LWR_LW)
+ {
+ return HAL_ERROR;
+ }
+
+ /* Sets the Line watermark configuration */
+ WRITE_REG(hdma2d->Instance->LWR, Line);
+
+ /* Enable the Line interrupt (transfer watermark) */
+ __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TW);
+
+ return HAL_OK;
+}
+
/**
* @brief Add a CLUT Loading operation LDM with the specified parameters in DMA2D_CLUTCfgTypeDef
* and copy the prepared LDM instructions and register values. to the chosen Command List address.
@@ -3155,17 +3245,22 @@ HAL_StatusTypeDef HAL_DMA2D_CL_Init_CommandList(uint32_t *Address, uint32_t Size
* Must be a valid pre/post flag operation.
* @retval HAL status
*/
-#define RBS_TO_RING_BUFFER_SIZE(val) (1U << ((val) + 6))
HAL_StatusTypeDef HAL_DMA2D_CL_InsertCommandList(DMA2D_CL_HandleTypeDef *hdma2d,
DMA2D_CL_CommandListTypeDef *pCommandList,
uint32_t gpflag, uint32_t post_flag_config, uint32_t pre_flag_config)
{
uint32_t write_ptr;
uint64_t *descriptor;
+
+ if ((hdma2d == NULL) || (pCommandList == NULL))
+ {
+ return HAL_ERROR;
+ }
+
uint32_t *CLaddress = (uint32_t *)pCommandList->Address;
uint32_t ring_buffer_size = RBS_TO_RING_BUFFER_SIZE(((hdma2d->Instance->CLCR & DMA2D_CLCR_RBS_Msk) >>
- DMA2D_CLCR_RBS_Pos));
+ DMA2D_CLCR_RBS_Pos));
assert_param(IS_DMA2D_CL_GPFLAG(gpflag));
@@ -3174,10 +3269,6 @@ HAL_StatusTypeDef HAL_DMA2D_CL_InsertCommandList(DMA2D_CL_HandleTypeDef *hdma2d,
assert_param(IS_DMA2D_CL_ADDRESS_VALID((uint32_t)pCommandList->Address));
assert_param(IS_DMA2D_CL_SIZE(pCommandList->Size));
- if ((hdma2d == NULL) || (pCommandList == NULL))
- {
- return HAL_ERROR;
- }
if (pCommandList->Address[pCommandList->Index] != 0xFFFFFFFF)
{
@@ -3507,15 +3598,15 @@ void HAL_DMA2D_CL_IRQHandler(DMA2D_CL_HandleTypeDef *hdma2d)
__HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CLE);
/* Check the error source */
- if ((clsrflags & DMA2D_CLSR_LCLMSE) != 0U)
+ if ((clsrflags & DMA2D_FLAG_LCLMSE) != 0U)
{
hdma2d->ErrorCode |= HAL_DMA2D_ERROR_LCLMSE;
}
- if ((clsrflags & DMA2D_CLSR_LCLIE) != 0U)
+ if ((clsrflags & DMA2D_FLAG_LCLIE) != 0U)
{
hdma2d->ErrorCode |= HAL_DMA2D_ERROR_LCLIE ;
}
- if ((clsrflags & DMA2D_CLSR_LCLRE) != 0U)
+ if ((clsrflags & DMA2D_FLAG_LCLRE) != 0U)
{
hdma2d->ErrorCode |= HAL_DMA2D_ERROR_LCLRE;
}
@@ -4125,6 +4216,10 @@ HAL_StatusTypeDef HAL_DMA2D_CL_UnRegister_GeneralPurposeEvent_Callback(DMA2D_CL_
}
#endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
+/**
+ * @}
+ */
+
/** @defgroup DMA2D_Exported_Functions_Group4 Peripheral State and Error functions
* @brief Peripheral State functions
*
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth.c
index 0405a17d5c..bc8bf23b6c 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth.c
@@ -196,11 +196,13 @@
* @{
*/
#define ETH_MACCR_MASK 0xFFFB7F7CU
-#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx)
+#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) \
+ || defined(STM32H553xx) || defined(STM32H543xx)
#define ETH_MACECR_MASK 0x7F077FFFU
#else
#define ETH_MACECR_MASK 0x3F077FFFU
-#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) */
+#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) ||
+ defined(STM32H553xx) || defined(STM32H543xx) */
#define ETH_MACPFR_MASK 0x800007FFU
#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) \
|| defined(STM32H553xx) || defined(STM32H543xx)
@@ -216,11 +218,13 @@
#define ETH_DMAMR_MASK 0x00007802U
#define ETH_DMASBMR_MASK 0x0000D001U
-#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx)
+#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) \
+ || defined(STM32H553xx) || defined(STM32H543xx)
#define ETH_DMACCR_MASK 0x04013FFFU
#else
#define ETH_DMACCR_MASK 0x00013FFFU
-#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) */
+#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) ||
+ defined(STM32H553xx) || defined(STM32H543xx) */
#define ETH_DMACTCR_MASK 0x003F1010U
#define ETH_DMACRCR_MASK 0x803F0000U
#define ETH_MACPCSR_MASK (ETH_MACPCSR_PWRDWN | ETH_MACPCSR_RWKPKTEN | \
@@ -232,11 +236,13 @@
ETH_DMARXNDESCWBF_OE | ETH_DMARXNDESCWBF_RWT |\
ETH_DMARXNDESCWBF_GP | ETH_DMARXNDESCWBF_CE))
-#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx)
+#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) \
+ || defined(STM32H553xx) || defined(STM32H543xx)
#define ETH_MACTSCR_MASK 0x3F07FF6FU
#else
#define ETH_MACTSCR_MASK 0x0087FF2FU
-#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) */
+#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) ||
+ defined(STM32H553xx) || defined(STM32H543xx) */
#define ETH_MACSTSUR_VALUE 0xFFFFFFFFU
#define ETH_MACSTNUR_VALUE 0xBB9ACA00U
@@ -1562,12 +1568,14 @@ HAL_StatusTypeDef HAL_ETH_PTP_SetConfig(ETH_HandleTypeDef *heth, ETH_PTP_ConfigT
((uint32_t)ptpconfig->TimestampMaster << ETH_MACTSCR_TSMSTRENA_Pos) |
((uint32_t)ptpconfig->TimestampSnapshots << ETH_MACTSCR_SNAPTYPSEL_Pos) |
((uint32_t)ptpconfig->TimestampFilter << ETH_MACTSCR_TSENMACADDR_Pos) |
-#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx)
+#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) \
+ || defined(STM32H553xx) || defined(STM32H543xx)
((uint32_t)ptpconfig->TimestampPCS << ETH_MACTSCR_EPCSL_Pos) |
((uint32_t)ptpconfig->TimestampCapturing << ETH_MACTSCR_ECPD_Pos) |
((uint32_t)ptpconfig->TimestampLatencyAccuracy << ETH_MACTSCR_LITA_Pos) |
((uint32_t)ptpconfig->AV8021ASMEN << ETH_MACTSCR_AV8021ASMEN_Pos) |
-#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) */
+#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) ||
+ defined(STM32H553xx) || defined(STM32H543xx) */
((uint32_t)ptpconfig->TimestampStatusMode << ETH_MACTSCR_TXTSSTSM_Pos);
/* Write to MACTSCR */
@@ -1651,14 +1659,15 @@ HAL_StatusTypeDef HAL_ETH_PTP_GetConfig(ETH_HandleTypeDef *heth, ETH_PTP_ConfigT
ptpconfig->TimestampFilter = ((READ_BIT(heth->Instance->MACTSCR,
ETH_MACTSCR_TSENMACADDR) >> ETH_MACTSCR_TSENMACADDR_Pos) > 0U)
? ENABLE : DISABLE;
-#if !defined(STM32H5E5xx) && !defined(STM32H5E4xx) && !defined(STM32H5F5xx) && !defined(STM32H5F4xx)
+#if defined(STM32H563xx) || defined(STM32H573xx)
ptpconfig->TimestampChecksumCorrection = ((READ_BIT(heth->Instance->MACTSCR,
ETH_MACTSCR_CSC) >> ETH_MACTSCR_CSC_Pos) > 0U) ? ENABLE : DISABLE;
-#endif /* !defined(STM32H5E5xx) && !defined(STM32H5E4xx) && !defined(STM32H5F5xx) && !defined(STM32H5F4xx) */
+#endif /* defined(STM32H563xx) || defined(STM32H573xx) */
ptpconfig->TimestampStatusMode = ((READ_BIT(heth->Instance->MACTSCR,
ETH_MACTSCR_TXTSSTSM) >> ETH_MACTSCR_TXTSSTSM_Pos) > 0U)
? ENABLE : DISABLE;
-#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx)
+#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) \
+ || defined(STM32H553xx) || defined(STM32H543xx)
ptpconfig->TimestampPCS = ((READ_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_EPCSL) >>
ETH_MACTSCR_EPCSL_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampCapturing = ((READ_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_ECPD) >>
@@ -1667,7 +1676,8 @@ HAL_StatusTypeDef HAL_ETH_PTP_GetConfig(ETH_HandleTypeDef *heth, ETH_PTP_ConfigT
ETH_MACTSCR_LITA_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->AV8021ASMEN = ((READ_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_AV8021ASMEN) >>
ETH_MACTSCR_AV8021ASMEN_Pos) > 0U) ? ENABLE : DISABLE;
-#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) */
+#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) ||
+ defined(STM32H553xx) || defined(STM32H543xx) */
/* Return function status */
return HAL_OK;
@@ -1692,7 +1702,7 @@ HAL_StatusTypeDef HAL_ETH_PTP_SetTime(ETH_HandleTypeDef *heth, ETH_TimeTypeDef *
heth->Instance->MACSTNUR = time->NanoSeconds;
/* the system time is updated */
- SET_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_TSUPDT);
+ SET_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_TSINIT);
/* Return function status */
return HAL_OK;
@@ -3037,9 +3047,11 @@ static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth)
macDefaultConf.PauseTime = 0x0U;
macDefaultConf.PreambleLength = ETH_PREAMBLELENGTH_7;
macDefaultConf.ProgrammableWatchdog = DISABLE;
-#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx)
+#if defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) \
+ || defined(STM32H553xx) || defined(STM32H543xx)
macDefaultConf.ProgrammableJabber = DISABLE;
-#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) */
+#endif /* defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H5F5xx) || defined(STM32H5F4xx) ||
+ defined(STM32H553xx) || defined(STM32H543xx) */
macDefaultConf.ReceiveFlowControl = DISABLE;
macDefaultConf.ReceiveOwn = ENABLE;
macDefaultConf.ReceiveQueueMode = ETH_RECEIVESTOREFORWARD;
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth_ex.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth_ex.c
index 6a6ca98fa8..84db7bc96c 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth_ex.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_eth_ex.c
@@ -296,16 +296,16 @@ HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t
/* 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]);
+ WRITE_REG(heth->Instance->MACL3A2R1R, pL3FilterConfig->Ip6Addr[2]);
/* update Bits[127:96] of 128-bit IP addr */
- WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip6Addr[3]);
+ WRITE_REG(heth->Instance->MACL3A3R1R, 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);
+ WRITE_REG(heth->Instance->MACL3A1R1R, pL3FilterConfig->Ip4DestAddr);
}
}
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash.c
index fd8e3bfcd4..db0ce2cb4a 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash.c
@@ -554,6 +554,13 @@ __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
/**
* @brief Unlock the FLASH control registers access
+ * @note When called from secure context on TrustZone-enabled devices,
+ * this function unlocks BOTH secure and non-secure FLASH control
+ * registers. This prevents non-secure code from controlling its
+ * own FLASH access independently until a new unlock sequence is
+ * performed.
+ * For per-domain control, use HAL_FLASH_Unlock_S(),
+ * HAL_FLASH_Unlock_NS() instead.
* @retval HAL Status
*/
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
@@ -596,6 +603,11 @@ HAL_StatusTypeDef HAL_FLASH_Unlock(void)
/**
* @brief Locks the FLASH control registers access
+ * @note When called from secure context on TrustZone-enabled devices,
+ * this function locks BOTH secure and non-secure FLASH control
+ * registers. This may interfere with ongoing non-secure FLASH
+ * operations. For per-domain control, use HAL_FLASH_Lock_S(),
+ * HAL_FLASH_Lock_NS() instead.
* @retval HAL Status
*/
HAL_StatusTypeDef HAL_FLASH_Lock(void)
@@ -628,6 +640,94 @@ HAL_StatusTypeDef HAL_FLASH_Lock(void)
return status;
}
+/**
+ * @brief Unlock the non-secure FLASH control registers access
+ * @retval HAL Status
+ */
+HAL_StatusTypeDef HAL_FLASH_Unlock_NS(void)
+{
+ HAL_StatusTypeDef status = HAL_OK;
+
+ if (READ_BIT(FLASH->NSCR, FLASH_CR_LOCK) != 0U)
+ {
+ /* Authorize the FLASH Control Register access */
+ WRITE_REG(FLASH->NSKEYR, FLASH_KEY1);
+ WRITE_REG(FLASH->NSKEYR, FLASH_KEY2);
+
+ /* Verify Flash CR is unlocked */
+ if (READ_BIT(FLASH->NSCR, FLASH_CR_LOCK) != 0U)
+ {
+ status = HAL_ERROR;
+ }
+ }
+ return status;
+}
+
+/**
+ * @brief Lock the non-secure FLASH control registers access
+ * @retval HAL Status
+ */
+HAL_StatusTypeDef HAL_FLASH_Lock_NS(void)
+{
+ HAL_StatusTypeDef status = HAL_OK;
+
+ /* Set the LOCK Bit to lock the FLASH Control Register access */
+ SET_BIT(FLASH->NSCR, FLASH_CR_LOCK);
+
+ /* Verify Flash is locked */
+ if (READ_BIT(FLASH->NSCR, FLASH_CR_LOCK) == 0U)
+ {
+ status = HAL_ERROR;
+ }
+ return status;
+}
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+/**
+ * @brief Unlock the secure FLASH control registers access
+ * @retval HAL Status
+ */
+HAL_StatusTypeDef HAL_FLASH_Unlock_S(void)
+{
+ HAL_StatusTypeDef status = HAL_OK;
+
+ if (READ_BIT(FLASH->SECCR, FLASH_CR_LOCK) != 0U)
+ {
+ /* Authorize the FLASH Control Register access */
+ WRITE_REG(FLASH->SECKEYR, FLASH_KEY1);
+ WRITE_REG(FLASH->SECKEYR, FLASH_KEY2);
+
+ /* verify Flash CR is unlocked */
+ if (READ_BIT(FLASH->SECCR, FLASH_CR_LOCK) != 0U)
+ {
+ status = HAL_ERROR;
+ }
+ }
+
+ return status;
+}
+
+/**
+ * @brief Lock the secure FLASH control registers access
+ * @retval HAL Status
+ */
+HAL_StatusTypeDef HAL_FLASH_Lock_S(void)
+{
+ HAL_StatusTypeDef status = HAL_OK;
+
+ /* Set the LOCK Bit to lock the FLASH Control Register access */
+ SET_BIT(FLASH->SECCR, FLASH_CR_LOCK);
+
+ /* verify Flash is locked */
+ if (READ_BIT(FLASH->SECCR, FLASH_CR_LOCK) == 0U)
+ {
+ status = HAL_ERROR;
+ }
+
+ return status;
+}
+#endif /* __ARM_FEATURE_CMSE && __ARM_FEATURE_CMSE == 3U */
+
/**
* @brief Unlock the FLASH Option Control Registers access.
* @retval HAL Status
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_i3c.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_i3c.c
index 9006937e5b..213fcb2da3 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_i3c.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_i3c.c
@@ -135,6 +135,9 @@
(#) To check if I2C target device is ready for communication, use the function HAL_I3C_Ctrl_IsDeviceI2C_Ready()
(#) To send a message header {S + 0x7E + W + STOP}, use the function HAL_I3C_Ctrl_GenerateArbitration().
+
+ (#) To send a target reset pattern or HDR exit pattern, use the function HAL_I3C_Ctrl_GeneratePattern().
+
(#) To insert a target reset pattern before the STOP of a transmitted frame containing a RSTACT CCC command,
the application must enable the reset pattern configuration using HAL_I3C_Ctrl_SetConfigResetPattern()
before calling HAL_I3C_Ctrl_TransmitCCC() or HAL_I3C_Ctrl_ReceiveCCC() interfaces.
@@ -1615,10 +1618,14 @@ void HAL_I3C_ER_IRQHandler(I3C_HandleTypeDef *hi3c)
*/
void HAL_I3C_EV_IRQHandler(I3C_HandleTypeDef *hi3c) /* Derogation MISRAC2012-Rule-8.13 */
{
+#if defined(I3C_MISR_CFNFMIS)
+ uint32_t it_masks = READ_REG(hi3c->Instance->MISR);
+#else
uint32_t it_flags = READ_REG(hi3c->Instance->EVR);
uint32_t it_sources = READ_REG(hi3c->Instance->IER);
uint32_t it_masks = (uint32_t)(it_flags & it_sources);
+#endif /* I3C_MISR_CFNFMIS */
/* I3C events treatment */
if (hi3c->XferISR != NULL)
@@ -1911,6 +1918,11 @@ HAL_StatusTypeDef HAL_I3C_Ctrl_Config(I3C_HandleTypeDef *hi3c, const I3C_CtrlCon
assert_param(IS_I3C_DYNAMICADDRESS_VALUE(pConfig->DynamicAddr));
assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->HighKeeperSDA));
assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->HotJoinAllowed));
+#if defined(I3C_TIMINGR2_STALLL)
+ assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->ACKI2CAddrState));
+ assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->ACKI2CWriteState));
+ assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->ACKI2CReadState));
+#endif /* I3C_TIMINGR2_STALLL */
assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->ACKStallState));
assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->CCCStallState));
assert_param(IS_I3C_FUNCTIONALSTATE_VALUE(pConfig->TxStallState));
@@ -1921,6 +1933,11 @@ HAL_StatusTypeDef HAL_I3C_Ctrl_Config(I3C_HandleTypeDef *hi3c, const I3C_CtrlCon
/* Calculate value to be written in timing register 2 */
timing2_value = (((uint32_t)pConfig->StallTime << I3C_TIMINGR2_STALL_Pos) |
+#if defined(I3C_TIMINGR2_STALLL)
+ ((uint32_t)pConfig->ACKI2CAddrState << I3C_TIMINGR2_STALLL_Pos) |
+ ((uint32_t)pConfig->ACKI2CWriteState << I3C_TIMINGR2_STALLS_Pos) |
+ ((uint32_t)pConfig->ACKI2CReadState << I3C_TIMINGR2_STALLR_Pos) |
+#endif /* I3C_TIMINGR2_STALLL */
((uint32_t)pConfig->ACKStallState << I3C_TIMINGR2_STALLA_Pos) |
((uint32_t)pConfig->CCCStallState << I3C_TIMINGR2_STALLC_Pos) |
((uint32_t)pConfig->TxStallState << I3C_TIMINGR2_STALLD_Pos) |
@@ -2716,6 +2733,8 @@ HAL_StatusTypeDef HAL_I3C_GetConfigFifo(I3C_HandleTypeDef *hi3c, I3C_FifoConfTyp
during the Dynamic Address Assignment processus.
(+) Call the function HAL_I3C_Ctrl_IsDeviceI3C_Ready() to check if I3C target device is ready.
(+) Call the function HAL_I3C_Ctrl_IsDeviceI2C_Ready() to check if I2C target device is ready.
+ (+) Call the function HAL_I3C_Ctrl_GeneratePatterns() to send target reset pattern or HDR exit pattern with
+ arbitration in polling mode
(+) Call the function HAL_I3C_Ctrl_GenerateArbitration to send arbitration
(message header {S + 0x7E + W + STOP}) in polling mode
@@ -5118,6 +5137,8 @@ HAL_StatusTypeDef HAL_I3C_Ctrl_DynAddrAssign(I3C_HandleTypeDef *hi3c,
/* Check TX FIFO not full flag */
if (__HAL_I3C_GET_FLAG(hi3c, HAL_I3C_FLAG_TXFNFF) == SET)
{
+ *target_payload = 0UL;
+
/* Check on the Rx FIFO threshold to know the Rx treatment process : byte or word */
if (LL_I3C_GetRxFIFOThreshold(hi3c->Instance) == LL_I3C_RXFIFO_THRESHOLD_1_4)
{
@@ -5352,6 +5373,123 @@ HAL_StatusTypeDef HAL_I3C_Ctrl_IsDeviceI2C_Ready(I3C_HandleTypeDef *hi3c,
return status;
}
+/**
+ * @brief Controller generates patterns (target reset pattern or HDR exit pattern) with arbitration in polling mode.
+ * @param hi3c : [IN] Pointer to an I3C_HandleTypeDef structure that contains
+ * the configuration information for the specified I3C.
+ * @param pattern : [IN] Specifies the generated pattern.
+ * It can be a value of @ref I3C_PATTERN_CONFIGURATION
+ * @param timeout : [IN] Timeout duration
+ * @retval HAL Status : Value from HAL_StatusTypeDef enumeration.
+ */
+HAL_StatusTypeDef HAL_I3C_Ctrl_GeneratePatterns(I3C_HandleTypeDef *hi3c, uint32_t pattern, uint32_t timeout)
+{
+ HAL_StatusTypeDef status = HAL_OK;
+ HAL_I3C_StateTypeDef handle_state;
+ __IO uint32_t exit_condition;
+ uint32_t tickstart;
+
+ /* check on the handle */
+ if (hi3c == NULL)
+ {
+ status = HAL_ERROR;
+ }
+ else
+ {
+ /* Check the instance and the mode parameters */
+ assert_param(IS_I3C_ALL_INSTANCE(hi3c->Instance));
+ assert_param(IS_I3C_MODE(hi3c->Mode));
+ assert_param(IS_I3C_PATTERN(pattern));
+
+ /* Get I3C handle state */
+ handle_state = hi3c->State;
+
+ /* check on the Mode */
+ if (hi3c->Mode != HAL_I3C_MODE_CONTROLLER)
+ {
+ hi3c->ErrorCode = HAL_I3C_ERROR_NOT_ALLOWED;
+ status = HAL_ERROR;
+ }
+ /* check on the State */
+ else if ((handle_state != HAL_I3C_STATE_READY) && (handle_state != HAL_I3C_STATE_LISTEN))
+ {
+ status = HAL_BUSY;
+ }
+ else
+ {
+ hi3c->State = HAL_I3C_STATE_BUSY;
+
+ /* The target reset pattern is sent after the issued message header */
+ if (pattern == HAL_I3C_TARGET_RESET_PATTERN)
+ {
+ /* Enable reset pattern */
+ LL_I3C_EnableResetPattern(hi3c->Instance);
+
+ /* Disable exit pattern */
+ LL_I3C_DisableExitPattern(hi3c->Instance);
+ }
+ /* The HDR exit pattern is sent after the issued message header */
+ else
+ {
+ /* Disable reset pattern */
+ LL_I3C_DisableResetPattern(hi3c->Instance);
+
+ /* Enable exit pattern */
+ LL_I3C_EnableExitPattern(hi3c->Instance);
+ }
+
+ /* Write message control register */
+ WRITE_REG(hi3c->Instance->CR, LL_I3C_CONTROLLER_MTYPE_HEADER | LL_I3C_GENERATE_STOP);
+
+ /* Calculate exit_condition value based on Frame complete and error flags */
+ exit_condition = (READ_REG(hi3c->Instance->EVR) & (I3C_EVR_FCF | I3C_EVR_ERRF));
+
+ tickstart = HAL_GetTick();
+
+ while (exit_condition == 0U)
+ {
+ if (timeout != HAL_MAX_DELAY)
+ {
+ if (((HAL_GetTick() - tickstart) > timeout) || (timeout == 0U))
+ {
+ /* Update I3C error code */
+ hi3c->ErrorCode |= HAL_I3C_ERROR_TIMEOUT;
+ status = HAL_TIMEOUT;
+
+ break;
+ }
+ }
+ /* Calculate exit_condition value based on Frame complete and error flags */
+ exit_condition = (READ_REG(hi3c->Instance->EVR) & (I3C_EVR_FCF | I3C_EVR_ERRF));
+ }
+
+ if (status == HAL_OK)
+ {
+ /* Check if the FCF flag has been set */
+ if (__HAL_I3C_GET_FLAG(hi3c, I3C_EVR_FCF) == SET)
+ {
+ /* Clear frame complete flag */
+ LL_I3C_ClearFlag_FC(hi3c->Instance);
+ }
+ else
+ {
+ /* Clear error flag */
+ LL_I3C_ClearFlag_ERR(hi3c->Instance);
+
+ /* Update handle error code parameter */
+ I3C_GetErrorSources(hi3c);
+
+ /* Update returned status value */
+ status = HAL_ERROR;
+ }
+ }
+ /* At the end of Rx process update state to Previous state */
+ I3C_StateUpdate(hi3c);
+ }
+ }
+
+ return status;
+}
/**
* @brief Controller generates arbitration (message header {S/Sr + 0x7E addr + W}) in polling mode.
@@ -7177,14 +7315,22 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
uint32_t tmpevent = 0U;
/* I3C Rx FIFO not empty interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_RXFNEMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, HAL_I3C_FLAG_RXFNEF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Call receive treatment function */
hi3c->ptrRxFunc(hi3c);
}
/* I3C target complete controller-role hand-off procedure (direct GETACCR CCC) event management --------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_CRUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CRUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear controller-role update flag */
LL_I3C_ClearFlag_CRUPD(hi3c->Instance);
@@ -7194,7 +7340,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive any direct GETxxx CCC event management -------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_GETMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_GETF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear GETxxx CCC flag */
LL_I3C_ClearFlag_GET(hi3c->Instance);
@@ -7204,7 +7354,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive get status command (direct GETSTATUS CCC) event management -----------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_STAMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_STAF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear GETSTATUS CCC flag */
LL_I3C_ClearFlag_STA(hi3c->Instance);
@@ -7214,7 +7368,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive a dynamic address update (ENTDAA/RSTDAA/SETNEWDA CCC) event management -----------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_DAUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_DAUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear dynamic address update flag */
LL_I3C_ClearFlag_DAUPD(hi3c->Instance);
@@ -7224,7 +7382,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive maximum write length update (direct SETMWL CCC) event management -----------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_MWLUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_MWLUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear SETMWL CCC flag */
LL_I3C_ClearFlag_MWLUPD(hi3c->Instance);
@@ -7234,7 +7396,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive maximum read length update(direct SETMRL CCC) event management -------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_MRLUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_MRLUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear SETMRL CCC flag */
LL_I3C_ClearFlag_MRLUPD(hi3c->Instance);
@@ -7244,7 +7410,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target detect reset pattern (broadcast or direct RSTACT CCC) event management -------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_RSTMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_RSTF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear reset pattern flag */
LL_I3C_ClearFlag_RST(hi3c->Instance);
@@ -7254,7 +7424,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive activity state update (direct or broadcast ENTASx) CCC event management ----------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_ASUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_ASUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear ENTASx CCC flag */
LL_I3C_ClearFlag_ASUPD(hi3c->Instance);
@@ -7264,7 +7438,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive a direct or broadcast ENEC/DISEC CCC event management ----------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_INTUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_INTUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear ENEC/DISEC CCC flag */
LL_I3C_ClearFlag_INTUPD(hi3c->Instance);
@@ -7274,7 +7452,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive a broadcast DEFTGTS CCC event management -----------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_DEFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_DEFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear DEFTGTS CCC flag */
LL_I3C_ClearFlag_DEF(hi3c->Instance);
@@ -7284,7 +7466,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target receive a group addressing (broadcast DEFGRPA CCC) event management ----------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_GRPMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_GRPF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear DEFGRPA CCC flag */
LL_I3C_ClearFlag_GRP(hi3c->Instance);
@@ -7294,7 +7480,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
}
/* I3C target wakeup event management ----------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_WKPMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_WKPF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear WKP flag */
LL_I3C_ClearFlag_WKP(hi3c->Instance);
@@ -7330,7 +7520,11 @@ static HAL_StatusTypeDef I3C_Tgt_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uin
static HAL_StatusTypeDef I3C_Ctrl_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_t itMasks)
{
/* I3C controller receive IBI event management ---------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_IBIMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_IBIF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear IBI request flag */
LL_I3C_ClearFlag_IBI(hi3c->Instance);
@@ -7345,7 +7539,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Event_ISR(struct __I3C_HandleTypeDef *hi3c, ui
}
/* I3C controller controller-role request event management ---------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CRMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CRF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear controller-role request flag */
LL_I3C_ClearFlag_CR(hi3c->Instance);
@@ -7360,7 +7558,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Event_ISR(struct __I3C_HandleTypeDef *hi3c, ui
}
/* I3C controller hot-join event management ------------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_HJMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_HJF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear hot-join flag */
LL_I3C_ClearFlag_HJ(hi3c->Instance);
@@ -7390,7 +7592,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Event_ISR(struct __I3C_HandleTypeDef *hi3c, ui
static HAL_StatusTypeDef I3C_Tgt_HotJoin_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_t itMasks)
{
/* I3C target receive a dynamic address update event management */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_DAUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_DAUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear dynamic address update flag */
LL_I3C_ClearFlag_DAUPD(hi3c->Instance);
@@ -7435,7 +7641,11 @@ static HAL_StatusTypeDef I3C_Tgt_HotJoin_ISR(struct __I3C_HandleTypeDef *hi3c, u
static HAL_StatusTypeDef I3C_Tgt_CtrlRole_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_t itMasks)
{
/* I3C target complete controller-role hand-off procedure (direct GETACCR CCC) event management -------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_CRUPDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CRUPDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear controller-role update flag */
LL_I3C_ClearFlag_CRUPD(hi3c->Instance);
@@ -7469,7 +7679,11 @@ static HAL_StatusTypeDef I3C_Tgt_CtrlRole_ISR(struct __I3C_HandleTypeDef *hi3c,
static HAL_StatusTypeDef I3C_Tgt_IBI_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_t itMasks)
{
/* I3C target IBI end process event management ---------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_IBIENDMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_IBIENDF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear IBI end flag */
LL_I3C_ClearFlag_IBIEND(hi3c->Instance);
@@ -7506,7 +7720,11 @@ static HAL_StatusTypeDef I3C_Tgt_Tx_ISR(struct __I3C_HandleTypeDef *hi3c, uint32
if (hi3c->State == HAL_I3C_STATE_BUSY_TX)
{
/* I3C Tx FIFO not full interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_TXFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_TXFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->TxXferCount > 0U)
{
@@ -7516,7 +7734,11 @@ static HAL_StatusTypeDef I3C_Tgt_Tx_ISR(struct __I3C_HandleTypeDef *hi3c, uint32
}
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -7549,7 +7771,11 @@ static HAL_StatusTypeDef I3C_Tgt_Tx_ISR(struct __I3C_HandleTypeDef *hi3c, uint32
}
/* I3C target wakeup event management ----------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_WKPMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_WKPF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear WKP flag */
LL_I3C_ClearFlag_WKP(hi3c->Instance);
@@ -7580,7 +7806,11 @@ static HAL_StatusTypeDef I3C_Tgt_Rx_ISR(struct __I3C_HandleTypeDef *hi3c, uint32
if (hi3c->State == HAL_I3C_STATE_BUSY_RX)
{
/* I3C Rx FIFO not empty interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_RXFNEMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, HAL_I3C_FLAG_RXFNEF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->RxXferCount > 0U)
{
@@ -7590,7 +7820,11 @@ static HAL_StatusTypeDef I3C_Tgt_Rx_ISR(struct __I3C_HandleTypeDef *hi3c, uint32
}
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -7623,7 +7857,11 @@ static HAL_StatusTypeDef I3C_Tgt_Rx_ISR(struct __I3C_HandleTypeDef *hi3c, uint32
}
/* I3C target wakeup event management ----------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_WKPMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_WKPF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear WKP flag */
LL_I3C_ClearFlag_WKP(hi3c->Instance);
@@ -7655,7 +7893,11 @@ static HAL_StatusTypeDef I3C_Tgt_Tx_DMA_ISR(struct __I3C_HandleTypeDef *hi3c, ui
if (hi3c->State == HAL_I3C_STATE_BUSY_TX)
{
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -7691,7 +7933,11 @@ static HAL_StatusTypeDef I3C_Tgt_Tx_DMA_ISR(struct __I3C_HandleTypeDef *hi3c, ui
}
/* I3C target wakeup event management ----------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_WKPMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_WKPF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear WKP flag */
LL_I3C_ClearFlag_WKP(hi3c->Instance);
@@ -7722,7 +7968,11 @@ static HAL_StatusTypeDef I3C_Tgt_Rx_DMA_ISR(struct __I3C_HandleTypeDef *hi3c, ui
if (hi3c->State == HAL_I3C_STATE_BUSY_RX)
{
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -7758,7 +8008,11 @@ static HAL_StatusTypeDef I3C_Tgt_Rx_DMA_ISR(struct __I3C_HandleTypeDef *hi3c, ui
}
/* I3C target wakeup event management ----------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_WKPMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_WKPF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear WKP flag */
LL_I3C_ClearFlag_WKP(hi3c->Instance);
@@ -7790,7 +8044,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Tx_ISR(struct __I3C_HandleTypeDef *hi3c, uint3
if (hi3c->State == HAL_I3C_STATE_BUSY_TX)
{
/* Check if Control FIFO requests data */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->ControlXferCount > 0U)
{
@@ -7800,7 +8058,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Tx_ISR(struct __I3C_HandleTypeDef *hi3c, uint3
}
/* I3C Tx FIFO not full interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_TXFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_TXFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->TxXferCount > 0U)
{
@@ -7810,7 +8072,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Tx_ISR(struct __I3C_HandleTypeDef *hi3c, uint3
}
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -7865,7 +8131,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_ISR(struct __I3C_HandleTypeDef *hi3c, uint3
if (hi3c->State == HAL_I3C_STATE_BUSY_RX)
{
/* Check if Control FIFO requests data */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->ControlXferCount > 0U)
{
@@ -7875,7 +8145,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_ISR(struct __I3C_HandleTypeDef *hi3c, uint3
}
/* I3C Rx FIFO not empty interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_RXFNEMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, HAL_I3C_FLAG_RXFNEF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->RxXferCount > 0U)
{
@@ -7885,7 +8159,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_ISR(struct __I3C_HandleTypeDef *hi3c, uint3
}
/* I3C Tx FIFO not full interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_TXFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_TXFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->TxXferCount > 0U)
{
@@ -7895,7 +8173,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_ISR(struct __I3C_HandleTypeDef *hi3c, uint3
}
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -7949,7 +8231,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_ISR(struct __I3C_HandleTypeDef *
if (hi3c->State == HAL_I3C_STATE_BUSY_TX_RX)
{
/* Check if Control FIFO requests data */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->ControlXferCount > 0U)
{
@@ -7959,7 +8245,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_ISR(struct __I3C_HandleTypeDef *
}
/* I3C Tx FIFO not full interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_TXFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_TXFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->TxXferCount > 0U)
{
@@ -7969,7 +8259,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_ISR(struct __I3C_HandleTypeDef *
}
/* I3C Rx FIFO not empty interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_RXFNEMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, HAL_I3C_FLAG_RXFNEF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (hi3c->RxXferCount > 0U)
{
@@ -7979,7 +8273,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_ISR(struct __I3C_HandleTypeDef *
}
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -8027,7 +8325,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_ISR(struct __I3C_HandleTypeDef *
static HAL_StatusTypeDef I3C_Ctrl_Tx_Listen_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_t itMasks)
{
/* I3C controller receive IBI event management ---------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_IBIMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_IBIF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear IBI request flag */
LL_I3C_ClearFlag_IBI(hi3c->Instance);
@@ -8042,7 +8344,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Tx_Listen_Event_ISR(struct __I3C_HandleTypeDef
}
/* I3C controller controller-role request event management ---------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CRMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CRF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear controller-role request flag */
LL_I3C_ClearFlag_CR(hi3c->Instance);
@@ -8057,7 +8363,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Tx_Listen_Event_ISR(struct __I3C_HandleTypeDef
}
/* I3C controller hot-join event management ------------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_HJMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_HJF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear hot-join flag */
LL_I3C_ClearFlag_HJ(hi3c->Instance);
@@ -8085,7 +8395,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Tx_Listen_Event_ISR(struct __I3C_HandleTypeDef
static HAL_StatusTypeDef I3C_Ctrl_Rx_Listen_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_t itMasks)
{
/* I3C controller receive IBI event management ---------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_IBIMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_IBIF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear IBI request flag */
LL_I3C_ClearFlag_IBI(hi3c->Instance);
@@ -8100,7 +8414,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_Listen_Event_ISR(struct __I3C_HandleTypeDef
}
/* I3C controller controller-role request event management ---------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CRMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CRF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear controller-role request flag */
LL_I3C_ClearFlag_CR(hi3c->Instance);
@@ -8115,7 +8433,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_Listen_Event_ISR(struct __I3C_HandleTypeDef
}
/* I3C controller hot-join event management ------------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_HJMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_HJF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear hot-join flag */
LL_I3C_ClearFlag_HJ(hi3c->Instance);
@@ -8144,7 +8466,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_Listen_Event_ISR(struct __I3C_HandleTypeDef
static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_Listen_Event_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_t itMasks)
{
/* I3C controller receive IBI event management ---------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_IBIMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_IBIF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear IBI request flag */
LL_I3C_ClearFlag_IBI(hi3c->Instance);
@@ -8159,7 +8485,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_Listen_Event_ISR(struct __I3C_Ha
}
/* I3C controller controller-role request event management ---------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CRMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CRF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear controller-role request flag */
LL_I3C_ClearFlag_CR(hi3c->Instance);
@@ -8174,7 +8504,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_Listen_Event_ISR(struct __I3C_Ha
}
/* I3C controller hot-join event management ------------------------------------------------------------------------*/
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_HJMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_HJF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear hot-join flag */
LL_I3C_ClearFlag_HJ(hi3c->Instance);
@@ -8206,14 +8540,22 @@ static HAL_StatusTypeDef I3C_Ctrl_DAA_ISR(struct __I3C_HandleTypeDef *hi3c, uint
if (hi3c->State == HAL_I3C_STATE_BUSY_DAA)
{
/* I3C Control FIFO not full interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_CFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_CFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Write ENTDAA CCC information in the control register */
LL_I3C_ControllerHandleCCC(hi3c->Instance, I3C_BROADCAST_ENTDAA, 0U, LL_I3C_GENERATE_STOP);
}
/* I3C Tx FIFO not full interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_TXFNFMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_TXFNFF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Check on the Rx FIFO threshold to know the Dynamic Address Assignment treatment process : byte or word */
if (LL_I3C_GetRxFIFOThreshold(hi3c->Instance) == LL_I3C_RXFIFO_THRESHOLD_1_4)
@@ -8243,7 +8585,11 @@ static HAL_StatusTypeDef I3C_Ctrl_DAA_ISR(struct __I3C_HandleTypeDef *hi3c, uint
}
/* I3C frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -8281,7 +8627,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Tx_DMA_ISR(struct __I3C_HandleTypeDef *hi3c, u
if (hi3c->State == HAL_I3C_STATE_BUSY_TX)
{
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -8349,7 +8699,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Rx_DMA_ISR(struct __I3C_HandleTypeDef *hi3c, u
if (hi3c->State == HAL_I3C_STATE_BUSY_RX)
{
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -8417,7 +8771,11 @@ static HAL_StatusTypeDef I3C_Ctrl_Multiple_Xfer_DMA_ISR(struct __I3C_HandleTypeD
if (hi3c->State == HAL_I3C_STATE_BUSY_TX_RX)
{
/* I3C target frame complete event Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
@@ -8492,7 +8850,11 @@ static HAL_StatusTypeDef I3C_Abort_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_
if (hi3c->State == HAL_I3C_STATE_ABORT)
{
/* I3C Rx FIFO not empty interrupt Check */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_RXFNEMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, HAL_I3C_FLAG_RXFNEF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
if (LL_I3C_IsActiveFlag_DOVR(hi3c->Instance) == 1U)
{
@@ -8504,7 +8866,11 @@ static HAL_StatusTypeDef I3C_Abort_ISR(struct __I3C_HandleTypeDef *hi3c, uint32_
/* I3C Abort frame complete event Check */
/* Evenif abort is called, the Frame completion can arrive if abort is requested at the end of the processus */
/* Evenif completion occurs, treat this end of processus as abort completion process */
+#if defined(I3C_MISR_CFNFMIS)
+ if (I3C_CHECK_FLAG(itMasks, HAL_I3C_IT_MASKS_FCMIS) != RESET)
+#else
if (I3C_CHECK_FLAG(itMasks, I3C_EVR_FCF) != RESET)
+#endif /* I3C_MISR_CFNFMIS */
{
/* Clear frame complete flag */
LL_I3C_ClearFlag_FC(hi3c->Instance);
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_mmc.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_mmc.c
index 6dd5f5d097..46666f52c7 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_mmc.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_mmc.c
@@ -516,7 +516,14 @@ HAL_StatusTypeDef HAL_MMC_InitCard(MMC_HandleTypeDef *hmmc)
hmmc->ErrorCode = SDMMC_ERROR_INVALID_PARAMETER;
return HAL_ERROR;
}
- Init.ClockDiv = sdmmc_clk / (2U * MMC_INIT_FREQ);
+ if (sdmmc_clk <= MMC_INIT_FREQ)
+ {
+ Init.ClockDiv = 0U;
+ }
+ else
+ {
+ Init.ClockDiv = (sdmmc_clk / (2U * MMC_INIT_FREQ)) + 1U;
+ }
#if (USE_SD_TRANSCEIVER != 0U)
Init.TranceiverPresent = SDMMC_TRANSCEIVER_NOT_PRESENT;
@@ -3381,7 +3388,7 @@ HAL_StatusTypeDef HAL_MMC_SleepDevice(MMC_HandleTypeDef *hmmc)
{
/* Send CMD5 CMD_MMC_SLEEP_AWAKE with RCA and SLEEP as argument */
errorstate = SDMMC_CmdSleepMmc(hmmc->Instance,
- ((hmmc->MmcCard.RelCardAdd << 16U) | (0x1UL << 15U)));
+ ((hmmc->MmcCard.RelCardAdd << 16UL) | (0x1UL << 15UL)));
if (errorstate == HAL_MMC_ERROR_NONE)
{
/* Wait that the device is ready by checking the D0 line */
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nand.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nand.c
index 9b882a8fb7..f791018f73 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nand.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nand.c
@@ -525,6 +525,7 @@ HAL_StatusTypeDef HAL_NAND_Read_Page_8b(NAND_HandleTypeDef *hnand, const NAND_Ad
uint32_t deviceaddress;
uint32_t nandaddress;
uint32_t nbpages = NumPageToRead;
+ uint32_t status;
uint8_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -615,9 +616,11 @@ HAL_StatusTypeDef HAL_NAND_Read_Page_8b(NAND_HandleTypeDef *hnand, const NAND_Ad
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -625,9 +628,28 @@ HAL_StatusTypeDef HAL_NAND_Read_Page_8b(NAND_HandleTypeDef *hnand, const NAND_Ad
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Go back to read mode */
*(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
@@ -679,6 +701,7 @@ HAL_StatusTypeDef HAL_NAND_Read_Page_16b(NAND_HandleTypeDef *hnand, const NAND_A
uint32_t deviceaddress;
uint32_t nandaddress;
uint32_t nbpages = NumPageToRead;
+ uint32_t status;
uint16_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -768,9 +791,11 @@ HAL_StatusTypeDef HAL_NAND_Read_Page_16b(NAND_HandleTypeDef *hnand, const NAND_A
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -778,9 +803,28 @@ HAL_StatusTypeDef HAL_NAND_Read_Page_16b(NAND_HandleTypeDef *hnand, const NAND_A
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Go back to read mode */
*(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
@@ -843,6 +887,7 @@ HAL_StatusTypeDef HAL_NAND_Write_Page_8b(NAND_HandleTypeDef *hnand, const NAND_A
uint32_t deviceaddress;
uint32_t nandaddress;
uint32_t nbpages = NumPageToWrite;
+ uint32_t status;
const uint8_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -940,9 +985,11 @@ HAL_StatusTypeDef HAL_NAND_Write_Page_8b(NAND_HandleTypeDef *hnand, const NAND_A
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -950,9 +997,28 @@ HAL_StatusTypeDef HAL_NAND_Write_Page_8b(NAND_HandleTypeDef *hnand, const NAND_A
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Decrement pages to write */
nbpages--;
@@ -992,6 +1058,7 @@ HAL_StatusTypeDef HAL_NAND_Write_Page_16b(NAND_HandleTypeDef *hnand, const NAND_
uint32_t deviceaddress;
uint32_t nandaddress;
uint32_t nbpages = NumPageToWrite;
+ uint32_t status;
const uint16_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -1100,9 +1167,11 @@ HAL_StatusTypeDef HAL_NAND_Write_Page_16b(NAND_HandleTypeDef *hnand, const NAND_
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -1110,9 +1179,28 @@ HAL_StatusTypeDef HAL_NAND_Write_Page_16b(NAND_HandleTypeDef *hnand, const NAND_
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Decrement pages to write */
nbpages--;
@@ -1153,6 +1241,7 @@ HAL_StatusTypeDef HAL_NAND_Read_SpareArea_8b(NAND_HandleTypeDef *hnand, const NA
uint32_t nandaddress;
uint32_t columnaddress;
uint32_t nbspare = NumSpareAreaToRead;
+ uint32_t status;
uint8_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -1249,9 +1338,11 @@ HAL_StatusTypeDef HAL_NAND_Read_SpareArea_8b(NAND_HandleTypeDef *hnand, const NA
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -1259,9 +1350,28 @@ HAL_StatusTypeDef HAL_NAND_Read_SpareArea_8b(NAND_HandleTypeDef *hnand, const NA
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Go back to read mode */
*(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
@@ -1314,6 +1424,7 @@ HAL_StatusTypeDef HAL_NAND_Read_SpareArea_16b(NAND_HandleTypeDef *hnand, const N
uint32_t nandaddress;
uint32_t columnaddress;
uint32_t nbspare = NumSpareAreaToRead;
+ uint32_t status;
uint16_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -1410,9 +1521,11 @@ HAL_StatusTypeDef HAL_NAND_Read_SpareArea_16b(NAND_HandleTypeDef *hnand, const N
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -1420,9 +1533,28 @@ HAL_StatusTypeDef HAL_NAND_Read_SpareArea_16b(NAND_HandleTypeDef *hnand, const N
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Go back to read mode */
*(__IO uint8_t *)((uint32_t)(deviceaddress | CMD_AREA)) = ((uint8_t)0x00);
@@ -1475,6 +1607,7 @@ HAL_StatusTypeDef HAL_NAND_Write_SpareArea_8b(NAND_HandleTypeDef *hnand, const N
uint32_t nandaddress;
uint32_t columnaddress;
uint32_t nbspare = NumSpareAreaTowrite;
+ uint32_t status;
const uint8_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -1581,9 +1714,11 @@ HAL_StatusTypeDef HAL_NAND_Write_SpareArea_8b(NAND_HandleTypeDef *hnand, const N
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -1591,9 +1726,28 @@ HAL_StatusTypeDef HAL_NAND_Write_SpareArea_8b(NAND_HandleTypeDef *hnand, const N
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Decrement spare areas to write */
nbspare--;
@@ -1634,6 +1788,7 @@ HAL_StatusTypeDef HAL_NAND_Write_SpareArea_16b(NAND_HandleTypeDef *hnand, const
uint32_t nandaddress;
uint32_t columnaddress;
uint32_t nbspare = NumSpareAreaTowrite;
+ uint32_t status;
const uint16_t *buff = pBuffer;
/* Check the NAND controller state */
@@ -1740,9 +1895,11 @@ HAL_StatusTypeDef HAL_NAND_Write_SpareArea_16b(NAND_HandleTypeDef *hnand, const
tickstart = HAL_GetTick();
/* Read status until NAND is ready */
- while (HAL_NAND_Read_Status(hnand) != NAND_READY)
+ do
{
- if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ status = HAL_NAND_Read_Status(hnand);
+
+ if (status == NAND_ERROR)
{
/* Update the NAND controller state */
hnand->State = HAL_NAND_STATE_ERROR;
@@ -1750,9 +1907,28 @@ HAL_StatusTypeDef HAL_NAND_Write_SpareArea_16b(NAND_HandleTypeDef *hnand, const
/* Process unlocked */
__HAL_UNLOCK(hnand);
- return HAL_TIMEOUT;
+ return HAL_ERROR;
}
- }
+
+ if ((HAL_GetTick() - tickstart) > NAND_WRITE_TIMEOUT)
+ {
+ /* Perform a new read status to check if NAND is now ready */
+ if (HAL_NAND_Read_Status(hnand) == NAND_READY)
+ {
+ break;
+ }
+ else
+ {
+ /* Update the NAND controller state */
+ hnand->State = HAL_NAND_STATE_ERROR;
+
+ /* Process unlocked */
+ __HAL_UNLOCK(hnand);
+
+ return HAL_TIMEOUT;
+ }
+ }
+ } while (status != NAND_READY);
/* Decrement spare areas to write */
nbspare--;
@@ -1873,13 +2049,11 @@ uint32_t HAL_NAND_Address_Inc(const NAND_HandleTypeDef *hnand, NAND_AddressTypeD
* @param hnand : NAND handle
* @param CallbackId : ID of the callback to be registered
* This parameter can be one of the following values:
- * @arg @ref HAL_NAND_MSP_INIT_CB_ID NAND MspInit callback ID (*)
- * @arg @ref HAL_NAND_MSP_DEINIT_CB_ID NAND MspDeInit callback ID (*)
- * @arg @ref HAL_NAND_IT_CB_ID NAND IT callback ID (*)
+ * @arg @ref HAL_NAND_MSP_INIT_CB_ID NAND MspInit callback ID
+ * @arg @ref HAL_NAND_MSP_DEINIT_CB_ID NAND MspDeInit callback ID
+ * @arg @ref HAL_NAND_IT_CB_ID NAND IT callback ID
* @param pCallback : pointer to the Callback function
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_NAND_RegisterCallback(NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId,
pNAND_CallbackTypeDef pCallback)
@@ -1941,12 +2115,10 @@ HAL_StatusTypeDef HAL_NAND_RegisterCallback(NAND_HandleTypeDef *hnand, HAL_NAND_
* @param hnand : NAND handle
* @param CallbackId : ID of the callback to be unregistered
* This parameter can be one of the following values:
- * @arg @ref HAL_NAND_MSP_INIT_CB_ID NAND MspInit callback ID (*)
- * @arg @ref HAL_NAND_MSP_DEINIT_CB_ID NAND MspDeInit callback ID (*)
- * @arg @ref HAL_NAND_IT_CB_ID NAND IT callback ID (*)
+ * @arg @ref HAL_NAND_MSP_INIT_CB_ID NAND MspInit callback ID
+ * @arg @ref HAL_NAND_MSP_DEINIT_CB_ID NAND MspDeInit callback ID
+ * @arg @ref HAL_NAND_IT_CB_ID NAND IT callback ID
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_NAND_UnRegisterCallback(NAND_HandleTypeDef *hnand, HAL_NAND_CallbackIDTypeDef CallbackId)
{
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nor.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nor.c
index 28b07eae8c..c70f37a789 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nor.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_nor.c
@@ -24,7 +24,7 @@
[..]
This driver is a generic layered driver which contains a set of APIs used to
control NOR flash memories. It uses the FMC layer functions to interface
- with NOR devices. This driver is used as follows:
+ with NOR 16-bit devices. The NOR 8-bit support is deprecated. This driver is used as follows:
(+) NOR flash memory configuration sequence using the function HAL_NOR_Init()
with control and timing parameters for both normal and extended mode.
@@ -127,11 +127,6 @@
*/
/* Constants to define address to set to write a command */
-#define NOR_CMD_ADDRESS_FIRST_BYTE (uint16_t)0x0AAA
-#define NOR_CMD_ADDRESS_FIRST_CFI_BYTE (uint16_t)0x00AA
-#define NOR_CMD_ADDRESS_SECOND_BYTE (uint16_t)0x0555
-#define NOR_CMD_ADDRESS_THIRD_BYTE (uint16_t)0x0AAA
-
#define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555
#define NOR_CMD_ADDRESS_FIRST_CFI (uint16_t)0x0055
#define NOR_CMD_ADDRESS_SECOND (uint16_t)0x02AA
@@ -196,8 +191,6 @@
* @{
*/
-static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B;
-
/**
* @}
*/
@@ -243,6 +236,12 @@ HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDe
return HAL_ERROR;
}
+ /* Check if deprecated 8-bit support is used */
+ if (hnor->Init.MemoryDataWidth == FMC_NORSRAM_MEM_BUS_WIDTH_8)
+ {
+ return HAL_ERROR;
+ }
+
if (hnor->State == HAL_NOR_STATE_RESET)
{
/* Allocate lock resource and initialize it */
@@ -275,16 +274,6 @@ HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDe
/* Enable the NORSRAM device */
__FMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank);
- /* Initialize NOR Memory Data Width*/
- if (hnor->Init.MemoryDataWidth == FMC_NORSRAM_MEM_BUS_WIDTH_8)
- {
- uwNORMemoryDataWidth = NOR_MEMORY_8B;
- }
- else
- {
- uwNORMemoryDataWidth = NOR_MEMORY_16B;
- }
-
/* Enable FMC Peripheral */
__FMC_ENABLE();
@@ -319,17 +308,9 @@ HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDe
else
{
/* Get the value of the command set */
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI_BYTE),
- NOR_CMD_DATA_CFI);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
- hnor->CommandSet = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_ADDRESS_COMMAND_SET);
+ hnor->CommandSet = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_ADDRESS_COMMAND_SET);
status = HAL_NOR_ReturnToReadMode(hnor);
}
@@ -490,22 +471,9 @@ HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_I
/* Send read ID command */
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
- NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
- NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
- NOR_CMD_DATA_AUTO_SELECT);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
- NOR_CMD_DATA_AUTO_SELECT);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_AUTO_SELECT);
}
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
@@ -520,13 +488,10 @@ HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_I
if (status != HAL_ERROR)
{
/* Read the NOR IDs */
- pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS);
- pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
- DEVICE_CODE1_ADDR);
- pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
- DEVICE_CODE2_ADDR);
- pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
- DEVICE_CODE3_ADDR);
+ pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, MC_ADDRESS);
+ pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, DEVICE_CODE1_ADDR);
+ pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, DEVICE_CODE2_ADDR);
+ pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, DEVICE_CODE3_ADDR);
}
/* Check the NOR controller state */
@@ -672,22 +637,9 @@ HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint
/* Send read data command */
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
- NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
- NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
- NOR_CMD_DATA_READ_RESET);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
- NOR_CMD_DATA_READ_RESET);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
}
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
@@ -702,7 +654,7 @@ HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint
if (status != HAL_ERROR)
{
/* Read the data */
- *pData = (uint16_t)(*(__IO uint32_t *)pAddress);
+ *pData = NOR_READ(pAddress);
}
/* Check the NOR controller state */
@@ -766,21 +718,9 @@ HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, u
/* Send program data command */
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
- NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
- NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
- NOR_CMD_DATA_PROGRAM);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM);
}
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
@@ -870,22 +810,9 @@ HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress
/* Send read data command */
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
- NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
- NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
- NOR_CMD_DATA_READ_RESET);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
- NOR_CMD_DATA_READ_RESET);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
}
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
@@ -978,20 +905,10 @@ HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddr
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- /* Issue unlock command sequence */
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
- NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
- NOR_CMD_DATA_SECOND);
- }
- else
- {
- /* Issue unlock command sequence */
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
- }
+ /* Issue unlock command sequence */
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
+
/* Write Buffer Load Command */
NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG);
NOR_WRITE((deviceaddress + uwAddress), (uint16_t)(uwBufferSize - 1U));
@@ -1091,26 +1008,15 @@ HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAdd
/* Send block erase command sequence */
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
- NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
- NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_THIRD),
+ NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FOURTH),
+ NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIFTH),
+ NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
+
NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE);
}
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
@@ -1188,28 +1094,16 @@ HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
/* Send NOR chip erase command sequence */
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
- NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
- NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH),
- NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH),
- NOR_CMD_DATA_CHIP_ERASE);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_THIRD),
+ NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FOURTH),
+ NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIFTH),
+ NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_SIXTH),
+ NOR_CMD_DATA_CHIP_ERASE);
}
else
{
@@ -1280,20 +1174,13 @@ HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR
}
/* Send read CFI query command */
- if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI_BYTE),
- NOR_CMD_DATA_CFI);
- }
- else
- {
- NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
- }
+ NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
+
/* read the NOR CFI information */
- pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS);
- pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS);
- pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS);
- pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS);
+ pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, CFI1_ADDRESS);
+ pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, CFI2_ADDRESS);
+ pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, CFI3_ADDRESS);
+ pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, NOR_MEMORY_16B, CFI4_ADDRESS);
/* Check the NOR controller state */
hnor->State = state;
@@ -1316,12 +1203,10 @@ HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR
* @param hnor : NOR handle
* @param CallbackId : ID of the callback to be registered
* This parameter can be one of the following values:
- * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID (*)
- * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID (*)
+ * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID
+ * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID
* @param pCallback : pointer to the Callback function
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_NOR_RegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId,
pNOR_CallbackTypeDef pCallback)
@@ -1366,11 +1251,9 @@ HAL_StatusTypeDef HAL_NOR_RegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_Call
* @param hnor : NOR handle
* @param CallbackId : ID of the callback to be unregistered
* This parameter can be one of the following values:
- * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID (*)
- * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID (*)
+ * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID
+ * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_NOR_UnRegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId)
{
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pcd.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pcd.c
index 4c01dba4f0..2de839d7a7 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pcd.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pcd.c
@@ -791,7 +791,7 @@ HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd)
status = HAL_ERROR;
}
- return status;
+ return status;
}
/**
@@ -1583,6 +1583,9 @@ void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
{
__HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF);
+ /* store current frame number */
+ hpcd->FrameNumber = USB_GetCurrentFrame(hpcd->Instance);
+
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
hpcd->SOFCallback(hpcd);
#else
@@ -2474,6 +2477,9 @@ static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
count = 0U;
#endif /* USE_USB_DOUBLE_BUFFER */
+ /* store current frame number */
+ hpcd->FrameNumber = USB_GetCurrentFrame(hpcd->Instance);
+
/* stay in loop while pending interrupts */
while ((hpcd->Instance->ISTR & USB_ISTR_CTR) != 0U)
{
@@ -2482,6 +2488,11 @@ static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
/* extract highest priority endpoint number */
epindex = (uint8_t)(wIstr & USB_ISTR_IDN);
+ if (epindex >= 8U)
+ {
+ return HAL_ERROR;
+ }
+
if (epindex == 0U)
{
/* Decode and service control endpoint interrupt */
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pka.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pka.c
index 19c742326e..235012b14a 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pka.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pka.c
@@ -277,6 +277,9 @@
*/
#define PKA_RAM_SIZE 1334U
#define PKA_RAM_ERASE_TIMEOUT 1000U
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+#define PKA_RNG_TIMEOUT_VALUE 2U
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/* Private macro -------------------------------------------------------------*/
#define __PKA_RAM_PARAM_END(TAB,INDEX) do{ \
@@ -324,6 +327,9 @@ void PKA_ECCCompleteAddition_Set(PKA_HandleTypeDef *hpka, PKA_ECCCompleteAdditio
HAL_StatusTypeDef PKA_WaitOnFlagUntilTimeout(PKA_HandleTypeDef *hpka, uint32_t Flag, FlagStatus Status,
uint32_t Tickstart, uint32_t Timeout);
uint32_t PKA_Result_GetSize(const PKA_HandleTypeDef *hpka, uint32_t Startindex, uint32_t Maxsize);
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+HAL_StatusTypeDef PKA_RNG_ResilientRecoverSeedError(void);
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/**
* @}
*/
@@ -393,6 +399,17 @@ HAL_StatusTypeDef HAL_PKA_Init(PKA_HandleTypeDef *hpka)
HAL_PKA_MspInit(hpka);
#endif /* USE_HAL_PKA_REGISTER_CALLBACKS */
}
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (PKA_RNG_ResilientRecoverSeedError() != HAL_OK)
+ {
+ return HAL_ERROR;
+ }
+ }
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/* Set the state to busy */
hpka->State = HAL_PKA_STATE_BUSY;
@@ -526,6 +543,18 @@ __weak void HAL_PKA_MspDeInit(PKA_HandleTypeDef *hpka)
/* Release PKA from reset state */
__HAL_RCC_PKA_RELEASE_RESET();
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ /*Check if there is an RNG seed error */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ /* Attempt to recover from the seed error */
+ if (PKA_RNG_ResilientRecoverSeedError() != HAL_OK)
+ {
+ hpka->State = HAL_PKA_STATE_ERROR;
+ }
+ }
+
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/* Wait the INITOK flag Setting */
while (hpka->Instance->CR != PKA_CR_EN)
{
@@ -2389,20 +2418,20 @@ void PKA_ModExpFastMode_Set(PKA_HandleTypeDef *hpka, PKA_ModExpFastModeInTypeDef
/* Move the input parameters pOp1 to PKA RAM */
PKA_Memcpy_u8_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_IN_EXPONENT_BASE], in->pOp1, in->OpSize);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_EXPONENT_BASE + (in->OpSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_EXPONENT_BASE + ((in->OpSize + 3UL) / 4UL));
/* Move the exponent to PKA RAM */
PKA_Memcpy_u8_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_IN_EXPONENT], in->pExp, in->expSize);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_EXPONENT + (in->expSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_EXPONENT + ((in->expSize + 3UL) / 4UL));
/* Move the modulus to PKA RAM */
PKA_Memcpy_u8_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_IN_MODULUS], in->pMod, in->OpSize);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_MODULUS + (in->OpSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_MODULUS + ((in->OpSize + 3UL) / 4UL));
/* Move the Montgomery parameter to PKA RAM */
PKA_Memcpy_u32_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_IN_MONTGOMERY_PARAM], in->pMontgomeryParam,
in->OpSize / 4UL);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_MONTGOMERY_PARAM + (in->OpSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_IN_MONTGOMERY_PARAM + ((in->OpSize + 3UL) / 4UL));
}
/**
@@ -2420,19 +2449,19 @@ void PKA_ModExpProtectMode_Set(PKA_HandleTypeDef *hpka, PKA_ModExpProtectModeInT
/* Move the input parameters pOp1 to PKA RAM */
PKA_Memcpy_u8_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE], in->pOp1, in->OpSize);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE + (in->OpSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT_BASE + ((in->OpSize + 3UL) / 4UL));
/* Move the exponent to PKA RAM */
PKA_Memcpy_u8_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_PROTECT_IN_EXPONENT], in->pExp, in->expSize);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + (in->expSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_EXPONENT + ((in->expSize + 3UL) / 4UL));
/* Move the modulus to PKA RAM */
PKA_Memcpy_u8_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_PROTECT_IN_MODULUS], in->pMod, in->OpSize);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_MODULUS + (in->OpSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_MODULUS + ((in->OpSize + 3UL) / 4UL));
/* Move Phi value to PKA RAM */
PKA_Memcpy_u8_to_u32(&hpka->Instance->RAM[PKA_MODULAR_EXP_PROTECT_IN_PHI], in->pPhi, in->OpSize);
- __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + (in->OpSize / 4UL));
+ __PKA_RAM_PARAM_END(hpka->Instance->RAM, PKA_MODULAR_EXP_PROTECT_IN_PHI + ((in->OpSize + 3UL) / 4UL));
}
/**
@@ -3066,6 +3095,179 @@ uint32_t PKA_Result_GetSize(const PKA_HandleTypeDef *hpka, uint32_t Startindex,
return size;
}
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+/**
+ * @brief RNG sequence to resilient recover from a seed error
+ * @retval HAL status
+ */
+HAL_StatusTypeDef PKA_RNG_ResilientRecoverSeedError(void)
+{
+ uint32_t timeout;
+ uint32_t htsr_temp = 0U;
+ uint32_t htsr_previous_temp = 0U;
+ uint32_t htsr_count = 0U;
+ uint32_t nsmr_temp = 0U;
+ uint32_t tickstart1 = 0U;
+ uint32_t tickstart2 = 0U;
+ uint32_t tickstart3 = 0U;
+ uint32_t oscillators_count = 0U;
+ uint32_t config_b_fewer_than_6_osc_count = 0U;
+ uint8_t count = 0U;
+
+ /* timeout here is an emperic value */
+ timeout = (1UL + ((1UL << (READ_BIT(RNG->CR, RNG_CR_CLKDIV) >> 16UL)) * PKA_RNG_TIMEOUT_VALUE / 8UL));
+ LL_RNG_Enable(RNG);
+
+ tickstart1 = HAL_GetTick();
+
+ /* Check if seed error current status indicates no error and auto-reset succeeded */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) == 0U)
+ {
+ /* Clear SEIS flag when automatic reset is activated */
+ LL_RNG_ClearFlag_SEIS(RNG);
+ }
+
+ else /* Sequence to fully recover from a seed error*/
+ {
+ if (LL_RNG_IsConfigLocked(RNG) == 0U)
+ {
+ do
+ {
+ if (LL_RNG_IsActiveFlag_SECS(RNG) == 0U)
+ {
+ break;
+ }
+ /* Read oscillator status registers combined */
+ htsr_temp = LL_RNG_GetHealthTestStatus(RNG, 0U);
+ htsr_temp |= LL_RNG_GetHealthTestStatus(RNG, 1U);
+ if (htsr_temp > 0U)
+ {
+ /* If any oscillator status bits overlap with previous status, increment counter */
+ if ((htsr_temp & htsr_previous_temp) != 0U)
+ {
+ htsr_count++;
+ }
+
+ if (htsr_count > 3U)
+ {
+ /* if the same repetitive or adaptative error is detected 3 times */
+ nsmr_temp = LL_RNG_GetNoiseSourceMask(RNG);
+
+ /* deactivate the same osc in each triple oscillator (Mask oscillators with the seed error by
+ clearing bits shifted right by 1) */
+ nsmr_temp = nsmr_temp & ~(htsr_temp >> 1U);
+
+ /* Count the number of active oscillators in nsmr */
+ oscillators_count = 0U;
+ for (count = 0U; count < 9U; count++)
+ {
+ if (((nsmr_temp >> count) & 0x1U) != 0U)
+ {
+ /* increment count1 for each 1 in nsmr */
+ oscillators_count++;
+ }
+ }
+
+ if (oscillators_count < 6U)
+ {
+ /* If fewer than 6 oscillators remain active, unmask all oscillators --> Reset masking */
+ nsmr_temp = LL_RNG_GetOscNoiseSrc(RNG, LL_RNG_NOISE_SRC_1 | LL_RNG_NOISE_SRC_2 \
+ | LL_RNG_NOISE_SRC_3);
+ htsr_previous_temp = 0;
+ htsr_count = 0U;
+ if ((RNG->CR & RNG_CR_CLKDIV_Msk) < ((uint32_t)RNG_CAND_NIST_CR_VALUE & RNG_CR_CLKDIV_Msk))
+ {
+ config_b_fewer_than_6_osc_count++;
+ }
+ }
+
+ if (config_b_fewer_than_6_osc_count > 2U)
+ {
+ /* Reset RNG condition */
+ WRITE_REG(RNG->CR, (RNG_CR_CONDRST_Msk | (uint32_t)RNG_CAND_NIST_CR_VALUE));
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(RNG, nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(RNG);
+ }
+
+ else
+ {
+ /* Reset RNG condition */
+ WRITE_REG(RNG->CR, (RNG->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(RNG, nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(RNG);
+ }
+ }
+
+ else
+ {
+ /* Briefly toggle conditional reset to recover RNG */
+ WRITE_REG(RNG->CR, (RNG->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* unmask all oscillators to find another working condition */
+ LL_RNG_SetNoiseSourceMask(RNG, LL_RNG_GetOscNoiseSrc(RNG, LL_RNG_OSC_1\
+ | LL_RNG_OSC_2 | LL_RNG_OSC_3));
+ LL_RNG_DisableCondReset(RNG);
+ }
+
+ /* Wait until RNG is not busy */
+ tickstart2 = HAL_GetTick();
+ do
+ {
+ if ((HAL_GetTick() - tickstart2) > PKA_RNG_TIMEOUT_VALUE)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ LL_RNG_Disable(RNG);
+ return HAL_ERROR;
+ }
+ } while (HAL_IS_BIT_SET(RNG->SR, RNG_SR_BUSY));
+
+ /* No timeout --> Enable RNG */
+ LL_RNG_Enable(RNG);
+ tickstart3 = HAL_GetTick();
+ do
+ {
+ if (LL_RNG_IsActiveFlag_DRDY(RNG) != 0UL)
+ {
+ break;
+ }
+ if ((HAL_GetTick() - tickstart3) > timeout)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ if (LL_RNG_IsActiveFlag_DRDY(RNG) == 0UL)
+ {
+ if (LL_RNG_IsActiveFlag_SECS(RNG) == 0UL)
+ {
+ LL_RNG_Disable(RNG);
+ return HAL_ERROR;
+ }
+ }
+ }
+ } while (LL_RNG_IsActiveFlag_SECS(RNG) == 0UL);
+
+ /* Accumulate seed error status bits */
+ htsr_previous_temp = htsr_previous_temp | htsr_temp;
+ }
+ } while ((HAL_GetTick() - tickstart1) <= timeout);
+ }
+ }
+
+ /*Check if seed error current status (SECS)is set */
+ if (LL_RNG_IsActiveFlag_SECS(RNG) != 0U)
+ {
+ return HAL_ERROR;
+ }
+
+ return HAL_OK;
+}
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/**
* @}
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_play.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_play.c
index e13ae48f49..2e935ff686 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_play.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_play.c
@@ -29,52 +29,51 @@
[..]
The PLAY HAL driver can be used as follows:
- (#) Declare a HAL_PLAY_HandleTypeDef handle structure (eg. HAL_PLAY_HandleTypeDef hplay).
- (#) Initialize the PLAY low level resources by implementing the HAL_PLAY_MspInit() API:
- (##) Select the PLAY kernel clock source with RCC API
- (##) Configure the PLAY kernel clock prescaler with RCC API
- (##) Enable the PLAY interface clock using __HAL_RCC_PLAYx_CLK_ENABLE()
+ (#) Declare a HAL_PLAY_HandleTypeDef handle structure, for example:
+ HAL_PLAY_HandleTypeDef hplay;
+ (#) Initialize the PLAY low-level resources by implementing the HAL_PLAY_MspInit() API:
+ (##) Select the PLAY kernel clock source
+ (##) Configure the PLAY kernel clock prescaler
+ (##) Enable the PLAY interface clock
(##) PLAY pins configuration:
(+++) Enable the clock for the PLAY GPIOs
- (+++) Configure these PLAY pins as alternate function
+ (+++) Configure PLAY pins as alternate function
(##) NVIC configuration if you need to use interrupt process:
(+++) Configure the PLAY interrupt priority.
- (+++) Enable the NVIC PLAY IRQ handler.
+ (+++) Enable the NVIC PLAY IRQ.
(##) Optionally, reset the peripheral either by a full reset of all registers or
- by an "application" reset for only the functional registers (refer to the RCC API)
+ by an "application" reset for only the functional registers (refer to the RCC APIs)
(#) Initialize PLAY registers by calling the HAL_PLAY_Init() API which calls HAL_PLAY_MspInit()
(#) To configure PLAY, call the following APIs:
- HAL_PLAY_INPUT_SetConfig() : to select the input signals and configure filters
- - HAL_PLAY_LUT_SetConfig() : to configure the Look-Up Tables
-
- Finalize the configuration by calling the API HAL_PLAY_OUTPUT_SetConfig.
- This one allows to output some Look-Up Table Outputs and
- indicates that the peripheral is ready to start (handle state = HAL_PLAY_STATE_READY).
+ - HAL_PLAY_LUT_SetConfig() : to configure the Look-Up Tables (LUTs)
+ - Finalize the configuration by calling the API HAL_PLAY_OUTPUT_SetConfig().
+ This one allows to output some Look-Up Table Outputs and
+ indicates that the peripheral is ready to start (handle state = @ref HAL_PLAY_STATE_READY).
(#) After ending the configuration, start the PLAY with HAL_PLAY_Start() to:
- - lock the PLAYx configuration registers to prevent any accidental write access.
- The kernel clock becomes operational. Then LUT Synchronized Outputs, Filters, SW Triggers and Edge Triggers
- become functional.
- - set a first configuration of Edge Trigger on LUT Outputs.
+ - Lock the PLAYx configuration registers to prevent any accidental write access.
+ The kernel clock becomes operational: LUT registered outputs, filters, software triggers and edge triggers
+ are functional.
+ - Set a first configuration of edge trigger on LUT outputs.
- At this step, the PLAY Outputs can be connected to GPIOs or internal IPs.
+ At this step, the PLAY Outputs can be connected to GPIOs or internal peripherals.
- (#) Stop the PLAY with the API HAL_PLAY_Stop.
- This function disables all Look-Up Table Output ITs and unlocks the configuration.
- The handle state is back to HAL_PLAY_STATE_READY and allows the Application to update the peripheral.
+ (#) Stop the PLAY with the API HAL_PLAY_Stop().
+ This function disables all Look-Up Table (LUT) output interrupts and unlocks the configuration.
+ The handle state is back to @ref HAL_PLAY_STATE_READY and allows the Application to update the peripheral.
- Before updating the PLAY configuration, it is strongly recommended to disconnect all peripherals connected
- to PLAY Outputs to avoid any glitches.
+ Disconnect all peripherals connected to PLAY outputs before updating the configuration to avoid glitches.
- (#) At then end of the PLAY processor User application, call the function HAL_PLAY_DeInit()
- to restore the default configuration which calls HAL_PLAY_MspDeInit().
+ (#) At the end of the PLAY processor User application, call the function HAL_PLAY_DeInit() to restore the default
+ configuration which calls HAL_PLAY_MspDeInit().
*** Look-Up Table Output ***
============================
[..]
- (+) The Truth Table of a Look-Up table is composed of 16 combinations (with 4 inputs):
+ (+) The Truth Table of a Look-Up Table is composed of 16 combinations (with 4 inputs):
Combination ID | IN3 | IN2 | IN1 | IN0 | OUT O(y)
-------------- | --- | --- | --- | --- | --------
0 | 0 | 0 | 0 | 0 | O0
@@ -98,8 +97,8 @@
(O0 * 2^0) + (O1 * 2^1) + (O2 * 2^2) + ... + ((O15 * 2^15))
- There are several Truth Table values for a logic gate depending of the selected inputs.
- For example the Truth Table value for the logic 'AND' are (non-exhaustive list):
+ There are several Truth Table values for a logic gate depending on the selected inputs.
+ For example the Truth Table values for the logic 'AND' are (non-exhaustive list):
- for IN1 & IN0: 0x8888
- for IN2 & IN1: 0xC0C0
- for IN3 & IN2: 0xF000
@@ -107,32 +106,32 @@
- for IN3, IN2, IN1 & IN0: 0x8000
- ...
(+) A Look-Up Table generates a single output which can be stored with a register.
- Each output has a flag which is triggered on a Rising or Falling edge (depends of user configuration).
+ Each output has a flag which is triggered on a rising or falling edge (depending on the user configuration).
- The best way to use PLAY is to use the LUT Output interrupts to be advise when an output is changed.
- You can also configure the interrupt mode using the HAL_PLAY_OUTPUT_EnableIT() function.
- When an IT is triggered the callback HAL_PLAY_LUTOutputRisingCallback() or HAL_PLAY_LUTOutputFallingCallback()
- is called (depending of the edge trigger configuration).
+ The LUT output interrupts can be enabled to advise when an output state change using the
+ HAL_PLAY_OUTPUT_EnableIT() function.
+ When an interrupt is triggered, the callbacks HAL_PLAY_LUTOutputRisingCallback()
+ or HAL_PLAY_LUTOutputFallingCallback() are called (depending on the edge trigger configuration).
- Otherwise, you can work in polling mode by using the HAL_PLAY_OUTPUT_PollForEdgeTrigger(), but the LUT output
- could changed in the time frame between the end of polling and the treatment to do for the related output.
+ In polling mode, HAL_PLAY_OUTPUT_PollForEdgeTrigger() can be used, but the LUT output might change in the time
+ frame between the end of polling and the treatment to do for the related output.
*** Callback registration ***
=============================
[..]
- The compilation define USE_HAL_PLAY_REGISTER_CALLBACKS, when set to 1,
- allows the user to configure dynamically the driver callbacks.
+ The compilation define USE_HAL_PLAY_REGISTER_CALLBACKS, when set to 1, allows the user to configure
+ dynamically the driver callbacks.
[..]
Use the function HAL_PLAY_RegisterCallback() to register a callback taking only the HAL peripheral handle
as parameter.
- Use the function HAL_PLAY_RegisterLUTOutputCallback() to register a callback taking
- 2 parameters (handle + uint32_t) and which is dedicated to perform action when almost a LUT Output state changed.
+ Use the function HAL_PLAY_RegisterLUTOutputCallback() to register a callback taking two parameters
+ (handle + uint32_t) and which is dedicated to perform action when almost a LUT Output state changed.
Both HAL_PLAY_RegisterCallback() and HAL_PLAY_RegisterLUTOutputCallback() take as parameters:
- - the HAL peripheral handle,
- - the Callback ID,
- - the pointer to the user callback function.
+ - The HAL peripheral handle
+ - The Callback ID
+ - The pointer to the user callback function
[..]
Use function HAL_PLAY_UnRegisterCallback() and HAL_PLAY_UnRegisterLUTOutputCallback() to reset a callback
@@ -141,8 +140,8 @@
handle and the Callback ID.
[..]
- Use respectively, the functions HAL_PLAY_RegisterCallback() / HAL_PLAY_UnRegisterCallback(),
- to register / unregister following callbacks:
+ Use respectively, the functions HAL_PLAY_RegisterCallback() / HAL_PLAY_UnRegisterCallback() to register or
+ unregister following callbacks:
(+) MspInitCallback : PLAY MspInit.
(+) MspDeInitCallback : PLAY MspDeInit.
(+) SWTriggerWriteCpltCallback : Software Trigger Write Complete callback.
@@ -151,31 +150,29 @@
[..]
Use respectively, the functions HAL_PLAY_RegisterLUTOutputCallback() / HAL_PLAY_UnRegisterLUTOutputCallback(),
to register / unregister following callbacks:
- (+) HAL_PLAY_LUTOutputRisingCallback() : Look-Up Table Output Rising Edge triggered callback.
- (+) HAL_PLAY_LUTOutputFallingCallback() : Look-Up Table Output Falling Edge triggered callback.
+ (+) HAL_PLAY_LUTOutputRisingCallback() : Look-Up Table output rising edge triggered callback.
+ (+) HAL_PLAY_LUTOutputFallingCallback() : Look-Up Table output falling edge triggered callback.
[..]
- By default, after the HAL_PLAY_Init and when the state is HAL_PLAY_STATE_RESET,
- all callbacks are reset to the corresponding legacy weak functions.
+ By default, after the HAL_PLAY_Init() and when the state is @ref HAL_PLAY_STATE_RESET, all callbacks are reset
+ to the corresponding legacy weak functions.
- Exception done for MspInit and MspDeInit callbacks that are respectively
- reset to the legacy weak function in the HAL_PLAY_Init() and HAL_PLAY_DeInit() only when
- these callbacks are NULL (not registered beforehand).
- If not, MspInit or MspDeInit are not NULL, the HAL_PLAY_Init() and HAL_PLAY_DeInit()
- keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
+ Exception done for MspInit and MspDeInit callbacks that are respectively reset to the legacy weak function in
+ the HAL_PLAY_Init() and HAL_PLAY_DeInit() only when these callbacks are NULL (not registered beforehand).
+ If not, MspInit or MspDeInit are not NULL, the HAL_PLAY_Init() and HAL_PLAY_DeInit() keep and use the user
+ MspInit/MspDeInit callbacks (registered beforehand).
[..]
- Callbacks can be registered/unregistered in HAL_PLAY_STATE_READY state only.
- Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
- in HAL_PLAY_STATE_READY or HAL_PLAY_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_PLAY_RegisterCallback before calling HAL_PLAY_DeInit() or HAL_PLAY_Init() function.
+ Callbacks can be registered/unregistered in @ref HAL_PLAY_STATE_INIT and @ref HAL_PLAY_STATE_READY states only.
+ Exception done for MspInit/MspDeInit callbacks that can also be registered/unregistered in
+ @ref HAL_PLAY_STATE_RESET state, thus registered (user) MspInit/DeInit callbacks can be used during
+ the Init/DeInit.
+ To do so, register the MspInit/MspDeInit user callbacks using HAL_PLAY_RegisterCallback() before calling
+ HAL_PLAY_DeInit() or HAL_PLAY_Init() functions.
[..]
- When the compilation define USE_HAL_PLAY_REGISTER_CALLBACKS is set to 0 or
- not defined, the callback registering feature is not available and all callbacks
- are set to the corresponding weak functions.
+ When the compilation define USE_HAL_PLAY_REGISTER_CALLBACKS is set to 0 or not defined, the callback registering
+ feature is not available and all callbacks are set to the corresponding weak functions.
@endverbatim
******************************************************************************
@@ -212,13 +209,13 @@
/**
* @brief PLAY Interrupt Definition
*/
-#define PLAY_IT_STATUS_SW_TRIGGER_WRITE_COMPLETE LL_PLAY_IER_SWINWC_IEN /*!< Interrupt Software Trigger write complete */
-#define PLAY_IT_STATUS_EDGE_TRIGGER_WRITE_COMPLETE LL_PLAY_IER_FLCTLWC_IEN /*!< Interrupt Edge Trigger write complete */
+#define PLAY_IT_STATUS_SW_TRIGGER_WRITE_COMPLETE LL_PLAY_IER_SWINWC_IEN /*!< Software trigger write complete interrupt */
+#define PLAY_IT_STATUS_EDGE_TRIGGER_WRITE_COMPLETE LL_PLAY_IER_FLCTLWC_IEN /*!< Edge trigger write complete interrupt */
/**
* @brief Maximum Timeout for any write on Software Trigger or Edge Trigger register.
*
- * With a LSI as PLAY kernel clock source and a prescaler of 32768, the play_clk cycle is 1s.
+ * With LSI as PLAY kernel clock source and a prescaler of 32768, the play_clk cycle is 1s.
* A write takes 3 cycles of play_clk + 2 cycles of PCLK, then a write can take almost 3s.
*/
#define PLAY_WRITE_TIMEOUT_MS (4000U) /*!< Maximum Write Timeout for Software Trigger or Edge Trigger register: 4000 ms */
@@ -235,35 +232,64 @@
/**
* @brief Retrieve the bit status in a given register.
* @param reg The register to check.
- * @param bit The bit to check to check.
- * @retval 1 Bit is set.
- * @retval 0 Bit is reset.
+ * @param bit The bit to check.
+ * @retval 1 bit is set.
+ * @retval 0 bit is reset.
*/
#define IS_PLAY_BIT_SET(reg, bit) (((reg) & (bit)) == (bit))
/**
* @brief Retrieve the PLAY hardware CMSIS instance from the hal handle.
- * @param handle specifies the peripheral Handle.
+ * @param handle specifies the peripheral handle.
*/
#define PLAY_GET_INSTANCE(handle) ((handle)->instance)
/**
* @brief Retrieve the PLAYx instance ID from the HAL handle.
- * @param handle Specifies the peripheral Handle.
+ * @param handle Specifies the peripheral handle.
*/
#define PLAY_GET_INSTANCE_ID(handle) \
(HAL_PLAY1_INSTANCE_ID)
/**
- * @brief Verifies the PLAY TrustZone access control value.
- * @param access Value of TZ access control.
- * @retval 1 access is a valid value.
- * @retval 0 access is an invalid value.
+ * @brief Verifies the PLAY privileged access level attribute.
+ * @param attribute Value of PLAY attribute.
+ * @retval 1 attribute is a valid value.
+ * @retval 0 attribute is an invalid value.
+ */
+#define IS_PLAY_ITEM_PRIV_ATTR(attribute) \
+ (((attribute) == HAL_PLAY_NPRIV) \
+ || ((attribute) == HAL_PLAY_PRIV))
+
+/**
+ * @brief Verifies the PLAY privileged item value.
+ * @param item Value of PLAY privileged item.
+ * @retval 1 item is a valid value.
+ * @retval 0 item is an invalid value.
+ */
+#define IS_PLAY_PRIV_ITEM(item) \
+ (((item) == HAL_PLAY_PRIV_ITEM_CONFIG) \
+ || ((item) == HAL_PLAY_PRIV_ITEM_ALL))
+
+/**
+ * @brief Verifies the PLAY security access level attribute.
+ * @param attribute Value of PLAY attribute.
+ * @retval 1 attribute is a valid value.
+ * @retval 0 attribute is an invalid value.
*/
-#define IS_PLAY_TZ_ACCESS_CONTROL(access) \
- (((access) == HAL_PLAY_TZ_REG_UNPROTECTED) \
- || ((access) == HAL_PLAY_TZ_CONFIG_REG_PROTECTED) \
- || ((access) == HAL_PLAY_TZ_ALL_REG_PROTECTED))
+#define IS_PLAY_ITEM_SEC_ATTR(attribute) \
+ (((attribute) == HAL_PLAY_NSEC) \
+ || ((attribute) == HAL_PLAY_SEC))
+
+/**
+ * @brief Verifies the PLAY security item value.
+ * @param item Value of PLAY security item.
+ * @retval 1 item is a valid value.
+ * @retval 0 item is an invalid value.
+ */
+#define IS_PLAY_SEC_ITEM(item) \
+ (((item) == HAL_PLAY_SEC_ITEM_CONFIG) \
+ || ((item) == HAL_PLAY_SEC_ITEM_ALL))
/**
* @brief Verifies the minimum pulse width value.
@@ -291,7 +317,7 @@
* @retval 1 mux is a valid value.
* @retval 0 mux is an invalid value.
*/
-#define IS_PLAY_IN_ID(mux) \
+#define IS_PLAY_IN(mux) \
(((mux) == HAL_PLAY_IN0) \
|| ((mux) == HAL_PLAY_IN1) \
|| ((mux) == HAL_PLAY_IN2) \
@@ -455,7 +481,7 @@
/**
* @brief Verifies the value of input multiplexer source.
- * @param instance PLAYx instance (@ref PLAY_TypeDef). (*)
+ * @param instance PLAYx instance (PLAY_TypeDef). (*)
* @param source Input signal (@ref HAL_PLAY_IN_SourceTypeDef).
* @retval 1 source is a valid value.
* @retval 0 source is an invalid value.
@@ -491,7 +517,7 @@
/**
* @brief Verifies the Look-Up Table.
- * @param instance PLAYx instance (@ref PLAY_TypeDef). (*)
+ * @param instance PLAYx instance (PLAY_TypeDef). (*)
* @param lut Look-Up Table (@ref HAL_PLAY_LUTTypeDef).
* @retval 1 lut is a valid value.
* @retval 0 lut is an invalid value.
@@ -855,7 +881,7 @@
/**
* @brief Verifies the input source of a look-up table
- * @param instance PLAYx instance (@ref PLAY_TypeDef). (*)
+ * @param instance PLAYx instance (PLAY_TypeDef). (*)
* @param lut Look-Up Table (@ref HAL_PLAY_LUTTypeDef).
* @param input_source Value of input source (@ref HAL_PLAY_LUT_InputSourceTypeDef).
* @retval 1 input_source is a valid value.
@@ -927,7 +953,7 @@
/**
* @brief Verifies the Clock Gate value.
- * @param instance PLAYx instance (@ref PLAY_TypeDef). (*)
+ * @param instance PLAYx instance (PLAY_TypeDef). (*)
* @param source Signal source for Clock Gate.
* @retval 1 source is a valid value.
* @retval 0 source is an invalid value.
@@ -1011,7 +1037,7 @@
/**
* @brief Verifies the Output Multiplexer source.
- * @param instance PLAYx instance (@ref PLAY_TypeDef). (*)
+ * @param instance PLAYx instance (PLAY_TypeDef). (*)
* @param source Value of output source.
* @retval 1 source is a valid value.
* @retval 0 source is an invalid value.
@@ -1072,7 +1098,7 @@
* @retval 0 swtrig is an invalid value.
*/
#define IS_PLAY_SWTRIGGER_MSK(swtrig_msk) \
- ((((uint32_t)(swtrig_msk) & HAL_PLAY_SWTRIG_ALL) != 0x00U) \
+ ((((uint32_t)(swtrig_msk) & HAL_PLAY_SWTRIG_ALL) != 0x00U) \
&& (((uint32_t)(swtrig_msk) & ~HAL_PLAY_SWTRIG_ALL) == 0x00U))
/**
@@ -1101,72 +1127,55 @@ static HAL_StatusTypeDef PLAY_LUT_SetEdgeTrigger(const HAL_PLAY_HandleTypeDef *h
/** @addtogroup PLAY_Exported_Functions_Group1
* @{
A set of functions allowing to initialize and deinitialize the PLAYx peripheral:
- - HAL_PLAY_Init() : initialize the selected device with the PLAY instance.
- - HAL_PLAY_DeInit() : de-initialize the selected PLAYx peripheral and reset the handle and status flags.
- - HAL_PLAY_MSPInit() : initialize the PLAY MSP (MCU Specific Package).
- - HAL_PLAY_MSPDeInit() : de-initialize the PLAY MSP.
+ - HAL_PLAY_Init() Initialize the selected device with the PLAY instance.
+ - HAL_PLAY_DeInit() De-initialize the selected PLAYx peripheral and reset the handle and status flags.
+ - HAL_PLAY_MSPInit() Initialize the PLAY MSP (MCU Specific Package).
+ - HAL_PLAY_MSPDeInit() De-initialize the PLAY MSP.
*/
/**
* @brief Initialize the PLAY according to the associated handle.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @retval HAL_OK PLAY instance has been correctly initialized.
- * @retval HAL_INVALID_PARAM PLAY handle is NULL
+ * @retval HAL_OK PLAY instance has been correctly initialized.
+ * @retval HAL_ERROR Invalid parameter.
*/
HAL_StatusTypeDef HAL_PLAY_Init(HAL_PLAY_HandleTypeDef *hplay)
{
- const PLAY_TypeDef *p_playx;
-
- /* Check the PLAY handle allocation */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- /* Check the parameters */
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
+ assert_param(IS_PLAY_ALL_INSTANCE(PLAY_GET_INSTANCE(hplay)));
- /* Init the peripheral */
- if (hplay->global_state == HAL_PLAY_STATE_RESET)
+ /* Initialize the peripheral */
+ if (hplay->State == HAL_PLAY_STATE_RESET)
{
#if (USE_HAL_PLAY_REGISTER_CALLBACKS == 1)
/* Register the default callback functions */
- hplay->SWTriggerWriteCpltCallback = HAL_PLAY_SWTriggerWriteCpltCallback;
+ hplay->SWTriggerWriteCpltCallback = HAL_PLAY_SWTriggerWriteCpltCallback;
hplay->EdgeTriggerWriteCpltCallback = HAL_PLAY_EdgeTriggerWriteCpltCallback;
- hplay->LUTOutputRisingCallback = HAL_PLAY_LUTOutputRisingCallback;
- hplay->LUTOutputFallingCallback = HAL_PLAY_LUTOutputFallingCallback;
+ hplay->LUTOutputRisingCallback = HAL_PLAY_LUTOutputRisingCallback;
+ hplay->LUTOutputFallingCallback = HAL_PLAY_LUTOutputFallingCallback;
- if (NULL == hplay->MspInitCallback)
+ if (hplay->MspInitCallback == NULL)
{
hplay->MspInitCallback = HAL_PLAY_MspInit;
}
- if (NULL == hplay->MspDeInitCallback)
- {
- hplay->MspDeInitCallback = HAL_PLAY_MspDeInit;
- }
-
- /* Init the low level hardware */
+ /* Initialize the low-level hardware */
hplay->MspInitCallback(hplay);
#else
- /* Init the low level hardware */
+ /* Initialize the low-level hardware */
HAL_PLAY_MspInit(hplay);
#endif /* USE_HAL_PLAY_REGISTER_CALLBACKS */
}
/* Reset error code */
- hplay->last_error_codes = HAL_PLAY_ERROR_NONE;
+ hplay->ErrorCode = HAL_PLAY_ERROR_NONE;
- hplay->global_state = HAL_PLAY_STATE_INIT;
+ hplay->State = HAL_PLAY_STATE_INIT;
return HAL_OK;
}
@@ -1174,7 +1183,7 @@ HAL_StatusTypeDef HAL_PLAY_Init(HAL_PLAY_HandleTypeDef *hplay)
/**
* @brief DeInitialize the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @note HAL_PLAY_DeInit does not reset all PLAY registers.
+ * @note HAL_PLAY_DeInit() does not reset all PLAY registers.
* The Application must call RCC API to force the reset of all PLAY registers.
* @retval HAL_OK Operation completed successfully.
* @retval HAL_ERROR Invalid parameter.
@@ -1183,7 +1192,7 @@ HAL_StatusTypeDef HAL_PLAY_DeInit(HAL_PLAY_HandleTypeDef *hplay)
{
PLAY_TypeDef *p_playx;
- /* Check the PLAY handle allocation */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -1191,18 +1200,8 @@ HAL_StatusTypeDef HAL_PLAY_DeInit(HAL_PLAY_HandleTypeDef *hplay)
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- /* Check the parameters */
assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
- p_playx = PLAY_GET_INSTANCE(hplay);
-
/* Clear only interrupts & flags. The rest of configuration must be reset by the application with MspDeInit */
LL_PLAY_LUT_DisableIT(p_playx, LL_PLAY_LUT_ALL_OUT_REGISTERED | LL_PLAY_LUT_ALL_OUT_DIRECT);
LL_PLAY_LUT_DisableIT_EdgeTriggerWriteComplete(p_playx);
@@ -1214,59 +1213,56 @@ HAL_StatusTypeDef HAL_PLAY_DeInit(HAL_PLAY_HandleTypeDef *hplay)
LL_PLAY_Unlock(p_playx);
#if (USE_HAL_PLAY_REGISTER_CALLBACKS == 1)
- /* Register the default callback functions */
- hplay->SWTriggerWriteCpltCallback = HAL_PLAY_SWTriggerWriteCpltCallback;
- hplay->EdgeTriggerWriteCpltCallback = HAL_PLAY_EdgeTriggerWriteCpltCallback;
- hplay->LUTOutputRisingCallback = HAL_PLAY_LUTOutputRisingCallback;
- hplay->LUTOutputFallingCallback = HAL_PLAY_LUTOutputFallingCallback;
- hplay->MspInitCallback = HAL_PLAY_MspInit;
-
if (hplay->MspDeInitCallback == NULL)
{
- /* DeInit Callback not initialized as expected then force it to default MspDeInit */
+ /* MspDeInit callback not set; reset to default HAL_PLAY_MspDeInit */
hplay->MspDeInitCallback = HAL_PLAY_MspDeInit;
}
- /* DeInit the low level hardware */
+ /* DeInitialize the low-level hardware */
hplay->MspDeInitCallback(hplay);
#else
- /* DeInit the low level hardware */
+ /* DeInitialize the low-level hardware */
HAL_PLAY_MspDeInit(hplay);
#endif /* USE_HAL_PLAY_REGISTER_CALLBACKS == 1 */
/* Reset error code */
- hplay->last_error_codes = HAL_PLAY_ERROR_NONE;
+ hplay->ErrorCode = HAL_PLAY_ERROR_NONE;
- hplay->global_state = HAL_PLAY_STATE_RESET;
+ hplay->State = HAL_PLAY_STATE_RESET;
return HAL_OK;
}
/**
- * @brief Initialize the PLAY MSP.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @brief Initialize the PLAY MSP.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @warning This weak function must not be modified. When the callback is needed,
+ * it must be implemented in the user file.
*/
__weak void HAL_PLAY_MspInit(HAL_PLAY_HandleTypeDef *hplay)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hplay);
- /* NOTE: This function must not be modified, when the callback is needed,
- the HAL_PLAY_MspInit can be implemented in the user file
+ /* WARNING: This function must not be modified, when the callback is needed,
+ function HAL_PLAY_MspInit() must be implemented in the user file.
*/
}
/**
- * @brief DeInitialize the PLAY MSP.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @brief DeInitialize the PLAY MSP.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @warning This weak function must not be modified. When the callback is needed,
+ * it must be implemented in the user file.
*/
__weak void HAL_PLAY_MspDeInit(HAL_PLAY_HandleTypeDef *hplay)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hplay);
- /* NOTE: This function must not be modified, when the callback is needed,
- the HAL_PLAY_MspDeInit can be implemented in the user file
+ /* WARNING: This function must not be modified, when the callback is needed,
+ function HAL_PLAY_MspDeInit() must be implemented in the user file.
*/
}
@@ -1308,14 +1304,15 @@ A set of functions allowing to configure the PLAYx peripheral:
* @brief Configure multiple input multiplexers for the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param p_config Pointer to an array of @ref HAL_PLAY_IN_ConfTypeDef.
- * @param array_size Number of configuration in the array.
+ * @param array_size Number of configurations in the array.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Array pointer or handle is NULL.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
HAL_StatusTypeDef HAL_PLAY_INPUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const HAL_PLAY_IN_ConfTypeDef *p_config,
uint32_t array_size)
{
PLAY_TypeDef *p_playx;
+ HAL_PLAY_StateTypeDef tmp_state;
uint32_t is_locked;
/* Check the parameters */
@@ -1326,32 +1323,25 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- if (p_config == NULL)
+ if ((p_config == NULL) || (array_size > PLAY_INPUT_MUX_NBR(p_playx)))
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(((array_size > 0U) && (array_size <= PLAY_INPUT_MUX_NBR(p_playx))));
/* Check the peripheral state */
- if ((hplay->global_state != HAL_PLAY_STATE_INIT) && (hplay->global_state != HAL_PLAY_STATE_READY))
+ tmp_state = hplay->State;
+ if ((tmp_state != HAL_PLAY_STATE_INIT) && (tmp_state != HAL_PLAY_STATE_READY))
{
return HAL_ERROR;
}
- /* UnLock the configuration if not already done */
+ /* Unlock the configuration if not already done */
is_locked = LL_PLAY_IsLocked(p_playx);
- if (is_locked == 1U)
+ if (is_locked != 0U)
{
LL_PLAY_Unlock(p_playx);
}
@@ -1379,7 +1369,7 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const
* where array_size specifies the number of configurations.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param p_config Pointer to an array of @ref HAL_PLAY_IN_ConfTypeDef to be filled.
- * @param array_size Number of configuration in the array.
+ * @param array_size Number of configurations in the array.
* @retval HAL_OK Operation completed successfully.
* @retval HAL_ERROR Invalid parameter.
*/
@@ -1396,21 +1386,13 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_GetConfig(HAL_PLAY_HandleTypeDef *hplay, HAL_PL
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- if (p_config == NULL)
+ if ((p_config == NULL) || (array_size > PLAY_INPUT_MUX_NBR(p_playx)))
{
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode = HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(((array_size > 0U) && (array_size <= PLAY_INPUT_MUX_NBR(p_playx))));
/* Rebuild the input source signal */
@@ -1434,17 +1416,18 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_GetConfig(HAL_PLAY_HandleTypeDef *hplay, HAL_PL
* @brief Configure multiple lookup tables for the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param p_config Pointer to an array of HAL_PLAY_LUT_ConfTypeDef.
- * @param array_size Number of configuration in the array.
+ * @param array_size Number of configurations in the array.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
HAL_StatusTypeDef HAL_PLAY_LUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const HAL_PLAY_LUT_ConfTypeDef *p_config,
uint32_t array_size)
{
PLAY_TypeDef *p_playx;
+ HAL_PLAY_StateTypeDef tmp_state;
uint32_t is_locked;
- /* Check handle parameter */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -1452,32 +1435,25 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const HA
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
+ if ((p_config == NULL) || (array_size > PLAY_INPUT_MUX_NBR(p_playx)))
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- if (p_config == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(((array_size > 0UL) && (array_size <= PLAY_LUT_NBR(p_playx))));
/* Check the peripheral state */
- if ((hplay->global_state != HAL_PLAY_STATE_INIT) && (hplay->global_state != HAL_PLAY_STATE_READY))
+ tmp_state = hplay->State;
+ if ((tmp_state != HAL_PLAY_STATE_INIT) && (tmp_state != HAL_PLAY_STATE_READY))
{
return HAL_ERROR;
}
- /* UnLock the configuration if not already done */
+ /* Unlock the configuration if not already done */
is_locked = LL_PLAY_IsLocked(p_playx);
- if (is_locked == 1U)
+ if (is_locked != 0U)
{
LL_PLAY_Unlock(p_playx);
}
@@ -1511,9 +1487,9 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const HA
/**
* @brief Retrieve the lookup table configurations of the PLAY peripheral in order from 0 to (array_size - 1),
* where array_size specifies the number of configurations.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @param p_config Pointer to an array of @ref HAL_PLAY_LUT_ConfTypeDef.
- * @param array_size Number of configuration in the array.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param p_config Pointer to an array of @ref HAL_PLAY_LUT_ConfTypeDef.
+ * @param array_size Number of configurations in the array.
* @retval HAL_OK Operation completed successfully.
* @retval HAL_ERROR Invalid parameter.
*/
@@ -1522,7 +1498,7 @@ HAL_StatusTypeDef HAL_PLAY_LUT_GetConfig(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY
{
const PLAY_TypeDef *p_playx;
- /* Check handle parameter */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -1530,22 +1506,13 @@ HAL_StatusTypeDef HAL_PLAY_LUT_GetConfig(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY
p_playx = PLAY_GET_INSTANCE(hplay);
- /* Check parameter setting */
- if (p_playx == NULL)
+ if ((p_config == NULL) || (array_size > PLAY_INPUT_MUX_NBR(p_playx)))
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- if (p_config == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(((array_size > 0UL) && (array_size <= PLAY_LUT_NBR(p_playx))));
for (uint32_t idx = 0; idx < array_size; idx++)
@@ -1567,16 +1534,18 @@ HAL_StatusTypeDef HAL_PLAY_LUT_GetConfig(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY
}
/**
- * @brief Configure a set of Output Multiplexer.
+ * @brief Configure a set of output multiplexers for the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param p_config Pointer to an array of @ref HAL_PLAY_OUT_ConfTypeDef.
- * @param array_size Number of configuration in the array.
- * @return HAL status.
+ * @param array_size Number of configurations in the array.
+ * @retval HAL_OK Operation completed successfully.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const HAL_PLAY_OUT_ConfTypeDef *p_config,
uint32_t array_size)
{
PLAY_TypeDef *p_playx;
+ HAL_PLAY_StateTypeDef tmp_state;
uint32_t is_locked;
/* Check the parameters */
@@ -1587,25 +1556,25 @@ HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
+ if ((p_config == NULL) || (array_size > PLAY_INPUT_MUX_NBR(p_playx)))
{
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode = HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(((array_size > 0UL) && (array_size <= PLAY_OUTPUT_MUX_NBR(p_playx))));
/* Check the peripheral state */
- if ((hplay->global_state != HAL_PLAY_STATE_INIT) && (hplay->global_state != HAL_PLAY_STATE_READY))
+ tmp_state = hplay->State;
+ if ((tmp_state != HAL_PLAY_STATE_INIT) && (tmp_state != HAL_PLAY_STATE_READY))
{
return HAL_ERROR;
}
- /* UnLock the configuration if not already done */
+ /* Unlock the configuration if not already done */
is_locked = LL_PLAY_IsLocked(p_playx);
- if (is_locked == 1U)
+ if (is_locked != 0U)
{
LL_PLAY_Unlock(p_playx);
}
@@ -1619,7 +1588,7 @@ HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const
LL_PLAY_OUTPUT_SetSource(p_playx, (uint32_t)p_config[idx].output_mux, (uint32_t)p_config[idx].lut_output);
}
- hplay->global_state = HAL_PLAY_STATE_READY;
+ hplay->State = HAL_PLAY_STATE_READY;
return HAL_OK;
}
@@ -1629,7 +1598,7 @@ HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetConfig(HAL_PLAY_HandleTypeDef *hplay, const
* where array_size specifies the number of configurations.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param p_config Pointer to an array of @ref HAL_PLAY_OUT_ConfTypeDef.
- * @param array_size Number of configuration in the array.
+ * @param array_size Number of configurations in the array.
* @retval HAL_OK Operation completed successfully.
* @retval HAL_ERROR Invalid parameter.
*/
@@ -1646,21 +1615,13 @@ HAL_StatusTypeDef HAL_PLAY_OUTPUT_GetConfig(HAL_PLAY_HandleTypeDef *hplay, HAL_P
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- if (p_config == NULL)
+ if ((p_config == NULL) || (array_size > PLAY_INPUT_MUX_NBR(p_playx)))
{
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode = HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(((array_size > 0UL) && (array_size <= PLAY_OUTPUT_MUX_NBR(p_playx))));
for (uint32_t idx = 0; idx < array_size; idx++)
@@ -1679,9 +1640,9 @@ HAL_StatusTypeDef HAL_PLAY_OUTPUT_GetConfig(HAL_PLAY_HandleTypeDef *hplay, HAL_P
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param source Input source signal.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter or current state is not @ref HAL_PLAY_STATE_READY.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_INPUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_IN_SourceTypeDef source)
+HAL_StatusTypeDef HAL_PLAY_INPUT_SetSource(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_IN_SourceTypeDef source)
{
PLAY_TypeDef *p_playx;
@@ -1693,28 +1654,20 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PL
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes = HAL_PLAY_ERROR_INVALID_PARAM;
+ assert_param(IS_PLAY_IN_SOURCE(p_playx, source));
+ /* Check the peripheral state */
+ if (hplay->State != HAL_PLAY_STATE_READY)
+ {
return HAL_ERROR;
}
- assert_param(IS_PLAY_IN_SOURCE(p_playx, source));
-
uint32_t src_u32 = (uint32_t)source;
/* Retrieve the input mux */
uint32_t input_mux = (src_u32 & PLAY_IN_MUX_MASK) >> HAL_PLAY_IN_MUX_POS;
uint32_t mux_sel = src_u32 & PLAY_IN_MUX_VALUE_MASK;
- /* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
- {
- return HAL_ERROR;
- }
-
- /* Set the source signal */
LL_PLAY_INPUT_SetSource(p_playx, input_mux, mux_sel);
return HAL_OK;
@@ -1724,34 +1677,23 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PL
* @brief Retrieve the signal source for an input multiplexer of the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param input_mux Input multiplexer.
- * @return Input source signal.
* @note Function will return @ref HAL_PLAY_IN_SOURCE_INVALID if the parameters are invalid.
+ * @return Input source signal.
*/
HAL_PLAY_IN_SourceTypeDef HAL_PLAY_INPUT_GetSource(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_INTypeDef input_mux)
{
- const PLAY_TypeDef *p_playx;
-
/* Check the parameters */
if (hplay == NULL)
{
- /* Return 0 as default value */
- return HAL_PLAY_IN_SOURCE_INVALID;
- }
-
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- /* Return 0 as default value */
return HAL_PLAY_IN_SOURCE_INVALID;
}
- assert_param(IS_PLAY_IN_ID(input_mux));
+ assert_param(IS_PLAY_IN(input_mux));
/* Rebuild the source signal */
uint32_t instance_id = (uint32_t)PLAY_GET_INSTANCE_ID(hplay);
uint32_t mux_sel = (uint32_t)input_mux << HAL_PLAY_IN_MUX_POS;
- uint32_t source = LL_PLAY_INPUT_GetSource(p_playx, (uint32_t)input_mux);
+ uint32_t source = LL_PLAY_INPUT_GetSource(PLAY_GET_INSTANCE(hplay), (uint32_t)input_mux);
uint32_t ret = (instance_id | mux_sel | source);
@@ -1765,38 +1707,27 @@ HAL_PLAY_IN_SourceTypeDef HAL_PLAY_INPUT_GetSource(const HAL_PLAY_HandleTypeDef
* @param width Pulse width in play_clk clock cycles, in range [0..255].
* Value 0 means that the filter is bypassed.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter or current state is not @ref HAL_PLAY_STATE_READY.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_INPUT_SetMinPulseWidth(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_INTypeDef input_mux,
+HAL_StatusTypeDef HAL_PLAY_INPUT_SetMinPulseWidth(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_INTypeDef input_mux,
uint32_t width)
{
- PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_IN_ID(input_mux));
+ assert_param(IS_PLAY_IN(input_mux));
assert_param(IS_PLAY_MIN_PULSE_WIDTH(width));
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
+ if (hplay->State != HAL_PLAY_STATE_READY)
{
return HAL_ERROR;
}
- LL_PLAY_INPUT_SetMinimumPulseWidth(p_playx, (uint32_t)input_mux, width);
+ LL_PLAY_INPUT_SetMinimumPulseWidth(PLAY_GET_INSTANCE(hplay), (uint32_t)input_mux, width);
return HAL_OK;
}
@@ -1805,29 +1736,20 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_SetMinPulseWidth(HAL_PLAY_HandleTypeDef *hplay,
* @brief Retrieve the minimum pulse width configured for an input filter of the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param input_mux Input multiplexer.
- * @return Pulse width in play_clk clock cycles, in range [0..255]. Value 0 means that the filter is bypassed.
* @note Function will return 0 if the parameters are invalid.
+ * @return Pulse width in play_clk clock cycles, in range [0..255]. Value 0 means that the filter is bypassed.
*/
uint32_t HAL_PLAY_INPUT_GetMinPulseWidth(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_INTypeDef input_mux)
{
- const PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return 0U;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- return 0U;
- }
+ assert_param(IS_PLAY_IN(input_mux));
- assert_param(IS_PLAY_IN_ID(input_mux));
-
- return LL_PLAY_INPUT_GetMinimumPulseWidth(p_playx, (uint32_t)input_mux);
+ return LL_PLAY_INPUT_GetMinimumPulseWidth(PLAY_GET_INSTANCE(hplay), (uint32_t)input_mux);
}
/**
@@ -1836,38 +1758,27 @@ uint32_t HAL_PLAY_INPUT_GetMinPulseWidth(const HAL_PLAY_HandleTypeDef *hplay, HA
* @param input_mux Input multiplexer.
* @param mode Mode of Edge Detection.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter or current state is not @ref HAL_PLAY_STATE_READY.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_INPUT_SetEdgeDetectionMode(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_INTypeDef input_mux,
+HAL_StatusTypeDef HAL_PLAY_INPUT_SetEdgeDetectionMode(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_INTypeDef input_mux,
HAL_PLAY_EdgeDetectionModeTypeDef mode)
{
- PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_IN_ID(input_mux));
+ assert_param(IS_PLAY_IN(input_mux));
assert_param(IS_PLAY_EDGE_DETECTION_MODE(mode));
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
+ if (hplay->State != HAL_PLAY_STATE_READY)
{
return HAL_ERROR;
}
- LL_PLAY_INPUT_SetEdgeDetectionMode(p_playx, (uint32_t)input_mux, (uint32_t)mode);
+ LL_PLAY_INPUT_SetEdgeDetectionMode(PLAY_GET_INSTANCE(hplay), (uint32_t)input_mux, (uint32_t)mode);
return HAL_OK;
}
@@ -1876,32 +1787,22 @@ HAL_StatusTypeDef HAL_PLAY_INPUT_SetEdgeDetectionMode(HAL_PLAY_HandleTypeDef *hp
* @brief Retrieve the edge detection mode configured for an input filter of the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param input_mux Input multiplexer.
- * @return Edge Detection mode.
* @note Function will return @ref HAL_PLAY_EDGE_DETECTION_BYPASSED if the parameters are invalid.
+ * @return Edge Detection mode.
*/
HAL_PLAY_EdgeDetectionModeTypeDef HAL_PLAY_INPUT_GetEdgeDetectionMode(const HAL_PLAY_HandleTypeDef *hplay,
HAL_PLAY_INTypeDef input_mux)
{
- const PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
- /* Return HAL_PLAY_EDGE_DETECTION_BYPASSED as default value */
return HAL_PLAY_EDGE_DETECTION_BYPASSED;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- /* Return HAL_PLAY_EDGE_DETECTION_BYPASSED as default value */
- return HAL_PLAY_EDGE_DETECTION_BYPASSED;
- }
+ assert_param(IS_PLAY_IN(input_mux));
- assert_param(IS_PLAY_IN_ID(input_mux));
-
- return (HAL_PLAY_EdgeDetectionModeTypeDef)LL_PLAY_INPUT_GetEdgeDetectionMode(p_playx, (uint32_t)input_mux);
+ return (HAL_PLAY_EdgeDetectionModeTypeDef)LL_PLAY_INPUT_GetEdgeDetectionMode(PLAY_GET_INSTANCE(hplay),
+ (uint32_t)input_mux);
}
/* PLAY Configuration - Unitary functions for lookup table *********************/
@@ -1912,14 +1813,14 @@ HAL_PLAY_EdgeDetectionModeTypeDef HAL_PLAY_INPUT_GetEdgeDetectionMode(const HAL_
* @param lut Lookup table.
* @param truth_table_value The value can be in range [0..0xFFFF].
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter or current state is not @ref HAL_PLAY_STATE_READY.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_LUT_SetTruthTable(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut,
+HAL_StatusTypeDef HAL_PLAY_LUT_SetTruthTable(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut,
uint32_t truth_table_value)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -1927,18 +1828,11 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetTruthTable(HAL_PLAY_HandleTypeDef *hplay, HAL_
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
assert_param(IS_PLAY_LUT(p_playx, lut));
assert_param(IS_PLAY_LUT_TRUTH_TABLE_VALUE(truth_table_value));
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
+ if (hplay->State != HAL_PLAY_STATE_READY)
{
return HAL_ERROR;
}
@@ -1953,28 +1847,21 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetTruthTable(HAL_PLAY_HandleTypeDef *hplay, HAL_
* @brief Retrieve the truth table value for a lookup table in the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param lut Lookup table.
- * @return Value in range [0..0xFFFF].
* @note Function will return 0 if the parameters are invalid.
+ * @return Value in range [0..0xFFFF].
*/
uint32_t HAL_PLAY_LUT_GetTruthTable(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut)
{
const PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
- /* Return 0 as default value */
return 0U;
}
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- /* Return 0 as default value */
- return 0U;
- }
-
assert_param(IS_PLAY_LUT(p_playx, lut));
return LL_PLAY_LUT_GetTruthTable(p_playx, (uint32_t)lut);
@@ -1987,15 +1874,15 @@ uint32_t HAL_PLAY_LUT_GetTruthTable(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLA
* @param lut_input Lookup table Input.
* @param input_source Signal source.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter or current state is not @ref HAL_PLAY_STATE_READY.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_LUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut,
+HAL_StatusTypeDef HAL_PLAY_LUT_SetSource(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut,
HAL_PLAY_LUT_InputTypeDef lut_input,
HAL_PLAY_LUT_InputSourceTypeDef input_source)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2003,19 +1890,12 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
assert_param(IS_PLAY_LUT(p_playx, lut));
assert_param(IS_PLAY_LUT_INPUT(lut_input));
assert_param(IS_PLAY_LUT_INPUT_SOURCE(p_playx, lut, input_source));
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
+ if (hplay->State != HAL_PLAY_STATE_READY)
{
return HAL_ERROR;
}
@@ -2030,29 +1910,22 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param lut Lookup table.
* @param lut_input Lookup table Input.
- * @return Lookup table input source.
* @note Function will return @ref HAL_PLAY_LUT_INPUT_DEFAULT if the parameters are invalid.
+ * @return Lookup table input source.
*/
HAL_PLAY_LUT_InputSourceTypeDef HAL_PLAY_LUT_GetSource(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut,
HAL_PLAY_LUT_InputTypeDef lut_input)
{
const PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
- /* Return HAL_PLAY_LUT_INPUT_DEFAULT as default value */
return HAL_PLAY_LUT_INPUT_DEFAULT;
}
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- /* Return HAL_PLAY_LUT_INPUT_DEFAULT as default value */
- return HAL_PLAY_LUT_INPUT_DEFAULT;
- }
-
assert_param(IS_PLAY_LUT(p_playx, lut));
assert_param(IS_PLAY_LUT_INPUT(lut_input));
@@ -2065,14 +1938,14 @@ HAL_PLAY_LUT_InputSourceTypeDef HAL_PLAY_LUT_GetSource(const HAL_PLAY_HandleType
* @param lut Lookup table.
* @param source Signal source.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter or current state is not @ref HAL_PLAY_STATE_READY.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_LUT_SetClockGateSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut,
+HAL_StatusTypeDef HAL_PLAY_LUT_SetClockGateSource(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_LUTTypeDef lut,
HAL_PLAY_LUT_ClkGateSourceTypeDef source)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2080,18 +1953,11 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetClockGateSource(HAL_PLAY_HandleTypeDef *hplay,
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
assert_param(IS_PLAY_LUT(p_playx, lut));
assert_param(IS_PLAY_LUT_CLOCK_GATE_SOURCE(p_playx, source));
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
+ if (hplay->State != HAL_PLAY_STATE_READY)
{
return HAL_ERROR;
}
@@ -2105,29 +1971,22 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetClockGateSource(HAL_PLAY_HandleTypeDef *hplay,
* @brief Retrieve the clock gate source for a lookup table in the PLAY peripheral.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param lut Lookup table.
- * @return Lookup table clock gate source.
* @note Function will return @ref HAL_PLAY_LUT_CLK_GATE_OFF if the parameters are invalid.
+ * @return Lookup table clock gate source.
*/
HAL_PLAY_LUT_ClkGateSourceTypeDef HAL_PLAY_LUT_GetClockGateSource(const HAL_PLAY_HandleTypeDef *hplay,
HAL_PLAY_LUTTypeDef lut)
{
const PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
- /* Return HAL_PLAY_LUT_CLK_GATE_OFF as default value */
return HAL_PLAY_LUT_CLK_GATE_OFF;
}
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- /* Return HAL_PLAY_LUT_CLK_GATE_OFF as default value */
- return HAL_PLAY_LUT_CLK_GATE_OFF;
- }
-
assert_param(IS_PLAY_LUT(p_playx, lut));
return (HAL_PLAY_LUT_ClkGateSourceTypeDef)LL_PLAY_LUT_GetClockGate(p_playx, (uint32_t)lut);
@@ -2140,47 +1999,47 @@ HAL_PLAY_LUT_ClkGateSourceTypeDef HAL_PLAY_LUT_GetClockGateSource(const HAL_PLAY
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param output_mux Output multiplexer.
* @param source Lookup table output. This parameter can be one of the following values:
- * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT
- * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED
- * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT
+ * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED
+ * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter or current state is not @ref HAL_PLAY_STATE_READY.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_OUTTypeDef output_mux,
+HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetSource(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_OUTTypeDef output_mux,
uint32_t source)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2188,18 +2047,11 @@ HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_P
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
assert_param(IS_PLAY_OUT(output_mux));
assert_param(IS_PLAY_OUT_SOURCE(p_playx, source));
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
+ if (hplay->State != HAL_PLAY_STATE_READY)
{
return HAL_ERROR;
}
@@ -2250,26 +2102,15 @@ HAL_StatusTypeDef HAL_PLAY_OUTPUT_SetSource(HAL_PLAY_HandleTypeDef *hplay, HAL_P
*/
uint32_t HAL_PLAY_OUTPUT_GetSource(const HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_OUTTypeDef output_mux)
{
- const PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
- /* Return 0 as default value */
- return 0U;
- }
-
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- /* Return 0 as default value */
return 0U;
}
assert_param(IS_PLAY_OUT(output_mux));
- return LL_PLAY_OUTPUT_GetSource(p_playx, (uint32_t)output_mux);
+ return LL_PLAY_OUTPUT_GetSource(PLAY_GET_INSTANCE(hplay), (uint32_t)output_mux);
}
/**
@@ -2290,14 +2131,14 @@ A set of functions allowing to start/stop the PLAYx peripheral:
* @note The falling and rising edge configuration is exclusive and thus, a lookup table output cannot be
* configured for both rising and falling edges at the same time.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
HAL_StatusTypeDef HAL_PLAY_Start(HAL_PLAY_HandleTypeDef *hplay, const HAL_PLAY_EdgeTriggerConfTypeDef *p_config)
{
PLAY_TypeDef *p_playx;
uint32_t is_locked;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2307,28 +2148,20 @@ HAL_StatusTypeDef HAL_PLAY_Start(HAL_PLAY_HandleTypeDef *hplay, const HAL_PLAY_E
if (p_config == NULL)
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param((p_config->lut_out_falling_mask & p_config->lut_out_rising_mask) == 0U);
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_READY)
+ if (hplay->State != HAL_PLAY_STATE_READY)
{
return HAL_ERROR;
}
- /* Lock the configuration only if already done.
+ /* Lock the configuration only if it is currently unlocked.
In context where configuration register requires a privilege and/or secure write access:
- this check prevents generating an unexpected illegal access (ilac) event if the caller does not have
the required permissions.
@@ -2341,7 +2174,7 @@ HAL_StatusTypeDef HAL_PLAY_Start(HAL_PLAY_HandleTypeDef *hplay, const HAL_PLAY_E
LL_PLAY_Lock(p_playx);
}
- hplay->global_state = HAL_PLAY_STATE_BUSY;
+ hplay->State = HAL_PLAY_STATE_BUSY;
return PLAY_LUT_SetEdgeTrigger(hplay, p_config, PLAY_WRITE_TIMEOUT_MS);
}
@@ -2358,7 +2191,7 @@ HAL_StatusTypeDef HAL_PLAY_Stop(HAL_PLAY_HandleTypeDef *hplay)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2366,17 +2199,8 @@ HAL_StatusTypeDef HAL_PLAY_Stop(HAL_PLAY_HandleTypeDef *hplay)
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
-
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
@@ -2386,7 +2210,7 @@ HAL_StatusTypeDef HAL_PLAY_Stop(HAL_PLAY_HandleTypeDef *hplay)
LL_PLAY_Unlock(p_playx);
- hplay->global_state = HAL_PLAY_STATE_READY;
+ hplay->State = HAL_PLAY_STATE_READY;
return HAL_OK;
}
@@ -2415,41 +2239,29 @@ A set of functions allowing to manage the lookup table Output of PLAYx periphera
* @note The falling and rising edge configuration is exclusive and thus, a lookup table output cannot be
* configured for both rising and falling edges at the same time.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
* @retval HAL_BUSY A write is pending.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
HAL_StatusTypeDef HAL_PLAY_LUT_SetEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay,
const HAL_PLAY_EdgeTriggerConfTypeDef *p_config,
uint32_t timeout_ms)
{
- PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
if (p_config == NULL)
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param((p_config->lut_out_falling_mask & p_config->lut_out_rising_mask) == 0U);
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
@@ -2458,21 +2270,21 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay,
}
/**
- * @brief Configure the Edge Triggers in mode: flag transition of lookup table outputs.
+ * @brief Configure the Edge Triggers in interrupt mode: flag transition of lookup table outputs.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param p_config Pointer to a @ref HAL_PLAY_EdgeTriggerConfTypeDef structure for the Edge Triggers configuration.
* @note The falling and rising edge configuration is exclusive and thus, a lookup table output cannot be
* configured for both rising and falling edges at the same time.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
* @retval HAL_BUSY A write is pending.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
HAL_StatusTypeDef HAL_PLAY_LUT_SetEdgeTrigger_IT(HAL_PLAY_HandleTypeDef *hplay,
const HAL_PLAY_EdgeTriggerConfTypeDef *p_config)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2480,24 +2292,16 @@ HAL_StatusTypeDef HAL_PLAY_LUT_SetEdgeTrigger_IT(HAL_PLAY_HandleTypeDef *hplay,
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
if (p_config == NULL)
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param((p_config->lut_out_falling_mask & p_config->lut_out_rising_mask) == 0U);
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
@@ -2527,7 +2331,7 @@ HAL_StatusTypeDef HAL_PLAY_LUT_GetEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay, HAL
{
const PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2535,22 +2339,13 @@ HAL_StatusTypeDef HAL_PLAY_LUT_GetEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay, HAL
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
if (p_config == NULL)
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
-
/* Retrieve the configuration */
p_config->lut_out_rising_mask = LL_PLAY_LUT_GetEdgeTrigger(p_playx);
p_config->lut_out_falling_mask = ~p_config->lut_out_rising_mask;
@@ -2564,45 +2359,45 @@ HAL_StatusTypeDef HAL_PLAY_LUT_GetEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay, HAL
* @param poll_mode Polling mode of type @ref HAL_PLAY_PollingEdgeTriggerTypeDef.
* @param edge_trig_mask Mask of flags to poll.
* This parameter can be a combination of the following values:
- * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The Flag of LUT0 direct output
- * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The Flag of LUT1 direct output
- * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The Flag of LUT2 direct output
- * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The Flag of LUT3 direct output
- * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The Flag of LUT4 direct output
- * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The Flag of LUT5 direct output
- * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The Flag of LUT6 direct output
- * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The Flag of LUT7 direct output
- * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The Flag of LUT8 direct output
- * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The Flag of LUT9 direct output
- * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The Flag of LUT10 direct output
- * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The Flag of LUT11 direct output
- * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The Flag of LUT12 direct output
- * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The Flag of LUT13 direct output
- * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The Flag of LUT14 direct output
- * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The Flag of LUT15 direct output
- * @arg @ref HAL_PLAY_LUT_ALL_OUT_DIRECT : All Flags of LUTs direct outputs
- * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The Flag of LUT0 registered output
- * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The Flag of LUT1 registered output
- * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The Flag of LUT2 registered output
- * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The Flag of LUT3 registered output
- * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The Flag of LUT4 registered output
- * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The Flag of LUT5 registered output
- * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The Flag of LUT6 registered output
- * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The Flag of LUT7 registered output
- * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The Flag of LUT8 registered output
- * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The Flag of LUT9 registered output
- * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The Flag of LUT10 registered output
- * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The Flag of LUT11 registered output
- * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The Flag of LUT12 registered output
- * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The Flag of LUT13 registered output
- * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The Flag of LUT14 registered output
- * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The Flag of LUT15 registered output
- * @arg @ref HAL_PLAY_LUT_ALL_OUT_REGISTERED : All Flags of LUTs registered outputs
+ * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The flag of LUT0 direct output
+ * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The flag of LUT1 direct output
+ * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The flag of LUT2 direct output
+ * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The flag of LUT3 direct output
+ * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The flag of LUT4 direct output
+ * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The flag of LUT5 direct output
+ * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The flag of LUT6 direct output
+ * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The flag of LUT7 direct output
+ * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The flag of LUT8 direct output
+ * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The flag of LUT9 direct output
+ * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The flag of LUT10 direct output
+ * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The flag of LUT11 direct output
+ * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The flag of LUT12 direct output
+ * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The flag of LUT13 direct output
+ * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The flag of LUT14 direct output
+ * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The flag of LUT15 direct output
+ * @arg @ref HAL_PLAY_LUT_ALL_OUT_DIRECT : All flags of LUTs direct outputs
+ * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The flag of LUT0 registered output
+ * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The flag of LUT1 registered output
+ * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The flag of LUT2 registered output
+ * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The flag of LUT3 registered output
+ * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The flag of LUT4 registered output
+ * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The flag of LUT5 registered output
+ * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The flag of LUT6 registered output
+ * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The flag of LUT7 registered output
+ * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The flag of LUT8 registered output
+ * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The flag of LUT9 registered output
+ * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The flag of LUT10 registered output
+ * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The flag of LUT11 registered output
+ * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The flag of LUT12 registered output
+ * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The flag of LUT13 registered output
+ * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The flag of LUT14 registered output
+ * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The flag of LUT15 registered output
+ * @arg @ref HAL_PLAY_LUT_ALL_OUT_REGISTERED : All flags of LUTs registered outputs
* @param timeout_ms Timeout duration (in ms).
* @param p_edge_trig_mask_status Pointer to return the triggered lookup table output flags.
* @retval HAL_OK Operation completed successfully.
* @retval HAL_TIMEOUT Operation timed out.
- * @retval HAL_ERROR Invalid parameter.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
HAL_StatusTypeDef HAL_PLAY_LUT_PollForEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay,
HAL_PLAY_PollingEdgeTriggerTypeDef poll_mode,
@@ -2612,7 +2407,7 @@ HAL_StatusTypeDef HAL_PLAY_LUT_PollForEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay,
PLAY_TypeDef *p_playx;
uint32_t tickstart;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2620,28 +2415,23 @@ HAL_StatusTypeDef HAL_PLAY_LUT_PollForEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay,
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
+ if (p_edge_trig_mask_status == NULL)
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- /* Return error status */
return HAL_ERROR;
}
assert_param(IS_PLAY_POLL_MODE(poll_mode));
assert_param((edge_trig_mask != 0U));
- assert_param((p_edge_trig_mask_status != NULL));
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
/* Check the peripheral state */
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
- /* Get tick count */
+ /* Get the current tick value */
tickstart = HAL_GetTick();
/* Check selected event flag */
@@ -2684,71 +2474,59 @@ HAL_StatusTypeDef HAL_PLAY_LUT_PollForEdgeTrigger(HAL_PLAY_HandleTypeDef *hplay,
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param its_mask Mask of lookup table output interrupt to enable.
* This parameter can be a combination of the following values:
- * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The Interrupt of LUT0 direct output
- * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The Interrupt of LUT1 direct output
- * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The Interrupt of LUT2 direct output
- * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The Interrupt of LUT3 direct output
- * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The Interrupt of LUT4 direct output
- * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The Interrupt of LUT5 direct output
- * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The Interrupt of LUT6 direct output
- * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The Interrupt of LUT7 direct output
- * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The Interrupt of LUT8 direct output
- * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The Interrupt of LUT9 direct output
- * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The Interrupt of LUT10 direct output
- * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The Interrupt of LUT11 direct output
- * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The Interrupt of LUT12 direct output
- * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The Interrupt of LUT13 direct output
- * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The Interrupt of LUT14 direct output
- * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The Interrupt of LUT15 direct output
- * @arg @ref HAL_PLAY_LUT_ALL_OUT_DIRECT : All Interrupts of LUTs direct outputs
- * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The Interrupt of LUT0 registered output
- * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The Interrupt of LUT1 registered output
- * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The Interrupt of LUT2 registered output
- * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The Interrupt of LUT3 registered output
- * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The Interrupt of LUT4 registered output
- * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The Interrupt of LUT5 registered output
- * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The Interrupt of LUT6 registered output
- * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The Interrupt of LUT7 registered output
- * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The Interrupt of LUT8 registered output
- * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The Interrupt of LUT9 registered output
- * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The Interrupt of LUT10 registered output
- * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The Interrupt of LUT11 registered output
- * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The Interrupt of LUT12 registered output
- * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The Interrupt of LUT13 registered output
- * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The Interrupt of LUT14 registered output
- * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The Interrupt of LUT15 registered output
- * @arg @ref HAL_PLAY_LUT_ALL_OUT_REGISTERED : All Interrupts of LUTs registered outputs
+ * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The interrupt of LUT0 direct output
+ * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The interrupt of LUT1 direct output
+ * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The interrupt of LUT2 direct output
+ * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The interrupt of LUT3 direct output
+ * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The interrupt of LUT4 direct output
+ * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The interrupt of LUT5 direct output
+ * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The interrupt of LUT6 direct output
+ * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The interrupt of LUT7 direct output
+ * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The interrupt of LUT8 direct output
+ * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The interrupt of LUT9 direct output
+ * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The interrupt of LUT10 direct output
+ * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The interrupt of LUT11 direct output
+ * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The interrupt of LUT12 direct output
+ * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The interrupt of LUT13 direct output
+ * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The interrupt of LUT14 direct output
+ * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The interrupt of LUT15 direct output
+ * @arg @ref HAL_PLAY_LUT_ALL_OUT_DIRECT : All interrupts of LUTs direct outputs
+ * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The interrupt of LUT0 registered output
+ * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The interrupt of LUT1 registered output
+ * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The interrupt of LUT2 registered output
+ * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The interrupt of LUT3 registered output
+ * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The interrupt of LUT4 registered output
+ * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The interrupt of LUT5 registered output
+ * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The interrupt of LUT6 registered output
+ * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The interrupt of LUT7 registered output
+ * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The interrupt of LUT8 registered output
+ * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The interrupt of LUT9 registered output
+ * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The interrupt of LUT10 registered output
+ * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The interrupt of LUT11 registered output
+ * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The interrupt of LUT12 registered output
+ * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The interrupt of LUT13 registered output
+ * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The interrupt of LUT14 registered output
+ * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The interrupt of LUT15 registered output
+ * @arg @ref HAL_PLAY_LUT_ALL_OUT_REGISTERED : All interrupts of LUTs registered outputs
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_LUT_EnableIT(HAL_PLAY_HandleTypeDef *hplay, uint32_t its_mask)
+HAL_StatusTypeDef HAL_PLAY_LUT_EnableIT(const HAL_PLAY_HandleTypeDef *hplay, uint32_t its_mask)
{
- PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param((its_mask != 0U));
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
- LL_PLAY_LUT_EnableIT(p_playx, its_mask);
+ LL_PLAY_LUT_EnableIT(PLAY_GET_INSTANCE(hplay), its_mask);
return HAL_OK;
}
@@ -2758,70 +2536,59 @@ HAL_StatusTypeDef HAL_PLAY_LUT_EnableIT(HAL_PLAY_HandleTypeDef *hplay, uint32_t
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param its_mask Mask of lookup table output interrupt to disable
* This parameter can be a combination of the following values:
- * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The Interrupt of LUT0 direct output
- * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The Interrupt of LUT1 direct output
- * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The Interrupt of LUT2 direct output
- * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The Interrupt of LUT3 direct output
- * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The Interrupt of LUT4 direct output
- * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The Interrupt of LUT5 direct output
- * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The Interrupt of LUT6 direct output
- * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The Interrupt of LUT7 direct output
- * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The Interrupt of LUT8 direct output
- * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The Interrupt of LUT9 direct output
- * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The Interrupt of LUT10 direct output
- * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The Interrupt of LUT11 direct output
- * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The Interrupt of LUT12 direct output
- * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The Interrupt of LUT13 direct output
- * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The Interrupt of LUT14 direct output
- * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The Interrupt of LUT15 direct output
- * @arg @ref HAL_PLAY_LUT_ALL_OUT_DIRECT : All Interrupts of LUTs direct outputs
- * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The Interrupt of LUT0 registered output
- * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The Interrupt of LUT1 registered output
- * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The Interrupt of LUT2 registered output
- * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The Interrupt of LUT3 registered output
- * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The Interrupt of LUT4 registered output
- * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The Interrupt of LUT5 registered output
- * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The Interrupt of LUT6 registered output
- * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The Interrupt of LUT7 registered output
- * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The Interrupt of LUT8 registered output
- * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The Interrupt of LUT9 registered output
- * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The Interrupt of LUT10 registered output
- * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The Interrupt of LUT11 registered output
- * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The Interrupt of LUT12 registered output
- * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The Interrupt of LUT13 registered output
- * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The Interrupt of LUT14 registered output
- * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The Interrupt of LUT15 registered output
- * @arg @ref HAL_PLAY_LUT_ALL_OUT_REGISTERED : All Interrupts of LUTs registered outputs
+ * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The interrupt of LUT0 direct output
+ * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The interrupt of LUT1 direct output
+ * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The interrupt of LUT2 direct output
+ * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The interrupt of LUT3 direct output
+ * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The interrupt of LUT4 direct output
+ * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The interrupt of LUT5 direct output
+ * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The interrupt of LUT6 direct output
+ * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The interrupt of LUT7 direct output
+ * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The interrupt of LUT8 direct output
+ * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The interrupt of LUT9 direct output
+ * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The interrupt of LUT10 direct output
+ * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The interrupt of LUT11 direct output
+ * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The interrupt of LUT12 direct output
+ * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The interrupt of LUT13 direct output
+ * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The interrupt of LUT14 direct output
+ * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The interrupt of LUT15 direct output
+ * @arg @ref HAL_PLAY_LUT_ALL_OUT_DIRECT : All interrupts of LUTs direct outputs
+ * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The interrupt of LUT0 registered output
+ * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The interrupt of LUT1 registered output
+ * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The interrupt of LUT2 registered output
+ * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The interrupt of LUT3 registered output
+ * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The interrupt of LUT4 registered output
+ * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The interrupt of LUT5 registered output
+ * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The interrupt of LUT6 registered output
+ * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The interrupt of LUT7 registered output
+ * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The interrupt of LUT8 registered output
+ * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The interrupt of LUT9 registered output
+ * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The interrupt of LUT10 registered output
+ * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The interrupt of LUT11 registered output
+ * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The interrupt of LUT12 registered output
+ * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The interrupt of LUT13 registered output
+ * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The interrupt of LUT14 registered output
+ * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The interrupt of LUT15 registered output
+ * @arg @ref HAL_PLAY_LUT_ALL_OUT_REGISTERED : All interrupts of LUTs registered outputs
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_LUT_DisableIT(HAL_PLAY_HandleTypeDef *hplay, uint32_t its_mask)
+HAL_StatusTypeDef HAL_PLAY_LUT_DisableIT(const HAL_PLAY_HandleTypeDef *hplay, uint32_t its_mask)
{
- PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
+ assert_param((its_mask != 0U));
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
- LL_PLAY_LUT_DisableIT(p_playx, its_mask);
+ LL_PLAY_LUT_DisableIT(PLAY_GET_INSTANCE(hplay), its_mask);
return HAL_OK;
}
@@ -2831,57 +2598,48 @@ HAL_StatusTypeDef HAL_PLAY_LUT_DisableIT(HAL_PLAY_HandleTypeDef *hplay, uint32_t
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @return Mask of enabled lookup table output interrupts.
* This returned parameter can be a combination of the following values:
- * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The Interrupt of LUT0 direct output
- * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The Interrupt of LUT1 direct output
- * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The Interrupt of LUT2 direct output
- * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The Interrupt of LUT3 direct output
- * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The Interrupt of LUT4 direct output
- * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The Interrupt of LUT5 direct output
- * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The Interrupt of LUT6 direct output
- * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The Interrupt of LUT7 direct output
- * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The Interrupt of LUT8 direct output
- * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The Interrupt of LUT9 direct output
- * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The Interrupt of LUT10 direct output
- * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The Interrupt of LUT11 direct output
- * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The Interrupt of LUT12 direct output
- * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The Interrupt of LUT13 direct output
- * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The Interrupt of LUT14 direct output
- * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The Interrupt of LUT15 direct output
- * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The Interrupt of LUT0 registered output
- * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The Interrupt of LUT1 registered output
- * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The Interrupt of LUT2 registered output
- * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The Interrupt of LUT3 registered output
- * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The Interrupt of LUT4 registered output
- * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The Interrupt of LUT5 registered output
- * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The Interrupt of LUT6 registered output
- * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The Interrupt of LUT7 registered output
- * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The Interrupt of LUT8 registered output
- * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The Interrupt of LUT9 registered output
- * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The Interrupt of LUT10 registered output
- * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The Interrupt of LUT11 registered output
- * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The Interrupt of LUT12 registered output
- * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The Interrupt of LUT13 registered output
- * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The Interrupt of LUT14 registered output
- * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The Interrupt of LUT15 registered output
+ * @arg @ref HAL_PLAY_LUT0_OUT_DIRECT : The interrupt of LUT0 direct output
+ * @arg @ref HAL_PLAY_LUT1_OUT_DIRECT : The interrupt of LUT1 direct output
+ * @arg @ref HAL_PLAY_LUT2_OUT_DIRECT : The interrupt of LUT2 direct output
+ * @arg @ref HAL_PLAY_LUT3_OUT_DIRECT : The interrupt of LUT3 direct output
+ * @arg @ref HAL_PLAY_LUT4_OUT_DIRECT : The interrupt of LUT4 direct output
+ * @arg @ref HAL_PLAY_LUT5_OUT_DIRECT : The interrupt of LUT5 direct output
+ * @arg @ref HAL_PLAY_LUT6_OUT_DIRECT : The interrupt of LUT6 direct output
+ * @arg @ref HAL_PLAY_LUT7_OUT_DIRECT : The interrupt of LUT7 direct output
+ * @arg @ref HAL_PLAY_LUT8_OUT_DIRECT : The interrupt of LUT8 direct output
+ * @arg @ref HAL_PLAY_LUT9_OUT_DIRECT : The interrupt of LUT9 direct output
+ * @arg @ref HAL_PLAY_LUT10_OUT_DIRECT : The interrupt of LUT10 direct output
+ * @arg @ref HAL_PLAY_LUT11_OUT_DIRECT : The interrupt of LUT11 direct output
+ * @arg @ref HAL_PLAY_LUT12_OUT_DIRECT : The interrupt of LUT12 direct output
+ * @arg @ref HAL_PLAY_LUT13_OUT_DIRECT : The interrupt of LUT13 direct output
+ * @arg @ref HAL_PLAY_LUT14_OUT_DIRECT : The interrupt of LUT14 direct output
+ * @arg @ref HAL_PLAY_LUT15_OUT_DIRECT : The interrupt of LUT15 direct output
+ * @arg @ref HAL_PLAY_LUT0_OUT_REGISTERED : The interrupt of LUT0 registered output
+ * @arg @ref HAL_PLAY_LUT1_OUT_REGISTERED : The interrupt of LUT1 registered output
+ * @arg @ref HAL_PLAY_LUT2_OUT_REGISTERED : The interrupt of LUT2 registered output
+ * @arg @ref HAL_PLAY_LUT3_OUT_REGISTERED : The interrupt of LUT3 registered output
+ * @arg @ref HAL_PLAY_LUT4_OUT_REGISTERED : The interrupt of LUT4 registered output
+ * @arg @ref HAL_PLAY_LUT5_OUT_REGISTERED : The interrupt of LUT5 registered output
+ * @arg @ref HAL_PLAY_LUT6_OUT_REGISTERED : The interrupt of LUT6 registered output
+ * @arg @ref HAL_PLAY_LUT7_OUT_REGISTERED : The interrupt of LUT7 registered output
+ * @arg @ref HAL_PLAY_LUT8_OUT_REGISTERED : The interrupt of LUT8 registered output
+ * @arg @ref HAL_PLAY_LUT9_OUT_REGISTERED : The interrupt of LUT9 registered output
+ * @arg @ref HAL_PLAY_LUT10_OUT_REGISTERED : The interrupt of LUT10 registered output
+ * @arg @ref HAL_PLAY_LUT11_OUT_REGISTERED : The interrupt of LUT11 registered output
+ * @arg @ref HAL_PLAY_LUT12_OUT_REGISTERED : The interrupt of LUT12 registered output
+ * @arg @ref HAL_PLAY_LUT13_OUT_REGISTERED : The interrupt of LUT13 registered output
+ * @arg @ref HAL_PLAY_LUT14_OUT_REGISTERED : The interrupt of LUT14 registered output
+ * @arg @ref HAL_PLAY_LUT15_OUT_REGISTERED : The interrupt of LUT15 registered output
*/
uint32_t HAL_PLAY_LUT_GetIT(const HAL_PLAY_HandleTypeDef *hplay)
{
- const PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return 0U;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- return 0U;
- }
-
- return LL_PLAY_LUT_GetIT(p_playx);
+ return LL_PLAY_LUT_GetIT(PLAY_GET_INSTANCE(hplay));
}
/**
@@ -2923,16 +2681,16 @@ A set of functions allowing to manage the Software Triggers:
* @param state State to set of type @ref HAL_PLAY_SWTriggerStateTypeDef.
* @param timeout_ms Timeout duration (in ms).
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
* @retval HAL_BUSY A write is pending.
* @retval HAL_TIMEOUT Timeout reached.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger(HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers,
+HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger(const HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers,
HAL_PLAY_SWTriggerStateTypeDef state, uint32_t timeout_ms)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -2940,17 +2698,10 @@ HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger(HAL_PLAY_HandleTypeDef *hplay, uint32_
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(IS_PLAY_SWTRIGGER_MSK(sw_triggers));
+ assert_param(IS_PLAY_SWTRIGGER_STATE(state));
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
@@ -3016,15 +2767,15 @@ HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger(HAL_PLAY_HandleTypeDef *hplay, uint32_
* @arg @ref HAL_PLAY_SWTRIG_ALL : All software triggers
* @param state State to set of type @ref HAL_PLAY_SWTriggerStateTypeDef.
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
* @retval HAL_BUSY A write is pending.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger_IT(HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers,
+HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger_IT(const HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers,
HAL_PLAY_SWTriggerStateTypeDef state)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -3032,17 +2783,10 @@ HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger_IT(HAL_PLAY_HandleTypeDef *hplay, uint
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(IS_PLAY_SWTRIGGER_MSK(sw_triggers));
+ assert_param(IS_PLAY_SWTRIGGER_STATE(state));
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
@@ -3093,15 +2837,16 @@ HAL_StatusTypeDef HAL_PLAY_WriteSWTrigger_IT(HAL_PLAY_HandleTypeDef *hplay, uint
* @arg @ref HAL_PLAY_SWTRIG_ALL : All software triggers
* @param timeout_ms Timeout duration (in ms).
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
* @retval HAL_BUSY A write is pending.
* @retval HAL_TIMEOUT Timeout reached.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger(HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers, uint32_t timeout_ms)
+HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger(const HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers,
+ uint32_t timeout_ms)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -3109,17 +2854,9 @@ HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger(HAL_PLAY_HandleTypeDef *hplay, uint32
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(IS_PLAY_SWTRIGGER_MSK(sw_triggers));
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
@@ -3177,14 +2914,14 @@ HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger(HAL_PLAY_HandleTypeDef *hplay, uint32
* @arg @ref HAL_PLAY_SWTRIG15 : Software trigger 15
* @arg @ref HAL_PLAY_SWTRIG_ALL : All software triggers
* @retval HAL_OK Operation completed successfully.
- * @retval HAL_ERROR Invalid parameter.
* @retval HAL_BUSY A write is pending.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger_IT(HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers)
+HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger_IT(const HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_triggers)
{
PLAY_TypeDef *p_playx;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
@@ -3192,17 +2929,9 @@ HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger_IT(HAL_PLAY_HandleTypeDef *hplay, uin
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_playx == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
assert_param(IS_PLAY_SWTRIGGER_MSK(sw_triggers));
- if (hplay->global_state != HAL_PLAY_STATE_BUSY)
+ if (hplay->State != HAL_PLAY_STATE_BUSY)
{
return HAL_ERROR;
}
@@ -3241,33 +2970,22 @@ HAL_StatusTypeDef HAL_PLAY_ToggleSWTrigger_IT(HAL_PLAY_HandleTypeDef *hplay, uin
* @arg @ref HAL_PLAY_SWTRIG13 : Software trigger 13
* @arg @ref HAL_PLAY_SWTRIG14 : Software trigger 14
* @arg @ref HAL_PLAY_SWTRIG15 : Software trigger 15
- * @note This function will return HAL_PLAY_SW_TRIGGER_RESET in case of wrong parameter.
+ * @note This function will return @ref HAL_PLAY_SW_TRIGGER_RESET in case of wrong parameter.
* @return State of Software Trigger.
*/
HAL_PLAY_SWTriggerStateTypeDef HAL_PLAY_ReadSWTrigger(const HAL_PLAY_HandleTypeDef *hplay, uint32_t sw_trig)
{
- const PLAY_TypeDef *p_playx;
-
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
- /* Return HAL_PLAY_SW_TRIGGER_RESET as default value */
return HAL_PLAY_SW_TRIGGER_RESET;
}
- p_playx = PLAY_GET_INSTANCE(hplay);
-
- if (p_playx == NULL)
- {
- /* Return HAL_PLAY_SW_TRIGGER_RESET as default value */
- return HAL_PLAY_SW_TRIGGER_RESET;
- }
-
- /* Check the parameters */
- assert_param(IS_PLAY_ALL_INSTANCE(hplay->instance));
+ assert_param(IS_PLAY_SWTRIGGER(sw_trig));
/* Read the SW Trigger values */
- return ((LL_PLAY_IsSWTriggerSet(p_playx, sw_trig) != 0U) ? HAL_PLAY_SW_TRIGGER_SET : HAL_PLAY_SW_TRIGGER_RESET);
+ return ((LL_PLAY_IsSWTriggerSet(PLAY_GET_INSTANCE(hplay), sw_trig) != 0U)
+ ? HAL_PLAY_SW_TRIGGER_SET : HAL_PLAY_SW_TRIGGER_RESET);
}
/**
@@ -3282,7 +3000,7 @@ A set of functions allowing to handle the PLAY interrupts in asynchronous mode.
- HAL_PLAY_IRQHandler()
- Callback functions:
- - Depending on the process function used, different callback might be triggered:
+ - Depending on the process function used, different callbacks might be triggered:
| Process API \n \ \n Callbacks | HAL_PLAY_WriteSWTrigger_IT() | HAL_PLAY_ToggleSWTrigger_IT() |
|-----------------------------------------|:----------------------------:|:-----------------------------:|
@@ -3313,7 +3031,6 @@ void HAL_PLAY_IRQHandler(HAL_PLAY_HandleTypeDef *hplay)
PLAY_TypeDef *p_playx;
p_playx = PLAY_GET_INSTANCE(hplay);
- assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
/* Get status of general interrupts */
uint32_t reg_ier = LL_PLAY_READ_REG(p_playx, IER);
@@ -3399,13 +3116,13 @@ void HAL_PLAY_IRQHandler(HAL_PLAY_HandleTypeDef *hplay)
* @warning This weak function must not be modified. When the callback is needed,
* it must be implemented in the user file.
*/
-__WEAK void HAL_PLAY_SWTriggerWriteCpltCallback(HAL_PLAY_HandleTypeDef *hplay)
+__weak void HAL_PLAY_SWTriggerWriteCpltCallback(HAL_PLAY_HandleTypeDef *hplay)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hplay);
/* WARNING: This function must not be modified. When the callback is needed,
- function HAL_PLAY_SWTriggerWriteCpltCallback must be implemented in the user file.
+ function HAL_PLAY_SWTriggerWriteCpltCallback() must be implemented in the user file.
*/
}
@@ -3415,13 +3132,13 @@ __WEAK void HAL_PLAY_SWTriggerWriteCpltCallback(HAL_PLAY_HandleTypeDef *hplay)
* @warning This weak function must not be modified. When the callback is needed,
* it must be implemented in the user file.
*/
-__WEAK void HAL_PLAY_EdgeTriggerWriteCpltCallback(HAL_PLAY_HandleTypeDef *hplay)
+__weak void HAL_PLAY_EdgeTriggerWriteCpltCallback(HAL_PLAY_HandleTypeDef *hplay)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hplay);
/* WARNING: This function must not be modified. When the callback is needed,
- function HAL_PLAY_EdgeTriggerWriteCpltCallback must be implemented in the user file.
+ function HAL_PLAY_EdgeTriggerWriteCpltCallback() must be implemented in the user file.
*/
}
@@ -3439,7 +3156,7 @@ __weak void HAL_PLAY_LUTOutputRisingCallback(HAL_PLAY_HandleTypeDef *hplay, uint
UNUSED(edge_trig_mask_status);
/* WARNING: This function must not be modified. When the callback is needed,
- function HAL_PLAY_LUTOutputRisingCallback must be implemented in the user file.
+ function HAL_PLAY_LUTOutputRisingCallback() must be implemented in the user file.
*/
}
@@ -3450,55 +3167,55 @@ __weak void HAL_PLAY_LUTOutputRisingCallback(HAL_PLAY_HandleTypeDef *hplay, uint
* @warning This weak function must not be modified. When the callback is needed,
* it must be implemented in the user file.
*/
-__WEAK void HAL_PLAY_LUTOutputFallingCallback(HAL_PLAY_HandleTypeDef *hplay, uint32_t edge_trig_mask_status)
+__weak void HAL_PLAY_LUTOutputFallingCallback(HAL_PLAY_HandleTypeDef *hplay, uint32_t edge_trig_mask_status)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hplay);
UNUSED(edge_trig_mask_status);
/* WARNING: This function must not be modified. When the callback is needed,
- function HAL_PLAY_LUTOutputFallingCallback must be implemented in the user file.
+ function HAL_PLAY_LUTOutputFallingCallback() must be implemented in the user file.
*/
}
#if (USE_HAL_PLAY_REGISTER_CALLBACKS == 1)
/**
- * @brief Register an User PLAY Callback.
- * @note The User PLAY Callback is to be used instead of the weak predefined callback.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @param CallbackID ID of the callback to be registered.
- * This parameter can be one of the following values:
- * @arg @ref HAL_PLAY_SW_TRIGGER_WRITE_CPLT_CB_ID SWIN Write Complete callback ID
- * @arg @ref HAL_PLAY_EDGE_TRIGGER_WRITE_CPLT_CB_ID Edge Trigger Write Complete callback ID
- * @arg @ref HAL_PLAY_MSPINIT_CB_ID MspInit callback ID
- * @arg @ref HAL_PLAY_MSPDEINIT_CB_ID MspDeInit callback ID
+ * @brief Register a user PLAY Callback.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param CallbackID ID of the callback to be registered.
+ * This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_SW_TRIGGER_WRITE_CPLT_CB_ID SWIN Write Complete callback ID
+ * @arg @ref HAL_PLAY_EDGE_TRIGGER_WRITE_CPLT_CB_ID Edge Trigger Write Complete callback ID
+ * @arg @ref HAL_PLAY_MSPINIT_CB_ID MspInit callback ID
+ * @arg @ref HAL_PLAY_MSPDEINIT_CB_ID MspDeInit callback ID
* @param pCallback Pointer to the callback function.
- * @note The HAL_PLAY_RegisterCallback() may be called before HAL_PLAY_Init() in HAL_PLAY_STATE_RESET
- * to register callbacks for HAL_PLAY_MSPINIT_CB_ID and HAL_PLAY_MSPDEINIT_CB_ID only.
- * @return HAL status.
+ * @note The HAL_PLAY_RegisterCallback() must be called before HAL_PLAY_Init() in @ref HAL_PLAY_STATE_RESET
+ * to register callbacks for @ref HAL_PLAY_MSPINIT_CB_ID and @ref HAL_PLAY_MSPDEINIT_CB_ID only.
+ * @retval HAL_OK Operation completed successfully.
+ * @retval HAL_ERROR Invalid parameter.
*/
HAL_StatusTypeDef HAL_PLAY_RegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_CallbackIDTypeDef CallbackID,
pPLAY_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
+ HAL_PLAY_StateTypeDef tmp_state;
- /* Check the PLAY handle allocation */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- /* Check the parameters */
- assert_param(IS_PLAY_ALL_INSTANCE(hplay->instance));
-
if (pCallback == NULL)
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- if (hplay->global_state == HAL_PLAY_STATE_READY)
+ /* Check the peripheral state */
+ tmp_state = hplay->State;
+ if ((tmp_state == HAL_PLAY_STATE_INIT) || (tmp_state == HAL_PLAY_STATE_READY))
{
switch (CallbackID)
{
@@ -3519,13 +3236,13 @@ HAL_StatusTypeDef HAL_PLAY_RegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL_P
break;
default :
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;
}
}
- else if (hplay->global_state == HAL_PLAY_STATE_RESET)
+ else if (tmp_state == HAL_PLAY_STATE_RESET)
{
switch (CallbackID)
{
@@ -3538,7 +3255,7 @@ HAL_StatusTypeDef HAL_PLAY_RegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL_P
break;
default :
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;
@@ -3546,49 +3263,49 @@ HAL_StatusTypeDef HAL_PLAY_RegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL_P
}
else
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}
- /* Return error status */
return status;
}
/**
- * @brief Register a User PLAY LUT Output Callback.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @param CallbackID ID of the callback to be registered.
- * This parameter can be one of the following values:
- * @arg @ref HAL_PLAY_LUT_OUTPUT_RISING_CB_ID LUT output rising callback ID
- * @arg @ref HAL_PLAY_LUT_OUTPUT_FALLING_CB_ID LUT output falling callback ID
+ * @brief Register a user PLAY LUT Output Callback.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param CallbackID ID of the callback to be registered.
+ * This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_LUT_OUTPUT_RISING_CB_ID LUT output rising callback ID
+ * @arg @ref HAL_PLAY_LUT_OUTPUT_FALLING_CB_ID LUT output falling callback ID
* @param pCallback Pointer to the callback function.
- * @note The User PLAY Callback is to be used instead of the weak predefined callback.
- * @return HAL status.
+ * @note The user PLAY Callback is to be used instead of the weak predefined callback.
+ * @retval HAL_OK Operation completed successfully.
+ * @retval HAL_ERROR Invalid parameter.
*/
HAL_StatusTypeDef HAL_PLAY_RegisterLUTOutputCallback(HAL_PLAY_HandleTypeDef *hplay,
HAL_PLAY_CallbackIDTypeDef CallbackID,
pPLAY_LUTOutputCallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
+ HAL_PLAY_StateTypeDef tmp_state;
- /* Check the PLAY handle allocation */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- /* Check the parameters */
- assert_param(IS_PLAY_ALL_INSTANCE(PLAY_GET_INSTANCE(hplay)));
-
if (pCallback == NULL)
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_PARAM;
return HAL_ERROR;
}
- if (hplay->global_state == HAL_PLAY_STATE_READY)
+ /* Check the peripheral state */
+ tmp_state = hplay->State;
+ if ((tmp_state == HAL_PLAY_STATE_INIT) || (tmp_state == HAL_PLAY_STATE_READY))
{
switch (CallbackID)
{
@@ -3602,7 +3319,7 @@ HAL_StatusTypeDef HAL_PLAY_RegisterLUTOutputCallback(HAL_PLAY_HandleTypeDef *hpl
default :
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;
@@ -3611,7 +3328,7 @@ HAL_StatusTypeDef HAL_PLAY_RegisterLUTOutputCallback(HAL_PLAY_HandleTypeDef *hpl
else
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}
@@ -3620,33 +3337,33 @@ HAL_StatusTypeDef HAL_PLAY_RegisterLUTOutputCallback(HAL_PLAY_HandleTypeDef *hpl
}
/**
- * @brief Unregister an User PLAY Callback.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @brief Unregister a user PLAY Callback. The PLAY callback will be redirected to the weak predefined callback.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @param CallbackID ID of the callback to be unregistered
- * This parameter can be one of the following values:
- * @arg @ref HAL_PLAY_SW_TRIGGER_WRITE_CPLT_CB_ID SW trigger write complete callback ID
- * @arg @ref HAL_PLAY_EDGE_TRIGGER_WRITE_CPLT_CB_ID Edge trigger write complete callback ID
- * @arg @ref HAL_PLAY_MSPINIT_CB_ID MspInit callback ID
- * @arg @ref HAL_PLAY_MSPDEINIT_CB_ID MspDeInit callback ID
- * @note The PLAY callback is redirected to the weak predefined callback.
- * @note The HAL_PLAY_UnRegisterCallback() can be called before HAL_PLAY_Init() in HAL_PLAY_STATE_RESET
- * to unregister callbacks for HAL_PLAY_MSPINIT_CB_ID and HAL_PLAY_MSPDEINIT_CB_ID only.
- * @return HAL status.
+ * This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_SW_TRIGGER_WRITE_CPLT_CB_ID SW trigger write complete callback ID
+ * @arg @ref HAL_PLAY_EDGE_TRIGGER_WRITE_CPLT_CB_ID Edge trigger write complete callback ID
+ * @arg @ref HAL_PLAY_MSPINIT_CB_ID MspInit callback ID
+ * @arg @ref HAL_PLAY_MSPDEINIT_CB_ID MspDeInit callback ID
+ * @note The HAL_PLAY_UnRegisterCallback() can be called before HAL_PLAY_Init() in @ref HAL_PLAY_STATE_RESET
+ * to unregister callbacks for @ref HAL_PLAY_MSPINIT_CB_ID and @ref HAL_PLAY_MSPDEINIT_CB_ID only.
+ * @retval HAL_OK Operation completed successfully.
+ * @retval HAL_ERROR Invalid parameter.
*/
HAL_StatusTypeDef HAL_PLAY_UnRegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL_PLAY_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
+ HAL_PLAY_StateTypeDef tmp_state;
- /* Check the PLAY handle allocation */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- /* Check the parameters */
- assert_param(IS_PLAY_ALL_INSTANCE(PLAY_GET_INSTANCE(hplay)));
-
- if (hplay->global_state == HAL_PLAY_STATE_READY)
+ /* Check the peripheral state */
+ tmp_state = hplay->State;
+ if ((tmp_state == HAL_PLAY_STATE_INIT) || (tmp_state == HAL_PLAY_STATE_READY))
{
switch (CallbackID)
{
@@ -3668,12 +3385,12 @@ HAL_StatusTypeDef HAL_PLAY_UnRegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL
default:
/* Update the error code */
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;
}
}
- else if (hplay->global_state == HAL_PLAY_STATE_RESET)
+ else if (tmp_state == HAL_PLAY_STATE_RESET)
{
switch (CallbackID)
{
@@ -3687,14 +3404,14 @@ HAL_StatusTypeDef HAL_PLAY_UnRegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL
default:
/* Update the error code */
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;
}
}
else
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}
@@ -3702,30 +3419,31 @@ HAL_StatusTypeDef HAL_PLAY_UnRegisterCallback(HAL_PLAY_HandleTypeDef *hplay, HAL
}
/**
- * @brief Unregister a User PLAY LUT Output Callback.
- * @note The PLAY callback is redirected to the weak predefined callback.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @param CallbackID ID of the callback to be unregistered
- * This parameter can be one of the following values:
- * @arg @ref HAL_PLAY_LUT_OUTPUT_RISING_CB_ID LUT output rising callback ID
- * @arg @ref HAL_PLAY_LUT_OUTPUT_FALLING_CB_ID LUT output falling callback ID
- * @return HAL status.
+ * @brief Unregister a user PLAY LUT Output Callback. The PLAY callback will be redirected to the weak
+ * predefined callback.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param CallbackID ID of the callback to be unregistered
+ * This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_LUT_OUTPUT_RISING_CB_ID LUT output rising callback ID
+ * @arg @ref HAL_PLAY_LUT_OUTPUT_FALLING_CB_ID LUT output falling callback ID
+ * @retval HAL_OK Operation completed successfully.
+ * @retval HAL_ERROR Invalid parameter.
*/
HAL_StatusTypeDef HAL_PLAY_UnRegisterLUTOutputCallback(HAL_PLAY_HandleTypeDef *hplay,
HAL_PLAY_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
+ HAL_PLAY_StateTypeDef tmp_state;
- /* Check the PLAY handle allocation */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- /* Check the parameters */
- assert_param(IS_PLAY_ALL_INSTANCE(PLAY_GET_INSTANCE(hplay)));
-
- if (hplay->global_state == HAL_PLAY_STATE_READY)
+ /* Check the peripheral state */
+ tmp_state = hplay->State;
+ if ((tmp_state == HAL_PLAY_STATE_INIT) || (tmp_state == HAL_PLAY_STATE_READY))
{
switch (CallbackID)
{
@@ -3738,14 +3456,14 @@ HAL_StatusTypeDef HAL_PLAY_UnRegisterLUTOutputCallback(HAL_PLAY_HandleTypeDef *h
break;
default :
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;
}
}
else
{
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_CALLBACK;
+ hplay->ErrorCode |= HAL_PLAY_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}
@@ -3759,44 +3477,40 @@ HAL_StatusTypeDef HAL_PLAY_UnRegisterLUTOutputCallback(HAL_PLAY_HandleTypeDef *h
/** @addtogroup PLAY_Exported_Functions_Group7
* @{
-A set of functions allowing to retrieve peripheral state,last process errors and kernel clock frequency.
-- HAL_PLAY_GetState() : Return the PLAY handle state.
-- HAL_PLAY_GetError() : Returns errors limited to the last process.
+A set of functions allowing to retrieve peripheral state and last process errors.
+- HAL_PLAY_GetState() Return the PLAY handle state.
+- HAL_PLAY_GetError() Returns errors limited to the last process.
*/
/**
* @brief Return the HAL PLAY handle state.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @note This function will return @ref HAL_PLAY_STATE_RESET in case of wrong parameter.
* @return Current PLAY state.
- * @note This function will return HAL_PLAY_STATE_RESET in case of wrong parameter.
*/
HAL_PLAY_StateTypeDef HAL_PLAY_GetState(const HAL_PLAY_HandleTypeDef *hplay)
{
- /* Check parameters */
if (hplay == NULL)
{
- /* Return HAL_PLAY_STATE_RESET in case of wrong parameter */
return HAL_PLAY_STATE_RESET;
}
- return hplay->global_state;
+ return hplay->State;
}
/**
* @brief Get the HAL PLAY last error codes.
* @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
* @note This function will return 0 in case of wrong parameter.
- * @return PLAY Error Code.
+ * @return PLAY Error Code. This value is a combination of @ref PLAY_Error_Codes values.
*/
uint32_t HAL_PLAY_GetError(const HAL_PLAY_HandleTypeDef *hplay)
{
- /* Check parameters */
if (hplay == NULL)
{
- /* Return 0 in case of wrong parameter */
return 0U;
}
- return hplay->last_error_codes;
+ return hplay->ErrorCode;
}
/**
@@ -3805,96 +3519,153 @@ uint32_t HAL_PLAY_GetError(const HAL_PLAY_HandleTypeDef *hplay)
/** @addtogroup PLAY_Exported_Functions_Group8
* @{
+A set of functions allowing to manage security and privileged access levels attributes:
+ - HAL_PLAY_SetSecAttr() Set the security access level attribute.
+ - HAL_PLAY_GetSecAttr() Get the security access level attribute.
+ - HAL_PLAY_SetPrivAttr() Set the privileged access level attribute.
+ - HAL_PLAY_GetPrivAttr() Get the privileged access level attribute.
*/
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
/**
- * @brief Configure the Secure & Privilege attributes.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @param p_config Pointer to a @ref HAL_PLAY_AccessControlConfTypeDef structure
- * @return HAL status.
+ * @brief Set the security access level attribute for item(s).
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param item This parameter can be one or a combination of the following values:
+ * @arg @ref HAL_PLAY_SEC_ITEM_CONFIG
+ * @arg @ref HAL_PLAY_SEC_ITEM_ALL
+ * @param sec_attr This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_SEC
+ * @arg @ref HAL_PLAY_NSEC
+ * @retval HAL_OK Security attribute has been set successfully.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
*/
-HAL_StatusTypeDef HAL_PLAY_ConfigAttributes(HAL_PLAY_HandleTypeDef *hplay,
- const HAL_PLAY_AccessControlConfTypeDef *p_config)
+HAL_StatusTypeDef HAL_PLAY_SetSecAttr(const HAL_PLAY_HandleTypeDef *hplay, uint32_t item,
+ HAL_PLAY_SecAttrTypeDef sec_attr)
{
PLAY_TypeDef *p_playx;
+ HAL_PLAY_StateTypeDef tmp_state;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
return HAL_ERROR;
}
- if (p_config == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
-
- return HAL_ERROR;
- }
-
p_playx = PLAY_GET_INSTANCE(hplay);
assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
- assert_param(IS_PLAY_TZ_ACCESS_CONTROL(p_config->SecureAccess));
- assert_param(IS_PLAY_TZ_ACCESS_CONTROL(p_config->PrivilegeAccess));
+ assert_param(IS_PLAY_SEC_ITEM(item));
+ assert_param(IS_PLAY_ITEM_SEC_ATTR(sec_attr));
- if (hplay->global_state != HAL_PLAY_STATE_RESET)
+ /* Check the peripheral state */
+ tmp_state = hplay->State;
+ if ((tmp_state != HAL_PLAY_STATE_INIT) && (tmp_state != HAL_PLAY_STATE_READY))
{
return HAL_ERROR;
}
- /* Set Secure access */
- uint32_t reg_value = (uint32_t)(p_config->SecureAccess) << PLAY_SECCFGR_SEC_Pos;
- ATOMIC_MODIFY_REG(p_playx->SECCFGR, PLAY_SECCFGR_SEC, reg_value);
-
- /* Set Privilege access */
- reg_value = (uint32_t)(p_config->PrivilegeAccess) << PLAY_PRIVCFGR_PRIV_Pos;
- ATOMIC_MODIFY_REG(p_playx->PRIVCFGR, PLAY_PRIVCFGR_PRIV, reg_value);
+ LL_PLAY_SetSecAttr(p_playx, item, (uint32_t)sec_attr);
return HAL_OK;
}
+#endif /* __ARM_FEATURE_CMSE */
/**
- * @brief Get the Secure & Privilege attributes configuration.
- * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
- * @param p_config Pointer to a @ref HAL_PLAY_AccessControlConfTypeDef structure.
- * @return HAL status.
+ * @brief Get the security access level attribute of an item.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param item This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_SEC_ITEM_CONFIG
+ * @arg @ref HAL_PLAY_SEC_ITEM_ALL
+ * @note This function returns @ref HAL_PLAY_NSEC if the handle is NULL.
+ * @return The security access level attribute.
*/
-HAL_StatusTypeDef HAL_PLAY_GetConfigAttributes(HAL_PLAY_HandleTypeDef *hplay,
- HAL_PLAY_AccessControlConfTypeDef *p_config)
+HAL_PLAY_SecAttrTypeDef HAL_PLAY_GetSecAttr(const HAL_PLAY_HandleTypeDef *hplay, uint32_t item)
{
const PLAY_TypeDef *p_playx;
- uint32_t reg_value;
- uint32_t sec_value;
- uint32_t priv_value;
- /* Check parameters */
+ /* Check the parameters */
if (hplay == NULL)
{
- return HAL_ERROR;
+ return HAL_PLAY_NSEC;
}
+
p_playx = PLAY_GET_INSTANCE(hplay);
- if (p_config == NULL)
- {
- hplay->last_error_codes |= HAL_PLAY_ERROR_INVALID_PARAM;
+ assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
+ assert_param(IS_PLAY_SEC_ITEM(item));
+ return ((HAL_PLAY_SecAttrTypeDef)LL_PLAY_GetSecAttr(p_playx, item));
+}
+
+/**
+ * @brief Set the privileged access level attribute for item(s).
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param item This parameter can be one or a combination of the following values:
+ * @arg @ref HAL_PLAY_PRIV_ITEM_CONFIG
+ * @arg @ref HAL_PLAY_PRIV_ITEM_ALL
+ * @param priv_attr This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_PRIV
+ * @arg @ref HAL_PLAY_NPRIV
+ * @retval HAL_OK Privileged attribute has been set successfully.
+ * @retval HAL_ERROR Invalid parameter or wrong state.
+ */
+HAL_StatusTypeDef HAL_PLAY_SetPrivAttr(const HAL_PLAY_HandleTypeDef *hplay, uint32_t item,
+ HAL_PLAY_PrivAttrTypeDef priv_attr)
+{
+ PLAY_TypeDef *p_playx;
+ HAL_PLAY_StateTypeDef tmp_state;
+
+ /* Check the parameters */
+ if (hplay == NULL)
+ {
return HAL_ERROR;
}
+ p_playx = PLAY_GET_INSTANCE(hplay);
+
assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
+ assert_param(IS_PLAY_PRIV_ITEM(item));
+ assert_param(IS_PLAY_ITEM_PRIV_ATTR(priv_attr));
- /* Read Secure access */
- reg_value = READ_REG(p_playx->SECCFGR);
- sec_value = (reg_value & PLAY_SECCFGR_SEC_Msk) >> PLAY_SECCFGR_SEC_Pos;
- p_config->SecureAccess = (HAL_PLAY_TrustZone_AccessControlTypeDef)(sec_value);
+ /* Check the peripheral state */
+ tmp_state = hplay->State;
+ if ((tmp_state != HAL_PLAY_STATE_INIT) && (tmp_state != HAL_PLAY_STATE_READY))
+ {
+ return HAL_ERROR;
+ }
- /* Read Privilege access */
- reg_value = READ_REG(p_playx->PRIVCFGR);
- priv_value = (reg_value & PLAY_PRIVCFGR_PRIV_Msk) >> PLAY_PRIVCFGR_PRIV_Pos;
- p_config->PrivilegeAccess = (HAL_PLAY_TrustZone_AccessControlTypeDef)(priv_value);
+ LL_PLAY_SetPrivAttr(p_playx, item, (uint32_t)priv_attr);
return HAL_OK;
}
+/**
+ * @brief Get the privileged access level attribute of an item.
+ * @param hplay Pointer to a @ref HAL_PLAY_HandleTypeDef.
+ * @param item This parameter can be one of the following values:
+ * @arg @ref HAL_PLAY_PRIV_ITEM_CONFIG
+ * @arg @ref HAL_PLAY_PRIV_ITEM_ALL
+ * @note This function returns @ref HAL_PLAY_NPRIV if the handle is NULL.
+ * @return The privileged access level attribute.
+ */
+HAL_PLAY_PrivAttrTypeDef HAL_PLAY_GetPrivAttr(const HAL_PLAY_HandleTypeDef *hplay, uint32_t item)
+{
+ const PLAY_TypeDef *p_playx;
+
+ /* Check the parameters */
+ if (hplay == NULL)
+ {
+ return HAL_PLAY_NPRIV;
+ }
+
+ p_playx = PLAY_GET_INSTANCE(hplay);
+
+ assert_param(IS_PLAY_ALL_INSTANCE(p_playx));
+ assert_param(IS_PLAY_PRIV_ITEM(item));
+
+ return ((HAL_PLAY_PrivAttrTypeDef)LL_PLAY_GetPrivAttr(p_playx, item));
+}
+
/**
* @}
*/
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng.c
index cb6ca88a7d..8339ef5bbf 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng.c
@@ -115,7 +115,7 @@
/** @defgroup RNG_Private_Constants RNG Private Constants
* @{
*/
-#define RNG_TIMEOUT_VALUE 4U
+#define RNG_TIMEOUT_VALUE 6U
/**
* @}
*/
@@ -206,7 +206,11 @@ HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
#endif /* RNG_CR_NIST_VALUE */
#if defined(RNG_HTCR_NIST_VALUE)
/* Recommended value for NIST compliance, refer to application note AN4230 */
+#if defined(RNG_HTCR3_HTCFG)
+ WRITE_REG(hrng->Instance->HTCR[0], RNG_HTCR_NIST_VALUE);
+#else
WRITE_REG(hrng->Instance->HTCR, RNG_HTCR_NIST_VALUE);
+#endif /* RNG_HTCR0_HTCFG || RNG_HTCR1_HTCFG || RNG_HTCR2_HTCFG || RNG_HTCR3_HTCFG */
#endif /* RNG_HTCR_NIST_VALUE */
#if defined(RNG_NSCR_NIST_VALUE)
WRITE_REG(hrng->Instance->NSCR, RNG_NSCR_NIST_VALUE);
@@ -645,11 +649,12 @@ HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t
/* Change RNG peripheral state */
hrng->State = HAL_RNG_STATE_BUSY;
/* Check if there is a seed error */
- if (__HAL_RNG_GET_IT(hrng, RNG_IT_SEI) != RESET)
+ if (__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_SECS) != RESET)
{
/* Update the error code */
hrng->ErrorCode = HAL_RNG_ERROR_SEED;
/* Reset from seed error */
+#if !((defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX)))
status = RNG_RecoverSeedError(hrng);
if (status == HAL_ERROR)
{
@@ -657,6 +662,7 @@ HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t
hrng->ErrorCode = HAL_RNG_ERROR_RECOVERSEED;
return status;
}
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX) */
}
/* Get tick */
@@ -665,6 +671,16 @@ HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t
/* Check if data register contains valid random data */
while (__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET)
{
+ if (__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_SECS) != RESET)
+ {
+#if !((defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX)))
+ /* Update the error code */
+ hrng->ErrorCode = HAL_RNG_ERROR_RECOVERSEED;
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX) */
+ hrng->State = HAL_RNG_STATE_READY;
+ return HAL_ERROR;
+ }
+
if ((HAL_GetTick() - tickstart) > RNG_TIMEOUT_VALUE)
{
/* New check to avoid false timeout detection in case of preemption */
@@ -811,7 +827,11 @@ void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng)
#endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
/* Clear the clock error flag */
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ __HAL_RNG_CLEAR_IT(hrng, RNG_IT_CEI);
+#else
__HAL_RNG_CLEAR_IT(hrng, RNG_IT_CEI | RNG_IT_SEI);
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX) */
return;
}
@@ -1002,7 +1022,7 @@ HAL_StatusTypeDef RNG_RecoverSeedError(RNG_HandleTypeDef *hrng)
if (count == 0U)
{
hrng->State = HAL_RNG_STATE_READY;
- hrng->ErrorCode |= HAL_RNG_ERROR_TIMEOUT;
+
/* Process Unlocked */
__HAL_UNLOCK(hrng);
#if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
@@ -1017,6 +1037,10 @@ HAL_StatusTypeDef RNG_RecoverSeedError(RNG_HandleTypeDef *hrng)
} while (HAL_IS_BIT_SET(hrng->Instance->SR, RNG_FLAG_SECS));
}
/* Update the error code */
+ if (__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_SECS) != RESET)
+ {
+ return HAL_ERROR;
+ }
hrng->ErrorCode &= ~ HAL_RNG_ERROR_SEED;
return HAL_OK;
}
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng_ex.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng_ex.c
index 693747bdeb..41e369dcc6 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng_ex.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rng_ex.c
@@ -51,6 +51,9 @@
/* Private macros ------------------------------------------------------------*/
/* Private functions prototypes ----------------------------------------------*/
/* Private functions --------------------------------------------------------*/
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+HAL_StatusTypeDef RNG_ResilientRecoverSeedError(RNG_HandleTypeDef *hrng);
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
/* Exported functions --------------------------------------------------------*/
/** @defgroup RNGEx_Exported_Functions RNGEx Exported Functions
@@ -127,7 +130,11 @@ HAL_StatusTypeDef HAL_RNGEx_SetConfig(RNG_HandleTypeDef *hrng, const RNG_ConfigT
(uint32_t)(RNG_CR_CONDRST | cr_value));
/* RNG health test control in accordance with NIST */
+#if defined(RNG_HTCR3_HTCFG)
+ WRITE_REG(hrng->Instance->HTCR[0], pConf->HealthTest);
+#else
WRITE_REG(hrng->Instance->HTCR, pConf->HealthTest);
+#endif /* RNG_HTCR0_HTCFG || RNG_HTCR1_HTCFG || RNG_HTCR2_HTCFG || RNG_HTCR3_HTCFG */
/* Writing bit CONDRST=0*/
CLEAR_BIT(hrng->Instance->CR, RNG_CR_CONDRST);
@@ -155,6 +162,14 @@ HAL_StatusTypeDef HAL_RNGEx_SetConfig(RNG_HandleTypeDef *hrng, const RNG_ConfigT
/* Initialize the RNG state */
hrng->State = HAL_RNG_STATE_READY;
+ /*Check if seed error current status (SECS)is set */
+ if (__HAL_RNG_GET_FLAG(hrng, RNG_SR_SECS) != RESET)
+ {
+ /* Update the error code */
+ hrng->ErrorCode = HAL_RNG_ERROR_SEED;
+ return HAL_ERROR;
+ }
+
/* function status */
status = HAL_OK;
}
@@ -202,7 +217,11 @@ HAL_StatusTypeDef HAL_RNGEx_GetConfig(RNG_HandleTypeDef *hrng, RNG_ConfigTypeDef
pConf->ClockDivider = (hrng->Instance->CR & RNG_CR_CLKDIV);
pConf->NistCompliance = (hrng->Instance->CR & RNG_CR_NISTC);
pConf->AutoReset = (hrng->Instance->CR & RNG_CR_ARDIS);
+#if defined(RNG_HTCR3_HTCFG)
+ pConf->HealthTest = (hrng->Instance->HTCR[0]);
+#else
pConf->HealthTest = (hrng->Instance->HTCR);
+#endif /* RNG_HTCR0_HTCFG || RNG_HTCR1_HTCFG || RNG_HTCR2_HTCFG || RNG_HTCR3_HTCFG */
/* Initialize the RNG state */
hrng->State = HAL_RNG_STATE_READY;
@@ -286,11 +305,13 @@ HAL_StatusTypeDef HAL_RNGEx_LockConfig(RNG_HandleTypeDef *hrng)
/**
* @brief RNG sequence to recover from a seed error
* @param hrng: pointer to a RNG_HandleTypeDef structure.
+ * @warning Recover from seed error will adapt the parameters config1,2,3 to overcome seed error.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_RNGEx_RecoverSeedError(RNG_HandleTypeDef *hrng)
{
HAL_StatusTypeDef status;
+ HAL_RNG_StateTypeDef state;
/* Check the RNG handle allocation */
if (hrng == NULL)
@@ -298,14 +319,20 @@ HAL_StatusTypeDef HAL_RNGEx_RecoverSeedError(RNG_HandleTypeDef *hrng)
return HAL_ERROR;
}
+ state = hrng->State;
+
/* Check RNG peripheral state */
- if (hrng->State == HAL_RNG_STATE_READY)
+ if ((state == HAL_RNG_STATE_READY) || (state == HAL_RNG_STATE_ERROR))
{
/* Change RNG peripheral state */
hrng->State = HAL_RNG_STATE_BUSY;
/* sequence to fully recover from a seed error */
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+ status = RNG_ResilientRecoverSeedError(hrng);
+#else
status = RNG_RecoverSeedError(hrng);
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX) */
if (status == HAL_ERROR)
{
/* Update the error code */
@@ -322,6 +349,77 @@ HAL_StatusTypeDef HAL_RNGEx_RecoverSeedError(RNG_HandleTypeDef *hrng)
return status;
}
+#if defined(RNG_HTCR3_HTCFG)
+/**
+ * @brief Configure the RNG additional health tests.
+ * @param hrng hrng pointer to a RNG_HandleTypeDef structure that contains
+ * the configuration information for RNG.
+ * @param htcr_idx is a value of the htcr.
+ * @param htcr_value Health test value.
+ * @retval HAL_OK configuration succeeded.
+ * @retval HAL_ERROR configuration fail.
+ * @retval HAL_INVALID_PARAM invalid parameter.
+ */
+HAL_StatusTypeDef HAL_RNGEx_SetHealthFactorConfig(RNG_HandleTypeDef *hrng, uint32_t htcr_idx, uint32_t htcr_value)
+{
+ HAL_StatusTypeDef status = HAL_ERROR;
+ uint32_t tickstart;
+
+ assert_param(IS_RNG_HTCR_INDEX(htcr_idx));
+ assert_param(IS_RNG_HTCR_VALUE(htcr_value));
+
+ /* 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;
+
+ if (LL_RNG_IsConfigLocked(hrng->Instance) == 0U)
+ {
+ LL_RNG_EnableCondReset(hrng->Instance);
+ LL_RNG_SetAdditionalHealthTest(hrng->Instance, htcr_idx, htcr_value);
+ LL_RNG_DisableCondReset(hrng->Instance);
+
+ /* 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;
+ }
+ }
+ }
+ }
+
+ /* 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 status;
+}
+#endif /* defined(RNG_HTCR0_HTCFG || RNG_HTCR1_HTCFG || RNG_HTCR2_HTCFG) */
/**
* @}
*/
@@ -330,6 +428,202 @@ HAL_StatusTypeDef HAL_RNGEx_RecoverSeedError(RNG_HandleTypeDef *hrng)
* @}
*/
+#if (defined(RNG_HTSR0_RPERRX) || defined(RNG_HTSR1_ADERRX))
+/* Private functions -------------------------------------------------------------------------------------------------*/
+/** @defgroup RNGEx_Private_Functions RNGEx Private Functions
+ * @brief RNGEx Private Functions
+ * @{
+ */
+
+/**
+ * @brief RNG sequence to resilient recover from a seed error
+ * @param hrng pointer to a RNG_HandleTypeDef structure.
+ * @retval HAL status
+ */
+HAL_StatusTypeDef RNG_ResilientRecoverSeedError(RNG_HandleTypeDef *hrng)
+{
+ uint32_t timeout;
+ uint32_t htsr_temp = 0U;
+ uint32_t htsr_previous_temp = 0U;
+ uint32_t htsr_count = 0U;
+ uint32_t nsmr_temp = 0U;
+ uint32_t tickstart1 = 0U;
+ uint32_t tickstart2 = 0U;
+ uint32_t tickstart3 = 0U;
+ uint32_t oscillators_count = 0U;
+ uint32_t config_b_fewer_than_6_osc_count = 0U;
+ uint8_t count = 0U;
+
+ /* timeout here is an emperic value */
+ timeout = (1UL + ((1UL << (READ_BIT(hrng->Instance->CR, RNG_CR_CLKDIV) >> 16UL)) * RNG_TIMEOUT_VALUE / 8UL));
+ LL_RNG_Enable(hrng->Instance);
+
+ tickstart1 = HAL_GetTick();
+
+ /* Check if seed error current status indicates no error and auto-reset succeeded */
+ if (LL_RNG_IsActiveFlag_SECS(hrng->Instance) == 0U)
+ {
+ /* Clear SEIS flag when automatic reset is activated */
+ LL_RNG_ClearFlag_SEIS(hrng->Instance);
+ }
+
+ else /* Sequence to fully recover from a seed error*/
+ {
+ if (LL_RNG_IsConfigLocked(hrng->Instance) == 0U)
+ {
+ do
+ {
+ if (LL_RNG_IsActiveFlag_SECS(hrng->Instance) == 0U)
+ {
+ break;
+ }
+ /* Read oscillator status registers combined */
+ htsr_temp = LL_RNG_GetHealthTestStatus(hrng->Instance, 0U);
+ htsr_temp |= LL_RNG_GetHealthTestStatus(hrng->Instance, 1U);
+ if (htsr_temp > 0U)
+ {
+ /* If any oscillator status bits overlap with previous status, increment counter */
+ if ((htsr_temp & htsr_previous_temp) != 0U)
+ {
+ htsr_count++;
+ }
+
+ if (htsr_count > 3U)
+ {
+ /* if the same repetitive or adaptative error is detected 3 times */
+ nsmr_temp = LL_RNG_GetNoiseSourceMask(hrng->Instance);
+
+ /* deactivate the same osc in each triple oscillator (Mask oscillators with the seed error by
+ clearing bits shifted right by 1) */
+ nsmr_temp = nsmr_temp & ~(htsr_temp >> 1U);
+
+ /* Count the number of active oscillators in nsmr */
+ oscillators_count = 0U;
+ for (count = 0U; count < 9U; count++)
+ {
+ if (((nsmr_temp >> count) & 0x1U) != 0U)
+ {
+ /* increment count1 for each 1 in nsmr */
+ oscillators_count++;
+ }
+ }
+
+ if (oscillators_count < 6U)
+ {
+ /* If fewer than 6 oscillators remain active, unmask all oscillators --> Reset masking */
+ nsmr_temp = LL_RNG_GetOscNoiseSrc(hrng->Instance, LL_RNG_NOISE_SRC_1 | LL_RNG_NOISE_SRC_2 \
+ | LL_RNG_NOISE_SRC_3);
+ htsr_previous_temp = 0;
+ htsr_count = 0U;
+ if ((hrng->Instance->CR & RNG_CR_CLKDIV_Msk) < ((uint32_t)RNG_CAND_NIST_CR_VALUE & RNG_CR_CLKDIV_Msk))
+ {
+ config_b_fewer_than_6_osc_count++;
+ }
+ }
+
+ if (config_b_fewer_than_6_osc_count > 2U)
+ {
+ /* Reset RNG condition */
+ WRITE_REG(hrng->Instance->CR, (RNG_CR_CONDRST_Msk | (uint32_t)RNG_CAND_NIST_CR_VALUE));
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(hrng->Instance, nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(hrng->Instance);
+ }
+
+ else
+ {
+ /* Reset RNG condition */
+ WRITE_REG(hrng->Instance->CR, (hrng->Instance->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* Update mask register with new oscillator mask */
+ LL_RNG_SetNoiseSourceMask(hrng->Instance, nsmr_temp);
+
+ /* Clear condition reset bit to resume operation */
+ LL_RNG_DisableCondReset(hrng->Instance);
+ }
+ }
+
+ else
+ {
+ /* Briefly toggle conditional reset to recover RNG */
+ WRITE_REG(hrng->Instance->CR, (hrng->Instance->CR & ~RNG_CR_RNGEN_Msk) | RNG_CR_CONDRST_Msk);
+
+ /* unmask all oscillators to find another working condition */
+ LL_RNG_SetNoiseSourceMask(hrng->Instance, LL_RNG_GetOscNoiseSrc(hrng->Instance, LL_RNG_OSC_1\
+ | LL_RNG_OSC_2 | LL_RNG_OSC_3));
+ LL_RNG_DisableCondReset(hrng->Instance);
+ }
+
+ /* Wait until RNG is not busy */
+ tickstart2 = HAL_GetTick();
+ do
+ {
+ if ((HAL_GetTick() - tickstart2) > RNG_TIMEOUT_VALUE)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ LL_RNG_Disable(hrng->Instance);
+ hrng->State = HAL_RNG_STATE_ERROR;
+ __HAL_UNLOCK(hrng);
+ return HAL_ERROR;
+ }
+ } while (HAL_IS_BIT_SET(hrng->Instance->SR, RNG_SR_BUSY));
+
+ /* No timeout --> Enable RNG */
+ LL_RNG_Enable(hrng->Instance);
+ tickstart3 = HAL_GetTick();
+ do
+ {
+ if (LL_RNG_IsActiveFlag_DRDY(hrng->Instance) != 0UL)
+ {
+ break;
+ }
+ if ((HAL_GetTick() - tickstart3) > timeout)
+ {
+ /* New check to avoid false timeout detection in case of preemption */
+ if (LL_RNG_IsActiveFlag_DRDY(hrng->Instance) == 0UL)
+ {
+ if (LL_RNG_IsActiveFlag_SECS(hrng->Instance) == 0UL)
+ {
+ LL_RNG_Disable(hrng->Instance);
+ hrng->State = HAL_RNG_STATE_ERROR;
+ __HAL_UNLOCK(hrng);
+ return HAL_ERROR;
+ }
+ }
+ }
+ } while (LL_RNG_IsActiveFlag_SECS(hrng->Instance) == 0UL);
+
+ /* Accumulate seed error status bits */
+ htsr_previous_temp = htsr_previous_temp | htsr_temp;
+ }
+ } while ((HAL_GetTick() - tickstart1) <= timeout);
+ }
+ }
+
+ /*Check if seed error current status (SECS)is set */
+ if (LL_RNG_IsActiveFlag_SECS(hrng->Instance) != 0U)
+ {
+ hrng->ErrorCode &= HAL_RNG_ERROR_SEED;
+ __HAL_UNLOCK(hrng);
+ return HAL_ERROR;
+ }
+
+ /* Update the error code */
+ hrng->ErrorCode &= ~ HAL_RNG_ERROR_SEED;
+
+ /* Return the function status */
+ hrng->State = HAL_RNG_STATE_READY;
+ __HAL_UNLOCK(hrng);
+ return HAL_OK;
+}
+
+/**
+ * @}
+ */
+#endif /* RNG_HTSR0_RPERRX || RNG_HTSR1_ADERRX */
#endif /* RNG_CR_CONDRST */
#endif /* HAL_RNG_MODULE_ENABLED */
/**
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sd.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sd.c
index 37e5767a9b..31d6db9a1c 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sd.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sd.c
@@ -491,7 +491,14 @@ HAL_StatusTypeDef HAL_SD_InitCard(SD_HandleTypeDef *hsd)
hsd->ErrorCode = SDMMC_ERROR_INVALID_PARAMETER;
return HAL_ERROR;
}
- Init.ClockDiv = sdmmc_clk / (2U * SD_INIT_FREQ);
+ if (sdmmc_clk <= SD_INIT_FREQ)
+ {
+ Init.ClockDiv = 0U;
+ }
+ else
+ {
+ Init.ClockDiv = (sdmmc_clk / (2U * SD_INIT_FREQ)) + 1U;
+ }
#if (USE_SD_TRANSCEIVER != 0U)
Init.TranceiverPresent = hsd->Init.TranceiverPresent;
@@ -3128,7 +3135,7 @@ static uint32_t SD_PowerON(SD_HandleTypeDef *hsd)
/* CMD8: SEND_IF_COND: Command available only on V2.0 cards */
errorstate = SDMMC_CmdOperCond(hsd->Instance);
- if (errorstate == SDMMC_ERROR_TIMEOUT) /* No response to CMD8 */
+ if (errorstate == SDMMC_ERROR_CMD_RSP_TIMEOUT) /* No response to CMD8 */
{
hsd->SdCard.CardVersion = CARD_V1_X;
/* CMD0: GO_IDLE_STATE */
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdio.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdio.c
index e9a18d3294..2f80c3ec33 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdio.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdio.c
@@ -228,21 +228,21 @@
/** @addtogroup SDIO_Private_Defines
* @{
*/
-#define SDIO_INIT_FREQ 400000UL /*!< Initialization phase : 400 kHz max */
-#define SDIO_TIMEOUT 1000UL /*!< SDIO timeout millisecond */
+#define SDIO_INIT_FREQ 400000U /*!< Initialization phase : 400 kHz max */
+#define SDIO_TIMEOUT 1000U /*!< SDIO timeout millisecond */
-#define SDIO_FUNCTION_0 0x00UL /*!< SDIO_Functions 0 */
-#define SDIO_FUNCTION_1 0x01UL /*!< SDIO_Functions 1 */
+#define SDIO_FUNCTION_0 0x00UL /*!< SDIO_Functions 0 */
+#define SDIO_FUNCTION_1 0x01UL /*!< SDIO_Functions 1 */
-#define SDIO_READ 0x0UL /*!< Read flag for cmd52 and cmd53 */
-#define SDIO_WRITE 0x1UL /*!< Write flag for cmd52 and cmd53 */
+#define SDIO_READ 0x0UL /*!< Read flag for cmd52 and cmd53 */
+#define SDIO_WRITE 0x1UL /*!< Write flag for cmd52 and cmd53 */
-#define SDIO_BUS_SPEED_SDR12 0x00UL /*!< SDIO bus speed mode SDR12 */
-#define SDIO_BUS_SPEED_SDR25 0x02UL /*!< SDIO bus speed mode SDR25 */
-#define SDIO_BUS_SPEED_SDR50 0x04UL /*!< SDIO bus speed mode SDR50 */
-#define SDIO_BUS_SPEED_DDR50 0x08UL /*!< SDIO bus speed mode DDR50 */
+#define SDIO_BUS_SPEED_SDR12 0x00U /*!< SDIO bus speed mode SDR12 */
+#define SDIO_BUS_SPEED_SDR25 0x02U /*!< SDIO bus speed mode SDR25 */
+#define SDIO_BUS_SPEED_SDR50 0x04U /*!< SDIO bus speed mode SDR50 */
+#define SDIO_BUS_SPEED_DDR50 0x08U /*!< SDIO bus speed mode DDR50 */
-#define SDIO_CCCR_REG_NUMBER 0x16UL /*!< SDIO card cccr register number */
+#define SDIO_CCCR_REG_NUMBER 0x16U /*!< SDIO card cccr register number */
#define SDIO_OCR_VDD_32_33 (1UL << 20U)
#define SDIO_OCR_SDIO_S18R (1UL << 24U)
@@ -1036,7 +1036,14 @@ HAL_StatusTypeDef HAL_SDIO_ReadExtended(SDIO_HandleTypeDef *hsdio, const HAL_SDI
cmd |= Argument->Block_Mode << 27U;
cmd |= Argument->OpCode << 26U;
cmd |= (Argument->Reg_Addr & 0x1FFFFU) << 9U;
- cmd |= (Size_byte & 0x1FFU);
+ if (Argument->Block_Mode == HAL_SDIO_MODE_BYTE)
+ {
+ cmd |= (((uint32_t)Size_byte) & 0x1FFU);
+ }
+ else /* HAL_SDIO_BLOCK_MODE_BLOCK */
+ {
+ cmd |= nbr_of_block & 0x1FFU;
+ }
errorstate = SDMMC_SDIO_CmdReadWriteExtended(hsdio->Instance, cmd);
if (errorstate != HAL_SDIO_ERROR_NONE)
{
@@ -1181,7 +1188,7 @@ HAL_StatusTypeDef HAL_SDIO_WriteExtended(SDIO_HandleTypeDef *hsdio, const HAL_SD
uint8_t byteCount;
uint32_t data;
uint32_t dataremaining;
- uint8_t *u32tempbuff = pData;
+ uint32_t *u32tempbuff = (uint32_t *)(uint32_t)pData;
uint32_t nbr_of_block;
/* Check the parameters */
@@ -1241,7 +1248,14 @@ HAL_StatusTypeDef HAL_SDIO_WriteExtended(SDIO_HandleTypeDef *hsdio, const HAL_SD
cmd |= Argument->Block_Mode << 27U;
cmd |= Argument->OpCode << 26U;
cmd |= (Argument->Reg_Addr & 0x1FFFFU) << 9U;
- cmd |= (Size_byte & 0x1FFU);
+ if (Argument->Block_Mode == HAL_SDIO_MODE_BYTE)
+ {
+ cmd |= (((uint32_t)Size_byte) & 0x1FFU);
+ }
+ else /* HAL_SDIO_BLOCK_MODE_BLOCK */
+ {
+ cmd |= nbr_of_block & 0x1FFU;
+ }
errorstate = SDMMC_SDIO_CmdReadWriteExtended(hsdio->Instance, cmd);
if (errorstate != HAL_SDIO_ERROR_NONE)
{
@@ -1693,7 +1707,6 @@ void HAL_SDIO_IRQHandler(SDIO_HandleTypeDef *hsdio)
}
hsdio->Context = SDIO_CONTEXT_NONE;
- hsdio->State = HAL_SDIO_STATE_READY;
}
if (hsdio->remaining_data != 0U)
@@ -2517,7 +2530,7 @@ static HAL_StatusTypeDef SDIO_InitCard(SDIO_HandleTypeDef *hsdio)
uint32_t errorstate;
uint32_t timeout = 0U;
uint16_t sdio_rca = 1U;
- uint32_t Resp4;
+ uint32_t Resp4 = 0U;
uint32_t nbr_of_func;
/* Identify card operating voltage */
@@ -2858,7 +2871,7 @@ static uint8_t SDIO_Convert_Block_Size(const SDIO_HandleTypeDef *hsdio, uint32_t
static HAL_StatusTypeDef SDIO_IOFunction_IRQHandler(SDIO_HandleTypeDef *hsdio)
{
uint8_t count;
- uint8_t pendingInt;
+ uint8_t pendingInt = 0U;
if (hsdio->IOInterruptNbr == 1U)
{
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdram.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdram.c
index 9b533b41ca..e69c7da910 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdram.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sdram.c
@@ -916,13 +916,11 @@ HAL_StatusTypeDef HAL_SDRAM_Write_DMA(SDRAM_HandleTypeDef *hsdram, uint32_t *pAd
* @param hsdram : SDRAM handle
* @param CallbackId : ID of the callback to be registered
* This parameter can be one of the following values:
- * @arg @ref HAL_SDRAM_MSP_INIT_CB_ID SDRAM MspInit callback ID (*)
- * @arg @ref HAL_SDRAM_MSP_DEINIT_CB_ID SDRAM MspDeInit callback ID (*)
- * @arg @ref HAL_SDRAM_REFRESH_ERR_CB_ID SDRAM Refresh Error callback ID (*)
+ * @arg @ref HAL_SDRAM_MSP_INIT_CB_ID SDRAM MspInit callback ID
+ * @arg @ref HAL_SDRAM_MSP_DEINIT_CB_ID SDRAM MspDeInit callback ID
+ * @arg @ref HAL_SDRAM_REFRESH_ERR_CB_ID SDRAM Refresh Error callback ID
* @param pCallback : pointer to the Callback function
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_SDRAM_RegisterCallback(SDRAM_HandleTypeDef *hsdram, HAL_SDRAM_CallbackIDTypeDef CallbackId,
pSDRAM_CallbackTypeDef pCallback)
@@ -986,14 +984,12 @@ HAL_StatusTypeDef HAL_SDRAM_RegisterCallback(SDRAM_HandleTypeDef *hsdram, HAL_SD
* @param hsdram : SDRAM handle
* @param CallbackId : ID of the callback to be unregistered
* This parameter can be one of the following values:
- * @arg @ref HAL_SDRAM_MSP_INIT_CB_ID SDRAM MspInit callback ID (*)
- * @arg @ref HAL_SDRAM_MSP_DEINIT_CB_ID SDRAM MspDeInit callback ID (*)
- * @arg @ref HAL_SDRAM_REFRESH_ERR_CB_ID SDRAM Refresh Error callback ID (*)
- * @arg @ref HAL_SDRAM_DMA_XFER_CPLT_CB_ID SDRAM DMA Xfer Complete callback ID (*)
- * @arg @ref HAL_SDRAM_DMA_XFER_ERR_CB_ID SDRAM DMA Xfer Error callback ID (*)
+ * @arg @ref HAL_SDRAM_MSP_INIT_CB_ID SDRAM MspInit callback ID
+ * @arg @ref HAL_SDRAM_MSP_DEINIT_CB_ID SDRAM MspDeInit callback ID
+ * @arg @ref HAL_SDRAM_REFRESH_ERR_CB_ID SDRAM Refresh Error callback ID
+ * @arg @ref HAL_SDRAM_DMA_XFER_CPLT_CB_ID SDRAM DMA Xfer Complete callback ID
+ * @arg @ref HAL_SDRAM_DMA_XFER_ERR_CB_ID SDRAM DMA Xfer Error callback ID
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_SDRAM_UnRegisterCallback(SDRAM_HandleTypeDef *hsdram, HAL_SDRAM_CallbackIDTypeDef CallbackId)
{
@@ -1057,12 +1053,10 @@ HAL_StatusTypeDef HAL_SDRAM_UnRegisterCallback(SDRAM_HandleTypeDef *hsdram, HAL_
* @param hsdram : SDRAM handle
* @param CallbackId : ID of the callback to be registered
* This parameter can be one of the following values:
- * @arg @ref HAL_SDRAM_DMA_XFER_CPLT_CB_ID SDRAM DMA Xfer Complete callback ID (*)
- * @arg @ref HAL_SDRAM_DMA_XFER_ERR_CB_ID SDRAM DMA Xfer Error callback ID (*)
+ * @arg @ref HAL_SDRAM_DMA_XFER_CPLT_CB_ID SDRAM DMA Xfer Complete callback ID
+ * @arg @ref HAL_SDRAM_DMA_XFER_ERR_CB_ID SDRAM DMA Xfer Error callback ID
* @param pCallback : pointer to the Callback function
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_SDRAM_RegisterDmaCallback(SDRAM_HandleTypeDef *hsdram, HAL_SDRAM_CallbackIDTypeDef CallbackId,
pSDRAM_DmaCallbackTypeDef pCallback)
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_smartcard.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_smartcard.c
index 62a740c020..b90717f272 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_smartcard.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_smartcard.c
@@ -2510,14 +2510,6 @@ static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard
((uint32_t)hsmartcard->Init.WordLength));
MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_FIELDS, tmpreg);
- /*-------------------------- USART CR2 Configuration -----------------------*/
- tmpreg = hsmartcard->Init.StopBits;
- /* Synchronous mode is activated by default */
- tmpreg |= (uint32_t) USART_CR2_CLKEN | hsmartcard->Init.CLKPolarity;
- tmpreg |= (uint32_t) hsmartcard->Init.CLKPhase | hsmartcard->Init.CLKLastBit;
- tmpreg |= (uint32_t) hsmartcard->Init.TimeOutEnable;
- MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_FIELDS, tmpreg);
-
/*-------------------------- USART CR3 Configuration -----------------------*/
/* Configure
* - one-bit sampling method versus three samples' majority rule
@@ -2539,6 +2531,14 @@ static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard
tmpreg = (hsmartcard->Init.Prescaler | ((uint32_t)hsmartcard->Init.GuardTime << USART_GTPR_GT_Pos));
MODIFY_REG(hsmartcard->Instance->GTPR, (uint16_t)(USART_GTPR_GT | USART_GTPR_PSC), (uint16_t)tmpreg);
+ /*-------------------------- USART CR2 Configuration -----------------------*/
+ tmpreg = hsmartcard->Init.StopBits;
+ /* Synchronous mode is activated by default */
+ tmpreg |= (uint32_t) USART_CR2_CLKEN | hsmartcard->Init.CLKPolarity;
+ tmpreg |= (uint32_t) hsmartcard->Init.CLKPhase | hsmartcard->Init.CLKLastBit;
+ tmpreg |= (uint32_t) hsmartcard->Init.TimeOutEnable;
+ MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_FIELDS, tmpreg);
+
/*-------------------------- USART RTOR Configuration ----------------------*/
tmpreg = ((uint32_t)hsmartcard->Init.BlockLength << USART_RTOR_BLEN_Pos);
if (hsmartcard->Init.TimeOutEnable == SMARTCARD_TIMEOUT_ENABLE)
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sram.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sram.c
index 46adf27fe8..9190ff38d9 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sram.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_sram.c
@@ -865,12 +865,10 @@ HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddre
* @param hsram : SRAM handle
* @param CallbackId : ID of the callback to be registered
* This parameter can be one of the following values:
- * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID (*)
- * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID (*)
+ * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
+ * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
* @param pCallback : pointer to the Callback function
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_SRAM_RegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId,
pSRAM_CallbackTypeDef pCallback)
@@ -915,13 +913,11 @@ HAL_StatusTypeDef HAL_SRAM_RegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_
* @param hsram : SRAM handle
* @param CallbackId : ID of the callback to be unregistered
* This parameter can be one of the following values:
- * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID (*)
- * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID (*)
- * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID (*)
- * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID (*)
+ * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
+ * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
+ * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
+ * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_SRAM_UnRegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId)
{
@@ -982,12 +978,10 @@ HAL_StatusTypeDef HAL_SRAM_UnRegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRA
* @param hsram : SRAM handle
* @param CallbackId : ID of the callback to be registered
* This parameter can be one of the following values:
- * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID (*)
- * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID (*)
+ * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
+ * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
* @param pCallback : pointer to the Callback function
* @retval status
- *
- * (*) : For all h5 series
*/
HAL_StatusTypeDef HAL_SRAM_RegisterDmaCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId,
pSRAM_DmaCallbackTypeDef pCallback)
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_exti.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_exti.c
index f70c8c2a13..47fb47b622 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_exti.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_exti.c
@@ -89,7 +89,7 @@ ErrorStatus LL_EXTI_DeInit(void)
LL_EXTI_WriteReg(IMR2, 0x07DBFFFFU);
#elif defined(STM32H503xx)
LL_EXTI_WriteReg(IMR2, 0x001BFFFFU);
-#elif defined(STM32H5F5xx) || defined(STM32H5F4xx) || defined(STM32H5E5xx) ||defined(STM32H5E4xx)
+#elif defined(STM32H5F5xx) || defined(STM32H5F4xx) || defined(STM32H5E5xx) || defined(STM32H5E4xx) || defined(STM32H553xx) || defined(STM32H543xx)
LL_EXTI_WriteReg(IMR2, 0xF3D9BFFFU);
#else
LL_EXTI_WriteReg(IMR2, 0x03DBBFFFU);
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_play.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_play.c
index 506188b8ac..7c75eaeb9f 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_play.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_play.c
@@ -54,9 +54,8 @@
/**
* @brief De-Initialize PLAY peripheral registers to their default reset values.
* @param PLAYx PLAY Instance
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: PLAY registers are de-initialized
- * - ERROR: PLAY registers are not de-initialized
+ * @retval SUCCESS Operation completed successfully.
+ * @retval ERROR Invalid instance.
*/
ErrorStatus LL_PLAY_DeInit(PLAY_TypeDef *PLAYx)
{
@@ -70,7 +69,6 @@ ErrorStatus LL_PLAY_DeInit(PLAY_TypeDef *PLAYx)
/* Unlock the Configuration Registers */
LL_PLAY_Unlock(PLAYx);
- /* Reset Configuration Registers which are not reset by */
/* Force PLAY reset */
LL_APB3_GRP1_ForceReset(LL_APB3_GRP1_PERIPH_PLAY1APB);
@@ -78,11 +76,11 @@ ErrorStatus LL_PLAY_DeInit(PLAY_TypeDef *PLAYx)
LL_APB3_GRP1_ReleaseReset(LL_APB3_GRP1_PERIPH_PLAY1APB);
/* Privilege register set to default reset values */
- LL_PLAY_ConfigPrivilege(PLAYx, LL_PLAY_NPRIV);
+ LL_PLAY_SetPrivAttr(PLAYx, LL_PLAY_PRIV_ITEM_ALL, LL_PLAY_ATTR_NPRIV);
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
/* Secure register set to default reset values */
- LL_PLAY_ConfigSecure(PLAYx, LL_PLAY_NSEC);
+ LL_PLAY_SetSecAttr(PLAYx, LL_PLAY_SEC_ITEM_ALL, LL_PLAY_ATTR_NSEC);
#endif /* __ARM_FEATURE_CMSE */
}
else
diff --git a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_usb.c b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_usb.c
index 55d6b77f10..20bd49d2c6 100644
--- a/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_usb.c
+++ b/system/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_ll_usb.c
@@ -3324,6 +3324,16 @@ void USB_ReadPMA(USB_DRD_TypeDef const *USBx, uint8_t *pbUsrBuf, uint16_t wPMABu
}
}
+/**
+ * @brief Return Current Frame number
+ * @param USBx Selected device
+ * @retval current frame number
+ */
+uint32_t USB_GetCurrentFrame(USB_DRD_TypeDef const *USBx)
+{
+ return (uint32_t)(USBx->FNR & 0x7FFU);
+}
+
/*------------------------------------------------------------------------*/
/* HOST API */
@@ -3403,16 +3413,6 @@ uint32_t USB_GetHostSpeed(USB_DRD_TypeDef const *USBx)
}
}
-/**
- * @brief Return Host Current Frame number
- * @param USBx Selected device
- * @retval current frame number
- */
-uint32_t USB_GetCurrentFrame(USB_DRD_TypeDef const *USBx)
-{
- return USBx->FNR & 0x7FFU;
-}
-
#if defined (HAL_HCD_MODULE_ENABLED)
/**
* @brief Initialize a host channel
diff --git a/system/Drivers/STM32YYxx_HAL_Driver_version.md b/system/Drivers/STM32YYxx_HAL_Driver_version.md
index 1a099a3214..556d2f6f33 100644
--- a/system/Drivers/STM32YYxx_HAL_Driver_version.md
+++ b/system/Drivers/STM32YYxx_HAL_Driver_version.md
@@ -9,7 +9,7 @@
* STM32F7: 1.3.3
* STM32G0: 1.4.7
* STM32G4: 1.2.7
- * STM32H5: 1.6.0
+ * STM32H5: 1.7.0
* STM32H7: 1.11.6
* STM32L0: 1.10.7
* STM32L1: 1.4.6