Skip to content

nrf, samd: Run events at least once in mp_hal_delay_ms.#19289

Open
dpgeorge wants to merge 2 commits into
micropython:masterfrom
dpgeorge:nrf-samd-run-events-delay-ms
Open

nrf, samd: Run events at least once in mp_hal_delay_ms.#19289
dpgeorge wants to merge 2 commits into
micropython:masterfrom
dpgeorge:nrf-samd-run-events-delay-ms

Conversation

@dpgeorge
Copy link
Copy Markdown
Member

@dpgeorge dpgeorge commented Jun 1, 2026

Summary

Per the docs for time.sleep() and time.sleep_ms(), events must be run at least once in mp_hal_delay_ms().

This gets the tests/micropython/schedule_sleep.py test working when using the native emitter.

Testing

Tested on ARDUINO_NANO_33_BLE_SENSE (nrf) and ADAFRUIT_ITSYBITSY_M0_EXPRESS (samd), using:

$ ./run-tests -t a0 --via-mpy --emit native micropython/schedule_sleep.py

It now passes instead of locking up.

Existing tests still pass OK.

Generative AI

Not used.

Per the docs for `time.sleep()` and `time.sleep_ms()`.  This gets the
`tests/micropython/schedule_sleep.py` test working when using the native
emitter.

Signed-off-by: Damien George <damien@micropython.org>
Per the docs for `time.sleep()` and `time.sleep_ms()`.  This gets the
`tests/micropython/schedule_sleep.py` test working when using the native
emitter.

The structure of `mp_hal_delay_ms()` matches the rp2 port.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the nrf-samd-run-events-delay-ms branch from 3d97bbb to a4a422a Compare June 1, 2026 01:53
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Code size report:

Reference:  rp2/CMakeLists.txt: Require boards to define PICO_FLASH_SIZE_BYTES. [44a569b]
Comparison: samd/mphalport: Run events at least once in mp_hal_delay_ms. [merge of a4a422a]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link
Copy Markdown
Contributor

@robert-hh robert-hh left a comment

Choose a reason for hiding this comment

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

The code looks fine (obviously). Built and tested with SAMD ITSYBITSY M0 and M4, Micro.Bit and Arduino Nano 33 BLE. All but Micro.Bit tested with micropython/schedule_sleep.py. Micro.Bit tested with extmod/time_ms_us.py.

The additional test in the NRF port for ms == 0 is interesting. I'm not sure whether this is obsolete or helpful. At least, that way a minimal wait time until the next event is avoided.

@dpgeorge
Copy link
Copy Markdown
Member Author

dpgeorge commented Jun 1, 2026

Thanks for the quick review!

The additional test in the NRF port for ms == 0 is interesting.

Yes, that bit of code has been there from the beginning and wasn't strictly necessary prior to the change in this PR. But now, the code needs a way to do 0-delay but still check events, and this explicit test is necessary.

To make nrf more like samd (and rp2) it would first need to be converted to the new event system.

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.

2 participants