Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32L4: Timer callbacks broken after stmlib L4-1.17.0 #8732

Closed
chrismas9 opened this issue Jun 7, 2022 · 2 comments
Closed

STM32L4: Timer callbacks broken after stmlib L4-1.17.0 #8732

chrismas9 opened this issue Jun 7, 2022 · 2 comments
Labels

Comments

@chrismas9
Copy link
Contributor

Timer callbacks seem to be broken for STM32L4 series after stmlib was updated to L4-1.17.0. Tested on custom L496 board and NUCLEO-L452RE. Works on F401, F411 and F405. Not tested on L0, F0, F7, H7, G0, G4 or WB.

On NUCLEO-L452RE the attached test script works on V1.17-147-gd72d699da but fails on V1.17-240-gbc1b0fd2c. I can't see any relevant changes to MicroPython code between these, except for the library update. Also fails with the latest nightly build of NUCLEO-L452RE, so not dependant on build environment.

The issue can be duplicated by running the attached test script on any board with PB15 (output) jumpered to PA1 (input). Rising edges on PA1 should trigger a calback, flash LED1 and print the capture time once per second.

callback.zip

@chrismas9 chrismas9 added the bug label Jun 7, 2022
@yn386
Copy link
Contributor

yn386 commented Sep 1, 2022

I tried to be duplicated by running the attached script with NUCLEO-F446RE.

I could not be duplicated with MicroPython v1.19.1-358-g0b26efe73.
This version uses STM32CubeF4 version 1.16.0.
But using STM32CubeF4 version v1.27.1, this issue could be duplicated on NUCLEO-F446RE.

I found some changes about timer between v1.16 and v1.27.1 and the implementation of timer.c should change for v1.27.1.
So I'm trying to implement it.
STM32CubeL4 also includes these changes, so this implementation may also fix this issue on STM32L4.

For workaround, specify callback when creating gps_PPS_IC like following change can prevent this issue.

--- callback.py.1	2022-09-01 17:22:03.976472646 +0900
+++ callback_f4.py	2022-09-01 17:20:48.323016890 +0900
@@ -55,8 +55,7 @@
 
     timer_PPS = Timer(2, prescaler=0, freq = 1)
     fake_PPS_out_PWM = timer_PPS.channel(1, Timer.PWM, pin=fake_PPS_out, pulse_width_percent=10) # PA0
-    gps_PPS_IC = timer_PPS.channel(2, Timer.IC, pin=gps_PPS_in, polarity=Timer.RISING) # PA1
-    gps_PPS_IC.callback(gps_callback)
+    gps_PPS_IC = timer_PPS.channel(2, Timer.IC, callback=gps_callback, pin=gps_PPS_in, polarity=Timer.RISING) # PA1
     print('Waiting for callbacks')
 
     while 1:

yn386 added a commit to yn386/micropython that referenced this issue Sep 1, 2022
dpgeorge pushed a commit that referenced this issue Sep 6, 2022
Since L4 HAL version 1.17.0, HAL_TIM_IC_Start_IT() checks whether specified
channel of timer is busy or not, which is the case if this function is
called more than once without first calling HAL_TIM_IC_Stop_IT().  The fix
in this commit is to call the stop function before calling start.  The PWM
and OC modes have the same issue with the same fix.

Fixes issue #8732.
@dpgeorge
Copy link
Member

dpgeorge commented Sep 6, 2022

Fixed by 989b8c7

@dpgeorge dpgeorge closed this as completed Sep 6, 2022
karfas pushed a commit to karfas/micropython that referenced this issue Apr 23, 2023
Since L4 HAL version 1.17.0, HAL_TIM_IC_Start_IT() checks whether specified
channel of timer is busy or not, which is the case if this function is
called more than once without first calling HAL_TIM_IC_Stop_IT().  The fix
in this commit is to call the stop function before calling start.  The PWM
and OC modes have the same issue with the same fix.

Fixes issue micropython#8732.
alphonse82 pushed a commit to alphonse82/micropython-wch-ch32v307 that referenced this issue May 8, 2023
Since L4 HAL version 1.17.0, HAL_TIM_IC_Start_IT() checks whether specified
channel of timer is busy or not, which is the case if this function is
called more than once without first calling HAL_TIM_IC_Stop_IT().  The fix
in this commit is to call the stop function before calling start.  The PWM
and OC modes have the same issue with the same fix.

Fixes issue micropython#8732.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants