Skip to content

Conversation

@gschorcht
Copy link
Contributor

Backport of PR #19146

Contribution description

This PR fixes issue #19138 that was introduced with PR #19100. It contains the following changes to fix the problems and to improve the UART initialization:

  • If LOG_LEVEL is greater or equal 4, such as in tests/log_printfnoformat, the ESP-IDF config function called for the GPIO pins of the UART will output the configuration with printf before the _GLOBAL_REENT structure is initialized. This causes a crash during system startup. Therefore the initialization by syscalls_init must be called by `earlier in the startup procedure.

  • Since PR cpu/esp_common: allow configuration of UART0 #19100 it is possible to define:

    • other pins for UART_DEV(0) than the default pins
    • different UART_DEV(0) pins for the bootloader and RIOT

    To allow correct reinitialization of the UART pins used by the bootloader as well as their usage for other purposes, the pin usage for the default UART0 pins and the UART pinsused by the bootloader are reset to _GPIO. This is done in uart_system_init which has to be called earlier in the startup procedure.

  • To avoid garbage on reconfiguring the UART console pins, e.g. in initialization of the arduino module, pins that are already configured as UART pins must not be initialized.

  • To avoid a several msec long LOW pulse resulting in some garbage during the UART initialization, the TX line is set to HIGH and temporarily configured as a pull-up open-drain output before configuring it as a push-pull output.

The PR requires a backport to 2023.1

Testing procedure

The following tests should work with this PR:

  • tests/log_color
  • tests/log_printfnoformat
  • tests/sys_arduino

Issues/PRs references

Fixes #19138

If LOG_LEVEL >= 4, such as in `tests/log_printfnoformat`, the ESP-IDF config function called for the GPIO pins of the UART will output the configuration with `printf` before the `_GLOBAL_REENT` structure is initialized. This causes a crash during system startup. Therefore the initialization by `syscalls_init` must be called earlier in the startup procedure.
Since PR RIOT-OS#19100 it is possible to define:
- other pins for `UART_DEV(0)` than the default pins
- different `UART_DEV(0)` pins for the bootloader and RIOT
To allow correct reinitialization of the UART pins used by the bootloader as well as their usage for other purposes, the pin usage for the default UART0 pins and the UART pins used by the bootloader are reset to `_GPIO`. This is done in `uart_system_init` which has to be called earlier in the startup procedure.
The TX line is set and temporarily configured as a pull-up open-drain output before configuring it as a push-pull output to avoid a several msec long LOW pulse resulting in some garbage.
To avoid garbage on reconfiguring the UART console pins, e.g. in initialization of the `arduino` module, pins that are already configured as UART pins must not be initialized.
@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Jan 15, 2023
@gschorcht gschorcht added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 15, 2023
@gschorcht gschorcht requested review from benpicco and maribu January 15, 2023 09:49
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

backport-ACK.

@riot-ci
Copy link

riot-ci commented Jan 15, 2023

Murdock results

✔️ PASSED

638fc18 cpu/esp32: don't initialize the UART pins if already initialized

Success Failures Total Runtime
6770 0 6770 14m:10s

Artifacts

@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Jan 15, 2023

Build succeeded:

@bors bors bot merged commit 24774dc into RIOT-OS:2023.01-branch Jan 15, 2023
@gschorcht gschorcht deleted the backport/2023.1/cpu/esp32/fix_uart_initialization branch February 1, 2023 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ESP Platform: This PR/issue effects ESP-based platforms 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.

4 participants