Skip to content
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/esp32: periph uart cleanups #11276

Merged
merged 6 commits into from
Mar 26, 2019

Conversation

gschorcht
Copy link
Contributor

@gschorcht gschorcht commented Mar 26, 2019

Contribution description

This PR contains different cleanups which will make future merging with the reimplementation of ESP8266 easier. These are in detail:

  • Removes the additional _ of static symbols that has been added by mistake.
  • Moves internal function _uart_config moved to internal function section.
  • Moves external functions to external function section.
  • Declares now all functions that are only used internally as static.
  • Declares function uart_set_baudrate which is used only internally as static and renames it to _uart_set_baudrate.
  • Now handles baudrate reconfiguration as a critical section.

Testing procedure

Compile and flash the tests/uart application for a board that defines UART_DEV(1), e.g., esp32-wroom-32:

make BOARD=esp32-wroom-32 -C tests/periph_uart flash

Connect GPIO9 and GPIO10 and execute the following test in terminal program

init 1 9600
send 1 test

You should be able to observe the following output:

> init 1 9600
Success: Initialized UART_DEV(1) at BAUD 9600
UARD_DEV(1): test uart_poweron() and uart_poweroff()  ->  [OK]
> 
> send 1 test
UART_DEV(1) TX: test
> 
> Success: UART_DEV(1) RX: [test]\n

Issues/PRs references

Prerequisite for PR #11231

An additional _ for static symbols has been added by mistake and should be removed. This will make future merging with the reimplementation of ESP8266 easier.
For consistency reasons, internal function _uart_config was moved to the section of internal functions.
For consistency reasons, external functions were moved to the section of external functions.
The interrupt handler is only used internally and declared to be static.
Function uart_set_baudrate which is only used internally was made static and renamed to _uart_set_baudrate to indicate that it is an internal function. Furthermore, an additional waiting for flushed TX FIFO added. The reconfiguration is now handled as critical section.
@gschorcht gschorcht requested a review from MrKevinWeiss March 26, 2019 09:24
@gschorcht gschorcht added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Platform: ESP Platform: This PR/issue effects ESP-based platforms Area: cpu Area: CPU/MCU ports labels Mar 26, 2019
Copy link
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

All changes look good, I still need to confirm with testing before I can ACK

@MrKevinWeiss MrKevinWeiss added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 26, 2019
Copy link
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

Well I tested on the esp32-wroom and it seems to be fine.

I did notice an issue when leaving the GPIO9 and GPIO10 connected after a reset then trying to init gives some weird output then crashes. This is in master as well so maybe it is me?

# Have GPIO9 and GPIO10 connected
make BOARD=esp32-wroom-32 -C tests/periph_uart flash term
# After term is connected
init 1 9600
# it crashes, wait until reset
# disconnect gpio pins
init 1 9600
# it works...
# reconnect the gpio pins for loopback
send 1 test
# it works
# init again with gpio connected
init 1 9600
send 1 test
# it works
# press the reset button with gpio left in
init 1 9600
# it crashes

Seeing as this is in master as well, I don't think it is an issue for the PR but I would like someone else to verify or explain why this happens...

@MrKevinWeiss
Copy link
Contributor

The crash output I get

init 1 9600
2019-03-26 12:45:06,756 - INFO # EXCE������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������d MHz.
2019-03-26 12:45:06,951 - INFO # ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������...

@gschorcht
Copy link
Contributor Author

@MrKevinWeiss Thank you for testing and figuring out the problem.

I did notice an issue when leaving the GPIO9 and GPIO10 connected after a reset then trying to init gives some weird output then crashes.

Hm ... interessting. I haven't seen this problem before with the boards I used for testing. But, I have a board where I can reproduce it. The crash output

2019-03-26 12:45:06,756 - INFO # EXCE

is the beginning of an exception message.

GPIO9 and GPIO10 are critical on some boards because they are connected as additional data lines to the SPI flash memory for the QOUT and QIO flash modes. Normally, these GPIOs should be available when QOUT/QIO flash modes are not used. Obviously this does not seem to be the case with some boards. I have to think about whether it makes sense to forbit the use of these GPIOs to avoid such problems.

Could you test again with other GPIOs by overwriting the default board configuration:

CFLAGS='-DUART1_RXD=GPIO16 -DUART1_TXD=GPIO17' make BOARD=esp32-wroom-32 -C tests/periph_uart

@gschorcht
Copy link
Contributor Author

gschorcht commented Mar 26, 2019

@MrKevinWeiss Thanks you again for figuring out this problem. I could also reproduce it with tests/periph_gpio.

# reset
init_out 0 10
# crashes
# reset
init_in 0 9
init_out 0 10
# works

The problem was caused by initialization order of RX and TX GPIOs. Unfortunatly, TX GPIO was initialized first. This might lead to crashes if RX GPIO was initialized as output before.

Normally, all GPIOs should be initialized as inputs after startup, and the order of GPIO initialization should not matter. However since GPIO9 and GPIO10 are used as data lines during boot, the mode of GPIO9 could be output mode.

I have provided an additional commit to this PR which fixes this Problem. It would be great, if you could check again whether it now also works with your board.

The GPIO for RX has to be initialized as input before the GPIO for TX can be initialized as output. Otherwise it could lead to creash if RX GPIO was used as output before.
@MrKevinWeiss
Copy link
Contributor

Very good, I will test in two hours but everything looks good.

Copy link
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

Tested, everything looks good to me! ACK!

@MrKevinWeiss MrKevinWeiss merged commit 14d17b6 into RIOT-OS:master Mar 26, 2019
@gschorcht
Copy link
Contributor Author

@MrKevinWeiss Thanks

@gschorcht gschorcht deleted the cpu/esp32/periph/uart/cleanup branch March 29, 2019 06:43
@danpetry danpetry added this to the Release 2019.04 milestone Apr 11, 2019
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: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants