RFC: UART enhanced settings#10743
Conversation
MrKevinWeiss
left a comment
There was a problem hiding this comment.
A few things to note, I can test and look deeper tomorrow.
|
Did you consider a combined value for all options? E.g., In addition, define the most used ones as speaking defines: My main reason would be that this way, uart users actually using modes don't need all the fields: |
|
@kaspar030 we already had this discussion here and so I've made this PR according to it. |
484f239 to
fefe813
Compare
fefe813 to
c9bbadb
Compare
|
v2 changes:
TODO: convert uart_mode() to a feature |
c9bbadb to
433693e
Compare
433693e to
cae00a1
Compare
|
v3 changes:
|
|
@bluephoton could you test this PR with your setup and report the results here? Thanks. |
|
@yegorich , I gave it a try but it didn't work! I know that I need to invert RX for my scenario so I added the following code (at the very end before you enable uart): but this didn't help! I'll look bit more tomorrow, in case its something with my environment. Here is how I initialize (working case): Here is with new uart_mode (not working case): Couple notes on implementation:
|
|
@yegorich I found the culprit! Two issues:
I also recommend replacing all numeric constants with actual macro as defined in CMSIS header file. Also not use _M (mask) and use actual bit value (even if it happen to be the same) like: Edit: Added comments on the exact code location with changes required |
cae00a1 to
ceacf21
Compare
haukepetersen
left a comment
There was a problem hiding this comment.
some small findings left, closing in...
14bf254 to
ba48dba
Compare
a4a66a0 to
dc67f4b
Compare
haukepetersen
left a comment
There was a problem hiding this comment.
1 left, then we can merge.
As suggested in PR#5899 add a routine uart_mode() that will setup data bits, stop bits and parity at runtime. uart.h provides a set of enums defining these settings and each platform will override them to specify values corresponding to its configuration registers. The idea behind the enums is to specify default settings i.e. 8N1 through the 0 value item. Invoking uart_mode(uart, 0, 0, 0) will setup 8N1 mode. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Add support for specifying data bits, stop bits and parity at runtime. Introduce feature periph_uart_modecfg for uart_mode() till all other CPUs implement it. STM32 L1, F1, F2, F4 supports following modes: * 7E1, 7E2 * 7O1, 7O2 * 8N1, 8N2 * 8E1, 8E2 * 8O1, 8O2 STM32 L0, L4, F0, F3, F7 supports following modes: * 6E1, 6E2 * 6O1, 6O2 * 7E1, 7E2 * 7O1, 7O2 * 7N1, 7N2 * 8N1, 8N2 * 8E1, 8E2 * 8O1, 8O2 Use USART_CR1_M1 macro to detect 7-bit support because even inside one family there could be devices that don't support 7-bit mode. So just using a family macro is not enough. As stated in the datasheets for L0, L4, F0, F3, F7 devices, data bits can only be changed when UART is disabled (UE=0). Introduce uart_stop() routine to satisfy this requirement. STM32 UART adds parity to the MSB of a byte to send. The same also applies to the received bytes. As a result this bit must be masked in order to get the pure data. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Add command mode that will be used like this: mode <dev> <data bits> <parity> <stop bits> This command must be called after init otherwise the UART won't be fully initialized. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Add positive and negative tests for data bits, stop bits and parity: - 7E1, 7O1 - 8E1, 8O1 - 8N2 Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
dc67f4b to
2673b66
Compare
haukepetersen
left a comment
There was a problem hiding this comment.
ACK from my side.
BUT to make sure: I did not compile or test any of this code, I just did a code quality and style review...
|
@MrKevinWeiss could you give this a final test-run? Thx. If you succeed, feel free to merge! |
|
Ok hold for retesting |
|
Seems good to me. GO! |
Contribution description
As suggested in PR #5899 add a routine uart_mode() that will setup databits, stopbits and parity at runtime.
uart.hprovides a set of enums defining these settings and each platform will override them to specify values corresponding to its configuration registers.The idea behind the enums is to specify default settings i.e. 8N1 through the 0 value item. Invoking
uart_mode(uart, 0, 0, 0)will setup 8N1 mode.9-bit mode was excluded as UART API is working with uin8_t data units.
As a proof of concept uart_mode was implemented for STM32 UART and tested on Nucleo-F411re.
Testing procedure
periph_uart test was extended with
modecommand that will be invoked directly afterinitcommand. Below some examples:mode 1 8 e 1- configures 8E1 mode, i.e. 8 databits, even parity and 1 stopbitmode 1 7 o 2- configures 7O2 mode, i.e. 7 databits, odd parity and 2 stopbitsIssues/PRs references
This PR reimplements PR #5899 for general use.