mimxrt: clean up unused systick code, and fix mp_hal_delay_ms(0)#19115
mimxrt: clean up unused systick code, and fix mp_hal_delay_ms(0)#19115dpgeorge wants to merge 4 commits intomicropython:masterfrom
mp_hal_delay_ms(0)#19115Conversation
|
Code size report: |
|
Cleaning out unused stuff is always good. I'm a little bit skeptic about disable IRQ stopping the ms tick. IRQ is disabled often during flash write/erase, e.g. when files are written. I cannot estimate how serious the problem is for using ticks_ms(). It seems better to keep the timer based ticks and provide a separate function. Edit: No all GPT devices are used. So maybe one could set up a GPT counting at 1kHz or a power of 2. Using the low frequency reference clock, 1kHz is possible. When the 24MHz crystal is used, a 8kHz timer can be set up, The GPT prescaler has a range of 1-4096. |
|
For our use cases, it's expected that the value wouldn't increment when there are no IRQs. STM32 systick behavior sets the standard, which does not increment when interrupts are disabled. |
|
Still |
Yes, I agree, I think it would be best to leave the existing implementation of Then we could provide |
|
I've updated this PR to go back to using GPT for |
These legacy functions were copied verbatim from the stm32 port and never used. And the use of WFI in `systick_wait_at_least()` is probably wrong. And correct the comment in SysTick_Handler, which was also copied from stm32. Signed-off-by: Damien George <damien@micropython.org>
The config option `MICROPY_SOFT_TIMER_TICKS_MS` is used instead. Signed-off-by: Damien George <damien@micropython.org>
`systick.h` and `pendsv.h` both use MICROPY-level configuration macros, so must include `py/mpconfig.h`. 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. Signed-off-by: Damien George <damien@micropython.org>
b3d053e to
ab6c2a5
Compare
mp_hal_ticks_ms(), and fix mp_hal_delay_ms(0)mp_hal_delay_ms(0)
|
Based on discussion I've now removed the new |
|
Looks fine. Tested with three representative candidates: MIMXRT1010 (Makerdiary), MIMXRT1015 (MIMXRT1015-EVK), MIMXRT1062 (Teensy 4.1) and MIXRT1176 (MIMXRT1070-EVK) and the test suite packages micropython and extmod. MIMXRFT1010 fails some test running out of heap space. On a side note: Looking why the MIMX1010 failed a socket test I wondered, why it was not skipped. Reason: socket and network modules are enabled on MIMXRT1010 and MIMXRT1015, even if they have no network support. I cannot recall if that was for a reason or just an oversight. Disabling it saves ~3k flash. I can make a separate PR for that, or revive the habit of maintenance PRs collecting small uncritical changes. Edit: Another aspect of test: I noticed that with MIMXRT all vfs_lfs tests are skipped, just because the MIMXRT port does not support VFS_LFS1. Maybe the tests could be adapted to support either one. |

Summary
This PR cleans up and improves mimxrt's systick component:
use the SysTick 1ms counter to implementmp_hal_ticks_ms(); this counter already exists and is much more efficient thanticks_ms32()which needs to convert a 64-bit microsecond counter to millisecondsmp_hal_delay_ms(0)so it runs the schedulerPoint 2 addresses #19076, providing a fastmp_hal_ticks_ms().Edit: as discussed further in #19076, there's no need to change how ticks-ms works, so that's been reverted.
Testing
Tested on TEENSY40, running the test suite in standard mode, and with
--via-mpy --emit native. With the native emittertests/micropython/schedule_sleep.pywould lock up prior to the fix in this PR. Now it passes, as do all other tests (exceptsocket_badconstructor.pywhich is fixed by a different PR).Trade-offs and Alternatives
Note thatsystick_mswill stop counting if IRQs are disabled. That's also partly true of the existing ticks based on a GPT, due to the handling of the overflow in an IRQ, although there the overflow happens every 71 minutes, rather than every millisecond.This also makesticks_ms32()unused, so it could be removed. But probably best to keep it in case it's needed again.Alternatively, could provide a config option to select the
mp_hal_ticks_ms()implementation: systick vs microsecond GPT. Another alternative would be to provide amp_hal_ticks_ms_fast()which uses systick, and keepmp_hal_ticks_ms()using the GPT.Generative AI
I did not use generative AI tools when creating this PR.