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
Fix GPIO AF settings being overridden by timerInit(). #12886
Conversation
Do you want to test this code? You can flash it directly from Betaflight Configurator:
WARNING: It may be unstable. Use only for testing! |
There are binaries for testing in betaflight/config#66 for the SPRacingH7ZERO and SPRacingH7NANO. The former of which requires this PR to boot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasonable first step. But isn't it possible to init timers only when they are used.
Also, this PR does not affect non-hal times. Is that intentional?
This is the simplest work-around to allow targets to boot until a BF maintainer, i.e. not me, comes up with a long-term solution. I looked for similar code in timer_stdperiph.c but didn't find it. I didn't check any other architectures either. FYI: From what I can tell the code was broken in #12862 by @blckmn The default was The check that was removed was this:
Enjoy! |
I agree with @ledvinap. We can initialise the AF when the pin is first requested to be used with a timer. I'm happy to clean this up given I broke it. |
FYI, this PR is the quickest thing I could think of that would allow me to continue working on restoring the H7ZERO target. I didn't spend a lot of time on this PR, nor do I intend to. Suggest merging as-is, and then @blckmn can do a follow-up PR which should be tested on the H7ZERO before being merged. This PR is tested on 4 H7 targets, binaries are in the linked issue. |
Going to merge immediately as it fixes the issue, and I'll work on a longer term fix. |
Servos, PWM Motor outputs all seem to have the IOConfigGPIOAF already located within their respective @ledvinap explains why it may have only been present for the HAL driver, a hangover. |
There's already comments in the Thanks everyone for being pragmatic and getting this merged. |
timerInit
blindly reconfigures GPIO AF for all pins in thefullTimerHardware
array regardless of if the timer pin is used already by something else.For example, if it is called AFTER the SPI initilisation (e.g. after
configureSPIBusses
), then any AF settings for the SPI are overridden by timer AF, making the SPI hang when it's used.This PR extracts the AF init code into
timerIOInit
and calls it early in the init code.Targets like the SPRacingH7ZERO, which use PB3/PB4 for SPI3 gyro, now boot. With out this PR the target would hang on SPI3 access because the GPIO AF settings were reset from AF6 (SPI3) to AF1 and AF2 respectively.