Skip to content

Fix serial IRQ handling #10774

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

Merged
merged 17 commits into from
Jun 25, 2019
Merged

Fix serial IRQ handling #10774

merged 17 commits into from
Jun 25, 2019

Conversation

fkjagodzinski
Copy link
Member

@fkjagodzinski fkjagodzinski commented Jun 6, 2019

Description

Check that the RX or TX interrupt is enabled before calling a registered handler with RxIrq or TxIrq arg.

Fixes #10773

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

Release Notes

@fkjagodzinski fkjagodzinski force-pushed the fix-uart_irq branch 2 times, most recently from c2e8417 to 189b4d6 Compare June 6, 2019 10:43
@jeromecoutant
Copy link
Collaborator

@ARMmbed/team-st-mcd

@ciarmcom ciarmcom requested review from maclobdell, MarceloSalazar and a team June 6, 2019 11:00
@ciarmcom
Copy link
Member

ciarmcom commented Jun 6, 2019

@fkjagodzinski, thank you for your changes.
@MarceloSalazar @maclobdell @ARMmbed/mbed-os-maintainers please review.

Copy link
Contributor

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks.
should be applied to all STM32 targets in a similar way (the same MACROs should be available)

Filip Jagodzinski added 17 commits June 7, 2019 15:17
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
Check that the RX or TX interrupt is enabled before calling
a registered handler with RxIrq or TxIrq arg.
@jeromecoutant
Copy link
Collaborator

@fkjagodzinski
I could see you applied patch to STM32 F0/F3/F7/L0/L4/H7/WB
This is good,
But I am afraid F1/F2/F4/L1 are missing... :-(
Thx

@fkjagodzinski
Copy link
Member Author

@jeromecoutant I think I've covered all the affected ST targets.

I provided patches for ST targets that have an if statement like this one

if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {

Checking __HAL_UART_GET_IT(huart, UART_IT_TXE) is not enough; additional __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) helps here.

F1, F2, F4 and L1 all already use __HAL_UART_GET_IT_SOURCE(), which is the only check-uart-irq macro they currently provide.

if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {

Of course I might have missed something. I've just checked NUCLEO_F207ZG, NUCLEO_F429ZI with the test code from #10773 and couldn't reproduce this issue.

@fkjagodzinski fkjagodzinski marked this pull request as ready for review June 17, 2019 14:13
@adbridge
Copy link
Contributor

@jeromecoutant could you re-review please ?

Copy link
Contributor

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

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

Just one question left to be answered

@@ -62,12 +62,12 @@ static void uart_irq(UARTName uart_name)
UART_HandleTypeDef *huart = &uart_handlers[id];
if (serial_irq_ids[id] != 0) {
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET && __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok so in case Interrupt has been disabled but FLAG is on anyway, handler will not be called, then shouldn't we clear the flag ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Giving it a second thought ... that should not be required. The flag could be left in current state I guess until inerrupt is activated again

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point; I haven't thought about that. In a normal flow, these flags are cleared by the handler (provided it actually calls serial_putc() / serial_getc()):

  • TXE is cleared by a write to the USART_TDR register,
  • RXNE is cleared by a read to the USART_RDR register.

When the handler is not called, the flags will remain asserted. I can't think of any side effects of that right now. Both flags may be cleared with the use of USART_RQR though.

@LMESTM
Copy link
Contributor

LMESTM commented Jun 19, 2019

F1, F2, F4 and L1 all already use __HAL_UART_GET_IT_SOURCE(), which is the only check-uart-irq macro they currently provide.

Right indeed. On F1, F2, F4, L1 __HAL_UART_GET_IT() is actually the same as __HAL_UART_GET_IT_SOURCE() from other families. From discussions we've had in #10853 , on those families _HAL_UART_GET_IT() does the same as __HAL_UART_GET_FLAG ...

So I'm fine with this PR.
We will need a further clean-up to fully cover the bug reported in #10853

@adbridge
Copy link
Contributor

@LMESTM could you approve on the review if you're happy now thanks.

@adbridge
Copy link
Contributor

@kjbracey-arm could you possibly review on behalf of maintainers ?

Copy link
Contributor

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

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

for STM targets - approved

@0xc0170 0xc0170 requested a review from a team June 24, 2019 12:21
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 24, 2019

I can't find this in Travis logs, it has not even started. I'll reopen this PR

@0xc0170 0xc0170 closed this Jun 24, 2019
@0xc0170 0xc0170 reopened this Jun 24, 2019
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 24, 2019

Travis pending, should help

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 24, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Jun 25, 2019

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@fkjagodzinski
Copy link
Member Author

All greentea tests run for NUCLEO_F746ZG-GCC_ARM ended with IOERR_SERIAL.

[1561420280.33][GLRM][INF] remote resources reset...
[1561420297.58][GLRM][ERR] Write response(request_id: f862a6b0-96da-11e9-a49f-0242ac110002) timeout!

@0xc0170, is there a daplink/st-link issue on this board?

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 25, 2019

Yes, also noticed in another test but latest one was all good, restarted

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 25, 2019

This is ready to go in 👍

@0xc0170 0xc0170 merged commit b0073bb into ARMmbed:master Jun 25, 2019
@fkjagodzinski fkjagodzinski deleted the fix-uart_irq branch June 25, 2019 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serial IRQ handler called for disabled IRQs
7 participants