Skip to content

Commit

Permalink
USARTv3: support IRQ callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator committed Jan 28, 2025
1 parent 88b8460 commit c6d0293
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
48 changes: 26 additions & 22 deletions os/hal/ports/STM32/LLD/USARTv3/hal_uart_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,31 +1209,35 @@ size_t uart_lld_stop_receive(UARTDriver *uartp) {
* @param[in] uartp pointer to the @p UARTDriver object
*/
void uart_lld_serve_interrupt(UARTDriver *uartp) {
uint32_t isr;
USART_TypeDef *u = uartp->usart;
uint32_t cr1 = u->CR1;

/* Reading and clearing status.*/
isr = u->ISR;
u->ICR = isr;

if (isr & (USART_ISR_LBDF | USART_ISR_ORE | USART_ISR_NE |
USART_ISR_FE | USART_ISR_PE)) {
_uart_rx_error_isr_code(uartp, translate_errors(isr));
}
if (uartp->config->irq_cb == NULL) {
uint32_t isr;
USART_TypeDef *u = uartp->usart;
uint32_t cr1 = u->CR1;

/* Reading and clearing status.*/
isr = u->ISR;
u->ICR = isr;

if (isr & (USART_ISR_LBDF | USART_ISR_ORE | USART_ISR_NE |
USART_ISR_FE | USART_ISR_PE)) {
_uart_rx_error_isr_code(uartp, translate_errors(isr));
}

if ((isr & USART_ISR_TC) && (cr1 & USART_CR1_TCIE)) {
/* TC interrupt disabled.*/
u->CR1 = cr1 & ~USART_CR1_TCIE;
if ((isr & USART_ISR_TC) && (cr1 & USART_CR1_TCIE)) {
/* TC interrupt disabled.*/
u->CR1 = cr1 & ~USART_CR1_TCIE;

/* End of transmission, a callback is generated.*/
_uart_tx2_isr_code(uartp);
}
/* End of transmission, a callback is generated.*/
_uart_tx2_isr_code(uartp);
}

/* Timeout interrupt sources are only checked if enabled in CR1.*/
if (((cr1 & USART_CR1_IDLEIE) && (isr & USART_ISR_IDLE)) ||
((cr1 & USART_CR1_RTOIE) && (isr & USART_ISR_RTOF))) {
_uart_timeout_isr_code(uartp);
/* Timeout interrupt sources are only checked if enabled in CR1.*/
if (((cr1 & USART_CR1_IDLEIE) && (isr & USART_ISR_IDLE)) ||
((cr1 & USART_CR1_RTOIE) && (isr & USART_ISR_RTOF))) {
_uart_timeout_isr_code(uartp);
}
} else {
uartp->config->irq_cb(uartp);
}
}

Expand Down
4 changes: 4 additions & 0 deletions os/hal/ports/STM32/LLD/USARTv3/hal_uart_lld.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ typedef struct hal_uart_config {
*/
uartecb_t rxerr_cb;
/* End of the mandatory fields.*/
/**
* @brief UART IRQ Global Handler
*/
uartcb_t irq_cb;
/**
* @brief Receiver timeout callback.
* @details Handles both idle and timeout interrupts depending on configured
Expand Down

0 comments on commit c6d0293

Please sign in to comment.