Skip to content

Commit d688fcc

Browse files
committed
fix current sense for stm32f7 MCUs
1 parent cd79e01 commit d688fcc

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

src/current_sense/hardware_specific/stm32/stm32f7/stm32f7_hal.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
7777
// automating TRGO flag finding - hardware specific
7878
uint8_t tim_num = 0;
7979
for (size_t i=0; i<6; i++) {
80-
HardwareTimer *timer_to_check = driver_params->timers[tim_num++];
81-
TIM_TypeDef *instance_to_check = timer_to_check->getHandle()->Instance;
80+
TIM_HandleTypeDef *timer_to_check = driver_params->timers_handle[tim_num++];
81+
TIM_TypeDef *instance_to_check = timer_to_check->Instance;
8282

8383
// bool TRGO_already_configured = instance_to_check->CR2 & LL_TIM_TRGO_UPDATE;
8484
// if(TRGO_already_configured) continue;
@@ -110,7 +110,7 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
110110
// display which timer is being used
111111
#ifdef SIMPLEFOC_STM32_DEBUG
112112
// it would be better to use the getTimerNumber from driver
113-
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->getHandle()->Instance) + 1);
113+
SIMPLEFOC_DEBUG("STM32-CS: injected trigger for timer index: ", get_timer_index(cs_params->timer_handle->Instance) + 1);
114114
#endif
115115

116116

src/current_sense/hardware_specific/stm32/stm32f7/stm32f7_mcu.cpp

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

4444
// stop all the timers for the driver
45-
_stopTimers(driver_params->timers, 6);
45+
stm32_pause(driver_params);
4646

4747
// if timer has repetition counter - it will downsample using it
4848
// and it does not need the software downsample
49-
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->getHandle()->Instance) ){
49+
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->Instance) ){
5050
// adjust the initial timer state such that the trigger
5151
// - for DMA transfer aligns with the pwm peaks instead of throughs.
5252
// - for interrupt based ADC transfer
5353
// - only necessary for the timers that have repetition counters
5454

55-
cs_params->timer_handle->getHandle()->Instance->CR1 |= TIM_CR1_DIR;
56-
cs_params->timer_handle->getHandle()->Instance->CNT = cs_params->timer_handle->getHandle()->Instance->ARR;
55+
cs_params->timer_handle->Instance->CR1 |= TIM_CR1_DIR;
56+
cs_params->timer_handle->Instance->CNT = cs_params->timer_handle->Instance->ARR;
5757
// remember that this timer has repetition counter - no need to downasmple
5858
needs_downsample[_adcToIndex(cs_params->adc_handle)] = 0;
5959
}
6060
// set the trigger output event
61-
LL_TIM_SetTriggerOutput(cs_params->timer_handle->getHandle()->Instance, LL_TIM_TRGO_UPDATE);
61+
LL_TIM_SetTriggerOutput(cs_params->timer_handle->Instance, LL_TIM_TRGO_UPDATE);
6262

6363
// start the adc
6464
#ifdef SIMPLEFOC_STM32_ADC_INTERRUPT
@@ -68,7 +68,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
6868
#endif
6969

7070
// restart all the timers of the driver
71-
_startTimers(driver_params->timers, 6);
71+
stm32_resume(driver_params);
7272

7373
// return the cs parameters
7474
// successfully initialized

src/current_sense/hardware_specific/stm32/stm32f7/stm32f7_utils.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,28 +163,28 @@ ADC_EXTERNALTRIGINJECCONV_T6_TRGO
163163
*/
164164
// timer to injected TRGO
165165
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h#L179
166-
uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
166+
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer){
167167

168-
if(timer->getHandle()->Instance == TIM1)
168+
if(timer->Instance == TIM1)
169169
return ADC_EXTERNALTRIGINJECCONV_T1_TRGO;
170170
#ifdef TIM2 // if defined timer 2
171-
else if(timer->getHandle()->Instance == TIM2)
171+
else if(timer->Instance == TIM2)
172172
return ADC_EXTERNALTRIGINJECCONV_T2_TRGO;
173173
#endif
174174
#ifdef TIM4 // if defined timer 4
175-
else if(timer->getHandle()->Instance == TIM4)
175+
else if(timer->Instance == TIM4)
176176
return ADC_EXTERNALTRIGINJECCONV_T4_TRGO;
177177
#endif
178178
#ifdef TIM5 // if defined timer 5
179-
else if(timer->getHandle()->Instance == TIM5)
179+
else if(timer->Instance == TIM5)
180180
return ADC_EXTERNALTRIGINJECCONV_T5_TRGO;
181181
#endif
182182
#ifdef TIM6 // if defined timer 6
183-
else if(timer->getHandle()->Instance == TIM6)
183+
else if(timer->Instance == TIM6)
184184
return ADC_EXTERNALTRIGINJECCONV_T6_TRGO;
185185
#endif
186186
#ifdef TIM8 // if defined timer 8
187-
else if(timer->getHandle()->Instance == TIM8)
187+
else if(timer->Instance == TIM8)
188188
return ADC_EXTERNALTRIGINJECCONV_T8_TRGO;
189189
#endif
190190
else
@@ -204,27 +204,27 @@ ADC_EXTERNALTRIGCONV_T6_TRGO
204204

205205
// timer to regular TRGO
206206
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h#L331
207-
uint32_t _timerToRegularTRGO(HardwareTimer* timer){
208-
if(timer->getHandle()->Instance == TIM1)
207+
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer){
208+
if(timer->Instance == TIM1)
209209
return ADC_EXTERNALTRIGCONV_T1_TRGO;
210210
#ifdef TIM2 // if defined timer 2
211-
else if(timer->getHandle()->Instance == TIM2)
211+
else if(timer->Instance == TIM2)
212212
return ADC_EXTERNALTRIGCONV_T2_TRGO;
213213
#endif
214214
#ifdef TIM4 // if defined timer 4
215-
else if(timer->getHandle()->Instance == TIM4)
215+
else if(timer->Instance == TIM4)
216216
return ADC_EXTERNALTRIGCONV_T4_TRGO;
217217
#endif
218218
#ifdef TIM5 // if defined timer 5
219-
else if(timer->getHandle()->Instance == TIM5)
219+
else if(timer->Instance == TIM5)
220220
return ADC_EXTERNALTRIGCONV_T5_TRGO;
221221
#endif
222222
#ifdef TIM6 // if defined timer 6
223-
else if(timer->getHandle()->Instance == TIM6)
223+
else if(timer->Instance == TIM6)
224224
return ADC_EXTERNALTRIGCONV_T6_TRGO;
225225
#endif
226226
#ifdef TIM8 // if defined timer 8
227-
else if(timer->getHandle()->Instance == TIM8)
227+
else if(timer->Instance == TIM8)
228228
return ADC_EXTERNALTRIGCONV_T8_TRGO;
229229
#endif
230230
else

src/current_sense/hardware_specific/stm32/stm32f7/stm32f7_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ uint32_t _getADCChannel(PinName pin);
1717

1818
// timer to injected TRGO
1919
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h#L179
20-
uint32_t _timerToInjectedTRGO(HardwareTimer* timer);
20+
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer);
2121

2222
// timer to regular TRGO
2323
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h#L331
24-
uint32_t _timerToRegularTRGO(HardwareTimer* timer);
24+
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer);
2525

2626
// function returning index of the ADC instance
2727
int _adcToIndex(ADC_HandleTypeDef *AdcHandle);

0 commit comments

Comments
 (0)