Skip to content

UARTSerial output does not work with REALTEK_RTL8195AM #6358

@SeppoTakalo

Description

@SeppoTakalo

Description

  • Type: Bug
  • Target: REALTEK_RTL8195AM

Following example should work on all platforms, but crashes on REALTEK_RTL8195AM.

#include "mbed.h"

int main() {
    UARTSerial *serial = new UARTSerial(USBTX, USBRX);
    serial->set_baud(115200);

    FILE *out = fdopen(serial, "w");
    FILE *in = fdopen(serial, "r");

    fprintf(out, "Started!\r\n");

    while (true) {
        int c = fgetc(in);
        if (c != EOF) {
            fprintf(out, "Input: %c\r\n", c);
        } else {
            return 0;
        }
    }
}


This, however works:

#include "mbed.h"

int main() {
    UARTSerial *serial = new UARTSerial(USBTX, USBRX);
    serial->set_baud(115200);

    //FILE *out = fdopen(serial, "w");
    FILE *in = fdopen(serial, "r");

    printf("Started!\r\n");

    while (true) {
        int c = fgetc(in);
        if (c != EOF) {
            printf("Input: %c\r\n", c);
        } else {
            return 0;
        }
    }
}

Problem seems to be in the TX interrupt of the serial port.
Following code is able to crash the device using RawSerial:

#include "mbed.h"

int c = 0;
RawSerial *serial;

void tx_avail(void)
{
    while (serial->writeable())
        serial->putc((c++ % 95) + ' ');
}

int main() {
    serial = new RawSerial(USBTX, USBRX, 115200);

    core_util_critical_section_enter();
    serial->attach(tx_avail, SerialBase::TxIrq);
    tx_avail();
    core_util_critical_section_exit();

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions