Skip to content

Commit cd79e01

Browse files
committed
now working on Portenta H7
1 parent 8102189 commit cd79e01

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/drivers/hardware_specific/stm32/stm32_mcu.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,11 @@ TIM_HandleTypeDef* stm32_initPinPWM(uint32_t PWM_freq, PinMap* timer, uint32_t m
147147
return NULL;
148148
TIM_HandleTypeDef* handle = stm32_getTimer(timer);
149149
uint32_t channel = STM_PIN_CHANNEL(timer->function);
150-
#ifdef SIMPLEFOC_STM32_DEBUG
151-
SIMPLEFOC_DEBUG("STM32-DRV: Configuring timer ", (int)stm32_getTimerNumber(handle->Instance));
152-
SIMPLEFOC_DEBUG("STM32-DRV: Configuring channel ", (int)channel);
153-
#endif
154150
if (handle==NULL) {
155151
handle = stm32_useTimer(timer);
152+
#ifdef SIMPLEFOC_STM32_DEBUG
153+
SIMPLEFOC_DEBUG("STM32-DRV: Initializing TIM", (int)stm32_getTimerNumber(handle->Instance));
154+
#endif
156155
uint32_t arr = stm32_setClockAndARR(handle, PWM_freq);
157156
if (arr<SIMPLEFOC_STM32_MIN_RESOLUTION) {
158157
SIMPLEFOC_DEBUG("STM32-DRV: WARN timer resolution too low (<8bit): ", (int)arr+1);
@@ -162,7 +161,6 @@ TIM_HandleTypeDef* stm32_initPinPWM(uint32_t PWM_freq, PinMap* timer, uint32_t m
162161
SIMPLEFOC_DEBUG("STM32-DRV: Timer resolution set to: ", (int)arr+1);
163162
#endif
164163
}
165-
166164
}
167165
TIM_OC_InitTypeDef channelOC;
168166
channelOC.OCMode = TIM_OCMODE_PWM1;
@@ -184,6 +182,11 @@ TIM_HandleTypeDef* stm32_initPinPWM(uint32_t PWM_freq, PinMap* timer, uint32_t m
184182
if (IS_TIM_BREAK_INSTANCE(handle->Instance)) {
185183
__HAL_TIM_MOE_ENABLE(handle);
186184
}
185+
#ifdef SIMPLEFOC_STM32_DEBUG
186+
SimpleFOCDebug::print("STM32-DRV: Configured TIM");
187+
SimpleFOCDebug::print((int)stm32_getTimerNumber(handle->Instance));
188+
SIMPLEFOC_DEBUG("_CH", (int)channel);
189+
#endif
187190
return handle;
188191
}
189192

src/drivers/hardware_specific/stm32/stm32_timerutils.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ uint32_t stm32_setClockAndARR(TIM_HandleTypeDef* handle, uint32_t PWM_freq) {
5353
}
5454
__HAL_TIM_SET_AUTORELOAD(handle, arr_value);
5555
stm32_refreshTimer(handle);
56-
#ifdef SIMPLEFOC_STM32_DEBUG
57-
SIMPLEFOC_DEBUG("STM32-DRV: Timer clock: ", (int)stm32_getTimerClockFreq(handle));
58-
SIMPLEFOC_DEBUG("STM32-DRV: Timer prescaler: ", (int)prescaler);
59-
SIMPLEFOC_DEBUG("STM32-DRV: Timer ARR: ", (int)arr_value);
60-
#endif
56+
// #ifdef SIMPLEFOC_STM32_DEBUG
57+
// SIMPLEFOC_DEBUG("STM32-DRV: Timer clock: ", (int)stm32_getTimerClockFreq(handle));
58+
// SIMPLEFOC_DEBUG("STM32-DRV: Timer prescaler: ", (int)prescaler);
59+
// SIMPLEFOC_DEBUG("STM32-DRV: Timer ARR: ", (int)arr_value);
60+
// #endif
6161
return arr_value;
6262
}
6363

@@ -458,7 +458,8 @@ TIM_HandleTypeDef* stm32_alignTimers(TIM_HandleTypeDef *timers_in[], uint8_t num
458458
LL_TIM_SetSlaveMode(timers[slave_index]->Instance, LL_TIM_SLAVEMODE_GATED);
459459
#endif
460460
}
461-
stm32_resumeTimer(timers[master_index]); // start the master to start all timers
461+
for (int i=0; i<numTimers; i++) // resume the timers TODO at the moment the first PWM cycle is not well-aligned
462+
stm32_resumeTimer(timers[i]);
462463
return timers[master_index];
463464
}
464465
}

0 commit comments

Comments
 (0)