Skip to content

cpu/stm32: Fix garbage on UART init [backport 2020.07] #14426#14529

Merged
miri64 merged 2 commits intoRIOT-OS:2020.07-branchfrom
maribu:backport-uart-stm32
Jul 15, 2020
Merged

cpu/stm32: Fix garbage on UART init [backport 2020.07] #14426#14529
miri64 merged 2 commits intoRIOT-OS:2020.07-branchfrom
maribu:backport-uart-stm32

Conversation

@maribu
Copy link
Copy Markdown
Member

@maribu maribu commented Jul 15, 2020

Backport of #14426

Contribution description

cpu/stm32: Fix gpio_init() / gpio_int_af()

  • 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)

cpu/stm32: Fix uart_init()

  • 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

Testing procedure

  • UART should still work for STM32F1 and STM32Fx (x != 1)
  • 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

maribu added 2 commits July 15, 2020 21:34
- 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
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: release backport Integration Process: The PR is a release backport of a change previously provided to master labels Jul 15, 2020
@maribu maribu requested a review from MrKevinWeiss as a code owner July 15, 2020 19:37
@miri64
Copy link
Copy Markdown
Member

miri64 commented Jul 15, 2020

@maribu Since the format is different: do you know about dist/tools/backport_pr?

@miri64 miri64 added this to the Release 2020.07 milestone Jul 15, 2020
Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are identical to #14426

@miri64 miri64 merged commit 92184c9 into RIOT-OS:2020.07-branch Jul 15, 2020
@maribu
Copy link
Copy Markdown
Member Author

maribu commented Jul 16, 2020

@maribu Since the format is different: do you know about dist/tools/backport_pr?

No, I didn't. Thanks for the pointer!

@maribu maribu deleted the backport-uart-stm32 branch July 16, 2020 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: release backport Integration Process: The PR is a release backport of a change previously provided to master Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants