Skip to content

Hardware serial port RX locks up after overrun error. #494

@benwaffle

Description

@benwaffle

Describe the bug
When you run the following code, and start spamming words (followed by the enter key) on your keyboard, eventually it stops reading data. You can also lock it up by just hitting enter without any letters. The USART1 interrupt stops firing, because the code seems to fail to set TXEIE. It also appears to only happen when there's an overrun error as verified by looking at USART_SR with gdb.

To Reproduce

#include <Arduino.h>

void setup() {
    Serial.begin(9600);
    Serial.println("hello");
}

void loop() {
    if (Serial.available() > 0) {
        printf("Serial available: %d\n", Serial.available());
        char buf[128] = {0};
        char *line = buf;
        size_t nbytes;
        if ((nbytes = Serial.readBytesUntil('\n', buf, sizeof buf)) == 0) {
            printf("# error: no data read from serial\n");
            return;
        }

        printf("# read %d [%s]\n", nbytes, line);
        printf("rest = %d\n", Serial.available());
    }
}

Steps to reproduce the behavior:

  1. Run code
  2. Open a serial monitor (e.g. pio device monitor)
  3. Spam stuff into the serial console. (Or just hit enter)
  4. See it lock up and refuse to take more input.

Expected behavior
Continue receiving input, possibly by dropping the next character.

Desktop (please complete the following information):

  • OS: Mac OS 10.14.3
  • Platformio: 3.6.6
  • STM32 core version: 1.5.0
  • Upload method: STLink

Board (please complete the following information):

  • Name: Bluepill 128k

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions