Loss of UART data
Posted: Wed Jan 01, 2014 12:36 am
I've been experiencing intermittent loss of receive data when using the UARTV1 driver on an STM32F103. I normally use ChibiOS V2.6.1 but have also tried the updated driver that's part of V2.6.2 to address bug #442, this version has the same issue.
After investigating, I find that the technique to reset the transmission complete status in the SR register can cause problems. This line of code
becomes this assembly language with my usual optimization level (-O2)
It's possible that the RXNE bit can be set between the initial read of the SR register and it being set again, this results in loss of one character as the RXNE bit is cleared to 0.
My current solution is to use the alternative way of resetting the TC bit in the status register, read status followed by data register write, testing of this technique is ongoing.
Hopefully you can confirm this issue and correct in V2.6.2 when released.
Regards
James.
After investigating, I find that the technique to reset the transmission complete status in the SR register can cause problems. This line of code
Code: Select all
u->SR &= ~USART_SR_TC;becomes this assembly language with my usual optimization level (-O2)
Code: Select all
292 00c4 2B88 ldrh r3, [r5, #0]
293 00c6 23F04003 bic r3, r3, #64
294 00ca 1B04 lsls r3, r3, #16
295 00cc 1B0C lsrs r3, r3, #16
296 00ce 2B80 strh r3, [r5, #0] @ movhiIt's possible that the RXNE bit can be set between the initial read of the SR register and it being set again, this results in loss of one character as the RXNE bit is cleared to 0.
My current solution is to use the alternative way of resetting the TC bit in the status register, read status followed by data register write, testing of this technique is ongoing.
Code: Select all
/* Physical transmission end.*/
if (sr & USART_SR_TC) {
chSysLockFromIsr();
chnAddFlagsI(sdp, CHN_TRANSMISSION_END);
sr = u->SR;
u->DR = 0;
chSysUnlockFromIsr();
u->CR1 = cr1 & ~USART_CR1_TCIE;
//u->SR &= ~USART_SR_TC;
}
Hopefully you can confirm this issue and correct in V2.6.2 when released.
Regards
James.