summaryrefslogtreecommitdiff
path: root/ports/esp32
AgeCommit message (Collapse)Author
5 daysesp32/machine_timer: Warn that hard timers are not implemented.Chris Webb
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. Most ports now support a hard= argument to the machine.Timer constructor or initialiser to explicitly choose between these behaviours. However, esp32 does not support hardware interrupts because they are not delivered to the main thread, so the interrupt handler would need to acquire the GIL. Raise a ValueError if hard=True is requested for esp32 machine.Timer. Signed-off-by: Chris Webb <chris@arachsys.com>
6 daysesp32/machine_uart: Call uart_wait_tx_done() only with driver installed.robert-hh
Otherwise an error message will pop up at the first instatiation of the UART object. Addresses #18122 / #18123. Signed-off-by: robert-hh <robert@hammelrath.com>
2025-09-11esp32/machine_uart: Handle properly the timeout_char argument.robert-hh
Before, it was ignored. Tested with ESP32, ESP32S3, ESP32C6. Signed-off-by: robert-hh <robert@hammelrath.com>
2025-09-10esp32/machine_uart: Convert machine.UART objects to static instances.Angus Gratton
Makes machine.UART objects static instances (similar to other ports), adds machine_uart_deinit_all() function for cleanup on soft reset. - Fixes the case where the OS-level uart_event_task is leaked (along with 2KB of heap) when a UART object is garbage collected (including after a soft reset). - Fixes hard fault if a previous UART irq() fires after the UART object is garbage collected (including after a soft reset), but before any new UART object is instantiated for the same UART number. - Constructing multiple UART objects for the same UART now returns the same instance multiple times, not different instances. - Was also able to streamline deinit/init to only install the driver once, rather than install-with-defaults/uninstall/reinstall. Alternative would be to add a finaliser, but this is more consistent with how most other UART objects are implemented. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-09-09esp32: Add IDF Component Lockfiles to git repo.Angus Gratton
This is recommended by Espressif, and it's the only way to ensure everyone builds the same set of component versions. The awkward part is that updating the ESP-IDF version will churn a line in each of these files (and possibly other changes). Adds a build-time check for lock file changes, which is either a warning or a hard error depending on the value of MICROPY_MAINTAINER_BUILD flag (introduced in previous commit). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-09-09esp32: Update esp_tinyusb component to v1.7.6.Angus Gratton
Reported to fix issues reported with serial corruption when interacting with MicroPython from macOS hosts. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-09-09esp32/usb: Fix building with USB CDC disabled.Alessandro Gatti
This commit fixes the build issues in the ESP32 port that arise when explicitly disabling USB CDC support. The USB support code gated the USB serial number retrieval behind the USB CDC support definition, even though all USB devices must be able to be queried for their serial number. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-09-01esp32: Revert "esp32/mpconfigport: Disable I2CTarget on ESP32-C6 to ..".Damien George
This reverts commit 3c9546ea0911b50d4b85ad4046864c90f84b3fd3. I2CTarget now fits on ESP32-C6 because it's compiled with -Os, see commit 5b98126c21f8eaa996e258761a291a7a88624082. Signed-off-by: Damien George <damien@micropython.org>
2025-08-29esp32/boards: Enable I2S for ESP32_GENERIC_C6 and other C6 boards.Jimisola Laursen
I2S works on the ESP32-C6, and it now has enough space to fit. Signed-off-by: Jimisola Laursen <jimisola@jimisola.com> Signed-off-by: Damien George <damien@micropython.org>
2025-08-29esp32/boards: Build ESP32-C2 and C3 with -Os instead of -O2.Angus Gratton
Same optimisation that was applied to C6 in the parent commit, now applied to all RISC-V boards. +------------+------------+------------+------------+ | Size | Before | After | Delta | +------------+------------+------------+------------+ | C2 Binary | 1680384 | 1494224 | -186160 | | C2 D/IRAM | 83710 | 79080 | -4630 | | C3 Binary | 1833328 | 1636624 | -196704 | | C3 D/IRAM | 139608 | 131896 | -7712 | +------------+------------+------------+------------+ This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-29esp32/boards: Reduce flash usage of ESP32-C6 boards.Angus Gratton
Reduces ESP32_GENERIC_C6 application flash size from 2024432 to 1813216 (206KB smaller). Also has benefit of reducing D/IRAM size, increasing free memory at runtime (167187 to 148584, -18603 bytes). Most of this savings comes from building with -Os instead of -O2, but about 10KB comes from using the SPI flash functions from the ROM. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-25esp32/network_ppp: Stop polling if PPP was disconnected.Daniël van de Giessen
When disconnecting from PPP the modem sends a confirmation. This message is received, like all messages, through the poll() method. lwIP may then immediately call our status callback with code PPPERR_USER to indicate the connection was closed. Our callback then immediately proceeds to free the PCB. Thus, during each new iteration of the loop in poll() we must check if we haven't disconnected in the meantime to prevent calling the pppos_input_tcpip with a PCB that is now NULL. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-25esp32/network_ppp: Stop polling if stream becomes None.Daniël van de Giessen
If while a polling operation is active the stream is removed we should stop polling data from that stream. This was already the intended behaviour, but implemented incorrectly. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-19py/mpconfig: Enable CRYPTOLIB, HASHLIB_MD5, HASHLIB_SHA1 if SSL enabled.Damien George
This commit unifies the configuration of MICROPY_PY_CRYPTOLIB, MICROPY_PY_HASHLIB_MD5 and MICROPY_PY_HASHLIB_SHA1, so they are enabled by default if MICROPY_PY_SSL is enabled. This matches the existing configuration of most of the ports. With this change, all ports remain the same except: - reneses-ra now enables MICROPY_PY_CRYPTOLIB, MICROPY_PY_HASHLIB_MD5 and MICROPY_PY_HASHLIB_SHA1. - rp2 now enables MICROPY_PY_HASHLIB_MD5. Signed-off-by: Damien George <damien@micropython.org>
2025-08-15extmod/modtime: Move tuple creation to common localtime implementation.Damien George
This factors code out of the ports and into the common `time.localtime` implementation in `extmod/modtime.c`. That helps to reduce code duplication, prevent errors in implementation, and reduce code size on some ports (mimxrt and stm32 at least). Signed-off-by: Damien George <damien@micropython.org>
2025-08-11esp32/network_ppp: Correctly clean up PPP PCB after close.Daniël van de Giessen
If PPP is still connected, freeing the PCB will fail and thus instead we should trigger a disconnect and wait for the lwIP callback to actually free the PCB. When PPP is not connected we should check if the freeing failed, warn the user if so, and only mark the connection as inactive if not. When all this happens during garbage collection the best case is that the PPP connection is already dead, which means the callback will be called immediately and cleanup will happen correctly. The worst case is that the connection is still alive, thus we are unable to free the PCB (lwIP won't let us) and it remains referenced in the netif_list, meaning a use-after-free happens later when lwIP traverses that linked list. This change does not fully prevent that, but it *does* improve how the PPP.active(False) method on the ESP32 port behaves: It no longer immediately tries to free (and fails), but instead triggers a disconnect and lets the cleanup happen correctly through the status callback. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-11esp32/network_ppp: Use non-thread-safe API inside status callback.Daniël van de Giessen
The status callback runs on the lwIP tcpip_thread, and thus must use the non-thread-safe API because the thread-safe API would cause a deadlock. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-11esp32/network_ppp: Use thread-safe API for PPPoS input.Daniël van de Giessen
A small follow-up to 3b1e22c66947271e8b60eddf4e8aa6dadc6d9a7d, in which the entire PPP implementation was reworked to more closely resemble the extmod version. One of the differences between extmod and the ESP32 port is that the ESP32 port uses the thread-safe API, but in that changeset the PPP input function was accidentally changed to use the non-safe API. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-11esp32: Support building against IDFv5.5.Daniël van de Giessen
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-07esp32/machine_timer: Fix machine.Timer() tick frequency on ESP32C2,C6.Angus Gratton
Also future-proofs this code for other chips. Apart form C6 and C2, all currently supported chips use APB clock for GPTIMER_CLK_SRC_DEFAULT. ESP32-C2 uses 40MHz PLL but APB_CLK_FREQ was 26MHz. ESP32-C6 uses 80MHz PLL but APB_CLK_FREQ was 40MHz. Implementation now gets the correct frequency from ESP-IDF. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-07esp32/machine_timer: Enable timer clock source for ESP32C6.Angus Gratton
Otherwise the PLL is not enabled. These changes are adapted from `timer_legacy.h` in ESP-IDF. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-07ports: Allow MICROPY_PY_MACHINE_I2C_TARGET to be disabled by board cfg.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-08-02esp32/mpconfigport: Disable I2CTarget on ESP32-C6 to reduce code size.Damien George
I2CTarget costs about 8k of flash size on ESP32-S2, and about 11k on ESP32-C6. The ESP32-C6 only has about 8k remaining, so disable I2CTarget on that SoC until more flash can be made available. Signed-off-by: Damien George <damien@micropython.org>
2025-08-01esp32/modules/machine.py: Add Counter and Encoder classes.Jonathan Hogg
Adds a Python override of the `machine` module, which delegates to the built-in module and adds an implementation of `Counter` and `Encoder`, based on the `esp32.PCNT` class. Original implementation by: Jonathan Hogg <me@jonathanhogg.com> Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2025-08-01esp32/modesp32: Add esp32.PCNT class.Jonathan Hogg
Add a new `esp32.PCNT` class that provides complete, low-level support to the ESP32 PCNT pulse counting hardware units. This can be used as a building block to implement the higher-level `machine.Counter` and `machine.Encoder` classes. This is enabled by default on all OG, S2, S3, C6 boards, but not on C3 (as the PCNT peripheral is not supported). Original implementation by: Jonathan Hogg <me@jonathanhogg.com> Signed-off-by: Jim Mussared <jim.mussared@gmail.com> Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-01esp32/machine_i2c_target: Implement I2CTarget class.Damien George
Only soft IRQs are supported. Signed-off-by: Damien George <damien@micropython.org>
2025-08-01esp32/machine_i2c: Factor default pin macros to header file.Damien George
So the implementation of I2CTarget can use them. Signed-off-by: Damien George <damien@micropython.org>
2025-07-30esp32: Fix first line ESP32-C2 serial output after reset or deepsleep.Angus Gratton
ESP32-C2 ROM prints at 74880bps (same as ESP8266), so need a newline before first MicroPython output to avoid it being appended on end of a line of noise. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-07-30esp32: Add "Free RAM" optimisation config flags.Angus Gratton
This is necessary for ESP32-C2 Wi-Fi & BT to work reliably (and for TLS to work at all). On IDF 5.4.2 the free static RAM goes from 60KB to 100KB, and there will also be a reduction in lwIP & Wi-Fi memory use at runtime. The performance trade-off seems low for most use cases, although it will probably be significant for certain combinations of load (i.e. heavy TCP/IP, heavy BT throughput, and some peripheral driver functions). Added as a set of config flags because this is potentially useful on other SoCs where the goal is to maximise RAM available for MicroPython. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-07-30esp32: Add support for ESP32-C2 (aka ESP8684).TianShuang Ke
Includes: esp32/esp32c2: Adapt to target chip ESP32C2. esp32/esp32c2: Fix heap size is too small to enable Bluetooth. Signed-off-by: TianShuangKe <qinyun575@gmail.com> Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-07-25ports: Eliminate define of {U,}INT_FMT where redundant.Jeff Epler
The default definition in `py/mpconfig.h` for 32-bit architectures is `%u/%d`, so these can be removed. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-23esp32: Update to use ESP-IDF v5.4.2.Damien George
This is a patch release of the IDF. Comparing with 5.4.1, firmware size is up by about 1.5k on ESP32 and 9k on ESP32-S3. But IRAM usage (of the IDF) is down by about 500 byte on ESP32 and DRAM usage is down by about 20k on ESP32 and 10k on ESP32-S3. Testing on ESP32, ESP32-S2, ESP32-S3 and ESP32-C3 shows no regressions, except in BLE MTU ordering (the MTU exchange event occuring before the connect event). Signed-off-by: Damien George <damien@micropython.org>
2025-07-23esp32/machine_uart: Improve sendbreak so it doesn't reconfig the UART.Damien George
Currently, `UART.sendbreak()` on esp32 will reconfigure the UART to a slower baudrate and send out a null byte, to synthesise a break condition. That's not great because it changes the baudrate of the RX path as well, which could miss incoming bytes while sending the break. This commit changes the sendbreak implementation to just reconfigure the TX pin as GPIO in output mode, and hold the pin low for the required duration. Signed-off-by: Damien George <damien@micropython.org>
2025-07-09shared/timeutils: Standardize supported date range on all platforms.Yoctopuce dev
This is code makes sure that time functions work properly on a reasonable date range, on all platforms, regardless of the epoch. The suggested minimum range is 1970 to 2099. In order to reduce code footprint, code to support far away dates is only enabled specified by the port. New types are defined to identify timestamps. The implementation with the smallest code footprint is when support timerange is limited to 1970-2099 and Epoch is 1970. This makes it possible to use 32 bit unsigned integers for all timestamps. On ARM4F, adding support for dates up to year 3000 adds 460 bytes of code. Supporting dates back to 1600 adds another 44 bytes of code. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-07-06esp32/panichandler: Support building against IDFv5.4.2.Daniël van de Giessen
The IDF panic handler resets the watchdog timeout to prevent the printing of the error message from being cut off by a WDT reset. We use the exact same function call in our wrapper function for the same purpose. In IDFv5.4.2 the function used for this was changed from `esp_panic_handler_reconfigure_wdts` to `esp_panic_handler_feed_wdts`, specifically in this commit: https://github.com/espressif/esp-idf/commit/cd887ef59a7b966a7f431754aaec6ee653849d77 Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-06-26esp32/boards/GARATRONIC_PYBSTICK26_ESP32C3: Add pybstick26-esp32c3 defn.Garatronic
2025-06-17esp32/modesp32: Fix access to ext0_pin only if defined.Meir Armon
In different functions `machine_rtc_config.ext0_pin` is accessed where SOC_PM_SUPPORT_EXT0_WAKEUP is not defined, fix that. Signed-off-by: Meir Armon <meirarmon@gmail.com>
2025-06-16esp32/modesp32: Make wake_on_ext1 available only on SoCs supporting it.Meir Armon
The `esp32.wake_on_ext1()` method should only be available on boards that have SOC_PM_SUPPORT_EXT1_WAKEUP=y. And update docs to reflect this. Signed-off-by: Meir Armon <meirarmon@gmail.com>
2025-06-16esp32/modesp32: Make wake_on_ext0 available only on SoCs supporting it.Meir Armon
The `esp32.wake_on_ext0()` method should only be available on boards that have SOC_PM_SUPPORT_EXT0_WAKEUP=y. And update docs to reflect this. Signed-off-by: Meir Armon <meirarmon@gmail.com>
2025-06-16esp32/modesp32: Make wake_on_touch available only on SoCs supporting it.Meir Armon
The `esp32.wake_on_touch()` method should only be available on boards that have SOC_TOUCH_SENSOR_SUPPORTED=y. And update docs to reflect this. Signed-off-by: Meir Armon <meirarmon@gmail.com>
2025-06-16esp32/modesp32: Make wake_on_ulp available only on SoCs that support it.Meir Armon
The `esp32.wake_on_ulp()` method should only be available on boards that have SOC_ULP_SUPPORTED=y. Update docs to reflect this. Signed-off-by: Meir Armon <meirarmon@gmail.com>
2025-06-14esp32/README: Update README to describe auto filesystem sizing.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-06-14esp32/boards: Convert all boards to auto detect flash size.Damien George
Remove the "vfs" entry from all partitions-*.csv files, and then remove duplicated files. And remove the ESP32_GENERIC_S3-FLASH_4M variant, because it's no longer needed. Signed-off-by: Damien George <damien@micropython.org>
2025-06-14esp32/main: Auto detect the size of flash and auto create vfs partition.Damien George
Currently in the esp32 port the size of the SPI flash must be configured at build time, eg 4MiB, 8MiB, etc. Also, the esp32 partition table must be configured at build time, which depends on the size of the SPI flash. A bigger flash means more can be allocated to the user filesystem. This commit makes it so the SPI flash size is automatically determined at runtime, and the filesystem size is automatically set to take up as much room as possible (a "vfs" partition is created automatically if it doesn't exist). This works by: - Setting the SPI flash size to be 4MiB in the build (or some other value, as long as the firmware app fits). - Removing the vfs partition from the esp32 partition table (only nvs, phy_init and firmware, and maybe romfs, remain in the partition table). - At boot, query the physical size of the SPI flash and use that as the actual size in the code. - If it doesn't already exist, automatically create a "vfs" partition which takes up the flash from the end of all existing partitions to the end of flash. This allows simplifying a lot of board configurations, and removing some board variants that just change the flash size (to be done in a following commit). It's also fully backwards compatible, in the following sense: - Existing boards with MicroPython firmware will continue to work with the same filesystem, ie the filesystem won't be erased when the firmware is updated. - If a user has a custom esp32 partition table and installs MicroPython as a bare app into the app partition, the new MicroPython firmware will honour the esp32 partition table and use either "vfs" or "ffat" partitions as the filesystem. Signed-off-by: Damien George <damien@micropython.org>
2025-06-05esp32: Update ADC driver update to the new esp_adc API.purewack
This commit updates the ADC to use the new driver `esp_adc/adc_oneshot.h`. There are several errata notes about not being able to change the bit-width of the ADCs certain chips. The only chip that can switch resolution to a lower one is the normal ESP32. ESP32 C2 and S3 are stuck at 12 bits, while S2 is at 13 bits. On the S2, you can change the resolution, but it has no effect on the resolution, rather, it prevents attenuation from working at all! The resolution is set to the maximum possible for each SoC, with the ESP32 being the only one not throwing errors when trying to set the bit-width to 9, 10, 11 or 12 bits using `ADC.width(bits)`. Signed-off-by: Damian Nowacki (purewack) bobimaster15@gmail.com
2025-06-05esp32: Re-use allocated timer interrupts and simplify UART timer code.Daniël van de Giessen
If the interrupt is not freed but merely disabled, instead of reallocating it every time the timer is enabled again we can instead just re-enable it. That means we're no longer setting the handler every time, and we need to ensure it does not change. Doing so by adding an additional wrapper function does not only solve that problem, it also allows us to remove some code duplication and simplify how machine_uart uses the timer. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-06-05esp32/machine_timer: Do not free interrupt from ISR.Daniël van de Giessen
esp_intr_free is not safe to call from the timer ISR because it requires the current task (the one the ISR interrupted) to be pinned to the same core as the interrupt was allocated on. Merely disabling the ISR however is safe since that only requires that we're currently running on the same core (which the ISR always is), regardless of the current task. This was causing deadlocks in machine_uart when the ISR happened to interrupt a task that was not pinned to a specific core. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-06-04extmod/modbluetooth: Add timeout to deinit.Andrew Leech
If the BLE radio stops responding before deinit is called the function can get stuck waiting for an event that is never received, particularly if the radio is external or on a separate core. This commit adds a timeout, similar to the timeout already used in the init function. Updated for nimble, btstack, esp32 and zephyr bindings. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-06-04ports: Update board.json files for vendor/product consistency.Matt Trentini
The vendor and product fields in the `board.json` files were somewhat inconsistent. Remove any duplication of the vendor name in the product field so that `f"{vendor} {product}"` reads well. In addition to that, update most of the URL's for `board.json` files that are modified here, and match case and spacing used by the manufacturers for the vendor and product names. Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2025-06-03esp32/modsocket: Add optional flags argument for recv and recvfrom.Angus Gratton
Implements MSG_PEEK and MSG_DONTWAIT (both passed through to LWIP sockets API). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>