-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/stm32: Fix garbage on UART init #14426
Conversation
cpu/stm32/periph/gpio_all.c
Outdated
return _gpio_init(pin, mode, 0); | ||
} | ||
|
||
int gpio_init_set(gpio_t pin, gpio_mode_t mode) |
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.
How about gpio_init_high()
😉
Then, should #12612 get merged we just have to define GPIO_HAVE_INIT_LEVEL
Is
the garbage? do I need to interface directly over uart or though the debugger works? Or do I need a logic analyzer? |
Yep, exactly. With a logic analyzer you should be able to confirm that the initialization is only "almost flicker free", as the pin sadly still goes briefly down during initialization. However, with this PR the duration of the pin being LOW during initialization is much shorter. On my Nucleo F446RE, I tested booting about 50 times and the UART interface of the debugger never picked up this as a start bit, while it previously got a 0xff character on every boot. For testing this PR just using |
In that case just with make term I still get the garbage |
It seems I god lucky with my UART adapter: Console output (multiple reboots triggered via reset button)
With the logic analyzer I can however see a start bit long enough that it should actually be detected by my UART adapter. |
OK. For the STM32F1xx I found the culprits:
I think I don't need I will update this PR when I have time to clean up the WIP code. |
I updated the fix and force pushed, as this is basically a rewrite compared to the original approach. Now the result is correct even when using a logic analyzer. There should be no garbage being detected anymore. I think this fix might need a bit more testing, as a broken GPIO implementation might result in very unhappy users. Btw: I realized that I think the odds of this resulting in an issue are pretty low, as most GPIO initialization is done during |
I'll rebase to fix a typo in a commit message. I wont change the commits or squash. (I'll also disable ready for build now: Now need to rebuild for a changed commit message.) |
Out of the bugs still open for the release, this is likely the least important one. The UART is working reliable after the first broken character without this. So we might focus on the other open PRs first. (IMO, we might even just leave this out of the release. UART is known to not be super reliable anyway, so one if one byte of garbage more breaks some application, that application is desperately in need of some error detection mechanism anyway.) |
This now realiably fixes the issue for me on PR
master
|
If uart works then |
Please squash @maribu and trigger ci! |
- Do not set an intermediate mode, prepare correct mode settings in a temporary variable - Consistently enabled the GPIO periph in gpio_init_af() - Previously, STM32 F1 did not require a separate call to gpio_init() prior to a call of gpio_init_af(), but other STM32 families did - Now, gpio_init_af() can be used without gpio_init() consistently - STM32 F1: Do not touch ODR for non input pins - For input pins, this enables / disabled pull up resistors. For outputs, this register should remain untouched (according to API doc)
- Make use of the fact that gpio_init_af() does not need prior call to gpio_init() for all STM32 families anymore and drop call to gpio_init() - Initialize the UART periph first, before initializing the pins - While uninitialized, the UART periph will send signal LOW to TXD. This results in a start bit being picked up by the other side. - Instead, we do not connect the UART periph to the pins until it is initialized, so that the TXD level will already be HIGH when the pins are attached. - This results in no more garbage being send during initialization
b7f7fc0
to
aec9eb7
Compare
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.
Given @fjmolinas tests and the fact that the CI is green. I think we can safely merge this PR.
ACK
@miri64 since this PR is fixing a bug, I think it needs a backport, right ? |
Yepp. |
cpu/stm32: Fix garbage on UART init [backport 2020.07] #14426
Contribution description
cpu/stm32: Fix gpio_init() / gpio_int_af()
cpu/stm32: Fix uart_init()
Testing procedure
gpio_init()
should still work for ST32F1 and STM32Fx (x != 1)Note: It should be sufficient to test with STM32F1 and one of the other STM32 not belonging to the STM32F1 family
Issues/PRs references
Fixes #8045