stm32/timer: Cannot specify timer callbacks using callback(). #9182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes issue #8732.
MicroPython Version
v1.19.1
How to reproduce
Execute attached in #8732.
Specified callback is not called.
Detail of changes
Since HAL version 1.17.0, HAL_TIM_IC_Start_IT() checks whether specified channel of timer is busy or not.
For more detail of changes, see
git diff 540ae5c5 9153dc73 STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c
in lib/stm32lib.timer.c calls HAL_TIM_IC_Start() when callback parameter is not specified.
micropython/ports/stm32/timer.c
Lines 1249 to 1253 in 0b26efe
After callback() is called by python, call HAL_TIM_IC_Start_IT() at
micropython/ports/stm32/timer.c
Lines 1589 to 1591 in 0b26efe
but the timer is already running, so HAL_TIM_IC_Start_IT() returns HAL_ERROR and irq of timer is not enabled here.
This issue is not occurred if Timer.channel() is called with paramerter 'callback' because HAL_TIM_IC_Start_IT() is called in pyb_timer_channel_callback() and irq of timer is enabled.
To prevent this error, call HAL_TIM_IC_Stop_IT() before HAL_TIM_IC_Start_IT().
Mode PWM and OC have same issue, so I also fixed those.