Skip to content

Commit b4aff56

Browse files
ABOSTMfpistm
authored andcommitted
HardwareTimer: pause() needed before setMode() and resume()
Due to HAL strict management of its internal state, introduced with HAL Cube update (ex: for STM32L4 sha1 f41f10e), it is now required to pause() timer before setMode() and resume() otherwise HAL state is busy and timer is not (re)started. Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
1 parent dbf87f9 commit b4aff56

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

examples/NonReg/HardwareTimer/HardwareTimer_OutputInput_test/HardwareTimer_OutputInput_test.ino

+7-1
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ void loop()
396396
Verify_output_interrupts(0, 0, 0);
397397
test_step++;
398398

399+
MyTim_output->pause();
399400
MyTim_output->setMode(Output1_channel, TIMER_OUTPUT_COMPARE_PWM1, TIM1_CH1N_PIN);
400401
MyTim_output->setOverflow((1000000 / OUTPUT_FREQUENCY), MICROSEC_FORMAT);
401402
MyTim_output->setCaptureCompare(Output1_channel, OUTPUT_DUTY1, PERCENT_COMPARE_FORMAT);
@@ -404,24 +405,28 @@ void loop()
404405
Verify_output(2, 0, 0);
405406
test_step++;
406407

408+
MyTim_output->pause();
407409
MyTim_output->setMode(Output1_channel, TIMER_OUTPUT_COMPARE_TOGGLE, TIM1_CH1N_PIN);
408410
MyTim_output->resume();
409411
Verify_output(1, OUTPUT_FREQUENCY / 2, 50); // in PWM2, output is the complementary of PW1
410412
Verify_output(2, 0, 0);
411413
test_step++;
412414

415+
MyTim_output->pause();
413416
MyTim_output->setMode(Output1_channel, TIMER_OUTPUT_COMPARE_PWM2, TIM1_CH1N_PIN);
414417
MyTim_output->resume();
415418
Verify_output(1, OUTPUT_FREQUENCY, 100 - OUTPUT_DUTY1); // in PWM2, output is the complementary of PW1
416419
Verify_output(2, 0, 0);
417420
test_step++;
418421

422+
MyTim_output->pause();
419423
MyTim_output->setMode(Output1_channel, TIMER_OUTPUT_COMPARE_PWM1, TIM1_CH1N_PIN);
420424
MyTim_output->resume();
421425
Verify_output(1, OUTPUT_FREQUENCY, OUTPUT_DUTY1);
422426
Verify_output(2, 0, 0);
423427
test_step++;
424428

429+
MyTim_output->pause();
425430
MyTim_output->setMode(Output2_channel, TIMER_OUTPUT_COMPARE_PWM1, TIM1_CH2_PIN);
426431
MyTim_output->setCaptureCompare(Output2_channel, OUTPUT_DUTY2, PERCENT_COMPARE_FORMAT);
427432
MyTim_output->resumeChannel(Output2_channel);
@@ -571,6 +576,7 @@ void loop()
571576
}
572577
test_step++;
573578

579+
MyTim_output->pause();
574580
MyTim_output->setPWM(Output1_channel, TIM1_CH1N_PIN, OUTPUT_FREQUENCY, OUTPUT_DUTY1);
575581
Verify_output(1, OUTPUT_FREQUENCY, OUTPUT_DUTY1);
576582
test_step++;
@@ -588,4 +594,4 @@ void loop()
588594
while (1)
589595
{
590596
};
591-
}
597+
}

0 commit comments

Comments
 (0)