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

WIP - SerialX(__UART__) tx speedup and fixes #59

Closed
wants to merge 1 commit into from

Conversation

KurtE
Copy link
Contributor

@KurtE KurtE commented Jul 18, 2023

Should address: #44

@facchinm, and others, would be good to get your feedback on this.
Short version:
The current released code, outputs one character at at time and waits for the first callback, which could be because of TDRE or transfer complete, before returning. It makes no use of the txBuffer which is defined to use 512 bytes. If you call Serial.print/write from ISR today it hangs.

First attempts where to continue using R_SCI_UART_Write, but there were/are difficulties in getting this to work, as it simply wants to output a buffer of size N. Once that is done, it calls the callback to the UART code. If I then try to start up a new transfer, in the callback, you will often lose one character. As they will notify you of the TDRE like condition as they have already output the last character in your buffer, and if you call the R_SCI_UART_Write, it will blindly write one character out into the transfer register, but the TDRE condition is not true, so you overwrite the last character of previous buffer....

So this version does not call their write, but instead handles the TDRE like code itself...

Longer version below:

This is a WIP.

The released code does not use the write(buf, cnt) code, but instead unrolls it to use the one byte at a time, as the method signature did not match that in print (missing const)

Fixing this uncovered lots of issues where data would be lost as, you would typically call to output again while the last one was still putting and could lose one or two bytes.

This code bypasses the R_SCI_UART_Write(&uart_ctrl, c, len); functions and instead I do my own code wheich utilizes the txBuffer that was already part of the class. The code both fills the buffer and if the hardware buffer has room, it takes characters from the txBuffer to fill it.

I also implemented my own version of the TDRE interrupt, to again simply take data from our txBuffer.

But to do this without changing the underlying layers, I implemented a version of attachInterruptVector, that plugs in the location of my ISR handler into the interrupt vector.

Probably could/should overwrite some of the others as well.

the SerialX.flush() code was completely busted. But you hardly noticed it before as you were only outputting one character at a time and then waiting for an interrupt before returning.

I have some debug code still in here, hopefully disabled by a #define.

This is a WIP.

The released code does not use the write(buf, cnt) code, but instead unrolls it to use the one byte at a time, as the method signature did not match that in print (missing const)

Fixing this uncovered lots of issues where data would be lost as, you would typically call to output again while the last one was still putting and could lose one or two bytes.

This code bypasses the R_SCI_UART_Write(&uart_ctrl, c, len); functions and instead I do my own code wheich utilizes the txBuffer that was already part of the class.  The code both fills the buffer and if the hardware buffer has room, it takes characters from the txBuffer to fill it.

I also implemented my own version of the TDRE interrupt, to again simply take data from our txBuffer.

But to do this without changing the underlying layers, I
implemented a version of attachInterruptVector, that plugs in the location of my ISR handler into the interrupt vector.

Probably could/should overwrite some of the others as well.

the SerialX.flush() code was completely busted.  But you hardly noticed it before as you were only outputting one character at a time and then waiting for an interrupt before returning.

I have some debug code still in here, hopefully disabled by a #define.
@CLAassistant
Copy link

CLAassistant commented Jul 18, 2023

CLA assistant check
All committers have signed the CLA.

@KurtE
Copy link
Contributor Author

KurtE commented Aug 1, 2023

Going to close this one out, and replace with different version.

No feedback, I am taking as probably not an approach that would be accepted. So reimplemented to not change or bypass the lower layer.

@KurtE KurtE closed this Aug 1, 2023
pennam pushed a commit to pennam/ArduinoCore-renesas that referenced this pull request Aug 9, 2023
cristidragomir97 pushed a commit to cristidragomir97/ArduinoCore-renesas that referenced this pull request May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants