Skip to content

Commit afa8e3d

Browse files
committed
fix STM32F1 current sense
1 parent 3d26880 commit afa8e3d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/current_sense/hardware_specific/stm32/stm32f1/stm32f1_hal.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77

88
// timer to injected TRGO
99
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h#L215
10-
uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
11-
if(timer->getHandle()->Instance == TIM1)
10+
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer){
11+
if(timer->Instance == TIM1)
1212
return ADC_EXTERNALTRIGINJECCONV_T1_TRGO;
1313
#ifdef TIM2 // if defined timer 2
14-
else if(timer->getHandle()->Instance == TIM2)
14+
else if(timer->Instance == TIM2)
1515
return ADC_EXTERNALTRIGINJECCONV_T2_TRGO;
1616
#endif
1717
#ifdef TIM4 // if defined timer 4
18-
else if(timer->getHandle()->Instance == TIM4)
18+
else if(timer->Instance == TIM4)
1919
return ADC_EXTERNALTRIGINJECCONV_T4_TRGO;
2020
#endif
2121
#ifdef TIM5 // if defined timer 5
22-
else if(timer->getHandle()->Instance == TIM5)
22+
else if(timer->Instance == TIM5)
2323
return ADC_EXTERNALTRIGINJECCONV_T5_TRGO;
2424
#endif
2525
else
@@ -28,11 +28,11 @@ uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
2828

2929
// timer to regular TRGO
3030
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h#L215
31-
uint32_t _timerToRegularTRGO(HardwareTimer* timer){
32-
if(timer->getHandle()->Instance == TIM3)
31+
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer){
32+
if(timer->Instance == TIM3)
3333
return ADC_EXTERNALTRIGCONV_T3_TRGO;
3434
#ifdef TIM8 // if defined timer 8
35-
else if(timer->getHandle()->Instance == TIM8)
35+
else if(timer->Instance == TIM8)
3636
return ADC_EXTERNALTRIGCONV_T8_TRGO;
3737
#endif
3838
else
@@ -82,16 +82,16 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
8282

8383
// automating TRGO flag finding - hardware specific
8484
uint8_t tim_num = 0;
85-
while(driver_params->timers[tim_num] != NP && tim_num < 6){
86-
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers[tim_num++]);
85+
while(driver_params->timers_handle[tim_num] != NP && tim_num < 6){
86+
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers_handle[tim_num++]);
8787
if(trigger_flag == _TRGO_NOT_AVAILABLE) continue; // timer does not have valid trgo for injected channels
8888

8989
// if the code comes here, it has found the timer available
9090
// timer does have trgo flag for injected channels
9191
sConfigInjected.ExternalTrigInjecConv = trigger_flag;
9292

9393
// this will be the timer with which the ADC will sync
94-
cs_params->timer_handle = driver_params->timers[tim_num-1];
94+
cs_params->timer_handle = driver_params->timers_handle[tim_num-1];
9595
// done
9696
break;
9797
}
@@ -105,7 +105,7 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
105105
// display which timer is being used
106106
#ifdef SIMPLEFOC_STM32_DEBUG
107107
// it would be better to use the getTimerNumber from driver
108-
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->getHandle()->Instance) + 1);
108+
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->Instance) + 1);
109109
#endif
110110

111111
// first channel

src/current_sense/hardware_specific/stm32/stm32f1/stm32f1_mcu.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
5656
if (cs_params->timer_handle == NULL) return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED;
5757

5858
// stop all the timers for the driver
59-
_stopTimers(driver_params->timers, 6);
59+
stm32_pause(driver_params);
6060

6161
// if timer has repetition counter - it will downsample using it
6262
// and it does not need the software downsample
63-
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->getHandle()->Instance) ){
63+
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->Instance) ){
6464
// adjust the initial timer state such that the trigger
6565
// - for DMA transfer aligns with the pwm peaks instead of throughs.
6666
// - for interrupt based ADC transfer
6767
// - only necessary for the timers that have repetition counters
68-
cs_params->timer_handle->getHandle()->Instance->CR1 |= TIM_CR1_DIR;
69-
cs_params->timer_handle->getHandle()->Instance->CNT = cs_params->timer_handle->getHandle()->Instance->ARR;
68+
cs_params->timer_handle->Instance->CR1 |= TIM_CR1_DIR;
69+
cs_params->timer_handle->Instance->CNT = cs_params->timer_handle->Instance->ARR;
7070
// remember that this timer has repetition counter - no need to downasmple
7171
needs_downsample[_adcToIndex(cs_params->adc_handle)] = 0;
7272
}else{
@@ -79,7 +79,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
7979
}
8080
}
8181
// set the trigger output event
82-
LL_TIM_SetTriggerOutput(cs_params->timer_handle->getHandle()->Instance, LL_TIM_TRGO_UPDATE);
82+
LL_TIM_SetTriggerOutput(cs_params->timer_handle->Instance, LL_TIM_TRGO_UPDATE);
8383

8484
// Start the adc calibration
8585
HAL_ADCEx_Calibration_Start(cs_params->adc_handle);
@@ -96,7 +96,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
9696

9797

9898
// restart all the timers of the driver
99-
_startTimers(driver_params->timers, 6);
99+
stm32_resume(driver_params);
100100

101101
// return the cs parameters
102102
// successfully initialized

0 commit comments

Comments
 (0)