incldued the slave present variable to check the neighbouring slave
This commit is contained in:
parent
b0ad31881d
commit
84c56e534e
File diff suppressed because one or more lines are too long
@ -35,7 +35,7 @@ extern "C" {
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
/* #define HAL_ADC_MODULE_ENABLED */
|
||||
/* #define HAL_CRC_MODULE_ENABLED */
|
||||
/* #define HAL_CRYP_MODULE_ENABLED */
|
||||
/* #define HAL_I2C_MODULE_ENABLED */
|
||||
|
@ -31,7 +31,16 @@ int main(void)
|
||||
HAL_GPIO_WritePin(GPIOA, Red_LED_OUT_Pin, GPIO_PIN_RESET); // Changed to GPIOA
|
||||
HAL_GPIO_WritePin(GPIOA, LR_OUT_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, RL_OUT_Pin, GPIO_PIN_RESET);
|
||||
// uint8_t slave_present = HAL_GPIO_ReadPin(GPIOA, Slave_Detect_Pin);
|
||||
|
||||
// if(slave_present == TRUE)
|
||||
// {
|
||||
// HAL_GPIO_WritePin(Last_Node_Switch_GPIO_Port, feed_back_Pin, GPIO_PIN_RESET);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// HAL_GPIO_WritePin(Last_Node_Switch_GPIO_Port, feed_back_Pin, GPIO_PIN_SET);
|
||||
// }
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -226,8 +235,8 @@ void Error_Handler(void)
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIOA, Amber_LED_OUT_Pin | Red_LED_OUT_Pin);
|
||||
HAL_Delay(500);
|
||||
// HAL_GPIO_TogglePin(GPIOA, Amber_LED_OUT_Pin | Red_LED_OUT_Pin);
|
||||
// HAL_Delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,79 +77,6 @@ void HAL_MspInit(void)
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hadc: ADC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(hadc->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
|
||||
/** Initializes the peripherals clocks
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**ADC1 GPIO Configuration
|
||||
PA8 ------> ADC1_IN8
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hadc: ADC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
if(hadc->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ADC_CLK_DISABLE();
|
||||
|
||||
/**ADC1 GPIO Configuration
|
||||
PA8 ------> ADC1_IN8
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8);
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,185 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32c0xx_hal_adc_ex.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file of ADC HAL extended module.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef STM32C0xx_HAL_ADC_EX_H
|
||||
#define STM32C0xx_HAL_ADC_EX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32c0xx_hal_def.h"
|
||||
|
||||
/** @addtogroup STM32C0xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup ADCEx
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/** @defgroup ADCEx_Exported_Types ADC Extended Exported Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ADCEx_Exported_Constants ADC Extended Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup ADC_HAL_EC_GROUPS ADC instance - Groups
|
||||
* @{
|
||||
*/
|
||||
#define ADC_REGULAR_GROUP (LL_ADC_GROUP_REGULAR) /*!< ADC group regular (available on all STM32 devices) */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ADCEx_Private_Macro_internal_HAL_driver ADC Extended Private Macros
|
||||
* @{
|
||||
*/
|
||||
/* Macro reserved for internal HAL driver usage, not intended to be used in */
|
||||
/* code of final user. */
|
||||
|
||||
/**
|
||||
* @brief Check whether or not ADC is independent.
|
||||
* @param __HANDLE__ ADC handle.
|
||||
* @note When multimode feature is not available, the macro always returns SET.
|
||||
* @retval SET (ADC is independent) or RESET (ADC is not).
|
||||
*/
|
||||
#define ADC_IS_INDEPENDENT(__HANDLE__) (SET)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calibration factor size verification (7 bits maximum).
|
||||
* @param __CALIBRATION_FACTOR__ Calibration factor value.
|
||||
* @retval SET (__CALIBRATION_FACTOR__ is within the authorized size) or RESET (__CALIBRATION_FACTOR__ is too large)
|
||||
*/
|
||||
#define IS_ADC_CALFACT(__CALIBRATION_FACTOR__) ((__CALIBRATION_FACTOR__) <= (0x7FU))
|
||||
|
||||
/**
|
||||
* @brief Verify the ADC oversampling ratio.
|
||||
* @param __RATIO__ programmed ADC oversampling ratio.
|
||||
* @retval SET (__RATIO__ is a valid value) or RESET (__RATIO__ is invalid)
|
||||
*/
|
||||
#define IS_ADC_OVERSAMPLING_RATIO(__RATIO__) (((__RATIO__) == ADC_OVERSAMPLING_RATIO_2 ) || \
|
||||
((__RATIO__) == ADC_OVERSAMPLING_RATIO_4 ) || \
|
||||
((__RATIO__) == ADC_OVERSAMPLING_RATIO_8 ) || \
|
||||
((__RATIO__) == ADC_OVERSAMPLING_RATIO_16 ) || \
|
||||
((__RATIO__) == ADC_OVERSAMPLING_RATIO_32 ) || \
|
||||
((__RATIO__) == ADC_OVERSAMPLING_RATIO_64 ) || \
|
||||
((__RATIO__) == ADC_OVERSAMPLING_RATIO_128 ) || \
|
||||
((__RATIO__) == ADC_OVERSAMPLING_RATIO_256 ))
|
||||
|
||||
/**
|
||||
* @brief Verify the ADC oversampling shift.
|
||||
* @param __SHIFT__ programmed ADC oversampling shift.
|
||||
* @retval SET (__SHIFT__ is a valid value) or RESET (__SHIFT__ is invalid)
|
||||
*/
|
||||
#define IS_ADC_RIGHT_BIT_SHIFT(__SHIFT__) (((__SHIFT__) == ADC_RIGHTBITSHIFT_NONE) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_1 ) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_2 ) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_3 ) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_4 ) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_5 ) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_6 ) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_7 ) || \
|
||||
((__SHIFT__) == ADC_RIGHTBITSHIFT_8 ))
|
||||
|
||||
/**
|
||||
* @brief Verify the ADC oversampling triggered mode.
|
||||
* @param __MODE__ programmed ADC oversampling triggered mode.
|
||||
* @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
|
||||
*/
|
||||
#define IS_ADC_TRIGGERED_OVERSAMPLING_MODE(__MODE__) (((__MODE__) == ADC_TRIGGEREDMODE_SINGLE_TRIGGER) || \
|
||||
((__MODE__) == ADC_TRIGGEREDMODE_MULTI_TRIGGER) )
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup ADCEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup ADCEx_Exported_Functions_Group1
|
||||
* @{
|
||||
*/
|
||||
/* IO operation functions *****************************************************/
|
||||
|
||||
/* ADC calibration */
|
||||
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc);
|
||||
uint32_t HAL_ADCEx_Calibration_GetValue(const ADC_HandleTypeDef *hadc);
|
||||
HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t CalibrationFactor);
|
||||
|
||||
/* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption) */
|
||||
void HAL_ADCEx_LevelOutOfWindow2Callback(ADC_HandleTypeDef *hadc);
|
||||
void HAL_ADCEx_LevelOutOfWindow3Callback(ADC_HandleTypeDef *hadc);
|
||||
void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef *hadc);
|
||||
void HAL_ADCEx_ChannelConfigReadyCallback(ADC_HandleTypeDef *hadc);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup ADCEx_Exported_Functions_Group2
|
||||
* @{
|
||||
*/
|
||||
/* Peripheral Control functions ***********************************************/
|
||||
HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef *hadc);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* STM32C0xx_HAL_ADC_EX_H */
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,417 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32c0xx_hal_adc_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides firmware functions to manage the following
|
||||
* functionalities of the Analog to Digital Converter (ADC)
|
||||
* peripheral:
|
||||
* + Operation functions
|
||||
* ++ Calibration
|
||||
* +++ ADC automatic self-calibration
|
||||
* +++ Calibration factors get or set
|
||||
* Other functions (generic functions) are available in file
|
||||
* "stm32c0xx_hal_adc.c".
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
[..]
|
||||
(@) Sections "ADC peripheral features" and "How to use this driver" are
|
||||
available in file of generic functions "stm32c0xx_hal_adc.c".
|
||||
[..]
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32c0xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32C0xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup ADCEx ADCEx
|
||||
* @brief ADC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ADCEx_Private_Constants ADC Extended Private Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Fixed timeout value for ADC calibration. */
|
||||
/* Values defined to be higher than worst cases: maximum ratio between ADC */
|
||||
/* and CPU clock frequencies. */
|
||||
/* Example of profile low frequency : ADC frequency at 31.25kHz (ADC clock */
|
||||
/* source 8MHz, ADC clock prescaler 256), CPU frequency 48MHz. */
|
||||
/* Calibration time max = 116 / fADC (refer to datasheet) */
|
||||
/* = 178 176 CPU cycles */
|
||||
#define ADC_CALIBRATION_TIMEOUT (178176UL) /*!< ADC calibration time-out value (unit: CPU cycles) */
|
||||
#define ADC_DISABLE_TIMEOUT (2UL)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ADCEx_Exported_Functions ADC Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup ADCEx_Exported_Functions_Group1 Extended Input and Output operation functions
|
||||
* @brief Extended IO operation functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### IO operation functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
|
||||
(+) Perform the ADC self-calibration.
|
||||
(+) Get calibration factors.
|
||||
(+) Set calibration factors.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Perform an ADC automatic self-calibration
|
||||
* Calibration prerequisite: ADC must be disabled (execute this
|
||||
* function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
|
||||
* @note Calibration factor can be read after calibration, using function
|
||||
* HAL_ADC_GetValue() (value on 7 bits: from DR[6;0]).
|
||||
* @param hadc ADC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
HAL_StatusTypeDef tmp_hal_status;
|
||||
__IO uint32_t wait_loop_index = 0UL;
|
||||
uint32_t backup_setting_cfgr1;
|
||||
uint32_t calibration_index;
|
||||
uint32_t calibration_factor_accumulated = 0;
|
||||
uint32_t tickstart;
|
||||
uint32_t adc_clk_async_presc;
|
||||
__IO uint32_t delay_cpu_cycles;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hadc);
|
||||
|
||||
/* Calibration prerequisite: ADC must be disabled. */
|
||||
|
||||
/* Disable the ADC (if not already disabled) */
|
||||
tmp_hal_status = ADC_Disable(hadc);
|
||||
|
||||
/* Check if ADC is effectively disabled */
|
||||
if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
|
||||
{
|
||||
/* Set ADC state */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_REG_BUSY,
|
||||
HAL_ADC_STATE_BUSY_INTERNAL);
|
||||
|
||||
/* Manage settings impacting calibration */
|
||||
/* - Disable ADC mode auto power-off */
|
||||
/* - Disable ADC DMA transfer request during calibration */
|
||||
/* Note: Specificity of this STM32 series: Calibration factor is */
|
||||
/* available in data register and also transferred by DMA. */
|
||||
/* To not insert ADC calibration factor among ADC conversion data */
|
||||
/* in array variable, DMA transfer must be disabled during */
|
||||
/* calibration. */
|
||||
backup_setting_cfgr1 = READ_BIT(hadc->Instance->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG | ADC_CFGR1_AUTOFF);
|
||||
CLEAR_BIT(hadc->Instance->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG | ADC_CFGR1_AUTOFF);
|
||||
|
||||
/* ADC calibration procedure */
|
||||
/* Note: Perform an averaging of 8 calibrations for optimized accuracy */
|
||||
for (calibration_index = 0UL; calibration_index < 8UL; calibration_index++)
|
||||
{
|
||||
/* Start ADC calibration */
|
||||
LL_ADC_StartCalibration(hadc->Instance);
|
||||
|
||||
/* Wait for calibration completion */
|
||||
while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
|
||||
{
|
||||
wait_loop_index++;
|
||||
if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)
|
||||
{
|
||||
/* Update ADC state machine to error */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
||||
HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
|
||||
__HAL_UNLOCK(hadc);
|
||||
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
calibration_factor_accumulated += LL_ADC_GetCalibrationFactor(hadc->Instance);
|
||||
}
|
||||
/* Compute average */
|
||||
calibration_factor_accumulated /= calibration_index;
|
||||
/* Apply calibration factor (requires ADC enable and disable process) */
|
||||
LL_ADC_Enable(hadc->Instance);
|
||||
|
||||
/* Case of ADC clocked at low frequency: Delay required between ADC enable and disable actions */
|
||||
if (LL_ADC_GetClock(hadc->Instance) == LL_ADC_CLOCK_ASYNC)
|
||||
{
|
||||
adc_clk_async_presc = LL_ADC_GetCommonClock(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
|
||||
|
||||
if (adc_clk_async_presc >= LL_ADC_CLOCK_ASYNC_DIV16)
|
||||
{
|
||||
/* Delay loop initialization and execution */
|
||||
/* Delay depends on ADC clock prescaler: Compute ADC clock asynchronous prescaler to decimal format */
|
||||
delay_cpu_cycles = (1UL << ((adc_clk_async_presc >> ADC_CCR_PRESC_Pos) - 3UL));
|
||||
/* Divide variable by 2 to compensate partially CPU processing cycles */
|
||||
delay_cpu_cycles >>= 1UL;
|
||||
|
||||
while (delay_cpu_cycles != 0UL)
|
||||
{
|
||||
delay_cpu_cycles--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LL_ADC_SetCalibrationFactor(hadc->Instance, calibration_factor_accumulated);
|
||||
LL_ADC_Disable(hadc->Instance);
|
||||
|
||||
/* Wait for ADC effectively disabled before changing configuration */
|
||||
/* Get tick count */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
while (LL_ADC_IsEnabled(hadc->Instance) != 0UL)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > ADC_DISABLE_TIMEOUT)
|
||||
{
|
||||
/* New check to avoid false timeout detection in case of preemption */
|
||||
if (LL_ADC_IsEnabled(hadc->Instance) != 0UL)
|
||||
{
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
|
||||
/* Set ADC error code to ADC peripheral internal error */
|
||||
SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
|
||||
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore configuration after calibration */
|
||||
SET_BIT(hadc->Instance->CFGR1, backup_setting_cfgr1);
|
||||
|
||||
/* Set ADC state */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
||||
HAL_ADC_STATE_READY);
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
|
||||
/* Note: No need to update variable "tmp_hal_status" here: already set */
|
||||
/* to state "HAL_ERROR" by function disabling the ADC. */
|
||||
}
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
|
||||
/* Return function status */
|
||||
return tmp_hal_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the calibration factor.
|
||||
* @param hadc ADC handle.
|
||||
* @retval Calibration value.
|
||||
*/
|
||||
uint32_t HAL_ADCEx_Calibration_GetValue(const ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
|
||||
|
||||
/* Return the selected ADC calibration value */
|
||||
return ((hadc->Instance->CALFACT) & 0x0000007FU);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the calibration factor to overwrite automatic conversion result.
|
||||
* ADC must be enabled and no conversion is ongoing.
|
||||
* @param hadc ADC handle
|
||||
* @param CalibrationFactor Calibration factor (coded on 7 bits maximum)
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t CalibrationFactor)
|
||||
{
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
uint32_t tmp_adc_is_conversion_on_going_regular;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
|
||||
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. */
|
||||
tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
|
||||
|
||||
if ((LL_ADC_IsEnabled(hadc->Instance) != 0UL)
|
||||
&& (tmp_adc_is_conversion_on_going_regular == 0UL)
|
||||
)
|
||||
{
|
||||
hadc->Instance->CALFACT &= ~ADC_CALFACT_CALFACT;
|
||||
hadc->Instance->CALFACT |= CalibrationFactor;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update ADC state machine */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
/* Update ADC error code */
|
||||
SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
|
||||
|
||||
/* Update ADC state machine to error */
|
||||
tmp_hal_status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
|
||||
/* Return function status */
|
||||
return tmp_hal_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analog watchdog 2 callback in non-blocking mode.
|
||||
* @param hadc ADC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_ADCEx_LevelOutOfWindow2Callback(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hadc);
|
||||
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_ADCEx_LevelOutOfWindow2Callback must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analog watchdog 3 callback in non-blocking mode.
|
||||
* @param hadc ADC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_ADCEx_LevelOutOfWindow3Callback(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hadc);
|
||||
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_ADCEx_LevelOutOfWindow3Callback must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief End Of Sampling callback in non-blocking mode.
|
||||
* @param hadc ADC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hadc);
|
||||
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_ADCEx_EndOfSamplingCallback must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC channel configuration ready callback in non-blocking mode.
|
||||
* @param hadc ADC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_ADCEx_ChannelConfigReadyCallback(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hadc);
|
||||
|
||||
/* NOTE : This function should not be modified. When the callback is needed,
|
||||
function HAL_ADCEx_ChannelConfigReadyCallback must be implemented in the user file.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Disable ADC voltage regulator.
|
||||
* @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.
|
||||
* @param hadc ADC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
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)
|
||||
{
|
||||
LL_ADC_DisableInternalRegulator(hadc->Instance);
|
||||
tmp_hal_status = HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_hal_status = HAL_ERROR;
|
||||
}
|
||||
|
||||
return tmp_hal_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -1,8 +1,4 @@
|
||||
#MicroXplorer Configuration settings - do not modify
|
||||
ADC1.IPParameters=NbrOfConversionFlag,master,SelectedChannel
|
||||
ADC1.NbrOfConversionFlag=0
|
||||
ADC1.SelectedChannel=ADC_CHANNEL_8
|
||||
ADC1.master=1
|
||||
CAD.formats=
|
||||
CAD.pinconfig=
|
||||
CAD.provider=
|
||||
@ -11,30 +7,28 @@ GPIO.groupedBy=Group By Peripherals
|
||||
KeepUserPlacement=false
|
||||
Mcu.CPN=STM32C011F6P6
|
||||
Mcu.Family=STM32C0
|
||||
Mcu.IP0=ADC1
|
||||
Mcu.IP1=CORTEX_M0+
|
||||
Mcu.IP2=DEBUG
|
||||
Mcu.IP3=NVIC
|
||||
Mcu.IP4=RCC
|
||||
Mcu.IP5=SYS
|
||||
Mcu.IPNb=6
|
||||
Mcu.IP0=CORTEX_M0+
|
||||
Mcu.IP1=DEBUG
|
||||
Mcu.IP2=NVIC
|
||||
Mcu.IP3=RCC
|
||||
Mcu.IP4=SYS
|
||||
Mcu.IPNb=5
|
||||
Mcu.Name=STM32C011F(4-6)Px
|
||||
Mcu.Package=TSSOP20
|
||||
Mcu.Pin0=PA0
|
||||
Mcu.Pin1=PA1
|
||||
Mcu.Pin10=PA12 [PA10]
|
||||
Mcu.Pin11=PA13
|
||||
Mcu.Pin12=PA14-BOOT0
|
||||
Mcu.Pin13=VP_SYS_VS_Systick
|
||||
Mcu.Pin10=PA13
|
||||
Mcu.Pin11=PA14-BOOT0
|
||||
Mcu.Pin12=VP_SYS_VS_Systick
|
||||
Mcu.Pin2=PA2
|
||||
Mcu.Pin3=PA3
|
||||
Mcu.Pin4=PA4
|
||||
Mcu.Pin5=PA5
|
||||
Mcu.Pin6=PA6
|
||||
Mcu.Pin7=PA7
|
||||
Mcu.Pin8=PA8
|
||||
Mcu.Pin9=PA11 [PA9]
|
||||
Mcu.PinsNb=14
|
||||
Mcu.Pin8=PA11 [PA9]
|
||||
Mcu.Pin9=PA12 [PA10]
|
||||
Mcu.PinsNb=13
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32C011F6Px
|
||||
@ -93,9 +87,6 @@ PA7.GPIOParameters=GPIO_Label
|
||||
PA7.GPIO_Label=Amber_LED_OUT
|
||||
PA7.Locked=true
|
||||
PA7.Signal=GPIO_Output
|
||||
PA8.Locked=true
|
||||
PA8.Mode=IN8
|
||||
PA8.Signal=ADC1_IN8
|
||||
PinOutPanel.RotationAngle=0
|
||||
ProjectManager.AskForMigrate=true
|
||||
ProjectManager.BackupPrevious=false
|
||||
@ -127,7 +118,7 @@ ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,0-MX_CORTEX_M0+_Init-CORTEX_M0+-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,0-MX_CORTEX_M0+_Init-CORTEX_M0+-false-HAL-true
|
||||
RCC.ADCFreq_Value=12000000
|
||||
RCC.AHBFreq_Value=12000000
|
||||
RCC.APBFreq_Value=12000000
|
||||
|
Loading…
Reference in New Issue
Block a user