summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-09-01esp32/machine_uart: Release GIL for blocking reads.Daniël van de Giessen
If we're reading from an UART with a non-zero timeout, we can release the GIL so that other threads/tasks may run while we are sleeping waiting for data to arrive. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-09-01esp32: Support JTAG console, free up UART.Daniël van de Giessen
CONFIG_USB_OTG_SUPPORTED is automatically set by the ESP-IDF when the chip supports USB-OTG, which is the case for the ESP32-S2 and ESP32-S3. When trying to use the JTAG console with these chips, it would not work because our USB implementation will take over control over the USB port, breaking the JTAG console in the process. Thus, when the board is configured to use the JTAG console, we should not enable our USB console support. Additionally, this change also frees up UART0 when an USB-based console is configured, since there's no reason to prevent (re)configuration of UART0 for other uses in that case. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-09-01esp32/modnetwork: Add support for SO_BINDTODEVICE socket option.Daniël van de Giessen
This implements support for SO_BINDTODEVICE, which allows telling a socket to use a specific interface instead of lwIP automatically selecting one. This allows devices that have multiple connections (for example cellular over PPP in addition to WLAN) to explicitly choose which data is send over which connection, which may have different reliability and or (mobile data) costs associated with using them. The used lwIP network stack already has support for this, so all that was needed was to expose this functionality in MicroPython. This commit exposes a new constant SO_BINDTODEVICE which can be set as an socket option. As a value it expects the name of the interface to bind to. These names can be retrieved using `.config('ifname')` implemented on each interface type (including adding in this commit a `.config()` method to PPP, which it didn't have before), which returns a string with the interface name: >>> import machine >>> import network >>> network.WLAN(network.AP_IF).config('ifname') 'lo0' >>> wlan = network.WLAN(network.AP_IF) >>> wlan.active(True) and wlan.config('ifname') 'ap1' >>> wlan = network.WLAN(network.STA_IF) >>> wlan.active(True) and wlan.config('ifname') 'st1' >>> ppp = network.PPP(machine.UART(0)) >>> ppp.active(True) and ppp.config('ifname') 'pp1' >>> ppp = network.PPP(machine.UART(0)) >>> ppp.active(True) and ppp.config('ifname') 'pp2' >>> ppp = network.PPP(machine.UART(0)) >>> ppp.active(True) and ppp.config('ifname') 'pp3' Note that lo0 seems to be returned by lwIP if the interface is not yet active. The method can also return None in the case of PPP where the entire lwIP interface doesn't yet exist before being activated. Currently no effort is made to unify those cases; it is expected that whatever we receive from lwIP is valid. When the socket option is set, this forces using a specific device: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, 'st1') setsockopt will throw (OSError: [Errno 19] ENODEV) if the specified interface does not exist. Tested with LAN, WLAN, and PPP; can specify which interface should be used and when testing with, for example, HTTP requests to ifconfig.co the returned IP address confirms a specific interface was used. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-09-01esp32/modsocket: Add support for SO_BROADCAST socket option.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-09-01extmod/{modlwip,modsocket}: Add support for SO_BROADCAST socket option.Wang Xuancong
Signed-off-by: Wang Xuancong <xuancong84@gmail.com>
2023-09-01extmod/vfs_posix_file: Implement sys.std*.buffer objects.stephanelsmith
Add the buffer attribute to sys.stdin, sys.stdout and sys.stderr. This provides raw access to underlying stdio streams for the unix port (and others that use VfsPosix). Signed-off-by: stephanelsmith <stephane.smith@titansensor.com>
2023-09-01extmod/vfs_posix_file: Fix flush handling on macOS.stephanelsmith
On macOS, if running micropython from subprocess.check_output, then a stdout.flush() raises error 45. Here's a test case. This will run fine on linux, but crashes on macOS with error 45. import sys import subprocess import tempfile with tempfile.NamedTemporaryFile('w') as fp: fp.write(''' import sys sys.stdout.write('hello world') sys.stdout.flush() print('') ''') fp.flush() print('py3') o = subprocess.check_output(f'python3 {fp.name}'.split()) print(o) print('upy') o = subprocess.check_output(f'micropython {fp.name}'.split()) print(o) On macOS: py3 b'hello world\n' upy Traceback (most recent call last): File "...", line 4, in <module> OSError: 45 On unix: py3 b'hello world\n' upy b'hello world\n' Signed-off-by: stephanelsmith <stephane.smith@titansensor.com>
2023-09-01tests/run-tests.py: Capture output of stderr when running on CPython.stephanelsmith
Signed-off-by: stephanelsmith <stephane.smith@titansensor.com>
2023-09-01py/dynruntime.h: Implement MP_OBJ_NEW_QSTR.Jim Mussared
Because mpy_ld.py doesn't know the target object representation, it emits instances of `MP_OBJ_NEW_QSTR(MP_QSTR_Foo)` as const string objects, rather than qstrs. However this doesn't work for map keys (e.g. for a locals dict) because the map has all_keys_are_qstrs flag is set (and also auto-complete requires the map keys to be qstrs). Instead, emit them as regular qstrs, and make a functioning MP_OBJ_NEW_QSTR function available (via `native_to_obj`, also used for e.g. making integers). Remove the code from mpy_ld.py to emit qstrs as constant strings, but leave behind the scaffold to emit constant objects in case we want to do use this in the future. Strictly this should be a .mpy sub-version bump, even though the function table isn't changing, it does lead to a change in behavior for a new .mpy running against old MicroPython. `mp_native_to_obj` will incorrectly return the qstr value directly as an `mp_obj_t`, leading to unexpected results. But given that it's broken at the moment, it seems unlikely that anyone is relying on this, so it's not work the other downsides of a sub-version bump (i.e. breaking pure-Python modules that use @native). The opposite case of running an old .mpy on new MicroPython is unchanged, and remains broken in exactly the same way. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-01tools/mpy_ld.py: Support more complex rodata sections.Jon Nordby
Sections sometimes named .rodata.str1.1 etc, instead of just .rodata. Avoid crashing in that case. Instead treat it like any other RO section. Fix thanks to @phlash. Fixes issue #8783. Signed-off-by: Jon Nordby <jononor@gmail.com>
2023-09-01py/modstruct: Support pad bytes in struct format.Daniël van de Giessen
This adds support for the x format code in struct.pack and struct.unpack. The primary use case for this is ignoring bytes while unpacking. When interfacing with existing systems, it may often happen that you either have fields in a struct that aren't properly specified or you simply don't care about them. Being able to easily skip them is useful. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-09-01py/objstr: Fix `str % {}` edge case.mcskatkat
Eliminate `TypeError` when format string contains no named conversions. This matches CPython behavior. Signed-off-by: mcskatkat <mc_skatkat@hotmail.com>
2023-09-01tests/unix/mod_os: Make os.system() test work on windows.stijn
The "true" command by default is unavailable on windows so use an equivalent which works on both unix and windows. Signed-off-by: stijn <stijn@ignitron.net>
2023-09-01examples/bluetooth: Link to aioble in BLE examples.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-01examples/bluetooth: Raise ValueError when advertising data is too large.Alexander Wilde
Signed-off-by: Alexander Wilde <alexander.wilde87@gmail.com>
2023-09-01docs/library/neopixel: Change link to a micropython-lib reference.Andy Piper
Signed-off-by: Andy Piper <andypiperuk@gmail.com>
2023-09-01stm32/uart: Fix UART timeout issue with low baudrate on G4 MCUs.Yuuki NAGAO
With using UART FIFO, the timeout should be long enough that FIFO becomes empty. Since previous data transfer may be ongoing, the timeout must be timeout_char multiplied by FIFO size + 1. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-09-01stm32/mboot: Fix fwupdate by replacing zlib with new deflate module.Oliver Joos
Since commit 3533924c36ae85ce6e8bf8598dd71cf16bbdb10b the zlib module has been replaced by the new deflate module. This commit updates the script fwupdate.py to use the new deflate module. Signed-off-by: Oliver Joos <oliver.joos@hispeed.ch>
2023-09-01extmod/moddeflate: Change default window size.Jim Mussared
The primary purpose of this commit is to make decompress default to wbits=15 when the format is gzip (or auto format with gzip detected). The idea is that someone decompressing a gzip stream should be able to use the default `deflate.DeflateIO(f)` and it will "just work" for any input stream, even though it uses a lot of memory. This is done by making uzlib report gzip files as having wbits set to 15 in their header (where it previously only set the wbits out parameter for zlib files), and then fixing up the logic in `deflateio_init_read`. Updates the documentation to match. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-01mimxrt/machine_uart: Support slow baud rates for UART.robert-hh
Down to 50 baud (in reverence to Jean-Maurice-Émile Baudot). Implemented for the MIMXRT10xx MCU's only. The MIMXRT1176 runs down to 300 baud. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-01mimxrt/boards: Fix use of MICROPY_HW_SDRAM_AVAIL in MIMXRT1176.ld.robert-hh
MICROPY_HW_SDRAM_AVAIL is always defined. Thanks to Ibrahim Abdakader for noticing. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-01mimxrt/machine_uart: Fix and complete UART.deinit and uart_deinit_all.robert-hh
The code did not check at deinit whether a UART was initialized. That did not matter for all MCU's except MIMXRT1176, which crashes at the second soft reset in a row. But since it is a general problem to use UART methods of a UART which has been deinitialized, checks were added to all applicable methods for a clear response instead of e.g. a crash. Deinitialize UART using software reset. It resets the UART but keeps it accessible for software, avoiding an exception when UART registers are accessed after a DeInit. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-01mimxrt/irq: Move all IRQ related definitions to dedicated header.iabdalkader
Following other ports, IRQ priorities and related functions are moved to their own header, to simplify mpconfigport.h. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-01drivers/cyw43: Make the CYW43 Bluetooth HCI driver more portable.iabdalkader
This commit allows other ports to reuse the CYW43 HCI driver, by replacing all Bluetooth UART and control named pins with defines in config files and using `mpbthci` abstract functions (i.e. `mp_bluetooth_hci_*`) instead of the STM32 specific UART functions. Note: the function `cywbt_wait_cts_low` does not need to switch the CTS pin from alternate function to GPIO to read it. At least on stm32, mimxrt it's possible to just read the pin input. For example, see the STM32F7 RM0410 section 6.3.11, and the `SION` for IMXRT. So this function can also be available for other ports if the pin mode switching is removed. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-08-31mimxrt: Integrate Bluetooth support with NimBLE bindings.iabdalkader
This commit adds the necessary functions to get NimBLE working with the mimxrt port. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-08-31mimxrt: Integrate support for WiFi via the CYW43 driver.iabdalkader
This commit adds the necessary configuration and hooks to get the CYW43 driver working with the mimxrt port. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-08-31mimxrt/sdio: Add SDIO driver.iabdalkader
This is a basic SDIO driver for the mimxrt port, that was added mainly to support the CYW43 WiFi driver, and as such it only supports the commands required by the CYW43 driver (but more commands can be added easily). The driver performs non-blocking DMA transfers, and can detect and recover from errors. Note: because the mimxrt port is missing static alternate functions, named pins and other pin related functions, currently the alternate functions for USDHC 1 and 2 are hard-coded in the driver. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-08-31mimxrt/machine_pin: Extend pin configuration functions.iabdalkader
Add portable pin config macros to mphalport.h. And add a function to configure pins with more pin options such as alt function, pull, speed, drive, interrupt mode, etc. Note: this new `machine_pin_config()` function can replace `machine_pin_set_mode()`, but the latter is left as-is to avoid breaking anything. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-08-30extmod/modssl_mbedtls: Clear sock member if error creating SSLSocket.Damien George
Otherwise if/when the finaliser runs for this newly created SSLSocket the mbedtls state will be freed again. Signed-off-by: Damien George <damien@micropython.org>
2023-08-30py/mpconfig: Enable SSL finalizers if finalizers are enabled.Jim Mussared
The rp2 port was enabling SSL and had finalizers enabled via the "extra features" level, but missed explicitly enabling `MICROPY_PY_SSL_FINALISER` (like esp32, stm32, and mimxrt did). This commit makes `MICROPY_PY_SSL_FINALISER` default to enabled if finalizers are enabled, and removes the explicit setting of this for esp32, stm32, mimxrt (because they all use the "extra features" level). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-30py/profile: Remove the requirement to disable MICROPY_COMP_CONST.Jim Mussared
The only reason that const had to be disabled was to make the test output match CPython when const was involved. Instead, this commit fixes the test to handle the lines where const is used. Also: - remove the special handling for MICROPY_PERSISTENT_CODE_SAVE in unix/mpconfigport.h, and make this automatic. - move the check for MICROPY_PERSISTENT_CODE_SAVE to where it's used (like we do for other similar checks) and add a comment explaining it. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-30tests/misc/sys_settrace_features.py: Fix to run on newer CPython.Jim Mussared
This test was failing on CPython 3.11 as it now emits `0` as the line number for the "call" event corresponding to import, where as in 3.6 it had `1` as the line number. We maintain the old behavior, but in order to make this test pass on both CPython versions, the trace handler now converts the `0` to a `1`. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-24esp8266/boards/ESP8266_GENERIC: Add image filename.Damien George
This image is now in micropython-media. Signed-off-by: Damien George <damien@micropython.org>
2023-08-24cc3200/Makefile: Build firmware.zip.Jim Mussared
This allows the cc3200 port to be build with the standard autobuild script rather than the custom build-cc3200-latest.sh (which is now removed). This also fixes the path inside the zip file (by using the `-j` flag to zip). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23esp32/boards/ESP32_GENERIC_C3: Enable UART REPL.Jim Mussared
This should have been added in 4815af75bc0bc21e1e66b958fd4ee4e90c24ba10 when the variants were combined. The original non-USB variant got this implicitly, and therefore was not in mpconfigvariant.h Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23rp2: Rename PICO, PICO_W to RPI_PICO, RPI_PICO_W.Jim Mussared
PICO might not always be a unique name across all ports, and the convention generally for other boards is to do VENDOR_BOARD. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23esp8266: Add board variant support.Jim Mussared
This merges the existing GENERIC, GENERIC_1M, and GENERIC_512k boards into variants of the new ESP8266_GENERIC board (renamed from GENERIC so as not to clash with other ports). Also moves the generation of the "OTA" variant (previously generated by autobuild/build-esp8266-latest.sh) into the variant. Following the convention established for the WEACTSTUDIO rp2 board, the names of the variants are FLASH_1M and FLASH_512K (but rename the .ld files to use MiB and kiB). Updates autobuild to build esp8266 firmware the same way as other ports. This requires renaming the output from firmware-combined.bin to just firmware.bin. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23esp32: Rename GENERIC* boards to ESP32_GENERIC*.Jim Mussared
Board names need to be unique across ports, and GENERIC clashes with the ESP8266 (which will be renamed to ESP8266_GENERIC). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23{esp32,rp2,stm32}/Makefile: Append board variant to BUILD.Jim Mussared
This allows switching between variants without clobbering the build output. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23ports/*/boards/*/board.json: Remove "id" field.Jim Mussared
This was used to override the firmware filename generated by the build server (to match the historical name before board definitions existed). Now we're making everything use the board definition name (i.e. the directory name). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23stm32: Use uppercase variant names.Jim Mussared
This is to support a future change to add the variant name to the build directory and therefore should be the same style as the board name. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23rp2: Use uppercase variant names.Jim Mussared
This is to support a future change to add the variant name to the build directory and therefore should be the same style as the board name. This only affects the WEACTSTUDIO board. Also standardises on a convention for naming flash-size variants. Normally we would write e.g. 2MiB, but in uppercase, it's awkward to write 2MIB, so instead use 2M, 512K, etc for variant names, but use 2MiB when not constrained by case (e.g. a regular filename). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23esp32: Use uppercase variant names.Jim Mussared
This is to support a future change to add the variant name to the build directory and therefore should be the same style as the board name. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23nrf/boards: Rename all nRF boards to use uppercase.Jim Mussared
This is to match all the other ports. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-23stm32/modstm: Add MICROPY_PY_STM_CONST flag, clear it for STM32WL5.Angus Gratton
MICROPY_PY_STM_CONST defaults to 1 if MICROPY_PY_STM is set. Overriding to 0 disables the named register peripheral constants being including in the stm32 module. This saves about 7.5KB of code size for the STM32WL55, which is significant as this SoC doesn't have a lot of flash. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-23stm32/subghz: Add STM32WL55 subghz radio interface to stm module.Angus Gratton
This is the minimum C interface to allow a modem driver to be built in Python. Interface is simple, with the intention that the micropython-lib driver is the main (only) consumer of it. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-23stm32/dma: Fix DMA completion on WL55 boards.Angus Gratton
No IRQHandlers were compiled in for this board. Includes small consolidation of the same DMAMUX_ENABLE line for STM32G4, STM32WB, STM32WL. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-23stm32/powerctrlboot: Support STM32WL system clock from HSE+PLL.Angus Gratton
Switches default on the NUCLEO_WL55 board to use the HSE oscillator powered from PB0_VDDTCXO pin. Build-time configuration can select from MSI internal oscillator (previous default), HSE via crystal, or HSE bypass with TCXO powered from PB0_VDDTCXO pin (new default) Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-23stm32/spi: Add STM32WL5 SUBGHZ SPI peripheral.Angus Gratton
This is a "normal" SPI peripheral with no external pins, to avoid having to grow spi_obj[] for just this one board map it as SPI ID 3 (board has SPI IDs 1,2 already). Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16mimxrt: Fix UART RTS/CTS assignments for the OLIMEX and Adafruit boards.robert-hh
At the Adafruit Metro M7 the pin GPIO_AD_13 is used for JTAG. Therefore it is not configured for RTS at UART 2 and 3. Signed-off-by: robert-hh <robert@hammelrath.com>