Skip to content

Commit 5569f73

Browse files
committed
update l4 current sense to new API
1 parent 1d1c5dd commit 5569f73

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

src/current_sense/hardware_specific/stm32/stm32l4/stm32l4_hal.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
125125

126126
// automating TRGO flag finding - hardware specific
127127
uint8_t tim_num = 0;
128-
while(driver_params->timers[tim_num] != NP && tim_num < 6){
129-
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers[tim_num++]);
128+
while(driver_params->timers_handle[tim_num] != NP && tim_num < 6){
129+
uint32_t trigger_flag = _timerToInjectedTRGO(driver_params->timers_handle[tim_num++]);
130130
if(trigger_flag == _TRGO_NOT_AVAILABLE) continue; // timer does not have valid trgo for injected channels
131131

132132
// if the code comes here, it has found the timer available
133133
// timer does have trgo flag for injected channels
134134
sConfigInjected.ExternalTrigInjecConv = trigger_flag;
135135

136136
// this will be the timer with which the ADC will sync
137-
cs_params->timer_handle = driver_params->timers[tim_num-1];
137+
cs_params->timer_handle = driver_params->timers_handle[tim_num-1];
138138
// done
139139
break;
140140
}

src/current_sense/hardware_specific/stm32/stm32l4/stm32l4_mcu.cpp

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

5151
// stop all the timers for the driver
52-
_stopTimers(driver_params->timers, 6);
52+
stm32_pause(driver_params);
5353

5454
// if timer has repetition counter - it will downsample using it
5555
// and it does not need the software downsample
56-
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->getHandle()->Instance) ){
56+
if( IS_TIM_REPETITION_COUNTER_INSTANCE(cs_params->timer_handle->Instance) ){
5757
// adjust the initial timer state such that the trigger
5858
// - for DMA transfer aligns with the pwm peaks instead of throughs.
5959
// - for interrupt based ADC transfer
6060
// - only necessary for the timers that have repetition counters
61-
cs_params->timer_handle->getHandle()->Instance->CR1 |= TIM_CR1_DIR;
62-
cs_params->timer_handle->getHandle()->Instance->CNT = cs_params->timer_handle->getHandle()->Instance->ARR;
61+
cs_params->timer_handle->Instance->CR1 |= TIM_CR1_DIR;
62+
cs_params->timer_handle->Instance->CNT = cs_params->timer_handle->Instance->ARR;
6363
// remember that this timer has repetition counter - no need to downasmple
6464
needs_downsample[_adcToIndex(cs_params->adc_handle)] = 0;
6565
}else{
@@ -73,7 +73,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
7373
}
7474

7575
// set the trigger output event
76-
LL_TIM_SetTriggerOutput(cs_params->timer_handle->getHandle()->Instance, LL_TIM_TRGO_UPDATE);
76+
LL_TIM_SetTriggerOutput(cs_params->timer_handle->Instance, LL_TIM_TRGO_UPDATE);
7777

7878
// Start the adc calibration
7979
HAL_ADCEx_Calibration_Start(cs_params->adc_handle,ADC_SINGLE_ENDED);
@@ -119,7 +119,7 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
119119
}
120120

121121
// restart all the timers of the driver
122-
_startTimers(driver_params->timers, 6);
122+
stm32_resume(driver_params);
123123
// return the cs parameters
124124
// successfully initialized
125125
// TODO verify if success in future

src/current_sense/hardware_specific/stm32/stm32l4/stm32l4_utils.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,31 +133,31 @@ uint32_t _getADCChannel(PinName pin)
133133

134134
// timer to injected TRGO
135135
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_adc_ex.h#L210
136-
uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
137-
if(timer->getHandle()->Instance == TIM1)
136+
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer){
137+
if(timer->Instance == TIM1)
138138
return ADC_EXTERNALTRIGINJEC_T1_TRGO;
139139
#ifdef TIM2 // if defined timer 2
140-
else if(timer->getHandle()->Instance == TIM2)
140+
else if(timer->Instance == TIM2)
141141
return ADC_EXTERNALTRIGINJEC_T2_TRGO;
142142
#endif
143143
#ifdef TIM3 // if defined timer 3
144-
else if(timer->getHandle()->Instance == TIM3)
144+
else if(timer->Instance == TIM3)
145145
return ADC_EXTERNALTRIGINJEC_T3_TRGO;
146146
#endif
147147
#ifdef TIM4 // if defined timer 4
148-
else if(timer->getHandle()->Instance == TIM4)
148+
else if(timer->Instance == TIM4)
149149
return ADC_EXTERNALTRIGINJEC_T4_TRGO;
150150
#endif
151151
#ifdef TIM6 // if defined timer 6
152-
else if(timer->getHandle()->Instance == TIM6)
152+
else if(timer->Instance == TIM6)
153153
return ADC_EXTERNALTRIGINJEC_T6_TRGO;
154154
#endif
155155
#ifdef TIM8 // if defined timer 8
156-
else if(timer->getHandle()->Instance == TIM8)
156+
else if(timer->Instance == TIM8)
157157
return ADC_EXTERNALTRIGINJEC_T8_TRGO;
158158
#endif
159159
#ifdef TIM15 // if defined timer 15
160-
else if(timer->getHandle()->Instance == TIM15)
160+
else if(timer->Instance == TIM15)
161161
return ADC_EXTERNALTRIGINJEC_T15_TRGO;
162162
#endif
163163
else
@@ -166,31 +166,31 @@ uint32_t _timerToInjectedTRGO(HardwareTimer* timer){
166166

167167
// timer to regular TRGO
168168
// https://github.com/stm32duino/Arduino_Core_STM32/blob/6588dee03382e73ed42c4a5e473900ab3b79d6e4/system/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_adc.h#L519
169-
uint32_t _timerToRegularTRGO(HardwareTimer* timer){
170-
if(timer->getHandle()->Instance == TIM1)
169+
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer){
170+
if(timer->Instance == TIM1)
171171
return ADC_EXTERNALTRIG_T1_TRGO;
172172
#ifdef TIM2 // if defined timer 2
173-
else if(timer->getHandle()->Instance == TIM2)
173+
else if(timer->Instance == TIM2)
174174
return ADC_EXTERNALTRIG_T2_TRGO;
175175
#endif
176176
#ifdef TIM3 // if defined timer 3
177-
else if(timer->getHandle()->Instance == TIM3)
177+
else if(timer->Instance == TIM3)
178178
return ADC_EXTERNALTRIG_T3_TRGO;
179179
#endif
180180
#ifdef TIM4 // if defined timer 4
181-
else if(timer->getHandle()->Instance == TIM4)
181+
else if(timer->Instance == TIM4)
182182
return ADC_EXTERNALTRIG_T4_TRGO;
183183
#endif
184184
#ifdef TIM6 // if defined timer 6
185-
else if(timer->getHandle()->Instance == TIM6)
185+
else if(timer->Instance == TIM6)
186186
return ADC_EXTERNALTRIG_T6_TRGO;
187187
#endif
188188
#ifdef TIM8 // if defined timer 8
189-
else if(timer->getHandle()->Instance == TIM8)
189+
else if(timer->Instance == TIM8)
190190
return ADC_EXTERNALTRIG_T8_TRGO;
191191
#endif
192192
#ifdef TIM15 // if defined timer 15
193-
else if(timer->getHandle()->Instance == TIM15)
193+
else if(timer->Instance == TIM15)
194194
return ADC_EXTERNALTRIG_T15_TRGO;
195195
#endif
196196
else

src/current_sense/hardware_specific/stm32/stm32l4/stm32l4_utils.h

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

2020
// timer to injected TRGO
2121
// https://github.com/stm32duino/Arduino_Core_STM32/blob/6588dee03382e73ed42c4a5e473900ab3b79d6e4/system/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_adc_ex.h#L217
22-
uint32_t _timerToInjectedTRGO(HardwareTimer* timer);
22+
uint32_t _timerToInjectedTRGO(TIM_HandleTypeDef* timer);
2323

2424
// timer to regular TRGO
2525
// https://github.com/stm32duino/Arduino_Core_STM32/blob/6588dee03382e73ed42c4a5e473900ab3b79d6e4/system/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_adc.h#L519
26-
uint32_t _timerToRegularTRGO(HardwareTimer* timer);
26+
uint32_t _timerToRegularTRGO(TIM_HandleTypeDef* timer);
2727

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

0 commit comments

Comments
 (0)