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

HardwareSerial data bits issue? #482

Closed
mrv96 opened this issue Mar 25, 2019 · 6 comments
Closed

HardwareSerial data bits issue? #482

mrv96 opened this issue Mar 25, 2019 · 6 comments
Labels
question ❓ Usually converted as a discussion

Comments

@mrv96
Copy link

mrv96 commented Mar 25, 2019

Hi, i'm analyzing HardwareSerial library, inside begin method i've seen that the variable databits can assume from config the values 6,7,8, but HAL library supports only 7,8,9 data bits. Should the defined configurations be changed and subsequently change the if inside begin method?

@fpistm fpistm added the question ❓ Usually converted as a discussion label Mar 25, 2019
@fpistm
Copy link
Member

fpistm commented Mar 25, 2019

6 databits could be managed with a parity bit on some STM32.
Refers to issue #50 and PR #51
Do not mix uart data and uart frame.

Ex for F3, for some device you can have 6 bits + PB:

#if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
defined(STM32F334x8) || \
defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
#define USART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1) /*!< 7-bit long USART frame */

Additional Table: If the parity is enabled, then the MSB bit of the data written
in the data register is transmitted but is changed by the parity bit.
According to device capability (support or not of 7-bit word length),
frame length is either defined by the M bit (8-bits or 9-bits)
or by the M1 and M0 bits (7-bit, 8-bit or 9-bit).
Possible UART frame formats are as listed in the following table:
Table 1. UART frame format.
+-----------------------------------------------------------------------+
| M bit | PCE bit | UART frame |
|-------------------|-----------|---------------------------------------|
| 0 | 0 | | SB | 8-bit data | STB | |
|-------------------|-----------|---------------------------------------|
| 0 | 1 | | SB | 7-bit data | PB | STB | |
|-------------------|-----------|---------------------------------------|
| 1 | 0 | | SB | 9-bit data | STB | |
|-------------------|-----------|---------------------------------------|
| 1 | 1 | | SB | 8-bit data | PB | STB | |
+-----------------------------------------------------------------------+
| M1 bit | M0 bit | PCE bit | UART frame |
|---------|---------|-----------|---------------------------------------|
| 0 | 0 | 0 | | SB | 8 bit data | STB | |
|---------|---------|-----------|---------------------------------------|
| 0 | 0 | 1 | | SB | 7 bit data | PB | STB | |
|---------|---------|-----------|---------------------------------------|
| 0 | 1 | 0 | | SB | 9 bit data | STB | |
|---------|---------|-----------|---------------------------------------|
| 0 | 1 | 1 | | SB | 8 bit data | PB | STB | |
|---------|---------|-----------|---------------------------------------|
| 1 | 0 | 0 | | SB | 7 bit data | STB | |
|---------|---------|-----------|---------------------------------------|
| 1 | 0 | 1 | | SB | 6 bit data | PB | STB | |
+-----------------------------------------------------------------------+

@mrv96
Copy link
Author

mrv96 commented Mar 25, 2019

Ok sorry, my fault. In any case, for a generic user, it seems that 9 data bits are not achievable by the library, because both defined config miss and databits cannot be 9.

@fpistm
Copy link
Member

fpistm commented Mar 25, 2019

Right, 9 is not achievable.
As Arduino doesn't define it it was not added
https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/
Moreover, HardwareSerial::write allows only uint8_t.

@mrv96
Copy link
Author

mrv96 commented Mar 25, 2019

Ok... i believe that it would better implement it because STM32 is a very powerfull uC. If the software philosopy make it equal as Arduino, why should i use STM32? :) Changing slightly the library, in my current application i use 9 data bits, however it would be fantastic if also less expert people can use the whole STM32 power :)

@fpistm
Copy link
Member

fpistm commented Mar 25, 2019

First goal of this core was to be able to use STM32 based boards with Arduino and to be as more as possible compatible with basics sketches and libraries.
I think this step is achieved 🙄, now core features are/could be extended and also performance/robustness.
All HAL and LL are available at level sketch some advanced user already use it to use further capabilities.

Adding the 9bits support could be a good addition. Do not hesitate to submit a PR.
Any contribution are welcome :)

@fpistm
Copy link
Member

fpistm commented Apr 2, 2019

Close it as no issue.

@fpistm fpistm closed this as completed Apr 2, 2019
@fpistm fpistm mentioned this issue Jul 6, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Usually converted as a discussion
Projects
None yet
Development

No branches or pull requests

2 participants