Skip to content

New version 1.8.0 and Hardware Timer on MK4duo FW printer 3D #841

Closed
@MagoKimbra

Description

@MagoKimbra

Hi, sorry for my bad english.
I need your help.
I am the programmer of MK4duo firmware for 3D printers.
I am using a Rumba32 with STM32F4.
Using version 1.7.0 of STM32core.
I use the TIM2 timer for the movement of the motors.
I use Hardware timer and everything works perfectly.
Yesterday I updated to version 1.8.0 and now when I try to move the motors everything freezes, the card freezes and no longer responds, it must be turned off and on again.
This is the routine I use to initialize the timer, and the routines for reading the count and write the new count:

#define STEP_TIMER TIM2
#define STEPPER_TIMER_PRESCALE 2
#define HAL_TIMER_TYPE_MAX 0xFFFFFFF

FORCE_INLINE bool HAL_timer_initialized() {
  return MK_step_timer != nullptr;
}

FORCE_INLINE bool HAL_timer_interrupt_is_enabled() {
  return HAL_timer_initialized() && MK_step_timer->hasInterrupt();
}

FORCE_INLINE hal_timer_t HAL_timer_get_current_count(const uint8_t) {
  return HAL_timer_initialized() ? MK_step_timer->getCount() : 0;
}

FORCE_INLINE void HAL_timer_set_count(const uint8_t, const hal_timer_t count) {
  if (HAL_timer_initialized()) {
    MK_step_timer->setOverflow(count + 1, TICK_FORMAT);
    if (count < MK_step_timer->getCount()) MK_step_timer->refresh(); // Generate an immediate update interrupt
}

void HAL_timer_start() {
  if (!HAL_timer_initialized()) {
    MK_step_timer = new HardwareTimer(STEP_TIMER);
    MK_step_timer->setInterruptPriority(NvicPriorityStepper, 0);
    MK_step_timer->setPrescaleFactor(STEPPER_TIMER_PRESCALE);
    MK_step_timer->setOverflow(HAL_TIMER_TYPE_MAX, TICK_FORMAT);
    MK_step_timer->attachInterrupt(Step_Handler);
    MK_step_timer->resume();
  }
}

void HAL_timer_enable_interrupt() {
  if (HAL_timer_initialized() && !MK_step_timer->hasInterrupt()) {
    MK_step_timer->attachInterrupt(Step_Handler);
  }
}

void HAL_timer_disable_interrupt() {
  if (HAL_timer_initialized() && MK_step_timer->hasInterrupt()) {
    MK_step_timer->detachInterrupt();
  }
}

uint32_t HAL_timer_get_Clk_Freq() {
  return HAL_timer_initialized() ? MK_step_timer->getTimerClkFreq() : 0;
}

I'm trying in every way to understand where the problem may be, but I really don't understand it.
I kindly ask you to give me a hand, even just to make me understand where the differences are between 1.7.0 and 1.8.0.
The rest works everything, analog reading, pwm pin.
Use Hardware Timer only for Motors.
Thank's.

EDIT: Ok I understand where the problem is.
By default the timer is in TIMER_DISABLED, so it does not perform the callback.
You have to set the mode with setMode in TIMER_OUTPUT_COMPARE, but there is no command to set the entire timer only the channel.
I solved it by putting setMode (1, TIMER_OUTPUT_COMPARE), but wouldn't it be more logical to create a command for the whole timer if you don't use the channels?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions