Skip to content

Commit

Permalink
now working on Portenta H7
Browse files Browse the repository at this point in the history
  • Loading branch information
runger1101001 committed Aug 30, 2024
1 parent 8102189 commit cd79e01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 8 additions & 5 deletions src/drivers/hardware_specific/stm32/stm32_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ TIM_HandleTypeDef* stm32_initPinPWM(uint32_t PWM_freq, PinMap* timer, uint32_t m
return NULL;
TIM_HandleTypeDef* handle = stm32_getTimer(timer);
uint32_t channel = STM_PIN_CHANNEL(timer->function);
#ifdef SIMPLEFOC_STM32_DEBUG
SIMPLEFOC_DEBUG("STM32-DRV: Configuring timer ", (int)stm32_getTimerNumber(handle->Instance));
SIMPLEFOC_DEBUG("STM32-DRV: Configuring channel ", (int)channel);
#endif
if (handle==NULL) {
handle = stm32_useTimer(timer);
#ifdef SIMPLEFOC_STM32_DEBUG
SIMPLEFOC_DEBUG("STM32-DRV: Initializing TIM", (int)stm32_getTimerNumber(handle->Instance));
#endif
uint32_t arr = stm32_setClockAndARR(handle, PWM_freq);
if (arr<SIMPLEFOC_STM32_MIN_RESOLUTION) {
SIMPLEFOC_DEBUG("STM32-DRV: WARN timer resolution too low (<8bit): ", (int)arr+1);
Expand All @@ -162,7 +161,6 @@ TIM_HandleTypeDef* stm32_initPinPWM(uint32_t PWM_freq, PinMap* timer, uint32_t m
SIMPLEFOC_DEBUG("STM32-DRV: Timer resolution set to: ", (int)arr+1);
#endif
}

}
TIM_OC_InitTypeDef channelOC;
channelOC.OCMode = TIM_OCMODE_PWM1;
Expand All @@ -184,6 +182,11 @@ TIM_HandleTypeDef* stm32_initPinPWM(uint32_t PWM_freq, PinMap* timer, uint32_t m
if (IS_TIM_BREAK_INSTANCE(handle->Instance)) {
__HAL_TIM_MOE_ENABLE(handle);
}
#ifdef SIMPLEFOC_STM32_DEBUG
SimpleFOCDebug::print("STM32-DRV: Configured TIM");
SimpleFOCDebug::print((int)stm32_getTimerNumber(handle->Instance));
SIMPLEFOC_DEBUG("_CH", (int)channel);
#endif
return handle;
}

Expand Down
13 changes: 7 additions & 6 deletions src/drivers/hardware_specific/stm32/stm32_timerutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ uint32_t stm32_setClockAndARR(TIM_HandleTypeDef* handle, uint32_t PWM_freq) {
}
__HAL_TIM_SET_AUTORELOAD(handle, arr_value);
stm32_refreshTimer(handle);
#ifdef SIMPLEFOC_STM32_DEBUG
SIMPLEFOC_DEBUG("STM32-DRV: Timer clock: ", (int)stm32_getTimerClockFreq(handle));
SIMPLEFOC_DEBUG("STM32-DRV: Timer prescaler: ", (int)prescaler);
SIMPLEFOC_DEBUG("STM32-DRV: Timer ARR: ", (int)arr_value);
#endif
// #ifdef SIMPLEFOC_STM32_DEBUG
// SIMPLEFOC_DEBUG("STM32-DRV: Timer clock: ", (int)stm32_getTimerClockFreq(handle));
// SIMPLEFOC_DEBUG("STM32-DRV: Timer prescaler: ", (int)prescaler);
// SIMPLEFOC_DEBUG("STM32-DRV: Timer ARR: ", (int)arr_value);
// #endif
return arr_value;
}

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

0 comments on commit cd79e01

Please sign in to comment.