Skip to content

nrf/modules/machine: Catch exceptions from pin interrupts #13368

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

Closed
wants to merge 2 commits into from

Conversation

cwalther
Copy link
Contributor

@cwalther cwalther commented Jan 5, 2024

Exceptions in pin interrupt handlers (including the "TypeError: function takes 0 positional arguments but 1 were given" that happens when a function taking the wrong number of arguments was set as an interrupt handler) would end up crashing MicroPython with a "FATAL: uncaught exception". This is particularly annoying on a device such as the DS-D6 where the reset pin is not easily accessible.

In addition, on the nRF52832 (apparently not on the nRF52840, I haven’t checked why), MicroPython would get stuck trying to output this error message, or generally any print output from inside a pin interrupt handler, through the UART after the first character, so that only "F" was visible. The reason was a matching interrupt priority between the running pin interrupt and the UARTE interrupt signaling completion of the output operation. Fix that by increasing the UARTE interrupt priority.

Code taken from the stm32 port and adapted.

(This is just something I happened on and fixed on the side. It’s less important to me than the other nrf PRs. I am also wondering whether the whole thing should be rewritten using shared/runtime/mpirq.c, but am not putting in that effort now.)

Copy link

github-actions bot commented Jan 5, 2024

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

Copy link

codecov bot commented Jan 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.39%. Comparing base (d712feb) to head (56b23d9).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13368   +/-   ##
=======================================
  Coverage   98.39%   98.39%           
=======================================
  Files         161      161           
  Lines       21078    21078           
=======================================
  Hits        20739    20739           
  Misses        339      339           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cwalther
Copy link
Contributor Author

Side note: The reason I didn’t see the problem of getting stuck after printing the first character on the nRF52840, as @tb4450 points out in #13520, is that the 840 uses USB CDC for stdout, which is a different code path. I have now confirmed that the problem does occur on the nRF52840 when writing to a hardware UART, and is also fixed by this commit.

It destroys a few manual alignments, but these seem minor compared to
the benefit of automated code style consistency.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
Exceptions in pin interrupt handlers would end up crashing MicroPython
with a "FATAL: uncaught exception".

In addition, MicroPython would get stuck trying to output this error
message, or generally any print output from inside a pin interrupt
handler, through the UART after the first character, so that only "F"
was visible. The reason was a matching interrupt priority between the
running pin interrupt and the UARTE interrupt signaling completion of
the output operation. Fix that by increasing the UARTE interrupt
priority.

Code taken from the stm32 port and adapted.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
@cwalther
Copy link
Contributor Author

Rebased on master to deal with the STATIC removal, no other changes required.

@dpgeorge
Copy link
Member

This is a good improvement, thanks.

Note that pin interrupts on the nrf are always hard interrupts. Ideally they'd be soft interrupts by default, but...

I am also wondering whether the whole thing should be rewritten using shared/runtime/mpirq.c

Yes, it should be, eventually. That can be done another time. For now this PR is good.

@dpgeorge
Copy link
Member

Rebased and merged in 5e926b2

@dpgeorge dpgeorge closed this Mar 26, 2024
@cwalther cwalther deleted the nrf-pininterrupt branch March 26, 2024 22:31
@cwalther
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy