Commit Graph

3896 Commits

Author SHA1 Message Date
iabdalkader
abd9bed667 renesas-ra/fsp_cfg: Add common FSP config files.
Add DAC, SCE and USB FSP config files.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:51:30 +10:00
iabdalkader
31ff3ff3aa renesas-ra: Add mbedTLS support.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:51:20 +10:00
iabdalkader
62e650f2c2 renesas-ra: Add networking support using lwIP.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:51:18 +10:00
iabdalkader
142e8b70e2 renesas-ra: Add RNG driver.
It needs to be enabled explicitly by a board.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:50:47 +10:00
iabdalkader
5b774517dc renesas-ra: Add Bluetooth support using NimBLE.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:50:47 +10:00
iabdalkader
d89a0606e0 renesas-ra: Add TinyUSB support.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:50:45 +10:00
iabdalkader
816b88ad07 mimxrt/Makefile: Update to work with latest TinyUSB.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:35:54 +10:00
iabdalkader
09a2ee8e7f renesas-ra/Makefile: Generate binary firmware output.
This patch generates a binary firmware image (*.bin) and removes the split
TEXT1/0_ADDR/SECTIONS because it's not configured for this port so it
generates broken binaries.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-14 23:34:18 +10:00
Damien George
dc99840b3a stm32/uart: Add support for UART10 when it's a USART.
Signed-off-by: Damien George <damien@micropython.org>
2023-09-13 16:48:15 +10:00
Damien George
a4d28e5279 stm32/timer: Fix use of TIM8 on H5 MCU's.
Signed-off-by: Damien George <damien@micropython.org>
2023-09-13 16:48:15 +10:00
Damien George
67b1c81f69 stm32/powerctrlboot: Allow using PLL3 for USB clock on H5 MCU's.
A board should enable MICROPY_HW_CLK_USE_PLL3_FOR_USB to use this feature.

Signed-off-by: Damien George <damien@micropython.org>
2023-09-13 16:48:15 +10:00
Damien George
60e0ef6ef6 stm32/octospi: Add support for dual-line SPI interface.
And fix the case of 32-bit addresses in single-line mode.

Signed-off-by: Damien George <damien@micropython.org>
2023-09-13 16:48:15 +10:00
Damien George
ee5e594472 stm32/dma: Add support for SPI1 DMA on H5 MCU's.
Signed-off-by: Damien George <damien@micropython.org>
2023-09-13 16:14:23 +10:00
Andrew Leech
ff70bd1197 stm32/timer: Fix deadtime config on Advanced Timer peripherals.
Newer MCU series have additional fields in the struct which need to be
initialised to zero, eg Break2AFMode on WB55.

This work was funded by Planet Innovation.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-09-12 17:12:16 +10:00
Glenn Moloney
0bafdaf5f0 esp32: Skip validation of image on boot from deepsleep.
sdkconfig.base: Add CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y.
This reduces time to boot from deepsleep by at least 200ms and can
provide significant power savings for deepsleep-based battery
applications.

docs/library/esp32.rst: Add note cautioning not to enter deepsleep after
changing the boot partition, without first performing a hard reset.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2023-09-05 22:36:06 +10:00
Damien George
671b38f944 mimxrt/sdio: Move config guard so headers are only included if used.
Otherwise it's a build error on certain MCU series.

Signed-off-by: Damien George <damien@micropython.org>
2023-09-05 11:03:08 +10:00
robert-hh
297892c4f4 mimxrt/machine_uart: Add a helper function to change the baudrate.
And use it in the Bluetooth bindings instead of setting the baudrate by a
call to the NXP lib.

Also fixes machine_uart.c to work with a baud rate of 921600.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-05 10:54:49 +10:00
Seon Rozenblum
8bd2494c95 esp32/boards/UM_FEATHERS3: Fix I2C pins in pins.csv.
Signed-off-by: Seon Rozenblum <seon@unexpectedmaker.com>
2023-09-04 23:32:09 +10:00
Sebastian Romero
bf35eefc62 esp32/boards/ARDUINO_NANO_ESP32: Clarify recovery instructions.
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
2023-09-04 10:55:31 +10:00
David Yang
545b94a8f5 unix/modjni: Fix build errors with type definitions and error strings.
- Superfluous comments in MP_DEFINE_CONST_OBJ_TYPE stop correct macro
  expanding.
- MP_ERROR_TEXT now gives mp_rom_error_text_t, but we want plain const
  char *.

Signed-off-by: David Yang <mmyangfl@gmail.com>
2023-09-04 10:22:19 +10:00
David Lechner
ffb43b2dd3 py/modthread: Return thread id from start_new_thread().
In CPython, `_thread.start_new_thread()` returns an ID that is the same ID
that is returned by `_thread.get_ident()`.  The current MicroPython
implementation of `_thread.start_new_thread()` always returns `None`.

This modifies the required functions to return a value. The native thread
id is returned since this can be used for interop with other functions, for
example, `pthread_kill()` on *nix. `_thread.get_ident()` is also modified
to return the native thread id so that the values match and avoids the need
for a separate `native_id` attribute.

Fixes issue #12153.

Signed-off-by: David Lechner <david@pybricks.com>
2023-09-03 18:49:18 +10:00
Daniël van de Giessen
c0d4c604e6 esp32/network_ppp: Block after deleting task.
When calling ppp.active(False) we could get a crash due to immediately
returning after asking FreeRTOS to delete the current task.

This commit adds a simple blocking loop, the same as used in all other
places where we call vTaskDelete(NULL).

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-09-02 18:01:03 +10:00
Seon Rozenblum
6bd1404225 esp32/boards/UM_NANOS3: Add new UM NanoS3 board.
Signed-off-by: Seon Rozenblum <seon@unexpectedmaker.com>
2023-09-02 17:55:24 +10:00
Seon Rozenblum
6ec2e8f643 esp32/boards: Add pins.csv to UM boards and other minor changes.
Signed-off-by: Seon Rozenblum <seon@unexpectedmaker.com>
2023-09-02 17:51:26 +10:00
robert-hh
9f1576f2ad rp2/machine_timer: Fix printing of timer period.
Showing the period alway as microsecond quantities, since tick_hz is
assumed as 1_000_000 if the period is given by freq=xxx.  If the period is
larger than 0xffffffff, the value is divided by 1000 and "000" is appended
in the display.  That works for periods up to about 50 days.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-02 17:09:51 +10:00
Jim Mussared
f52a2cd55a samd/modules/_boot.py: Add /lib to sys.path.
Needed for mip to find a default location to install to.

Like esp32, samd uses "/" as the mount point for the flash. Make _boot.py
add the entry after successfully mounting.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-02 00:09:26 +10:00
Daniël van de Giessen
3cc3e4e032
esp32/machine_uart: Release GIL for blocking reads.
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-01 14:23:54 +02:00
Daniël van de Giessen
f8bd6778c8 esp32: Support JTAG console, free up UART.
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-01 21:01:26 +10:00
Daniël van de Giessen
ba8aad3d1d esp32/modnetwork: Add support for SO_BINDTODEVICE socket option.
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-01 19:21:20 +10:00
Damien George
56e5a21312 esp32/modsocket: Add support for SO_BROADCAST socket option.
Signed-off-by: Damien George <damien@micropython.org>
2023-09-01 18:35:09 +10:00
Yuuki NAGAO
141750ff79 stm32/uart: Fix UART timeout issue with low baudrate on G4 MCUs.
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-01 13:52:00 +10:00
Oliver Joos
a175f98a65 stm32/mboot: Fix fwupdate by replacing zlib with new deflate module.
Since commit 3533924c36 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-01 12:39:06 +10:00
robert-hh
81c19d93bc mimxrt/machine_uart: Support slow baud rates for UART.
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-01 00:41:23 +10:00
robert-hh
c86b9ec8bd mimxrt/boards: Fix use of MICROPY_HW_SDRAM_AVAIL in MIMXRT1176.ld.
MICROPY_HW_SDRAM_AVAIL is always defined.

Thanks to Ibrahim Abdakader for noticing.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-01 00:40:44 +10:00
robert-hh
ce38784fa8 mimxrt/machine_uart: Fix and complete UART.deinit and uart_deinit_all.
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-01 00:27:13 +10:00
iabdalkader
3f5976e14a mimxrt/irq: Move all IRQ related definitions to dedicated header.
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-01 00:02:19 +10:00
iabdalkader
a453b4f31d drivers/cyw43: Make the CYW43 Bluetooth HCI driver more portable.
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-09-01 00:02:00 +10:00
iabdalkader
fc495240a6 mimxrt: Integrate Bluetooth support with NimBLE bindings.
This commit adds the necessary functions to get NimBLE working with the
mimxrt port.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-08-31 23:42:10 +10:00
iabdalkader
772a36098f mimxrt: Integrate support for WiFi via the CYW43 driver.
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-31 23:40:49 +10:00
iabdalkader
46d83d9748 mimxrt/sdio: Add SDIO driver.
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-31 23:39:34 +10:00
iabdalkader
6b407d5600 mimxrt/machine_pin: Extend pin configuration functions.
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-31 23:36:20 +10:00
Jim Mussared
f3eccb154c py/mpconfig: Enable SSL finalizers if finalizers are enabled.
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-30 12:38:13 +10:00
Jim Mussared
b2b5bcce28 py/profile: Remove the requirement to disable MICROPY_COMP_CONST.
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-30 10:58:04 +10:00
Damien George
1dedb65e64 esp8266/boards/ESP8266_GENERIC: Add image filename.
This image is now in micropython-media.

Signed-off-by: Damien George <damien@micropython.org>
2023-08-24 17:15:32 +10:00
Jim Mussared
bc1af5ab7f cc3200/Makefile: Build firmware.zip.
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-24 15:44:20 +10:00
Jim Mussared
326dfd2a85 esp32/boards/ESP32_GENERIC_C3: Enable UART REPL.
This should have been added in 4815af75bc
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-23 15:49:37 +10:00
Jim Mussared
873bd00ad4 rp2: Rename PICO, PICO_W to RPI_PICO, RPI_PICO_W.
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-23 15:49:37 +10:00
Jim Mussared
ef03ca8bf2 esp8266: Add board variant support.
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-23 15:49:37 +10:00
Jim Mussared
aa23698119 esp32: Rename GENERIC* boards to ESP32_GENERIC*.
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 13:54:37 +10:00
Jim Mussared
97ffc53ec9 {esp32,rp2,stm32}/Makefile: Append board variant to BUILD.
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-23 13:54:37 +10:00
Jim Mussared
1a99f74063 ports/*/boards/*/board.json: Remove "id" field.
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-23 13:54:37 +10:00
Jim Mussared
c3093080b1 stm32: Use uppercase variant names.
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-23 13:54:37 +10:00
Jim Mussared
45845acf6d rp2: Use uppercase variant names.
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-23 13:54:37 +10:00
Jim Mussared
b5836e7252 esp32: Use uppercase variant names.
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-23 13:54:37 +10:00
Jim Mussared
f007d0aa3d nrf/boards: Rename all nRF boards to use uppercase.
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-23 13:54:37 +10:00
Angus Gratton
2919a9fbf3 stm32/modstm: Add MICROPY_PY_STM_CONST flag, clear it for STM32WL5.
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-23 11:58:11 +10:00
Angus Gratton
02620c2236 stm32/subghz: Add STM32WL55 subghz radio interface to stm module.
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-23 11:58:11 +10:00
Angus Gratton
9e0f934cdf stm32/dma: Fix DMA completion on WL55 boards.
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-23 11:58:11 +10:00
Angus Gratton
2c62adb42c stm32/powerctrlboot: Support STM32WL system clock from HSE+PLL.
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-23 11:58:11 +10:00
Angus Gratton
e6cfb77342 stm32/spi: Add STM32WL5 SUBGHZ SPI peripheral.
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-23 11:58:08 +10:00
robert-hh
a18d62e067
mimxrt: Fix UART RTS/CTS assignments for the OLIMEX and Adafruit boards.
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>
2023-08-16 10:06:59 +02:00
Angus Gratton
974f99482c renesas-ra/boards: Remove unreachable code in make-pins.py.
Looks like copy-paste from the stm32 make-pins.py, references a function
that is not present in the renesas-ra version.

Found by Ruff checking F821.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16 16:16:40 +10:00
Angus Gratton
801910fc83 all: Add missing imports for micropython.const.
Found by Ruff checking F821.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16 16:13:27 +10:00
Angus Gratton
ef864a4aa4 cc3200/tools: Fix exception raised on process failure.
subprocess.CalledProcessError() constructor arguments aren't documented,
but these are them.  Even if they change, it's an improvement over a
non-existent exception name!

Found by Ruff checking F821.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16 16:13:11 +10:00
Angus Gratton
861fbf6ab5 examples: Mark asm, pio, etc. as noqa: F821 (undefined-name).
These files all use decorators (@asm_thumb, @asm_pio) that add names to the
function scope, that the linter cannot see.

It's useful to clear them in the file not in pyproject.toml as example code
will be copied and adapted elsewhere, and those developers may also use
Ruff (we hope!)

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16 16:12:33 +10:00
Kwabena W. Agyeman
00855eeb36 mimxrt/hal: Make flash clock frequency configurable.
Signed-off-by: "Kwabena W. Agyeman" <kwagyeman@live.com>
2023-08-15 23:45:22 +10:00
Kwabena W. Agyeman
cb7e133dbe mimxrt/boards: Add support for GPIO control of SNVS pins.
Signed-off-by: "Kwabena W. Agyeman" <kwagyeman@live.com>
2023-08-15 23:35:33 +10:00
Kwabena W. Agyeman
afe2ca1a0a mimxrt/machine_uart: Add support for UART hardware flow control.
Signed-off-by: "Kwabena W. Agyeman" <kwagyeman@live.com>
2023-08-15 23:21:33 +10:00
robert-hh
e43c669b4a mimxrt/machine_uart: Add uart.deinit method and machine_uart_deinit_all.
The call to machine_uart_deinit_all() is needed to avoid a crash after soft
reset, if a UART had been used and data arrives before it is instantiated
again.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-08-15 23:08:30 +10:00
robert-hh
a9a219d8bf mimxrt/hal/pwm_backport: Fix 0 and 65536 edge cases of PWM's duty_u16.
It should be that:
- duty_u16=0: output low, no pulse
- duty_u16=65536: output high, no pulse

That previously did not apply to all of the three PWM mechanisms of this
port.  This commit fixes it.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-08-15 23:06:12 +10:00
robert-hh
a9821c0185 mimxrt/machine_pin: Fix bug when Pin.irq is called without a handler.
When called without a handler, the IRQ data was not cleared.  That caused a
crash at the second soft reset in a row.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-08-15 23:03:37 +10:00
Jim Mussared
96258d3716 esp32/partitions.csv: Rename to partitions-4MiB.csv.
To be consistent with the other partitions files (which have the "-
{2,8,16,32}MiB" suffix). Also renames partitions-ota.csv.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:38:02 +10:00
Jim Mussared
afd407af8f esp32/boards/GENERIC_S3: Merge with GENERIC_S3_{SPIRAM,SPIRAM_OCT}.
These are now variants of the GENERIC_S3 board.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:38:02 +10:00
Jim Mussared
b25a67590d esp32/boards/GENERIC_S2: Merge with ESP32_S2_WROVER.
Unsure of the history of the ESP32_S2_WROVER board (and why it wasn't
named GENERIC_S2_...) but now it's a variant of the generic S2 board.

Also removes the non-existent CONFIG_USB_AND_UART from all S2 boards.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:38:02 +10:00
Jim Mussared
4815af75bc esp32/boards/GENERIC_C3: Merge with GENERIC_C3_USB.
As the IDF no longer supports earlier revisions of the C3 by default, we
now just explicitly support rev 3+ and enable USB (which wasn't supported
in earlier revisions).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:37:44 +10:00
Jim Mussared
2fbf42d3ad esp32/boards/GENERIC: Merge with GENERIC_{SPIRAM,OTA,D2WD,UNICORE}.
These are now variants of the GENERIC board.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:37:44 +10:00
Jim Mussared
9573d31071 all: Remove query-variants make target.
This is difficult to implement on cmake-based ports, and having the list
of variants in mpconfigboard.{cmake,mk} duplicates information that's
already in board.json.

This removes the existing query-variants make target from stm32 & rp2
and the definition of BOARD_VARIANTS from the various board files.

Also renames the cmake variable to MICROPY_BOARD_VARIANT to match other
variables such as MICROPY_BOARD. The make variable stays as
BOARD_VARIANT.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:37:44 +10:00
Jim Mussared
ad123ed013 esp32/Makefile: Implement make submodules to match other ports.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:37:44 +10:00
Damien George
fa1ea21f75 esp32/gccollect: Make level arg volatile to force recursive function.
Otherwise the compiler may inline the gc_collect_inner() function and/or
remove the recursion, which is necessary to spill all the windowed
registers to the C stack.

Signed-off-by: Damien George <damien@micropython.org>
2023-08-15 16:12:54 +10:00
Angus Gratton
05dcb8be99 esp32: Enable automatic Python heap growth.
Via MICROPY_GC_SPLIT_HEAP_AUTO feature flag added in previous commit.

Tested on ESP32 GENERIC_SPIRAM and GENERIC_S3 configurations, with some
worst-case allocation patterns and the standard test suite.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-15 10:50:46 +10:00
Angus Gratton
98fd78437c esp32: Allow malloc() to allocate from SPIRAM.
Also shrinks the "prefer internal" threshold to 8KB, any allocation larger
than this will try PSRAM first.

Change the mbedTLS config to use regular malloc() as well, instead of
internal only.  The default is set to internal-only due to to potential
physical security issue of readout via PSRAM on the original ESP32.
However, as MicroPython runs from plaintext flash and all other context is
in the MP heap of PSRAM then it's hard to see how worsens physical security
for MP.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-15 10:49:33 +10:00
Jim Mussared
24a6e951ec ports: Simplify board feature tags in board.json.
This commit:
- Finds a common set of board feature tags and maps existing features to
  that reduced set.
- Removes some less-useful board feature tags.
- Ensures all MCUs are specified correctly.
- Ensures all boards have a vendor (and fixes some vendor names).

This is to make the downloads page show a less intimidating set of filters.

Work done in conjunction with Matt Trentini <matt.trentini@gmail.com>.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-10 14:54:03 +10:00
Damien George
ef71028f77 extmod/modselect: Add optimisation to use system poll when possible.
A previous commit removed the unix-specific select module implementation
and made unix use the common one.

This commit adds an optimisation so that the system poll function is used
when polling objects that have a file descriptor.  With this optimisation
enabled, if code registers both file-descriptor-based objects, and non-
file-descriptor-based objects with select.poll() then the following occurs:

- the system poll is called for all file-descriptor-based objects with a
  timeout of 1ms

- then the bare-metal polling implementation is used for remaining objects,
  which calls into their ioctl method (which can be in C or Python)

In the case where all objects have file descriptors, the system poll is
called with the full timeout requested by the caller.  That makes it as
efficient as possible in the case everything has a file descriptor.

Benefits of this approach:

- all ports use the same select module implementation

- the unix port now supports polling of all objects and matches bare metal
  implementations

- it's still efficient for existing cases where only files and sockets are
  polled (on unix)

- the bare metal implementation does not change

- polling of SSL objects will now work on unix by calling in to the ioctl
  method on SSL objects (this is required for asyncio ssl support)

Note that extmod/vfs_posix_file.c has poll disable when the optimisation is
enabled, because the code is not reachable when the optimisation is used.

Signed-off-by: Damien George <damien@micropython.org>
2023-08-07 12:11:40 +10:00
Damien George
df08c38c28 unix/modselect: Remove unix-specific implementation of select module.
The unix port has a custom select module which only works with objects that
have a file descriptor, eg files and sockets.  On the other hand, bare
metal ports use the common extmod/modselect.c implementation of the select
module that supports polling of arbitrary objects, as long as those objects
provide a MP_STREAM_POLL in their ioctl implementation (which can be done
in C or Python).

This commit removes the unix-specific code and makes unix use the common
one provided by extmod/modselect.c instead.  All objects with file
descriptors implement MP_STREAM_POLL so they continue to work.

Signed-off-by: Damien George <damien@micropython.org>
2023-08-07 12:09:38 +10:00
Damien George
6a179019e8 unix/modsocket: Add poll support for missing ERR,HUP,NVAL poll values.
Signed-off-by: Damien George <damien@micropython.org>
2023-08-06 11:54:06 +10:00
Brett Cannon
01c758e26a unix/README: Fix Markdown link markup.
Signed-off-by: Brett Cannon <brett@python.org>
2023-07-27 21:40:41 +10:00
Damien George
cfcce4b531 esp32/README: Specify that only IDF v5.0.2 is supported.
Signed-off-by: Damien George <damien@micropython.org>
2023-07-25 12:59:02 +10:00
Damien George
c9d2c5537b esp32/boards: Remove references to the IDF version in board.md files.
Listing the IDF version number in the board description is not as important
as it once was, when the IDF was still undergoing a lot of changes.  Now,
all builds use IDF 5.x and it's possible to query the exact version with
platform.platform().

Signed-off-by: Damien George <damien@micropython.org>
2023-07-25 12:35:21 +10:00
Damien George
b2adfc8077 esp32/machine_hw_spi: Check for valid SPI id in constructor, not init.
Otherwise constructing an invalid SPI instance (eg machine.SPI(3)) will
mess up machine.SPI(2)'s state before it's detected that it's an invalid
SPI id.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-25 11:33:51 +10:00
Damien George
162dd022b1 esp32/machine_hw_spi: Remove SPI host renaming for C3 and S3 variants.
On ESP32C3 it's not doing anything.  On ESP32S3 the original code prevented
prevented machine.SPI(1) from working.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-25 11:13:25 +10:00
Damien George
862944a71f esp32/machine_hw_spi: Remove unnecessary duplicate SPI pin defaults.
Signed-off-by: Damien George <damien@micropython.org>
2023-07-25 10:54:41 +10:00
Damien George
aab8061dce esp32/machine_hw_spi: Fix access of SPI(2).
SPI3_HOST is not a macro but rather an enum, so use SOC_SPI_PERIPH_NUM to
detect if it's defined.

Fixes issue #11919.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-25 10:54:29 +10:00
Jim Mussared
975a687447 py/mpconfig: Add MICROPY_PY_PLATFORM, enabled at extra features level.
Previously this was explicitly enabled on esp32/stm32/renesas/mimxrt/samd,
but didn't get a default feature level because it wasn't in py/mpconfig.h.

With this commit it's now enabled at the "extra features" level, which adds
rp2, unix-standard, windows, esp8266, webassembly, and some nrf boards.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-24 23:53:20 +10:00
Daniël van de Giessen
52dc48b2a0 esp32/machine_wdt: Allow feeding WDT from threads.
This changes the ESP32 WDT implementation to use a custom handle so that it
becomes possible to reset the WDT from a thread.

By default esp_task_wdt_add subscribes the task_id of the current task.
That means that if we're running in a different task we are unable to reset
the WDT, which prevents feeding the WDT from a thread directly, or even
from a timer (which may randomly run in a different task when there's
multiple threads).

As an added bonus, the name we set makes the error clearly specify that it
was the user-specified WDT that reset the chip.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-07-24 23:29:53 +10:00
Daniël van de Giessen
1bde5f3316 esp32/main: Remove unused mbedtls debug function.
Since commit beeb74 we already check in modussl_mbedtls whether this
function is provided by the ESP-IDF before calling it, thus we no longer
need to define it here in order to compile.

Removing it so that if CONFIG_MBEDTLS_DEBUG is defined we do not cause any
'multiple definition' compile errors.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-07-24 23:28:16 +10:00
iabdalkader
c1acea0e73 esp32/boards/ARDUINO_NANO_ESP32: Fix deploy instructions.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-07-24 17:45:19 +10:00
Jim Mussared
3533924c36 extmod/moddeflate: Add deflate module providing the DeflateIO class.
This provides similar functionality to the former zlib.DecompIO and
especially CPython's gzip.GzipFile for both compression and decompression.

This class can be used directly, and also can be used from Python to
implement (via io.BytesIO) zlib.decompress and zlib.compress, as well as
gzip.GzipFile.

Enable/disable this on all ports/boards that zlib was previously configured
for.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:32:40 +10:00
Jim Mussared
e6c290c3d1 lib/uzlib: Add a source_read_data var to pass to source_read_cb.
For better abstraction for users of this API.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:34 +10:00
Jim Mussared
d75a3cd861 lib/uzlib: Combine zlib/gzip header parsing to allow auto-detect.
This supports `wbits` values between +40 to +47.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:34 +10:00
Jim Mussared
c2b8e6e5d6 lib/uzlib: Clean up tinf -> uzlib rename.
This library used a mix of "tinf" and "uzlib" to refer to itself.  Remove
all use of "tinf" in the public API.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:24 +10:00
Jim Mussared
198311c780 py/stream: Add mp_stream___exit___obj that calls mp_stream_close.
There are enough places that implement __exit__ by forwarding directly to
mp_stream_close that this saves code size.

For the cases where __exit__ is a no-op, additionally make their
MP_STREAM_CLOSE ioctl handled as a no-op.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 18:49:03 +10:00
Jim Mussared
add1200343 all: Remove the zlib module.
This will be replaced with a new deflate module providing the same
functionality, with an optional frozen Python wrapper providing a
replacement zlib module.

binascii.crc32 is temporarily disabled.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 18:48:29 +10:00
Mark Grosen
9fb56d1562 esp32/CMakeLists: Enable multiple extra component directories in build.
The EXTRA_COMPONENT_DIRS variable is a list so adding a directory so should
be done via append, not set.  This enables boards to use other components
in the build. See:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#optional-project-variables
2023-07-21 00:13:10 +10:00
Luca Burelli
cc9735ad6a esp32/boards/ARDUINO_NANO_ESP32: Add support for Arduino Nano ESP32.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20 23:55:48 +10:00
Luca Burelli
3d98f6b80a esp32/usb: Add custom TinyUSB callback support.
Allow boards to define their own additional USB callbacks.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20 23:55:35 +10:00
Luca Burelli
904ccfaf94 esp32/modmachine: Add generic machine.bootloader().
Implement a standard machine.bootloader() method for ESP32-series devices.
No default implementation, each board can enable it as required.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20 23:55:21 +10:00
Luca Burelli
31ef7c186b esp32: Collect properties from IDF-managed components as well.
Some targets like the ESP32-S3 use the IDF Component Manager to provide
additional dependencies to the build.  Make sure to include these extra
components when collecting properties used by MicroPython-specific build
steps, like qstr preprocessing.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20 23:54:53 +10:00
Angus Gratton
4548928449 stm32/boards/B_L072Z_LRWAN1: Lower default ROM level to "Core".
Re-enable some features required for the board to still build and the lora
driver to run.

This board only has 192KB of flash total, so default stm32 build is very
close to the limit.

Before:

LINK build-B_L072Z_LRWAN1/firmware.elf
   text    data     bss     dec     hex filename
 184352      68   14112  198532   30784 build-B_L072Z_LRWAN1/firmware.elf

(12256 bytes free)

After:

LINK build-B_L072Z_LRWAN1/firmware.elf
   text    data     bss     dec     hex filename
 155028      68   14052  169148   294bc build-B_L072Z_LRWAN1/firmware.elf

(41580 bytes free)

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-07-20 21:48:10 +10:00
Angus Gratton
3aabdf2f6b stm32/boards/B_L072Z_LRWAN1: Add pin definitions for internal SX1262.
Includes fixing the SCK connection pin.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-07-20 21:47:55 +10:00
Damien George
cb31c0ae9c esp32: Add support for board-named pins and the Pin.board dict.
This adds named-pins support to the esp32 port, following other ports.
Since the name of esp32 CPU pins is just GPIOx, where x is an integer, the
Pin.cpu dict is not supported and CPU pins are just retrieved via their
existing integer "name" (the cost of adding Pin.cpu is about 800 bytes,
mostly due to the additional qstrs).

What this commit supports is the Pin.board dict and constructing a pin by
names given by a board.  These names are defined in a pins.csv file at the
board level.  If no such file exists then Pin.board exists but is empty.

As part of this commit, pin and pin IRQ objects are optimised to reduce
their size in flash (by removing their gpio_num_t entry).  The net change
in firmware size for this commit is about -132 bytes.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-20 18:17:36 +10:00
robert-hh
51c2d26f15 renesas-ra/machine_spi: Consistently use machine_pin_find to get pin.
Sometimes mp_hal_get_pin_obj() was used.  machine_pin_find() is the
internal name, and the external interface is mp_hal_get_pin_obj().

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20 17:36:18 +10:00
robert-hh
9fea0e98b1 esp8266/machine_pin: Accept an integer argument to mp_obj_get_pin_obj.
Allowing the machine.pwm() and esp.apa102() module to accept Pin(x) integer
parameters.  Not so much of a gain, just consistent with other ports.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20 17:33:54 +10:00
robert-hh
29e9573de7 esp32: Use always machine_pin_get_id for getting a Pin id.
This applies to all machine modules which have pins as arguments.  Since
machine_pin_get_id() calls pin_find(), these pin arguments may be at the
moment either integer objects or Pin objects.  That allows for instance to
write

    uart = UART(1, tx=Pin(4), rx=Pin(5))

instead of

    uart = UART(1, tx=4, rx=5)

which is consistent with other ports.  Since this handling is done at a
single place in the code, extending that scheme to accept strings for named
pins is easy.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20 17:33:04 +10:00
robert-hh
3819ee4a6f esp32/machine_pin: Add a pin-find func and use it in machine_pin_get_id.
The new machine_pin_find() function accepts a Pin object and a integer
object as input and returns a pin object.  That can be extended later to
accept a string object, once named pins are supported.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20 17:31:38 +10:00
robert-hh
c02da6d81d rp2/machine_pin: Factor out pin-find code from machine_pin_make_new.
And use it in mp_hal_get_pin_obj() and machine_pin_make_new().  That way,
mp_hal_get_pin_obj() accepts both int and str objects as argument, allowing
use of a pin specifier instead of a pin object in the constructor of
devices which need a pin as parameter.

E.g. instead of

    uart = UART(0, tx=Pin(0), rx=Pin(1))

one can write:

    uart = UART(0, tx=0, rx=1)

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20 17:30:17 +10:00
Damien George
7d66ae603d esp32/machine_timer: Switch from legacy driver to timer HAL.
The legacy driver was deprecated in IDF v5, and crashes when the ISR
handler is called.  Instead of fixing the legacy code, this commit reworks
the machine.Timer class to use the low-level HAL driver.

Tested on ESP32, ESP32S2, ESP32S3 and ESP32C3.  Behaviour is the same as it
was before this commit, except the way the Timer object is printed, it now
gives more useful information (timer id, mode, period in ms).

Fixes issue #11970.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-14 10:02:42 +10:00
Nicholas H.Tollervey
14c2b64131 webassembly: Replace typeof window check with ENVIRONMENT_IS_NODE flag.
When the "typeof window" check is run within a web worker the window is
undefined, causing an error because "require" is only defined in a Node
environment.  Change the logic to reflect the true intentions of when this
code should run, ie in Node only.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-13 13:24:35 +10:00
Damien George
88771c1500 renesas-ra,stm32: Remove duplicate machine module from constants list.
In the u-module renaming done in 30628d1bb7,
these duplicate lines were accidentally left.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-13 13:18:09 +10:00
Damien George
62673a7708 stm32/mpconfigport: Always define MICROPY_SOFT_TIMER_TICKS_MS.
Even if MICROPY_PY_MACHINE is disabled, the soft timer is still used.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-13 13:10:31 +10:00
Victor Rajewski
730525cec9 stm32/qspi: Allow qspi_write_cmd_data to write cmd with 1 data byte.
The existing qspi for stm32 implementation can only send a spi command with
exactly 0 or 2 data bytes.  Certain spiflash chips (e.g. AT25SF321B) have
commands that only take a single data byte, and will ignore the command if
more than that is sent.  This commit allows sending a command with a single
data byte.

Signed-off-by: Victor Rajewski <victor@allumeenergy.com.au>
2023-07-13 12:49:51 +10:00
Yuuki NAGAO
409978a1fb stm32/adc: Fix pyb.ADCAll.read_core_bat on G4 and L4 MCUs.
Update adc_refcor before reading ADC_CHANNEL_VBAT because VREFINT_CAL is at
VDDA=3.0V.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:40:55 +10:00
Yuuki NAGAO
cb38f77918 stm32/adc: Add workaround for ADC errata with G4 MCUs.
For STM32G4, there is a errata on ADC that may get wrong ADC result.
According to the errata sheet, this can be avoid by performing two
consecutive ADC conversions and keep second result.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:40:52 +10:00
Yuuki NAGAO
0a31b9bf78 stm32/machine_adc: Fix machine.ADC to work on G4 MCUs.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:12 +10:00
Yuuki NAGAO
d9764ad140 stm32/adc: Fix reading internal ADC channels on G4 MCUs.
For STM32G4 series, the internal sensors are connected to:
- ADC1_IN16: Temperature sensor
- ADC1_IN17: Battery voltage monitoring
- ADC1_IN18: Internal voltage reference
but ADC_CHANNEL_TEMPSENSOR_ADC1, ADC_CHANNEL_VBAT,
ADC_CHANNEL_VREFINT are not defined as 16, 17, 18.

This commit converts channel 16, 17, 18 to ADC_CHANNEL_x in
adc_get_internal_channel().

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:12 +10:00
Yuuki NAGAO
0ba94a67ba stm32/adc: Fix pyb.ADCAll.read_core_temp for G4 MCUs.
For STM32G4,
 * TS_CAL1 raw data acquired at a temperature of 30°C
 * TS_CAL2 raw data acquired at a temperature of 130°C
Also, these values are at VDDA=3.0V.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:06 +10:00
Yuuki NAGAO
de8035b510 stm32/adc: Fix ADC clock prescaler for G4 MCUs.
For STM32G4, ADC clock frequency should be equal or less than 60MHz.
To satisfy this specification, ADC clock prescaler should be equal or
greater than 4 (For example, NUCLEO_G474RE runs 170MHz).

In addition, to obtain accurate internal channel value,
the ADC clock prescaler is set to 16 because vbat needs at least 12us
(16/170*247.5=23.3us).

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:01 +10:00
Yuuki NAGAO
ec9ea97413 stm32/dac: Fix dac.write_timed on G4 MCUs to use 32-bit DMA access.
For STMG4 MCUs, the peripheral registers for DAC have to be accessed by
words (32bits) because DAC is connected to AHB directly.

(This requirement is also there for other MCU series.  However, if DAC is
connected to APB like F4/L1/L4 MCUs, AHB byte or half-word transfer is
changed into a 32-bit APB transfer.  This means that PSIZE does not have to
be DMA_PDATAALIGN_WORD on these MCUs, and in fact must be BYTE/HALFWORD to
function correctly.)

Fixes issue #9563.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:23:34 +10:00
Glenn Moloney
dbced75b48 esp32/network_wlan: Wait for STA/AP START/STOP event in wlan.active.
This is a fix for commit bccbaa92b1:
- Should only wait for WIFI_EVENT_STA_START when invoked on the STA_IF
  interface.
- The WIFI_EVENT_STA_START event is generated every time the STA_IF
  interface is set active(True) and it was previously inactive, ie. not
  only after calling esp_wifi_start().
- Also wait for WIFI_EVENT_STA_STOP when deactivating the interface.
- Also wait for relevant AP events.

Fixes issue #11910.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2023-07-13 11:49:14 +10:00
Damien George
2c67671651 esp32/boards/GENERIC_OTA: Enable silent checks to reduce firmware size.
Enabling mDNS put this firmware over the limit of the OTA partition size,
so tweak the compiler settings to reduce the firmware size.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-12 00:12:13 +10:00
Carlosgg
1f35576a69 esp32: Re-enable mDNS after move to IDF v5.0.2.
mDNS was disabled in e4650125b8.  This commit
re-enables it.

For reference see:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/release-5.x/5.0/removed-components.html

Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-07-11 15:58:15 +10:00
Damien George
7bced2eaec stm32/modmachine: Make machine_reset_cause_obj public.
To match the other functions in the machine module, in particular so that
MICROPY_PY_MACHINE can be disabled without getting a compiler warning about
unused code.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-11 13:45:53 +10:00
Tobias Thyrrestrup
dd8de8b412 stm32/modmachine: Remove duplicate machine_timer_type declaration.
Signed-off-by: Tobias Thyrrestrup <tt@LEGO.com>
2023-07-11 12:34:51 +10:00
Yuuki NAGAO
a2c02014cd stm32: Modify RCC->APB2ENR directly instead of HAL API.
Also, it is needed only when USB is enabled.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-06-27 22:28:31 +09:00
Yuuki NAGAO
7ca3c1d892 stm32: Add USB support for STM32L1 MCUs.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-06-27 22:28:31 +09:00
elibdev
813d559bc0 webassembly: Make mp_js_process_char asynchronous.
This may also call the garbage collector.

Signed-off-by: Eli Bierman <eli@elib.dev>
2023-06-27 15:27:29 +10:00
elibdev
b2ad7e238b webassembly: Make mp_js_do_str asynchronous.
This fixes a bug where `gc.collect()` would crash due to
emscripten_scan_stack being called synchronously within mp_js_do_str.  The
fix is to make mp_js_do_str asynchronous.

Fixes #10692.

Signed-off-by: Eli Bierman <eli@elib.dev>
2023-06-27 15:26:42 +10:00
robert-hh
0e215a9fba samd/mpconfigport: Provide the platform module.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-27 14:58:44 +10:00
robert-hh
057f3b0020 samd/mpconfigport: Enable DHT and onewire drivers on all MCUs/boards.
And move the setting to the samd-generic files, now that both samd21
and samd51 support it.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-27 14:58:07 +10:00
robert-hh
5ef7ce5116 samd/Makefile: Print memory region usage instead of totals.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-27 14:58:07 +10:00
robert-hh
cfaa9a4997 samd/Makefile: Move the math lib files from mpconfigmcu.mk to Makefile.
They are used by both SAMD21 and SAMD51.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-27 14:58:07 +10:00
robert-hh
909fe30dfd samd: Set the LFS type in mpconfigmcu.mk instead of mpconfigboard.mk.
SAMD21: set the filesystem type to LFS1.

SAMD51: the type is already set to LFS2, support is now dropped for LFS1.
It has not been used and dropping it saves 10 k of flash.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-27 14:57:41 +10:00
Damien George
5a9a0df340 esp32/machine_uart: Always select a source_clk value in UART config.
Fixes issue #11872.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-27 13:05:33 +10:00
mbedNoobNinja
761d86ae56 renesas-ra/boards/VK_RA6M5: Add new board definition.
Signed-off-by: mbedNoobNinja <novoltage@gmail.com>
2023-06-27 12:35:39 +10:00
mbedNoobNinja
fae96b17a7 renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard.
This commit adds support for a new processor RA6M5.  It also adds the
following classes to the machine module: PWM, DAC, SDCard.

Signed-off-by: mbedNoobNinja <novoltage@gmail.com>
2023-06-27 12:30:25 +10:00
Takeo Takahashi
92c7532d8e renesas-ra: Support changing baudrate for UART.
* Use R_SCI_UART_BaudCalculate() of fsp/src/r_sci_uart/r_sci_uart.c
* Support UART.init(baudrate)

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-06-26 22:04:39 +10:00
Damien George
c2ea8b2f98 renesas-ra: Consolidate all fsp_cfg header files to one location.
The config header files with the same name have the same contents, so they
don't need to be repeated for each board in the board's source directory.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-25 16:14:28 +10:00
Wind-stormger
23fe170da4 esp32/modules/inisetup.py: Format partition as FAT if its label is ffat.
Signed-off-by: Wind-stormger <storm-wind@foxmail.com>
2023-06-25 16:09:46 +10:00
Damien George
2ede7c6c21 esp32/boards: Change SDK config parameters from deprecated to new ones.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-24 18:20:56 +10:00
Damien George
717060447f esp32/Makefile: Provide more IDF shortcuts.
And change erase_flash to erase-flash, because the former is deprecated
since IDF 4.4.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-23 15:34:37 +10:00
Damien George
bccbaa92b1 esp32/network_wlan: Wait for WIFI_EVENT_STA_START after activating.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-23 15:34:37 +10:00
Glenn Moloney
2cc3711e5e esp32: In recv_cb, get espnow rssi from recv_info->rx_ctrl.
IDF v5.0 provides access to rssi value for received espnow packets via
recv_info arg to recv_cb().

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2023-06-23 15:34:22 +10:00
Damien George
e4650125b8 esp32: Update port to support IDF v5.0.2.
This commit updates the esp32 port to work exclusively with ESP-IDF v5.
IDF v5 is needed for some of the newer ESP32 SoCs to work, and it also
cleans up a lot of the inconsistencies between existing SoCs (eg S2, S3,
and C3).

Support for IDF v4 is dropped because it's a lot of effort to maintain both
versions at the same time.

The following components have been verified to work on the various SoCs:

                ESP32     ESP32-S2  ESP32-S3  ESP32-C3
    build       pass      pass      pass      pass
    SPIRAM      pass      pass      pass      N/A
    REPL (UART) pass      pass      pass      pass
    REPL (USB)  N/A       pass      pass      N/A
    filesystem  pass      pass      pass      pass
    GPIO        pass      pass      pass      pass
    SPI         pass      pass      pass      pass
    I2C         pass      pass      pass      pass
    PWM         pass      pass      pass      pass
    ADC         pass      pass      pass      pass
    WiFi STA    pass      pass      pass      pass
    WiFi AP     pass      pass      pass      pass
    BLE         pass      N/A       pass      pass
    ETH         pass      --        --        --
    PPP         pass      pass      pass      --
    sockets     pass      pass      pass      pass
    SSL         pass      ENOMEM    pass      pass
    RMT         pass      pass      pass      pass
    NeoPixel    pass      pass      pass      pass
    I2S         pass      pass      pass      N/A
    ESPNow      pass      pass      pass      pass
    ULP-FSM     pass      pass      pass      N/A
    SDCard      pass      N/A       N/A       pass
    WDT         pass      pass      pass      pass

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-23 15:34:22 +10:00
Damien George
2af229c3cc esp32/modesp32: Remove esp32.hall_sensor function.
The hall sensor is no longer supported by IDF v5.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-23 15:34:22 +10:00
Damien George
1db40ed295 esp32/ppp_set_auth: Add pppapi_set_auth from ESP-IDF.
This function was made private/static in IDF commit
c67f4c2b4c2bb4b7740f988fc0f8a3e911e56afe, so it add back here.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-23 15:34:22 +10:00
Angus Gratton
7c929d4478 esp32: Switch from UART driver to UART HAL.
Allows registering UART interrupt again.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-06-23 15:34:22 +10:00
Jim Mussared
7979a4d267 ports: In machine_i2s.c, rename uasyncio to asyncio.
Mostly updates comments, but also renames the UASYNCIO enum value to
ASYNCIO.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-19 18:36:54 +10:00
Jim Mussared
2fbc08c462 extmod/asyncio: Rename uasyncio to asyncio.
The asyncio module now has much better CPython compatibility and
deserves to be just called "asyncio".

This will avoid people having to write `from uasyncio import asyncio`.

Renames all files, and updates port manifests to use the new path. Also
renames the built-in _uasyncio to _asyncio.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-19 17:33:03 +10:00
Damien George
47dc7d0130 esp32,esp8266: Allow Ctrl-C to interrupt the corrupt-fs while loop.
Commit c046b23ea2 prevented frozen boot code
from being interrupted by Ctrl-C, but that means a corrupt filesystem will
forever lock up an esp32/esp8266 board.  This commit fixes that by
explicitly enabling Ctrl-C before running the forever loop.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 12:19:57 +10:00
Damien George
6f74146bc1 stm32/boards/STM32H573I_DK: Add H5 board definition files.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:37 +10:00
Damien George
56a22ddc8b stm32/octospi: Add preliminary support for OCTOSPI peripheral.
It currently operates in 1-line (SPI) mode only.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:37 +10:00
Damien George
ec4232b32e stm32/boards: Add ld, af.csv and hal_conf_base.h files for H5 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:37 +10:00
Damien George
61339aa506 stm32: Add initial support for H5 MCUs.
This commit adds initial support for STM32H5xx MCUs.  The following
features have been confirmed to be working on an STM32H573:
- UART over REPL and USB CDC
- USB CDC and MSC
- internal flash filesystem
- machine.Pin
- machine.SPI transfers with DMA
- machine.ADC
- machine.RTC
- pyb.LED
- pyb.Switch
- pyb.rng
- mboot

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:20 +10:00
Damien George
f7f8332ddf stm32/machine_adc: Handle ADC resolution less than 8 bits on all MCUs.
All MCUs can have 6-bit resolution; see adc_cr_to_bits_table.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:55 +10:00
Damien George
92d2de82e2 stm32/usbd_conf: Treat G0 USB periph as MICROPY_HW_USB_IS_MULTI_OTG=0.
The G0 USB peripheral behaves more like MICROPY_HW_USB_IS_MULTI_OTG=0 than
that config =1.  This fixes the configuration of the PMA FIFO buffers.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:53 +10:00
Damien George
b839acc7d9 stm32/main: Start UART REPL as early as possible.
For debugging purposes, to see output from other peripherals.

Also reset the pyb_stdio_uart state at the end of soft reset, in case it
points to a heap-allocated object.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:49 +10:00
Damien George
fb1bdf0ff2 stm32/make-stmconst.py: Support structs with names ending in _t.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:41 +10:00
Damien George
68b09abc45 stm32/Makefile: Pass relevant CPU flags to assembler.
Needed for compiling gchelper_thumb2 on cortex-m33.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:34 +10:00
Peter Harper
856e08b193 rp2/boards/PICO_W: Enable Bluetooth Low Energy support.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 22:20:20 +10:00
Peter Harper
a459eaf3e6 rp2/mpbthciport: Cancel existing alarms.
Cancel any existing poll alarm before add a new one.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 22:20:20 +10:00
Peter Harper
888a15cda3 rp2: Add Bluetooth support via cyw43.
Using BTstack with CYW43 for Pico W.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 22:20:20 +10:00
Wilko Nienhaus
034502bc72 esp32/esp32_ulp: Fix ULP (FSM) support for S2 and S3.
This change enables the ULP (FSM) for all ESP32 variants rather than
requiring it to be enabled for each board specifically.

It also ensures the correct header file is included for each variant.

Lastly, it updates the IDF version we're builing against to v4.4.2, as that
version contains important fixes to make the ULP actually work on S2/S3
chips. See: https://github.com/espressif/esp-idf/commit/a0e3d48

Signed-off-by: Wilko Nienhaus <wilko.nienhaus@gmail.com>
2023-06-14 16:41:03 +10:00
Brian 'redbeard' Harrington
ea8f0fd896 rp2/CMake: Normalize MICROPY_PORT_DIR.
In 5fe2a3f1 the ESP32 port underwent a change to how `MICROPY_PORT_DIR`
is defined.  This commit normalizes the `rp2` port to use the same
underlying variable mechanism (`CMAKE_CURRENT_LIST_DIR`).

Signed-off-by: Brian 'redbeard' Harrington <redbeard@dead-city.org>
2023-06-13 00:11:06 -07:00
Brian 'redbeard' Harrington
5fe2a3f14f esp32/CMake: Change PROJECT_DIR to CMAKE_CURRENT_LIST_DIR.
This migrates the CMake variable `MICROPY_PORT_DIR` from the ESP-IDF
defined project to the component. Previously used instances of the variable
within the project definition have been migrated to
`CMAKE_CURRENT_LIST_DIR`. Within the component (the `main` subdirectory in
the ESP32 port) we define `MICROPY_PORT_DIR` using `CMAKE_CURRENT_LIST_DIR`
and subsequently use the `MICROPY_PORT_DIR` value in all locations where
`PROJECT` had previously been used.

Context:

In commit 9b90882146, initial support was added for building with the newly
introduced CMake support provided by the ESP-IDF.

Specifically, the commit message states:

> This commit adds support for building the esp32 port with CMake, and in
particular, it builds MicroPython as a component within the ESP-IDF. Using
CMake and the ESP-IDF build infrastructure makes it much easier to maintain
the port, especially with the various new ESP32 MCUs and their required
toolchains.

`PROJECT_DIR` is a variable populated by the ESP-IDF specifically and is
not stable when used with "[Pure CMake components][1]" as documented in the
ESP-IDF. It is intended to be used in the scope of the parent of the
current file (the "project") as opposed to the current file ("the
component"). Crossing into the parent scope like this works solely when the
"project" is MicroPython, but not when used as a component by other ESP-IDF
projects.

Analyzing this file, the intention is to reference the "Project" which in
the example is the parent directory. Within the [CMake variables][2]
documentation, there is one specifically defined for referencing the
directory for the CMake listfile currently being processed:
[`CMAKE_CURRENT_LIST_DIR`][3].

After making the change from `PROJECT_DIR` to `CMAKE_CURRENT_LIST_DIR`, the
reach into the parent scope defined by the ESP-IDF and the resulting CMake
interface violation is removed.

Similar to the component definition, the project `CMakeLists.txt` uses the
variable `CMAKE_SOURCE_DIR` which CMake defines as "The path to the top
level of the source tree."  This commit changes the variable to
`CMAKE_CURRENT_LIST_DIR` for the reasons cited above.

[1]: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/build-system.html#writing-pure-cmake-components
[2]: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html
[3]: https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_LIST_DIR.html

Signed-off-by: Brian 'redbeard' Harrington <redbeard@dead-city.org>
2023-06-13 00:11:05 -07:00
Glenn Moloney
fd277704c4 esp32/modespnow: Change name of buffer size config option to "rxbuf".
Rename "buffer" option to "rxbuf" which accords with docs and esp8266.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2023-06-10 12:16:26 +10:00
Damien George
f01d5fb657 py/mkrules.mk: Automatically configure frozen options when manifest set.
Following how mkrules.cmake works.  This makes it easy for a port to enable
frozen code, by defining FROZEN_MANIFEST in its Makefile.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-08 23:12:56 +10:00
Damien George
30100e9b3d stm32/boards: Use default spibdev config where appropriate.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-08 23:01:03 +10:00
Damien George
3b370157d0 stm32/mpconfigboard_common: Provide default spidev config.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-08 23:01:03 +10:00
Jim Mussared
a1fbb1980c extmod/modtimeq: Remove timeq module.
This is a MicroPython-specific module that existed to support the old
version of uasyncio.  It's undocumented and not enabled on all ports and
takes up code size unnecessarily.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:28 +10:00
Jim Mussared
5fd042e7d1 all: Replace all uses of umodule in Python code.
Applies to drivers/examples/extmod/port-modules/tools.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared
4216bc7d13 tests: Replace umodule with module everywhere.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared
5e50975a6d py/modsys: Allow sys.path to be assigned to.
Previously sys.path could be modified by append/pop or slice assignment.

This allows `sys.path = [...]`, which can be simpler in many cases, but
also improves CPython compatibility.

It also allows sys.path to be set to a tuple which means that you can
clear sys.path (e.g. temporarily) with no allocations.

This also makes sys.path (and sys.argv for consistency) able to be disabled
via mpconfig. The unix port (and upytesthelper) require them, so they
explicitly verify that they're enabled.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared
7d2ee8aed0 py/mpconfig: Enable module delegation if sys needs it.
Otherwise you can get into the confusing state where e.g. sys.ps1 is
enabled in config (via `MICROPY_PY_SYS_PS1_PS2`) but still doesn't actually
get enabled.

Also verify that the required delegation options are enabled in modsys.c.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared
2eba98f1e0 all: Use MP_REGISTER_EXTENSIBLE_MODULE for overrideable built-ins.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:21 +10:00
Jim Mussared
45ac651d1a all: Rename *umodule*.c to remove the "u" prefix.
Updates any includes, and references from Makefiles/CMake.

This essentially reverts what was done long ago in commit
136b5cbd76

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:17 +10:00
Jim Mussared
0ceccd4cf8 all: Rename *umodule*.h to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Also updates #includes.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:14 +10:00
Jim Mussared
f5f9edf645 all: Rename UMODULE to MODULE in preprocessor/Makefile vars.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:11 +10:00
Jim Mussared
7f5d5c7271 all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:07 +10:00
Jim Mussared
1bf2dcb15e all: Rename mp_umodule*, mp_module_umodule* to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:04 +10:00
Jim Mussared
dfe232d000 py/builtinimport: Remove weak links.
In order to keep "import umodule" working, the existing mechanism is
replaced with a simple fallback to drop the "u".

This makes importing of built-ins no longer touch the filesystem, which
makes a typical built-in import take ~0.15ms rather than 3-5ms.

(Weak links were added in c14a81662c)

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:04 +10:00
Jim Mussared
30628d1bb7 all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.
This renames the builtin-modules, such that help('modules') and printing
the module object will show "module" rather than "umodule".

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:53:57 +10:00
robert-hh
db5444f68a samd/boards: Extend the code size limit for boards with external flash.
Code size limits are charged to:
- SAMD21:    184K -> 248K
- SAMD51x19: 368K -> 496K
- SAMD51x20: 368K -> 1008K

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-06 00:49:36 +10:00
robert-hh
69cb5e8f2a samd: Adapt existing samd.Flash and integrate with (Q)SPI flash in boot.
Checks are added to ensure, that only one of the flash drivers is selected.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-06 00:49:36 +10:00
robert-hh
2b5a5a0f35 samd/samd_qspiflash: Add QSPI flash driver and configure it accordingly.
The QSPI driver provides the interface for using an on-board QSPI flash for
the filesystem.  It provides the same methods as the driver for the
internal flash and uses the same name.  Therefore, only one of the drivers
for internal flash, SPI flash and QSPI flash must be enabled at a time.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-06 00:49:36 +10:00
robert-hh
5561130c3f samd/samd_spiflash: Add SPI flash driver and configure it accordingly.
The SPI flash driver includes the block device for being used as a
filesystem.  It provides the same methods as the driver for the internal
flash.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-06 00:49:36 +10:00
robert-hh
bf7d3ad8c6 samd/boards: Rename flash pins consistently for QSPI and SPI.
For SAMD21 devices, the board flash signals must be named in pins.csv as
FLASH_MOSI, FLASH_MISO, FLASH_SCK, FLASH_CS for creating the SPI object.

And rename the QSPI pins to QSPI_xxxx instead of FLASH_xxx.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-06 00:42:33 +10:00
Damien George
e4886dda85 stm32/help: Exclude legacy entries from help, and adjust constant names.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-02 12:43:58 +10:00
Jim Mussared
aac8744671 stm32/help: Don't include unavailable features in help().
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-02 11:49:13 +10:00
Jim Mussared
1d4b4f0ce2 ports: Standardise docs link in help text.
Updates all `help()` output to use the phrase:
`For online docs please visit http://docs.micropython.org/`

Some ports previously used different wording, some pointed to the wrong
link.  Also make all ports use `help.c` for consistency.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-02 11:48:46 +10:00
Jim Mussared
952a78f88a unix/main: Add NLR scope for checking module __path__.
If the module has a user-defined getattr, this could raise.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01 16:21:37 +10:00
Jim Mussared
525557738c py/builtinimport: Optimise sub-package loading.
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 a7fa18c203
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-01 16:21:21 +10:00
Takeo Takahashi
1f60841123 renesas-ra/boards/make-pins.py: Fix PA/PB pins support.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-06-01 13:00:24 +10:00
robert-hh
6c0af30e38 mimxrt/Makefile: Use a specific fsl_flexspi_nor_boot.c for mimxrt1062.
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
8e54225140 but got lost when the MIMXRT1176
board was added.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01 12:38:17 +10:00
robert-hh
8f6315a279 mimxrt/machine_pwm: Fix freq change, PWM print, and error checks.
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-01 12:25:34 +10:00
robert-hh
73cc6b750e ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51.
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-01 11:39:01 +10:00
robert-hh
1c53bda27f ports: Remove os.sync() implementation from stm32 and renesas-ra.
Now that this code was moved to extmod/moduos.c.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01 11:39:01 +10:00
Damien George
324d01eb52 renesas-ra: Consolidate hal_entry.c code and remove hal_entry() func.
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-24 11:44:17 +10:00
Damien George
b57b079bbe stm32/boards/NUCLEO_L4A6ZG: Add new board definition.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-24 11:25:53 +10:00
Damien George
87cf439e0d stm32/adc: Add support for STM32L4A6 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-24 11:25:50 +10:00
Jim Mussared
0ba08e6299 stm32/boards/NUCLEO_G474RE: Make it easier to enable USB.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-24 11:13:23 +10:00
Jim Mussared
f4b4d05e49 stm32/usb: Fix USB support on STM32G4.
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-24 11:12:45 +10:00
robert-hh
5707fd74e5 mimxrt/boards/ADAFRUIT_METRO_M7: Add Adafruit Metro M7 board definition.
Support for WiFi and BLE is in progress.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-23 16:54:39 +10:00
iabdalkader
8d446b2ad5 mimxrt/led: Add support for up to four LEDs.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-23 10:54:23 +10:00
Yilin Sun
0f0dcec984 mimxrt/sdcard: Fix GCC 13 build error with sdcard_cmd_set_bus_width.
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-23 10:38:13 +10:00
robert-hh
c3f031afac samd/boards/ADAFRUIT_METRO_M4_EXPRESS: Add Metro M4 Express Airlift.
The board files can be used for both Adafruit Metro M4 variants.  The Wifi
support is in progress.
2023-05-23 10:17:16 +10:00
robert-hh
20fd22edad samd/machine_uart: Add support for UART hardware flow control.
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-23 09:53:24 +10:00
robert-hh
2a38531d73 samd/mcu: Reduce the startup time after hard reset.
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-22 18:41:48 +10:00
robert-hh
984456731b samd/boards/SEEED_WIO_TERMINAL: Rename two pins starting with a digit.
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-22 18:40:23 +10:00
robert-hh
47fa723586 samd/modmachine: Make some machine classes configurable by #defines.
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-22 18:39:07 +10:00
robert-hh
b2df094bf8 samd/modmachine: Add machine.deepsleep as alias of machine.lightsleep.
Just for coverage.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:38:51 +10:00
robert-hh
7a847bab1e samd/main: Fix sercom deinit ordering in soft-reset.
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-22 18:37:35 +10:00
robert-hh
b7180d53f0 samd/boards: Add default deploy instructions.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:37:24 +10:00
robert-hh
05e684dc07 samd/mcu/samd51: Enable MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:37:11 +10:00
robert-hh
315eb949da samd: Rearrange the MCU-specific loader files.
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-22 18:36:29 +10:00
robert-hh
457d9ee68a samd/boards/MINISAM_M4: Update pins.csv for the Mini SAM M4 board.
Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:36:07 +10:00
robert-hh
267d1ab2ba samd/mpconfigport: Drop support for SoftSPI max speed.
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-22 18:35:45 +10:00
patrick
a802f71908 esp32/uart: Use xtal as UART clock source on S3 and C3.
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-22 10:11:24 +10:00
patrick
05e143dbdd esp32/esp32_ulp: Enable FSM ULP for S2 and S3 chips.
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-19 22:37:25 +10:00
UnexpectedMaker
3a7ad64267 esp32/boards: Add some missing board configs for two UM boards. 2023-05-19 22:30:42 +10:00
iabdalkader
bfcaf39197 stm32/irq: Fix typo in comment about priorities.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-19 22:23:33 +10:00
iabdalkader
70b60fe24e renesas-ra/irq: Fix typo in comment about IRQ priorities.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-19 22:23:10 +10:00
Andrew Leech
f03ac04321 stm32/mboot: Fix alignment of packed final buffer.
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-19 22:16:53 +10:00
brave ulysses
ad216be5f1 stm32/boards/stm32h723_af.csv: Fix ADC AF definitions.
These were incorrectly added in d995c01042.
The fix here includes the full differential ADC definitions.

Signed-off-by: brave ulysses <brave_ulysses@email.com>
2023-05-19 22:12:05 +10:00
Damien George
53cb073571 esp32,esp8266: Change network.WLAN from a function to a type.
When the network module was first introduced in the esp8266 port in
ee3fec3167 there was only one interface (STA)
and, to save flash, the WLAN object was aliased to the network module,
which had just static methods for WLAN operations.  This was subsequently
changed in 9e8396accb when the AP interface
was introduced, and the WLAN object became a true class.

But, network.WLAN remained a function that returned either the STA or AP
object and was never upgraded to the type itself.  This scheme was then
copied over to the esp32 port when it was first introduced.

This commit changes network.WLAN from a function to a reference to the WLAN
type.  This makes it consistent with other ports and network objects, and
allows accessing constants of network.WLAN without creating an instance.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-18 14:52:28 +10:00
Ondrej Wisniewski
29401a719f rp2/mphalport: Only use CYW43 MAC for WLAN0 interface.
Building the Pico-W needs the MICROPY_PY_NETWORK_CYW43 flag to be set in
order to include building the CYW43 Wifi driver.  But then mp_hal_get_mac()
handles the MAC assignment for all nics the "CYW43 way", copying the real
MAC provided by the WiFi hardware.  This will fail for all other NIC types,
resulting in an invalid MAC address.

The solution in this commit is to add a check for the NIC type parameter
idx and handle the MAC address respectively.
2023-05-18 13:06:06 +10:00
Phil Howard
4ce360fa83 rp2/CMakeLists: Allow relative MICROPY_BOARD_DIR when invoking cmake.
Convert to an absolute path to always reliably locate manifest.py.  This is
already done in Makefile, but is also needed in CMakeLists.txt if cmake is
invoked directly.

Signed-off-by: Phil Howard <phil@pimoroni.com>
2023-05-18 12:51:36 +10:00
Adam Green
f9958417d8 rp2: Make rp2_state_machine_exec accept integers.
Currently rp2.StateMachine.exec(instr_in) requires that the instr_in
parameter be a string representing the PIO assembly language instruction
to be encoded by rp2.asm_pio_encode(). This commit allows the parameter
to also be of integral type. This is useful if the exec() method is
being called often where the use of pre-encoded machine code is
desireable.

This commit still supports calls like:
    sm.exec("set(0, 1)")

It also now supports calls like:
    # Performed once earlier, maybe in __init__()
    assembled_instr = rp2.asm_pio_encode("out(y, 8)", 0)
    # Performed multiple times later as the PIO state machine is
    # configured for its next run.
    sm.exec(assembled_instr)

The existing examples/rp2/pio_exec.py and examples/rp2/pio_pwm.py that
exercise the rp2.StateMachine.exec() method still work with this change.

Signed-off-by: Adam Green <adamgrym@yahoo.com>
2023-05-18 12:33:02 +10:00
Takeo Takahashi
3229791b60 renesas-ra: Add a macro definition to avoid compile error of FSP v4.4.0.
FSP v4.4.0 refers to CMSIS V5.4.1, and __COMPILER_BARRIER() is used in bsp.
On the other hand, lib/cmsis is V5.1.0 and the macro is not defined.
Therefore, compile error happens.
As the workaround, the macro definition is added.
If lib/cmsis is updated in the future, this addition can be removed.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-05-11 16:18:39 +10:00
Takeo Takahashi
b4834e5cba renesas-ra: Update boards and ra directory files to support FSP v4.4.0.
* Update boards and ra files
* Remove unreferenced files, board_init.c and board_leds.c, from Makefile
* Remove unreferenced FSP instances from ra_gen/*.[ch]
* Remove unreferenced FSP config files ra_cfg/*.h
* e2 studio generates FSP instances but renesas-ra uses only followings:
  lpm, flash, ioport

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-05-11 16:18:39 +10:00
David Lechner
6a4a9bc147 windows/Makefile: Allow variants to add QSTR_DEFS.
This modifies the windows port Makefile to use += for QSTR_DEFS and
QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if
needed (similar to stm32 port).

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-11 14:34:15 +10:00
David Lechner
6836acf3dc unix/Makefile: Allow variants to add QSTR_DEFS.
This modifies the unix port Makefile to use += for QSTR_DEFS and
QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if
needed (similar to stm32 port).

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-11 14:34:01 +10:00
robert-hh
65d376b11d mimxrt/machine_pin: Perform full configuration in machine_pin_set_mode.
machine_pin_set_mode() is used by the internal mp_hal_pin_xxx() set of
functions to configure pins.
2023-05-09 16:15:05 +10:00
robert-hh
14b862f70f mimxrt/machine_spi: Ignore transfers with len=0.
It was treated as an error before.  The error surfaced when using the
NINAW10 drivers for WiFi support.  Even if this is a bad behavior of the
NINA driver, machine_spi can be forgiving in that situation.
2023-05-09 16:14:40 +10:00
robert-hh
d2a02dcee3 mimxrt: Add missing UART defintion and remove obsolete config.
Changes in this commit:
- Add a missing UART defintion for MIMXRT1010_EVK.
- Remove an obsolete line from mpconfigport.h.
2023-05-09 16:13:51 +10:00
robert-hh
facc51f3ea mimxrt/mpconfigport: Add back lost uos.urandom().
It got lost in a clean-up session recently.
2023-05-09 16:13:27 +10:00
Philipp Ebensberger
a3f3b9045c mimxrt/flash: Separate low level driver code from flash object.
Separate low level flash access from mimxrt flash driver object.  Allows
better abstraction from hardware for testing and reuse in other areas (e.g.
bootloader).

Signed-off-by: Philipp Ebensberger <philipp.ebensberger@3bricks-software.de>
2023-05-09 15:18:36 +10:00
Jim Lipsey
7333c06d05 stm32/boards/ARDUINO_PORTENTA_H7: Enable FDCAN.
Add pin definitions to enable FDCAN support using the pyb.CAN() class.
2023-05-09 13:25:03 +10:00
glenn20
1093dea709 esp32,esp8266: Add support to set/get power saving mode of WLAN.
For esp32 and esp8266 this commit adds:
- a 'pm' option to WLAN.config() to set/get the wifi power saving mode; and
- PM_NONE, PM_PERFORMANCE and PM_POWERSAVE constants to the WLAN class.

This API should be general enough to use with all WLAN drivers.

Documentation is also added.
2023-05-06 13:51:00 +10:00
Damien George
38243cd8e0 extmod/machine_pwm: Remove PWM_INIT and PWM_DUTY_U16_NS config options.
All ports that enable MICROPY_PY_MACHINE_PWM now enable these two
sub-options, so remove these sub-options altogether to force consistency in
new ports that implement machine.PWM.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-04 13:19:19 +10:00
robert-hh
7952694a3c rp2/machine_pwm: Add duty_x() checks and return 0 if PWM is not started.
Changes in this commit:
- Limit duty_u16() to 65535 and duty_ns() to the period duration.
- Return 0 for pwm.freq() if the frequency has not been set yet.
- Return 0 for pwm.duty_us16() and duty_ns() unless both frequency and
  duty cycle have been set.
- Initialize the pin to PWM at the very end of the constructor, to avoid
  possible glitches on the pin when setting up the PWM.
2023-05-04 13:18:58 +10:00
robert-hh
0b3b508d1d rp2/machine_pwm: Add support for inverting a PWM channel output.
Using the invert=True|False keyword option with the constructor or init().
2023-05-04 13:18:47 +10:00
robert-hh
2ac643c15b esp8266/machine_pwm: Implement duty_u16() and duty_ns() for consistency.
Also adds these keyword arguments to the constructor and init method.
2023-05-04 13:17:55 +10:00
robert-hh
84302b2854 rp2/machine_pwm: Enable keyword args in constructor and add init method.
This adds support for freq/duty_u16/duty_ns keyword arguments in the PWM
constructor, and adds the PWM.init() method.  Using init() without
arguments enables a previously deinit-ed PWM again.

Further changes in this commit:
- Do not start PWM output if only duty was set.
- Stop all PWM slices on soft-reset.
- Fix a bug when changing the freq on a channel pair with duty_ns set.
2023-05-04 13:13:05 +10:00
robert-hh
250757716a samd/machine_pwm: Add init() method to PWM and simplify the PWM code.
The PWM.init() method has been added.  Calling init() without arguments
restarts a PWM channel stopped with deinit().  Otherwise single parameters
except for "device=n" can be changed again.  The device can only be
specified once, either in the constructor or the first init() call.

Also simplify get_pwm_config() and get_adc_config(), and shrink the PWM
object.
2023-05-04 13:10:38 +10:00
robert-hh
9c7ad68165 mimxrt/machine_pwm: Start PWM only if freq and duty are set.
And also fix/improve the following:
- Simplify the duty handling a little bit.
- Allow duty_u16(65536), which sets the output high.
- Rename machine_pwm_start() to mp_machine_pwm_start(), in preparation for
  a possible start/stop method pair.
2023-05-04 13:09:39 +10:00
Christian Clauss
2a1db770ce all: Fix cases of Python variable assigned but never used.
This fixes ruff rule F841.
2023-05-02 16:36:05 +10:00
Christian Clauss
79e57473b2 all: Fix various Python coding inconsistencies found by ruff.
This fixes:
- type-comparison (E721): do not compare types, use isinstance().
- string-dot-format-missing-arguments (F524): .format call is missing
  argument(s) for placeholder(s): {message}.
- f-string-missing-placeholders (F541).
- is-literal (F632): Use != to compare constant literals.

The last one is fixed by just comparing for truthfulness of `state`.
2023-05-02 16:14:45 +10:00
Christian Clauss
8f8bd98164 all: Fix strings with backslash by using raw string literals. 2023-05-02 11:55:02 +10:00
Glenn Moloney
7fa322afb8 esp32,esp8266: Add support for the Espressif ESP-NOW protocol.
ESP-NOW is a proprietary wireless communication protocol which supports
connectionless communication between ESP32 and ESP8266 devices, using
vendor specific WiFi frames.  This commit adds support for this protocol
through a new `espnow` module.

This commit builds on original work done by @nickzoic, @shawwwn and with
contributions from @zoland.  Features include:
- Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO.
- Signal strength (RSSI) monitoring.
- Core support in `_espnow` C module, extended by `espnow.py` module.
- Asyncio support via `aioespnow.py` module (separate to this commit).
- Docs provided at `docs/library/espnow.rst`.

Methods available in espnow.ESPNow class are:
- active(True/False)
- config(): set rx buffer size, read timeout and tx rate
- recv()/irecv()/recvinto() to read incoming messages from peers
- send() to send messages to peer devices
- any() to test if a message is ready to read
- irq() to set callback for received messages
- stats() returns transfer stats:
    (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts)
- add_peer(mac, ...) registers a peer before sending messages
- get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt)
- mod_peer(mac, ...) changes peer info parameters
- get_peers() returns all peer info tuples
- peers_table supports RSSI signal monitoring for received messages:
    {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...}

ESP8266 is a pared down version of the ESP32 ESPNow support due to code
size restrictions and differences in the low-level API.  See docs for
details.

Also included is a test suite in tests/multi_espnow.  This tests basic
espnow data transfer, multiple transfers, various message sizes, encrypted
messages (pmk and lmk), and asyncio support.

Initial work is from https://github.com/micropython/micropython/pull/4115.
Initial import of code is from:
https://github.com/nickzoic/micropython/tree/espnow-4115.
2023-05-01 16:47:21 +10:00
Carlosgg
b5f4611969 lib/mbedtls_errors: Add esp32-specific mbedtls error file.
This allows updating mp_mbedtls_errors.c for the other mbedtls based ports
based on mbedTLS v2.28.1.  This esp32-specific file will not be required
after updating IDF support to >= v4.4.1.

Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-05-01 10:50:01 +10:00
Damien George
b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Damien George
143b863f54 zephyr/modutime: Use extmod version of time module.
API change: time.time_ns() is added, but it just returns 0.

No API or functional change to existing time functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:52 +10:00
Damien George
fa8a81ae23 webassembly/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:52 +10:00
Damien George
127fd170c8 unix/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:52 +10:00
Damien George
996a1f911b stm32/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:52 +10:00
Damien George
d7cb53cb60 samd/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
67e917609f rp2/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
322c53bbc9 renesas-ra/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
a3c427898e nrf/modules/utime: Use extmod version of time module.
API additions;
- time.sleep() is added
- time.ticks_cpu() is added, but it just returns 0

No API or functional change to existing time functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
c234a26954 mimxrt/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
4a4046d825 esp8266/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
5be20b67df esp32/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
8ad2da93be cc3200/mods/modutime: Use extmod version of time module.
API change: time.time_ns() is added, but it just returns 0.

No API or functional change to existing time functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Damien George
9955553001 extmod/modutime: Provide a generic time module.
Based on extmod/utime_mphal.c, with:
- a globals dict added
- time.localtime wrapper added
- time.time wrapper added
- time.time_ns function added

New configuration options are added for this module:
- MICROPY_PY_UTIME (enabled at basic features level)
- MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME
- MICROPY_PY_UTIME_TIME_TIME_NS

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:09:56 +10:00
Damien George
083dc1f082 ports: Use extmod version of mktime instead of port-specific one.
Apart from slight differences in the error message, the functionality of
all ports is unchanged.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 14:55:07 +10:00
Takeo Takahashi
dc7de6ed83 renesas-ra: Change MICROPY_HW_BOARD_NAME definition to product name.
Changes in this commit:
- Change MICROPY_HW_BOARD_NAME definition to match the product name.
- Rename board folder's name to match the product name style.
- Change related files like Makefile, document descriptions, test cases, CI
  and tools.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-04-27 14:12:53 +10:00
Damien George
a14e79bcfb stm32/cyw43_configport: Provide cyw43_hal_pin_config_irq_falling func.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-26 12:57:35 +10:00
Damien George
fe4ac49d7f rp2/memmap_mp.ld: Allow a board to reserve memory for the C heap.
Since c80e7c14e6 changed the GC heap to use
all unused RAM, there is no longer any RAM available for the traditional C
heap (which is not used by default in MicroPython but may be used by C
extensions).  This commit adds a provision for a board to reserve RAM for
the C heap, by defining MICROPY_C_HEAP_SIZE.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-26 12:36:21 +10:00
IcedRooibos
7ea06a3e26 esp32/esp32_rmt: Fix looping behaviour for RMT on ESP32-S3.
The previous code worked on ESP32 but not ESP32-S3.  All the IDF (v4.4.3)
examples call rmt_set_tx_loop_mode before rmt_write_items, so make that
change here.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-26 12:32:13 +10:00
Jim Mussared
a42a8022d8 extmod/modbluetooth: Make all HCI transports trace in the same format.
- Use HCI_TRACE macro consistently.
 - Use the same colour formatting.
 - Add a tool to convert to .pcap for Wireshark.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Jim Mussared
256f47e2f8 extmod/btstack: Fix indicate/notify queuing.
This adds a mechanism to track a pending notify/indicate operation that
is deferred due to the send buffer being full. This uses a tracked alloc
that is passed as the content arg to the callback.

This replaces the previous mechanism that did this via the global pending
op queue, shared with client read/write ops.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Jim Mussared
bc9ec1cf71 extmod/modbluetooth: Merge gatts_notify/indicate implementation.
Makes gatts_notify and gatts_indicate work in the same way: by default they
send the DB value, but you can manually override the payload.

In other words, makes gatts_indicate work the same as gatts_notify.

Note: This removes support for queuing notifications and indications on
btstack when the ACL buffer is full. This functionality will be
reimplemented in a future commit.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Damien George
9e6885ad82 extmod/btstack: Switch to use hci_dump_init instead of hci_dump_open.
The latter is no longer available in the version of BTstack now in use by
this repository.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-22 00:39:31 +10:00
David (Pololu)
bf3eb9dc39 rp2/machine_i2c: Add timeout parameter for machine.I2C().
This commit adds support for the `timeout` keyword argument to machine.I2C
on the rp2 port, following how it's done on other ports.

The main motivation here is avoid the interpreter crashing due to infinite
loops when SDA is stuck low, which is quite common if the board gets reset
while reading from an I2C device.

A default timeout of 50ms is chosen because it's consistent with:
- Commit a707fe50b0 which used a timeout of
  50,000us for zero-length writes on the rp2 port.
- The machine.SoftI2C class which uses 50,000us as the default timeout.
- The stm32 port's hardware I2C, which uses 50,000us for
  I2C_POLL_DEFAULT_TIMEOUT_US.

This commit also fixes the default timeout on the esp32 port to be
consistent with the above, and updates the documentation for machine.I2C to
document this keyword argument.
2023-04-21 18:03:33 +10:00
iabdalkader
0acc73344a mimxrt: Fix the build for boards without ROM API. 2023-04-12 17:01:25 +02:00
iabdalkader
bde222ce84 mimxrt/modmachine: Implement machine.bootloader().
If a board defines a custom bootloader entry function it will be called
first, if not and the ROM API supports RUN bootloader API, then
`machine.bootloader()` will jump to the ROM serial downloader in USB mode.
2023-04-11 17:40:18 +10:00
iabdalkader
8b72721b29 mimxrt/mpconfigport: Allow configuring different network interfaces.
This commit allows boards to disable Ethernet and keep the networking stack
enabled, to use an alternate networking interface, such as WiFi.

Note that the `network` and `socket` modules are now enabled by default for
a board.
2023-04-11 17:20:29 +10:00
iabdalkader
944b4c2058 mimxrt/boards/MIMXRT1064_EVK: Fix board config to use internal flash.
This commit is necessary to make MicroPython work on this eval kit out of
the box, as the eval kit ships with the HyperFlash physically disconnected
from the bus (refer to the schematics or the user guide) and the QSPI
connected instead, but the fuses/board/pins are configured to boot from
internal flash (on FlexSPI2).

Note that enabling the HyperFlash is not trivial, as it requires soldering
and desoldering of many small footprint resistors and changing fuses.
2023-04-11 17:04:21 +10:00
iabdalkader
ed5e3598f1 mimxrt/Makefile: Fix internal flash configuration and build. 2023-04-11 17:03:28 +10:00
David Grayson
c046b23ea2 shared/runtime/pyexec: Don't allow Ctrl+C to interrupt frozen boot code.
Helps prevent the filesystem from getting formatted by mistake, among other
things.  For example, on a Pico board, entering Ctrl+D and Ctrl+C fast many
times will eventually wipe the filesystem (without warning or notice).

Further rationale: Ctrl+C is used a lot by automation scripts (eg mpremote)
and UI's (eg Mu, Thonny) to get the board into a known state.  If the board
is not responding for a short time then it's not possible to know if it's
just a slow start up (eg in _boot.py), or an infinite loop in the main
application.  The former should not be interrupted, but the latter should.
The only way to distinguish these two cases would be to wait "long enough",
and if there's nothing on the serial after "long enough" then assume it's
running the application and Ctrl+C should break out of it.  But defining
"long enough" is impossible for all the different boards and their possible
behaviour.  The solution in this commit is to make it so that frozen
start-up code cannot be interrupted by Ctrl+C.  That code then effectively
acts like normal C start-up code, which also cannot be interrupted.

Note: on the stm32 port this was never seen as an issue because all
start-up code is in C.  But now other ports start to put more things in
_boot.py and so this problem crops up.

Signed-off-by: David Grayson <davidegrayson@gmail.com>
2023-04-05 10:38:50 +10:00
iabdalkader
db4b416ea8 mimxrt/pendsv: Clean up PendSV code.
The dispatch active flag is only set once and never reset, so it will
always call the dispatch handler (once enabled), and it's not really
needed because it doesn't make things more efficient.

Also remove unused included headers.
2023-04-05 10:16:22 +10:00
robert-hh
eb6e5143c4 nrf/modules/machine/uart: Prevent UART lock-up after a receive error.
Like frame error, overrun, etc.  Fix is provided by @ricksorensen.
2023-04-05 10:00:43 +10:00
robert-hh
a529e0e8cf nrf/nrfx_config: Use UARTE for nrf52xxx devices.
It was incomplete.
2023-04-05 10:00:06 +10:00
robert-hh
408556504c nrf/modules/machine/pwm: Fix resource conflict, and change id to device.
Changes in this commit:
- Move the pwm_seq array to the p_config data structure.  That prevents
  potential resource collisions between PWM devices.
- Rename the keyword argument 'id' to 'device'.  That's consistent with the
  SAMD port as the other port allowing to specify it.
2023-04-05 09:58:33 +10:00
Jan Hrudka
5652f1f661 stm32/flash: Fix get_bank function for STM32H750.
STM32H750 has only 1 flash bank so function get_bank should always return
FLASH_BANK_1.
2023-04-04 14:58:54 +10:00
Damien George
783ddfc264 shared/tinyusb: Allow max USB descriptor string to be configured.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-04 11:57:25 +10:00
Sebastian Romero
0a3600a9ad stm32/boards/ARDUINO_NICLA_VISION: Fix incorrect bootloader PID. 2023-03-31 17:11:14 +11:00
Damien George
38e7b842c6 ports: Implement simple write polling for stdout.
This is a best-effort implementation of write polling.  It's difficult to
do correctly because if there are multiple output streams (eg UART and USB
CDC) then some may not be writeable while others are.  A full solution
should also have a return value from mp_hal_stdout_tx_strn(), returning the
number of bytes written to the stream(s).  That's also hard to define.

The renesas-ra and stm32 ports already implement a similar best-effort
mechanism for write polling.

Fixes issue #11026.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-23 13:51:17 +11:00
Damien George
31e7a0587d stm32/boards/NUCLEO_G0B1RE: Add config for USB and mboot.
But leave these disabled.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George
31638473b7 stm32/mboot: Add support for G0 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George
c7923b1139 stm32: Add support for USB on G0 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00