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

Conversation

nicovince
Copy link

When calling irq_rx_ready or irq_tx_ready API, return the logical AND between the irq status and the enable of that irq.

The reason behind this PR is to be consistent with nRF and MCUX chips and return true on the irq_[tr]x_ready if the corresponding irq is set and enabled.

This allows #26516 improvements to work on stm32.

This has been tested on nucleo_h743 and nucleo_f429 on the sample/subsys/modbus/ samples.

When calling irq_rx_ready or irq_tx_ready API, return the logical AND
between the irq status and the enable of that irq.

Signed-off-by: Nicolas VINCENT <[email protected]>
@@ -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.

@erwango erwango added area: API Changes to public APIs area: UART Universal Asynchronous Receiver-Transmitter labels Jan 8, 2021
@erwango
Copy link
Member

erwango commented Jan 8, 2021

Adding the API label as there are several examples in the code that rely on this behavior which isn't explicit in the API and not implemented in several drivers.

@erwango erwango requested a review from jfischer-no January 8, 2021 17:05
@erwango erwango requested review from carlescufi and dcpleung January 8, 2021 17:06
@erwango
Copy link
Member

erwango commented Jan 8, 2021

@dcpleung According to various uart api users that could be found in tree, the proposal implement an expected behavior. But this is not explicit in the API and not uniformly implemented.

@carlescufi
Copy link
Member

@nordic-krch could you please comment on this PR?

@nashif nashif merged commit eb534d3 into zephyrproject-rtos:master Jan 11, 2021
@erwango
Copy link
Member

erwango commented Jan 12, 2021

ok, that was merged a bit fast...
Anyway, I think there was an agreement on the fix.
But it doesn't prevent the API related discussion to happen.

erwango added a commit to erwango/zephyr that referenced this pull request Jan 15, 2021
In zephyrproject-rtos#31192 stm32 uart driver uart_irq_rx/tx_ready functions were
modified to take into account status of irq.
While it seems wlecome for TX (based on uart client's implementation),
this is not correct for RX.
Revert change in uart_stm32_irq_rx_ready function.

Signed-off-by: Erwan Gouriou <[email protected]>
nashif pushed a commit that referenced this pull request Jan 15, 2021
In #31192 stm32 uart driver uart_irq_rx/tx_ready functions were
modified to take into account status of irq.
While it seems wlecome for TX (based on uart client's implementation),
this is not correct for RX.
Revert change in uart_stm32_irq_rx_ready function.

Signed-off-by: Erwan Gouriou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: UART Universal Asynchronous Receiver-Transmitter platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants