Skip to content

HardwareSerial data bits issue? #482

Closed

Description

@mrv96

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?

Activity

  1. added
    question ❓
    on Mar 25, 2019
  2. fpistm commented on Mar 25, 2019

    @fpistm
    Member

    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 | |
    +-----------------------------------------------------------------------+

  3. mrv96 commented on Mar 25, 2019

    @mrv96
    Author

    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.

  4. fpistm commented on Mar 25, 2019

    @fpistm
    Member

    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.

  5. mrv96 commented on Mar 25, 2019

    @mrv96
    Author

    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 :)

  6. fpistm commented on Mar 25, 2019

    @fpistm
    Member

    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 :)

  7. fpistm commented on Apr 2, 2019

    @fpistm
    Member

    Close it as no issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question ❓

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions