Skip to content

PIO Serial.flush - seems to take too much time #3256

@zmechu

Description

@zmechu

Hello!

Using ArduinoIDE for RP2040 programming. Use serial transmission (PIOSerial, 115k) for sending data, with code:

(...)
int SerialBufferSize=512;
SerialPIO PIOSerial3 (10, 11, SerialBufferSize);
(...)
HardwareSerial* port=nullptr;
port = &PIOSerial3; 
(...)

gpio_put(DIR_PIN, true); //start sending

port->write(txFrameBuffer, totalLen); //sending

gpio_put(DIR_PIN, false); //sending end

Of course it fails, because “sending end” information raise to early - DIR_PIN going low during transmission (upper: data frame, lower DIR_PIN state):

Image

So, lets use Serial.flush() which check when output buffer will be empty (all data sent):

gpio_put(DIR_PIN, true);

port->write(txFrameBuffer, totalLen);

port->flush();  

gpio_put(DIR_PIN, false);

Much better, but.. why Serial.flush() tooks so much time longer? All Serial goes out, but DIR_PIN is HIGH for over 170us after real transmission ends?

Image

Lets do other test - change serial speed to 9600:

Image

The same situation, too long “tail” but seems almost fine

So, speed up to 961k:

Image

Seems Serial.flush() takes about 10x more time than real transmission time! As I see, Serial.flush() executes not less than ~1ms (?)

My questions are:

  • Does Serial.flush() should works like that?
  • How proper check when serial transmission ends?

Best regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions