Skip to content

Commit 8ff05e0

Browse files
bugobliteratorandyp1per
authored andcommitted
USARTv3: support IRQ callbacks
1 parent d384d32 commit 8ff05e0

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

os/hal/ports/STM32/LLD/USARTv3/hal_uart_lld.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,31 +1209,35 @@ size_t uart_lld_stop_receive(UARTDriver *uartp) {
12091209
* @param[in] uartp pointer to the @p UARTDriver object
12101210
*/
12111211
void uart_lld_serve_interrupt(UARTDriver *uartp) {
1212-
uint32_t isr;
1213-
USART_TypeDef *u = uartp->usart;
1214-
uint32_t cr1 = u->CR1;
1215-
1216-
/* Reading and clearing status.*/
1217-
isr = u->ISR;
1218-
u->ICR = isr;
1219-
1220-
if (isr & (USART_ISR_LBDF | USART_ISR_ORE | USART_ISR_NE |
1221-
USART_ISR_FE | USART_ISR_PE)) {
1222-
_uart_rx_error_isr_code(uartp, translate_errors(isr));
1223-
}
1212+
if (uartp->config->irq_cb == NULL) {
1213+
uint32_t isr;
1214+
USART_TypeDef *u = uartp->usart;
1215+
uint32_t cr1 = u->CR1;
1216+
1217+
/* Reading and clearing status.*/
1218+
isr = u->ISR;
1219+
u->ICR = isr;
1220+
1221+
if (isr & (USART_ISR_LBDF | USART_ISR_ORE | USART_ISR_NE |
1222+
USART_ISR_FE | USART_ISR_PE)) {
1223+
_uart_rx_error_isr_code(uartp, translate_errors(isr));
1224+
}
12241225

1225-
if ((isr & USART_ISR_TC) && (cr1 & USART_CR1_TCIE)) {
1226-
/* TC interrupt disabled.*/
1227-
u->CR1 = cr1 & ~USART_CR1_TCIE;
1226+
if ((isr & USART_ISR_TC) && (cr1 & USART_CR1_TCIE)) {
1227+
/* TC interrupt disabled.*/
1228+
u->CR1 = cr1 & ~USART_CR1_TCIE;
12281229

1229-
/* End of transmission, a callback is generated.*/
1230-
_uart_tx2_isr_code(uartp);
1231-
}
1230+
/* End of transmission, a callback is generated.*/
1231+
_uart_tx2_isr_code(uartp);
1232+
}
12321233

1233-
/* Timeout interrupt sources are only checked if enabled in CR1.*/
1234-
if (((cr1 & USART_CR1_IDLEIE) && (isr & USART_ISR_IDLE)) ||
1235-
((cr1 & USART_CR1_RTOIE) && (isr & USART_ISR_RTOF))) {
1236-
_uart_timeout_isr_code(uartp);
1234+
/* Timeout interrupt sources are only checked if enabled in CR1.*/
1235+
if (((cr1 & USART_CR1_IDLEIE) && (isr & USART_ISR_IDLE)) ||
1236+
((cr1 & USART_CR1_RTOIE) && (isr & USART_ISR_RTOF))) {
1237+
_uart_timeout_isr_code(uartp);
1238+
}
1239+
} else {
1240+
uartp->config->irq_cb(uartp);
12371241
}
12381242
}
12391243

os/hal/ports/STM32/LLD/USARTv3/hal_uart_lld.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ typedef struct hal_uart_config {
888888
*/
889889
uartecb_t rxerr_cb;
890890
/* End of the mandatory fields.*/
891+
/**
892+
* @brief UART IRQ Global Handler
893+
*/
894+
uartcb_t irq_cb;
891895
/**
892896
* @brief Receiver timeout callback.
893897
* @details Handles both idle and timeout interrupts depending on configured

0 commit comments

Comments
 (0)