Skip to content

Commit daaa0fb

Browse files
committed
bugfixes and handling only one adc nad no timer 8
1 parent 5d06560 commit daaa0fb

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/current_sense/hardware_specific/stm32/stm32_mcu.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
#include "../../hardware_api.h"
55
#include "../../../common/foc_utils.h"
66

7-
#if defined(_STM32_DEF_) and !defined(ARDUINO_B_G431B_ESC1)
8-
9-
#define _ADC_VOLTAGE 3.3f
10-
#define _ADC_RESOLUTION 1024.0f
7+
#if defined(_STM32_DEF_)
118

129
// generic implementation of the hardware specific structure
1310
// containing all the necessary current sense parameters

src/current_sense/hardware_specific/stm32/stm32f4/stm32f4_hal.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
99
if(timer->getHandle()->Instance == TIM1)
1010
return ADC_EXTERNALTRIGINJECCONV_T1_TRGO;
1111
else if(timer->getHandle()->Instance == TIM2)
12+
#ifdef TIM2 // if defined timer 2
1213
return ADC_EXTERNALTRIGINJECCONV_T2_TRGO;
1314
else if(timer->getHandle()->Instance == TIM4)
1415
return ADC_EXTERNALTRIGINJECCONV_T4_TRGO;
16+
#endif
17+
#ifdef TIM5 // if defined timer 5
1518
else if(timer->getHandle()->Instance == TIM5)
1619
return ADC_EXTERNALTRIGINJECCONV_T5_TRGO;
20+
#endif
1721
else
1822
return 0;
1923
}
@@ -23,10 +27,14 @@ uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
2327
uint32_t _timerToRegularTRGO(HardwareTimer* timer){
2428
if(timer->getHandle()->Instance == TIM2)
2529
return ADC_EXTERNALTRIGCONV_T2_TRGO;
30+
#ifdef TIM3 // if defined timer 3
2631
else if(timer->getHandle()->Instance == TIM3)
2732
return ADC_EXTERNALTRIGCONV_T3_TRGO;
33+
#endif
34+
#ifdef TIM8 // if defined timer 8
2835
else if(timer->getHandle()->Instance == TIM8)
2936
return ADC_EXTERNALTRIGCONV_T8_TRGO;
37+
#endif
3038
else
3139
return 0;
3240
}
@@ -42,8 +50,13 @@ void _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* driv
4250
hadc.Instance = (ADC_TypeDef *)pinmap_peripheral(analogInputToPinName(cs_params->pins[0]), PinMap_ADC);
4351

4452
if(hadc.Instance == ADC1) __HAL_RCC_ADC1_CLK_ENABLE();
53+
#ifdef ADC2 // if defined ADC2
4554
else if(hadc.Instance == ADC2) __HAL_RCC_ADC2_CLK_ENABLE();
55+
#endif
56+
#ifdef ADC3 // if defined ADC3
4657
else if(hadc.Instance == ADC3) __HAL_RCC_ADC3_CLK_ENABLE();
58+
#endif
59+
else return; // error not a valid ADC instance
4760

4861
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
4962
hadc.Init.Resolution = ADC_RESOLUTION_12B;

src/current_sense/hardware_specific/stm32/stm32f4/stm32f4_hal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#if defined(STM32F4xx)
77
#include "stm32f4xx_hal.h"
8-
#include "stm32f4xx_hal_adc.h"
98
#include "../../../../common/foc_utils.h"
109
#include "../../../../drivers/hardware_specific/stm32_mcu.h"
1110
#include "../stm32_mcu.h"

src/current_sense/hardware_specific/stm32/stm32f4/stm32f4_mcu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ uint16_t adc_channel_number[3]={0};
1818

1919
int _adcToIndex(ADC_HandleTypeDef *AdcHandle){
2020
if(AdcHandle->Instance == ADC1) return 0;
21+
#ifdef ADC2 // if ADC2 exists
2122
else if(AdcHandle->Instance == ADC2) return 1;
23+
#endif
24+
#ifdef ADC3 // if ADC3 exists
2225
else if(AdcHandle->Instance == ADC3) return 2;
26+
#endif
2327
return 0;
2428
}
2529

0 commit comments

Comments
 (0)