-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
uart_stm32: Fix conflit between poll_out and irq API #40173
Conversation
Thanks @jdascenzio for working on this. |
@@ -58,6 +58,7 @@ struct uart_stm32_data { | |||
uint32_t baud_rate; | |||
/* clock device */ | |||
const struct device *clock; | |||
atomic_t tx_lock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use Zephyr spinlock instead of re-implementing it in this driver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is spinlock available before kernel init ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to lock interrupt so spinlock isn't adapted. I used a simple lock because poll_out could be call in interrupt function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is spinlock available before kernel init ?
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to lock interrupt so spinlock isn't adapted. I used a simple lock because poll_out could be call in interrupt function.
Well, you are checking the nucleo_l432kc which is based on STM32L432xxxx chip which is based on ARM Cortex-M4 which doesn't have atomic instructions (please correct me if I wrong). So, in this case we end up with atomics-in-C implementation which simply uses spinlock internally. And for single core Zephyr spinlock is just interrupt lock :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to lock interrupt so spinlock isn't adapted. I used a simple lock because poll_out could be call in interrupt function.
Well, you are checking the nucleo_l432kc which is based on STM32L432xxxx chip which is based on ARM Cortex-M4 which doesn't have atomic instructions (please correct me if I wrong). So, in this case we end up with atomics-in-C implementation which simply uses spinlock internally. And for single core Zephyr spinlock is just interrupt lock :)
Yes, you're right but I don't understand what you want to do when you say "use Zephyr spinlock instead of re-implementing it in this drive". The function z_impl_atomic_cas protect correctly my lock variable against the uart interrupt thanks spinlock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evgeniy-paltsev Do you have more comments ?
@jdascenzio @erwango thanks for this patch! It seems to work well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. use atomic_set()
to set data->tx_lock
for consistence as data->tx_lock
is an atomic variable.
A lock was added to manage situation where the API poll_out and irq API are used in same time. Signed-off-by: Julien D'ascenzio <[email protected]>
7750486
to
755e5c8
Compare
I applied your remarks to the patch |
Despite the fix #39752 I sent, I continue to have some troubles with the stm32 usart when I'm using console and shell in same time.
I made this branch to illustrate this behavior: https://github.com/jdascenzio/zephyr/commits/shell_bug
The bug can be triggered in shell_module sample
When a "help" command is sent, the answer is received character by character with the printk text:
To fix this, I added a lock between poll_out and irq API