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

driver: uart stm32: Check irq enabled in API calls #31192

Merged
merged 1 commit into from
Jan 11, 2021
Merged
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
6 changes: 4 additions & 2 deletions drivers/serial/uart_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ static int uart_stm32_irq_tx_ready(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);

return LL_USART_IsActiveFlag_TXE(UartInstance);
return LL_USART_IsActiveFlag_TXE(UartInstance) &&
LL_USART_IsEnabledIT_TC(UartInstance);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why mixing LL_USART_IsActiveFlag_TXE with TC here ?
as the _uart_stm32_irq_tx_complete_ exists and could be:
LL_USART_IsActiveFlag_TC && LL_USART_IsEnabledIT_TC

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FRASTM Agree this is not clear and situation is due to a reported behavior where rq_tx_ready could be called after irq_tx_disable has been called and in that case is "expected" to return 0.
This is not explicit in the API, but apparently this behavior is also used in other (at least some) uart drivers.
To achieve that, since irq_tx_disable is actually disabling TC, this is TC flag that should checked here.

}

static int uart_stm32_irq_tx_complete(const struct device *dev)
Expand Down Expand Up @@ -561,7 +562,8 @@ static int uart_stm32_irq_rx_ready(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);

return LL_USART_IsActiveFlag_RXNE(UartInstance);
return LL_USART_IsActiveFlag_RXNE(UartInstance) &&
LL_USART_IsEnabledIT_RXNE(UartInstance);
}

static void uart_stm32_irq_err_enable(const struct device *dev)
Expand Down