Commit Graph

3723 Commits

Author SHA1 Message Date
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