Wykres commitów

768 Commity (master)

Autor SHA1 Wiadomość Data
Damien George f2f3ef162d extmod/machine_i2s: Factor ports' I2S Python bindings to common code.
This factors the basic top-level I2S class code from the ports into
extmod/machine_i2s.c:
- I2S class definition and method table.
- The init and deinit method wrappers.
- The make_new code.

Further factoring will follow.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:39:57 +11:00
Damien George 7e7af71527 extmod/machine_pwm: Remove header file and move decls to .c file.
With public declarations moved to extmod/modmachine.h.  It's now mandatory
for a port to define MICROPY_PY_MACHINE_PWM_INCLUDEFILE if it enables
MICROPY_PY_MACHINE_PWM.  This follows how extmod/machine_wdt.c works.

All ports have been updated to work with this modified scheme.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 16:24:46 +11:00
Damien George 60929ec7e2 extmod/machine_wdt: Factor ports' WDT Python bindings to common code.
There are currently 7 ports that implement machine.WDT and a lot of code is
duplicated across these implementations.  This commit factors the common
parts of all these implementations to a single location in
extmod/machine_wdt.c.  This common code provides the top-level Python
bindings (class and method wrappers), and then each port implements the
back end specific to that port.

With this refactor the ports remain functionally the same except for:

- The esp8266 WDT constructor now takes keyword arguments, and accepts the
  "timeout" argument but raises an exception if it's not the default value
  (this port doesn't support changing the timeout).

- The mimxrt and samd ports now interpret the argument to WDT.timeout_ms()
  as signed and if it's negative truncate it to the minimum timeout (rather
  than it being unsigned and a negative value truncating to the maximum
  timeout).

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 15:36:09 +11:00
Seon Rozenblum 86c7b957a8 esp32/boards: Update UM board image names for consistency.
Signed-off-by: Seon Rozenblum <seon@unexpectedmaker.com>
2023-10-19 18:21:09 +11:00
robert-hh 480659b1ac ports: Make all ports skip execution of main.py if boot.py fails.
That can be caused e.g. by an exception.  This feature is implemented in
some way already for the stm32, renesas-ra, mimxrt and samd ports.  This
commit adds it for the rp2, esp8266, esp32 and nrf ports.  No change for
the cc3200 and teensy ports.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-10-12 11:53:29 +11:00
Glenn Moloney 9f835df35e esp32,esp8266: Rename MICROPY_ESPNOW to MICROPY_PY_ESPNOW.
For consistency with other Python-level modules.

Also add the corresponding missing preprocessor guard to esp32/modespnow.c,
so that this port compiles if MICROPY_PY_ESPNOW and MICROPY_PY_NETWORK_WLAN
are set to 0.

Fixes #12622.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2023-10-10 17:56:36 +11:00
Glenn Moloney f0f173ff5c esp32/boards/manifest.py: Freeze aioespnow into firmware by default.
Also remove corresponding commented line from esp8266/boards/manifest.py.
It doesn't have enough flash to have this frozen by default.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2023-10-05 20:50:49 +11:00
Luca Burelli 1cd61149e4 esp32/boards/ARDUINO_NANO_ESP32: Use Arduino USB IDs.
The IDF-provided version of TinyUSB defaults to Espressif's standard
VID:PID unless specific sdkconfig options are present. The numbers
already defined for the CUSTOM_* config options were ignored otherwise.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-10-04 13:06:14 +11:00
Jim Mussared 65a3ce39a3 extmod/modnetwork: Forward if.config(hostname) to network.hostname.
This removes the duplicate code in cyw43, esp32, esp8266 that implements
the same logic as network.hostname.

Renames the `mod_network_hostname` (where we store the hostname value in
`.data`) to `mod_network_hostname_data` to make way for calling the shared
function `mod_network_hostname`.

And uses memcpy for mod_network_hostname_data, because the length of source
is already known and removes reliance on string data being null-terminated.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-04 12:39:51 +11:00
Jim Mussared b329fdcb73 extmod/modnetwork: Increase max hostname length to 32.
This changes from the previous limit of 15 characters.  Although DHCP and
mDNS allow for up to 63, ESP32 and ESP8266 only allow 32, so this seems
like a reasonable limit to enforce across all ports (and avoids wasting the
additional memory).

Also clarifies that `MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN` does not include
the null terminator (which was unclear before).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-04 12:39:23 +11:00
dotnfc d7f63f994f esp32/main: Allow a board to override the MicroPython task stack size.
This allows the MicroPython task stack size to be overridden by the
mpconfigboard.h settings.

Signed-off-by: dotnfc <dotnfc@163.com>
2023-09-29 16:14:15 +10:00
Glenn Moloney 6662d84faa esp32/boards: Add bootloader rollback support for all builds.
Add "CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y" to
ports/esp32/boards/sdkconfig.base so that all micropython esp32 images
support OTA rollback in the bootloader.  These images can then be converted
to OTA-capable images as required by user tools.

Also remove CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y from board-specific
sdkconfig files as this is now the default.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2023-09-29 16:00:51 +10:00
Jim Mussared cf32c2feb5 ports: Restrict board.json to standard features.
Applies to newly-added ARDUINO_PORTENTA_C33 and UM_NANOS3.

Makes the list match the standard features defined in
24a6e951ec.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-29 14:15:02 +10:00
Seon Rozenblum 77ae0a0948 esp32/boards: Fix VBAT voltage calculation for UM S3 boards.
Signed-off-by: Seon Rozenblum <seon@unexpectedmaker.com>
2023-09-29 14:09:15 +10:00
Luca Burelli dd58be19ee esp32: Fix Partition.writeblocks() partial write corruption.
To simulate a partial erase, the code reads a native block, erases it,
and writes back the data before and after the erased area. However, the
current logic was filling the area after the erased block with data
from the beginning of the native block-aligned data, instead of applying
the proper offset.

Fixes #12474.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-09-21 17:49:48 +02:00
IhorNehrutsa 00930b213e esp32/mphalport: Add function/line/file info to check_esp_err exception.
Currently, check_esp_err() raises an exception without a location in the
source code, eg:

    Traceback (most recent call last):
      File "<stdin>", line 8, in <module>
    OSError: (-258, 'ESP_ERR_INVALID_ARG')

This commit allows additional error reporting (function, line and file) to
be enabled via detailed exceptions.  Change the error reporting config to

    #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)

and then exception messages from IDF errors look like:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: (-258, "0x0102 ESP_ERR_INVALID_ARG in function 'set_duty_u16'
    at line 342 in file './machine_pwm.c'")

Signed-off-by: Ihor Nehrutsa <IhorNehrutsa@gmail.com>
2023-09-18 11:26:43 +10:00
iabdalkader 7087880ce9 esp32/machine_pin: Fix null pointer access in machine_pin_find.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-15 13:44:50 +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
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 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
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
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 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 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 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 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 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 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
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
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 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
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
Glenn Moloney dbced75b48 esp32/network_wlan: Wait for STA/AP START/STOP event in wlan.active.
This is a fix for commit bccbaa92b1fc6237f0f49a7f07cc194835fbf4e3:
- 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 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
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
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 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
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 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 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 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
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
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
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
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
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
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 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 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
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
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
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
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
IhorNehrutsa 416707eefe esp32/machine_pin: Use const for size of machine_pin_irq_handler array. 2023-03-13 12:14:09 +11:00
Damien George f450e94ba0 ports: Rename remaining "Micro Python" to "MicroPython".
Signed-off-by: Damien George <damien@micropython.org>
2023-03-10 10:54:00 +11:00
Jim Mussared eb51ca4a11 esp32: Use extmod/modnetwork.c instead of port-specific version.
Rather than duplicating the implementation of `network`, this allows ESP32
to use the shared one in extmod.  In particular this gains access to
network.hostname and network.country.

Set default hostnames for various ESP32 boards.

Other than adding these two methods and the change to the default hostname,
there is no other user-visible change.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:26:54 +11:00
Jim Mussared 742037ec38 esp32/Makefile: Allow specifying BOARD_DIR on make command line.
This matches the behavior of the makefile ports but implemented for CMake,
making it easy to specify custom board definitions.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-23 09:49:54 +11:00
Jim Mussared 8b27482692 top: Update Python formatting to black "2023 stable style".
See https://black.readthedocs.io/en/stable/the_black_code_style/index.html

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-02 12:51:03 +11:00
Jim Mussared 6250337c9c ports: Make all network-capable boards use bundle-networking.
This will ensure that any board with networking support gets:
 - webrepl
 - mip
 - urequests
 - ntptime

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-01 12:42:06 +11:00
robert-hh c2ab1b5185 esp32/boards/OLIMEX_ESP32_POE: Remove id from and update board.json. 2023-01-28 15:29:01 +11:00
robert-hh d6bc34a13a esp32: Add a small delay before leaving wlan.active().
The delay is 1 ms. It avoids the crashes reported by the
issues #8289, #8792 and #9236 with esp-idf versions >= 4.2, but does
not solve an underlying problem in the esp-idf.
2023-01-19 21:31:46 +01:00
ma-lalonde 30db33d1e0 esp32/network_lan: Add support for Ethernet PHY KSZ8081.
This is available since ESP-IDF v4.4.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-19 22:50:41 +11:00
Clayton Cronk 54e85fe212 esp32/boards/GENERIC_UNICORE: Add board definition for unicore chips.
Tested to work on an ESP32-MINI-1, which is a single core ESP32-U4DWH.

Signed-off-by: Clayton Cronk <awesomecronk@gmail.com>
2023-01-19 22:38:02 +11:00
robert-hh 32a858e254 esp32/boards: Add board definition for Olimex ESP32 PoE boards.
The major setting is about the PHY interface configuration.  The
configuration matches the Olimex ESP32 Gateway as well.

Tested with esp-idf v4.2.4 and Olimex ESP32 POE boards.
2023-01-19 20:24:06 +11:00
Maripo GODA fb0dd86b39 esp32/machine_sdcard: Change dma_channel to SPI_DMA_CH_AUTO for ESP32S3.
Specifying DMA channel 2 causes an "invalid dma channel" error.  In
ESP-IDF, the only available channel for ESP32S3 is SPI_DMA_CH_AUTO=3.
2023-01-19 13:13:42 +11:00
Damien George 67097d8c2b esp32/network_lan: Fix compilation on IDF lower than v4.4.
Signed-off-by: Damien George <damien@micropython.org>
2023-01-18 13:47:10 +11:00
Damien Tournoud c7301b8d03 esp32/network_lan: Fix setting MAC address of ethernet devices.
`esp_eth_ioctl(ETH_CMD_S_MAC_ADDR)` sets the MAC address of the hardware
device, but we also need to notify the upper layers of the change so that
e.g. DHCP work properly.
2023-01-18 11:19:12 +11:00
Damien Tournoud e982c1d8de esp32/network_lan: Add support for SPI-based ethernet chips.
Add support for various SPI-based ethernet chips (W5500, KSZ8851SNL,
DM9051) to the ESP32 port.  This leverages the existing support in ESP-IDF
for these chips -- which configures these chips in "MAC raw" mode -- and
the existing support for network.LAN in the ESP32 port.  In particular,
this doesn't leverage the wiznet5k support that is used on the rp2 and
stm32 ports (because that's for native use of lwIP).

Tested on the POE Featherwing (with the SJIRQ solder jumper bridged) and a
ESP32-S3 feather.

A note about the interrupt pin: The W5500 implementation within ESP-IDF
relies on hardware interrupt, and requires the interrupt pin from the W5500
to be wired to a GPIO.  This is not the case by default on the Adafruit
Ethernet FeatherWing, which makes it not directly compatible with this
implementation.
2023-01-18 11:16:09 +11:00
robert-hh 4b52003fb8 esp32/network_lan: Support configuration of ETH ref_clk pin.
Both the direction and the Pin used for ref_clk can now be configured.  It
Requires at least idf v4.4.  The new keyword arguments to the constructor
are:

- ref_clk_mode=mode: with mode being Pin.IN or Pin.OUT.  If it is not set,
  then the default configuration is used, which may be configured by
  kconfig settings.

- ref_clk=pin_obj: which defines the Pin used for ref_clk.  This is either
  Pin(0), Pin(16) or Pin(17).  No check is done for the pin number.  If it
  is the wrong one, it simply will not work.  Besides that, no harm.
2023-01-18 10:05:13 +11:00
robert-hh efb4bd3555 esp32/network_lan: Add support for LAN8710 PHY.
LAN8710 uses the same drivers as LAN8720, so this commit just adds the
names.  Alternatively, both could be summarised under LAN87xx, like the
esp-idf does.
2023-01-18 10:04:31 +11:00
Red_M 1290329415 esp32/boards/GENERIC_S3_SPIRAM_OCT: Add ESP32S3 board with Octal SPIRAM. 2022-12-19 13:29:33 +11:00
Damien Tournoud fd1e66edb3 esp32/usb: Cleanup connection detection.
This was introduced by 35fb90bd57, but
it is much simpler and essentially the same to just use
`tud_cdc_n_connected()`.

The only difference is that tud_cdc_n_connected() only checks for DTR,
but this is correct anyway: DTR indicates device presence, RTS indicates
that the host wants to receive data.

Signed-off-by: Damien Tournoud <damien@platform.sh>
2022-12-13 20:46:32 -08:00
Jim Mussared 9bec52a2f8 esp32/main: Don't call usocket_events_deinit if unavailable.
usocket_events_deinit will only be available if MICROPY_PY_USOCKET_EVENTS
is enabled (which is only enabled when webrepl is enabled).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-14 13:51:20 +11:00
Wind-stormger 3a3739037d esp32/machine_touchpad: Fix TouchPad for ESP32S2, ESP32S3. 2022-12-14 13:46:41 +11:00
Brian Cooke 7fe7c55bb8 esp32/machine_timer: Fix ESP32C3 timer period doubling.
The original ESP32 only supports timer source clock APB so it doesn't need
and doesn't have a clk_src field.

The ESP32C3 supports timer source clock APB and XTAL so it does have a
clk_src field, and this needs to be configured to get the correct period.

Fixes #8084.
2022-11-23 11:57:39 +11:00
Jim Mussared b705732d5f esp32/boards/GENERIC_S3_SPIRAM: Enable BLE.
Follow up to 8a91c719 to no longer explicitly disable BLE in
mpconfigport.h.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-23 09:42:54 +11:00
David Lechner 4dcfd19bbf extmod/extmod.cmake: Add MICROPY_PY_BTREE compiler definition.
Instead of defining `MICROPY_PY_BTREE` in `mpconfigport.h` we can define
it via CMake similar to how other ports that use Makefiles define it in
`mpconfigport.mk`.

Signed-off-by: David Lechner <david@pybricks.com>
2022-11-17 23:20:58 +11:00
PGE 8a91c71966 esp32/boards/GENERIC_S3_SPIRAM: Enable BLE support. 2022-11-15 23:40:42 +11:00
robert-hh eefd946e60 esp32/modmachine: Move dht_readinto() to the machine module. 2022-11-09 15:58:39 +11:00
robert-hh d68e3b03b1 esp32/usb: Add a timeout to usb_tx_strn().
If USB CDC is connected and the board sends data, but the host does not
receive the data, the device locks up.  This is fixed in this commit by
having a timeout of 500ms, after which time the transmission is skipped.
2022-11-09 11:16:55 +11:00
Patrick d0687e90ab esp32: Add 32MiB partition table templates.
Signed-off-by: Patrick <patrick@joytech.com.au>
2022-11-09 10:57:44 +11:00
robert-hh 7775523b2d esp32/machine_pwm: Verify PWM is active when config methods are called.
Checks are added for pwm.freq(), pwm_duty(), pwm_duty_u10() and
pwm.duty_u16().  This avoids a core dump on ESP32C3, and misleading error
messages on Xtensa ESP32 devices.
2022-10-31 11:54:46 +11:00
Ihor Nehrutsa 5b2929a0e6 esp32/machine_pin: Fix size of machine_pin_irq_handler array.
Set the size of machine_pin_irq_handler array to GPIO_NUM_MAX:
- Min GPIO_NUM_MAX is 22 for IDF_TARGET_ESP32C3.
- Max GPIO_NUM_MAX is 49 for IDF_TARGET_ESP32S3.

The MP_REGISTER_ROOT_POINTER entry must be hard-coded, because the location
that it's evaluated by the compiler does not include the relevant IDF
header to get a definition of GPIO_NUM_MAX.
2022-10-31 11:42:20 +11:00
Mark Grosen 12f9948151 esp32/machine_i2c: Fix clocks and timeouts for ESP32-C3, ESP32-S3.
Each SoC family has its own clocks and timings/timeouts. For I2C, the
default source clock is either APB (ESP32, ESP32-S2) or XTAL (ESP32-S3,
ESP32-C3) as shown in the datasheets.  Since
machine_i2c.c/machine_hw_i2c_init() uses the default clk_flags (0), the
alternate low-power clock source is never selected in ESP-IDF
i2c.c/i2c_param_config().  There is not an API in i2c.c to get the source
clock frequency, so a compile-time value is used based on SoC family.

Also, the maximum timeout is different across the SoC families, so use the
I2C_LL_MAX_TIMEOUT constant to eliminate the warning from
i2c_set_timeout().

With these changes, the following results were obtained.  The I2C SCL
frequencies were measured with a Saleae logic analyzer.

ESP32 (TTGO T Dislay)
    I2C(0, scl=22, sda=21, freq=101781)  Measured: 100KHz
    I2C(0, scl=22, sda=21, freq=430107)  Measured: 400KHz
    I2C(0, scl=22, sda=21, freq=1212121) Measured: 941KHz

ESP32-S3 (TTGO T-QT)
    I2C(0, scl=34, sda=33, freq=111111)  Measured: 107KHz
    I2C(0, scl=34, sda=33, freq=444444)  Measured: 400KHz
    I2C(0, scl=34, sda=33, freq=1111111) Measured: 842KHz

ESP32-C3 (XIAO ESP32C3)
    I2C(0, scl=7, sda=6, freq=107816)  Measured: 103KHz
    I2C(0, scl=7, sda=6, freq=444444)  Measured: 380KHz
    I2C(0, scl=7, sda=6, freq=1176470) Measured: 800KHz

(ESP32-S2 board was not available for testing.)
2022-10-28 19:06:41 +11:00
iabdalkader 427670c210 esp32: Rename machine I2C and SPI types consistently across ports.
This renames:
- machine_hw_i2c_type -> machine_i2c_type
- machine_hw_spi_type -> machine_spi_type
2022-10-22 12:56:10 +11:00
Damien George 95c614e2b6 esp32/machine_hw_spi: Use auto DMA channel on S2, S3, C3 chips.
Auto DMA channel is supported in IDF v4.4, and is required to be used on S3
chips, so use this simpler configuration option where possible.

Fixes issue #8634.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-04 17:43:48 +11:00
Damien George 0ee877a207 esp32/machine_i2s: Add I2S finaliser which calls deinit().
So that the FreeRTOS resources can be freed, eg on soft reset.

Fixes issue #9366.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-04 11:47:06 +11:00
Jim Mussared 924a3e03ec top: Replace upip with mip everywhere.
Updates all README.md and docs, and manifests to `require("mip")`.

Also extend and improve the documentation on freezing and packaging.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-30 17:34:03 +10:00
Damien George dd9dcb594c esp32/machine_pwm: Don't use LEDC_USE_REF_TICK on ESP32-C3 variants.
Because it's not supported by this particular MCU (since IDF v4.4.2).

Signed-off-by: Damien George <damien@micropython.org>
2022-09-26 00:11:42 +10:00
Damien George 3abcfb9aec esp32/modsocket: Use mp_obj_is_integer to test port type.
Because the value may be a big integer, which is still a valid type to use.

Fixes issue #9410.

Signed-off-by: Damien George <damien@micropython.org>
2022-09-26 00:07:58 +10:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:15 +10:00
Jim Mussared 6da41b5900 py/obj: Merge getiter and iternext mp_obj_type_t slots.
The goal here is to remove a slot (making way to turn make_new into a slot)
as well as reduce code size by the ~40 references to mp_identity_getiter
and mp_stream_unbuffered_iter.

This introduces two new type flags:
- MP_TYPE_FLAG_ITER_IS_ITERNEXT: This means that the "iter" slot in the
  type is "iternext", and should use the identity getiter.
- MP_TYPE_FLAG_ITER_IS_CUSTOM: This means that the "iter" slot is a pointer
  to a mp_getiter_iternext_custom_t instance, which then defines both
  getiter and iternext.

And a third flag that is the OR of both, MP_TYPE_FLAG_ITER_IS_STREAM: This
means that the type should use the identity getiter, and
mp_stream_unbuffered_iter as iternext.

Finally, MP_TYPE_FLAG_ITER_IS_GETITER is defined as a no-op flag to give
the default case where "iter" is "getiter".

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:13 +10:00
Jim Mussared 9dce82776d all: Remove unnecessary locals_dict cast.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 662b9761b3 all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00