Skip to content

Commit

Permalink
Added idle interupt to callback to UART driver (#482)
Browse files Browse the repository at this point in the history
Added uart interrupt callback to the serial driver which is required for Spektrum SRXL2 protocol
  • Loading branch information
madchiller authored and nerdCopter committed Mar 19, 2021
1 parent eeb396b commit 0e89169
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/drivers/serial_uart_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ void uartReconfigure(uartPort_t *uartPort) {
SET_BIT(uartPort->USARTx->CR3, USART_CR3_EIE);
/* Enable the UART Data Register not empty Interrupt */
SET_BIT(uartPort->USARTx->CR1, USART_CR1_RXNEIE);
/* Enable Idle Line detection */
SET_BIT(uartPort->USARTx->CR1, USART_CR1_IDLEIE);
}
}
// Transmit DMA or IRQ
Expand Down
1 change: 1 addition & 0 deletions src/main/drivers/serial_uart_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ serialPort_t *uartOpen(UARTDevice_e device, serialReceiveCallbackPtr rxCallback,
} else {
USART_ClearITPendingBit(s->USARTx, USART_IT_RXNE);
USART_ITConfig(s->USARTx, USART_IT_RXNE, ENABLE);
USART_ITConfig(s->USARTx, USART_IT_IDLE, ENABLE);
}
}
// Transmit DMA or IRQ
Expand Down
8 changes: 8 additions & 0 deletions src/main/drivers/serial_uart_stm32f10x.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,13 @@ void uartIrqHandler(uartPort_t *s) {
USART_ITConfig(s->USARTx, USART_IT_TXE, DISABLE);
}
}
if (SR & USART_FLAG_IDLE) {
if (s->port.idleCallback) {
s->port.idleCallback();
}

const uint32_t read_to_clear = s->USARTx->DR;
(void) read_to_clear;
}
}
#endif // USE_UART
13 changes: 11 additions & 2 deletions src/main/drivers/serial_uart_stm32f30x.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,17 @@ void uartIrqHandler(uartPort_t *s) {
USART_ITConfig(s->USARTx, USART_IT_TXE, DISABLE);
}
}
if (ISR & USART_FLAG_ORE) {
USART_ClearITPendingBit (s->USARTx, USART_IT_ORE);
if (ISR & USART_FLAG_ORE)
{
USART_ClearITPendingBit(s->USARTx, USART_IT_ORE);
}

if (ISR & USART_FLAG_IDLE) {
if (s->port.idleCallback) {
s->port.idleCallback();
}

USART_ClearITPendingBit(s->USARTx, USART_IT_IDLE);
}
}
#endif // USE_UART
13 changes: 12 additions & 1 deletion src/main/drivers/serial_uart_stm32f4xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,19 @@ void uartIrqHandler(uartPort_t *s) {
USART_ITConfig(s->USARTx, USART_IT_TXE, DISABLE);
}
}

if (USART_GetITStatus(s->USARTx, USART_IT_ORE) == SET) {
USART_ClearITPendingBit (s->USARTx, USART_IT_ORE);
USART_ClearITPendingBit(s->USARTx, USART_IT_ORE);
}

if (USART_GetITStatus(s->USARTx, USART_IT_IDLE) == SET) {
if (s->port.idleCallback) {
s->port.idleCallback();
}

// clear
(void) s->USARTx->SR;
(void) s->USARTx->DR;
}
}
#endif
8 changes: 8 additions & 0 deletions src/main/drivers/serial_uart_stm32f7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ void uartIrqHandler(uartPort_t *s) {
handleUsartTxDma(s);
}
}

if (__HAL_UART_GET_IT(huart, UART_IT_IDLE)) {
if (s->port.idleCallback) {
s->port.idleCallback();
}

__HAL_UART_CLEAR_IDLEFLAG(huart);
}
}

static void handleUsartTxDma(uartPort_t *s) {
Expand Down

0 comments on commit 0e89169

Please sign in to comment.