@@ -35,7 +35,6 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
3535 return -1 ;
3636 }
3737
38-
3938 /* *Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
4039 */
4140 hadc.Instance = (ADC_TypeDef *)pinmap_peripheral (analogInputToPinName (cs_params->pins [0 ]), PinMap_ADC);
@@ -74,10 +73,15 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
7473 // https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h#L170C13-L170C27
7574 hadc.Init .DMAContinuousRequests = DISABLE;
7675 // not sure about this one!!! maybe use: ADC_SAMPLING_MODE_NORMAL
77- hadc.Init .SamplingMode = ADC_SAMPLING_MODE_TRIGGER_CONTROLED ;
76+ hadc.Init .SamplingMode = ADC_SAMPLING_MODE_BULB ;
7877#endif
7978 hadc.Init .NbrOfConversion = 1 ;
79+ hadc.Init .NbrOfDiscConversion = 0 ;
8080 hadc.Init .EOCSelection = ADC_EOC_SINGLE_CONV;
81+
82+ hadc.Init .LowPowerAutoWait = DISABLE;
83+
84+
8185 if ( HAL_ADC_Init (&hadc) != HAL_OK){
8286#ifdef SIMPLEFOC_STM32_DEBUG
8387 SIMPLEFOC_DEBUG (" STM32-CS: ERR: cannot init ADC!" );
@@ -91,16 +95,20 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
9195 // if ADC1 or ADC2
9296 if (hadc.Instance == ADC1 || hadc.Instance == ADC2){
9397 // more info here: https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h#L658
94- sConfigInjected .InjectedNbrOfConversion = ADC_SAMPLETIME_2CYCLE_5;
98+ sConfigInjected .InjectedSamplingTime = ADC_SAMPLETIME_2CYCLE_5;
9599 }else {
96100 // adc3
97101 // https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h#L673
98- sConfigInjected .InjectedNbrOfConversion = ADC3_SAMPLETIME_2CYCLES_5;
102+ sConfigInjected .InjectedSamplingTime = ADC3_SAMPLETIME_2CYCLES_5;
99103 }
100104 sConfigInjected .ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING;
101105 sConfigInjected .AutoInjectedConv = DISABLE;
102106 sConfigInjected .InjectedDiscontinuousConvMode = DISABLE;
103107 sConfigInjected .InjectedOffset = 0 ;
108+ sConfigInjected .InjectedSingleDiff = ADC_SINGLE_ENDED;
109+ sConfigInjected .InjectedOffsetNumber = ADC_OFFSET_NONE;
110+ sConfigInjected .QueueInjectedContext = DISABLE;
111+ sConfigInjected .InjecOversamplingMode = DISABLE;
104112
105113 // automating TRGO flag finding - hardware specific
106114 uint8_t tim_num = 0 ;
@@ -139,11 +147,11 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
139147#endif
140148 }
141149
150+ uint32_t ranks[4 ] = {ADC_INJECTED_RANK_1, ADC_INJECTED_RANK_2, ADC_INJECTED_RANK_3, ADC_INJECTED_RANK_4};
142151 for (int i=0 ; i<3 ; i++){
143152 // skip if not set
144- if (!_isset (cs_params->pins [i])) continue ;
145-
146- sConfigInjected .InjectedRank = ADC_INJECTED_RANK_1 + i;
153+ if (!_isset (cs_params->pins [i])) continue ;
154+ sConfigInjected .InjectedRank = ranks[i];
147155 sConfigInjected .InjectedChannel = _getADCChannel (analogInputToPinName (cs_params->pins [i]));
148156 if (HAL_ADCEx_InjectedConfigChannel (&hadc, &sConfigInjected ) != HAL_OK){
149157 #ifdef SIMPLEFOC_STM32_DEBUG
@@ -152,7 +160,9 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
152160 return -1 ;
153161 }
154162 }
155-
163+
164+
165+ delay (1000 );
156166 #ifdef SIMPLEFOC_STM32_ADC_INTERRUPT
157167 // enable interrupt
158168 HAL_NVIC_SetPriority (ADC_IRQn, 0 , 0 );
0 commit comments