summaryrefslogtreecommitdiff
path: root/ports/esp32
AgeCommit message (Collapse)Author
37 hoursesp32/machine_timer: Fix machine.Timer() tick frequency on ESP32C2,C6.HEADorigin/masterorigin/HEADmasterAngus 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>
37 hoursesp32/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>
43 hoursports: Allow MICROPY_PY_MACHINE_I2C_TARGET to be disabled by board cfg.Damien George
Signed-off-by: Damien George <damien@micropython.org>
7 daysesp32/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>
7 daysesp32/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>
7 daysesp32/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>
7 daysesp32/machine_i2c_target: Implement I2CTarget class.Damien George
Only soft IRQs are supported. Signed-off-by: Damien George <damien@micropython.org>
7 daysesp32/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>
10 daysesp32: 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>
10 daysesp32: 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>
10 daysesp32: 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>
2025-05-26shared/tinyusb: Use device event hook to schedule USB task.Angus Gratton
Previously MicroPython ports would linker-wrap dcd_event_handler in order to schedule the USB task callback to run when needed. TinyUSB 0.16 added proper support for an event hook to do the same thing without the hacky linker wrapping. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-22esp32/boards/SPARKFUN_IOT_REDBOARD_ESP32: Add SparkFun board.Malcolm McKellips
Add board definition files for SparkFun IoT RedBoard ESP32. Signed-off-by: Malcolm McKellips <malcolm.mckellips@sparkfun.com>
2025-05-16esp32/network_lan: Add PHY_GENERIC device type.Elvis Pfutzenreuter
Support the new PHY_GENERIC device type, added in ESP-IDF v5.4.0 [1]. This PHY driver was added to ESP-IDF to support "generic"/oddball PHY LAN chips like the JL1101, which offer no features beyond the bare 802.3 PHY standard and don't actually need a chip-specific driver (see discussion at [2]). [1] https://github.com/espressif/esp-idf/commit/0738314308ad36a73601ddb8bb82f1dcbfe1f550 [2] https://github.com/espressif/esp-eth-drivers/pull/28 Signed-off-by: Elvis Pfutzenreuter <epxx@epxx.co>
2025-05-16esp32/machine_i2c: Fix default I2C pins for C3, S3.Rick Sorensen
The default I2C init does not require setting SCL or SDA but the default I2C0 pins for C3, S3 conflict with the espressif GPIO usage. For the C3, pins 18/19 are for USB/JTAG. If used for I2C() they will cause the REPL to hang on initialization of the I2C. For the S3 pin 19 is allocated for USB/JTAG also but the defaults do not seem to affect the REPL. See related #16956. Fixes issue #17103. Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com> Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-16esp32/modesp32: Implement esp32.idf_task_info().Daniël van de Giessen
This adds a new function, `esp32.idf_task_info()`, that can be used to retrieve task statistics which is useful for diagnosing issues where some tasks are using up a lot of CPU time. It's best used in conjunction with the `utop` module from micropython-lib. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-05-16esp32/network_lan: Add support for LAN8670 PHY.Angus Gratton
This adds support for LAN8670 to the esp32 port. Enabled conditionally for the esp32 target, if ESP-IDF version is new enough (v5.3 or newer). Fixes issue #15731. Signed-off-by: Damien George <damien@micropython.org> Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-16esp32: Update to use ESP-IDF v5.4.1.IhorNehrutsa
This version of the IDF uses about 1KB more IRAM and 1KB more DRAM on most boards, but 6.5KB more DRAM usage on the S3. It seems that's due to a lot of small increases in many components. Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com>
2025-05-16esp32/mpthreadport: Fix double delete of tasks on soft reset.Damien George
Python threads (created via the `_thread` module) are backed by a FreeRTOS task. Managing the deletion of the task can be tricky, and there are currently some bugs with this in the esp32 port. The actual crash seen was in FreeRTOS' `uxListRemove()`, and that's because of two calls to `vTaskDelete()` for the same task: one in `freertos_entry()` when the task ran to completion, and the other in `mp_thread_deinit()`. The latter tried to delete the task a second time because it was still in the linked list, because `vTaskPreDeletionHook()` had not yet been called. And the reason `vTaskPreDeletionHook()` was yet to be called is because the FreeRTOS idle task was starved. This commit fixes that. There are three things done by this commit: - remove the `vTaskPreDeletionHook`, it's not needed anymore because task stack memory is allocated by the IDF, not on the MicroPython heap - when a task finishes it now removes itself from the linked list, just before it deletes itself - on soft reset, all tasks are deleted and removed from the linked list in one swoop (while the mutex is held) Signed-off-by: Damien George <damien@micropython.org>
2025-05-16esp32/mpconfigport: Document how to get more debug info.IhorNehrutsa
Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com>
2025-05-16esp32/machine_pwm: Improve PWM and make its API match other ports.IhorNehrutsa
This reduce inconsistencies between esp32 PWM and other ports: 1. duty_u16() high value is 2**16-1 == 65535 2. Invert PWM wave with invert=1 parameter 3. Enable PWM in light sleep mode 4. Allow PWM output and read pulse input simultaneously on the same Pin() 5. Code refactoring Co-Authored-By: Angus Gratton <angus@redyak.com.au> Co-Authored-By: robert-hh <robert@hammelrath.com> Co-Authored-By: Andrew Leech <andrew.leech@planetinnovation.com.au> Co-Authored-By: Yoann Darche <yoannd@hotmail.com> Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com>
2025-05-15esp32/network_ppp: Restructure to match extmod/network_ppp_lwip.Daniël van de Giessen
The ESP32 PPP implementation predates the generic implementation in extmod. The new extmod implementation has a few advantages such as a better deinitialisation procedure (the ESP32 implemementation would not clean up properly and cause crashes if recreated) and using the UART IRQ functionality instead of running a task to read data from the UART. This change restructures the ESP implementation to be much closer to the new extmod version, while also bringing a few tiny improvements from the ESP32 version to the extmod version. The diff between extmod/network_ppp_lwip.c and ports/esp32/network_ppp.c is now a small set of easy to review ESP32 port-specific changes. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-05-15esp32/network_common: Raise a memory error on ESP_ERR_NO_MEM.Alessandro Gatti
This commit changes the error handler for WiFi operations to recognise out of memory conditions reported by ESP-IDF functions, and report them as more descriptive exceptions rather than a generic "error 0x101". The error handler only provided a human-readable error description for WiFi-specific error codes (codes in the ESP_ERR_WIFI_BASE range), but WiFi functions are known to return other codes. Now ESP_ERR_NO_MEM is covered with a specific error message, making it easier to debug issues related to running out of ESP-IDF heap. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-05-14esp32/machine_uart: Correctly manage UART queue and event task.Daniël van de Giessen
If the driver was reinitialised while there was already an event task running the queue that task is trying to receive from would be deleted, causing it to try to take a lock that no longer existed and deadlocking the CPU. This change ensures the task is always shut down before recreating the queue and recreates the task afterwards. It also allows setting an IRQ handler before the UART is initialized (like other ports allow), removes the task when the UART is deinitialized (which was previously missing), adds a check that no event task can be started when no queue exists, and adds a check to prevent reinitialising the UART driver unnecessarily. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-05-14esp32/main: Make the entry point function name configurable.Alessandro Gatti
This commit introduces a new port configuration entry allowing the entry point function name to be changed, from "app_main" to a custom name. This is needed when MicroPython is embedded as an ESP-IDF component, since the "app_main" symbol is already provided elsewhere, making compilation not possible. Marking MicroPython's symbol as weak would make it compile and make it possible to create and start the MicroPython task anyway with the right FreeRTOS task creation incantation, but it is probably easier to just rename the initialisation function into something else that can be accessed from outside. When MicroPython is embedded as an ESP-IDF component, the MICROPY_ESP_IDF_ENTRY definition can be set to indicate the new entry point function name. The new function name prototype should still be defined in external code to let linking succeed. Also, the NLR failure callback is marked as weak to give the chance of handling such error in a more controlled fashion rather than trigger an unconditional board restart. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-05-14esp32/esp32_common.cmake: Allow adding defines and compiler flags.Alessandro Gatti
This commit introduces two extra CMake variables, MICROPY_DEF_COMPONENT and MICROPY_COMPILE_COMPONENT, that make it easier to integrate MicroPython as a custom ESP-IDF component. Whilst there is no official MicroPython component available for ESP-IDF, integration can be achieved with some minor CMake scripting outside the MicroPython tree - except for customisation of compilation defines and build flags, which is what this commit tries to provide. Compilation defines customisation is especially important for MicroPython configuration, as it is not possible to inject a value for MP_CONFIGFILE otherwise. This means that unless MicroPython itself is forked first to edit ports/esp32/mpconfigport.h, it is not possible to perform any meaningful configuration of the interpreter/runtime when included as a component. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-05-14esp32/machine_timer: Fix timer.value() for an uninitialized timer.robert-hh
Raises a value error in that case, which happens after a timer was created but not initialized, or after calling `timer.deinit()`. Fixes issue #17033. Signed-off-by: robert-hh <robert@hammelrath.com>
2025-05-14esp32/esp32_common.cmake: Use the tinyusb source files from ESP-IDF.Alessandro Gatti
This commit removes the explicit dependency on the vendored tinyusb version for the ESP32S2 and ESP32S3 boards. Tinyusb is still available to MicroPython through a dependency on the `espressif/esp_tinyusb` ESP-IDF component, which in turn depends on the `espressif/tinyusb` component itself. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-05-13all: Rename the "NORETURN" macro to "MP_NORETURN".Alessandro Gatti
This commit renames the NORETURN macro, indicating to the compiler that a function does not return, into MP_NORETURN to maintain the same naming convention of other similar macros. To maintain compaitiblity with existing code NORETURN is aliased to MP_NORETURN, but it is also deprecated for MicroPython v2. This changeset was created using a similar process to decf8e6a8bb940d5829ca3296790631fcece7b21 ("all: Remove the "STATIC" macro and just use "static" instead."), with no documentation or python scripts to change to reflect the new macro name. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-04-24esp32/tools: Update metrics_esp32 script for ESP-IDF >=v5.4.x.Angus Gratton
The output of 'idf.py size' has changed, plus some other cleanups around build dir name, etc. Can now run on v5.2.2 and v5.4.1, probably other versions. Signed-off-by: Angus Gratton <angus@redyak.com.au>