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

USARTv3: support IRQ callbacks #94

Merged
Merged
Show file tree
Hide file tree
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
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