From d2358743d776c32f721dca668ec2e5841b287190 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 14 May 2014 08:21:58 +0000 Subject: [PATCH] Fixed bug #503. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@6935 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/USARTv1/serial_lld.c | 9 +++++---- os/hal/ports/STM32/LLD/USARTv2/serial_lld.c | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/os/hal/ports/STM32/LLD/USARTv1/serial_lld.c b/os/hal/ports/STM32/LLD/USARTv1/serial_lld.c index 87be9bbb6..1991c6ae0 100644 --- a/os/hal/ports/STM32/LLD/USARTv1/serial_lld.c +++ b/os/hal/ports/STM32/LLD/USARTv1/serial_lld.c @@ -159,8 +159,8 @@ static void serve_interrupt(SerialDriver *sdp) { if (sr & USART_SR_LBD) { osalSysLockFromISR(); chnAddFlagsI(sdp, SD_BREAK_DETECTED); - osalSysUnlockFromISR(); u->SR = ~USART_SR_LBD; + osalSysUnlockFromISR(); } /* Data available.*/ @@ -191,10 +191,11 @@ static void serve_interrupt(SerialDriver *sdp) { /* Physical transmission end.*/ if (sr & USART_SR_TC) { osalSysLockFromISR(); - chnAddFlagsI(sdp, CHN_TRANSMISSION_END); - osalSysUnlockFromISR(); - u->CR1 = cr1 & ~(USART_CR1_TXEIE | USART_CR1_TCIE); + if (oqIsEmptyI(&sdp->oqueue)) + chnAddFlagsI(sdp, CHN_TRANSMISSION_END); + u->CR1 = cr1 & ~USART_CR1_TCIE; u->SR = ~USART_SR_TC; + osalSysUnlockFromISR(); } } diff --git a/os/hal/ports/STM32/LLD/USARTv2/serial_lld.c b/os/hal/ports/STM32/LLD/USARTv2/serial_lld.c index 38042003e..3ecf1fcbf 100644 --- a/os/hal/ports/STM32/LLD/USARTv2/serial_lld.c +++ b/os/hal/ports/STM32/LLD/USARTv2/serial_lld.c @@ -155,18 +155,21 @@ static void serve_interrupt(SerialDriver *sdp) { /* Error condition detection.*/ if (isr & (USART_ISR_ORE | USART_ISR_NE | USART_ISR_FE | USART_ISR_PE)) set_error(sdp, isr); + /* Special case, LIN break detection.*/ if (isr & USART_ISR_LBD) { osalSysLockFromISR(); chnAddFlagsI(sdp, SD_BREAK_DETECTED); osalSysUnlockFromISR(); } + /* Data available.*/ if (isr & USART_ISR_RXNE) { osalSysLockFromISR(); sdIncomingDataI(sdp, (uint8_t)u->RDR); osalSysUnlockFromISR(); } + /* Transmission buffer empty.*/ if ((cr1 & USART_CR1_TXEIE) && (isr & USART_ISR_TXE)) { msg_t b; @@ -180,12 +183,14 @@ static void serve_interrupt(SerialDriver *sdp) { u->TDR = b; osalSysUnlockFromISR(); } + /* Physical transmission end.*/ if (isr & USART_ISR_TC) { osalSysLockFromISR(); - chnAddFlagsI(sdp, CHN_TRANSMISSION_END); - osalSysUnlockFromISR(); + if (oqIsEmptyI(&sdp->oqueue)) + chnAddFlagsI(sdp, CHN_TRANSMISSION_END); u->CR1 = cr1 & ~USART_CR1_TCIE; + osalSysUnlockFromISR(); } }