summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-06-01tests/import/import_pkg9.py: Add test for subpackage attribute.Jim Mussared
When foo.bar is imported, bar is added as an attribute to foo. Previously this happened on every import, but should only happen on first import. This verifies the behavior for relative imports and overriding. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01tests/import/builtin_ext.py: Add test for built-in module override.Jim Mussared
This verifies the behavior: - Exact matches of built-ins bypass filesystem. - u-prefix modules can be overridden from the filesystem. - Builtin import can be forced using either u-prefix or sys.path=[]. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01examples/usercmodule: Add a sub-package example.Jim Mussared
This demonstrates how to add a sub-package in a user c module, as well as how to define the necessary qstrs and enable the feature in the build. This is used by the unix coverage build to test this feature. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01py/objmodule: Don't use sys.modules to track a builtin __init__.Jim Mussared
This can lead to duplicate initialisations if a module can be imported via multiple names, so the module must track this itself anyway. This reduces code size (diff is -40 bytes), and avoids special treatment of builtin-modules-with-init with respect to sys.modules. No other builtin modules get put into sys.modules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01py/builtinimport: Allow builtin modules to be packages.Jim Mussared
To use this: - Create a built-in module, and add the module object as a member of the parent module's globals dict. - The submodule can set its `__name__` to either `QSTR_foo_dot_bar` or `QSTR_bar`. The former requires using qstrdefs(port).h to make the qstr. Because `bar` is a member of `foo`'s globals, it is possible to write `import foo` and then immediately use `foo.bar` without importing it explicitly. This means that if `bar` has an `__init__`, it will not be called in this situation, and for that reason, sub-modules should not have `__init__` methods. If this is required, then all initalisation for sub-modules should be done by the top-level module's (i.e. `foo`'s) `__init__` method. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01py/builtinimport: Optimise sub-package loading.Jim Mussared
This makes it so that sub-packages are resolved relative to their parent's `__path__`, rather than re-resolving each parent's filesystem path. The previous behavior was that `import foo.bar` would first re-search `sys.path` for `foo`, then use the resulting path to find `bar`. For already-loaded and u-prefixed modules, because we no longer need to build the path from level to level, we no longer unnecessarily search the filesystem. This should improve startup time. Explicitly makes the resolving process clear: - Loaded modules are returned immediately without touching the filesystem. - Exact-match of builtins are also returned immediately. - Then the filesystem search happens. - If that fails, then the weak-link handling is applied. This maintains the existing behavior: if a user writes `import time` they will get time.py if it exits, otherwise the built-in utime. Whereas `import utime` will always return the built-in. This also fixes a regression from a7fa18c203a241f670f12ab507aa8b349fcd45a1 where we search the filesystem for built-ins. It is now only possible to override u-prefixed builtins. This will remove a lot of filesystem stats at startup, as micropython-specific modules (e.g. `pyb`) will no longer attempt to look at the filesystem. Added several improvements to the comments and some minor renaming and refactoring to make it clearer how the import mechanism works. Overall code size diff is +56 bytes on STM32. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01py/builtinimport: Handle empty sys.path correctly.Jim Mussared
If sys.path is enabled, but empty, this will now no longer search the filesystem. Previously an empty sys.path was equivalent to having `sys.path=[""]`. This is a breaking change, but this behavior now matches CPython. This also provides an alternative mechanism to the u-prefix to force an import of a builtin module: ``` import sys _path = sys.path[:] sys.path.clear() import foo # Forces the built-in foo. sys.path.extend(_path) del _path ``` Code size diff is -32 bytes on PYBV11. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01py/objint: Allow int() to parse anything with the buffer protocol.Damien George
This generalises and simplifies the code and follows CPython behaviour. See similar change for floats in a07fc5b6403b9a8bf7e7cb64f857272e5346d7e2. Signed-off-by: Damien George <damien@micropython.org>
2023-06-01py/obj: Accept user types in mp_obj_get_int_maybe.Damien George
This is possible now that MP_UNARY_OP_INT_MAYBE exists. As a consequence mp_obj_get_int now also supports user types, which was previously possible with MP_UNARY_OP_INT but no tests existed for it. Signed-off-by: Damien George <damien@micropython.org>
2023-06-01py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE.Damien George
To be consistent with MP_UNARY_OP_INT_FLOAT and MP_UNARY_OP_INT_COMPLEX, and allow int() to first check if a type supports __int__ before trying other things (as per CPython). Signed-off-by: Damien George <damien@micropython.org>
2023-06-01tests/basics: Remove __index__ and __inv__ from special methods tests.Damien George
MicroPython does not support these special methods, and they may get in the way of other tests (eg indexing with __int__). Signed-off-by: Damien George <damien@micropython.org>
2023-06-01renesas-ra/boards/make-pins.py: Fix PA/PB pins support.Takeo Takahashi
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-06-01docs/samd: Add the pin-out for the Adafruit Metro M4 Airlift board.robert-hh
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01docs/mimxrt: Add the pin-out for the Adafruit Metro M7 board.robert-hh
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01mimxrt/Makefile: Use a specific fsl_flexspi_nor_boot.c for mimxrt1062.robert-hh
This one sets the flash image length properly for the teensy loader, such that the file system is not erased. It was already set in commit 8e542251405d780f7aa0d6c9abaa30282dd360d5 but got lost when the MIMXRT1176 board was added. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01mimxrt/machine_pwm: Fix freq change, PWM print, and error checks.robert-hh
Three bugs have been fixed in this commit: 1. When the duty was set with duty_u16(), changing the freq with pwm.freq() would not keep relative duty rate, but the absolute pulse duration. 2. Fix another inconsistency when displaying the PWM pin's properties of a QTMR channel. 3. Improve the error checks for the second channel being a PWM pin and pin pairs to be a FLEXPWM A/B pair. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51.robert-hh
These have by default FAT support. The SAMD21 build does not support FAT. The nrf port also implements os.sync(), but has it's own copy of moduos.c. Code size increases seen: 40 to 56 bytes. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01ports: Remove os.sync() implementation from stm32 and renesas-ra.robert-hh
Now that this code was moved to extmod/moduos.c. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01extmod/moduos: Move os.sync() into extmod/moduos.c.robert-hh
Avoiding code duplication. To enable it, set MICROPY_PY_UOS_SYNC in the port's mpconfigport.h. It is operational only for FAT file system. For other filesystems it's a no-op. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-31shared/libc/printf: Fix stdout destination for putchar and puts.Damien George
These functions should output to the same location as printf in this file. Signed-off-by: Damien George <damien@micropython.org>
2023-05-24tools/pydfu.py: Use getattr to retrieve getargspec function.Damien George
Since Python 3.11, inspect.getargspec() has been removed. Signed-off-by: Damien George <damien@micropython.org>
2023-05-24renesas-ra: Consolidate hal_entry.c code and remove hal_entry() func.Damien George
The hal_entry.c code is duplicated across all boards, so consolidate it to a common ra_hal.c file. And remove the hal_entry() function because it simply calls main(). Signed-off-by: Damien George <damien@micropython.org>
2023-05-24stm32/boards/NUCLEO_L4A6ZG: Add new board definition.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-05-24stm32/adc: Add support for STM32L4A6 MCUs.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-05-24stm32/boards/NUCLEO_G474RE: Make it easier to enable USB.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-24stm32/usb: Fix USB support on STM32G4.Jim Mussared
Also fix MAX_ENDPOINT definition for G0, which follows G4. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-23docs/reference/speed_python: Remove 4-arg limit for viper.Jim Mussared
This limit was removed in a676b5acf6ee9c17926cf9786370d30a077d99c0. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-23mimxrt/boards/ADAFRUIT_METRO_M7: Add Adafruit Metro M7 board definition.robert-hh
Support for WiFi and BLE is in progress. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-23mimxrt/led: Add support for up to four LEDs.iabdalkader
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-23mimxrt/sdcard: Fix GCC 13 build error with sdcard_cmd_set_bus_width.Yilin Sun
This updates the declaration of 'sdcard_cmd_set_bus_width()' to the same as its definition. Signed-off-by: Yilin Sun <imi415@imi.moe>
2023-05-23samd/boards/ADAFRUIT_METRO_M4_EXPRESS: Add Metro M4 Express Airlift.robert-hh
The board files can be used for both Adafruit Metro M4 variants. The Wifi support is in progress.
2023-05-23samd/machine_uart: Add support for UART hardware flow control.robert-hh
By specifying rts=pin(x) and/or cts=Pin(x) in the constructor. The pad numbers for the UART pins are fix in this case: TX must be at pad 0, RX at pad 1, RTS at pad 2 and CTS at pad 3. repr(uart) shows the pin names for rts and cts, if set. In case of a RX overflow, the rx interrupt will be disabled instead of just discarding the data. That allows RTS to act. If RTS is inactive, still 2 bytes can be buffered in the FIFO. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/mcu: Reduce the startup time after hard reset.robert-hh
With Crystal: set the crystal startup wait time to 1 second. It was 2 seconds before, and that seeemed too long. With USB-Sync: scan for up to 1 second for the USB to be registered and carry on with boot as soon as it it. Before, the code just waited for 500ms. Side change: improve related comments. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/boards/SEEED_WIO_TERMINAL: Rename two pins starting with a digit.robert-hh
So the names don't start with a digit, which isn't allowed in Python. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/modmachine: Make some machine classes configurable by #defines.robert-hh
These include ADC, DAC, I2C, SoftI2C, SPI, SoftI2C, PWM, UART, pulse. This is useful for devices like the Adafruit Trinket series which have almost no accessible GPIO pins. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/modmachine: Add machine.deepsleep as alias of machine.lightsleep.robert-hh
Just for coverage. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/main: Fix sercom deinit ordering in soft-reset.robert-hh
If sockets were open when calling soft reset, gc_sweep_all() would try to close them. In case of e.g. the NINA WiFi handler, connected through SPI, spi_transfer() would be called for command exchange with the NINA module. But at that time SerCom was already disabled. Moving sercom_deinit_all() behind gc_sweep_all() solves this issue. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/boards: Add default deploy instructions.robert-hh
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/mcu/samd51: Enable MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF.robert-hh
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd: Rearrange the MCU-specific loader files.robert-hh
Such that they are easier to adapt. The maximum code size is set by: MICROPY_HW_CODESIZE=xxxK in mpconfigmcu.mk for the MCU family as default or in mpconfigboard.mk for a specific board. Setting the maximum code size allows the loader to error out if the code gets larger than the space dedicated for it. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/boards/MINISAM_M4: Update pins.csv for the Mini SAM M4 board.robert-hh
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22samd/mpconfigport: Drop support for SoftSPI max speed.robert-hh
Saves ~140 bytes and is not really needed, since for higher baud rates hard SPI is available. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22tools/mpremote: Add repl option to escape non-printable characters.Damien George
This commit adds the "--escape-non-printable" option to the repl command. When specified the REPL console will escape non-printable characters, printing them as their hex value in square brackets. This escaping behaviour was previously the default and only behaviour, but it is now opt-in. As part of this change, the speed of echoing device data to the console is improved by by reading and writing in chunks. Signed-off-by: Damien George <damien@micropython.org>
2023-05-22esp32/uart: Use xtal as UART clock source on S3 and C3.patrick
Change UART clock source on S3/C3 so the UART can operate when CPU frequency is below 80MHz. This allows the UART to remain operational when using Dynamic Frequency Scaling (DFS). Signed-off-by: Patrick Joy <patrick@joytech.com.au>
2023-05-19esp32/esp32_ulp: Enable FSM ULP for S2 and S3 chips.patrick
This commit enables the ULP for the S2 and S3 chips. Note this is the FSM (Finite State Machine) ULP. Signed-off-by: Patrick Joy <patrick@joytech.com.au>
2023-05-19esp32/boards: Add some missing board configs for two UM boards.UnexpectedMaker
2023-05-19stm32/irq: Fix typo in comment about priorities.iabdalkader
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-19renesas-ra/irq: Fix typo in comment about IRQ priorities.iabdalkader
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-19stm32/mboot: Fix alignment of packed final buffer.Andrew Leech
Once all the firmware has been flashed and the final signatures checked, mboot writes the "all good" byte into the header of the application. This step uses the buffer firmware_head which, if unaligned in the build, fails when cast to a uint64_t* in flash.c. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-05-19stm32/boards/stm32h723_af.csv: Fix ADC AF definitions.brave ulysses
These were incorrectly added in d995c010428420c7690d5cd59b9580c3f4f9649a. The fix here includes the full differential ADC definitions. Signed-off-by: brave ulysses <brave_ulysses@email.com>