+This software component is licensed by ST under BSD 3-Clause
+license, the "License"; You may not use this component except in
+compliance with
+the License. You may obtain a copy of the License at:
+
Add stm32l412xx.h and stm32l422xx.h device description files
Add startup files startup_stm32l412xx.sandstartup_stm32l422xx.s for EWARM, MDK-ARM and SW4STM32 toolchains
Add EWARM associated linker files for execution from internal RAM or internal FLASH
stm32l4xx.h
Add the following device defines:
"#define STM32L412xx" for all STM32L412xx devices
"#define STM32L422xx" for all STM32L422xx devices
stm32l4r5xx.h, stm32l4r7xx.h,
+stm32l4r9xx.h, stm32l4s5xx.h, stm32l4s7xx.h and
+stm32l4s9xx.h description files
Update SDMMC mask register
Correct SDMMC DPSMACT and CPSMACT bits definition
All stm32l4XXxx.h device description files except stm32l4rXxx.h and stm32l4sXxx.h
Correct Misra C:2012 Rule10.3 warning in replacing 0xFFUL by 0xFFU when CRC IDR register is 8-bit long only
All iar/linker/stm32l4XXxx_flash.icf and iar/linker/stm32l4XXxx_sram.icf
Remove SRAM1 and SRAM2 (and SRAM3 for stm32l4rXxx_flash.icf, stm32l4sXxx_flash.icf, stm32l4rXxx_sram.icf and stm32l4sXxx_sram.icf) start and end addresses from ICF editor section
Define RAM section as covering whole SRAM1 plus SRAM2 (and SRAM3 when applicable) when the SRAM regions are contiguous
+
+
+
+
+
+
+
Update History
+
V1.4.3 / 30-April-2018
Main Changes
all stm32l4XXxx.h device description files
Fix DFSDM_FLTICR_CLRSCDF definition
Cleanup USB Host & Device bit definitions
[MISRAC2012-Rule-10.6] Use 'UL' postfix for _Msk definitions and memory/peripheral base addresses
Add startup files startup_stm32l4r5xx.s, startup_stm32l4r7xx.s, startup_stm32l4r9xx.s,startup_stm32l4s5xx.s,startup_stm32l4s7xx.sandstartup_stm32l4s9xx.s for EWARM, MDK-ARM and SW4STM32 toolchains
Add EWARM associated linker files for execution from internal RAM or internal FLASH
stm32l4xx.h
Add the following device defines:
"#define STM32L4R5xx" for all STM32L4R5xx devices
"#define STM32L4R7xx" for all STM32L4R7xx devices
"#define STM32L4R9xx" for all STM32L4R9xx devices
"#define STM32L4S5xx" for all STM32L4S5xx devices
"#define STM32L4S7xx" for all STM32L4S7xx devices
"#define STM32L4S9xx" for all STM32L4S9xx devices
all adequate stm32l4XXxx.h device description files
PWR: Rename PWR_CR3_EIWF to PWR_CR3_EIWUL
TIM: Add missing TIM8 check in debug macro IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE() devices
USB: Fix USB_EP0R...USB_EP7R definitions
system_stm32l4xx.c
Fix MISRA C 2004 rule 10.6 : a 'U' suffix shall be applied to all constants of 'unsigned' type
V1.3.2
/ 16-June-2017
Main
Changes
@@ -142,68 +241,14 @@
Main
Changes
-
First official release for STM32L471xx, STM32L475xx, STM32L476xx, STM32L485xx and STM32L486xx devices
-
-
-
License
-
-
-
-
Redistribution
-and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-
-
Redistributions
-of source code must retain the above copyright notice, this list of
-conditions and the following disclaimer.
-
Redistributions
-in binary form must reproduce the above copyright notice, this list of
-conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-
Neither the
-name of STMicroelectronics nor the names of its contributors may be
-used to endorse or promote products derived
-
-
-
-from this software without specific prior written permission.
-
-THIS
-SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-THE POSSIBILITY OF SUCH DAMAGE.
-
-
-
-
-
-
-
For
-complete documentation on STM32 Microcontrollers
-visit www.st.com/STM32
-
-
-
-
-
-
-
-
-
+
First official release for STM32L471xx, STM32L475xx, STM32L476xx, STM32L485xx and STM32L486xx devices
+
+
+
+
For complete
+documentation on STM32 Microcontrollers,
+visit: www.st.com/STM32
+
-
\ No newline at end of file
diff --git a/system/Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l412xx.s b/system/Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l412xx.s
new file mode 100644
index 0000000000..e6280c2127
--- /dev/null
+++ b/system/Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l412xx.s
@@ -0,0 +1,447 @@
+/**
+ ******************************************************************************
+ * @file startup_stm32l412xx.s
+ * @author MCD Application Team
+ * @brief STM32L412xx devices vector table for GCC toolchain.
+ * This module performs:
+ * - Set the initial SP
+ * - Set the initial PC == Reset_Handler,
+ * - Set the vector table entries with the exceptions ISR address,
+ * - Configure the clock system
+ * - Branches to main in the C library (which eventually
+ * calls main()).
+ * After Reset the Cortex-M4 processor is in Thread mode,
+ * priority is Privileged, and the Stack is set to Main.
+ ******************************************************************************
+ * @attention
+ *
+ *
+This software component is licensed by ST under BSD 3-Clause
+license, the "License"; You may not use this component except in
+compliance with
+the License. You may obtain a copy of the License at:
+
Correct MISRA C:2012 warnings reported by rule 21.1
HAL USART driver
Correct MISRA C:2012 warnings reported by rule 10.4_a, 10.6, 12.2
LL Drivers changes
+
LL ADC driver
stm32l4xx_ll_dmamux.h: clarify comments when oversampling is enabled
LL DMAdriver
stm32l4xx_ll_dmamux.h: remove test on DMAMUX1
LL RCC driver
stm32l4xx_ll_rcc.c, stm32l4xx_ll_rcc.h: compilation switches update to ensure full STM32L412xx/L422xx devices support
LL RTC driver
stm32l4xx_ll_rtc.h: add new macros LL_RTC_WAKEUP_SetAutoClr(), LL_RTC_WAKEUP_GetAutoClr() applicable to STM32L412xx/L422xx devices only
+
+
+
+
+
+
Update History
+
+
V1.8.3
/ 22-May-2018
Main
@@ -992,61 +528,14 @@
Main
Changes
-
First official release of STM32L4xx HAL Drivers for STM32L471xx/STM32L475xx/ STM32L476xx/ STM32L485xx and STM32L486xx devices.
-
License
-
-
Redistribution
-and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-
-
Redistributions
-of source code must retain the above copyright notice, this list of
-conditions and the following disclaimer.
-
Redistributions
-in binary form must reproduce the above copyright notice, this list of
-conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-
Neither the
-name of STMicroelectronics nor the names of its contributors may be
-used to endorse or promote products derived
-
-
-
-from this software without specific prior written permission.
-
-THIS
-SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-THE POSSIBILITY OF SUCH DAMAGE.
-
-
-
-
-
For
-complete documentation on STM32 Microcontrollers visit www.st.com/STM32
-
-
-
-
-
-
-
-
-
+
First official release of STM32L4xx HAL Drivers for STM32L471xx/STM32L475xx/ STM32L476xx/ STM32L485xx and STM32L486xx devices.
+
+
+
+
For complete
+documentation on STM32 Microcontrollers,
+visit: www.st.com/STM32
+
-
\ No newline at end of file
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c
index 27702e3ee8..e045a89782 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c
@@ -67,17 +67,17 @@
/**
* @brief STM32L4xx HAL Driver version number
*/
-#define __STM32L4xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */
-#define __STM32L4xx_HAL_VERSION_SUB1 (0x08) /*!< [23:16] sub1 version */
-#define __STM32L4xx_HAL_VERSION_SUB2 (0x03) /*!< [15:8] sub2 version */
-#define __STM32L4xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */
-#define __STM32L4xx_HAL_VERSION ((__STM32L4xx_HAL_VERSION_MAIN << 24)\
- |(__STM32L4xx_HAL_VERSION_SUB1 << 16)\
- |(__STM32L4xx_HAL_VERSION_SUB2 << 8 )\
- |(__STM32L4xx_HAL_VERSION_RC))
+#define STM32L4XX_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
+#define STM32L4XX_HAL_VERSION_SUB1 (0x09U) /*!< [23:16] sub1 version */
+#define STM32L4XX_HAL_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
+#define STM32L4XX_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
+#define STM32L4XX_HAL_VERSION ((STM32L4XX_HAL_VERSION_MAIN << 24U)\
+ |(STM32L4XX_HAL_VERSION_SUB1 << 16U)\
+ |(STM32L4XX_HAL_VERSION_SUB2 << 8U)\
+ |(STM32L4XX_HAL_VERSION_RC))
#if defined(VREFBUF)
-#define VREFBUF_TIMEOUT_VALUE (uint32_t)10 /* 10 ms (to be confirmed) */
+#define VREFBUF_TIMEOUT_VALUE 10U /* 10 ms (to be confirmed) */
#endif /* VREFBUF */
/* ------------ SYSCFG registers bit address in the alias region ------------ */
@@ -85,20 +85,29 @@
/* --- MEMRMP Register ---*/
/* Alias word address of FB_MODE bit */
#define MEMRMP_OFFSET SYSCFG_OFFSET
-#define FB_MODE_BitNumber ((uint8_t)0x8)
-#define FB_MODE_BB (PERIPH_BB_BASE + (MEMRMP_OFFSET * 32) + (FB_MODE_BitNumber * 4))
+#define FB_MODE_BitNumber 8U
+#define FB_MODE_BB (PERIPH_BB_BASE + (MEMRMP_OFFSET * 32U) + (FB_MODE_BitNumber * 4U))
/* --- SCSR Register ---*/
/* Alias word address of SRAM2ER bit */
-#define SCSR_OFFSET (SYSCFG_OFFSET + 0x18)
-#define BRER_BitNumber ((uint8_t)0x0)
-#define SCSR_SRAM2ER_BB (PERIPH_BB_BASE + (SCSR_OFFSET * 32) + (BRER_BitNumber * 4))
+#define SCSR_OFFSET (SYSCFG_OFFSET + 0x18U)
+#define BRER_BitNumber 0U
+#define SCSR_SRAM2ER_BB (PERIPH_BB_BASE + (SCSR_OFFSET * 32U) + (BRER_BitNumber * 4U))
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+
+/* Exported variables --------------------------------------------------------*/
+
+/** @defgroup HAL_Exported_Variables HAL Exported Variables
+ * @{
+ */
__IO uint32_t uwTick;
+/**
+ * @}
+ */
-/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup HAL_Exported_Functions HAL Exported Functions
@@ -139,23 +148,25 @@ __IO uint32_t uwTick;
/**
* @brief Configure the Flash prefetch, the Instruction and Data caches,
- * the time base source, NVIC and any required global low level hardware
- * by calling the HAL_MspInit() callback function to be optionally defined in user file
+ * the time base source, NVIC and any required global low level hardware
+ * by calling the HAL_MspInit() callback function to be optionally defined in user file
* stm32l4xx_hal_msp.c.
*
- * @note HAL_Init() function is called at the beginning of program after reset and before
+ * @note HAL_Init() function is called at the beginning of program after reset and before
* the clock configuration.
- *
+ *
* @note In the default implementation the System Timer (Systick) is used as source of time base.
* The Systick configuration is based on MSI clock, as MSI is the clock
* used after a system Reset and the NVIC configuration is set to Priority group 4.
- * Once done, time base tick starts incrementing: the tick variable counter is incremented
+ * Once done, time base tick starts incrementing: the tick variable counter is incremented
* each 1ms in the SysTick_Handler() interrupt handler.
*
* @retval HAL status
*/
HAL_StatusTypeDef HAL_Init(void)
{
+ HAL_StatusTypeDef status = HAL_OK;
+
/* Configure Flash prefetch, Instruction cache, Data cache */
/* Default configuration at reset is: */
/* - Prefetch disabled */
@@ -177,13 +188,18 @@ HAL_StatusTypeDef HAL_Init(void)
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
/* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */
- HAL_InitTick(TICK_INT_PRIORITY);
-
- /* Init the low level hardware */
- HAL_MspInit();
+ if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
+ {
+ status = HAL_ERROR;
+ }
+ else
+ {
+ /* Init the low level hardware */
+ HAL_MspInit();
+ }
/* Return function status */
- return HAL_OK;
+ return status;
}
/**
@@ -256,14 +272,21 @@ __weak void HAL_MspDeInit(void)
*/
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
- /*Configure the SysTick to have interrupt in 1ms time basis*/
- HAL_SYSTICK_Config(SystemCoreClock/1000);
+ HAL_StatusTypeDef status = HAL_OK;
- /*Configure the SysTick IRQ priority */
- HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0);
+ /*Configure the SysTick to have interrupt in 1ms time basis*/
+ if (HAL_SYSTICK_Config(SystemCoreClock/1000UL) != 0U)
+ {
+ status = HAL_ERROR;
+ }
+ else
+ {
+ /*Configure the SysTick IRQ priority */
+ HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0);
+ }
/* Return function status */
- return HAL_OK;
+ return status;
}
/**
@@ -316,8 +339,8 @@ __weak uint32_t HAL_GetTick(void)
}
/**
- * @brief This function provides minimum delay (in milliseconds) based
- * on variable incremented.
+ * @brief This function provides minimum delay (in milliseconds) based
+ * on variable incremented.
* @note In the default implementation , SysTick timer is the source of time base.
* It is used to generate interrupts at regular time intervals where uwTick
* is incremented.
@@ -335,7 +358,7 @@ __weak void HAL_Delay(uint32_t Delay)
if (wait < HAL_MAX_DELAY)
{
wait++;
- }
+ }
while((HAL_GetTick() - tickstart) < wait)
{
@@ -380,7 +403,7 @@ __weak void HAL_ResumeTick(void)
*/
uint32_t HAL_GetHalVersion(void)
{
- return __STM32L4xx_HAL_VERSION;
+ return STM32L4XX_HAL_VERSION;
}
/**
@@ -389,7 +412,7 @@ uint32_t HAL_GetHalVersion(void)
*/
uint32_t HAL_GetREVID(void)
{
- return((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16);
+ return((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16);
}
/**
@@ -398,7 +421,7 @@ uint32_t HAL_GetREVID(void)
*/
uint32_t HAL_GetDEVID(void)
{
- return(DBGMCU->IDCODE & DBGMCU_IDCODE_DEV_ID);
+ return(DBGMCU->IDCODE & DBGMCU_IDCODE_DEV_ID);
}
/**
@@ -407,7 +430,7 @@ uint32_t HAL_GetDEVID(void)
*/
uint32_t HAL_GetUIDw0(void)
{
- return(READ_REG(*((uint32_t *)UID_BASE)));
+ return(READ_REG(*((uint32_t *)UID_BASE)));
}
/**
@@ -416,7 +439,7 @@ uint32_t HAL_GetUIDw0(void)
*/
uint32_t HAL_GetUIDw1(void)
{
- return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
+ return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
}
/**
@@ -425,7 +448,7 @@ uint32_t HAL_GetUIDw1(void)
*/
uint32_t HAL_GetUIDw2(void)
{
- return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
+ return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
}
/**
@@ -536,7 +559,7 @@ void HAL_SYSCFG_SRAM2Erase(void)
SYSCFG->SKR = 0xCA;
SYSCFG->SKR = 0x53;
/* Starts a hardware SRAM2 erase operation*/
- *(__IO uint32_t *) SCSR_SRAM2ER_BB = (uint8_t)0x00000001;
+ *(__IO uint32_t *) SCSR_SRAM2ER_BB = 0x00000001UL;
}
/**
@@ -551,7 +574,7 @@ void HAL_SYSCFG_SRAM2Erase(void)
*/
void HAL_SYSCFG_EnableMemorySwappingBank(void)
{
- *(__IO uint32_t *)FB_MODE_BB = (uint32_t)ENABLE;
+ *(__IO uint32_t *)FB_MODE_BB = 0x00000000UL;
}
/**
@@ -567,7 +590,7 @@ void HAL_SYSCFG_EnableMemorySwappingBank(void)
void HAL_SYSCFG_DisableMemorySwappingBank(void)
{
- *(__IO uint32_t *)FB_MODE_BB = (uint32_t)DISABLE;
+ *(__IO uint32_t *)FB_MODE_BB = 0x00000000UL;
}
#if defined(VREFBUF)
@@ -575,9 +598,9 @@ void HAL_SYSCFG_DisableMemorySwappingBank(void)
* @brief Configure the internal voltage reference buffer voltage scale.
* @param VoltageScaling specifies the output voltage to achieve
* This parameter can be one of the following values:
- * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.048 V.
+ * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.048 V.
* This requires VDDA equal to or higher than 2.4 V.
- * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT2 around 2.5 V.
+ * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT2 around 2.5 V.
* This requires VDDA equal to or higher than 2.8 V.
* @retval None
*/
@@ -585,7 +608,7 @@ void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
{
/* Check the parameters */
assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
-
+
MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling);
}
@@ -601,7 +624,7 @@ void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
{
/* Check the parameters */
assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
-
+
MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
}
@@ -613,7 +636,7 @@ void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
{
/* Check the parameters */
assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
-
+
MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue);
}
@@ -623,22 +646,22 @@ void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
*/
HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
{
- uint32_t tickstart = 0;
-
+ uint32_t tickstart;
+
SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
-
+
/* Get Start Tick*/
tickstart = HAL_GetTick();
/* Wait for VRR bit */
- while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == RESET)
+ while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0U)
{
if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
-
+
return HAL_OK;
}
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c
index a7543d8b73..03d9628cf5 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c
@@ -336,18 +336,18 @@
* @{
*/
-#define ADC_CFGR_FIELDS_1 ((uint32_t)(ADC_CFGR_RES | ADC_CFGR_ALIGN |\
- ADC_CFGR_CONT | ADC_CFGR_OVRMOD |\
- ADC_CFGR_DISCEN | ADC_CFGR_DISCNUM |\
- ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL)) /*!< ADC_CFGR fields of parameters that can be updated
- when no regular conversion is on-going */
+#define ADC_CFGR_FIELDS_1 ((ADC_CFGR_RES | ADC_CFGR_ALIGN |\
+ ADC_CFGR_CONT | ADC_CFGR_OVRMOD |\
+ ADC_CFGR_DISCEN | ADC_CFGR_DISCNUM |\
+ ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL)) /*!< ADC_CFGR fields of parameters that can be updated
+ when no regular conversion is on-going */
/* Timeout values for ADC operations (enable settling time, */
/* disable settling time, ...). */
/* Values defined to be higher than worst cases: low clock frequency, */
/* maximum prescalers. */
-#define ADC_ENABLE_TIMEOUT ((uint32_t) 2) /*!< ADC enable time-out value */
-#define ADC_DISABLE_TIMEOUT ((uint32_t) 2) /*!< ADC disable time-out value */
+#define ADC_ENABLE_TIMEOUT (2UL) /*!< ADC enable time-out value */
+#define ADC_DISABLE_TIMEOUT (2UL) /*!< ADC disable time-out value */
/* Timeout to wait for current conversion on going to be completed. */
/* Timeout fixed to longest ADC conversion possible, for 1 channel: */
@@ -357,7 +357,7 @@
/* - ADC oversampling ratio 256 */
/* Calculation: 653 * 4096 * 256 CPU clock cycles max */
/* Unit: cycles of CPU clock. */
-#define ADC_CONVERSION_TIME_MAX_CPU_CYCLES ((uint32_t) 653U * 4096U * 256U) /*!< ADC conversion completion time-out value */
+#define ADC_CONVERSION_TIME_MAX_CPU_CYCLES (653UL * 4096UL * 256UL) /*!< ADC conversion completion time-out value */
/**
@@ -418,8 +418,11 @@
HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
{
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
- uint32_t tmpCFGR = 0U;
+ uint32_t tmpCFGR;
+ uint32_t tmp_adc_reg_is_conversion_on_going;
__IO uint32_t wait_loop_index = 0;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
/* Check ADC handle */
if(hadc == NULL)
@@ -431,7 +434,9 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
assert_param(IS_ADC_CLOCKPRESCALER(hadc->Init.ClockPrescaler));
assert_param(IS_ADC_RESOLUTION(hadc->Init.Resolution));
+#if defined(ADC_CFGR_DFSDMCFG) &&defined(DFSDM1_Channel0)
assert_param(IS_ADC_DFSDMCFG_MODE(hadc));
+#endif
assert_param(IS_ADC_DATA_ALIGN(hadc->Init.DataAlign));
assert_param(IS_ADC_SCAN_MODE(hadc->Init.ScanConvMode));
assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
@@ -493,7 +498,7 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
}
/* - Exit from deep-power-down mode and ADC voltage regulator enable */
- if(LL_ADC_IsDeepPowerDownEnabled(hadc->Instance) != 0U)
+ if(LL_ADC_IsDeepPowerDownEnabled(hadc->Instance) != 0UL)
{
/* Disable ADC deep power down mode */
LL_ADC_DisableDeepPowerDown(hadc->Instance);
@@ -503,17 +508,16 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
re-applied once the ADC voltage regulator is enabled */
}
- if(LL_ADC_IsInternalRegulatorEnabled(hadc->Instance) == 0U)
+ if(LL_ADC_IsInternalRegulatorEnabled(hadc->Instance) == 0UL)
{
/* Enable ADC internal voltage regulator */
LL_ADC_EnableInternalRegulator(hadc->Instance);
- /* Delay for ADC stabilization time */
- /* Wait loop initialization and execution */
- /* Note: Variable divided by 2 to compensate partially */
- /* CPU processing cycles. */
- wait_loop_index = (LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (1000000 * 2)));
- while(wait_loop_index != 0)
+ /* Note: Variable divided by 2 to compensate partially */
+ /* CPU processing cycles, scaling in us split to not */
+ /* exceed 32 bits register capacity and handle low frequency. */
+ wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
+ while(wait_loop_index != 0UL)
{
wait_loop_index--;
}
@@ -522,7 +526,7 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
/* Verification that ADC voltage regulator is correctly enabled, whether */
/* or not ADC is coming from state reset (if any potential problem of */
/* clocking, voltage regulator would not be enabled). */
- if(LL_ADC_IsInternalRegulatorEnabled(hadc->Instance) == 0U)
+ if(LL_ADC_IsInternalRegulatorEnabled(hadc->Instance) == 0UL)
{
/* Update ADC state machine to error */
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
@@ -537,8 +541,10 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
/* correctly completed and if there is no conversion on going on regular */
/* group (ADC may already be enabled at this point if HAL_ADC_Init() is */
/* called to update a parameter on the fly). */
- if( (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL))
- && (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ tmp_adc_reg_is_conversion_on_going = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+
+ if( ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) == 0UL)
+ && (tmp_adc_reg_is_conversion_on_going == 0UL)
)
{
/* Set ADC state */
@@ -551,27 +557,29 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
/* Parameters update conditioned to ADC state: */
/* Parameters that can be updated only when ADC is disabled: */
/* - clock configuration */
- if ((ADC_IS_ENABLE(hadc) == RESET) &&
- (ADC_ANY_OTHER_ENABLED(hadc) == RESET) )
- {
- /* Reset configuration of ADC common register CCR: */
- /* */
- /* - ADC clock mode and ACC prescaler (CKMODE and PRESC bits)are set */
- /* according to adc->Init.ClockPrescaler. It selects the clock */
- /* source and sets the clock division factor. */
- /* */
- /* Some parameters of this register are not reset, since they are set */
- /* by other functions and must be kept in case of usage of this */
- /* function on the fly (update of a parameter of ADC_InitTypeDef */
- /* without needing to reconfigure all other ADC groups/channels */
- /* parameters): */
- /* - when multimode feature is available, multimode-related */
- /* parameters: MDMA, DMACFG, DELAY, DUAL (set by API */
- /* HAL_ADCEx_MultiModeConfigChannel() ) */
- /* - internal measurement paths: Vbat, temperature sensor, Vref */
- /* (set into HAL_ADC_ConfigChannel() or */
- /* HAL_ADCEx_InjectedConfigChannel() ) */
- LL_ADC_SetCommonClock(__LL_ADC_COMMON_INSTANCE(hadc->Instance), hadc->Init.ClockPrescaler);
+ if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
+ {
+ if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
+ {
+ /* Reset configuration of ADC common register CCR: */
+ /* */
+ /* - ADC clock mode and ACC prescaler (CKMODE and PRESC bits)are set */
+ /* according to adc->Init.ClockPrescaler. It selects the clock */
+ /* source and sets the clock division factor. */
+ /* */
+ /* Some parameters of this register are not reset, since they are set */
+ /* by other functions and must be kept in case of usage of this */
+ /* function on the fly (update of a parameter of ADC_InitTypeDef */
+ /* without needing to reconfigure all other ADC groups/channels */
+ /* parameters): */
+ /* - when multimode feature is available, multimode-related */
+ /* parameters: MDMA, DMACFG, DELAY, DUAL (set by API */
+ /* HAL_ADCEx_MultiModeConfigChannel() ) */
+ /* - internal measurement paths: Vbat, temperature sensor, Vref */
+ /* (set into HAL_ADC_ConfigChannel() or */
+ /* HAL_ADCEx_InjectedConfigChannel() ) */
+ LL_ADC_SetCommonClock(__LL_ADC_COMMON_INSTANCE(hadc->Instance), hadc->Init.ClockPrescaler);
+ }
}
/* Configuration of ADC: */
@@ -583,11 +591,11 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
/* - overrun Init.Overrun */
/* - discontinuous mode Init.DiscontinuousConvMode */
/* - discontinuous mode channel count Init.NbrOfDiscConversion */
- tmpCFGR = (ADC_CFGR_CONTINUOUS(hadc->Init.ContinuousConvMode) |
- hadc->Init.Overrun |
- hadc->Init.DataAlign |
- hadc->Init.Resolution |
- ADC_CFGR_REG_DISCONTINUOUS(hadc->Init.DiscontinuousConvMode) );
+ tmpCFGR = (ADC_CFGR_CONTINUOUS((uint32_t)hadc->Init.ContinuousConvMode) |
+ hadc->Init.Overrun |
+ hadc->Init.DataAlign |
+ hadc->Init.Resolution |
+ ADC_CFGR_REG_DISCONTINUOUS((uint32_t)hadc->Init.DiscontinuousConvMode) );
if (hadc->Init.DiscontinuousConvMode == ENABLE)
{
@@ -615,13 +623,17 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
/* - DMA continuous request Init.DMAContinuousRequests */
/* - LowPowerAutoWait feature Init.LowPowerAutoWait */
/* - Oversampling parameters Init.Oversampling */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET)
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+ if ( (tmp_adc_is_conversion_on_going_regular == 0UL)
+ && (tmp_adc_is_conversion_on_going_injected == 0UL)
+ )
{
- tmpCFGR = ( ADC_CFGR_DFSDM(hadc) |
- ADC_CFGR_AUTOWAIT(hadc->Init.LowPowerAutoWait) |
- ADC_CFGR_DMACONTREQ(hadc->Init.DMAContinuousRequests) );
+ tmpCFGR = ( ADC_CFGR_DFSDM(hadc) |
+ ADC_CFGR_AUTOWAIT((uint32_t)hadc->Init.LowPowerAutoWait) |
+ ADC_CFGR_DMACONTREQ((uint32_t)hadc->Init.DMAContinuousRequests) );
- MODIFY_REG(hadc->Instance->CFGR, ADC_CFGR_FIELDS_2, tmpCFGR);
+ MODIFY_REG(hadc->Instance->CFGR, ADC_CFGR_FIELDS_2, tmpCFGR);
if (hadc->Init.OversamplingMode == ENABLE)
{
@@ -653,7 +665,7 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
CLEAR_BIT(hadc->Instance->CFGR2, ADC_CFGR2_ROVSE);
}
- } /* if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET) */
+ }
/* Configuration of regular group sequencer: */
/* - if scan mode is disabled, regular channels sequence length is set to */
@@ -710,6 +722,8 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
{
+ HAL_StatusTypeDef tmp_hal_status;
+
/* Check ADC handle */
if(hadc == NULL)
{
@@ -722,11 +736,8 @@ HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
/* Set ADC state */
SET_BIT(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL);
- /* Stop potential conversion on going, on regular and injected groups */
- /* Note: No check on ADC_ConversionStop() return status, */
- /* if the conversion stop failed, it is up to */
- /* HAL_ADC_MspDeInit() to reset the ADC IP. */
- ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP);
+ /* Stop potential conversion on going */
+ tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP);
/* Disable ADC peripheral if conversions are effectively stopped */
/* Flush register JSQR: reset the queue sequencer when injected */
@@ -736,11 +747,25 @@ HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
/* injected sequence. */
SET_BIT(hadc->Instance->CFGR, ADC_CFGR_JQM);
- /* Disable the ADC peripheral */
- /* No check on ADC_Disable() return status, if the ADC disabling process
- failed, it is up to HAL_ADC_MspDeInit() to reset the ADC IP */
- ADC_Disable(hadc);
+ /* Disable ADC peripheral if conversions are effectively stopped */
+ if (tmp_hal_status == HAL_OK)
+ {
+ /* Disable the ADC peripheral */
+ tmp_hal_status = ADC_Disable(hadc);
+
+ /* Check if ADC is effectively disabled */
+ if (tmp_hal_status == HAL_OK)
+ {
+ /* Change ADC state */
+ hadc->State = HAL_ADC_STATE_READY;
+ }
+ }
+ /* Note: HAL ADC deInit is done independently of ADC conversion stop */
+ /* and disable return status. In case of status fail, attempt to */
+ /* perform deinitialization anyway and it is up user code in */
+ /* in HAL_ADC_MspDeInit() to reset the ADC peripheral using */
+ /* system RCC hard reset. */
/* ========== Reset ADC registers ========== */
/* Reset register IER */
@@ -839,8 +864,7 @@ HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
/* Software is allowed to change common parameters only when all the other
ADCs are disabled. */
- if ((ADC_IS_ENABLE(hadc) == RESET) &&
- (ADC_ANY_OTHER_ENABLED(hadc) == RESET) )
+ if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
{
/* Reset configuration of ADC common register CCR:
- clock mode: CKMODE, PRESCEN
@@ -890,7 +914,7 @@ HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
__HAL_UNLOCK(hadc);
/* Return function status */
- return HAL_OK;
+ return tmp_hal_status;
}
/**
@@ -961,7 +985,7 @@ HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_Call
return HAL_ERROR;
}
- if ((hadc->State & HAL_ADC_STATE_READY) != 0)
+ if ((hadc->State & HAL_ADC_STATE_READY) != 0UL)
{
switch (CallbackID)
{
@@ -1077,7 +1101,7 @@ HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_Ca
{
HAL_StatusTypeDef status = HAL_OK;
- if ((hadc->State & HAL_ADC_STATE_READY) != 0)
+ if ((hadc->State & HAL_ADC_STATE_READY) != 0UL)
{
switch (CallbackID)
{
@@ -1206,14 +1230,17 @@ HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_Ca
*/
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
- ADC_TypeDef *tmpADC_Master;
+ HAL_StatusTypeDef tmp_hal_status;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ const ADC_TypeDef *tmpADC_Master;
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
/* Perform ADC enable and conversion start if no conversion is on going */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* Process locked */
__HAL_LOCK(hadc);
@@ -1231,14 +1258,18 @@ HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP,
HAL_ADC_STATE_REG_BUSY);
+#if defined(ADC_MULTIMODE_SUPPORT)
/* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
- - by default if ADC is Master or Independent or if multimode feature is not available
- - if multimode setting is set to independent mode (no dual regular or injected conversions are configured) */
- if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
+ - if ADC instance is master or if multimode feature is not available
+ - if multimode setting is disabled (ADC instance slave in independent mode) */
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ )
{
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
}
-
+#endif
+
/* Set ADC error code */
/* Check if a conversion is on going on ADC group injected */
if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY))
@@ -1269,12 +1300,15 @@ HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
/* - if ADC is slave and dual regular conversions are enabled, ADC is */
/* enabled only (conversion is not started), */
/* - if ADC is master, ADC is enabled and conversion is started. */
- if (ADC_INDEPENDENT_OR_NONMULTIMODEREGULAR_SLAVE(hadc))
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
+ )
{
- /* Multimode feature is not available or ADC Instance is Independent or Master,
- or is not Slave ADC with dual regular conversions enabled.
- Then, set HAL_ADC_STATE_INJ_BUSY bit and reset HAL_ADC_STATE_INJ_EOC bit if JAUTO is set. */
- if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != RESET)
+ /* ADC instance is not a multimode slave instance with multimode regular conversions enabled */
+ if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
{
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
}
@@ -1284,16 +1318,26 @@ HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
}
else
{
+ /* ADC instance is a multimode slave instance with multimode regular conversions enabled */
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
/* if Master ADC JAUTO bit is set, update Slave State in setting
HAL_ADC_STATE_INJ_BUSY bit and in resetting HAL_ADC_STATE_INJ_EOC bit */
- tmpADC_Master = ADC_MASTER_REGISTER(hadc);
- if (READ_BIT(tmpADC_Master->CFGR, ADC_CFGR_JAUTO) != RESET)
+ tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
+ if (READ_BIT(tmpADC_Master->CFGR, ADC_CFGR_JAUTO) != 0UL)
{
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
}
}
+#else
+ if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
+ {
+ ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
+ }
+
+ /* Start ADC group regular conversion */
+ LL_ADC_REG_StartConversion(hadc->Instance);
+#endif
}
else
{
@@ -1321,7 +1365,7 @@ HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1375,10 +1419,13 @@ HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
{
- uint32_t tickstart = 0U;
- uint32_t tmp_Flag_End = 0U;
- uint32_t tmp_cfgr = 0U;
- ADC_TypeDef *tmpADC_Master;
+ uint32_t tickstart;
+ uint32_t tmp_Flag_End;
+ uint32_t tmp_cfgr;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ const ADC_TypeDef *tmpADC_Master;
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1397,10 +1444,14 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
/* several ranks and polling for end of each conversion. */
/* For code simplicity sake, this particular case is generalized to */
/* ADC configured in DMA mode and and polling for end of each conversion. */
- if(ADC_IS_DUAL_REGULAR_CONVERSION_ENABLE(hadc) == RESET)
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
+ )
{
- /* Check ADC DMA mode in independant mode */
- if(READ_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN) != RESET)
+ /* Check ADC DMA mode in independent mode on ADC group regular */
+ if(READ_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN) != 0UL)
{
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
return HAL_ERROR;
@@ -1412,8 +1463,8 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
}
else
{
- /* Check ADC DMA mode in multimode */
- if(ADC_MULTIMODE_DMA_ENABLED(hadc))
+ /* Check ADC DMA mode in multimode on ADC group regular */
+ if (LL_ADC_GetMultiDMATransfer(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) != LL_ADC_MULTI_REG_DMA_EACH_ADC)
{
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
return HAL_ERROR;
@@ -1423,18 +1474,30 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
tmp_Flag_End = (ADC_FLAG_EOC);
}
}
+#else
+ /* Check ADC DMA mode */
+ if(READ_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN) != 0UL)
+ {
+ SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
+ return HAL_ERROR;
+ }
+ else
+ {
+ tmp_Flag_End = (ADC_FLAG_EOC);
+ }
+#endif
}
/* Get tick count */
tickstart = HAL_GetTick();
/* Wait until End of unitary conversion or sequence conversions flag is raised */
- while(HAL_IS_BIT_CLR(hadc->Instance->ISR, tmp_Flag_End))
+ while((hadc->Instance->ISR & tmp_Flag_End) == 0UL)
{
/* Check if timeout is disabled (set to infinite wait) */
if(Timeout != HAL_MAX_DELAY)
{
- if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
+ if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
{
/* Update ADC state machine to timeout */
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
@@ -1452,8 +1515,9 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
/* Determine whether any further conversion upcoming on group regular */
/* by external trigger, continuous mode or scan sequence on going. */
- if(ADC_IS_SOFTWARE_START_REGULAR(hadc) &&
- (hadc->Init.ContinuousConvMode == DISABLE) )
+ if( (LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance) != 0UL)
+ && (hadc->Init.ContinuousConvMode == DISABLE)
+ )
{
/* Check whether end of sequence is reached */
if( __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS) )
@@ -1461,8 +1525,8 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
/* Set ADC state */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
- if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY))
- {
+ if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) == 0UL)
+ {
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
}
}
@@ -1471,17 +1535,26 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
/* Get relevant register CFGR in ADC instance of ADC master or slave */
/* in function of multimode state (for devices with multimode */
/* available). */
- if (ADC_INDEPENDENT_OR_NONMULTIMODEREGULAR_SLAVE(hadc))
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
+ )
{
/* Retrieve handle ADC CFGR register */
- tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
}
else
{
/* Retrieve Master ADC CFGR register */
- tmpADC_Master = ADC_MASTER_REGISTER(hadc);
+ tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
}
+#else
+ /* Retrieve handle ADC CFGR register */
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+#endif
/* Clear polled flag */
if (tmp_Flag_End == ADC_FLAG_EOS)
@@ -1493,7 +1566,7 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
/* Clear end of conversion EOC flag of regular group if low power feature */
/* "LowPowerAutoWait " is disabled, to not interfere with this feature */
/* until data register is read using function HAL_ADC_GetValue(). */
- if (READ_BIT(tmp_cfgr, ADC_CFGR_AUTDLY) == RESET)
+ if (READ_BIT(tmp_cfgr, ADC_CFGR_AUTDLY) == 0UL)
{
__HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS));
}
@@ -1525,7 +1598,7 @@ HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Ti
*/
HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout)
{
- uint32_t tickstart = 0;
+ uint32_t tickstart;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1535,12 +1608,12 @@ HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventTy
tickstart = HAL_GetTick();
/* Check selected event flag */
- while(__HAL_ADC_GET_FLAG(hadc, EventType) == RESET)
+ while(__HAL_ADC_GET_FLAG(hadc, EventType) == 0UL)
{
/* Check if timeout is disabled (set to infinite wait) */
if(Timeout != HAL_MAX_DELAY)
{
- if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
+ if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
{
/* Update ADC state machine to timeout */
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
@@ -1570,9 +1643,10 @@ HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventTy
/* which one triggered and on which ADCx, test ADC state of analog watchdog */
/* flags HAL_ADC_STATE_AWD1/2/3 using function "HAL_ADC_GetState()". */
/* For example: */
- /* " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1)) " */
- /* " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD2)) " */
- /* " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD3)) " */
+ /* " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD1) != 0UL) " */
+ /* " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD2) != 0UL) " */
+ /* " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD3) != 0UL) " */
+
/* Check analog watchdog 1 flag */
case ADC_AWD_EVENT:
/* Set ADC state */
@@ -1669,14 +1743,17 @@ HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventTy
*/
HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
- ADC_TypeDef *tmpADC_Master;
+ HAL_StatusTypeDef tmp_hal_status;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ const ADC_TypeDef *tmpADC_Master;
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
/* Perform ADC enable and conversion start if no conversion is on going */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* Process locked */
__HAL_LOCK(hadc);
@@ -1694,17 +1771,21 @@ HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP,
HAL_ADC_STATE_REG_BUSY);
+#if defined(ADC_MULTIMODE_SUPPORT)
/* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
- - by default if ADC is Master or Independent or if multimode feature is not available
- - if multimode setting is set to independent mode (no dual regular or injected conversions are configured) */
- if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
+ - if ADC instance is master or if multimode feature is not available
+ - if multimode setting is disabled (ADC instance slave in independent mode) */
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ )
{
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
}
+#endif
/* Set ADC error code */
/* Check if a conversion is on going on ADC group injected */
- if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY))
+ if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) != 0UL)
{
/* Reset ADC error code fields related to regular conversions only */
CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR|HAL_ADC_ERROR_DMA));
@@ -1756,12 +1837,15 @@ HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
/* - if ADC is slave and dual regular conversions are enabled, ADC is */
/* enabled only (conversion is not started), */
/* - if ADC is master, ADC is enabled and conversion is started. */
- if(ADC_INDEPENDENT_OR_NONMULTIMODEREGULAR_SLAVE(hadc))
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
+ )
{
- /* Multimode feature is not available or ADC Instance is Independent or Master,
- or is not Slave ADC with dual regular conversions enabled.
- Then set HAL_ADC_STATE_INJ_BUSY and reset HAL_ADC_STATE_INJ_EOC if JAUTO is set. */
- if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != RESET)
+ /* ADC instance is not a multimode slave instance with multimode regular conversions enabled */
+ if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
{
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
@@ -1788,13 +1872,12 @@ HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
}
else
{
- /* hadc is the handle of a Slave ADC with dual regular conversions
- enabled. Therefore, ADC_CR_ADSTART is NOT set */
+ /* ADC instance is a multimode slave instance with multimode regular conversions enabled */
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
/* if Master ADC JAUTO bit is set, Slave injected interruptions
are enabled nevertheless (for same reason as above) */
- tmpADC_Master = ADC_MASTER_REGISTER(hadc);
- if (READ_BIT(tmpADC_Master->CFGR, ADC_CFGR_JAUTO) != RESET)
+ tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
+ if (READ_BIT(tmpADC_Master->CFGR, ADC_CFGR_JAUTO) != 0UL)
{
/* First, update Slave State in setting HAL_ADC_STATE_INJ_BUSY bit
and in resetting HAL_ADC_STATE_INJ_EOC bit */
@@ -1814,6 +1897,33 @@ HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
}
}
}
+#else
+ /* ADC instance is not a multimode slave instance with multimode regular conversions enabled */
+ if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
+ {
+ ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
+
+ /* Enable as well injected interruptions in case
+ HAL_ADCEx_InjectedStart_IT() has not been called beforehand. This
+ allows to start regular and injected conversions when JAUTO is
+ set with a single call to HAL_ADC_Start_IT() */
+ switch(hadc->Init.EOCSelection)
+ {
+ case ADC_EOC_SEQ_CONV:
+ __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
+ __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOS);
+ break;
+ /* case ADC_EOC_SINGLE_CONV */
+ default:
+ __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOS);
+ __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
+ break;
+ }
+ }
+
+ /* Start ADC group regular conversion */
+ LL_ADC_REG_StartConversion(hadc->Instance);
+#endif
}
else
{
@@ -1840,7 +1950,7 @@ HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1893,20 +2003,28 @@ HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
/* Perform ADC enable and conversion start if no conversion is on going */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* Process locked */
__HAL_LOCK(hadc);
- /* Ensure that dual regular conversions are not enabled or unavailable. */
+#if defined(ADC_MULTIMODE_SUPPORT)
+ /* Ensure that multimode regular conversions are not enabled. */
/* Otherwise, dedicated API HAL_ADCEx_MultiModeStart_DMA() must be used. */
- if (ADC_IS_DUAL_REGULAR_CONVERSION_ENABLE(hadc) == RESET)
+ if ( (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
+ )
+#endif
{
/* Enable the ADC peripheral */
tmp_hal_status = ADC_Enable(hadc);
@@ -1921,16 +2039,20 @@ HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, ui
HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP,
HAL_ADC_STATE_REG_BUSY);
+#if defined(ADC_MULTIMODE_SUPPORT)
/* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
- - by default if ADC is Master or Independent or if multimode feature is not available
- - if multimode setting is set to independent mode (no dual regular or injected conversions are configured) */
- if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
+ - if ADC instance is master or if multimode feature is not available
+ - if multimode setting is disabled (ADC instance slave in independent mode) */
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ )
{
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
}
+#endif
/* Check if a conversion is on going on ADC group injected */
- if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY))
+ if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) != 0UL)
{
/* Reset ADC error code fields related to regular conversions only */
CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA));
@@ -1973,7 +2095,7 @@ HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, ui
SET_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN);
/* Start the DMA channel */
- HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length);
+ tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length);
/* Enable conversion of regular group. */
/* If software start has been selected, conversion starts immediately. */
@@ -1987,13 +2109,16 @@ HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, ui
/* Process unlocked */
__HAL_UNLOCK(hadc);
}
+
}
+#if defined(ADC_MULTIMODE_SUPPORT)
else
{
tmp_hal_status = HAL_ERROR;
/* Process unlocked */
__HAL_UNLOCK(hadc);
}
+#endif
}
else
{
@@ -2019,7 +2144,7 @@ HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, ui
*/
HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -2038,28 +2163,31 @@ HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc)
/* Disable the DMA channel (in case of DMA in circular mode or stop */
/* while DMA transfer is on going) */
- tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
-
- /* Check if DMA channel effectively disabled */
- if (tmp_hal_status != HAL_OK)
+ if(hadc->DMA_Handle->State == HAL_DMA_STATE_BUSY)
{
- /* Update ADC state machine to error */
- SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
+ tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
+
+ /* Check if DMA channel effectively disabled */
+ if (tmp_hal_status != HAL_OK)
+ {
+ /* Update ADC state machine to error */
+ SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
+ }
}
/* Disable ADC overrun interrupt */
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
/* 2. Disable the ADC peripheral */
- /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep */
- /* in memory a potential failing status. */
+ /* Update "tmp_hal_status" only if DMA channel disabling passed, */
+ /* to keep in memory a potential failing status. */
if (tmp_hal_status == HAL_OK)
{
tmp_hal_status = ADC_Disable(hadc);
}
else
{
- ADC_Disable(hadc);
+ (void)ADC_Disable(hadc);
}
/* Check if ADC is effectively disabled */
@@ -2118,11 +2246,16 @@ uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
*/
void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
{
- uint32_t overrun_error = 0; /* flag set if overrun occurrence has to be considered as an error */
+ uint32_t overrun_error = 0UL; /* flag set if overrun occurrence has to be considered as an error */
uint32_t tmp_isr = hadc->Instance->ISR;
uint32_t tmp_ier = hadc->Instance->IER;
- uint32_t tmp_cfgr = 0x0;
- ADC_TypeDef *tmpADC_Master;
+ uint32_t tmp_adc_inj_is_trigger_source_sw_start;
+ uint32_t tmp_adc_reg_is_trigger_source_sw_start;
+ uint32_t tmp_cfgr;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ const ADC_TypeDef *tmpADC_Master;
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -2132,7 +2265,7 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
if(((tmp_isr & ADC_FLAG_EOSMP) == ADC_FLAG_EOSMP) && ((tmp_ier & ADC_IT_EOSMP) == ADC_IT_EOSMP))
{
/* Update state machine on end of sampling status if not in error state */
- if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL))
+ if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) == 0UL)
{
/* Set ADC state */
SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOSMP);
@@ -2154,7 +2287,7 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
(((tmp_isr & ADC_FLAG_EOS) == ADC_FLAG_EOS) && ((tmp_ier & ADC_IT_EOS) == ADC_IT_EOS)) )
{
/* Update state machine on conversion status if not in error state */
- if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL))
+ if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) == 0UL)
{
/* Set ADC state */
SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC);
@@ -2163,22 +2296,30 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
/* Determine whether any further conversion upcoming on group regular */
/* by external trigger, continuous mode or scan sequence on going */
/* to disable interruption. */
- if(ADC_IS_SOFTWARE_START_REGULAR(hadc))
+ if(LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance) != 0UL)
{
/* Get relevant register CFGR in ADC instance of ADC master or slave */
/* in function of multimode state (for devices with multimode */
/* available). */
- if (ADC_INDEPENDENT_OR_NONMULTIMODEREGULAR_SLAVE(hadc))
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
+ )
{
/* check CONT bit directly in handle ADC CFGR register */
- tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
}
else
{
/* else need to check Master ADC CONT bit */
- tmpADC_Master = ADC_MASTER_REGISTER(hadc);
- tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
+ tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
+ tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
}
+#else
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+#endif
/* Carry on if continuous mode is disabled */
if (READ_BIT (tmp_cfgr, ADC_CFGR_CONT) != ADC_CFGR_CONT)
@@ -2188,7 +2329,7 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
{
/* Allowed to modify bits ADC_IT_EOC/ADC_IT_EOS only if bit */
/* ADSTART==0 (no conversion on going) */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* Disable ADC end of sequence conversion interrupt */
/* Note: Overrun interrupt was enabled with EOC interrupt in */
@@ -2197,10 +2338,10 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC | ADC_IT_EOS);
/* Set ADC state */
- CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
+ CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
- if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY))
- {
+ if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) == 0UL)
+ {
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
}
}
@@ -2240,37 +2381,48 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
(((tmp_isr & ADC_FLAG_JEOS) == ADC_FLAG_JEOS) && ((tmp_ier & ADC_IT_JEOS) == ADC_IT_JEOS)) )
{
/* Update state machine on conversion status if not in error state */
- if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL))
+ if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) == 0UL)
{
/* Set ADC state */
SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC);
}
+ /* Retrieve ADC configuration */
+ tmp_adc_inj_is_trigger_source_sw_start = LL_ADC_INJ_IsTriggerSourceSWStart(hadc->Instance);
+ tmp_adc_reg_is_trigger_source_sw_start = LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance);
/* Get relevant register CFGR in ADC instance of ADC master or slave */
/* in function of multimode state (for devices with multimode */
/* available). */
- if (ADC_INDEPENDENT_OR_NONMULTIMODEINJECTED_SLAVE(hadc))
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
+ )
{
- tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
}
else
{
- tmpADC_Master = ADC_MASTER_REGISTER(hadc);
+ tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
}
+#else
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+#endif
/* Disable interruption if no further conversion upcoming by injected */
/* external trigger or by automatic injected conversion with regular */
/* group having no further conversion upcoming (same conditions as */
/* regular group interruption disabling above), */
/* and if injected scan sequence is completed. */
- if(ADC_IS_SOFTWARE_START_INJECTED(hadc) ||
- ((READ_BIT (tmp_cfgr, ADC_CFGR_JAUTO) == RESET) &&
- (ADC_IS_SOFTWARE_START_REGULAR(hadc) &&
- (READ_BIT (tmp_cfgr, ADC_CFGR_CONT) == RESET) ) ) )
+ if((tmp_adc_inj_is_trigger_source_sw_start != 0UL) ||
+ ((READ_BIT (tmp_cfgr, ADC_CFGR_JAUTO) == 0UL) &&
+ ((tmp_adc_reg_is_trigger_source_sw_start != 0UL) &&
+ (READ_BIT (tmp_cfgr, ADC_CFGR_CONT) == 0UL) ) ) )
{
/* If End of Sequence is reached, disable interrupts */
- if( __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS))
+ if(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS))
{
/* Particular case if injected contexts queue is enabled: */
/* when the last context has been fully processed, JSQR is reset */
@@ -2278,11 +2430,11 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
/* (queue empty, triggers are ignored), it can start again */
/* immediately after setting a new context (JADSTART is still set). */
/* Therefore, state of HAL ADC injected group is kept to busy. */
- if(READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == RESET)
+ if(READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == 0UL)
{
/* Allowed to modify bits ADC_IT_JEOC/ADC_IT_JEOS only if bit */
/* JADSTART==0 (no conversion on going) */
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc) == RESET)
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* Disable ADC end of sequence conversion interrupt */
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC | ADC_IT_JEOS);
@@ -2290,7 +2442,7 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
/* Set ADC state */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
- if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
+ if ((hadc->State & HAL_ADC_STATE_REG_BUSY) == 0UL)
{
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
}
@@ -2383,34 +2535,35 @@ void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
/* overrun ") */
/* Exception for usage with DMA overrun event always considered as an */
/* error. */
-
if (hadc->Init.Overrun == ADC_OVR_DATA_PRESERVED)
{
- overrun_error = 1;
+ overrun_error = 1UL;
}
else
{
/* Check DMA configuration */
- if (ADC_IS_DUAL_CONVERSION_ENABLE(hadc) == RESET)
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if (tmp_multimode_config != LL_ADC_MULTI_INDEPENDENT)
{
- /* Multimode not set or feature not available or ADC independent */
- if (HAL_IS_BIT_SET(hadc->Instance->CFGR, ADC_CFGR_DMAEN))
+ /* Multimode (when feature is available) is enabled,
+ Common Control Register MDMA bits must be checked. */
+ if (LL_ADC_GetMultiDMATransfer(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) != LL_ADC_MULTI_REG_DMA_EACH_ADC)
{
- overrun_error = 1;
+ overrun_error = 1UL;
}
}
else
+#endif
{
- /* Multimode (when feature is available) is enabled,
- Common Control Register MDMA bits must be checked. */
- if (ADC_MULTIMODE_DMA_ENABLED(hadc))
+ /* Multimode not set or feature not available or ADC independent */
+ if ((hadc->Instance->CFGR & ADC_CFGR_DMAEN) != 0UL)
{
- overrun_error = 1;
+ overrun_error = 1UL;
}
}
}
- if (overrun_error == 1)
+ if (overrun_error == 1UL)
{
/* Change ADC state to error state */
SET_BIT(hadc->State, HAL_ADC_STATE_REG_OVR);
@@ -2505,7 +2658,7 @@ __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
* @brief ADC error callback in non-blocking mode
* (ADC conversion with interruption or transfer by DMA).
* @note In case of error due to overrun when using ADC with DMA transfer
- * (HAL ADC handle paramater "ErrorCode" to state "HAL_ADC_ERROR_OVR"):
+ * (HAL ADC handle parameter "ErrorCode" to state "HAL_ADC_ERROR_OVR"):
* - Reinitialize the DMA using function "HAL_ADC_Stop_DMA()".
* - If needed, restart a new ADC conversion using function
* "HAL_ADC_Start_DMA()"
@@ -2563,7 +2716,10 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
{
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
uint32_t tmpOffsetShifted;
+ uint32_t tmp_config_internal_channel;
__IO uint32_t wait_loop_index = 0;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -2595,11 +2751,11 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
/* conversion on going on regular group: */
/* - Channel number */
/* - Channel rank */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
{
#if !defined (USE_FULL_ASSERT)
- /* Correspondance for compatibility with legacy definition of */
- /* sequencer ranks in direct number format. This correspondance can */
+ /* Correspondence for compatibility with legacy definition of */
+ /* sequencer ranks in direct number format. This correspondence can */
/* be done only on ranks 1 to 5 due to literal values. */
/* Note: Sequencer ranks in direct number format are no more used */
/* and are detected by activating USE_FULL_ASSERT feature. */
@@ -2612,7 +2768,7 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
case 4U: sConfig->Rank = ADC_REGULAR_RANK_4; break;
case 5U: sConfig->Rank = ADC_REGULAR_RANK_5; break;
/* case 1U */
- default: sConfig->Rank = ADC_REGULAR_RANK_1;
+ default: sConfig->Rank = ADC_REGULAR_RANK_1; break;
}
}
#endif
@@ -2625,7 +2781,11 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
/* conversion on going on regular group: */
/* - Channel sampling time */
/* - Channel offset */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET)
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+ if ( (tmp_adc_is_conversion_on_going_regular == 0UL)
+ && (tmp_adc_is_conversion_on_going_injected == 0UL)
+ )
{
#if defined(ADC_SMPR1_SMPPLUS)
/* Manage specific case of sampling time 3.5 cycles replacing 2.5 cyles */
@@ -2688,7 +2848,7 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
/* Parameters update conditioned to ADC state: */
/* Parameters that can be updated only when ADC is disabled: */
/* - Single or differential mode */
- if (ADC_IS_ENABLE(hadc) == RESET)
+ if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
{
/* Set mode single-ended or differential input of the selected ADC channel */
LL_ADC_SetChannelSingleDiff(hadc->Instance, sConfig->Channel, sConfig->SingleDiff);
@@ -2697,7 +2857,8 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
if (sConfig->SingleDiff == ADC_DIFFERENTIAL_ENDED)
{
/* Set sampling time of the selected ADC channel */
- LL_ADC_SetChannelSamplingTime(hadc->Instance, __LL_ADC_DECIMAL_NB_TO_CHANNEL(__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfig->Channel) + 1), sConfig->SamplingTime);
+ /* Note: ADC channel number masked with value "0x1F" to ensure shift value within 32 bits range */
+ LL_ADC_SetChannelSamplingTime(hadc->Instance, __LL_ADC_DECIMAL_NB_TO_CHANNEL((__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfig->Channel) + 1UL) & 0x1FUL), sConfig->SamplingTime);
}
}
@@ -2707,51 +2868,49 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
/* paths. */
/* Note: these internal measurement paths can be disabled using */
/* HAL_ADC_DeInit(). */
-
- /* Configuration of common ADC parameters */
- /* If the requested internal measurement path has already been enabled, */
- /* bypass the configuration processing. */
- if (( (sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) &&
- ((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0U)) ||
- ( (sConfig->Channel == ADC_CHANNEL_VBAT) &&
- ((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VBAT) == 0U)) ||
- ( (sConfig->Channel == ADC_CHANNEL_VREFINT) &&
- ((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VREFINT) == 0U))
- )
+
+ if(__LL_ADC_IS_CHANNEL_INTERNAL(sConfig->Channel))
{
- /* Configuration of common ADC parameters (continuation) */
-
- if (sConfig->Channel == ADC_CHANNEL_TEMPSENSOR)
+ tmp_config_internal_channel = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+
+ /* If the requested internal measurement path has already been enabled, */
+ /* bypass the configuration processing. */
+ if ((sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0UL))
{
if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc))
{
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)));
+ LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | tmp_config_internal_channel);
/* Delay for temperature sensor stabilization time */
/* Wait loop initialization and execution */
- /* Note: Variable divided by 2 to compensate partially */
- /* CPU processing cycles. */
- wait_loop_index = (LL_ADC_DELAY_TEMPSENSOR_STAB_US * (SystemCoreClock / (1000000 * 2)));
- while(wait_loop_index != 0)
+ /* Note: Variable divided by 2 to compensate partially */
+ /* CPU processing cycles, scaling in us split to not */
+ /* exceed 32 bits register capacity and handle low frequency. */
+ wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
+ while(wait_loop_index != 0UL)
{
wait_loop_index--;
}
}
}
- else if (sConfig->Channel == ADC_CHANNEL_VBAT)
+ else if ((sConfig->Channel == ADC_CHANNEL_VBAT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VBAT) == 0UL))
{
if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc))
{
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)));
+ LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | tmp_config_internal_channel);
}
}
- else if (sConfig->Channel == ADC_CHANNEL_VREFINT)
+ else if ((sConfig->Channel == ADC_CHANNEL_VREFINT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VREFINT) == 0UL))
{
if (ADC_VREFINT_INSTANCE(hadc))
{
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)));
+ LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | tmp_config_internal_channel);
}
}
+ else
+ {
+ /* nothing to do */
+ }
}
}
@@ -2792,8 +2951,10 @@ HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConf
HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)
{
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
- uint32_t tmpAWDHighThresholdShifted = 0U;
- uint32_t tmpAWDLowThresholdShifted = 0U;
+ uint32_t tmpAWDHighThresholdShifted;
+ uint32_t tmpAWDLowThresholdShifted;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -2807,11 +2968,23 @@ HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDG
{
assert_param(IS_ADC_CHANNEL(hadc, AnalogWDGConfig->Channel));
}
-
- /* Verify if threshold is within the selected ADC resolution */
- assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->HighThreshold));
- assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->LowThreshold));
-
+
+ /* Verify thresholds range */
+ if (hadc->Init.OversamplingMode == ENABLE)
+ {
+ /* Case of oversampling enabled: depending on ratio and shift configuration,
+ analog watchdog thresholds can be higher than ADC resolution.
+ Verify if thresholds are within maximum thresholds range. */
+ assert_param(IS_ADC_RANGE(ADC_RESOLUTION_12B, AnalogWDGConfig->HighThreshold));
+ assert_param(IS_ADC_RANGE(ADC_RESOLUTION_12B, AnalogWDGConfig->LowThreshold));
+ }
+ else
+ {
+ /* Verify if thresholds are within the selected ADC resolution */
+ assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->HighThreshold));
+ assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->LowThreshold));
+ }
+
/* Process locked */
__HAL_LOCK(hadc);
@@ -2820,7 +2993,11 @@ HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDG
/* conversion on going on ADC groups regular and injected: */
/* - Analog watchdog channels */
/* - Analog watchdog thresholds */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET)
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+ if ( (tmp_adc_is_conversion_on_going_regular == 0UL)
+ && (tmp_adc_is_conversion_on_going_injected == 0UL)
+ )
{
/* Analog watchdog configuration */
if(AnalogWDGConfig->WatchdogNumber == ADC_ANALOGWATCHDOG_1)
@@ -2899,11 +3076,11 @@ HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDG
/* several channels by successive calls of this function. */
if (AnalogWDGConfig->WatchdogNumber == ADC_ANALOGWATCHDOG_2)
{
- SET_BIT(hadc->Instance->AWD2CR, (1U << __LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDGConfig->Channel)));
+ SET_BIT(hadc->Instance->AWD2CR, (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDGConfig->Channel) & 0x1FUL)));
}
else
{
- SET_BIT(hadc->Instance->AWD3CR, (1U << __LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDGConfig->Channel)));
+ SET_BIT(hadc->Instance->AWD3CR, (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDGConfig->Channel) & 0x1FUL)));
}
break;
@@ -3015,8 +3192,8 @@ HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDG
* @note ADC state machine is managed by bitfields, ADC status must be
* compared with states bits.
* For example:
- * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
- * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) "
+ * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_REG_BUSY) != 0UL) "
+ * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD1) != 0UL) "
* @param hadc ADC handle
* @retval ADC handle state (bitfield on 32 bits)
*/
@@ -3066,17 +3243,24 @@ uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
*/
HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t ConversionGroup)
{
- uint32_t tmp_ADC_CR_ADSTART_JADSTART = 0;
- uint32_t tickstart = 0;
- uint32_t Conversion_Timeout_CPU_cycles = 0;
-
+ uint32_t tickstart;
+ uint32_t Conversion_Timeout_CPU_cycles = 0UL;
+ uint32_t conversion_group_reassigned = ConversionGroup;
+ uint32_t tmp_ADC_CR_ADSTART_JADSTART;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
+
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
assert_param(IS_ADC_CONVERSION_GROUP(ConversionGroup));
-
+
/* Verification if ADC is not already stopped (on regular and injected */
/* groups) to bypass this function if not needed. */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc))
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+ if ( (tmp_adc_is_conversion_on_going_regular != 0UL)
+ || (tmp_adc_is_conversion_on_going_injected != 0UL)
+ )
{
/* Particular case of continuous auto-injection mode combined with */
/* auto-delay mode. */
@@ -3084,17 +3268,18 @@ HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t Conversio
/* injected group stop ADC_CR_JADSTP). */
/* Procedure to be followed: Wait until JEOS=1, clear JEOS, set ADSTP=1 */
/* (see reference manual). */
- if ((HAL_IS_BIT_SET(hadc->Instance->CFGR, ADC_CFGR_JAUTO))
- && (hadc->Init.ContinuousConvMode==ENABLE)
- && (hadc->Init.LowPowerAutoWait==ENABLE))
+ if ( ((hadc->Instance->CFGR & ADC_CFGR_JAUTO) != 0UL)
+ && (hadc->Init.ContinuousConvMode == ENABLE)
+ && (hadc->Init.LowPowerAutoWait == ENABLE)
+ )
{
/* Use stop of regular group */
- ConversionGroup = ADC_REGULAR_GROUP;
+ conversion_group_reassigned = ADC_REGULAR_GROUP;
/* Wait until JEOS=1 (maximum Timeout: 4 injected conversions) */
- while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS) == RESET)
+ while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS) == 0UL)
{
- if (Conversion_Timeout_CPU_cycles >= (ADC_CONVERSION_TIME_MAX_CPU_CYCLES *4))
+ if (Conversion_Timeout_CPU_cycles >= (ADC_CONVERSION_TIME_MAX_CPU_CYCLES * 4UL))
{
/* Update ADC state machine to error */
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
@@ -3111,32 +3296,36 @@ HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t Conversio
__HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOS);
}
- /* Stop potential conversion on going on regular group */
- if (ConversionGroup != ADC_INJECTED_GROUP)
+ /* Stop potential conversion on going on ADC group regular */
+ if (conversion_group_reassigned != ADC_INJECTED_GROUP)
{
/* Software is allowed to set ADSTP only when ADSTART=1 and ADDIS=0 */
- if (HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADSTART) &&
- HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADDIS) )
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL)
{
- /* Stop conversions on regular group */
- LL_ADC_REG_StopConversion(hadc->Instance);
+ if (LL_ADC_IsDisableOngoing(hadc->Instance) == 0UL)
+ {
+ /* Stop ADC group regular conversion */
+ LL_ADC_REG_StopConversion(hadc->Instance);
+ }
}
}
- /* Stop potential conversion on going on injected group */
- if (ConversionGroup != ADC_REGULAR_GROUP)
+ /* Stop potential conversion on going on ADC group injected */
+ if (conversion_group_reassigned != ADC_REGULAR_GROUP)
{
/* Software is allowed to set JADSTP only when JADSTART=1 and ADDIS=0 */
- if (HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_JADSTART) &&
- HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADDIS) )
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL)
{
- /* Stop conversions on injected group */
- SET_BIT(hadc->Instance->CR, ADC_CR_JADSTP);
- }
+ if (LL_ADC_IsDisableOngoing(hadc->Instance) == 0UL)
+ {
+ /* Stop ADC group injected conversion */
+ LL_ADC_INJ_StopConversion(hadc->Instance);
+ }
+ }
}
/* Selection of start and stop bits with respect to the regular or injected group */
- switch(ConversionGroup)
+ switch(conversion_group_reassigned)
{
case ADC_REGULAR_INJECTED_GROUP:
tmp_ADC_CR_ADSTART_JADSTART = (ADC_CR_ADSTART | ADC_CR_JADSTART);
@@ -3151,11 +3340,9 @@ HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t Conversio
}
/* Wait for conversion effectively stopped */
-
-
tickstart = HAL_GetTick();
- while((hadc->Instance->CR & tmp_ADC_CR_ADSTART_JADSTART) != RESET)
+ while((hadc->Instance->CR & tmp_ADC_CR_ADSTART_JADSTART) != 0UL)
{
if((HAL_GetTick()-tickstart) > ADC_STOP_CONVERSION_TIMEOUT)
{
@@ -3186,17 +3373,16 @@ HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t Conversio
*/
HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc)
{
- uint32_t tickstart = 0;
- __IO uint32_t wait_loop_index = 0;
+ uint32_t tickstart;
/* ADC enable and wait for ADC ready (in case of ADC is disabled or */
/* enabling phase not yet completed: flag ADC ready not yet set). */
/* Timeout implemented to not be stuck if ADC cannot be enabled (possible */
/* causes: ADC clock not running, ...). */
- if (ADC_IS_ENABLE(hadc) == RESET)
+ if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
{
/* Check if conditions to enable the ADC are fulfilled */
- if (ADC_ENABLING_CONDITIONS(hadc) == RESET)
+ if ((hadc->Instance->CR & (ADC_CR_ADCAL | ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | ADC_CR_ADSTART | ADC_CR_ADDIS | ADC_CR_ADEN)) != 0UL)
{
/* Update ADC state machine to error */
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
@@ -3210,20 +3396,10 @@ HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc)
/* Enable the ADC peripheral */
LL_ADC_Enable(hadc->Instance);
- /* Delay for ADC stabilization time */
- /* Wait loop initialization and execution */
- /* Note: Variable divided by 2 to compensate partially */
- /* CPU processing cycles. */
- wait_loop_index = (LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (1000000 * 2)));
- while(wait_loop_index != 0)
- {
- wait_loop_index--;
- }
-
/* Wait for ADC effectively enabled */
tickstart = HAL_GetTick();
- while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_RDY) == RESET)
+ while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_RDY) == 0UL)
{
/* If ADEN bit is set less than 4 ADC clock cycles after the ADCAL bit
has been cleared (after a calibration), ADEN bit is reset by the
@@ -3233,7 +3409,7 @@ HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc)
4 ADC clock cycle duration */
/* Note: Test of ADC enabled required due to hardware constraint to */
/* not enable ADC if already enabled. */
- if(LL_ADC_IsEnabled(hadc->Instance) == 0)
+ if(LL_ADC_IsEnabled(hadc->Instance) == 0UL)
{
LL_ADC_Enable(hadc->Instance);
}
@@ -3264,15 +3440,18 @@ HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef* hadc)
{
- uint32_t tickstart = 0;
+ uint32_t tickstart;
+ const uint32_t tmp_adc_is_disable_on_going = LL_ADC_IsDisableOngoing(hadc->Instance);
/* Verification if ADC is not already disabled: */
/* Note: forbidden to disable ADC (set bit ADC_CR_ADDIS) if ADC is already */
/* disabled. */
- if (ADC_IS_ENABLE(hadc) != RESET)
+ if ( (LL_ADC_IsEnabled(hadc->Instance) != 0UL)
+ && (tmp_adc_is_disable_on_going == 0UL)
+ )
{
/* Check if conditions to disable the ADC are fulfilled */
- if (ADC_DISABLING_CONDITIONS(hadc) != RESET)
+ if((hadc->Instance->CR & (ADC_CR_JADSTART | ADC_CR_ADSTART | ADC_CR_ADEN)) == ADC_CR_ADEN)
{
/* Disable the ADC peripheral */
LL_ADC_Disable(hadc->Instance);
@@ -3288,12 +3467,12 @@ HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef* hadc)
return HAL_ERROR;
}
-
+
/* Wait for ADC effectively disabled */
/* Get tick count */
tickstart = HAL_GetTick();
- while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADEN))
+ while((hadc->Instance->CR & ADC_CR_ADEN) != 0UL)
{
if((HAL_GetTick() - tickstart) > ADC_DISABLE_TIMEOUT)
{
@@ -3323,7 +3502,7 @@ void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma)
ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
/* Update state machine on conversion status if not in error state */
- if(HAL_IS_BIT_CLR(hadc->State, (HAL_ADC_STATE_ERROR_INTERNAL | HAL_ADC_STATE_ERROR_DMA)))
+ if((hadc->State & (HAL_ADC_STATE_ERROR_INTERNAL | HAL_ADC_STATE_ERROR_DMA)) == 0UL)
{
/* Set ADC state */
SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC);
@@ -3332,17 +3511,17 @@ void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma)
/* by external trigger, continuous mode or scan sequence on going */
/* to disable interruption. */
/* Is it the end of the regular sequence ? */
- if(HAL_IS_BIT_SET(hadc->Instance->ISR, ADC_FLAG_EOS))
+ if ((hadc->Instance->ISR & ADC_FLAG_EOS) != 0UL)
{
/* Are conversions software-triggered ? */
- if(ADC_IS_SOFTWARE_START_REGULAR(hadc))
+ if(LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance) != 0UL)
{
/* Is CONT bit set ? */
- if(READ_BIT(hadc->Instance->CFGR, ADC_CFGR_CONT) == RESET)
+ if(READ_BIT(hadc->Instance->CFGR, ADC_CFGR_CONT) == 0UL)
{
/* CONT bit is not set, no more conversions expected */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
- if(HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY))
+ if((hadc->State & HAL_ADC_STATE_INJ_BUSY) == 0UL)
{
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
}
@@ -3353,11 +3532,11 @@ void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma)
{
/* DMA End of Transfer interrupt was triggered but conversions sequence
is not over. If DMACFG is set to 0, conversions are stopped. */
- if(READ_BIT(hadc->Instance->CFGR, ADC_CFGR_DMACFG) == RESET)
+ if(READ_BIT(hadc->Instance->CFGR, ADC_CFGR_DMACFG) == 0UL)
{
/* DMACFG bit is not set, conversions are stopped. */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
- if(HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY))
+ if((hadc->State & HAL_ADC_STATE_INJ_BUSY) == 0UL)
{
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
}
@@ -3373,7 +3552,7 @@ void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma)
}
else /* DMA and-or internal error occurred */
{
- if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL))
+ if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) != 0UL)
{
/* Call HAL ADC Error Callback function */
#if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
@@ -3402,7 +3581,7 @@ void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma)
/* Half conversion callback */
#if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
- hadc->ConvHalfCpltCallback(hadc);
+ hadc->ConvHalfCpltCallback(hadc);
#else
HAL_ADC_ConvHalfCpltCallback(hadc);
#endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c
index f1baf9b8da..830351536a 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c
@@ -76,10 +76,10 @@
* @{
*/
-#define ADC_JSQR_FIELDS ((uint32_t)(ADC_JSQR_JL | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN |\
- ADC_JSQR_JSQ1 | ADC_JSQR_JSQ2 |\
- ADC_JSQR_JSQ3 | ADC_JSQR_JSQ4 )) /*!< ADC_JSQR fields of parameters that can be updated anytime
- once the ADC is enabled */
+#define ADC_JSQR_FIELDS ((ADC_JSQR_JL | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN |\
+ ADC_JSQR_JSQ1 | ADC_JSQR_JSQ2 |\
+ ADC_JSQR_JSQ3 | ADC_JSQR_JSQ4 )) /*!< ADC_JSQR fields of parameters that can be updated anytime
+ once the ADC is enabled */
/* Fixed timeout value for ADC calibration. */
/* Values defined to be higher than worst cases: maximum ratio between ADC */
@@ -88,8 +88,8 @@
/* source PLL SAI 8MHz, ADC clock prescaler 256), CPU frequency 80MHz. */
/* Calibration time max = 116 / fADC (refer to datasheet) */
/* = 296 960 CPU cycles */
-#define ADC_CALIBRATION_TIMEOUT (296960U) /*!< ADC calibration time-out value (unit: CPU cycles) */
-
+#define ADC_CALIBRATION_TIMEOUT (296960UL) /*!< ADC calibration time-out value (unit: CPU cycles) */
+
/**
* @}
*/
@@ -144,8 +144,8 @@
*/
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc, uint32_t SingleDiff)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
- uint32_t WaitLoopIndex = 0;
+ HAL_StatusTypeDef tmp_hal_status;
+ __IO uint32_t wait_loop_index = 0UL;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -176,10 +176,10 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc, uint32_t
SET_BIT(hadc->Instance->CR, ADC_CR_ADCAL);
/* Wait for calibration completion */
- while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADCAL))
+ while(LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
{
- WaitLoopIndex++;
- if (WaitLoopIndex >= ADC_CALIBRATION_TIMEOUT)
+ wait_loop_index++;
+ if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)
{
/* Update ADC state machine to error */
ADC_STATE_CLR_SET(hadc->State,
@@ -228,14 +228,7 @@ uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef* hadc, uint32_t Single
assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
/* Return the selected ADC calibration value */
- if (SingleDiff == ADC_DIFFERENTIAL_ENDED)
- {
- return ADC_CALFACT_DIFF_GET(hadc->Instance->CALFACT);
- }
- else
- {
- return ((hadc->Instance->CALFACT) & ADC_CALFACT_CALFACT_S);
- }
+ return LL_ADC_GetCalibrationFactor(hadc->Instance, SingleDiff);
}
/**
@@ -251,29 +244,29 @@ uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef* hadc, uint32_t Single
HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef* hadc, uint32_t SingleDiff, uint32_t CalibrationFactor)
{
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
- assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
- assert_param(IS_ADC_CALFACT(CalibrationFactor));
+ assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
+ assert_param(IS_ADC_CALFACT(CalibrationFactor));
/* Process locked */
__HAL_LOCK(hadc);
/* Verification of hardware constraints before modifying the calibration */
/* factors register: ADC must be enabled, no conversion on going. */
- if ( (ADC_IS_ENABLE(hadc) != RESET) &&
- (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET) )
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+
+ if ( (LL_ADC_IsEnabled(hadc->Instance) != 0UL)
+ && (tmp_adc_is_conversion_on_going_regular == 0UL)
+ && (tmp_adc_is_conversion_on_going_injected == 0UL)
+ )
{
/* Set the selected ADC calibration value */
- if (SingleDiff == ADC_DIFFERENTIAL_ENDED)
- {
- MODIFY_REG(hadc->Instance->CALFACT, ADC_CALFACT_CALFACT_D, ADC_CALFACT_DIFF_SET(CalibrationFactor));
- }
- else
- {
- MODIFY_REG(hadc->Instance->CALFACT, ADC_CALFACT_CALFACT_S, CalibrationFactor);
- }
+ LL_ADC_SetCalibrationFactor(hadc->Instance, SingleDiff, CalibrationFactor);
}
else
{
@@ -306,18 +299,21 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef* hadc, uint32
*/
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
+ uint32_t tmp_config_injected_queue;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc))
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL)
{
return HAL_BUSY;
}
else
{
-
/* In case of software trigger detection enabled, JQDIS must be set
(which can be done only if ADSTART and JADSTART are both cleared).
If JQDIS is not set at that point, returns an error
@@ -325,13 +321,15 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS.
- or (if JQDIS is intentionally reset) since JEXTEN = 0 which means
the queue is empty */
- if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == RESET)
- && (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS) == RESET))
+ tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
+
+ if ( (READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL)
+ && (tmp_config_injected_queue == 0UL)
+ )
{
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
return HAL_ERROR;
}
-
/* Process locked */
__HAL_LOCK(hadc);
@@ -343,10 +341,10 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
if (tmp_hal_status == HAL_OK)
{
/* Check if a regular conversion is ongoing */
- if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_REG_BUSY))
+ if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL)
{
/* Reset ADC error code field related to injected conversions only */
- CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
+ CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
}
else
{
@@ -361,13 +359,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
HAL_ADC_STATE_INJ_BUSY);
+#if defined(ADC_MULTIMODE_SUPPORT)
/* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
- - by default if ADC is Master or Independent or if multimode feature is not available
- - if multimode setting is set to independent mode (no dual regular or injected conversions are configured) */
- if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
+ - if ADC instance is master or if multimode feature is not available
+ - if multimode setting is disabled (ADC instance slave in independent mode) */
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ )
{
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
}
+#endif
/* Clear ADC group injected group conversion flag */
/* (To ensure of no unknown state from potential previous ADC operations) */
@@ -385,28 +387,37 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
/* trigger event. */
/* Case of multimode enabled (when multimode feature is available): */
/* if ADC is slave, */
- /* - ADC is enabled only (conversion is not started). */
+ /* - ADC is enabled only (conversion is not started), */
/* - if multimode only concerns regular conversion, ADC is enabled */
/* and conversion is started. */
/* If ADC is master or independent, */
/* - ADC is enabled and conversion is started. */
-
- /* Are injected conversions that of a dual Slave ? */
- if (ADC_INDEPENDENT_OR_NONMULTIMODEINJECTED_SLAVE(hadc))
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
+ )
{
- /* hadc is not the handle of a Slave ADC with dual injected conversions enabled:
- set ADSTART only if JAUTO is cleared */
- if (HAL_IS_BIT_CLR(hadc->Instance->CFGR, ADC_CFGR_JAUTO))
+ /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
+ if(LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
{
- SET_BIT(hadc->Instance->CR, ADC_CR_JADSTART) ;
+ LL_ADC_INJ_StartConversion(hadc->Instance);
}
}
else
{
- /* hadc is the handle of a Slave ADC with dual injected conversions enabled:
- ADSTART is not set */
- SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
+ /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
+ SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
+ }
+#else
+ if(LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
+ {
+ /* Start ADC group injected conversion */
+ LL_ADC_INJ_StartConversion(hadc->Instance);
}
+#endif
+
}
else
{
@@ -437,7 +448,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -452,7 +463,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
/* and if no conversion on regular group is on-going */
if (tmp_hal_status == HAL_OK)
{
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* 2. Disable the ADC peripheral */
tmp_hal_status = ADC_Disable(hadc);
@@ -492,10 +503,15 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
{
- uint32_t tickstart = 0U;
- uint32_t tmp_Flag_End = 0U;
- uint32_t tmp_cfgr = 0U;
- ADC_TypeDef *tmpADC_Master;
+ uint32_t tickstart;
+ uint32_t tmp_Flag_End;
+ uint32_t tmp_adc_inj_is_trigger_source_sw_start;
+ uint32_t tmp_adc_reg_is_trigger_source_sw_start;
+ uint32_t tmp_cfgr;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ const ADC_TypeDef *tmpADC_Master;
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -511,15 +527,15 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
}
/* Get timeout */
- tickstart = HAL_GetTick();
+ tickstart = HAL_GetTick();
/* Wait until End of Conversion or Sequence flag is raised */
- while(HAL_IS_BIT_CLR(hadc->Instance->ISR, tmp_Flag_End))
+ while((hadc->Instance->ISR & tmp_Flag_End) == 0UL)
{
/* Check if timeout is disabled (set to infinite wait) */
if(Timeout != HAL_MAX_DELAY)
{
- if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
+ if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
{
/* Update ADC state machine to timeout */
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
@@ -532,18 +548,29 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
}
}
+ /* Retrieve ADC configuration */
+ tmp_adc_inj_is_trigger_source_sw_start = LL_ADC_INJ_IsTriggerSourceSWStart(hadc->Instance);
+ tmp_adc_reg_is_trigger_source_sw_start = LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance);
/* Get relevant register CFGR in ADC instance of ADC master or slave */
/* in function of multimode state (for devices with multimode */
/* available). */
- if (ADC_INDEPENDENT_OR_NONMULTIMODEINJECTED_SLAVE(hadc) == SET)
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
+ )
{
- tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
}
else
{
- tmpADC_Master = ADC_MASTER_REGISTER(hadc);
- tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
+ tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
+ tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
}
+#else
+ tmp_cfgr = READ_REG(hadc->Instance->CFGR);
+#endif
/* Update ADC state machine */
SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC);
@@ -551,10 +578,10 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
/* Determine whether any further conversion upcoming on group injected */
/* by external trigger or by automatic injected conversion */
/* from group regular. */
- if(ADC_IS_SOFTWARE_START_INJECTED(hadc) ||
- ((READ_BIT (tmp_cfgr, ADC_CFGR_JAUTO) == RESET) &&
- (ADC_IS_SOFTWARE_START_REGULAR(hadc) &&
- (READ_BIT (tmp_cfgr, ADC_CFGR_CONT) == RESET) ) ) )
+ if((tmp_adc_inj_is_trigger_source_sw_start != 0UL) ||
+ ((READ_BIT (tmp_cfgr, ADC_CFGR_JAUTO) == 0UL) &&
+ ((tmp_adc_reg_is_trigger_source_sw_start != 0UL) &&
+ (READ_BIT (tmp_cfgr, ADC_CFGR_CONT) == 0UL) ) ) )
{
/* Check whether end of sequence is reached */
if( __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS) )
@@ -565,12 +592,12 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
/* (queue empty, triggers are ignored), it can start again */
/* immediately after setting a new context (JADSTART is still set). */
/* Therefore, state of HAL ADC injected group is kept to busy. */
- if(READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == RESET)
+ if(READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == 0UL)
{
/* Set ADC state */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
- if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
+ if((hadc->State & HAL_ADC_STATE_REG_BUSY) == 0UL)
{
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
}
@@ -585,7 +612,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
/* "LowPowerAutoWait " is disabled, to not interfere with this feature. */
/* For injected groups, no new conversion will start before JEOS is */
/* cleared. */
- if (READ_BIT (tmp_cfgr, ADC_CFGR_AUTDLY) == RESET)
+ if (READ_BIT (tmp_cfgr, ADC_CFGR_AUTDLY) == 0UL)
{
__HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
}
@@ -613,12 +640,16 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
*/
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
+ uint32_t tmp_config_injected_queue;
+#if defined(ADC_MULTIMODE_SUPPORT)
+ uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+#endif
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc))
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL)
{
return HAL_BUSY;
}
@@ -631,8 +662,11 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS.
- or (if JQDIS is intentionally reset) since JEXTEN = 0 which means
the queue is empty */
- if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == RESET)
- && (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS) == RESET))
+ tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
+
+ if ( (READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL)
+ && (tmp_config_injected_queue == 0UL)
+ )
{
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
return HAL_ERROR;
@@ -648,7 +682,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
if (tmp_hal_status == HAL_OK)
{
/* Check if a regular conversion is ongoing */
- if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_REG_BUSY))
+ if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL)
{
/* Reset ADC error code field related to injected conversions only */
CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
@@ -666,14 +700,18 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
HAL_ADC_STATE_INJ_BUSY);
+#if defined(ADC_MULTIMODE_SUPPORT)
/* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
- - by default if ADC is Master or Independent or if multimode feature is not available
- - if multimode setting is set to independent mode (no dual regular or injected conversions are configured) */
- if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
+ - if ADC instance is master or if multimode feature is not available
+ - if multimode setting is disabled (ADC instance slave in independent mode) */
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ )
{
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
}
-
+#endif
+
/* Clear ADC group injected group conversion flag */
/* (To ensure of no unknown state from potential previous ADC operations) */
__HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
@@ -685,7 +723,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
/* Enable ADC Injected context queue overflow interrupt if this feature */
/* is enabled. */
- if ((hadc->Instance->CFGR & ADC_CFGR_JQM) != RESET)
+ if ((hadc->Instance->CFGR & ADC_CFGR_JQM) != 0UL)
{
__HAL_ADC_ENABLE_IT(hadc, ADC_FLAG_JQOVF);
}
@@ -716,23 +754,32 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
/* and conversion is started. */
/* If ADC is master or independent, */
/* - ADC is enabled and conversion is started. */
-
- /* Are injected conversions that of a dual Slave ? */
- if (ADC_INDEPENDENT_OR_NONMULTIMODEINJECTED_SLAVE(hadc))
+#if defined(ADC_MULTIMODE_SUPPORT)
+ if ( (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
+ || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
+ || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
+ )
{
- /* hadc is not the handle of a Slave ADC with dual injected conversions enabled:
- set ADSTART only if JAUTO is cleared */
- if (HAL_IS_BIT_CLR(hadc->Instance->CFGR, ADC_CFGR_JAUTO))
+ /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
+ if(LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
{
- SET_BIT(hadc->Instance->CR, ADC_CR_JADSTART) ;
+ LL_ADC_INJ_StartConversion(hadc->Instance);
}
}
else
{
- /* hadc is the handle of a Slave ADC with dual injected conversions enabled:
- ADSTART is not set */
- SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
+ /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
+ SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
+ }
+#else
+ if(LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
+ {
+ /* Start ADC group injected conversion */
+ LL_ADC_INJ_StartConversion(hadc->Instance);
}
+#endif
+
}
else
{
@@ -766,7 +813,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -785,7 +832,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
/* Disable ADC end of conversion interrupt for injected channels */
__HAL_ADC_DISABLE_IT(hadc, (ADC_IT_JEOC | ADC_IT_JEOS | ADC_FLAG_JQOVF));
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* 2. Disable the ADC peripheral */
tmp_hal_status = ADC_Disable(hadc);
@@ -833,7 +880,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
ADC_HandleTypeDef tmphadcSlave;
ADC_Common_TypeDef *tmpADC_Common;
@@ -843,7 +890,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
assert_param(IS_ADC_EXTTRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests));
- if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc))
+ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL)
{
return HAL_BUSY;
}
@@ -913,7 +960,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
__HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
/* Start the DMA channel */
- HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&tmpADC_Common->CDR, (uint32_t)pData, Length);
+ tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&tmpADC_Common->CDR, (uint32_t)pData, Length);
/* Enable conversion of regular group. */
/* If software start has been selected, conversion starts immediately. */
@@ -948,9 +995,11 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
*/
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
uint32_t tickstart;
ADC_HandleTypeDef tmphadcSlave;
+ uint32_t tmphadcSlave_conversion_on_going;
+ HAL_StatusTypeDef tmphadcSlave_disable_status;
/* Check the parameters */
assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
@@ -982,11 +1031,13 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
/* Procedure to disable the ADC peripheral: wait for conversions */
/* effectively stopped (ADC master and ADC slave), then disable ADC */
- /* 1. Wait until ADSTP=0 for ADC master and ADC slave*/
+ /* 1. Wait for ADC conversion completion for ADC master and ADC slave */
tickstart = HAL_GetTick();
- while(ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) ||
- ADC_IS_CONVERSION_ONGOING_REGULAR(&tmphadcSlave) )
+ tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
+ while( (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
+ || (tmphadcSlave_conversion_on_going == 1UL)
+ )
{
if((HAL_GetTick()-tickstart) > ADC_STOP_CONVERSION_TIMEOUT)
{
@@ -998,6 +1049,8 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
return HAL_ERROR;
}
+
+ tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
}
/* Disable the DMA channel (in case of DMA in circular mode or stop */
@@ -1021,17 +1074,18 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
/* memory a potential failing status. */
if (tmp_hal_status == HAL_OK)
{
- /* Check if ADC are effectively disabled */
- if ((ADC_Disable(hadc) == HAL_OK) &&
- (ADC_Disable(&tmphadcSlave) == HAL_OK) )
+ tmphadcSlave_disable_status = ADC_Disable(&tmphadcSlave);
+ if ((ADC_Disable(hadc) == HAL_OK) &&
+ (tmphadcSlave_disable_status == HAL_OK) )
{
tmp_hal_status = HAL_OK;
}
}
else
{
- ADC_Disable(hadc);
- ADC_Disable(&tmphadcSlave);
+ /* In case of error, attempt to disable ADC master and slave without status assert */
+ (void) ADC_Disable(hadc);
+ (void) ADC_Disable(&tmphadcSlave);
}
/* Set ADC state (ADC master) */
@@ -1054,7 +1108,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
*/
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
{
- ADC_Common_TypeDef *tmpADC_Common;
+ const ADC_Common_TypeDef *tmpADC_Common;
/* Check the parameters */
assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
@@ -1101,7 +1155,7 @@ uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
*/
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank)
{
- uint32_t tmp_jdr = 0;
+ uint32_t tmp_jdr;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1218,7 +1272,7 @@ __weak void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_RegularStop(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1236,7 +1290,7 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop(ADC_HandleTypeDef* hadc)
/* Clear HAL_ADC_STATE_REG_BUSY bit */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc) == RESET)
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* 2. Disable the ADC peripheral */
tmp_hal_status = ADC_Disable(hadc);
@@ -1276,7 +1330,7 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_RegularStop_IT(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1298,7 +1352,7 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop_IT(ADC_HandleTypeDef* hadc)
__HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR));
/* 2. Disable ADC peripheral if no injected conversions are on-going */
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc) == RESET)
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
{
tmp_hal_status = ADC_Disable(hadc);
/* if no issue reported */
@@ -1336,7 +1390,7 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop_IT(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
@@ -1351,7 +1405,7 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef* hadc)
and if no injected conversion is on-going */
if (tmp_hal_status == HAL_OK)
{
- /* Clear HAL_ADC_STATE_REG_BUSY bit */
+ /* Clear HAL_ADC_STATE_REG_BUSY bit */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
/* Disable ADC DMA (ADC DMA configuration ADC_CFGR_DMACFG is kept) */
@@ -1359,30 +1413,30 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef* hadc)
/* Disable the DMA channel (in case of DMA in circular mode or stop while */
/* while DMA transfer is on going) */
- tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
+ tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
/* Check if DMA channel effectively disabled */
if (tmp_hal_status != HAL_OK)
{
/* Update ADC state machine to error */
- SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
+ SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
}
/* Disable ADC overrun interrupt */
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
/* 2. Disable the ADC peripheral */
- /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep in */
- /* memory a potential failing status. */
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc) == RESET)
- {
+ /* Update "tmp_hal_status" only if DMA channel disabling passed, */
+ /* to keep in memory a potential failing status. */
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
+ {
if (tmp_hal_status == HAL_OK)
{
tmp_hal_status = ADC_Disable(hadc);
}
else
{
- ADC_Disable(hadc);
+ (void)ADC_Disable(hadc);
}
/* Check if ADC is effectively disabled */
@@ -1396,7 +1450,7 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef* hadc)
}
else
{
- SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
+ SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
}
}
@@ -1423,9 +1477,10 @@ HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef* hadc)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status;
uint32_t tickstart;
ADC_HandleTypeDef tmphadcSlave;
+ uint32_t tmphadcSlave_conversion_on_going;
/* Check the parameters */
assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
@@ -1460,11 +1515,13 @@ HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef* hadc)
/* Procedure to disable the ADC peripheral: wait for conversions */
/* effectively stopped (ADC master and ADC slave), then disable ADC */
- /* 1. Wait until ADSTP=0 for ADC master and ADC slave*/
+ /* 1. Wait for ADC conversion completion for ADC master and ADC slave */
tickstart = HAL_GetTick();
- while(ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) ||
- ADC_IS_CONVERSION_ONGOING_REGULAR(&tmphadcSlave) )
+ tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
+ while( (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
+ || (tmphadcSlave_conversion_on_going == 1UL)
+ )
{
if((HAL_GetTick()-tickstart) > ADC_STOP_CONVERSION_TIMEOUT)
{
@@ -1476,6 +1533,8 @@ HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef* hadc)
return HAL_ERROR;
}
+
+ tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
}
/* Disable the DMA channel (in case of DMA in circular mode or stop */
@@ -1500,12 +1559,12 @@ HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef* hadc)
/* memory a potential failing status. */
if (tmp_hal_status == HAL_OK)
{
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc) == RESET)
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
{
tmp_hal_status = ADC_Disable(hadc);
if (tmp_hal_status == HAL_OK)
{
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(&tmphadcSlave) == RESET)
+ if (LL_ADC_INJ_IsConversionOngoing((&tmphadcSlave)->Instance) == 0UL)
{
tmp_hal_status = ADC_Disable(&tmphadcSlave);
}
@@ -1594,7 +1653,10 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
{
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
uint32_t tmpOffsetShifted;
- uint32_t wait_loop_index = 0U;
+ uint32_t tmp_config_internal_channel;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
+ __IO uint32_t wait_loop_index = 0;
uint32_t tmp_JSQR_ContextQueueBeingBuilt = 0U;
@@ -1774,21 +1836,23 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
/* enable (context decremented, up to 2 contexts queued) */
/* - Injected discontinuous mode: can be enabled only if auto-injected */
/* mode is disabled. */
- if (ADC_IS_CONVERSION_ONGOING_INJECTED(hadc) == RESET)
+ if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
{
/* If auto-injected mode is disabled: no constraint */
if (sConfigInjected->AutoInjectedConv == DISABLE)
{
- MODIFY_REG(hadc->Instance->CFGR, ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
- ADC_CFGR_INJECT_CONTEXT_QUEUE(sConfigInjected->QueueInjectedContext) |
- ADC_CFGR_INJECT_DISCCONTINUOUS(sConfigInjected->InjectedDiscontinuousConvMode) );
+ MODIFY_REG(hadc->Instance->CFGR,
+ ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
+ ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext) |
+ ADC_CFGR_INJECT_DISCCONTINUOUS((uint32_t)sConfigInjected->InjectedDiscontinuousConvMode) );
}
/* If auto-injected mode is enabled: Injected discontinuous setting is */
/* discarded. */
else
{
- MODIFY_REG(hadc->Instance->CFGR, ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
- ADC_CFGR_INJECT_CONTEXT_QUEUE(sConfigInjected->QueueInjectedContext) );
+ MODIFY_REG(hadc->Instance->CFGR,
+ ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
+ ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext) );
}
}
@@ -1800,7 +1864,12 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
/* external triggers are disabled. */
/* - Channel sampling time */
/* - Channel offset */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET)
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+
+ if ( (tmp_adc_is_conversion_on_going_regular == 0UL)
+ && (tmp_adc_is_conversion_on_going_injected == 0UL)
+ )
{
/* If injected group external triggers are disabled (set to injected */
/* software start): no constraint */
@@ -1923,16 +1992,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
/* Parameters update conditioned to ADC state: */
/* Parameters that can be updated only when ADC is disabled: */
/* - Single or differential mode */
- if (ADC_IS_ENABLE(hadc) == RESET)
+ if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
{
/* Set mode single-ended or differential input of the selected ADC channel */
LL_ADC_SetChannelSingleDiff(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSingleDiff);
/* Configuration of differential mode */
+ /* Note: ADC channel number masked with value "0x1F" to ensure shift value within 32 bits range */
if (sConfigInjected->InjectedSingleDiff == ADC_DIFFERENTIAL_ENDED)
{
/* Set sampling time of the selected ADC channel */
- LL_ADC_SetChannelSamplingTime(hadc->Instance, __LL_ADC_DECIMAL_NB_TO_CHANNEL(__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel) + 1), sConfigInjected->InjectedSamplingTime);
+ LL_ADC_SetChannelSamplingTime(hadc->Instance, __LL_ADC_DECIMAL_NB_TO_CHANNEL((__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel) + 1UL) & 0x1FUL), sConfigInjected->InjectedSamplingTime);
}
}
@@ -1942,47 +2012,49 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
/* enable dedicated internal buffers and path. */
/* Note: these internal measurement paths can be disabled using */
/* HAL_ADC_DeInit(). */
-
- /* Configuration of common ADC parameters */
- /* If the requested internal measurement path has already been enabled, */
- /* bypass the configuration processing. */
- if (( (sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) &&
- ((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0U)) ||
- ( (sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT) &&
- ((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VBAT) == 0U)) ||
- ( (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) &&
- ((LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) & LL_ADC_PATH_INTERNAL_VREFINT) == 0U))
- )
+
+ if(__LL_ADC_IS_CHANNEL_INTERNAL(sConfigInjected->InjectedChannel))
{
- if (sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR)
+ tmp_config_internal_channel = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
+
+ /* If the requested internal measurement path has already been enabled, */
+ /* bypass the configuration processing. */
+ if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0UL))
{
- if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc))
+ if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc))
{
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)));
-
+ LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | tmp_config_internal_channel);
+
/* Delay for temperature sensor stabilization time */
- /* Compute number of CPU cycles to wait for */
- wait_loop_index = (LL_ADC_DELAY_TEMPSENSOR_STAB_US * (SystemCoreClock / 1000000));
- while(wait_loop_index != 0)
+ /* Wait loop initialization and execution */
+ /* Note: Variable divided by 2 to compensate partially */
+ /* CPU processing cycles, scaling in us split to not */
+ /* exceed 32 bits register capacity and handle low frequency. */
+ wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
+ while(wait_loop_index != 0UL)
{
wait_loop_index--;
}
}
}
- else if (sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT)
+ else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VBAT) == 0UL))
{
if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc))
{
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)));
+ LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | tmp_config_internal_channel);
}
}
- else if (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)
+ else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VREFINT) == 0UL))
{
if (ADC_VREFINT_INSTANCE(hadc))
{
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)));
+ LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | tmp_config_internal_channel);
}
}
+ else
+ {
+ /* nothing to do */
+ }
}
/* Process unlocked */
@@ -2011,9 +2083,10 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
*/
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode)
{
- HAL_StatusTypeDef tmp_hal_status = HAL_OK;
+ HAL_StatusTypeDef tmp_hal_status = HAL_OK;
ADC_Common_TypeDef *tmpADC_Common;
ADC_HandleTypeDef tmphadcSlave;
+ uint32_t tmphadcSlave_conversion_on_going;
/* Check the parameters */
assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
@@ -2045,20 +2118,21 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_
/* conversion on going on regular group: */
/* - Multimode DMA configuration */
/* - Multimode DMA mode */
- if ( (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
- && (ADC_IS_CONVERSION_ONGOING_REGULAR(&tmphadcSlave) == RESET) )
+ tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
+ if ( (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
+ && (tmphadcSlave_conversion_on_going == 0UL) )
{
/* Pointer to the common control register */
tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
- /* If multimode is selected, configure all multimode paramaters. */
+ /* If multimode is selected, configure all multimode parameters. */
/* Otherwise, reset multimode parameters (can be used in case of */
/* transition from multimode to independent mode). */
if(multimode->Mode != ADC_MODE_INDEPENDENT)
{
MODIFY_REG(tmpADC_Common->CCR, ADC_CCR_MDMA | ADC_CCR_DMACFG,
multimode->DMAAccessMode |
- ADC_CCR_MULTI_DMACONTREQ(hadc->Init.DMAContinuousRequests));
+ ADC_CCR_MULTI_DMACONTREQ((uint32_t)hadc->Init.DMAContinuousRequests));
/* Parameters that can be updated only when ADC is disabled: */
/* - Multimode mode selection */
@@ -2070,8 +2144,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_
/* from 1 to 6 clock cycles for 6 bits */
/* If a higher delay is selected, it will be clipped to maximum delay */
/* range */
- if ((ADC_IS_ENABLE(hadc) == RESET) &&
- (ADC_IS_ENABLE(&tmphadcSlave) == RESET) )
+ if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
{
MODIFY_REG(tmpADC_Common->CCR,
ADC_CCR_DUAL |
@@ -2088,8 +2161,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_
/* Parameters that can be updated only when ADC is disabled: */
/* - Multimode mode selection */
/* - Multimode delay */
- if ((ADC_IS_ENABLE(hadc) == RESET) &&
- (ADC_IS_ENABLE(&tmphadcSlave) == RESET) )
+ if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
{
CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_DUAL | ADC_CCR_DELAY);
}
@@ -2124,20 +2196,34 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_
*/
HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue(ADC_HandleTypeDef* hadc)
{
- /* Parameter can be set only if no conversion is on-going */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET)
+ HAL_StatusTypeDef tmp_hal_status;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
+
+ /* Check the parameters */
+ assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
+
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+
+ /* Parameter can be set only if no conversion is on-going */
+ if ( (tmp_adc_is_conversion_on_going_regular == 0UL)
+ && (tmp_adc_is_conversion_on_going_injected == 0UL)
+ )
{
CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
/* Update state, clear previous result related to injected queue overflow */
CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_JQOVF);
- return HAL_OK;
+ tmp_hal_status = HAL_OK;
}
else
{
- return HAL_ERROR;
+ tmp_hal_status = HAL_ERROR;
}
+
+ return tmp_hal_status;
}
/**
@@ -2151,16 +2237,30 @@ HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue(ADC_HandleTypeDef* hadc)
{
- /* Parameter can be set only if no conversion is on-going */
- if (ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(hadc) == RESET)
+ HAL_StatusTypeDef tmp_hal_status;
+ uint32_t tmp_adc_is_conversion_on_going_regular;
+ uint32_t tmp_adc_is_conversion_on_going_injected;
+
+ /* Check the parameters */
+ assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
+
+ tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
+ tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
+
+ /* Parameter can be set only if no conversion is on-going */
+ if ( (tmp_adc_is_conversion_on_going_regular == 0UL)
+ && (tmp_adc_is_conversion_on_going_injected == 0UL)
+ )
{
- SET_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
- return HAL_OK;
+ LL_ADC_INJ_SetQueueMode(hadc->Instance, LL_ADC_INJ_QUEUE_DISABLE);
+ tmp_hal_status = HAL_OK;
}
else
{
- return HAL_ERROR;
+ tmp_hal_status = HAL_ERROR;
}
+
+ return tmp_hal_status;
}
/**
@@ -2168,22 +2268,29 @@ HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue(ADC_HandleTypeDef* hadc)
* @note Disabling voltage regulator allows to save power. This operation can
* be carried out only when ADC is disabled.
* @note To enable again the voltage regulator, the user is expected to
- * resort to HAL_ADC_Init() API.
+ * resort to HAL_ADC_Init() API.
* @param hadc ADC handle
* @retval HAL status
*/
HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef* hadc)
{
- /* ADVREGEN can be written only when the ADC is disabled */
- if (ADC_IS_ENABLE(hadc) == RESET)
+ HAL_StatusTypeDef tmp_hal_status;
+
+ /* Check the parameters */
+ assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
+
+ /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
+ if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
{
- CLEAR_BIT(hadc->Instance->CR, ADC_CR_ADVREGEN);
- return HAL_OK;
+ LL_ADC_DisableInternalRegulator(hadc->Instance);
+ tmp_hal_status = HAL_OK;
}
else
{
- return HAL_ERROR;
+ tmp_hal_status = HAL_ERROR;
}
+
+ return tmp_hal_status;
}
/**
@@ -2194,7 +2301,7 @@ HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef* hadc)
* @note Setting DEEPPWD automatically clears ADVREGEN bit and disables the
* ADC voltage regulator. This means that this API encompasses
* HAL_ADCEx_DisableVoltageRegulator(). Additionally, the internal
- * calibration is lost.
+ * calibration is lost.
* @note To exit the ADC deep-power-down mode, the user is expected to
* resort to HAL_ADC_Init() API as well as to relaunch a calibration
* with HAL_ADCEx_Calibration_Start() API or to re-apply a previously
@@ -2204,16 +2311,23 @@ HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef* hadc)
*/
HAL_StatusTypeDef HAL_ADCEx_EnterADCDeepPowerDownMode(ADC_HandleTypeDef* hadc)
{
- /* DEEPPWD can be written only when the ADC is disabled */
- if (ADC_IS_ENABLE(hadc) == RESET)
+ HAL_StatusTypeDef tmp_hal_status;
+
+ /* Check the parameters */
+ assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
+
+ /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
+ if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
{
- SET_BIT(hadc->Instance->CR, ADC_CR_DEEPPWD);
- return HAL_OK;
+ LL_ADC_EnableDeepPowerDown(hadc->Instance);
+ tmp_hal_status = HAL_OK;
}
else
{
- return HAL_ERROR;
+ tmp_hal_status = HAL_ERROR;
}
+
+ return tmp_hal_status;
}
/**
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_comp.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_comp.c
index 62cbea9361..f3a9e93c1b 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_comp.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_comp.c
@@ -18,7 +18,10 @@
[..]
The STM32L4xx device family integrates two analog comparators instances:
- COMP1, COMP2.
+ COMP1, COMP2 except for the STM32L412xx/STM32L422xx products that embed only
+ one: COMP1.
+ In the rest of the file, all comments related to a pair of comparators are not
+ applicable to STM32L412xx or STM32L422xx.
(#) Comparators input minus (inverting input) and input plus (non inverting input)
can be set to internal references or to GPIO pins
(refer to GPIO list in reference manual).
@@ -146,32 +149,33 @@
******************************************************************************
Table 1. COMP inputs and output for STM32L4xx devices
- +---------------------------------------------------------+
- | | | COMP1 | COMP2 |
- |----------------|----------------|-----------|-----------|
- | | IO1 | PC5 | PB4 |
- | Input plus | IO2 | PB2 | PB6 |
- | | IO3 (3) | PA1 | PA3 |
- |----------------|----------------|-----------------------|
- | | 1/4 VrefInt | Available | Available |
- | | 1/2 VrefInt | Available | Available |
- | | 3/4 VrefInt | Available | Available |
- | Input minus | VrefInt | Available | Available |
- | | DAC1 channel 1 | Available | Available |
- | | DAC1 channel 2 | Available | Available |
- | | IO1 | PB1 | PB3 |
- | | IO2 | PC4 | PB7 |
- | | IO3 (3) | PA0 | PA2 |
- | | IO4 (3) | PA4 | PA4 |
- | | IO5 (3) | PA5 | PA5 |
- +---------------------------------------------------------+
- | Output | | PB0 (1) | PB5 (1) |
- | | | PB10 (1) | PB11 (1) |
- | | | TIM (2) | TIM (2) |
- +---------------------------------------------------------+
+ +-----------------------------------------------------------------+
+ | | | COMP1 | COMP2 (4) |
+ |----------------|----------------|---------------|---------------+
+ | | IO1 | PC5 | PB4 |
+ | Input plus | IO2 | PB2 | PB6 |
+ | | IO3 (3) | PA1 | PA3 |
+ |----------------|----------------|---------------|---------------+
+ | | 1/4 VrefInt | Available | Available |
+ | | 1/2 VrefInt | Available | Available |
+ | | 3/4 VrefInt | Available | Available |
+ | Input minus | VrefInt | Available | Available |
+ | | DAC1 channel 1 | Available | Available (4) |
+ | | DAC1 channel 2 | Available | Available (4) |
+ | | IO1 | PB1 | PB3 |
+ | | IO2 | PC4 | PB7 |
+ | | IO3 (3) | PA0 | PA2 |
+ | | IO4 (3) | PA4 | PA4 |
+ | | IO5 (3) | PA5 | PA5 |
+ +----------------|----------------|---------------|---------------+
+ | Output | | PB0 (1) | PB5 (1) |
+ | | | PB10 (1) | PB11 (1) |
+ | | | TIM (2) | TIM (2) |
+ +-----------------------------------------------------------------+
(1) GPIO must be set to alternate function for comparator
(2) Comparators output to timers is set in timers instances.
(3) Only STM32L43x/L44x
+ (4) Not applicable to STM32L412x/L422x
******************************************************************************
* @attention
@@ -230,15 +234,15 @@
/* Literal set to maximum value (refer to device datasheet, */
/* parameter "tSTART"). */
/* Unit: us */
-#define COMP_DELAY_STARTUP_US (80U) /*!< Delay for COMP startup time */
+#define COMP_DELAY_STARTUP_US (80UL) /*!< Delay for COMP startup time */
/* Delay for COMP voltage scaler stabilization time. */
/* Literal set to maximum value (refer to device datasheet, */
/* parameter "tSTART_SCALER"). */
/* Unit: us */
-#define COMP_DELAY_VOLTAGE_SCALER_STAB_US (200U) /*!< Delay for COMP voltage scaler stabilization time */
+#define COMP_DELAY_VOLTAGE_SCALER_STAB_US (200UL) /*!< Delay for COMP voltage scaler stabilization time */
-#define COMP_OUTPUT_LEVEL_BITOFFSET_POS (30U)
+#define COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL)
/**
* @}
@@ -276,14 +280,18 @@
*/
HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
{
- uint32_t tmp_csr = 0U;
- uint32_t exti_line = 0U;
- uint32_t comp_voltage_scaler_not_initialized = 0U;
- __IO uint32_t wait_loop_index = 0U;
+ uint32_t tmp_csr;
+ uint32_t exti_line;
+ uint32_t comp_voltage_scaler_initialized; /* Value "0" if comparator voltage scaler is not initialized */
+ __IO uint32_t wait_loop_index = 0UL;
HAL_StatusTypeDef status = HAL_OK;
/* Check the COMP handle allocation and lock status */
- if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
+ if(hcomp == NULL)
+ {
+ status = HAL_ERROR;
+ }
+ else if(__HAL_COMP_IS_LOCKED(hcomp))
{
status = HAL_ERROR;
}
@@ -298,7 +306,9 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis));
assert_param(IS_COMP_BLANKINGSRC_INSTANCE(hcomp->Instance, hcomp->Init.BlankingSrce));
assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
+#if defined(COMP2)
assert_param(IS_COMP_WINDOWMODE(hcomp->Init.WindowMode));
+#endif
if(hcomp->State == HAL_COMP_STATE_RESET)
{
@@ -337,7 +347,7 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
}
/* Memorize voltage scaler state before initialization */
- comp_voltage_scaler_not_initialized = (READ_BIT(hcomp->Instance->CSR, COMP_CSR_SCALEN) == 0);
+ comp_voltage_scaler_initialized = READ_BIT(hcomp->Instance->CSR, COMP_CSR_SCALEN);
/* Set COMP parameters */
tmp_csr = ( hcomp->Init.NonInvertingInput
@@ -351,12 +361,21 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
/* Set parameters in COMP register */
/* Note: Update all bits except read-only, lock and enable bits */
#if defined (COMP_CSR_INMESEL)
+#if defined (COMP_CSR_WINMODE)
MODIFY_REG(hcomp->Instance->CSR,
COMP_CSR_PWRMODE | COMP_CSR_INMSEL | COMP_CSR_INPSEL |
COMP_CSR_WINMODE | COMP_CSR_POLARITY | COMP_CSR_HYST |
COMP_CSR_BLANKING | COMP_CSR_BRGEN | COMP_CSR_SCALEN | COMP_CSR_INMESEL,
tmp_csr
);
+#else
+ MODIFY_REG(hcomp->Instance->CSR,
+ COMP_CSR_PWRMODE | COMP_CSR_INMSEL | COMP_CSR_INPSEL |
+ COMP_CSR_POLARITY | COMP_CSR_HYST |
+ COMP_CSR_BLANKING | COMP_CSR_BRGEN | COMP_CSR_SCALEN | COMP_CSR_INMESEL,
+ tmp_csr
+ );
+#endif
#else
MODIFY_REG(hcomp->Instance->CSR,
COMP_CSR_PWRMODE | COMP_CSR_INMSEL | COMP_CSR_INPSEL |
@@ -366,6 +385,7 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
);
#endif
+#if defined(COMP2)
/* Set window mode */
/* Note: Window mode bit is located into 1 out of the 2 pairs of COMP */
/* instances. Therefore, this function can update another COMP */
@@ -378,17 +398,19 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
{
CLEAR_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE);
}
+#endif /* COMP2 */
/* Delay for COMP scaler bridge voltage stabilization */
- /* Apply the delay if voltage scaler bridge is enabled for the first time */
- if ((READ_BIT(hcomp->Instance->CSR, COMP_CSR_SCALEN) != 0U) &&
- (comp_voltage_scaler_not_initialized != 0U) )
+ /* Apply the delay if voltage scaler bridge is required and not already enabled */
+ if ((READ_BIT(hcomp->Instance->CSR, COMP_CSR_SCALEN) != 0UL) &&
+ (comp_voltage_scaler_initialized == 0UL) )
{
/* Wait loop initialization and execution */
- /* Note: Variable divided by 2 to compensate partially */
- /* CPU processing cycles. */
- wait_loop_index = (COMP_DELAY_VOLTAGE_SCALER_STAB_US * (SystemCoreClock / (1000000 * 2U)));
- while(wait_loop_index != 0U)
+ /* Note: Variable divided by 2 to compensate partially */
+ /* CPU processing cycles, scaling in us split to not */
+ /* exceed 32 bits register capacity and handle low frequency. */
+ wait_loop_index = ((COMP_DELAY_VOLTAGE_SCALER_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
+ while(wait_loop_index != 0UL)
{
wait_loop_index--;
}
@@ -398,10 +420,10 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
/* Manage EXTI settings */
- if((hcomp->Init.TriggerMode & (COMP_EXTI_IT | COMP_EXTI_EVENT)) != RESET)
+ if((hcomp->Init.TriggerMode & (COMP_EXTI_IT | COMP_EXTI_EVENT)) != 0UL)
{
/* Configure EXTI rising edge */
- if((hcomp->Init.TriggerMode & COMP_EXTI_RISING) != RESET)
+ if((hcomp->Init.TriggerMode & COMP_EXTI_RISING) != 0UL)
{
LL_EXTI_EnableRisingTrig_0_31(exti_line);
}
@@ -411,7 +433,7 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
}
/* Configure EXTI falling edge */
- if((hcomp->Init.TriggerMode & COMP_EXTI_FALLING) != RESET)
+ if((hcomp->Init.TriggerMode & COMP_EXTI_FALLING) != 0UL)
{
LL_EXTI_EnableFallingTrig_0_31(exti_line);
}
@@ -424,7 +446,7 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
LL_EXTI_ClearFlag_0_31(exti_line);
/* Configure EXTI event mode */
- if((hcomp->Init.TriggerMode & COMP_EXTI_EVENT) != RESET)
+ if((hcomp->Init.TriggerMode & COMP_EXTI_EVENT) != 0UL)
{
LL_EXTI_EnableEvent_0_31(exti_line);
}
@@ -434,7 +456,7 @@ HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
}
/* Configure EXTI interrupt mode */
- if((hcomp->Init.TriggerMode & COMP_EXTI_IT) != RESET)
+ if((hcomp->Init.TriggerMode & COMP_EXTI_IT) != 0UL)
{
LL_EXTI_EnableIT_0_31(exti_line);
}
@@ -476,7 +498,11 @@ HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
HAL_StatusTypeDef status = HAL_OK;
/* Check the COMP handle allocation and lock status */
- if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
+ if(hcomp == NULL)
+ {
+ status = HAL_ERROR;
+ }
+ else if(__HAL_COMP_IS_LOCKED(hcomp))
{
status = HAL_ERROR;
}
@@ -486,7 +512,7 @@ HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
/* Set COMP_CSR register to reset value */
- WRITE_REG(hcomp->Instance->CSR, 0x00000000U);
+ WRITE_REG(hcomp->Instance->CSR, 0x00000000UL);
#if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
if (hcomp->MspDeInitCallback == NULL)
@@ -727,11 +753,15 @@ HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COM
*/
HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
{
- __IO uint32_t wait_loop_index = 0U;
+ __IO uint32_t wait_loop_index = 0UL;
HAL_StatusTypeDef status = HAL_OK;
/* Check the COMP handle allocation and lock status */
- if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
+ if(hcomp == NULL)
+ {
+ status = HAL_ERROR;
+ }
+ else if(__HAL_COMP_IS_LOCKED(hcomp))
{
status = HAL_ERROR;
}
@@ -750,10 +780,11 @@ HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
/* Delay for COMP startup time */
/* Wait loop initialization and execution */
- /* Note: Variable divided by 2 to compensate partially */
- /* CPU processing cycles. */
- wait_loop_index = (COMP_DELAY_STARTUP_US * (SystemCoreClock / (1000000U * 2U)));
- while(wait_loop_index != 0U)
+ /* Note: Variable divided by 2 to compensate partially */
+ /* CPU processing cycles, scaling in us split to not */
+ /* exceed 32 bits register capacity and handle low frequency. */
+ wait_loop_index = ((COMP_DELAY_STARTUP_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
+ while(wait_loop_index != 0UL)
{
wait_loop_index--;
}
@@ -777,7 +808,11 @@ HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
HAL_StatusTypeDef status = HAL_OK;
/* Check the COMP handle allocation and lock status */
- if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
+ if(hcomp == NULL)
+ {
+ status = HAL_ERROR;
+ }
+ else if(__HAL_COMP_IS_LOCKED(hcomp))
{
status = HAL_ERROR;
}
@@ -786,8 +821,9 @@ HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
/* Check the parameter */
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
- if((hcomp->State == HAL_COMP_STATE_BUSY) ||
- (hcomp->State == HAL_COMP_STATE_READY) )
+ /* Check compliant states: HAL_COMP_STATE_READY or HAL_COMP_STATE_BUSY */
+ /* (all states except HAL_COMP_STATE_RESET and except locked status. */
+ if(hcomp->State != HAL_COMP_STATE_RESET)
{
/* Disable the selected comparator */
CLEAR_BIT(hcomp->Instance->CSR, COMP_CSR_EN);
@@ -815,8 +851,9 @@ void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
uint32_t exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
/* Check COMP EXTI flag */
- if(LL_EXTI_IsActiveFlag_0_31(exti_line) != RESET)
+ if(LL_EXTI_IsActiveFlag_0_31(exti_line) != 0UL)
{
+#if defined(COMP2)
/* Check whether comparator is in independent or window mode */
if(READ_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE) != RESET)
{
@@ -830,6 +867,7 @@ void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
LL_EXTI_ClearFlag_0_31((COMP_EXTI_LINE_COMP1 | COMP_EXTI_LINE_COMP2));
}
else
+#endif /* COMP2 */
{
/* Clear COMP EXTI line pending bit */
LL_EXTI_ClearFlag_0_31(exti_line);
@@ -875,7 +913,11 @@ HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
HAL_StatusTypeDef status = HAL_OK;
/* Check the COMP handle allocation and lock status */
- if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
+ if(hcomp == NULL)
+ {
+ status = HAL_ERROR;
+ }
+ else if(__HAL_COMP_IS_LOCKED(hcomp))
{
status = HAL_ERROR;
}
@@ -885,7 +927,18 @@ HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
/* Set HAL COMP handle state */
- hcomp->State = ((HAL_COMP_StateTypeDef)(hcomp->State | COMP_STATE_BITFIELD_LOCK));
+ switch(hcomp->State)
+ {
+ case HAL_COMP_STATE_RESET:
+ hcomp->State = HAL_COMP_STATE_RESET_LOCKED;
+ break;
+ case HAL_COMP_STATE_READY:
+ hcomp->State = HAL_COMP_STATE_READY_LOCKED;
+ break;
+ default: /* HAL_COMP_STATE_BUSY */
+ hcomp->State = HAL_COMP_STATE_BUSY_LOCKED;
+ break;
+ }
}
if(status == HAL_OK)
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc.c
index 7d7289c373..819158cdce 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc.c
@@ -305,9 +305,6 @@ uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_
uint32_t index; /* CRC input data buffer index */
uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
- /* Process locked */
- __HAL_LOCK(hcrc);
-
/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_BUSY;
@@ -327,7 +324,7 @@ uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_
break;
case CRC_INPUTDATA_FORMAT_HALFWORDS:
- temp = CRC_Handle_16(hcrc, (uint16_t *)pBuffer, BufferLength);
+ temp = CRC_Handle_16(hcrc, (uint16_t *)(void *)pBuffer, BufferLength); /* Derogation MisraC2012 R.11.5 */
break;
default:
break;
@@ -336,9 +333,6 @@ uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_
/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_READY;
- /* Process unlocked */
- __HAL_UNLOCK(hcrc);
-
/* Return the CRC computed value */
return temp;
}
@@ -363,9 +357,6 @@ uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t
uint32_t index; /* CRC input data buffer index */
uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
- /* Process locked */
- __HAL_LOCK(hcrc);
-
/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_BUSY;
@@ -391,7 +382,7 @@ uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t
case CRC_INPUTDATA_FORMAT_HALFWORDS:
/* Specific 16-bit input data handling */
- temp = CRC_Handle_16(hcrc, (uint16_t *)pBuffer, BufferLength);
+ temp = CRC_Handle_16(hcrc, (uint16_t *)(void *)pBuffer, BufferLength); /* Derogation MisraC2012 R.11.5 */
break;
default:
@@ -401,9 +392,6 @@ uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t
/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_READY;
- /* Process unlocked */
- __HAL_UNLOCK(hcrc);
-
/* Return the CRC computed value */
return temp;
}
@@ -469,30 +457,30 @@ static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_
for (i = 0U; i < (BufferLength / 4U); i++)
{
hcrc->Instance->DR = ((uint32_t)pBuffer[4U * i] << 24U) | \
- ((uint32_t)pBuffer[4U * i + 1U] << 16U) | \
- ((uint32_t)pBuffer[4U * i + 2U] << 8U) | \
- (uint32_t)pBuffer[4U * i + 3U];
+ ((uint32_t)pBuffer[(4U * i) + 1U] << 16U) | \
+ ((uint32_t)pBuffer[(4U * i) + 2U] << 8U) | \
+ (uint32_t)pBuffer[(4U * i) + 3U];
}
/* last bytes specific handling */
if ((BufferLength % 4U) != 0U)
{
- if (BufferLength % 4U == 1U)
+ if ((BufferLength % 4U) == 1U)
{
- *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[4U * i];
+ *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[4U * i]; /* Derogation MisraC2012 R.11.5 */
}
- if (BufferLength % 4U == 2U)
+ if ((BufferLength % 4U) == 2U)
{
- data = (uint16_t)(pBuffer[4U * i] << 8U) | (uint16_t)pBuffer[4U * i + 1U];
- pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR);
+ data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
+ pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
*pReg = data;
}
- if (BufferLength % 4U == 3U)
+ if ((BufferLength % 4U) == 3U)
{
- data = (uint16_t)(pBuffer[4U * i] << 8U) | (uint16_t)pBuffer[4U * i + 1U];
- pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR);
+ data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
+ pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
*pReg = data;
- *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[4U * i + 2U];
+ *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[(4U * i) + 2U]; /* Derogation MisraC2012 R.11.5 */
}
}
@@ -518,11 +506,11 @@ static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint3
* a correct type handling by the IP */
for (i = 0U; i < (BufferLength / 2U); i++)
{
- hcrc->Instance->DR = ((uint32_t)pBuffer[2U * i] << 16U) | (uint32_t)pBuffer[2U * i + 1U];
+ hcrc->Instance->DR = ((uint32_t)pBuffer[2U * i] << 16U) | (uint32_t)pBuffer[(2U * i) + 1U];
}
if ((BufferLength % 2U) != 0U)
{
- pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR);
+ pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
*pReg = pBuffer[2U * i];
}
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c
index 88ad1de311..1ecef9cb6a 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c
@@ -117,7 +117,7 @@ HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol
* Look for MSB position: msb will contain the degree of
* the second to the largest polynomial member. E.g., for
* X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */
- while ((msb-- > 0U) && ((Pol & ((uint32_t)(0x1U) << msb)) == 0U))
+ while ((msb-- > 0U) && ((Pol & ((uint32_t)(0x1U) << (msb & 0x1FU))) == 0U))
{
}
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp.c
index ff83ce4d7c..3747e05752 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp.c
@@ -1432,26 +1432,43 @@ void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp)
/* Check if computation complete interrupt is enabled
and if the computation complete flag is raised */
- if((__HAL_CRYP_GET_FLAG(hcryp, CRYP_IT_CCF) != RESET) && (__HAL_CRYP_GET_IT_SOURCE(hcryp, CRYP_IT_CCFIE) != RESET))
+ if (__HAL_CRYP_GET_FLAG(hcryp, CRYP_IT_CCF) != RESET)
{
+ if (__HAL_CRYP_GET_IT_SOURCE(hcryp, CRYP_IT_CCFIE) != RESET)
+ {
#if defined(AES_CR_NPBLB)
- if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
- || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM))
+ if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
+ || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM))
#else
- if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
- || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC))
+ if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
+ || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC))
#endif
- {
- /* To ensure proper suspension requests management, CCF flag
- is reset in CRYP_AES_Auth_IT() according to the current
- phase under handling */
- CRYP_AES_Auth_IT(hcryp);
- }
- else
- {
- /* Clear Computation Complete Flag */
- __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
- CRYP_AES_IT(hcryp);
+ {
+ /* To ensure proper suspension requests management, CCF flag
+ is reset in CRYP_AES_Auth_IT() according to the current
+ phase under handling */
+ if (CRYP_AES_Auth_IT(hcryp) != HAL_OK)
+ {
+#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
+ hcryp->ErrorCallback(hcryp);
+#else
+ HAL_CRYP_ErrorCallback(hcryp);
+#endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
+ }
+ }
+ else
+ {
+ /* Clear Computation Complete Flag */
+ __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
+ if (CRYP_AES_IT(hcryp) != HAL_OK)
+ {
+#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
+ hcryp->ErrorCallback(hcryp);
+#else
+ HAL_CRYP_ErrorCallback(hcryp);
+#endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
+ }
+ }
}
}
}
@@ -1519,9 +1536,9 @@ uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp)
*/
static HAL_StatusTypeDef CRYP_SetKey(CRYP_HandleTypeDef *hcryp)
{
- uint32_t keyaddr = 0x0;
+ uint32_t keyaddr;
- if ((uint32_t)(hcryp->Init.pKey == NULL))
+ if (hcryp->Init.pKey == NULL)
{
return HAL_ERROR;
}
@@ -1532,21 +1549,21 @@ static HAL_StatusTypeDef CRYP_SetKey(CRYP_HandleTypeDef *hcryp)
if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B)
{
hcryp->Instance->KEYR7 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR6 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR5 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR4 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
}
hcryp->Instance->KEYR3 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR2 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR1 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR0 = __REV(*(uint32_t*)(keyaddr));
return HAL_OK;
@@ -1560,7 +1577,7 @@ static HAL_StatusTypeDef CRYP_SetKey(CRYP_HandleTypeDef *hcryp)
*/
static HAL_StatusTypeDef CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp)
{
- uint32_t ivaddr = 0x0;
+ uint32_t ivaddr;
#if !defined(AES_CR_NPBLB)
if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
@@ -1581,11 +1598,11 @@ static HAL_StatusTypeDef CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp)
ivaddr = (uint32_t)(hcryp->Init.pInitVect);
hcryp->Instance->IVR3 = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->IVR2 = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->IVR1 = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->IVR0 = __REV(*(uint32_t*)(ivaddr));
}
return HAL_OK;
@@ -1603,7 +1620,7 @@ static HAL_StatusTypeDef CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp)
*/
static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp)
{
- uint32_t inputaddr = 0;
+ uint32_t inputaddr;
uint32_t outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
if(hcryp->State == HAL_CRYP_STATE_BUSY)
@@ -1612,14 +1629,14 @@ static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp)
{
/* Read the last available output block from the Data Output Register */
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
hcryp->pCrypOutBuffPtr += 16;
- hcryp->CrypOutCount -= 16;
+ hcryp->CrypOutCount -= 16U;
}
else
@@ -1628,27 +1645,27 @@ static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp)
if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B)
{
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR7);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR6);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR5);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR4);
- outputaddr+=4;
+ outputaddr+=4U;
}
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR3);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR2);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR1);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR0);
}
/* In case of ciphering or deciphering, check if all output text has been retrieved;
In case of key derivation, stop right there */
- if ((hcryp->CrypOutCount == 0) || (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION))
+ if ((hcryp->CrypOutCount == 0U) || (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION))
{
/* Disable Computation Complete Flag and Errors Interrupts */
__HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
@@ -1690,15 +1707,15 @@ static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp)
/* Increment/decrement instance pointer/counter */
hcryp->pCrypInBuffPtr += 16;
- hcryp->CrypInCount -= 16;
+ hcryp->CrypInCount -= 16U;
/* Write the next input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
return HAL_OK;
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp_ex.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp_ex.c
index 5fb87be580..9a85f160ac 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp_ex.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp_ex.c
@@ -83,8 +83,8 @@ static void CRYP_Authentication_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t
static void CRYP_Authentication_DMAInCplt(DMA_HandleTypeDef *hdma);
static void CRYP_Authentication_DMAError(DMA_HandleTypeDef *hdma);
static void CRYP_Authentication_DMAOutCplt(DMA_HandleTypeDef *hdma);
-static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef *hcryp, uint32_t Timeout);
-static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset(CRYP_HandleTypeDef *hcryp, uint32_t Timeout);
+static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef const * const hcryp, uint32_t Timeout);
+static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset(CRYP_HandleTypeDef const * const hcryp, uint32_t Timeout);
static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma);
static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma);
static void CRYP_DMAError(DMA_HandleTypeDef *hdma);
@@ -194,7 +194,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData,
}
else
{
- if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
+ if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -261,7 +261,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData,
*/
HAL_StatusTypeDef HAL_CRYPEx_AES_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData)
{
- uint32_t inputaddr = 0;
+ uint32_t inputaddr;
if(hcryp->State == HAL_CRYP_STATE_READY)
{
@@ -275,7 +275,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputD
}
else
{
- if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
+ if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -321,14 +321,14 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputD
inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
/* Increment/decrement instance pointer/counter */
hcryp->pCrypInBuffPtr += 16;
- hcryp->CrypInCount -= 16;
+ hcryp->CrypInCount -= 16U;
/* Write the first input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
@@ -366,8 +366,8 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputD
*/
HAL_StatusTypeDef HAL_CRYPEx_AES_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData)
{
- uint32_t inputaddr = 0;
- uint32_t outputaddr = 0;
+ uint32_t inputaddr;
+ uint32_t outputaddr;
if (hcryp->State == HAL_CRYP_STATE_READY)
{
@@ -380,7 +380,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
}
else
{
- if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
+ if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -447,23 +447,27 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
*/
HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData, uint32_t Timeout)
{
- uint32_t index = 0;
- uint32_t inputaddr = 0;
- uint32_t outputaddr = 0;
- uint32_t tagaddr = 0;
- uint64_t headerlength = 0;
- uint64_t inputlength = 0;
- uint64_t payloadlength = 0;
+ uint32_t index ;
+ uint32_t inputaddr ;
+ uint32_t outputaddr ;
+ uint32_t tagaddr ;
+ uint64_t headerlength ;
+ uint64_t inputlength ;
+ uint64_t payloadlength ;
uint32_t difflength = 0;
uint32_t addhoc_process = 0;
if (hcryp->State == HAL_CRYP_STATE_READY)
{
/* input/output parameters check */
- if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
+ if (hcryp->Init.GCMCMACPhase == CRYP_INIT_PHASE)
+ {
+ /* No processing required */
+ }
+ else if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
{
- if (((hcryp->Init.Header != NULL) && (hcryp->Init.HeaderSize == 0)) ||
- ((hcryp->Init.Header == NULL) && (hcryp->Init.HeaderSize != 0)))
+ if (((hcryp->Init.Header != NULL) && (hcryp->Init.HeaderSize == 0U)) ||
+ ((hcryp->Init.Header == NULL) && (hcryp->Init.HeaderSize != 0U)))
{
return HAL_ERROR;
}
@@ -474,7 +478,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
#endif
{
/* In case of CMAC or CCM (when applicable) header phase resumption, we can have pInputData = NULL and Size = 0 */
- if (((pInputData != NULL) && (Size == 0)) || ((pInputData == NULL) && (Size != 0)))
+ if (((pInputData != NULL) && (Size == 0U)) || ((pInputData == NULL) && (Size != 0U)))
{
return HAL_ERROR;
}
@@ -482,9 +486,9 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
}
else if (hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE)
{
- if (((pInputData == NULL) && (Size != 0)) || \
- ((pInputData != NULL) && (Size == 0)) || \
- ((pInputData != NULL) && (Size != 0) && (pOutputData == NULL)))
+ if (((pInputData == NULL) && (Size != 0U)) || \
+ ((pInputData != NULL) && (Size == 0U)) || \
+ ((pInputData != NULL) && (Size != 0U) && (pOutputData == NULL)))
{
return HAL_ERROR;
}
@@ -502,6 +506,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
}
#endif
}
+ else
+ {
+ /* Unspecified Phase */
+ return HAL_ERROR;
+ }
/* Process Locked */
@@ -555,21 +564,22 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* in case of CMAC, enter B0 block in header phase, before the header itself. */
/* If Size = 0 (possible case of resumption after CMAC header phase suspension),
skip these steps and go directly to header buffer feeding to the HW */
- if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC) && (Size != 0))
+ if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC) && (Size != 0U))
{
+ uint64_t index_test;
inputaddr = (uint32_t)pInputData;
- for( ; (index < Size); index += 16)
+ for(index=0U ; (index < Size); index += 16U)
{
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
{
@@ -582,7 +592,8 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* If the suspension flag has been raised and if the processing is not about
to end, suspend processing */
- if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < Size))
+ index_test = (uint64_t)index + 16U;
+ if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && (index_test < Size))
{
/* reset SuspendRequest */
hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
@@ -595,7 +606,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
/* Save the total number of bytes (B blocks + header) that remain to be
processed at this point */
- hcryp->CrypInCount = hcryp->Init.HeaderSize + Size - (index+16);
+ hcryp->CrypInCount = (uint32_t) (hcryp->Init.HeaderSize + Size - index_test);
/* Process Unlocked */
__HAL_UNLOCK(hcryp);
@@ -610,22 +621,23 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
inputaddr = (uint32_t)hcryp->Init.Header;
/* Local variable headerlength is a number of bytes multiple of 128 bits,
remaining header data (if any) are handled after this loop */
- headerlength = (((hcryp->Init.HeaderSize)/16)*16) ;
- if ((hcryp->Init.HeaderSize % 16) != 0)
+ headerlength = (((hcryp->Init.HeaderSize)/16U)*16U) ;
+ if ((hcryp->Init.HeaderSize % 16U) != 0U)
{
difflength = (uint32_t) (hcryp->Init.HeaderSize - headerlength);
}
- for(index=0; index < headerlength; index += 16)
+ for(index=0U ; index < headerlength; index += 16U)
{
+ uint64_t index_temp;
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
{
@@ -638,7 +650,8 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* If the suspension flag has been raised and if the processing is not about
to end, suspend processing */
- if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < headerlength))
+ index_temp = (uint64_t)index + 16U;
+ if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && (index_temp < headerlength))
{
/* reset SuspendRequest */
hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
@@ -650,7 +663,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* Save current reading and writing locations of Input and Output buffers */
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
/* Save the total number of bytes that remain to be processed at this point */
- hcryp->CrypInCount = hcryp->Init.HeaderSize - (index+16);
+ hcryp->CrypInCount = (uint32_t) (hcryp->Init.HeaderSize - index_temp);
/* Process Unlocked */
__HAL_UNLOCK(hcryp);
@@ -660,7 +673,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
}
/* Case header length is not a multiple of 16 bytes */
- if (difflength != 0)
+ if (difflength != 0U)
{
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
CRYP_Padding(hcryp, difflength, CRYP_POLLING_ON);
@@ -688,9 +701,9 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* Enter payload */
/* Specific handling to manage payload last block size less than 128 bits */
- if ((Size % 16) != 0)
+ if ((Size % 16U) != 0U)
{
- payloadlength = (Size/16) * 16;
+ payloadlength = (Size/16U) * 16U;
difflength = (uint32_t) (Size - payloadlength);
addhoc_process = 1;
}
@@ -700,17 +713,18 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
}
/* Feed payload */
- for( ; index < payloadlength; index += 16)
+ for(index=0U ; index < payloadlength; index += 16U)
{
+ uint64_t index_temp;
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
{
@@ -725,17 +739,18 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* Retrieve output data: read the output block
from the Data Output Register */
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
/* If the suspension flag has been raised and if the processing is not about
to end, suspend processing */
- if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < payloadlength))
+ index_temp = (uint64_t)index + 16U;
+ if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && (index_temp < payloadlength))
{
/* no flag waiting under IRQ handling */
if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT)
@@ -759,7 +774,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
hcryp->pCrypOutBuffPtr = (uint8_t *)outputaddr;
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
/* Save the number of bytes that remain to be processed at this point */
- hcryp->CrypInCount = Size - (index+16);
+ hcryp->CrypInCount = (uint32_t) (Size - index_temp);
/* Process Unlocked */
__HAL_UNLOCK(hcryp);
@@ -771,7 +786,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* Additional processing to manage GCM(/CCM) encryption and decryption cases when
payload last block size less than 128 bits */
- if (addhoc_process == 1)
+ if (addhoc_process == 1U)
{
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
@@ -786,7 +801,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/*==================================*/
/* GCM/GMAC/CCM or CMAC final phase */
/*==================================*/
- else if (hcryp->Init.GCMCMACPhase == CRYP_FINAL_PHASE)
+ else
{
tagaddr = (uint32_t)pOutputData;
@@ -805,30 +820,30 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
{
- headerlength = hcryp->Init.HeaderSize * 8; /* Header length in bits */
- inputlength = Size * 8; /* input length in bits */
+ headerlength = hcryp->Init.HeaderSize * 8U; /* Header length in bits */
+ inputlength = Size * 8U; /* input length in bits */
#if !defined(AES_CR_NPBLB)
if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
{
- hcryp->Instance->DINR = __RBIT((headerlength)>>32);
- hcryp->Instance->DINR = __RBIT(headerlength);
- hcryp->Instance->DINR = __RBIT((inputlength)>>32);
- hcryp->Instance->DINR = __RBIT(inputlength);
+ hcryp->Instance->DINR = __RBIT((uint32_t)(headerlength>>32));
+ hcryp->Instance->DINR = __RBIT((uint32_t)headerlength);
+ hcryp->Instance->DINR = __RBIT((uint32_t)(inputlength>>32));
+ hcryp->Instance->DINR = __RBIT((uint32_t)inputlength);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
{
- hcryp->Instance->DINR = __REV((headerlength)>>32);
- hcryp->Instance->DINR = __REV(headerlength);
- hcryp->Instance->DINR = __REV((inputlength)>>32);
- hcryp->Instance->DINR = __REV(inputlength);
+ hcryp->Instance->DINR = __REV((uint32_t)(headerlength>>32));
+ hcryp->Instance->DINR = __REV((uint32_t)headerlength);
+ hcryp->Instance->DINR = __REV((uint32_t)(inputlength>>32));
+ hcryp->Instance->DINR = __REV((uint32_t)inputlength);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
{
- hcryp->Instance->DINR = __ROR((headerlength)>>32, 16);
- hcryp->Instance->DINR = __ROR(headerlength, 16);
- hcryp->Instance->DINR = __ROR((inputlength)>>32, 16);
- hcryp->Instance->DINR = __ROR(inputlength, 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)(headerlength>>32), 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)headerlength, 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)(inputlength>>32), 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)inputlength, 16);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
{
@@ -837,6 +852,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
hcryp->Instance->DINR = (uint32_t)(inputlength>>32);
hcryp->Instance->DINR = (uint32_t)(inputlength);
}
+ else
+ {
+ /* Unspecified Data Type */
+ return HAL_ERROR;
+ }
#else
hcryp->Instance->DINR = (uint32_t)(headerlength>>32);
hcryp->Instance->DINR = (uint32_t)(headerlength);
@@ -851,13 +871,18 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* Enter the last block made of a 128-bit value formatted
from the original B0 packet. */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
+ else
+ {
+ /* Unspecified Chaining Mode */
+ return HAL_ERROR;
+ }
#endif
@@ -870,11 +895,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* Read the Auth TAG in the Data Out register */
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
- tagaddr+=4;
+ tagaddr+=4U;
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
- tagaddr+=4;
+ tagaddr+=4U;
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
- tagaddr+=4;
+ tagaddr+=4U;
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
@@ -885,15 +910,6 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
/* Disable the Peripheral */
__HAL_CRYP_DISABLE(hcryp);
}
- /*=================================================*/
- /* case incorrect hcryp->Init.GCMCMACPhase setting */
- /*=================================================*/
- else
- {
- hcryp->State = HAL_CRYP_STATE_ERROR;
- __HAL_UNLOCK(hcryp);
- return HAL_ERROR;
- }
/* Change the CRYP state */
hcryp->State = HAL_CRYP_STATE_READY;
@@ -943,27 +959,33 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInput
HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData)
{
- uint32_t inputaddr = 0;
- uint64_t headerlength = 0;
- uint64_t inputlength = 0;
- uint32_t index = 0;
+ uint32_t inputaddr ;
+ uint64_t headerlength ;
+ uint64_t inputlength ;
+ uint32_t index ;
uint32_t addhoc_process = 0;
uint32_t difflength = 0;
uint32_t difflengthmod4 = 0;
- uint32_t mask[4][3] = { {0xFF000000, 0xFFFF0000, 0xFFFFFF00}, /* 32-bit data */
- {0x0000FF00, 0x0000FFFF, 0xFF00FFFF}, /* 16-bit data */
- {0x000000FF, 0x0000FFFF, 0x00FFFFFF}, /* 8-bit data */
- {0x000000FF, 0x0000FFFF, 0x00FFFFFF}}; /* Bit data */
+ uint32_t mask[4][3];
+
uint32_t mask_index = hcryp->Init.DataType >> AES_CR_DATATYPE_Pos;
+ mask[0][0] = 0xFF000000U; mask[0][1] = 0xFFFF0000U; mask[0][2] = 0xFFFFFF00U; /* 32-bit data */
+ mask[1][0] = 0x0000FF00U; mask[1][1] = 0x0000FFFFU; mask[1][2] = 0xFF00FFFFU; /* 16-bit data */
+ mask[2][0] = 0x000000FFU; mask[2][1] = 0x0000FFFFU; mask[2][2] = 0x00FFFFFFU; /* 8-bit data */
+ mask[3][0] = 0x000000FFU; mask[3][1] = 0x0000FFFFU; mask[3][2] = 0x00FFFFFFU; /* Bit data */
if (hcryp->State == HAL_CRYP_STATE_READY)
{
/* input/output parameters check */
- if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
+ if (hcryp->Init.GCMCMACPhase == CRYP_INIT_PHASE)
+ {
+ /* No processing required */
+ }
+ else if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
{
- if (((hcryp->Init.Header != NULL) && (hcryp->Init.HeaderSize == 0)) ||
- ((hcryp->Init.Header == NULL) && (hcryp->Init.HeaderSize != 0)))
+ if (((hcryp->Init.Header != NULL) && (hcryp->Init.HeaderSize == 0U)) ||
+ ((hcryp->Init.Header == NULL) && (hcryp->Init.HeaderSize != 0U)))
{
return HAL_ERROR;
}
@@ -974,7 +996,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
#endif
{
/* In case of CMAC or CCM header phase resumption, we can have pInputData = NULL and Size = 0 */
- if (((pInputData != NULL) && (Size == 0)) || ((pInputData == NULL) && (Size != 0)))
+ if (((pInputData != NULL) && (Size == 0U)) || ((pInputData == NULL) && (Size != 0U)))
{
return HAL_ERROR;
}
@@ -982,7 +1004,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
}
else if (hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE)
{
- if ((pInputData != NULL) && (Size != 0) && (pOutputData == NULL))
+ if ((pInputData != NULL) && (Size != 0U) && (pOutputData == NULL))
{
return HAL_ERROR;
}
@@ -1000,6 +1022,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
}
#endif
}
+ else
+ {
+ /* Unspecified Phase */
+ return HAL_ERROR;
+ }
/* Process Locked */
@@ -1044,21 +1071,21 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
However, in case of resumption after suspension, if all the
B blocks have been entered (in that case, Size = 0), only the
remainder of the non-processed header bytes are entered. */
- if (Size != 0)
+ if (Size != 0U)
{
- hcryp->CrypInCount = Size + hcryp->Init.HeaderSize;
+ hcryp->CrypInCount = (uint32_t)(Size + hcryp->Init.HeaderSize);
hcryp->pCrypInBuffPtr = pInputData;
}
else
{
- hcryp->CrypInCount = hcryp->Init.HeaderSize;
+ hcryp->CrypInCount = (uint32_t)hcryp->Init.HeaderSize;
hcryp->pCrypInBuffPtr = hcryp->Init.Header;
}
}
else
{
/* Get the header addresses and sizes */
- hcryp->CrypInCount = hcryp->Init.HeaderSize;
+ hcryp->CrypInCount = (uint32_t)hcryp->Init.HeaderSize;
hcryp->pCrypInBuffPtr = hcryp->Init.Header;
}
@@ -1081,7 +1108,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
__HAL_CRYP_ENABLE(hcryp);
/* Increment/decrement instance pointer/counter */
- if (hcryp->CrypInCount == 0)
+ if (hcryp->CrypInCount == 0U)
{
/* Case of no header */
hcryp->State = HAL_CRYP_STATE_READY;
@@ -1089,17 +1116,17 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
hcryp->Phase = HAL_CRYP_PHASE_HEADER_OVER;
return HAL_OK;
}
- else if (hcryp->CrypInCount < 16)
+ else if (hcryp->CrypInCount < 16U)
{
hcryp->CrypInCount = 0;
addhoc_process = 1;
difflength = (uint32_t) (hcryp->Init.HeaderSize);
- difflengthmod4 = difflength%4;
+ difflengthmod4 = difflength%4U;
}
else
{
hcryp->pCrypInBuffPtr += 16;
- hcryp->CrypInCount -= 16;
+ hcryp->CrypInCount -= 16U;
}
@@ -1120,35 +1147,35 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
/* Enter header first block to initiate the process
in the Data Input register */
- if (addhoc_process == 0)
+ if (addhoc_process == 0U)
{
/* Header has size equal or larger than 128 bits */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
else
{
/* Header has size less than 128 bits */
/* Enter complete words when possible */
- for( ; index < (difflength/4); index ++)
+ for(index=0U ; index < (difflength/4U); index ++)
{
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
}
/* Enter incomplete word padded with zeroes if applicable
(case of header length not a multiple of 32-bits) */
- if (difflengthmod4 != 0)
+ if (difflengthmod4 != 0U)
{
- hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1]);
+ hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
}
/* Pad with zero-words to reach 128-bit long block and wrap-up header feeding to the IP */
- for(index=0; index < (4 - ((difflength+3)/4)); index ++)
+ for(index=0U; index < (4U - ((difflength+3U)/4U)); index ++)
{
hcryp->Instance->DINR = 0;
}
@@ -1161,10 +1188,10 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
else if (hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE)
{
/* Get the buffer addresses and sizes */
- hcryp->CrypInCount = Size;
+ hcryp->CrypInCount = (uint32_t)Size;
hcryp->pCrypInBuffPtr = pInputData;
hcryp->pCrypOutBuffPtr = pOutputData;
- hcryp->CrypOutCount = Size;
+ hcryp->CrypOutCount = (uint32_t)Size;
inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
@@ -1189,7 +1216,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
}
/* Specific handling to manage payload size less than 128 bits */
- if (Size < 16)
+ if (Size < 16U)
{
difflength = (uint32_t) (Size);
#if defined(AES_CR_NPBLB)
@@ -1197,14 +1224,14 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
bytes in last block of payload */
if (READ_BIT(hcryp->Instance->CR, AES_CR_GCMPH) == CRYP_PAYLOAD_PHASE)
{
- if (((READ_BIT(hcryp->Instance->CR, AES_CR_CHMOD) == CRYP_CHAINMODE_AES_GCM_GMAC)
- && (READ_BIT(hcryp->Instance->CR, AES_CR_MODE) == CRYP_ALGOMODE_ENCRYPT))
- || ((READ_BIT(hcryp->Instance->CR, AES_CR_CHMOD) == CRYP_CHAINMODE_AES_CCM)
- && (READ_BIT(hcryp->Instance->CR, AES_CR_MODE) == CRYP_ALGOMODE_DECRYPT)))
+ uint32_t cr_temp = hcryp->Instance->CR;
+
+ if (((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_GCM_GMAC|CRYP_ALGOMODE_ENCRYPT))
+ || ((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_CCM|CRYP_ALGOMODE_DECRYPT)))
{
/* Set NPBLB field in writing the number of padding bytes
for the last block of payload */
- MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16 - difflength) << AES_POSITION_CR_NPBLB);
+ MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16U - difflength) << AES_POSITION_CR_NPBLB);
}
}
#else
@@ -1222,22 +1249,22 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
/* Insert the last block (which size is inferior to 128 bits) padded with zeroes,
to have a complete block of 128 bits */
- difflengthmod4 = difflength%4;
+ difflengthmod4 = difflength%4U;
/* Insert the last block (which size is inferior to 128 bits) padded with zeroes
to have a complete block of 128 bits */
- for(index=0; index < (difflength/4); index ++)
+ for(index=0U; index < (difflength/4U); index ++)
{
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
}
/* If required, manage input data size not multiple of 32 bits */
- if (difflengthmod4 != 0)
+ if (difflengthmod4 != 0U)
{
- hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1]);
+ hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
}
/* Wrap-up in padding with zero-words if applicable */
- for(index=0; index < (4 - ((difflength+3)/4)); index ++)
+ for(index=0U; index < (4U - ((difflength+3U)/4U)); index ++)
{
hcryp->Instance->DINR = 0;
}
@@ -1246,23 +1273,23 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
{
/* Increment/decrement instance pointer/counter */
hcryp->pCrypInBuffPtr += 16;
- hcryp->CrypInCount -= 16;
+ hcryp->CrypInCount -= 16U;
/* Enter payload first block to initiate the process
in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
}
/*==================================*/
/* GCM/GMAC/CCM or CMAC final phase */
/*==================================*/
- else if (hcryp->Init.GCMCMACPhase == CRYP_FINAL_PHASE)
+ else
{
hcryp->pCrypOutBuffPtr = pOutputData;
@@ -1281,32 +1308,32 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
{
- headerlength = hcryp->Init.HeaderSize * 8; /* Header length in bits */
- inputlength = Size * 8; /* Input length in bits */
+ headerlength = hcryp->Init.HeaderSize * 8U; /* Header length in bits */
+ inputlength = Size * 8U; /* Input length in bits */
/* Write the number of bits in the header on 64 bits followed by the number
of bits in the payload on 64 bits as well */
#if !defined(AES_CR_NPBLB)
if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
{
- hcryp->Instance->DINR = __RBIT((headerlength)>>32);
- hcryp->Instance->DINR = __RBIT(headerlength);
- hcryp->Instance->DINR = __RBIT((inputlength)>>32);
- hcryp->Instance->DINR = __RBIT(inputlength);
+ hcryp->Instance->DINR = __RBIT((uint32_t)((headerlength)>>32));
+ hcryp->Instance->DINR = __RBIT((uint32_t)headerlength);
+ hcryp->Instance->DINR = __RBIT((uint32_t)((inputlength)>>32));
+ hcryp->Instance->DINR = __RBIT((uint32_t)inputlength);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
{
- hcryp->Instance->DINR = __REV((headerlength)>>32);
- hcryp->Instance->DINR = __REV(headerlength);
- hcryp->Instance->DINR = __REV((inputlength)>>32);
- hcryp->Instance->DINR = __REV(inputlength);
+ hcryp->Instance->DINR = __REV((uint32_t)(headerlength>>32));
+ hcryp->Instance->DINR = __REV((uint32_t)headerlength);
+ hcryp->Instance->DINR = __REV((uint32_t)(inputlength>>32));
+ hcryp->Instance->DINR = __REV((uint32_t)inputlength);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
{
- hcryp->Instance->DINR = __ROR((headerlength)>>32, 16);
- hcryp->Instance->DINR = __ROR(headerlength, 16);
- hcryp->Instance->DINR = __ROR((inputlength)>>32, 16);
- hcryp->Instance->DINR = __ROR(inputlength, 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)((headerlength)>>32), 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)headerlength, 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)((inputlength)>>32), 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)inputlength, 16);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
{
@@ -1315,6 +1342,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
hcryp->Instance->DINR = (uint32_t)(inputlength>>32);
hcryp->Instance->DINR = (uint32_t)(inputlength);
}
+ else
+ {
+ /* Unspecified Data Type */
+ return HAL_ERROR;
+ }
#else
hcryp->Instance->DINR = (uint32_t)(headerlength>>32);
hcryp->Instance->DINR = (uint32_t)(headerlength);
@@ -1329,23 +1361,20 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
/* Enter the last block made of a 128-bit value formatted
from the original B0 packet. */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
+ else
+ {
+ /* Unspecified Chaining Mode */
+ return HAL_ERROR;
+ }
#endif
}
- /*=================================================*/
- /* case incorrect hcryp->Init.GCMCMACPhase setting */
- /*=================================================*/
- else
- {
- hcryp->State = HAL_CRYP_STATE_ERROR;
- return HAL_ERROR;
- }
return HAL_OK;
}
@@ -1389,20 +1418,24 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pIn
*/
HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData)
{
- uint32_t inputaddr = 0;
- uint32_t outputaddr = 0;
- uint32_t tagaddr = 0;
- uint64_t headerlength = 0;
- uint64_t inputlength = 0;
- uint64_t payloadlength = 0;
+ uint32_t inputaddr ;
+ uint32_t outputaddr ;
+ uint32_t tagaddr ;
+ uint64_t headerlength ;
+ uint64_t inputlength ;
+ uint64_t payloadlength ;
if (hcryp->State == HAL_CRYP_STATE_READY)
{
/* input/output parameters check */
- if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
+ if (hcryp->Init.GCMCMACPhase == CRYP_INIT_PHASE)
+ {
+ /* No processing required */
+ }
+ else if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
{
- if ((hcryp->Init.Header != NULL) && (hcryp->Init.HeaderSize == 0))
+ if ((hcryp->Init.Header != NULL) && (hcryp->Init.HeaderSize == 0U))
{
return HAL_ERROR;
}
@@ -1410,7 +1443,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM)
{
/* In case of CMAC or CCM header phase resumption, we can have pInputData = NULL and Size = 0 */
- if (((pInputData != NULL) && (Size == 0)) || ((pInputData == NULL) && (Size != 0)))
+ if (((pInputData != NULL) && (Size == 0U)) || ((pInputData == NULL) && (Size != 0U)))
{
return HAL_ERROR;
}
@@ -1418,7 +1451,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
#else
if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
{
- if ((pInputData == NULL) || (Size == 0))
+ if ((pInputData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -1427,7 +1460,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
}
else if (hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE)
{
- if ((pInputData != NULL) && (Size != 0) && (pOutputData == NULL))
+ if ((pInputData != NULL) && (Size != 0U) && (pOutputData == NULL))
{
return HAL_ERROR;
}
@@ -1445,6 +1478,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
}
#endif
}
+ else
+ {
+ /* Unspecified Phase */
+ return HAL_ERROR;
+ }
/* Process Locked */
@@ -1502,11 +1540,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
{
inputaddr = (uint32_t)pInputData;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
@@ -1533,10 +1571,10 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
}
inputaddr = (uint32_t)hcryp->Init.Header;
- if ((hcryp->Init.HeaderSize % 16) != 0)
+ if ((hcryp->Init.HeaderSize % 16U) != 0U)
{
- if (hcryp->Init.HeaderSize < 16)
+ if (hcryp->Init.HeaderSize < 16U)
{
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
CRYP_Padding(hcryp, (uint32_t) (hcryp->Init.HeaderSize), CRYP_POLLING_OFF);
@@ -1554,7 +1592,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
{
/* Local variable headerlength is a number of bytes multiple of 128 bits,
remaining header data (if any) are handled after this loop */
- headerlength = (((hcryp->Init.HeaderSize)/16)*16) ;
+ headerlength = (((hcryp->Init.HeaderSize)/16U)*16U) ;
/* Store the ending transfer point */
hcryp->pCrypInBuffPtr = hcryp->Init.Header + headerlength;
hcryp->CrypInCount = (uint32_t)(hcryp->Init.HeaderSize - headerlength); /* remainder */
@@ -1562,14 +1600,14 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
/* Set the input and output addresses and start DMA transfer */
/* (incomplete DMA transfer, will be wrapped up after completion of
the first one (initiated here) with data padding */
- CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, headerlength, 0);
+ CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, (uint16_t)headerlength, 0);
}
}
else
{
hcryp->CrypInCount = 0;
/* Set the input address and start DMA transfer */
- CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, hcryp->Init.HeaderSize, 0);
+ CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, (uint16_t)hcryp->Init.HeaderSize, 0);
}
}
/*============================================*/
@@ -1612,11 +1650,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
/* Specific handling to manage payload size less than 128 bits */
- if ((Size % 16) != 0)
+ if ((Size % 16U) != 0U)
{
inputaddr = (uint32_t)pInputData;
outputaddr = (uint32_t)pOutputData;
- if (Size < 16)
+ if (Size < 16U)
{
/* Block is now entered in polling mode, no actual gain in resorting to DMA */
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
@@ -1638,17 +1676,19 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
}
else
{
- payloadlength = (Size/16) * 16;
+ payloadlength = (Size/16U) * 16U;
/* Store the ending transfer points */
- hcryp->pCrypInBuffPtr = pInputData + payloadlength;
- hcryp->pCrypOutBuffPtr = pOutputData + payloadlength;
+ hcryp->pCrypInBuffPtr = pInputData;
+ hcryp->pCrypInBuffPtr += payloadlength;
+ hcryp->pCrypOutBuffPtr = pOutputData;
+ hcryp->pCrypOutBuffPtr += payloadlength;
hcryp->CrypInCount = (uint32_t)(Size - payloadlength); /* remainder */
/* Set the input and output addresses and start DMA transfer */
/* (incomplete DMA transfer, will be wrapped up with data padding
after completion of the one initiated here) */
- CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, payloadlength, outputaddr);
+ CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, (uint16_t)payloadlength, outputaddr);
}
}
else
@@ -1658,13 +1698,13 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
outputaddr = (uint32_t)pOutputData;
/* Set the input and output addresses and start DMA transfer */
- CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
+ CRYP_Authentication_SetDMAConfig(hcryp, inputaddr, (uint16_t)Size, outputaddr);
}
}
/*==================================*/
/* GCM/GMAC/CCM or CMAC final phase */
/*==================================*/
- else if (hcryp->Init.GCMCMACPhase == CRYP_FINAL_PHASE)
+ else
{
/* If coming from header phase (GMAC or CMAC case when applicable),
wait for CCF flag to be raised */
@@ -1696,31 +1736,31 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
{
- headerlength = hcryp->Init.HeaderSize * 8; /* Header length in bits */
- inputlength = Size * 8; /* input length in bits */
+ headerlength = hcryp->Init.HeaderSize * 8U; /* Header length in bits */
+ inputlength = Size * 8U; /* input length in bits */
/* Write the number of bits in the header on 64 bits followed by the number
of bits in the payload on 64 bits as well */
#if !defined(AES_CR_NPBLB)
if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
{
- hcryp->Instance->DINR = __RBIT((headerlength)>>32);
- hcryp->Instance->DINR = __RBIT(headerlength);
- hcryp->Instance->DINR = __RBIT((inputlength)>>32);
- hcryp->Instance->DINR = __RBIT(inputlength);
+ hcryp->Instance->DINR = __RBIT((uint32_t)(headerlength>>32));
+ hcryp->Instance->DINR = __RBIT((uint32_t)headerlength);
+ hcryp->Instance->DINR = __RBIT((uint32_t)(inputlength>>32));
+ hcryp->Instance->DINR = __RBIT((uint32_t)inputlength);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
{
- hcryp->Instance->DINR = __REV((headerlength)>>32);
- hcryp->Instance->DINR = __REV(headerlength);
- hcryp->Instance->DINR = __REV((inputlength)>>32);
- hcryp->Instance->DINR = __REV(inputlength);
+ hcryp->Instance->DINR = __REV((uint32_t)(headerlength>>32));
+ hcryp->Instance->DINR = __REV((uint32_t)headerlength);
+ hcryp->Instance->DINR = __REV((uint32_t)(inputlength>>32));
+ hcryp->Instance->DINR = __REV((uint32_t)inputlength);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
{
- hcryp->Instance->DINR = __ROR((headerlength)>>32, 16);
- hcryp->Instance->DINR = __ROR(headerlength, 16);
- hcryp->Instance->DINR = __ROR((inputlength)>>32, 16);
- hcryp->Instance->DINR = __ROR(inputlength, 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)(headerlength>>32), 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)headerlength, 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)(inputlength>>32), 16);
+ hcryp->Instance->DINR = __ROR((uint32_t)inputlength, 16);
}
else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
{
@@ -1729,6 +1769,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
hcryp->Instance->DINR = (uint32_t)(inputlength>>32);
hcryp->Instance->DINR = (uint32_t)(inputlength);
}
+ else
+ {
+ /* Unspecified Data Type */
+ return HAL_ERROR;
+ }
#else
hcryp->Instance->DINR = (uint32_t)(headerlength>>32);
hcryp->Instance->DINR = (uint32_t)(headerlength);
@@ -1745,13 +1790,18 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
/* Enter the last block made of a 128-bit value formatted
from the original B0 packet. */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
+ else
+ {
+ /* Unspecified Chaining Mode */
+ return HAL_ERROR;
+ }
#endif
/* No DMA transfer is required at that point therefore, the software
@@ -1765,11 +1815,11 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
/* Read the Auth TAG in the IN FIFO */
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
- tagaddr+=4;
+ tagaddr+=4U;
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
- tagaddr+=4;
+ tagaddr+=4U;
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
- tagaddr+=4;
+ tagaddr+=4U;
*(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
/* Clear CCF Flag */
@@ -1782,15 +1832,6 @@ HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pI
__HAL_CRYP_DISABLE(hcryp);
}
- /*=================================================*/
- /* case incorrect hcryp->Init.GCMCMACPhase setting */
- /*=================================================*/
- else
- {
- hcryp->State = HAL_CRYP_STATE_ERROR;
- __HAL_UNLOCK(hcryp);
- return HAL_ERROR;
- }
/* Process Unlocked */
__HAL_UNLOCK(hcryp);
@@ -1841,11 +1882,11 @@ void HAL_CRYPEx_Read_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output)
uint32_t outputaddr = (uint32_t)Output;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR3);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR2);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR1);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR0);
}
@@ -1865,11 +1906,11 @@ void HAL_CRYPEx_Write_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input)
uint32_t ivaddr = (uint32_t)Input;
hcryp->Instance->IVR3 = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->IVR2 = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->IVR1 = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->IVR0 = __REV(*(uint32_t*)(ivaddr));
}
@@ -1910,19 +1951,19 @@ void HAL_CRYPEx_Read_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output
}
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP7R);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP6R);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP5R);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP4R);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP3R);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP2R);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP1R);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP0R);
}
@@ -1940,19 +1981,19 @@ void HAL_CRYPEx_Write_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input
uint32_t ivaddr = (uint32_t)Input;
hcryp->Instance->SUSP7R = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->SUSP6R = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->SUSP5R = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->SUSP4R = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->SUSP3R = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->SUSP2R = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->SUSP1R = __REV(*(uint32_t*)(ivaddr));
- ivaddr+=4;
+ ivaddr+=4U;
hcryp->Instance->SUSP0R = __REV(*(uint32_t*)(ivaddr));
}
@@ -1974,21 +2015,21 @@ void HAL_CRYPEx_Read_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output, ui
if (KeySize == CRYP_KEYSIZE_256B)
{
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR7);
- keyaddr+=4;
+ keyaddr+=4U;
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR6);
- keyaddr+=4;
+ keyaddr+=4U;
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR5);
- keyaddr+=4;
+ keyaddr+=4U;
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR4);
- keyaddr+=4;
+ keyaddr+=4U;
}
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR3);
- keyaddr+=4;
+ keyaddr+=4U;
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR2);
- keyaddr+=4;
+ keyaddr+=4U;
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR1);
- keyaddr+=4;
+ keyaddr+=4U;
*(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR0);
}
@@ -2009,21 +2050,21 @@ void HAL_CRYPEx_Write_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input, ui
if (KeySize == CRYP_KEYSIZE_256B)
{
hcryp->Instance->KEYR7 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR6 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR5 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR4 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
}
hcryp->Instance->KEYR3 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR2 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR1 = __REV(*(uint32_t*)(keyaddr));
- keyaddr+=4;
+ keyaddr+=4U;
hcryp->Instance->KEYR0 = __REV(*(uint32_t*)(keyaddr));
}
@@ -2039,7 +2080,7 @@ void HAL_CRYPEx_Write_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input, ui
*/
void HAL_CRYPEx_Read_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Output)
{
- *(uint32_t*)(Output) = hcryp->Instance->CR;
+ *(uint32_t*)(void *)(Output) = hcryp->Instance->CR; /* Derogation MisraC2012 R.11.5 */
}
/**
@@ -2053,7 +2094,7 @@ void HAL_CRYPEx_Read_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Output)
*/
void HAL_CRYPEx_Write_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Input)
{
- hcryp->Instance->CR = *(uint32_t*)(Input);
+ hcryp->Instance->CR = *(uint32_t*)(void *)(Input); /* Derogation MisraC2012 R.11.5 */
/* At the same time, set handle state back to READY to be able to resume the AES calculations
without the processing APIs returning HAL_BUSY when called. */
hcryp->State = HAL_CRYP_STATE_READY;
@@ -2100,9 +2141,8 @@ void HAL_CRYPEx_ProcessSuspend(CRYP_HandleTypeDef *hcryp)
*/
static void CRYP_Authentication_DMAInCplt(DMA_HandleTypeDef *hdma)
{
- uint32_t difflength = 0;
-
- CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
+ uint32_t difflength;
+ CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
/* Disable the DMA transfer for input request */
CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
@@ -2110,7 +2150,7 @@ static void CRYP_Authentication_DMAInCplt(DMA_HandleTypeDef *hdma)
if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
{
- if (hcryp->CrypInCount != 0)
+ if (hcryp->CrypInCount != 0U)
{
/* Last block is now entered in polling mode, no actual gain in resorting to DMA */
difflength = hcryp->CrypInCount;
@@ -2145,8 +2185,8 @@ static void CRYP_Authentication_DMAInCplt(DMA_HandleTypeDef *hdma)
*/
static void CRYP_Authentication_DMAOutCplt(DMA_HandleTypeDef *hdma)
{
- uint32_t difflength = 0;
- CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
+ uint32_t difflength;
+ CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
/* Disable the DMA transfer for output request */
CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
@@ -2155,7 +2195,7 @@ static void CRYP_Authentication_DMAOutCplt(DMA_HandleTypeDef *hdma)
__HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
/* Initiate additional transfer to wrap-up data feeding to the IP */
- if (hcryp->CrypInCount != 0)
+ if (hcryp->CrypInCount != 0U)
{
/* Last block is now entered in polling mode, no actual gain in resorting to DMA */
difflength = hcryp->CrypInCount;
@@ -2185,7 +2225,7 @@ static void CRYP_Authentication_DMAOutCplt(DMA_HandleTypeDef *hdma)
*/
static void CRYP_Authentication_DMAError(DMA_HandleTypeDef *hdma)
{
- CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
+ CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
hcryp->State= HAL_CRYP_STATE_ERROR;
hcryp->ErrorCode |= HAL_CRYP_DMA_ERROR;
@@ -2211,19 +2251,21 @@ static void CRYP_Authentication_DMAError(DMA_HandleTypeDef *hdma)
*/
HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
{
- uint32_t inputaddr = 0x0;
- uint32_t outputaddr = 0x0;
- uint32_t index = 0x0;
+ uint32_t inputaddr ;
+ uint32_t outputaddr ;
+ uint32_t index ;
uint32_t addhoc_process = 0;
uint32_t difflength = 0;
uint32_t difflengthmod4 = 0;
- uint32_t mask[4][3] = { {0xFF000000, 0xFFFF0000, 0xFFFFFF00}, /* 32-bit data */
- {0x0000FF00, 0x0000FFFF, 0xFF00FFFF}, /* 16-bit data */
- {0x000000FF, 0x0000FFFF, 0x00FFFFFF}, /* 8-bit data */
- {0x000000FF, 0x0000FFFF, 0x00FFFFFF}}; /* Bit data */
+ uint32_t mask[4][3] ;
uint32_t mask_index = hcryp->Init.DataType >> AES_CR_DATATYPE_Pos;
uint32_t intermediate_data[4] = {0};
+ mask[0][0] = 0xFF000000U; mask[0][1] = 0xFFFF0000U; mask[0][2] = 0xFFFFFF00U; /* 32-bit data */
+ mask[1][0] = 0x0000FF00U; mask[1][1] = 0x0000FFFFU; mask[1][2] = 0xFF00FFFFU; /* 16-bit data */
+ mask[2][0] = 0x000000FFU; mask[2][1] = 0x0000FFFFU; mask[2][2] = 0x00FFFFFFU; /* 8-bit data */
+ mask[3][0] = 0x000000FFU; mask[3][1] = 0x0000FFFFU; mask[3][2] = 0x00FFFFFFU; /* Bit data */
+
if(hcryp->State == HAL_CRYP_STATE_BUSY)
{
/*===========================*/
@@ -2257,7 +2299,7 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
else if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
{
/* Check if all input header data have been entered */
- if (hcryp->CrypInCount == 0)
+ if (hcryp->CrypInCount == 0U)
{
/* Clear Computation Complete Flag */
__HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
@@ -2308,17 +2350,17 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
/* Increment/decrement instance pointer/counter */
- if (hcryp->CrypInCount < 16)
+ if (hcryp->CrypInCount < 16U)
{
difflength = hcryp->CrypInCount;
hcryp->CrypInCount = 0;
addhoc_process = 1;
- difflengthmod4 = difflength%4;
+ difflengthmod4 = difflength%4U;
}
else
{
hcryp->pCrypInBuffPtr += 16;
- hcryp->CrypInCount -= 16;
+ hcryp->CrypInCount -= 16U;
}
#if defined(AES_CR_NPBLB)
@@ -2337,34 +2379,34 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
}
/* Write the Input block in the Data Input register */
- if (addhoc_process == 0)
+ if (addhoc_process == 0U)
{
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
else
{
/* Header remainder has size less than 128 bits */
/* Enter complete words when possible */
- for( ; index < (difflength/4); index ++)
+ for(index=0U ; index < (difflength/4U); index ++)
{
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
}
/* Enter incomplete word padded with zeroes if applicable
(case of header length not a multiple of 32-bits) */
- if (difflengthmod4 != 0)
+ if (difflengthmod4 != 0U)
{
- hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1]);
+ hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
}
/* Pad with zero-words to reach 128-bit long block and wrap-up header feeding to the IP */
- for(index=0; index < (4 - ((difflength+3)/4)); index ++)
+ for(index=0U; index < (4U - ((difflength+3U)/4U)); index ++)
{
hcryp->Instance->DINR = 0;
}
@@ -2385,38 +2427,37 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
when GCM (or CCM when applicable) encryption or decryption is selected.
Check here if the last block output data are read */
#if defined(AES_CR_NPBLB)
- if ((hcryp->CrypOutCount < 16) && \
- (hcryp->CrypOutCount > 0))
+ if ((hcryp->CrypOutCount < 16U) && \
+ (hcryp->CrypOutCount > 0U))
#else
if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) && \
- (hcryp->CrypOutCount < 16) && \
- (hcryp->CrypOutCount > 0))
+ (hcryp->CrypOutCount < 16U) && \
+ (hcryp->CrypOutCount > 0U))
#endif
{
- addhoc_process = 1;
difflength = hcryp->CrypOutCount;
- difflengthmod4 = difflength%4;
+ difflengthmod4 = difflength%4U;
hcryp->CrypOutCount = 0; /* mark that no more output data will be needed */
/* Retrieve intermediate data */
- for(index=0; index < 4; index ++)
+ for(index=0U ; index < 4U; index ++)
{
intermediate_data[index] = hcryp->Instance->DOUTR;
}
/* Retrieve last words of cyphered data */
/* First, retrieve complete output words */
- for(index=0; index < (difflength/4); index ++)
+ for(index=0U ; index < (difflength/4U); index ++)
{
*(uint32_t*)(outputaddr) = intermediate_data[index];
- outputaddr+=4;
+ outputaddr+=4U;
}
/* Next, retrieve partial output word if applicable;
at the same time, start masking intermediate data
with a mask of zeros of same size than the padding
applied to the last block of payload */
- if (difflengthmod4 != 0)
+ if (difflengthmod4 != 0U)
{
- intermediate_data[difflength/4] &= mask[mask_index][difflengthmod4-1];
- *(uint32_t*)(outputaddr) = intermediate_data[difflength/4];
+ intermediate_data[difflength/4U] &= mask[mask_index][difflengthmod4-1U];
+ *(uint32_t*)(outputaddr) = intermediate_data[difflength/4U];
}
#if !defined(AES_CR_NPBLB)
@@ -2430,15 +2471,15 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
/* Before inserting the intermediate data, carry on masking operation
with a mask of zeros of same size than the padding applied to the last block of payload */
- for(index=0; index < (4 - ((difflength+3)/4)); index ++)
+ for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
{
- intermediate_data[(difflength+3)/4+index] = 0;
+ intermediate_data[((difflength+3U)/4U)+index] = 0;
}
/* Insert intermediate data to trigger an additional DOUTR reading round */
/* Clear Computation Complete Flag before entering new block */
__HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
- for(index=0; index < 4; index ++)
+ for(index=0U ; index < 4U; index ++)
{
hcryp->Instance->DINR = intermediate_data[index];
}
@@ -2470,28 +2511,28 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
}
else
{
- if (hcryp->CrypOutCount != 0)
+ if (hcryp->CrypOutCount != 0U)
{
/* Usual case (different than GCM/CCM last block < 128 bits ciphering) */
/* Retrieve the last block available from the CRYP hardware block:
read the output block from the Data Output Register */
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
/* Increment/decrement instance pointer/counter */
hcryp->pCrypOutBuffPtr += 16;
- hcryp->CrypOutCount -= 16;
+ hcryp->CrypOutCount -= 16U;
}
#if !defined(AES_CR_NPBLB)
else
{
/* Software work-around: additional DOUTR reading round to discard the data */
- for(index=0; index < 4; index ++)
+ for(index=0U ; index < 4U; index ++)
{
intermediate_data[index] = hcryp->Instance->DOUTR;
}
@@ -2500,7 +2541,7 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
}
/* Check if all output text has been retrieved */
- if (hcryp->CrypOutCount == 0)
+ if (hcryp->CrypOutCount == 0U)
{
/* Clear Computation Complete Flag */
__HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
@@ -2552,24 +2593,26 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
/* Usual input data feeding case */
- if (hcryp->CrypInCount < 16)
+ if (hcryp->CrypInCount < 16U)
{
difflength = (uint32_t) (hcryp->CrypInCount);
- difflengthmod4 = difflength%4;
+ difflengthmod4 = difflength%4U;
hcryp->CrypInCount = 0;
#if defined(AES_CR_NPBLB)
/* In case of GCM encryption or CCM decryption, specify the number of padding
bytes in last block of payload */
- if (((READ_BIT(hcryp->Instance->CR, AES_CR_CHMOD) == CRYP_CHAINMODE_AES_GCM_GMAC)
- && (READ_BIT(hcryp->Instance->CR, AES_CR_MODE) == CRYP_ALGOMODE_ENCRYPT))
- || ((READ_BIT(hcryp->Instance->CR, AES_CR_CHMOD) == CRYP_CHAINMODE_AES_CCM)
- && (READ_BIT(hcryp->Instance->CR, AES_CR_MODE) == CRYP_ALGOMODE_DECRYPT)))
- {
- /* Set NPBLB field in writing the number of padding bytes
- for the last block of payload */
- MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16 - difflength) << AES_POSITION_CR_NPBLB);
- }
+ {
+ uint32_t cr_temp = hcryp->Instance->CR;
+
+ if (((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_GCM_GMAC|CRYP_ALGOMODE_ENCRYPT))
+ || ((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_CCM|CRYP_ALGOMODE_DECRYPT)))
+ {
+ /* Set NPBLB field in writing the number of padding bytes
+ for the last block of payload */
+ MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16U - difflength) << AES_POSITION_CR_NPBLB);
+ }
+ }
#else
/* Software workaround applied to GCM encryption only */
if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT)
@@ -2581,19 +2624,19 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
/* Insert the last block (which size is inferior to 128 bits) padded with zeroes
to have a complete block of 128 bits */
- for(index=0; index < (difflength/4); index ++)
+ for(index=0U ; index < (difflength/4U); index ++)
{
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
}
/* If required, manage input data size not multiple of 32 bits */
- if (difflengthmod4 != 0)
+ if (difflengthmod4 != 0U)
{
- hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1]);
+ hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
}
/* Wrap-up in padding with zero-words if applicable */
- for(index=0; index < (4 - ((difflength+3)/4)); index ++)
+ for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
{
hcryp->Instance->DINR = 0;
}
@@ -2602,15 +2645,15 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
else
{
hcryp->pCrypInBuffPtr += 16;
- hcryp->CrypInCount -= 16;
+ hcryp->CrypInCount -= 16U;
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
}
@@ -2632,11 +2675,11 @@ HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
/* Retrieve the last expected data from the CRYP hardware block:
read the output block from the Data Output Register */
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
/* Disable Computation Complete Flag and Errors Interrupts */
@@ -2696,7 +2739,7 @@ static void CRYP_Authentication_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t
/* Set the DMA error callback */
hcryp->hdmain->XferErrorCallback = CRYP_Authentication_DMAError;
- if (outputaddr != 0)
+ if (outputaddr != 0U)
{
/* Set the output CRYP DMA transfer complete callback */
hcryp->hdmaout->XferCpltCallback = CRYP_Authentication_DMAOutCplt;
@@ -2708,16 +2751,30 @@ static void CRYP_Authentication_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t
__HAL_CRYP_ENABLE(hcryp);
/* Enable the DMA input stream */
- HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, Size/4);
+ if (HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, ((uint32_t)Size)/4U) != HAL_OK)
+ {
+#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
+ hcryp->ErrorCallback(hcryp);
+#else
+ HAL_CRYP_ErrorCallback(hcryp);
+#endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
+ }
/* Enable the DMA input request */
SET_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
- if (outputaddr != 0)
+ if (outputaddr != 0U)
{
/* Enable the DMA output stream */
- HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, Size/4);
+ if (HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, ((uint32_t)Size)/4U) != HAL_OK)
+ {
+#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
+ hcryp->ErrorCallback(hcryp);
+#else
+ HAL_CRYP_ErrorCallback(hcryp);
+#endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
+ }
/* Enable the DMA output request */
SET_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
@@ -2738,22 +2795,22 @@ static void CRYP_Authentication_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t
*/
static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
{
- uint32_t index = 0;
+ uint32_t index;
uint32_t inputaddr = (uint32_t)Input;
uint32_t outputaddr = (uint32_t)Output;
- for(index=0; (index < Ilength); index += 16)
+ for(index=0U ; (index < Ilength); index += 16U)
{
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
/* Wait for CCF flag to be raised */
if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
@@ -2768,17 +2825,17 @@ static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* In
/* Read the Output block from the Data Output Register */
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
- outputaddr+=4;
+ outputaddr+=4U;
/* If the suspension flag has been raised and if the processing is not about
to end, suspend processing */
- if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < Ilength))
+ if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16U) < Ilength))
{
/* Reset SuspendRequest */
hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
@@ -2787,7 +2844,7 @@ static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* In
hcryp->pCrypOutBuffPtr = (uint8_t *)outputaddr;
hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
/* Save the number of bytes that remain to be processed at this point */
- hcryp->CrypInCount = Ilength - (index+16);
+ hcryp->CrypInCount = Ilength - (index+16U);
/* Change the CRYP state */
hcryp->State = HAL_CRYP_STATE_SUSPENDED;
@@ -2833,21 +2890,21 @@ static HAL_StatusTypeDef CRYP_ReadKey(CRYP_HandleTypeDef *hcryp, uint8_t* Output
if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B)
{
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR7);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR6);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR5);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR4);
- outputaddr+=4;
+ outputaddr+=4U;
}
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR3);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR2);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR1);
- outputaddr+=4;
+ outputaddr+=4U;
*(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR0);
@@ -2877,10 +2934,24 @@ static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uin
hcryp->hdmaout->XferErrorCallback = CRYP_DMAError;
/* Enable the DMA input stream */
- HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, Size/4);
+ if (HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, ((uint32_t)Size)/4U) != HAL_OK)
+ {
+#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
+ hcryp->ErrorCallback(hcryp);
+#else
+ HAL_CRYP_ErrorCallback(hcryp);
+#endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
+ }
/* Enable the DMA output stream */
- HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, Size/4);
+ if (HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, ((uint32_t)Size)/4U) != HAL_OK)
+ {
+#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
+ hcryp->ErrorCallback(hcryp);
+#else
+ HAL_CRYP_ErrorCallback(hcryp);
+#endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
+ }
/* Enable In and Out DMA requests */
SET_BIT(hcryp->Instance->CR, (AES_CR_DMAINEN | AES_CR_DMAOUTEN));
@@ -2897,9 +2968,9 @@ static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uin
* @param Timeout: Timeout duration.
* @retval HAL status
*/
-static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef *hcryp, uint32_t Timeout)
+static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef const * const hcryp, uint32_t Timeout)
{
- uint32_t tickstart = 0;
+ uint32_t tickstart;
/* Get timeout */
tickstart = HAL_GetTick();
@@ -2925,9 +2996,9 @@ static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef *hcryp, uint32_t T
* @param Timeout: Timeout duration.
* @retval HAL status
*/
-static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset(CRYP_HandleTypeDef *hcryp, uint32_t Timeout)
+static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset(CRYP_HandleTypeDef const * const hcryp, uint32_t Timeout)
{
- uint32_t tickstart = 0;
+ uint32_t tickstart;
/* Get timeout */
tickstart = HAL_GetTick();
@@ -2954,7 +3025,7 @@ static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset(CRYP_HandleTypeDef *hcryp, uin
*/
static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma)
{
- CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
+ CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
/* Disable the DMA transfer for input request */
CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
@@ -2974,7 +3045,7 @@ static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma)
*/
static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
{
- CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
+ CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
/* Disable the DMA transfer for output request */
CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
@@ -3003,7 +3074,7 @@ static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
*/
static void CRYP_DMAError(DMA_HandleTypeDef *hdma)
{
- CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
+ CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
hcryp->State= HAL_CRYP_STATE_ERROR;
hcryp->ErrorCode |= HAL_CRYP_DMA_ERROR;
@@ -3027,31 +3098,33 @@ static void CRYP_DMAError(DMA_HandleTypeDef *hdma)
*/
static void CRYP_Padding(CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_t polling)
{
- uint32_t index = 0;
- uint32_t difflengthmod4 = difflength%4;
+ uint32_t index;
+ uint32_t difflengthmod4 = difflength%4U;
uint32_t inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
uint32_t outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
- uint32_t mask[4][3] = { {0xFF000000, 0xFFFF0000, 0xFFFFFF00}, /* 32-bit data */
- {0x0000FF00, 0x0000FFFF, 0xFF00FFFF}, /* 16-bit data */
- {0x000000FF, 0x0000FFFF, 0x00FFFFFF}, /* 8-bit data */
- {0x000000FF, 0x0000FFFF, 0x00FFFFFF}}; /* Bit data */
+ uint32_t mask[4][3];
uint32_t mask_index = hcryp->Init.DataType >> AES_CR_DATATYPE_Pos;
uint32_t intermediate_data[4] = {0};
+ mask[0][0] = 0xFF000000U; mask[0][1] = 0xFFFF0000U; mask[0][2] = 0xFFFFFF00U; /* 32-bit data */
+ mask[1][0] = 0x0000FF00U; mask[1][1] = 0x0000FFFFU; mask[1][2] = 0xFF00FFFFU; /* 16-bit data */
+ mask[2][0] = 0x000000FFU; mask[2][1] = 0x0000FFFFU; mask[2][2] = 0x00FFFFFFU; /* 8-bit data */
+ mask[3][0] = 0x000000FFU; mask[3][1] = 0x0000FFFFU; mask[3][2] = 0x00FFFFFFU; /* Bit data */
+
#if defined(AES_CR_NPBLB)
/* In case of GCM encryption or CCM decryption, specify the number of padding
bytes in last block of payload */
if (READ_BIT(hcryp->Instance->CR,AES_CR_GCMPH) == CRYP_PAYLOAD_PHASE)
{
- if (((READ_BIT(hcryp->Instance->CR, AES_CR_CHMOD) == CRYP_CHAINMODE_AES_GCM_GMAC)
- && (READ_BIT(hcryp->Instance->CR, AES_CR_MODE) == CRYP_ALGOMODE_ENCRYPT))
- || ((READ_BIT(hcryp->Instance->CR, AES_CR_CHMOD) == CRYP_CHAINMODE_AES_CCM)
- && (READ_BIT(hcryp->Instance->CR, AES_CR_MODE) == CRYP_ALGOMODE_DECRYPT)))
+ uint32_t cr_temp = hcryp->Instance->CR;
+
+ if (((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_GCM_GMAC|CRYP_ALGOMODE_ENCRYPT))
+ || ((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_CCM|CRYP_ALGOMODE_DECRYPT)))
{
/* Set NPBLB field in writing the number of padding bytes
for the last block of payload */
- MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16 - difflength) << AES_POSITION_CR_NPBLB);
+ MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16U - difflength) << AES_POSITION_CR_NPBLB);
}
}
#else
@@ -3066,25 +3139,25 @@ static void CRYP_Padding(CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_
/* Wrap-up entering header or payload data */
/* Enter complete words when possible */
- for(index=0; index < (difflength/4); index ++)
+ for(index=0U ; index < (difflength/4U); index ++)
{
/* Write the Input block in the Data Input register */
hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
- inputaddr+=4;
+ inputaddr+=4U;
}
/* Enter incomplete word padded with zeroes if applicable
(case of header length not a multiple of 32-bits) */
- if (difflengthmod4 != 0)
+ if (difflengthmod4 != 0U)
{
- hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1]);
+ hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
}
/* Pad with zero-words to reach 128-bit long block and wrap-up header feeding to the IP */
- for(index=0; index < (4 - ((difflength+3)/4)); index ++)
+ for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
{
hcryp->Instance->DINR = 0;
}
- if (polling == CRYP_POLLING_ON)
+ if (polling == (uint32_t)CRYP_POLLING_ON)
{
if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
{
@@ -3106,25 +3179,25 @@ static void CRYP_Padding(CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_
{
/* Retrieve intermediate data */
- for(index=0; index < 4; index ++)
+ for(index=0U ; index < 4U; index ++)
{
intermediate_data[index] = hcryp->Instance->DOUTR;
}
/* Retrieve last words of cyphered data */
/* First, retrieve complete output words */
- for(index=0; index < (difflength/4); index ++)
+ for(index=0U ; index < (difflength/4U); index ++)
{
*(uint32_t*)(outputaddr) = intermediate_data[index];
- outputaddr+=4;
+ outputaddr+=4U;
}
/* Next, retrieve partial output word if applicable;
at the same time, start masking intermediate data
with a mask of zeros of same size than the padding
applied to the last block of payload */
- if (difflengthmod4 != 0)
+ if (difflengthmod4 != 0U)
{
- intermediate_data[difflength/4] &= mask[mask_index][difflengthmod4-1];
- *(uint32_t*)(outputaddr) = intermediate_data[difflength/4];
+ intermediate_data[difflength/4U] &= mask[mask_index][difflengthmod4-1U];
+ *(uint32_t*)(outputaddr) = intermediate_data[difflength/4U];
}
@@ -3141,12 +3214,12 @@ static void CRYP_Padding(CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_
/* Before inserting the intermediate data, carry on masking operation
with a mask of zeros of same size than the padding applied to the last block of payload */
- for(index=0; index < (4 - ((difflength+3)/4)); index ++)
+ for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
{
- intermediate_data[(difflength+3)/4+index] = 0;
+ intermediate_data[((difflength+3U)/4U)+index] = 0;
}
/* Insert intermediate data */
- for(index=0; index < 4; index ++)
+ for(index=0U ; index < 4U; index ++)
{
hcryp->Instance->DINR = intermediate_data[index];
}
@@ -3162,7 +3235,7 @@ static void CRYP_Padding(CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_
/* Read data to discard */
/* Clear CCF Flag */
__HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
- for(index=0; index < 4; index ++)
+ for(index=0U ; index < 4U; index ++)
{
intermediate_data[index] = hcryp->Instance->DOUTR;
}
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac.c
index ece455a744..e2e51adf8f 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac.c
@@ -47,7 +47,6 @@
(DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T3_TRGO...)
(#) Software using DAC_TRIGGER_SOFTWARE
-
*** DAC Buffer mode feature ***
===============================
[..]
@@ -317,7 +316,6 @@
******************************************************************************
*/
-
/* Includes ------------------------------------------------------------------*/
#include "stm32l4xx_hal.h"
@@ -325,21 +323,23 @@
* @{
*/
+#ifdef HAL_DAC_MODULE_ENABLED
+#if defined(DAC1)
+
/** @defgroup DAC DAC
* @brief DAC driver modules
* @{
*/
-#ifdef HAL_DAC_MODULE_ENABLED
-
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/** @addtogroup DAC_Private_Constants DAC Private Constants
* @{
*/
-#define TIMEOUT_DAC_CALIBCONFIG ((uint32_t)1) /* 1 ms */
-#define HFSEL_ENABLE_THRESHOLD_80MHZ ((uint32_t)80000000) /* 80 mHz */
+#define TIMEOUT_DAC_CALIBCONFIG 1U /* 1 ms */
+#define HFSEL_ENABLE_THRESHOLD_80MHZ 80000000U /* 80 MHz */
+
/**
* @}
*/
@@ -381,7 +381,7 @@ static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
/**
* @brief Initialize the DAC peripheral according to the specified parameters
* in the DAC_InitStruct and initialize the associated handle.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval HAL status
*/
@@ -413,10 +413,6 @@ HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
{
hdac->MspInitCallback = HAL_DAC_MspInit;
}
- if(hdac->MspDeInitCallback == NULL)
- {
- hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
- }
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
/* Allocate lock resource and initialize it */
@@ -446,7 +442,7 @@ HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
/**
* @brief Deinitialize the DAC peripheral registers to their default reset values.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval HAL status
*/
@@ -471,7 +467,6 @@ HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
}
/* DeInit the low level hardware */
hdac->MspDeInitCallback(hdac);
-
#else
/* DeInit the low level hardware */
HAL_DAC_MspDeInit(hdac);
@@ -492,7 +487,7 @@ HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
/**
* @brief Initialize the DAC MSP.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -508,7 +503,7 @@ __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
/**
* @brief DeInitialize the DAC MSP.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -546,9 +541,9 @@ __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
/**
* @brief Enables DAC and starts conversion of channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected (when supported)
@@ -595,7 +590,7 @@ HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
if(Channel == DAC_CHANNEL_1)
{
/* Check if software trigger enabled */
- if((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == (DAC_CR_TEN1 | DAC_CR_TSEL1))
+ if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_CR_TEN1)
{
/* Enable the selected DAC software conversion */
SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1);
@@ -604,7 +599,7 @@ HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
else
{
/* Check if software trigger enabled */
- if((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_CR_TEN2 | DAC_CR_TSEL2))
+ if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == DAC_CR_TEN2)
{
/* Enable the selected DAC software conversion*/
SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2);
@@ -634,9 +629,9 @@ HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
/**
* @brief Disables DAC and stop conversion of channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
@@ -660,14 +655,14 @@ HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
#if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
/**
* @brief Enables DAC and starts conversion of channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
- * @param pData: The destination peripheral Buffer address.
- * @param Length: The length of data to be transferred from memory to DAC peripheral
- * @param Alignment: Specifies the data alignment for DAC channel.
+ * @param pData The destination peripheral Buffer address.
+ * @param Length The length of data to be transferred from memory to DAC peripheral
+ * @param Alignment Specifies the data alignment for DAC channel.
* This parameter can be one of the following values:
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
@@ -676,7 +671,8 @@ HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
*/
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
{
- uint32_t tmpreg = 0;
+ HAL_StatusTypeDef status;
+ uint32_t tmpreg = 0U;
/* Check the parameters */
assert_param(IS_DAC_CHANNEL(Channel));
@@ -724,16 +720,23 @@ HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, u
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
/* Enable the DMA channel */
- HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
+ status = HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
/* Process Unlocked */
__HAL_UNLOCK(hdac);
- /* Enable the Peripheral */
- __HAL_DAC_ENABLE(hdac, Channel);
+ if (status == HAL_OK)
+ {
+ /* Enable the Peripheral */
+ __HAL_DAC_ENABLE(hdac, Channel);
+ }
+ else
+ {
+ hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
+ }
/* Return function status */
- return HAL_OK;
+ return status;
}
#endif /* STM32L451xx STM32L452xx STM32L462xx */
@@ -749,9 +752,9 @@ HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, u
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
- * @param pData: The destination peripheral Buffer address.
- * @param Length: The length of data to be transferred from memory to DAC peripheral
- * @param Alignment: Specifies the data alignment for DAC channel.
+ * @param pData The destination peripheral Buffer address.
+ * @param Length The length of data to be transferred from memory to DAC peripheral
+ * @param Alignment Specifies the data alignment for DAC channel.
* This parameter can be one of the following values:
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
@@ -760,7 +763,8 @@ HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, u
*/
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
{
- uint32_t tmpreg = 0;
+ HAL_StatusTypeDef status;
+ uint32_t tmpreg = 0U;
/* Check the parameters */
assert_param(IS_DAC_CHANNEL(Channel));
@@ -846,7 +850,7 @@ HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, u
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
/* Enable the DMA channel */
- HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
+ status = HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
}
else
{
@@ -854,17 +858,24 @@ HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, u
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
/* Enable the DMA channel */
- HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
+ status = HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
}
/* Process Unlocked */
__HAL_UNLOCK(hdac);
- /* Enable the Peripheral */
- __HAL_DAC_ENABLE(hdac, Channel);
+ if (status == HAL_OK)
+ {
+ /* Enable the Peripheral */
+ __HAL_DAC_ENABLE(hdac, Channel);
+ }
+ else
+ {
+ hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
+ }
/* Return function status */
- return HAL_OK;
+ return status;
}
#endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
/* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
@@ -872,9 +883,9 @@ HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, u
/**
* @brief Disables DAC and stop conversion of channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
@@ -882,13 +893,13 @@ HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, u
*/
HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
{
- HAL_StatusTypeDef status = HAL_OK;
+ HAL_StatusTypeDef status;
/* Check the parameters */
assert_param(IS_DAC_CHANNEL(Channel));
/* Disable the selected DAC channel DMA request */
- hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel);
+ hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << (Channel & 0x10UL));
/* Disable the Peripheral */
__HAL_DAC_DISABLE(hdac, Channel);
@@ -950,7 +961,7 @@ HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
* @brief Handles DAC interrupt request
* This function uses the interruption of DMA
* underrun.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -978,7 +989,7 @@ void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
hdac->DMAUnderrunCallbackCh1(hdac);
#else
HAL_DAC_DMAUnderrunCallbackCh1(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
}
}
#if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
@@ -998,7 +1009,7 @@ void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
/* Clear the underrun flag */
__HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2);
- /* Disable the selected DAC channel1 DMA request */
+ /* Disable the selected DAC channel2 DMA request */
CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN2);
/* Error callback */
@@ -1006,7 +1017,7 @@ void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
hdac->DMAUnderrunCallbackCh2(hdac);
#else
HAL_DACEx_DMAUnderrunCallbackCh2(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
}
}
#endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
@@ -1016,18 +1027,18 @@ void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
/**
* @brief Set the specified data holding register value for DAC channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
- * @param Alignment: Specifies the data alignment.
+ * @param Alignment Specifies the data alignment.
* This parameter can be one of the following values:
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
* @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
- * @param Data: Data to be loaded in the selected data holding register.
+ * @param Data Data to be loaded in the selected data holding register.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
@@ -1058,7 +1069,7 @@ HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, ui
/**
* @brief Conversion complete callback in non-blocking mode for Channel1
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -1074,7 +1085,7 @@ __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac)
/**
* @brief Conversion half DMA transfer callback in non-blocking mode for Channel1
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -1090,7 +1101,7 @@ __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)
/**
* @brief Error DAC callback for Channel1.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -1106,7 +1117,7 @@ __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac)
/**
* @brief DMA underrun DAC callback for channel1.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -1141,9 +1152,9 @@ __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac)
/**
* @brief Returns the last data output value of the selected DAC channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
@@ -1180,10 +1191,15 @@ uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
/**
* @brief Configures the selected DAC channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @note By calling this function, the high frequency interface mode (HFSEL bits)
+ * will be set. This parameter scope is the DAC instance. As the function
+ * is called for each channel, the @ref DAC_HighFrequency of @arg sConfig
+ * must be the same at each call.
+ * (or DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC self detect).
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param sConfig: DAC configuration structure.
- * @param Channel: The selected DAC channel.
+ * @param sConfig DAC configuration structure.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected (Whenever present)
@@ -1191,10 +1207,10 @@ uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
*/
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
{
- uint32_t tmpreg1 = 0, tmpreg2 = 0;
- uint32_t tickstart = 0;
+ uint32_t tmpreg1, tmpreg2;
+ uint32_t tickstart = 0U;
#if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
- uint32_t hclkfreq = 0;
+ uint32_t hclkfreq;
#endif /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
/* Check the DAC parameters */
@@ -1233,8 +1249,8 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConf
/* Get timeout */
tickstart = HAL_GetTick();
- /* SHSR1 can be written when BWST1 equals RESET */
- while (((hdac->Instance->SR) & DAC_SR_BWST1)!= RESET)
+ /* SHSR1 can be written when BWST1 is cleared */
+ while (((hdac->Instance->SR) & DAC_SR_BWST1) != 0UL)
{
/* Check for the Timeout */
if((HAL_GetTick() - tickstart) > TIMEOUT_DAC_CALIBCONFIG)
@@ -1254,9 +1270,9 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConf
#if !defined (STM32L451xx) & !defined (STM32L452xx) & !defined (STM32L462xx)
else /* Channel 2 */
{
- /* SHSR2 can be written when BWST2 equals RESET */
+ /* SHSR2 can be written when BWST2 is cleared */
- while (((hdac->Instance->SR) & DAC_SR_BWST2)!= RESET)
+ while (((hdac->Instance->SR) & DAC_SR_BWST2) != 0UL)
{
/* Check for the Timeout */
if((HAL_GetTick() - tickstart) > TIMEOUT_DAC_CALIBCONFIG)
@@ -1276,9 +1292,9 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConf
#endif /* STM32L451xx STM32L452xx STM32L462xx */
/* HoldTime */
- MODIFY_REG (hdac->Instance->SHHR, DAC_SHHR_THOLD1<DAC_SampleAndHoldConfig.DAC_HoldTime)<Instance->SHHR, DAC_SHHR_THOLD1 << (Channel & 0x10UL), (sConfig->DAC_SampleAndHoldConfig.DAC_HoldTime) << (Channel & 0x10UL));
/* RefreshTime */
- MODIFY_REG (hdac->Instance->SHRR, DAC_SHRR_TREFRESH1<DAC_SampleAndHoldConfig.DAC_RefreshTime)<Instance->SHRR, DAC_SHRR_TREFRESH1 << (Channel & 0x10UL), (sConfig->DAC_SampleAndHoldConfig.DAC_RefreshTime) << (Channel & 0x10UL));
}
if(sConfig->DAC_UserTrimming == DAC_TRIMMING_USER)
@@ -1287,11 +1303,11 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConf
/* Get the DAC CCR value */
tmpreg1 = hdac->Instance->CCR;
/* Clear trimming value */
- tmpreg1 &= ~(((uint32_t)(DAC_CCR_OTRIM1)) << Channel);
+ tmpreg1 &= ~(((uint32_t)(DAC_CCR_OTRIM1)) << (Channel & 0x10UL));
/* Configure for the selected trimming offset */
tmpreg2 = sConfig->DAC_TrimmingValue;
/* Calculate CCR register value depending on DAC_Channel */
- tmpreg1 |= tmpreg2 << Channel;
+ tmpreg1 |= tmpreg2 << (Channel & 0x10UL);
/* Write to DAC CCR */
hdac->Instance->CCR = tmpreg1;
}
@@ -1300,27 +1316,27 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConf
/* Get the DAC MCR value */
tmpreg1 = hdac->Instance->MCR;
- /* Clear DAC_MCR_MODE2_0, DAC_MCR_MODE2_1 and DAC_MCR_MODE2_2 bits */
- tmpreg1 &= ~(((uint32_t)(DAC_MCR_MODE1)) << Channel);
+ /* Clear DAC_MCR_MODEx bits */
+ tmpreg1 &= ~(((uint32_t)(DAC_MCR_MODE1)) << (Channel & 0x10UL));
/* Configure for the selected DAC channel: mode, buffer output & on chip peripheral connect */
tmpreg2 = (sConfig->DAC_SampleAndHold | sConfig->DAC_OutputBuffer | sConfig->DAC_ConnectOnChipPeripheral);
/* Calculate MCR register value depending on DAC_Channel */
- tmpreg1 |= tmpreg2 << Channel;
+ tmpreg1 |= tmpreg2 << (Channel & 0x10UL);
/* Write to DAC MCR */
hdac->Instance->MCR = tmpreg1;
/* DAC in normal operating mode hence clear DAC_CR_CENx bit */
- CLEAR_BIT (hdac->Instance->CR, DAC_CR_CEN1 << Channel);
+ CLEAR_BIT(hdac->Instance->CR, DAC_CR_CEN1 << (Channel & 0x10UL));
/* Get the DAC CR value */
tmpreg1 = hdac->Instance->CR;
/* Clear TENx, TSELx, WAVEx and MAMPx bits */
- tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1)) << Channel);
+ tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1)) << (Channel & 0x10UL));
/* Configure for the selected DAC channel: trigger */
/* Set TSELx and TENx bits according to DAC_Trigger value */
- tmpreg2 = (sConfig->DAC_Trigger);
+ tmpreg2 = sConfig->DAC_Trigger;
/* Calculate CR register value depending on DAC_Channel */
- tmpreg1 |= tmpreg2 << Channel;
+ tmpreg1 |= tmpreg2 << (Channel & 0x10UL);
#if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
if(DAC_HIGH_FREQUENCY_INTERFACE_MODE_ABOVE_80MHZ == sConfig->DAC_HighFrequency)
{
@@ -1354,7 +1370,7 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConf
hdac->Instance->CR = tmpreg1;
/* Disable wave generation */
- hdac->Instance->CR &= ~(DAC_CR_WAVE1 << Channel);
+ hdac->Instance->CR &= ~(DAC_CR_WAVE1 << (Channel & 0x10UL));
/* Change DAC state */
hdac->State = HAL_DAC_STATE_READY;
@@ -1366,12 +1382,71 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConf
return HAL_OK;
}
+/**
+ * @}
+ */
+
+/** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
+ * @brief Peripheral State and Errors functions
+ *
+@verbatim
+ ==============================================================================
+ ##### Peripheral State and Errors functions #####
+ ==============================================================================
+ [..]
+ This subsection provides functions allowing to
+ (+) Check the DAC state.
+ (+) Check the DAC Errors.
+
+@endverbatim
+ * @{
+ */
+
+/**
+ * @brief return the DAC handle state
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
+ * the configuration information for the specified DAC.
+ * @retval HAL state
+ */
+HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef *hdac)
+{
+ /* Return DAC handle state */
+ return hdac->State;
+}
+
+
+/**
+ * @brief Return the DAC error code
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
+ * the configuration information for the specified DAC.
+ * @retval DAC Error Code
+ */
+uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
+{
+ return hdac->ErrorCode;
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup DAC_Exported_Functions
+ * @{
+ */
+
+/** @addtogroup DAC_Exported_Functions_Group1
+ * @{
+ */
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
/**
* @brief Register a User DAC Callback
* To be used instead of the weak (surcharged) predefined callback
* @param hdac DAC handle
- * @param CallbackID ID of the callback to be registered
+ * @param CallbackID ID of the callback to be registered
* This parameter can be one of the following values:
* @arg @ref HAL_DAC_ERROR_INVALID_CALLBACK DAC Error Callback ID
* @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 Complete Callback ID
@@ -1479,7 +1554,7 @@ HAL_StatusTypeDef HAL_DAC_RegisterCallback (DAC_HandleTypeDef *hdac, HAL_DAC_Cal
* @brief Unregister a User DAC Callback
* DAC Callback is redirected to the weak (surcharged) predefined callback
* @param hdac DAC handle
- * @param CallbackID ID of the callback to be unregistered
+ * @param CallbackID ID of the callback to be unregistered
* This parameter can be one of the following values:
* @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 tranfer Complete Callback ID
* @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID
@@ -1587,51 +1662,6 @@ HAL_StatusTypeDef HAL_DAC_UnRegisterCallback (DAC_HandleTypeDef *hdac, HAL_DAC_C
}
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
-
-/**
- * @}
- */
-
-/** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
- * @brief Peripheral State and Errors functions
- *
-@verbatim
- ==============================================================================
- ##### Peripheral State and Errors functions #####
- ==============================================================================
- [..]
- This subsection provides functions allowing to
- (+) Check the DAC state.
- (+) Check the DAC Errors.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief return the DAC handle state
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
- * the configuration information for the specified DAC.
- * @retval HAL state
- */
-HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac)
-{
- /* Return DAC handle state */
- return hdac->State;
-}
-
-
-/**
- * @brief Return the DAC error code
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
- * the configuration information for the specified DAC.
- * @retval DAC Error Code
- */
-uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
-{
- return hdac->ErrorCode;
-}
-
/**
* @}
*/
@@ -1646,50 +1676,49 @@ uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
/**
* @brief DMA conversion complete callback.
- * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
+ * @param hdma pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma)
{
- DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
+ DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
hdac->ConvCpltCallbackCh1(hdac);
#else
HAL_DAC_ConvCpltCallbackCh1(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
- hdac->State= HAL_DAC_STATE_READY;
+ hdac->State = HAL_DAC_STATE_READY;
}
/**
* @brief DMA half transfer complete callback.
- * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
+ * @param hdma pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma)
{
- DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
-
+ DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
/* Conversion complete callback */
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
hdac->ConvHalfCpltCallbackCh1(hdac);
#else
HAL_DAC_ConvHalfCpltCallbackCh1(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
}
/**
* @brief DMA error callback
- * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
+ * @param hdma pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
{
- DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
+ DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
/* Set DAC error code to DMA error */
hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
@@ -1698,22 +1727,23 @@ static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
hdac->ErrorCallbackCh1(hdac);
#else
HAL_DAC_ErrorCallbackCh1(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
- hdac->State= HAL_DAC_STATE_READY;
+ hdac->State = HAL_DAC_STATE_READY;
}
/**
* @}
*/
-#endif /* HAL_DAC_MODULE_ENABLED */
-
-
/**
* @}
*/
+#endif /* DAC1 */
+
+#endif /* HAL_DAC_MODULE_ENABLED */
+
/**
* @}
*/
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac_ex.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac_ex.c
index 79c8e2a405..55100ceb55 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac_ex.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac_ex.c
@@ -63,13 +63,15 @@
* @{
*/
+#ifdef HAL_DAC_MODULE_ENABLED
+
+#if defined(DAC1)
+
/** @defgroup DACEx DACEx
* @brief DAC Extended HAL module driver
* @{
*/
-#ifdef HAL_DAC_MODULE_ENABLED
-
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
@@ -102,12 +104,13 @@
/**
* @brief Enable or disable the selected DAC channel wave generation.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
- * DAC_CHANNEL_1 / DAC_CHANNEL_2
- * @param Amplitude: Select max triangle amplitude.
+ * @arg DAC_CHANNEL_1: DAC Channel1 selected
+ * @arg DAC_CHANNEL_2: DAC Channel2 selected
+ * @param Amplitude Select max triangle amplitude.
* This parameter can be one of the following values:
* @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
* @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
@@ -136,7 +139,7 @@ HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32
hdac->State = HAL_DAC_STATE_BUSY;
/* Enable the triangle wave generation for the selected DAC channel */
- MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), (DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL));
/* Change DAC state */
hdac->State = HAL_DAC_STATE_READY;
@@ -150,12 +153,13 @@ HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32
/**
* @brief Enable or disable the selected DAC channel wave generation.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Channel: The selected DAC channel.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
- * DAC_CHANNEL_1 / DAC_CHANNEL_2
- * @param Amplitude: Unmask DAC channel LFSR for noise wave generation.
+ * @arg DAC_CHANNEL_1: DAC Channel1 selected
+ * @arg DAC_CHANNEL_2: DAC Channel2 selected
+ * @param Amplitude Unmask DAC channel LFSR for noise wave generation.
* This parameter can be one of the following values:
* @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
* @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
@@ -184,7 +188,7 @@ HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t
hdac->State = HAL_DAC_STATE_BUSY;
/* Enable the noise wave generation for the selected DAC channel */
- MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), (DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL));
/* Change DAC state */
hdac->State = HAL_DAC_STATE_READY;
@@ -202,22 +206,22 @@ HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t
/**
* @brief Set the specified data holding register value for dual DAC channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param Alignment: Specifies the data alignment for dual channel DAC.
+ * @param Alignment Specifies the data alignment for dual channel DAC.
* This parameter can be one of the following values:
* DAC_ALIGN_8B_R: 8bit right data alignment selected
* DAC_ALIGN_12B_L: 12bit left data alignment selected
* DAC_ALIGN_12B_R: 12bit right data alignment selected
- * @param Data1: Data for DAC Channel2 to be loaded in the selected data holding register.
- * @param Data2: Data for DAC Channel1 to be loaded in the selected data holding register.
+ * @param Data1 Data for DAC Channel1 to be loaded in the selected data holding register.
+ * @param Data2 Data for DAC Channel2 to be loaded in the selected data holding register.
* @note In dual mode, a unique register access is required to write in both
* DAC channels at the same time.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
{
- uint32_t data = 0, tmp = 0;
+ uint32_t data, tmp;
/* Check the parameters */
assert_param(IS_DAC_ALIGN(Alignment));
@@ -227,11 +231,11 @@ HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Align
/* Calculate and set dual DAC data holding register value */
if (Alignment == DAC_ALIGN_8B_R)
{
- data = ((uint32_t)Data2 << 8) | Data1;
+ data = ((uint32_t)Data2 << 8U) | Data1;
}
else
{
- data = ((uint32_t)Data2 << 16) | Data1;
+ data = ((uint32_t)Data2 << 16U) | Data1;
}
tmp = (uint32_t)hdac->Instance;
@@ -246,7 +250,7 @@ HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Align
/**
* @brief Conversion complete callback in non-blocking mode for Channel2.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -262,7 +266,7 @@ __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
/**
* @brief Conversion half DMA transfer callback in non-blocking mode for Channel2.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -278,7 +282,7 @@ __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
/**
* @brief Error DAC callback for Channel2.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -294,7 +298,7 @@ __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
/**
* @brief DMA underrun DAC callback for Channel2.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval None
*/
@@ -313,10 +317,10 @@ __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
/**
* @brief Run the self calibration of one DAC channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param sConfig: DAC channel configuration structure.
- * @param Channel: The selected DAC channel.
+ * @param sConfig DAC channel configuration structure.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
@@ -329,19 +333,23 @@ HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelC
{
HAL_StatusTypeDef status = HAL_OK;
- __IO uint32_t tmp = 0;
- uint32_t trimmingvalue = 0;
+ __IO uint32_t tmp;
+ uint32_t trimmingvalue;
uint32_t delta;
/* store/restore channel configuration structure purpose */
- uint32_t oldmodeconfiguration = 0;
+ uint32_t oldmodeconfiguration;
/* Check the parameters */
assert_param(IS_DAC_CHANNEL(Channel));
/* Check the DAC handle allocation */
/* Check if DAC running */
- if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_BUSY))
+ if (hdac == NULL)
+ {
+ status = HAL_ERROR;
+ }
+ else if (hdac->State == HAL_DAC_STATE_BUSY)
{
status = HAL_ERROR;
}
@@ -351,13 +359,13 @@ HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelC
__HAL_LOCK(hdac);
/* Store configuration */
- oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << Channel));
+ oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << (Channel & 0x10UL)));
/* Disable the selected DAC channel */
- CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_EN1 << Channel));
+ CLEAR_BIT((hdac->Instance->CR), (DAC_CR_EN1 << (Channel & 0x10UL)));
/* Set mode in MCR for calibration */
- MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), 0);
+ MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), 0U);
/* Set DAC Channel1 DHR register to the middle value */
tmp = (uint32_t)hdac->Instance;
@@ -379,26 +387,26 @@ HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelC
#if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
#endif /* STM32L451xx STM32L452xx STM32L462xx */
- *(__IO uint32_t *) tmp = 0x0800;
+ *(__IO uint32_t *) tmp = 0x0800U;
/* Enable the selected DAC channel calibration */
/* i.e. set DAC_CR_CENx bit */
- SET_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
+ SET_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
/* Init trimming counter */
/* Medium value */
- trimmingvalue = 16;
- delta = 8;
- while (delta != 0)
+ trimmingvalue = 16U;
+ delta = 8U;
+ while (delta != 0U)
{
/* Set candidate trimming */
- MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
/* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
/* i.e. minimum time needed between two calibration steps */
HAL_Delay(1);
- if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL)))
{
/* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
trimmingvalue -= delta;
@@ -408,35 +416,35 @@ HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelC
/* DAC_SR_CAL_FLAGx is LOW try lower trimming */
trimmingvalue += delta;
}
- delta >>= 1;
+ delta >>= 1U;
}
/* Still need to check if right calibration is current value or one step below */
/* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */
/* Set candidate trimming */
- MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
/* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
/* i.e. minimum time needed between two calibration steps */
- HAL_Delay(1);
+ HAL_Delay(1U);
- if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == 0UL)
{
/* OPAMP_CSR_OUTCAL is actually one value more */
trimmingvalue++;
/* Set right trimming */
- MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
}
/* Disable the selected DAC channel calibration */
/* i.e. clear DAC_CR_CENx bit */
- CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
+ CLEAR_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
sConfig->DAC_TrimmingValue = trimmingvalue;
sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
/* Restore configuration */
- MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), oldmodeconfiguration);
+ MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), oldmodeconfiguration);
/* Process unlocked */
__HAL_UNLOCK(hdac);
@@ -447,14 +455,14 @@ HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelC
/**
* @brief Set the trimming mode and trimming value (user trimming mode applied).
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
- * @param sConfig: DAC configuration structure updated with new DAC trimming value.
- * @param Channel: The selected DAC channel.
+ * @param sConfig DAC configuration structure updated with new DAC trimming value.
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
- * @param NewTrimmingValue: DAC new trimming value
+ * @param NewTrimmingValue DAC new trimming value
* @retval HAL status
*/
@@ -477,7 +485,7 @@ HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_Channe
__HAL_LOCK(hdac);
/* Set new trimming */
- MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (NewTrimmingValue << (Channel & 0x10UL)));
/* Update trimming mode */
sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
@@ -491,8 +499,8 @@ HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_Channe
/**
* @brief Return the DAC trimming value.
- * @param hdac : DAC handle
- * @param Channel: The selected DAC channel.
+ * @param hdac DAC handle
+ * @param Channel The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
@@ -502,23 +510,11 @@ HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_Channe
uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
{
- uint32_t trimmingvalue = 0;
-
- /* Check the DAC handle allocation */
- /* And not in Reset state */
- if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_RESET))
- {
- return HAL_ERROR;
- }
- else
- {
/* Check the parameter */
assert_param(IS_DAC_CHANNEL(Channel));
/* Retrieve trimming */
- trimmingvalue = ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << Channel)) >> Channel);
- }
- return trimmingvalue;
+ return ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << (Channel & 0x10UL))) >> (Channel & 0x10UL));
}
/**
@@ -537,7 +533,6 @@ uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
##### Peripheral Control functions #####
==============================================================================
[..] This section provides functions allowing to:
- (+) Configure channels.
(+) Set the specified data holding register value for DAC channel.
@endverbatim
@@ -546,17 +541,17 @@ uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
/**
* @brief Return the last data output value of the selected DAC channel.
- * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
+ * @param hdac pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @retval The selected DAC channel data output value.
*/
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
{
- uint32_t tmp = 0;
+ uint32_t tmp = 0U;
tmp |= hdac->Instance->DOR1;
- tmp |= hdac->Instance->DOR2 << 16;
+ tmp |= hdac->Instance->DOR2 << 16U;
/* Returns the DAC channel data output register value */
return tmp;
@@ -586,7 +581,7 @@ uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
/**
* @brief DMA conversion complete callback.
- * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
+ * @param hdma pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
@@ -598,32 +593,31 @@ void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
hdac->ConvCpltCallbackCh2(hdac);
#else
HAL_DACEx_ConvCpltCallbackCh2(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
hdac->State= HAL_DAC_STATE_READY;
}
/**
* @brief DMA half transfer complete callback.
- * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
+ * @param hdma pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
{
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
-
/* Conversion complete callback */
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
hdac->ConvHalfCpltCallbackCh2(hdac);
#else
HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
}
/**
* @brief DMA error callback.
- * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
+ * @param hdma pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
@@ -638,7 +632,8 @@ void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
hdac->ErrorCallbackCh2(hdac);
#else
HAL_DACEx_ErrorCallbackCh2(hdac);
-#endif
+#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
+
hdac->State= HAL_DAC_STATE_READY;
}
@@ -649,12 +644,14 @@ void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
/* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
/* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
-#endif /* HAL_DAC_MODULE_ENABLED */
-
/**
* @}
*/
+#endif /* DAC1 */
+
+#endif /* HAL_DAC_MODULE_ENABLED */
+
/**
* @}
*/
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dcmi.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dcmi.c
index c4c1734b24..327c672f4c 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dcmi.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dcmi.c
@@ -202,17 +202,13 @@
* @}
*/
-#define NPRIME 16
+#define NPRIME 16U
/**
* @}
*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
-uint32_t PrimeArray[NPRIME] = { 1, 2, 3, 5,
- 7, 11, 13, 17,
- 19, 23, 29, 31,
- 37, 41, 43, 47};
/* Private function prototypes -----------------------------------------------*/
/** @addtogroup DCMI_Private_Functions DCMI Private Functions
* @{
@@ -486,7 +482,7 @@ __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
*/
HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
{
- uint32_t circular_copy_length = 0;
+ uint32_t circular_copy_length;
/* Check capture parameter */
assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
@@ -509,7 +505,7 @@ HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mo
/* Set the dma abort callback */
hdcmi->DMA_Handle->XferAbortCallback = NULL;
- if(Length <= 0xFFFF)
+ if(Length <= 0xFFFFU)
{
hdcmi->XferCount = 0; /* Mark as direct transfer from DCMI_DR register to final destination buffer */
@@ -543,7 +539,7 @@ HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mo
circular_copy_length = DCMI_TransferSize(Length);
/* Check if issue in intermediate length computation */
- if (circular_copy_length == 0)
+ if (circular_copy_length == 0U)
{
/* Set state back to Ready */
hdcmi->State = HAL_DCMI_STATE_READY;
@@ -555,9 +551,9 @@ HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mo
}
/* Store the number of half - intermediate buffer copies needed */
- hdcmi->XferCount = 2 * ((Length / circular_copy_length) - 1);
+ hdcmi->XferCount = 2U * ((Length / circular_copy_length) - 1U);
/* Store the half-buffer copy length */
- hdcmi->HalfCopyLength = circular_copy_length / 2;
+ hdcmi->HalfCopyLength = circular_copy_length / 2U;
/* DCMI DR samples in circular mode will be copied
at the end of the final buffer.
@@ -566,7 +562,7 @@ HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mo
hdcmi->pCircularBuffer = pData;
/* Update pCircularBuffer in "moving" at the end of the final
buffer, don't forger to convert in bytes to compute exact address */
- hdcmi->pCircularBuffer += 4 * (((Length / circular_copy_length) - 1) * circular_copy_length);
+ hdcmi->pCircularBuffer += 4U * (((Length / circular_copy_length) - 1U) * circular_copy_length);
/* Initiate the circular DMA transfer from DCMI IP to final buffer end */
if ( HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)hdcmi->pCircularBuffer, circular_copy_length) != HAL_OK)
@@ -602,7 +598,7 @@ HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mo
*/
HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
{
- uint32_t tickstart = 0;
+ uint32_t tickstart;
HAL_StatusTypeDef status = HAL_OK;
/* Process locked */
@@ -618,7 +614,7 @@ HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
tickstart = HAL_GetTick();
/* Check if the DCMI capture is effectively disabled */
- while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0)
+ while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U)
{
if((HAL_GetTick() - tickstart ) > DCMI_TIMEOUT_STOP)
{
@@ -631,7 +627,10 @@ HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
}
/* Disable the DMA */
- HAL_DMA_Abort(hdcmi->DMA_Handle);
+ if (HAL_DMA_Abort(hdcmi->DMA_Handle) != HAL_OK)
+ {
+ DCMI_DMAError(hdcmi->DMA_Handle);
+ }
/* Disable DCMI IP */
__HAL_DCMI_DISABLE(hdcmi);
@@ -654,7 +653,7 @@ HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
*/
HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi)
{
- uint32_t tickstart = 0;
+ uint32_t tickstart;
/* Process locked */
__HAL_LOCK(hdcmi);
@@ -671,7 +670,7 @@ HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi)
tickstart = HAL_GetTick();
/* Check if the DCMI capture is effectively disabled */
- while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0)
+ while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U)
{
if((HAL_GetTick() - tickstart ) > DCMI_TIMEOUT_STOP)
{
@@ -733,7 +732,7 @@ void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
uint32_t misflags = READ_REG(hdcmi->Instance->MISR);
/* Synchronization error interrupt management *******************************/
- if ((misflags & DCMI_MIS_ERR_MIS) != RESET)
+ if ((misflags & DCMI_MIS_ERR_MIS) != 0x0U)
{
/* Clear the Synchronization error flag */
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
@@ -743,7 +742,7 @@ void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
}
/* Overflow interrupt management ********************************************/
- if ((misflags & DCMI_MIS_OVR_MIS) != RESET)
+ if ((misflags & DCMI_MIS_OVR_MIS) != 0x0U)
{
/* Clear the Overflow flag */
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
@@ -761,11 +760,14 @@ void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
/* Abort the DMA Transfer */
- HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
+ if (HAL_DMA_Abort_IT(hdcmi->DMA_Handle) != HAL_OK)
+ {
+ DCMI_DMAError(hdcmi->DMA_Handle);
+ }
}
/* Line Interrupt management ************************************************/
- if ((misflags & DCMI_MIS_LINE_MIS) != RESET)
+ if ((misflags & DCMI_MIS_LINE_MIS) != 0x0U)
{
/* Clear the Line interrupt flag */
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
@@ -780,7 +782,7 @@ void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
}
/* VSYNC interrupt management ***********************************************/
- if ((misflags & DCMI_MIS_VSYNC_MIS) != RESET)
+ if ((misflags & DCMI_MIS_VSYNC_MIS) != 0x0U)
{
/* Clear the VSYNC flag */
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
@@ -795,7 +797,7 @@ void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
}
/* End of Frame interrupt management ****************************************/
- if ((misflags & DCMI_MIS_FRAME_MIS) != RESET)
+ if ((misflags & DCMI_MIS_FRAME_MIS) != 0x0U)
{
/* Disable the Line interrupt when using snapshot mode */
if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
@@ -1080,7 +1082,7 @@ uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
* @brief DCMI Callback registering
* @param hdcmi dcmi handle
* @param CallbackID dcmi Callback ID
- * @param pCallback pointer to dcmi Callback function
+ * @param hdcmi pointer to dcmi Callback function
* @retval status
*/
HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback)
@@ -1261,14 +1263,15 @@ HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCM
*/
static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
{
- uint32_t loop_length = 0; /* transfer length */
- uint32_t * tmpBuffer_Dest = NULL;
- uint32_t * tmpBuffer_Orig = NULL;
+ uint32_t loop_length; /* transfer length */
+ uint32_t * tmpBuffer_Dest;
+ uint32_t * tmpBuffer_Orig;
+ uint32_t temp;
DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
- if(hdcmi->XferCount != 0)
+ if(hdcmi->XferCount != 0U)
{
/* Manage second half buffer copy in case of big transfer */
@@ -1280,13 +1283,15 @@ static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
/* Point at DCMI circular buffer mid-location */
tmpBuffer_Orig = (uint32_t *)hdcmi->pCircularBuffer;
- tmpBuffer_Orig += hdcmi->HalfCopyLength;
+ temp = (uint32_t) (tmpBuffer_Orig);
+ temp += hdcmi->HalfCopyLength;
+ tmpBuffer_Orig = (uint32_t *) temp;
/* copy half the buffer size */
loop_length = hdcmi->HalfCopyLength;
/* Save next entry to write at next half DMA transfer interruption */
- hdcmi->pBuffPtr += (uint32_t) loop_length*4;
+ hdcmi->pBuffPtr += (uint32_t) loop_length*4U;
hdcmi->XferSize -= hdcmi->HalfCopyLength;
/* Data copy from work buffer to final destination buffer */
@@ -1314,10 +1319,10 @@ static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
else
{
/* if End of frame IT is disabled */
- if((hdcmi->Instance->IER & DCMI_IT_FRAME) == RESET)
+ if((hdcmi->Instance->IER & DCMI_IT_FRAME) == 0x0U)
{
/* If End of Frame flag is set */
- if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET)
+ if(__HAL_DCMI_GET_FLAG(hdcmi, (uint32_t)DCMI_FLAG_FRAMERI) != 0x0UL)
{
/* Clear the End of Frame flag */
__HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
@@ -1359,13 +1364,13 @@ static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
*/
static void DCMI_DMAHalfXferCplt(DMA_HandleTypeDef *hdma)
{
- uint32_t loop_length = 0; /* transfer length */
- uint32_t * tmpBuffer_Dest = NULL;
- uint32_t * tmpBuffer_Orig = NULL;
+ uint32_t loop_length; /* transfer length */
+ uint32_t * tmpBuffer_Dest;
+ uint32_t * tmpBuffer_Orig;
DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
- if(hdcmi->XferCount != 0)
+ if(hdcmi->XferCount != 0U)
{
/* Manage first half buffer copy in case of big transfer */
@@ -1382,7 +1387,7 @@ static void DCMI_DMAHalfXferCplt(DMA_HandleTypeDef *hdma)
loop_length = hdcmi->HalfCopyLength;
/* Save next entry to write at next DMA transfer interruption */
- hdcmi->pBuffPtr += (uint32_t) loop_length*4;
+ hdcmi->pBuffPtr += (uint32_t) loop_length*4U;
hdcmi->XferSize -= hdcmi->HalfCopyLength;
/* Data copy from work buffer to final destination buffer */
@@ -1453,6 +1458,10 @@ static uint32_t DCMI_TransferSize(uint32_t InputSize)
uint32_t temp = InputSize;
uint32_t aPrime[NPRIME] = {0};
uint32_t output = 2; /* Want a result which is an even number */
+ uint32_t PrimeArray[NPRIME] = { 1UL, 2UL, 3UL, 5UL,
+ 7UL, 11UL, 13UL, 17UL,
+ 19UL, 23UL, 29UL, 31UL,
+ 37UL, 41UL, 43UL, 47UL};
/* Develop InputSize in product of prime numbers */
@@ -1463,7 +1472,7 @@ static uint32_t DCMI_TransferSize(uint32_t InputSize)
{
break;
}
- while ((temp % PrimeArray[j]) == 0)
+ while ((temp % PrimeArray[j]) == 0U)
{
aPrime[j]++;
temp /= PrimeArray[j];
@@ -1472,16 +1481,16 @@ static uint32_t DCMI_TransferSize(uint32_t InputSize)
}
/* Search for the biggest even divisor less or equal to 0xFFFE = 65534 */
- aPrime[1] -= 1; /* output is initialized to 2, so don't count dividor 2 twice */
+ aPrime[1] -= 1U; /* output is initialized to 2, so don't count dividor 2 twice */
/* The algorithm below yields a sub-optimal solution
but in an acceptable time. */
- j = NPRIME-1;
- while ((j > 0) && (output <= 0xFFFE))
+ j = NPRIME-1U;
+ while ((j > 0U) && (output <= 0xFFFEU))
{
- while (aPrime[j] >0)
+ while (aPrime[j] > 0U)
{
- if (output * PrimeArray[j] > 0xFFFE)
+ if ((output * PrimeArray[j]) > 0xFFFEU)
{
break;
}
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c
index 1179234ee6..7c8d9d97f5 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c
@@ -241,7 +241,7 @@ HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
/* Clear the DMAMUX synchro overrun flag */
hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
- if(((hdma->Init.Request > 0UL) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
+ if(((hdma->Init.Request > 0U) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
{
/* Initialize parameters for DMAMUX request generator :
DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask
@@ -374,7 +374,7 @@ HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
/* Reset Request generator parameters if any */
- if(((hdma->Init.Request > 0UL) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
+ if(((hdma->Init.Request > 0U) && (hdma->Init.Request <= DMA_REQUEST_GENERATOR3)))
{
/* Initialize parameters for DMAMUX request generator :
DMAmuxRequestGen, DMAmuxRequestGenStatus and DMAmuxRequestGenStatusMask
@@ -387,7 +387,7 @@ HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
/* Clear the DMAMUX request generator overrun flag */
hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
}
-
+
hdma->DMAmuxRequestGen = 0U;
hdma->DMAmuxRequestGenStatus = 0U;
hdma->DMAmuxRequestGenStatusMask = 0U;
@@ -1115,9 +1115,9 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t
#if defined(DMAMUX1)
/**
- * @brief Updates the DMA handle with the DMAMUX channel and status mask depending on stream number
+ * @brief Updates the DMA handle with the DMAMUX channel and status mask depending on channel number
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
- * the configuration information for the specified DMA Stream.
+ * the configuration information for the specified DMA Channel.
* @retval None
*/
static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma)
@@ -1145,7 +1145,7 @@ static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma)
/**
* @brief Updates the DMA handle with the DMAMUX request generator params
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
- * the configuration information for the specified DMA Stream.
+ * the configuration information for the specified DMA Channel.
* @retval None
*/
@@ -1160,7 +1160,6 @@ static void DMA_CalcDMAMUXRequestGenBaseAndMask(DMA_HandleTypeDef *hdma)
/* here "Request" is either DMA_REQUEST_GENERATOR0 to 4, i.e. <= 4*/
hdma->DMAmuxRequestGenStatusMask = 1UL << ((request - 1U) & 0x3U);
-
}
#endif /* DMAMUX1 */
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c
index 586d786124..2e9433536a 100644
--- a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c
@@ -133,8 +133,8 @@ HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSy
MODIFY_REG( hdma->DMAmuxChannel->CCR, \
(~DMAMUX_CxCR_DMAREQ_ID) , \
((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
- pSyncConfig->SyncPolarity | (pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
- (pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
+ pSyncConfig->SyncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
+ ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
/* Process UnLocked */
__HAL_UNLOCK(hdma);
diff --git a/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c
new file mode 100644
index 0000000000..f22844aa69
--- /dev/null
+++ b/system/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c
@@ -0,0 +1,659 @@
+/**
+ ******************************************************************************
+ * @file stm32l4xx_hal_exti.c
+ * @author MCD Application Team
+ * @brief EXTI HAL module driver.
+ * This file provides firmware functions to manage the following
+ * functionalities of the Extended Interrupts and events controller (EXTI) peripheral:
+ * + Initialization and de-initialization functions
+ * + IO operation functions
+ *
+ @verbatim
+ ==============================================================================
+ ##### EXTI Peripheral features #####
+ ==============================================================================
+ [..]
+ (+) Each Exti line can be configured within this driver.
+
+ (+) Exti line can be configured in 3 different modes
+ (++) Interrupt
+ (++) Event
+ (++) Both of them
+
+ (+) Configurable Exti lines can be configured with 3 different triggers
+ (++) Rising
+ (++) Falling
+ (++) Both of them
+
+ (+) When set in interrupt mode, configurable Exti lines have two different
+ interrupts pending registers which allow to distinguish which transition
+ occurs:
+ (++) Rising edge pending interrupt
+ (++) Falling
+
+ (+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can
+ be selected through multiplexer.
+
+ ##### How to use this driver #####
+ ==============================================================================
+ [..]
+
+ (#) Configure the EXTI line using HAL_EXTI_SetConfigLine().
+ (++) Choose the interrupt line number by setting "Line" member from
+ EXTI_ConfigTypeDef structure.
+ (++) Configure the interrupt and/or event mode using "Mode" member from
+ EXTI_ConfigTypeDef structure.
+ (++) For configurable lines, configure rising and/or falling trigger
+ "Trigger" member from EXTI_ConfigTypeDef structure.
+ (++) For Exti lines linked to gpio, choose gpio port using "GPIOSel"
+ member from GPIO_InitTypeDef structure.
+
+ (#) Get current Exti configuration of a dedicated line using
+ HAL_EXTI_GetConfigLine().
+ (++) Provide exiting handle as parameter.
+ (++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter.
+
+ (#) Clear Exti configuration of a dedicated line using HAL_EXTI_GetConfigLine().
+ (++) Provide exiting handle as parameter.
+
+ (#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback().
+ (++) Provide exiting handle as first parameter.
+ (++) Provide which callback will be registered using one value from
+ EXTI_CallbackIDTypeDef.
+ (++) Provide callback function pointer.
+
+ (#) Get interrupt pending bit using HAL_EXTI_GetPending().
+
+ (#) Clear interrupt pending bit using HAL_EXTI_GetPending().
+
+ (#) Generate software interrupt using HAL_EXTI_GenerateSWI().
+
+ @endverbatim
+ ******************************************************************************
+ * @attention
+ *
+ *