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

stm32:Discard data with Parity Errors #182

Draft
wants to merge 1 commit into
base: px4_firmware_nuttx-10.1.0+
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions arch/arm/src/stm32/stm32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@ static void up_shutdown(struct uart_dev_s *dev)
static void up_dma_shutdown(struct uart_dev_s *dev)
{
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
uint32_t regval;

/* Perform the normal UART shutdown */

Expand All @@ -2005,6 +2006,12 @@ static void up_dma_shutdown(struct uart_dev_s *dev)

stm32_dmafree(priv->rxdma);
priv->rxdma = NULL;

/* Disable Rx DMA */

regval = up_serialin(priv, STM32_USART_CR3_OFFSET);
regval &= ~USART_CR3_DMAR;
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
}
#endif

Expand All @@ -2019,6 +2026,12 @@ static void up_dma_shutdown(struct uart_dev_s *dev)

stm32_dmafree(priv->txdma);
priv->txdma = NULL;

/* Disable Tx DMA */

regval = up_serialin(priv, STM32_USART_CR3_OFFSET);
regval &= ~USART_CR3_DMAT;
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
}
#endif
}
Expand Down Expand Up @@ -2172,7 +2185,8 @@ static int up_interrupt(int irq, void *context, void *arg)
* error conditions.
*/

else if ((priv->sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE)) != 0)
else if ((priv->sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE |
USART_SR_PE)) != 0)
{
#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \
defined(CONFIG_STM32_STM32F37XX) || defined(CONFIG_STM32_STM32G4XXX)
Expand All @@ -2181,7 +2195,8 @@ static int up_interrupt(int irq, void *context, void *arg)
*/

up_serialout(priv, STM32_USART_ICR_OFFSET,
(USART_ICR_NCF | USART_ICR_ORECF | USART_ICR_FECF));
(USART_ICR_NCF | USART_ICR_ORECF | USART_ICR_FECF |
USART_ICR_PECF));
#else
/* If an error occurs, read from DR to clear the error (data has
* been lost). If ORE is set along with RXNE then it tells you
Expand All @@ -2192,6 +2207,15 @@ static int up_interrupt(int irq, void *context, void *arg)
*/

up_serialin(priv, STM32_USART_RDR_OFFSET);

# if defined(SERIAL_HAVE_RXDMA)
/* Discard the data with parity errors */

if (priv->sr & USART_SR_PE)
{
priv->rxdmanext = up_dma_nextrx(priv);
}
# endif
#endif
}

Expand Down Expand Up @@ -2719,6 +2743,8 @@ static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status)
static void up_dma_rxint(struct uart_dev_s *dev, bool enable)
{
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
irqstate_t flags;
uint16_t ie;

/* En/disable DMA reception.
*
Expand All @@ -2728,7 +2754,29 @@ static void up_dma_rxint(struct uart_dev_s *dev, bool enable)
* DMA event.
*/

flags = enter_critical_section();
priv->rxenable = enable;
ie = priv->ie;

if (enable)
{
/* Receive an interrupt when their is anything in the Rx data register
* (or an Rx timeout occurs).
*/

#ifndef CONFIG_SUPPRESS_SERIAL_INTS
ie |= (USART_CR1_PEIE | USART_CR3_EIE);
#endif
}
else
{
ie &= ~(USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR3_EIE);
}

/* Then set the new interrupt state */

up_restoreusartint(priv, ie);
leave_critical_section(flags);
}
#endif

Expand Down