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>
This reduces inconsitencies between esp32 and other ports.
According to the discussion in #10817.
Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com>
Previously, the navigation ended up messy when the (long) description of
the item became used as a 2nd level header, meaning that it was placed in
the navigation. Check for this when generating cpydiff so that new cases
don't sneak in unnoticed.
Signed-off-by: Jeff Epler <jepler@gmail.com>
The heading character for the difference title was always "~", but items
had been added which had just a single heading level. This made the
generated table of contents confused about heading levels, because heading
levels are not fixed in rst, but are inferred from the order they appear in
the document.
Signed-off-by: Jeff Epler <jepler@gmail.com>
In the syntax_space cpydiff, all the warnings were shown after the other
output. This is because the output always showed all of stdout first and
all of stdout second.
By running Python in unbuffered mode and using `stderr=STDOUT`, the two
streams are interleaved in exactly the order they're printed, so the
SyntaxWarnings are interleaved with the other output.
By using the `encoding=` argument of Popen, the need to explicitly convert
to utf-8 is avoided. The encoding of the input also becomes utf-8 in this
case, which all the test cases are (well, they're all ASCII, I think). As
in `run-tests.py`, setting PYTHONIOENCODING ensures the Python
interpreter's input and output are in utf-8, which is not always the case,
especially on Windows systems.
I spot-checked the generated doc pages and they all seemed to make sense
still.
Signed-off-by: Jeff Epler <jepler@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 groups non-decimal values by fours, such as bbb_bbbb_bbbb. It also
supports `{:_d}` to use underscore for decimal numbers (grouped in threes).
Use of incorrect ":,b" is not diagnosed.
Thanks to @dpgeorge for the suggestion to reduce code size.
Signed-off-by: Jeff Epler <jepler@gmail.com>
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>
There's no specified behaviour for what should happen if both CPUs call
`lightsleep()` together, but the latest changes could cause a permanent
hang due to a race in the timer cleanup code. Add a flag to prevent hangs
if two threads accidentally lightsleep, at least.
This allows the new lightsleep test to pass on RPI_PICO and RPI_PICO2, and
even have much tighter time deltas. However, the test still fails on
wireless boards where the lwIP tick wakes them up too frequently.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Stop using soft timer for `mp_wfe_or_timeout`. Now uses the alarm pool
again as issues with this code have been fixed. This resolves the "sev"
issue that stops the RP2350 going idle.
Also, change the lightsleep code to use the hardware timer library and
alarm 1, as alarm 2 is used by and soft timers and alarm 3 is used by the
alarm pool.
Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
This commit adds a new network multi-test which sends a burst of UDP
packets from the client, and the server doesn't recv them until they have
all been sent.
Signed-off-by: Damien George <damien@micropython.org>
The bare-metal lwIP socket interface is currently quite limited when used
for UDP streams, because it only allows one outstanding incoming UDP
packet. If one UDP packet is waiting to be socket.recv'd and another one
comes along, then the second one is simply dropped.
This commit implements a queue for incoming UDP and raw packets. The queue
depth is fixed at compile time, and is currently 4.
This allows better use of UDP connections, eg more efficient. It also
makes DTLS work better which sometimes has a queue of UDP packets (eg
during the connection phase).
Signed-off-by: Damien George <damien@micropython.org>
There is a bit of ambiguity as to how the prefix of the git subject line
should look like. Eg `py/vm: ...` vs `py/vm.c: ...` (whether the extension
should be there or not).
This commit makes the existing CI check of the git commit message stricter,
by applying extra rules to the prefix, the bit before the : in the subject
line. It now checks that the subject prefix:
- doesn't start with unwanted bits: ., /, ports/
- doesn't have an extension: .c, .h, .cpp, .js, .rst or .md
Full error messages are given when a rule does not pass.
This helps to reduce maintainer burden by applying stricter rules, to keep
the git commit history consistent.
Signed-off-by: Damien George <damien@micropython.org>
Otherwise if the target has certain files/directories (such as "test") in
its filesystem then these interfere with the unit tests.
Signed-off-by: Damien George <damien@micropython.org>
The Let's Encrypt root certificate has changed so needs updating in these
tests.
Also use `bytes.fromhex()` instead of `binascii.unhexlify()`, to eliminate
the need for the `binascii` module. Both of these features are controlled
by `MICROPY_PY_BUILTINS_BYTES_HEX`, so the test will still work on the same
targets that it previously did.
Signed-off-by: Damien George <damien@micropython.org>
Avoids the new Wunterminated-string-literal when compiled with gcc 15.1.
It would be preferable to just disable this warning, but Clang
-Wunknown-warning-option kicks in even when disabling warnings so this
becomes fiddly to apply.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Avoids the new Wunterminated-string-literal when compiled with gcc 15.1.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Avoids the new Wunterminated-string-literal when compiled with gcc 15.1.
Also split out the duplicate string to a top-level array (probably the
duplicate string literal was interned, so unlikely to have any impact.)
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
IOBase is quite an important building block of other parts of the system,
such as `mpremote mount` and running .mpy and native tests.
This feature costs +244 bytes of firmware size on ARM Thumb2 architectures,
which is worth the cost for the extra features it enables.
The change here means that `io.IOBase` is now enabled on all nrf boards,
(previously it was only nRF52840 and nRF9160) and also B_L072Z_LRWAN1
(there is no change to other ports or boards).
Signed-off-by: Damien George <damien@micropython.org>
This means the fix from dd1465e7 will also apply to stm32 and mimxrt ports
that use CYW43.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This is only a surface level refactor, some deeper refactoring would be
possible with (for example) the SDIO interface in mimxrt and stm32, or the
BTHCI interface which is is similar on supported ports. But sticking to
cases where the macros are the same across all ports.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
These both need to fit a pointer, so make them `intptr_t` and `uintptr_t`,
similar to other ports.
Signed-off-by: Anton Blanchard <antonb@tenstorrent.com>
This commit adds the required functionality for a peripheral to create
services at runtime, using `BLE.register_services()`.
The feature is enabled on the nrf52840dk_nrf52840 board.
Note that the `CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION=n` option must be used
so that BLE notifications/indications can be sent even if not subscribed.
Signed-off-by: danicampora <danicampora@gmail.com>
This ensures the check in MP_NLR_JUMP_HEAD works as expected and
nlr_jump_fail gets called so we get a bit better error message.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>