Currently the mimxrt port has a resolution of only 1 second for `machine.RTC().datetime()` and `time.time_ns()`. This means (among other things) that it fails the `tests/extmod/time_time_ns.py` test, which requires requires at least 5ms of resolution. The underlying RTC hardware is just a 64-bit counter, and the HAL functions `SNVS_LP_SRTC_GetDatetime()` and `SNVS_LP_SRTC_SetDatetime()` do conversions between y/m/d/h/m/s and this 64-bit value, which counts at a rate of 32kHz. This commit changes the RTC code to access the 64-bit counter directly and therefore improve resolution of all RTC functions to 1/32768 seconds. That makes things much simpler because it a lot of places the code wants to know the number of seconds since the Epoch. Currently it uses a combination of `SNVS_LP_SRTC_GetDatetime()` and `timeutils_seconds_since_epoch()` which converts the 64-bit counter to date-time and then back to seconds. Those operations are computationally expensive. With this commit, getting the number of seconds since the Epoch is as simple as reading the 64-bit counter and dividing by 32768. We can leverage a lot of the timeutils functions to simplify everything, and make it similar to other ports like rp2. Benefits of this change: - simpler, more efficient code to get/set RTC - `machine.RTC().datetime()` now has a non-zero value in the last slot, being the number of microseconds, and has a resolution of 1/32768 seconds - `time.time_ns()` now has a resolution of 1/32768 seconds - the `test/extmod/time_time_ns.py` test now passes Signed-off-by: Damien George <damien@micropython.org>
Port of MicroPython to NXP iMX RT 10xx
Currently supports Teensy 4.0, Teensy 4.1, and the MIMXRT1010_EVK, MIMXRT1020_EVK, MIMXRT1050_EVK, MIMXRT1060_EVK and MIMXRT1064_EVK boards.
Features:
- REPL over USB VCP
- machine.ADC
- machine.I2C
- machine.LED
- machine.Pin
- machine.PWM
- machine.RTC
- machine.SDCard
- machine.SPI
- machine.Signal
- machine.SoftI2C
- machine.SoftSPI
- machine.Timer
- machine.UART
- LFS2 file system at the internal Flash
- SDCard support (not on MIMXRT1010_EVK)
- Ethernet (not on Teensy 4.0 and MIMXRT1010_EVK)
Known issues:
TODO:
- More peripherals (Counter, I2S, CAN, etc)
- More Python options
Build Instructions
Before building the firmware for a given board the MicroPython cross-compiler must be built; it will be used to pre-compile some of the built-in scripts to bytecode. The cross-compiler is built and run on the host machine, using:
$ make -C mpy-cross
This command should be executed from the root directory of this repository. All other commands below should be executed from the ports/mimxrt/ directory.
An ARM compiler is required for the build, along with the associated binary
utilities. The default compiler is arm-none-eabi-gcc, which is available for
Arch Linux via the package arm-none-eabi-gcc, for Ubuntu via instructions
here, or
see here for the main GCC ARM
Embedded page. The compiler can be changed using the CROSS_COMPILE variable
when invoking make.
In addition newlib is required which is available for Arch Linux via the
package arm-none-eabi-newlib, for Ubuntu/Debian install package libnewlib-arm-none-eabi
Next, the board to build must be selected. Any of the board names of the
subdirectories in the boards/ directory is a valid board. The board name
must be passed as the argument to BOARD= when invoking make.
All boards require certain submodules to be obtained before they can be built.
The correct set of submodules can be initialised using (with SEEED_ARCH_MIX
as an example of the selected board):
$ make BOARD=SEEED_ARCH_MIX submodules
Then to build the board's firmware run:
$ make BOARD=SEEED_ARCH_MIX
The above command should produce binary images in the build-SEEED_ARCH_MIX/
subdirectory (or the equivalent directory for the board specified).
Flashing
Deploy the firmware following the instructions here https://docs.micropython.org/en/latest/mimxrt/tutorial/intro.html#deploying-the-firmware