Fix adc initialization
This commit is contained in:
parent
e444ec908c
commit
6e861d4938
|
@ -44,7 +44,7 @@
|
|||
| IIC | 支持 | 软件模拟 |
|
||||
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
|
||||
| SPI | 支持 | SPI1/2/3 |
|
||||
| ADC | 支持 | |
|
||||
| ADC | 支持 | ADC1_IN1/ADC2_IN2/ADC3_IN3 |
|
||||
| TIME | 支持 | TIME15/16/17 |
|
||||
| **扩展模块** | **支持情况** | **备注** |
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -15,14 +15,17 @@ Mcu.UserName=STM32L476RGTx
|
|||
SPI1.VirtualType=VM_MASTER
|
||||
SPI2.VirtualType=VM_MASTER
|
||||
PB10.Mode=Full_Duplex_Master
|
||||
ADC2.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_2
|
||||
SH.ADCx_IN2.0=ADC2_IN2,IN2-Single-Ended
|
||||
PC10.Signal=SPI3_SCK
|
||||
PC12.Signal=SPI3_MOSI
|
||||
RCC.PLLSAI1RoutputFreq_Value=64000000
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_RTC_Init-RTC-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_TIM15_Init-TIM15-false-HAL-true,9-MX_TIM16_Init-TIM16-false-HAL-true,10-MX_TIM17_Init-TIM17-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_RTC_Init-RTC-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_TIM15_Init-TIM15-false-HAL-true,9-MX_TIM16_Init-TIM16-false-HAL-true,10-MX_TIM17_Init-TIM17-false-HAL-true,11-MX_ADC1_Init-ADC1-false-HAL-true,12-MX_ADC2_Init-ADC2-false-HAL-true,13-MX_ADC3_Init-ADC3-false-HAL-true
|
||||
VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
|
||||
RCC.RTCFreq_Value=32768
|
||||
RCC.USART2Freq_Value=80000000
|
||||
PC15-OSC32_OUT\ (PC15).Mode=LSE-External-Oscillator
|
||||
ADC3.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_3
|
||||
PinOutPanel.RotationAngle=0
|
||||
RCC.MCO1PinFreq_Value=80000000
|
||||
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
|
||||
|
@ -31,56 +34,66 @@ PC14-OSC32_IN\ (PC14).Mode=LSE-External-Oscillator
|
|||
PA14\ (JTCK-SWCLK).Signal=SYS_JTCK-SWCLK
|
||||
RCC.I2C3Freq_Value=80000000
|
||||
RCC.LPTIM1Freq_Value=80000000
|
||||
Mcu.IP4=SPI2
|
||||
Mcu.IP4=RCC
|
||||
RCC.FCLKCortexFreq_Value=80000000
|
||||
Mcu.IP5=SPI3
|
||||
Mcu.IP5=RTC
|
||||
Mcu.IP2=ADC3
|
||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
Mcu.IP2=RTC
|
||||
Mcu.IP3=SPI1
|
||||
Mcu.IP0=NVIC
|
||||
Mcu.IP1=RCC
|
||||
Mcu.IP3=NVIC
|
||||
Mcu.IP0=ADC1
|
||||
Mcu.IP1=ADC2
|
||||
Mcu.UserConstants=
|
||||
RCC.VCOSAI1OutputFreq_Value=128000000
|
||||
RCC.SDMMCFreq_Value=64000000
|
||||
Mcu.ThirdPartyNb=0
|
||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||
RCC.HCLKFreq_Value=80000000
|
||||
Mcu.IPNb=11
|
||||
SH.ADCx_IN3.0=ADC3_IN3,IN3-Single-Ended
|
||||
Mcu.IPNb=14
|
||||
ProjectManager.PreviousToolchain=
|
||||
RCC.APB2TimFreq_Value=80000000
|
||||
SPI1.CalculateBaudRate=40.0 MBits/s
|
||||
SH.ADCx_IN3.ConfNb=1
|
||||
PC3.Signal=SPI2_MOSI
|
||||
Mcu.Pin6=PA5
|
||||
Mcu.Pin6=PA2
|
||||
RCC.SAI2Freq_Value=18285714.285714287
|
||||
Mcu.Pin7=PA6
|
||||
Mcu.Pin8=PA7
|
||||
Mcu.Pin9=PB10
|
||||
Mcu.Pin7=PA3
|
||||
Mcu.Pin8=PA5
|
||||
Mcu.Pin9=PA6
|
||||
RCC.AHBFreq_Value=80000000
|
||||
Mcu.Pin0=PC14-OSC32_IN (PC14)
|
||||
Mcu.Pin1=PC15-OSC32_OUT (PC15)
|
||||
Mcu.Pin2=PC2
|
||||
Mcu.Pin3=PC3
|
||||
Mcu.Pin2=PC0
|
||||
Mcu.Pin3=PC1
|
||||
RCC.USART3Freq_Value=80000000
|
||||
Mcu.Pin4=PA2
|
||||
Mcu.Pin5=PA3
|
||||
Mcu.Pin4=PC2
|
||||
Mcu.Pin5=PC3
|
||||
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_1
|
||||
ProjectManager.ProjectBuild=false
|
||||
RCC.HSE_VALUE=8000000
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
Mcu.IP10=USART2
|
||||
Mcu.IP10=TIM15
|
||||
USART2.VirtualMode-Asynchronous=VM_ASYNC
|
||||
RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE
|
||||
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
|
||||
RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE
|
||||
Mcu.IP12=TIM17
|
||||
Mcu.IP11=TIM16
|
||||
ProjectManager.FirmwarePackage=STM32Cube FW_L4 V1.15.1
|
||||
MxDb.Version=DB.5.0.60
|
||||
Mcu.IP13=USART2
|
||||
ProjectManager.BackupPrevious=false
|
||||
RCC.VCOInputFreq_Value=16000000
|
||||
SH.ADCx_IN1.ConfNb=1
|
||||
PB14.Mode=Full_Duplex_Master
|
||||
File.Version=6
|
||||
SPI2.CalculateBaudRate=40.0 MBits/s
|
||||
ADC3.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag
|
||||
RCC.PLLRCLKFreq_Value=80000000
|
||||
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
VP_TIM15_VS_ClockSourceINT.Signal=TIM15_VS_ClockSourceINT
|
||||
ProjectManager.HalAssertFull=false
|
||||
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5
|
||||
ProjectManager.ProjectName=CubeMX_Config
|
||||
Mcu.Package=LQFP64
|
||||
PA6.Signal=SPI1_MISO
|
||||
|
@ -89,15 +102,20 @@ SPI3.Mode=SPI_MODE_MASTER
|
|||
ProjectManager.ToolChainLocation=
|
||||
RCC.LSI_VALUE=32000
|
||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||
ADC3.Rank-0\#ChannelRegularConversion=1
|
||||
RCC.LSCOPinFreq_Value=32000
|
||||
ADC2.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5
|
||||
RCC.DFSDMFreq_Value=80000000
|
||||
PC11.Mode=Full_Duplex_Master
|
||||
ADC3.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE
|
||||
SH.ADCx_IN1.0=ADC1_IN1,IN1-Single-Ended
|
||||
RCC.PLLPoutputFreq_Value=22857142.85714286
|
||||
RCC.APB1TimFreq_Value=80000000
|
||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
RCC.LPUART1Freq_Value=80000000
|
||||
SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
||||
SPI2.Direction=SPI_DIRECTION_2LINES
|
||||
ADC2.Rank-0\#ChannelRegularConversion=1
|
||||
PA13\ (JTMS-SWDIO).Signal=SYS_JTMS-SWDIO
|
||||
ProjectManager.CustomerFirmwarePackage=
|
||||
PA3.Signal=USART2_RX
|
||||
|
@ -108,30 +126,37 @@ RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSI
|
|||
PA14\ (JTCK-SWCLK).Mode=Serial_Wire
|
||||
RCC.PLLQoutputFreq_Value=80000000
|
||||
ProjectManager.ProjectFileName=CubeMX_Config.ioc
|
||||
ADC1.Rank-0\#ChannelRegularConversion=1
|
||||
PA7.Mode=Full_Duplex_Master
|
||||
Mcu.PinsNb=20
|
||||
Mcu.PinsNb=23
|
||||
ProjectManager.NoMain=false
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
||||
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag,master
|
||||
ADC1.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE
|
||||
PC11.Signal=SPI3_MISO
|
||||
RCC.SWPMI1Freq_Value=80000000
|
||||
PC2.Signal=SPI2_MISO
|
||||
PC2.Signal=ADCx_IN3
|
||||
PC10.Mode=Full_Duplex_Master
|
||||
ProjectManager.DefaultFWLocation=true
|
||||
PC2.Mode=Full_Duplex_Master
|
||||
PC15-OSC32_OUT\ (PC15).Signal=RCC_OSC32_OUT
|
||||
VP_TIM16_VS_ClockSourceINT.Mode=Enable_Timer
|
||||
ProjectManager.DeletePrevious=true
|
||||
PC0.Signal=ADCx_IN1
|
||||
RCC.VCOSAI2OutputFreq_Value=128000000
|
||||
VP_TIM17_VS_ClockSourceINT.Signal=TIM17_VS_ClockSourceINT
|
||||
RCC.FamilyName=M
|
||||
PA3.Mode=Asynchronous
|
||||
ADC3.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5
|
||||
ProjectManager.TargetToolchain=MDK-ARM V5
|
||||
ADC2.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag
|
||||
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
||||
RCC.USBFreq_Value=64000000
|
||||
RCC.PLLSAI1PoutputFreq_Value=18285714.285714287
|
||||
PB10.Signal=SPI2_SCK
|
||||
PB14.Signal=SPI2_MISO
|
||||
RCC.PLLSAI2RoutputFreq_Value=64000000
|
||||
PA5.Signal=SPI1_SCK
|
||||
ADC2.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE
|
||||
PC12.Mode=Full_Duplex_Master
|
||||
board=custom
|
||||
RCC.VCOOutputFreq_Value=160000000
|
||||
|
@ -144,6 +169,7 @@ RCC.I2C1Freq_Value=80000000
|
|||
SPI1.Mode=SPI_MODE_MASTER
|
||||
RCC.LCDFreq_Value=32768
|
||||
RCC.RNGFreq_Value=64000000
|
||||
SH.ADCx_IN2.ConfNb=1
|
||||
RCC.PLLSAI1QoutputFreq_Value=64000000
|
||||
RCC.ADCFreq_Value=64000000
|
||||
VP_SYS_VS_Systick.Mode=SysTick
|
||||
|
@ -157,13 +183,18 @@ Mcu.Name=STM32L476R(C-E-G)Tx
|
|||
RCC.LPTIM2Freq_Value=80000000
|
||||
PA2.Signal=USART2_TX
|
||||
ProjectManager.UnderRoot=false
|
||||
Mcu.IP8=TIM16
|
||||
Mcu.IP9=TIM17
|
||||
Mcu.IP6=SYS
|
||||
Mcu.IP7=TIM15
|
||||
Mcu.IP8=SPI3
|
||||
Mcu.IP9=SYS
|
||||
Mcu.IP6=SPI1
|
||||
Mcu.IP7=SPI2
|
||||
ProjectManager.CoupleFile=false
|
||||
PA13\ (JTMS-SWDIO).Mode=Serial_Wire
|
||||
RCC.SYSCLKFreq_VALUE=80000000
|
||||
Mcu.Pin22=VP_TIM17_VS_ClockSourceINT
|
||||
Mcu.Pin20=VP_TIM15_VS_ClockSourceINT
|
||||
ADC1.master=1
|
||||
Mcu.Pin21=VP_TIM16_VS_ClockSourceINT
|
||||
ADC2.NbrOfConversionFlag=1
|
||||
RCC.PLLSAI2PoutputFreq_Value=18285714.285714287
|
||||
NVIC.ForceEnableDMAVector=true
|
||||
KeepUserPlacement=false
|
||||
|
@ -172,25 +203,28 @@ NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
|||
ProjectManager.CompilerOptimize=6
|
||||
VP_TIM15_VS_ClockSourceINT.Mode=Internal
|
||||
ProjectManager.HeapSize=0x200
|
||||
Mcu.Pin15=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin15=PC10
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
Mcu.Pin16=VP_SYS_VS_Systick
|
||||
Mcu.Pin13=PC11
|
||||
Mcu.Pin14=PC12
|
||||
Mcu.Pin19=VP_TIM17_VS_ClockSourceINT
|
||||
Mcu.Pin16=PC11
|
||||
Mcu.Pin13=PA13 (JTMS-SWDIO)
|
||||
Mcu.Pin14=PA14 (JTCK-SWCLK)
|
||||
Mcu.Pin19=VP_SYS_VS_Systick
|
||||
ProjectManager.ComputerToolchain=false
|
||||
Mcu.Pin17=VP_TIM15_VS_ClockSourceINT
|
||||
Mcu.Pin17=PC12
|
||||
RCC.HSI_VALUE=16000000
|
||||
Mcu.Pin18=VP_TIM16_VS_ClockSourceINT
|
||||
Mcu.Pin18=VP_RTC_VS_RTC_Activate
|
||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||
Mcu.Pin11=PA14 (JTCK-SWCLK)
|
||||
Mcu.Pin12=PC10
|
||||
ADC1.NbrOfConversionFlag=1
|
||||
Mcu.Pin11=PB10
|
||||
Mcu.Pin12=PB14
|
||||
RCC.PLLN=10
|
||||
Mcu.Pin10=PA13 (JTMS-SWDIO)
|
||||
Mcu.Pin10=PA7
|
||||
PA2.Mode=Asynchronous
|
||||
RCC.PWRFreq_Value=80000000
|
||||
RCC.I2C2Freq_Value=80000000
|
||||
RCC.APB1Freq_Value=80000000
|
||||
ADC3.NbrOfConversionFlag=1
|
||||
ProjectManager.DeviceId=STM32L476RGTx
|
||||
PC1.Signal=ADCx_IN2
|
||||
ProjectManager.LibraryCopy=2
|
||||
PA7.Signal=SPI1_MOSI
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
*/
|
||||
|
||||
#define HAL_MODULE_ENABLED
|
||||
/*#define HAL_ADC_MODULE_ENABLED */
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
/*#define HAL_CAN_MODULE_ENABLED */
|
||||
/*#define HAL_COMP_MODULE_ENABLED */
|
||||
|
|
|
@ -62,6 +62,10 @@
|
|||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
ADC_HandleTypeDef hadc1;
|
||||
ADC_HandleTypeDef hadc2;
|
||||
ADC_HandleTypeDef hadc3;
|
||||
|
||||
RTC_HandleTypeDef hrtc;
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
|
@ -90,6 +94,9 @@ static void MX_SPI3_Init(void);
|
|||
static void MX_TIM15_Init(void);
|
||||
static void MX_TIM16_Init(void);
|
||||
static void MX_TIM17_Init(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_ADC2_Init(void);
|
||||
static void MX_ADC3_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
|
@ -136,6 +143,9 @@ int main(void)
|
|||
MX_TIM15_Init();
|
||||
MX_TIM16_Init();
|
||||
MX_TIM17_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_ADC2_Init();
|
||||
MX_ADC3_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
@ -197,9 +207,18 @@ void SystemClock_Config(void)
|
|||
{
|
||||
Error_Handler();
|
||||
}
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART2;
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART2
|
||||
|RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
|
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSI;
|
||||
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
|
||||
PeriphClkInit.PLLSAI1.PLLSAI1N = 8;
|
||||
PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
|
||||
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
|
||||
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
|
||||
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_ADC1CLK;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
@ -212,6 +231,185 @@ void SystemClock_Config(void)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_ADC1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 0 */
|
||||
|
||||
/* USER CODE END ADC1_Init 0 */
|
||||
|
||||
ADC_MultiModeTypeDef multimode = {0};
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 1 */
|
||||
|
||||
/* USER CODE END ADC1_Init 1 */
|
||||
/** Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
||||
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||
hadc1.Init.LowPowerAutoWait = DISABLE;
|
||||
hadc1.Init.ContinuousConvMode = DISABLE;
|
||||
hadc1.Init.NbrOfConversion = 1;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.NbrOfDiscConversion = 1;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc1.Init.DMAContinuousRequests = DISABLE;
|
||||
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||
hadc1.Init.OversamplingMode = DISABLE;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure the ADC multi-mode
|
||||
*/
|
||||
multimode.Mode = ADC_MODE_INDEPENDENT;
|
||||
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_1;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC2 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_ADC2_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ADC2_Init 0 */
|
||||
|
||||
/* USER CODE END ADC2_Init 0 */
|
||||
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC2_Init 1 */
|
||||
|
||||
/* USER CODE END ADC2_Init 1 */
|
||||
/** Common config
|
||||
*/
|
||||
hadc2.Instance = ADC2;
|
||||
hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
||||
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
|
||||
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||
hadc2.Init.LowPowerAutoWait = DISABLE;
|
||||
hadc2.Init.ContinuousConvMode = DISABLE;
|
||||
hadc2.Init.NbrOfConversion = 1;
|
||||
hadc2.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc2.Init.NbrOfDiscConversion = 1;
|
||||
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc2.Init.DMAContinuousRequests = DISABLE;
|
||||
hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||
hadc2.Init.OversamplingMode = DISABLE;
|
||||
if (HAL_ADC_Init(&hadc2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_2;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC2_Init 2 */
|
||||
|
||||
/* USER CODE END ADC2_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC3 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_ADC3_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ADC3_Init 0 */
|
||||
|
||||
/* USER CODE END ADC3_Init 0 */
|
||||
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC3_Init 1 */
|
||||
|
||||
/* USER CODE END ADC3_Init 1 */
|
||||
/** Common config
|
||||
*/
|
||||
hadc3.Instance = ADC3;
|
||||
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
||||
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
|
||||
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||
hadc3.Init.LowPowerAutoWait = DISABLE;
|
||||
hadc3.Init.ContinuousConvMode = DISABLE;
|
||||
hadc3.Init.NbrOfConversion = 1;
|
||||
hadc3.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc3.Init.NbrOfDiscConversion = 1;
|
||||
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc3.Init.DMAContinuousRequests = DISABLE;
|
||||
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||
hadc3.Init.OversamplingMode = DISABLE;
|
||||
if (HAL_ADC_Init(&hadc3) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_3;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC3_Init 2 */
|
||||
|
||||
/* USER CODE END ADC3_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RTC Initialization Function
|
||||
* @param None
|
||||
|
|
|
@ -97,6 +97,163 @@ void HAL_MspInit(void)
|
|||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
static uint32_t HAL_RCC_ADC_CLK_ENABLED=0;
|
||||
|
||||
/**
|
||||
* @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};
|
||||
if(hadc->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
HAL_RCC_ADC_CLK_ENABLED++;
|
||||
if(HAL_RCC_ADC_CLK_ENABLED==1){
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
/**ADC1 GPIO Configuration
|
||||
PC0 ------> ADC1_IN1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
}
|
||||
else if(hadc->Instance==ADC2)
|
||||
{
|
||||
/* USER CODE BEGIN ADC2_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC2_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
HAL_RCC_ADC_CLK_ENABLED++;
|
||||
if(HAL_RCC_ADC_CLK_ENABLED==1){
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
/**ADC2 GPIO Configuration
|
||||
PC1 ------> ADC2_IN2
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN ADC2_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC2_MspInit 1 */
|
||||
}
|
||||
else if(hadc->Instance==ADC3)
|
||||
{
|
||||
/* USER CODE BEGIN ADC3_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC3_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
HAL_RCC_ADC_CLK_ENABLED++;
|
||||
if(HAL_RCC_ADC_CLK_ENABLED==1){
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
/**ADC3 GPIO Configuration
|
||||
PC2 ------> ADC3_IN3
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN ADC3_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC3_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_ENABLED--;
|
||||
if(HAL_RCC_ADC_CLK_ENABLED==0){
|
||||
__HAL_RCC_ADC_CLK_DISABLE();
|
||||
}
|
||||
|
||||
/**ADC1 GPIO Configuration
|
||||
PC0 ------> ADC1_IN1
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0);
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
else if(hadc->Instance==ADC2)
|
||||
{
|
||||
/* USER CODE BEGIN ADC2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
HAL_RCC_ADC_CLK_ENABLED--;
|
||||
if(HAL_RCC_ADC_CLK_ENABLED==0){
|
||||
__HAL_RCC_ADC_CLK_DISABLE();
|
||||
}
|
||||
|
||||
/**ADC2 GPIO Configuration
|
||||
PC1 ------> ADC2_IN2
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1);
|
||||
|
||||
/* USER CODE BEGIN ADC2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC2_MspDeInit 1 */
|
||||
}
|
||||
else if(hadc->Instance==ADC3)
|
||||
{
|
||||
/* USER CODE BEGIN ADC3_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC3_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
HAL_RCC_ADC_CLK_ENABLED--;
|
||||
if(HAL_RCC_ADC_CLK_ENABLED==0){
|
||||
__HAL_RCC_ADC_CLK_DISABLE();
|
||||
}
|
||||
|
||||
/**ADC3 GPIO Configuration
|
||||
PC2 ------> ADC3_IN3
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2);
|
||||
|
||||
/* USER CODE BEGIN ADC3_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC3_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RTC MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
|
@ -186,18 +343,18 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
|||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**SPI2 GPIO Configuration
|
||||
PC2 ------> SPI2_MISO
|
||||
PC3 ------> SPI2_MOSI
|
||||
PB10 ------> SPI2_SCK
|
||||
PB10 ------> SPI2_SCK
|
||||
PB14 ------> SPI2_MISO
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_14;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
|
@ -272,13 +429,13 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
|||
__HAL_RCC_SPI2_CLK_DISABLE();
|
||||
|
||||
/**SPI2 GPIO Configuration
|
||||
PC2 ------> SPI2_MISO
|
||||
PC3 ------> SPI2_MOSI
|
||||
PB10 ------> SPI2_SCK
|
||||
PB10 ------> SPI2_SCK
|
||||
PB14 ------> SPI2_MISO
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3);
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_3);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10);
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_14);
|
||||
|
||||
/* USER CODE BEGIN SPI2_MspDeInit 1 */
|
||||
|
||||
|
|
|
@ -166,6 +166,14 @@ menu "On-chip Peripheral Drivers"
|
|||
config BSP_USING_ADC1
|
||||
bool "Enable ADC1"
|
||||
default n
|
||||
|
||||
config BSP_USING_ADC2
|
||||
bool "Enable ADC2"
|
||||
default n
|
||||
|
||||
config BSP_USING_ADC3
|
||||
bool "Enable ADC3"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_ONCHIP_RTC
|
||||
|
|
Loading…
Reference in New Issue