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:
cd887ef59a
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
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>
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>
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>
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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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>
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] 0738314308
[2] https://github.com/espressif/esp-eth-drivers/pull/28
Signed-off-by: Elvis Pfutzenreuter <epxx@epxx.co>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
decf8e6a8b ("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>
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>
This commit makes the BTree module truly optional, as it was
unconditionally enabled in the shared CMake script for the port.
This meant that if a board/variant did explicitly turn BTree off said
request was not honoured by the build system and the BTree module would
still be brought in.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit removes a definition used back when ESP-IDF v4 was supported
by MicroPython. Those times are now long gone, and so is the need for
that particular definition to be set in the first place.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit cleans up a couple of RISC-V specific directives in the
build script. Namely, removes the forced inclusion of the "riscv"
component and introduces proper mpy-cross flags.
The "riscv" component is already included by the ESP-IDF build
framework, as certain low-level components would not build otherwise, so
there is no need to add it to the required components list.
The architecture flag for mpy-cross is now set for RISC-V targets, as it
was previously set only for Xtensa targets (and it relied on a string
comparison rather than using the appropriate configuration variable).
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit changes the gchelper implementation in use for RV32-based
targets (ESP32C3, ESP32C6) from the generic one written in C to the one
written in assembler that is specific to the CPU in question.
The native implementation is already exercised on most CI builds as it
is used by the QEMU port to compile and test the RV32 target.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Rather than having Make calling CMake to generate a list of submodules and
then run a Make target (which is complex and prone to masking other
errors), implement the submodule update logic in CMake itself.
Internal CMake-side changes are that GIT_SUBMODULES is now a CMake list,
and the trigger variable name is changed from ECHO_SUBMODULES to
UPDATE_SUBMODULES.
The run is otherwise 100% a normal CMake run now, so most of the other
special casing can be removed.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Similar to parent commit, allow using USB Serial/JTAG pins for other
purposes but only if this feature is disabled in the build config.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
When we don't use USB JTAG, we want to use the two USB pins (D+/D-) as
GPIO. So, do clear USB_SERIAL_JTAG_USB_PAD_ENABLE when USB SERIAL JTAG is
not enabled
Signed-off-by: Garry W <32130780+garywill@users.noreply.github.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The ESP32 PWM (LEDC) timer wasn't correctly stopped. `ledc_timer_rst()` is
for resetting the timer counter to zero, not for stopping the timer.
The correct way to stop a pwm timer is to pause it, then configure it with
`deconfigure = true`.
Signed-off-by: garywill <garywill@disroot.org>
This increases binary size by about 4KB on C3, probably a bit less on S2.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
These micros don't have full SDMMC host support, but they can initialise
the SDCard in SPI mode.
A bit limited on C3 and C6 as they only have one host SPI peripheral.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Previously ESP32-S3 SDMMC could only use fixed pin assignments, however the
ESP-IDF defaults don't match common boards. The chip also supports using
GPIO Matrix to assign any pin.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Reverts workaround added in acbdbcd9.
According to the linked ESP-IDF issue this was only a problem for ESP-IDF
V5.0.x, and support for versions older than V5.2 was dropped in 6e5d8d009.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Removes redundant metadata from each, shouldn't otherwise change
any build output.
Reverts the split originally added in e4650125.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>