-
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/esp32: add the new API function uart_mode to periph/uart #11231
cpu/esp32: add the new API function uart_mode to periph/uart #11231
Conversation
So far we have agreed upon making Other than that looks good to me. |
I didn't embed the function in
Furthermore, since |
I think @haukepetersen, @MrKevinWeiss what do you think? |
@yegorich I'm not sure whether
since it belongs to peripheral interfaces like |
That's true for |
I have realized it now in that way that there is an internal function |
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.
Green light from me.
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.
Would you be willing to split the PRs into a cleanup __uart -> _uart
and the mode functionality?
I can do some testing at the end of the week.
cpu/esp32/periph/uart.c
Outdated
/* wait until TX FIFI is empty */ | ||
while (_uarts[uart].regs->status.txfifo_cnt != 0) { } | ||
|
||
critical_enter(); |
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.
Can you put some information on why you added the critical*, does it apply to the *_mode or is it something separate
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.
It has to be ensured that the reconfiguration cannot be interrupted. Even though it is something I realized when I was testing _uart_set_mode
, I think it has to be ensured for reconfiguring the baudrate too. That's why I added it with this PR.
@MrKevinWeiss Thank you for reviewing the PR.
Hm, ... It is only a very small naming fix to get the code compatible with the reimplementation of ESP8266 in PR #11108 which will allow code deduplication with future PRs. Sure, I could provide a separate PR, but I didn't want to open too many different development branches which later cause a lot of merging conflicts or too many dependencies of different PRs. But, if you think that it might be better to have different PRs, I would provide a separate PR for renaming and would make the this PR dependent on the separate PR. BTW, PR #10644 requires changed names too. |
a1e9e52
to
fc72ca3
Compare
@MrKevinWeiss At the moment, this PR includes all commits of PR #11276 since I couldn't separate it completely due to unresolvable merge conflicts. Once, PR #11276 is merged, I will rebase this PR to remove them. |
No problem, the cleanup PR should get in soon. |
I guess ready for rebase now 😃 |
fc72ca3
to
43c144f
Compare
@MrKevinWeiss Rebased to current master 😄 |
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.
I think it is pretty good. I tested with loopback but I would like to confirm with the scope (so not until Thursday or Friday). Outside of that I am happy.
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.
Tested against scope. Only the stop bits seem to be an issue, everything else appeared correct.
case UART_STOP_BITS_1: _uarts[uart].regs->conf0.stop_bit_num = 1; | ||
_uarts[uart].regs->rs485_conf.dl1_en = 1; | ||
break; | ||
case UART_STOP_BITS_2: _uarts[uart].regs->conf0.stop_bit_num = 1; |
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.
Should this be 2? Either that or say not implemented.
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.
No, it is a known hardware bug. _uarts[uart].regs->conf0.stop_bit_num
has to be set to 1
if there is any stop bit. With _uarts[uart].regs->rs485_conf.dl1_en
it is decided whether there are 1 or 2 stop bits.
critical_exit(); | ||
return UART_NOMODE; | ||
} | ||
#else |
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.
Is the ifdef needed here since they are all MCU_ESP32 that use this file?
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.
Yes, at the moment. But, the UART source code is already compatible with that of the complete ESP8266 reimplemenation in PR #11108 (https://github.com/RIOT-OS/RIOT/blob/2f008018200c180a96f6457e7d0ec655b2209510/cpu/esp8266/periph/uart.c). To make planned deduplication easier, I'm already adapting the ESP32 code if I make changes.
Thanks.
What exactly is the issue? It worked for me. |
No difference between 1 stop bit and 2 stop bits, it appears that the second stop bit is not being sent (always just one stop bit). Also in the code it appears you are assigning the same thing if you set stop bits to 1 or 2. case UART_STOP_BITS_1:
_uarts[uart].regs->conf0.stop_bit_num = 1;
_uarts[uart].regs->rs485_conf.dl1_en = 1;
break;
case UART_STOP_BITS_2:
_uarts[uart].regs->conf0.stop_bit_num = 1;
_uarts[uart].regs->rs485_conf.dl1_en = 1;
break; |
At least this is how ESP-IDF sets stop bits: https://github.com/espressif/esp-idf/blob/106dc05903a1691c024bb61ac7b29ca728829671/components/driver/uart.c#L139
|
Ups, oh yeah. It should be case UART_STOP_BITS_1:
_uarts[uart].regs->conf0.stop_bit_num = 1;
_uarts[uart].regs->rs485_conf.dl1_en = 0;
break; This happened propably when I changed it back from trying to remove the hack due to the hardware bug. I thought that it is not necessary to test it again since it worked before 😎 |
Once it is in the HiL retesting shouldn't be a problem |
@MrKevinWeiss Fixed it, but I have no hardware here for testing it again. |
Leave it to me! |
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.
Retested and can see stop bit 2.
Please squash.
ACK!
Add data members to the UART device configuration data structure that are needed by uart_mode API function.
Set default values for additional data members of UART device configuration data structure that are needed by uart_mode API function.
Configuration of UART mode is realized by an internal function which is also used by UART initialization function.
The internal _uart_set_mode function is exposed if module periph_uart_modecfg is enabled.
cc6bd45
to
217ccbe
Compare
@MrKevinWeiss Thanks for reviewing and testing. |
Contribution description
This PR adds API function
uart_mode
according to PR #10743 toperiph/uart
low level driver of ESP32 implementation. The PR depends on some in PR #11276.Testing procedure
tests/periph_uart
with enabled moduleperiph_uart_modecfg
Connect GPIO9 [UART_DEV(1):RX] and GPIO10 [UART_DEV(1):TX].
Use the following commands and observe the UART communication with a logic analyzer
Issues/PRs references
Depends on PR #11276
Implementation according to #10743