-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu, sam0_common: fix uart TXC check #7638
Conversation
Tested. This works. |
FWIW, I've also tested without the check completely, and that works too. And is slightly faster at spewing characters at 230400 (I didn't try any other speeds). |
I'd like to suggest a compromise with the TXC test, based on some interaction we had with Microchip/Atmel engineers. We asked them why the ASF version has the TXC check in it:
The RIOT uart_write() function actually writes
I have tested this as well with positive results. It's worth about 1.5% faster for my tests. Obviously, the larger your buffers are, the more savings you get. But it's not really about the speed. It just seems more consistent with what the TXC bit was meant for. |
Nice idea, I agree - and thanks for the detailed background info! |
a805093
to
661b166
Compare
rebased and squashed |
Be great to see this bug fix get merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual fix looks good. I am however not so fond of the bit notation for flag checks and please re-fix the error bit clear...
cpu/sam0_common/periph/uart.c
Outdated
/* clear error flag */ | ||
dev(uartnum)->INTFLAG.reg = SERCOM_USART_INTFLAG_ERROR; | ||
dev(uartnum)->INTFLAG.reg |= SERCOM_USART_INTFLAG_ERROR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this change, not need for read/modify/write here, a simple write is sufficient: Writing a one to this bit will clear the flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you are right, I mis-interpreted the usage of it here and thought might be safer to read/write here - just as we do in other places.
cpu/sam0_common/periph/uart.c
Outdated
@@ -69,18 +69,18 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) | |||
|
|||
/* reset the UART device */ | |||
dev(uart)->CTRLA.reg = SERCOM_USART_CTRLA_SWRST; | |||
while (dev(uart)->SYNCBUSY.reg & SERCOM_USART_SYNCBUSY_SWRST) {} | |||
while (dev(uart)->SYNCBUSY.bit.SWRST) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I like the original check much better, but this might be subjective. At some point we decided to go the the .reg & ..
notation consistently for all the sam0 periph drivers...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the updated CMSIS headers from the newer ASF the bit fields are read-only, and reg
is RW. So I would guess the compiler could optimise things a bit (more) when using read-only registers for read operations on the bit-field instead of using an RW register when using reg
.
Do I make sense here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus, I would therefore recommend to adapt all periph drivers accordingly to have it consistent again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yepp, code size does not change with this, re-checked it. So yes, with them being read only why not change it. Maybe this would be cleaner done in a separate PR, but just leave it here if you want.
661b166
to
0d6abe2
Compare
Yes, please keep the PR fix-only... |
0d6abe2
to
fc3fa03
Compare
factored out into #7709 |
Parens missing... Please fix and squash. ACK. |
fc3fa03
to
732e60b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK.
should fix #7617, and also adapts some register checks to use read-only bits where possible.
Tested with
samr21-xpro
. @travisgriggs please try this one and verify if that resolves your issue reported in #7617.