stm32: add machine.Timer implemented as a 1ms resolution soft timer #5254
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a very simple but useful implementation of
machine.Timer
to the stm32 port, providing a "software timer" with a 1ms resolution, allowing unlimited number of concurrent timers. They can be one-shot or periodic, have a Python callback, and can be cancelled.It uses SysTick to implement the soft timer, so doesn't impact an existing hardware timer. There is a very small overhead added to the SysTick IRQ, which could be further optimised (eg by patching systick_irq code dynamically).
The Python-level API is intended to match esp8266 and esp32, like this:
Ultimately the Timer API will be refined further, see discussion at #2971, but for now this at least provides a starting point and something useful and portable.