cpu/esp32: fix and improve UART initialization [backport 2023.01] #19148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_LEVELis greater or equal 4, such as intests/log_printfnoformat, the ESP-IDF config function called for the GPIO pins of the UART will output the configuration withprintfbefore the_GLOBAL_REENTstructure is initialized. This causes a crash during system startup. Therefore the initialization bysyscalls_initmust be called by `earlier in the startup procedure.Since PR cpu/esp_common: allow configuration of UART0 #19100 it is possible to define:
UART_DEV(0)than the default pinsUART_DEV(0)pins for the bootloader and RIOTTo 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 inuart_system_initwhich has to be called earlier in the startup procedure.To avoid garbage on reconfiguring the UART console pins, e.g. in initialization of the
arduinomodule, 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_colortests/log_printfnoformattests/sys_arduinoIssues/PRs references
Fixes #19138