Recent MSVC versions have changed the definition of NAN to a non-constant
expression! This is a bug, C standard says it should be a constant.
Good explanation and workaround at: https://stackoverflow.com/a/79199887
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The micro:bit board (and probably other boards using the music or display
module) locked up on soft reboot. Reason was a buffer overflow caused by
an index counter, which was not reset on soft_reboot.
That's fixed in this commit. Tested with a micro:bit board, performing a
series of soft reboots.
Signed-off-by: robert-hh <robert@hammelrath.com>
This fixes a bug in FrameBuffer.ellipse where it goes into an infinite loop
if both radii are 0.
This fixes the bug with a simple pre-check to see if both radii are 0, and
in that case sets a single pixel at the center. This is consistent with the
behaviour of the method when called with just one of the radii set to 0,
where it will draw a horizontal or vertical line of 1 pixel width.
The pixel is set with setpixel_checked so it should handle out-of-bounds
drawing correctly.
This fix also includes three new tests: one for the default behaviour, one
for drawing out-of-bounds, and one for when the sector mask is 0.
Fixes issue #16053.
Signed-off-by: Corran Webster <cwebster@unital.dev>
Closes#13178.
TouchPad confirmed working on both chips, and fixes the the ESP32-S3
reading constant max value. Was unable to reproduce the bug on ESP32-S2 but
this may be due to my test setup, and it still works with the fix.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
ESP32 has hardware V1 and S2/S3 has V2, and future chips
may have different versions.
This should still compile to the same binary before and after.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
- Previously the call to esp_wifi_set_channel() would be immediately
overridden by calling esp_wifi_config(...) with the previous channel set.
- AP interface doesn't seem to need more than esp_wifi_config(...) to work.
It will automatically configure 40MHz bandwidth and place the secondary
channel using similar logic to what was being explicitly calculated here.
- However, calling esp_wifi_set_channel() on the STA interface is necessary
if using this interface with ESP-NOW (without connecting to an AP). So
the esp_wifi_set_channel() call is kept in for this purpose. Without
this, tests/multi_espnow/70_channel.py fails.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Configuring the AP for cyw43 writes to some buffers that are only sent to
the modem when the interface is brought up. This means you can't configure
the AP after calling active(True), the new settings seem to be accepted but
the radio doesn't change.
This is different to the WLAN behaviour on other ports. The esp8266 port
requires calling active(True) on the AP before configuring, even.
Fix this by bouncing the AP interface after a config change, if it's
active. Configuring with active(False) still works the same as before.
Adds a static variable to track interface active state, rather than relying
on the LWIP interface state. This is because the interface state is updated
by a driver callback and there's a race: if code calls active(True) and
then config(a=b) then the driver doesn't know it's active yet and the
changes aren't correctly applied.
It is possible this pattern will cause the AP to come up briefly with the
default "PICOabcd" SSID before being reconfigured, however (due to the
aforementioned race condition) it seems like this may not happen at all
before the new config is applied.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The `num_stas` was uninitialised and if it happened to take the value 0
then no results were returned. It now has the correct maximum value.
Signed-off-by: Damien George <damien@micropython.org>
This function is documented to return True if any stations are connected to
the AP. Without this fix it returns True whenever the driver has brought
the AP interface up.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Commit f4ab9d9247 inadvertently broke some
Python block devices, for example esp32 and stm32 SDCard classes. Those
classes return a bool from their `readblocks` and `writeblocks` methods
instead of an integer errno code. With that change, both `False` and
`True` return values are now be interpreted as non-zero and hence the block
device call fails.
The fix in this commit is to allow a bool and explicitly convert `True` to
0 and `False` to `-MP_EIO`.
Signed-off-by: Damien George <damien@micropython.org>
Because the `ai_canonname` field is subsequently used.
ESP32_GENERIC_S3 (at least) crashes with IDF 5.2.3 without this set.
Signed-off-by: Damien George <damien@micropython.org>
This fixes a regression in db59e55fe7: prior
to that commit `mpremote` supported trailing slashes on the destination of
a normal (non-recursive) copy.
Add back support for that, with the semantics that a trailing slash
requires the destination to be an existing directory.
Also add a test for this.
Signed-off-by: Damien George <damien@micropython.org>
mpremote error messages now go to stderr, so make sure stdout is flushed
before printing them.
Also update the test runner to capture error messages.
Signed-off-by: Damien George <damien@micropython.org>
Seemingly ESP-IDF incorrectly marks RTC FAST memory region
as MALLOC_CAP_EXEC on ESP32-S2 when it isn't. This memory is
the lowest priority, so it only is returned if D/IRAM is exhausted.
Apply this workaround to treat the allocation as failed if it gives us
non-executable RAM back, rather than crashing.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The cleanup in 548babf8 relies on some functions not available in older
ESP-IDF. Temporarily restore them, until we drop support for ESP-IDF <5.2.
PWM functionality should end up the same regardless of ESP-IDF version, and
also no different from MicroPython V1.23.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This was missed in 628abf8f25. The the bug
was that, when IPv6 is enabled, the `sizeof(ip_addr_t)` is much larger than
IPv4 size, which is what's needed for IGMP addressing.
Fixes issue #16100.
Signed-off-by: Damien George <damien@micropython.org>
In `deque_subscr()`, if `index_val` equals `self->alloc`, the index
correction `index_val -= self->alloc` does not execute, leading to an
out-of-bounds access in `self->items[index_val]`.
The fix in this commit ensures that the index correction is applied
whenever `index_val >= self->alloc`, preventing access beyond the allocated
buffer size.
Signed-off-by: Jan Sturm <jansturm92@googlemail.com>
The PIC16 port didn't catch up with the other ports, so it required a bit
of work to make it build with the latest version of XC16.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit fixes PWM configuration across C3, C6, S2 and S3 chips, which
was broken by 6d799378ba. Without this fix
the PWM frequency is limited to a maximum of 2446Hz (on S2 at least).
Signed-off-by: Andrew Leech <andrew@alelec.net>
The variable `written` was being used before it was defined in the
`fs_writefile()` method of the Transport class. This was causing an
`UnboundLocalError` to be raised when the `progress_callback` was not
provided.
Fixes issue #16084.
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
This brings in:
- requests improvements with overriding headers
- use non-u versions of built-in modules, including asyncio
- fix to logging so StreamHandler calls parent constructor
- various fixes to usb-device packages
- fixes to lora sx126x and sx127x drivers
- improvements to unix-ffi/sqlite3
- support additional gap_connect arguments in aioble
Signed-off-by: Damien George <damien@micropython.org>
This commit enables the implementation of alternative mbedTLS cryptography
functions, such as ECDSA sign and verify, in pure Python. Alternative
functions are implemented in Python callbacks, that get invoked from
wrapper functions when needed. The callback can return None to fall back
to the default mbedTLS function.
A common use case for this feature is with secure elements that have
drivers implemented in Python. Currently, only the ECDSA alternate sign
function wrapper is implemented.
Tested signing with a private EC key stored on an NXP SE05x secure element.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This is necessary for mbedTLS callbacks that do not carry any user state,
so those callbacks can be customised per SSL context.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Because VfsLfs2 uses time_ns to create timestamps for files, and for the
test to give consistent results it also needs to use this same function.
Signed-off-by: Damien George <damien@micropython.org>
Prior to this fix, `tests/extmod/vfs_lfs_mtime.py` would fail when run
after the `tests/ports/rp2/rp2_lightsleep.py` test, because
`time.time_ns()` would have a large and constant offset from `time.time()`.
Fix this by re-syncing the time-ns offset when coming out of lightsleep.
Signed-off-by: Damien George <damien@micropython.org>
This previously passed on some targets that automatically import the
`machine` module in `boot.py`.
Signed-off-by: Damien George <damien@micropython.org>
The LwIP interface is removed in wiznet5k_deinit() which is called as part
of the init sequence. Therefore, if using mDNS, then the interface will
need to be re-added when bringing the interface up.
Additionally, this allows to set the hostname from MicroPython code prior
to bringing the interface up and mDNS responding to the (new) hostname.
This allows the hostname to be configured and saved on the flash or be
based on dynamic information such as the MAC or unique_id().
Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
Getting this test running on stm32- and mimxrt-based boards requires adding
a small delay after constructing the UART so that the initial idle frame
has time to be transmitted before the test starts.
Also, the timing margin needs to account for an additional 1-bit worth of
time on some MCUs.
Thanks to @robert-hh for the esp32, mimxrt and samd settings.
Signed-off-by: Damien George <damien@micropython.org>
The port configuration file tagged callable pointers' LSB on both Arm
and RISC-V variants. This is needed on Arm due to Thumb/Thumb2
code addresses having their LSB set, but on RISC-V this is not required.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Some ports (eg stm32) configure the FAT driver differently (eg with
multi-partition support) and that leads to a slightly different sequence of
block reads, compared to other configurations (eg rp2).
Comment out the printing in `readblocks()` so the tests are deterministic
(the printing is still useful for debugging).
Signed-off-by: Damien George <damien@micropython.org>
This is a fix for issue #15944, and handles corner cases in the FrameBuffer
code when using stride values where the last line's stride may extend past
the end of the underlying buffer. This commit includes extra tests for
these corner cases.
For example a GS8 format FrameBuffer with a width of 8, height of 2 and
stride of 10 should be able to fit into a buffer of size 18 (10 bytes for
the first horizontal line, and 8 bytes for the second -- the full 10 bytes
are not needed).
Similarly a 1 by 9 FrameBuffer in MONO_VLSB format with a stride of 10
should be able to fit into a buffer of length 11 (10 bytes for the first
8 lines, and then one byte for the 9th line.
Being able to do this is particularly important when cropping the corner of
an existing FrameBuffer, either to copy a sprite or to clip drawing.
Signed-off-by: Corran Webster <cwebster@unital.dev>
This reverts commit c94a3205b0.
The idea behind this reverted commit was that it allowed to reconfigure the
UART to change only the baudrate, which is important in the context of a
PPP connection where the baudrate may be changed as part of the protocol.
Also, other ports like the rp2 port have this behaviour, where individual
parameters of the UART can be changed with the `.init()` method.
But this commit was no good for a few reasons:
1. It's a subtle breaking change to the UART API, because existing code
that constructs or initialises a UART with just the baudrate would
expect all other parameters to be reset to their defaults. But with
this commit those parameters would remain unchanged.
2. Constructing a UART like `UART(1, 9600)` also hits this code path of
only changing the baudrate and does not reset other parameters, which is
unexpected.
3. It doesn't support setting the baudrate via keyword, eg
`UART.init(baudrate=9600)`.
4. The `timeout_char` field is not updated when changing only the baudrate,
which can lead to unexpected timeouts when reading/writing.
Due to point (4), this commit broke the `tests/ports/stm32/uart.py` test,
the `uart.writechar(1)` has a timeout because the `uart.init(2400)` does
not set the `timeout_char` for the new baudrate.
Points (2)-(4) could be fixed, but point (1) (being a breaking change)
would remain as an issue. So the commit is reverted.
Signed-off-by: Damien George <damien@micropython.org>
Prior to this commit, when flushing a UART on the rp2 port, it returns just
before the last character is sent out the wire.
Fix this by waiting until the BUSY flag is cleared.
This also fixes the behaviour of `UART.txdone()` to return `True` only when
the last byte has gone out.
Updated docs and tests to match. The test now checks that UART TX time is
very close to the expected time (prior, it was just testing that the TX
time was less than the expected time).
Signed-off-by: Damien George <damien@micropython.org>
When descriptors are enabled, lookup of the `__get__`, `__set__` and
`__delete__` descriptor methods should not be delegated to `__getattr__`.
That follows CPython behaviour.
Signed-off-by: Damien George <damien@micropython.org>
This fixes a regression introduced in commit
4247921c4e, where this ring-buffer polling
was accidentally put inside the `#if MICROPY_HW_ESP_USB_SERIAL_JTAG`.
Signed-off-by: Andrew Leech <andrew@alelec.net>
NUM_GPIOS amd NUM_EXT_GPIOS are currently hardcoded in make-pins.py, which
makes it difficult to support SoCs with different pin count.
This commit generalises make-pins.py by passing in the pin count in via the
new arguments `--num-gpios` and `--num-ext-gpios`. These default to the
current values supported by Pico, namely 30/10. This can be changed with
PICO_NUM_GPIOS and PICO_NUM_EXT_GPIOS in `mpconfigboard.cmake`.
Signed-off-by: Damien George <damien@micropython.org>
Add support for 32 and 48 pin variants of RP2350.
Add new `PIO.gpio_base()` method, mirroring the Pico SDK.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Damien George <damien@micropython.org>
This commit separates various build settings and include files that are
specific to RP2040 and RP2350, and uses the aon_timer interface instead of
rtc, to work across both MCU variants.
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Phil Howard <phil@gadgetoid.com>
Two new bits were added to the ctrl register, and existing bits were
shifted, so use DMA_CH0_CTRL_TRIG_xxx constants to generalise the code.
Signed-off-by: Damien George <damien@micropython.org>
This isn't fully working, the CPU often wakes up early. That will be fixed
when a newer version of pico-sdk is released.
Signed-off-by: Damien George <damien@micropython.org>
Check a target exists before accessing properties. Otherwise
usermod_gather_sources would recurse into garbage property names and break.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
A long time ago when there was only the `stm` port, Ctrl-C would trigger a
preemptive NLR jump to break out of running code. Then in commit
124df6f8d0 a more general approach to
asynchronous `KeyboardInterrupt` exceptions was implemented, and `stmhal`
supported both approaches, with the general (soft) interrupt taking
priority.
Then in commit bc1488a05f `pyboard.py` was
updated with a corresponding change to make it issue a double Ctrl-C to
break out of any existing code when entering the raw REPL (two Ctrl-C
characters were sent in order to more reliably trigger the preemptive NLR
jump).
No other port has preemptive NLR jumps and so a double Ctrl-C doesn't
really behave any differently to a single Ctrl-C: with USB CDC the double
Ctrl-C would most likely be in the same USB packet and so processed in the
same low-level USB callback, so it's just setting the keyboard interrupt
flag twice in a row. The VM/runtime then just sees one keyboard interrupt
and acts as though only one Ctrl-C was sent.
This commit changes the double Ctrl-C to a single Ctrl-C in `pyboard.py`
and `mpremote`. That keeps things as simple as they need to be.
Signed-off-by: Damien George <damien@micropython.org>
Commit 69c25ea865 made raising `SystemExit`
do a soft reset (on bare-metal targets). This means that any test which is
skipped by a target (by raising `SystemExit`) will trigger a soft reset on
that target, and then it must execute its startup code, such as `boot.py`.
If the timing is right, this startup code can be unintentionally
interrupted by the test runner when preparing the next test, because the
test runner enters the raw REPL again via a Ctrl-C Ctrl-A ctrl-D sequence
(in `Pyboard.enter_raw_repl()`).
When this happens (`boot.py` is interrupted) the target may not be set up
correctly, and it may (in the case of stm32 boards) flash LEDs and take
extra time, slowing down the test run.
Fix this by explicitly waiting for the target to finish its soft reset when
it skips a test.
Signed-off-by: Damien George <damien@micropython.org>
Since the very beginning, the stm32 port (first called stm, then stmhal now
stm32) has had a special keyboard interrupt feature which works by using
PendSV to break out of any running code. This preemptive ctrl-C was added
long ago in commit 01156d510c.
The stm32 port still uses that code, and current does this:
- If ctrl-C is received on UART or USB then `mp_sched_keyboard_interrupt()`
is called (like all other ports) to set a flag for the VM to see, and
then the VM (or any loop calling `mp_handle_pending(true)`) will
eventually handle the `KeyboardInterrupt` exception, raising it via NLR.
- If another ctrl-C is received while the existing scheduled keyboard
interrupt is still pending (ie the VM has not yet processed it) then a
special hard NLR jump will activate, that preempts the calling code.
Within the PendSV interrupt the stack is adjusted and an NLR jump is made
to the most recent `nlr_push()` location. This is like a normal NLR
except it is called from an interrupt context and completely annihilates
the code that was interrupted by the IRQ.
The reason for the preemptive interrupt was to handle ctrl-C before the VM
was able to handle it. Eventually a mechanism (that's in use today by all
ports) was added to the VM and runtime to be able to check for pending
interrupts. Then the stm32 port was updated to use this mechanism, with a
fallback to the old preemptive way if a second ctrl-C was received (without
the first one being processed).
This preemptive NLR jump is problematic because it can interrupt
long-running instructions (eg store multiple, usually used at the end of a
function to restore registers and return). If such an instruction is
interrupted the CPU remembers that with some flags, and can resume the
long-running instruction when the interrupt finishes. But the preemptive
NLR does a long jump to different code at thread level and so the
long-running interrupt is never resumed. This leads to a CPU fault.
This fault has been previously reported in issues #3807 and #3842 (see also
issue #294). It's now possible to easily reproduce this problem, since
commit 69c25ea865. Running the test suite
over and over again on any stm32 board will eventually crash the board (it
can happen on a PYBv1.x, but it happens more regularly on PYBD-SF2/6).
The point is, a skipped test now soft resets the board and so the board
must run `boot.py` again. The test runner may then interrupt the execution
of `boot.py` with the double-ctrl-C that it sends (in `tools/pyboard.py`,
`enter_raw_repl()`) in order to get the board into a known good state for
the next test. If the timing is right, this can trigger the preemptive
PendSV in an unfortunate location and hard fault the board.
The fix in this commit is to just remove the preemptive NLR jump feature.
No other port has this feature and it's not needed, ctrl-C works very well
on those ports. Preemptive NLR jump is a very dangerous thing (eg it may
interrupt and break out of an external SPI flash operation when reading
code from a filesystem) and is obviously buggy.
With this commit, stm32 borads no longer hard fault when running the test
suite (but it does leave an issue, the tests can still interrupt `boot.py`
with a single ctrl-C; that will be fixed separately).
An alternative to this commit would be to clear the CPU state for the
long-running instruction as suggested in issue #3842. But it's much
simpler to just remove this code, which is now unnecessary and can have
other problems as per issue #294.
Signed-off-by: Damien George <damien@micropython.org>
This is a workaround for a bug in ESP-IDF where the configuration setting
for maximum active TCP sockets (PCBs) is not applied.
Fixes cases where a lot of short-lived TCP connections can cause:
- Excessive memory usage (unbounded number of sockets in TIME-WAIT).
- Much higher risk of stalled connections due to repeated port numbers. The
maximum number of active TCP PCBs is reduced from 16 to 12 to further
reduce this risk (trade-off against possibility of TIME-WAIT
Assassination as described in RFC1337).
This is not a watertight fix for the second point: a peer can still reuse a
port number while a previous socket is in TIME-WAIT, and LWIP will reject
that connection (in an RFC compliant way) causing the peer to stall.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Regression introduced in 337742f.
The hang occurs because the esp32 port was calling "from ISR" port-layer
functions to set/clear the interrupt mask. FreeRTOS kernel therefore
doesn't know the CPU is in a critical section. In taskYIELD() the riscv
port layer blocks after yielding until it knows the yield has happened, and
would block indefinitely if IRQs are disabled (until INT WDT triggers).
Moving to the "public" portENTER_CRITICAL/portEXIT_CRITICAL API means that
FreeRTOS knows we're in a critical section and can react accordingly.
Adds a regression test for this case (should be safe to run on all ports).
On single core CPUs, this should result in almost exactly the same
behaviour apart from fixing this case.
On dual core CPUs, we now have cross-CPU mutual exclusion for atomic
sections. This also shouldn't change anything, mostly because all the code
which enters an atomic section runs on the same CPU. If it does change
something, it will be to fix a thread safety bug.
There is some risk that this change triggers a FreeRTOS crash where there
is a call to a blocking FreeRTOS API with interrupts disabled. Previously
this code might have worked, but was probably thread unsafe and would have
hung in some circumstances.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
In idf v5.2.1 if the port flag is set it's validated even on jobs that
don't access hardware like clean. This causes the job to fail if device
isn't connected.
Signed-off-by: Andrew Leech <andrew@alelec.net>
This adds a -f/--force option to the "cp" command, which forces
unconditional copies, in particular does not check the hash.
Signed-off-by: Damien George <damien@micropython.org>
These tests are specifically for the command-line interface and cover:
- resume/soft-reset/connect/disconnect
- mount
- fs cp,touch,mkdir,cat,sha256sum,rm,rmdir
- eval/exec/run
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
Makes the filesystem command give standard error messages rather than
just printing the exception from the device.
Makes the distinction between CommandError and TransportError clearer.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Changes in this commit:
- Adds transport API `fs_hashfile` to compute the hash of a file with given
algorithm.
- Adds commands `mpremote <...>sum file` to compute and print hashes of
various algorithms.
- Adds shortcut `mpremote sha256sum file`.
- Uses the hash computation to improve speed of recursive file copy to
avoid copying a file where the target is identical.
For recursive copy, if possible it will use the board's support (e.g.
built-in hashlib or hashlib from micropython-lib), but will fall back to
downloading the file and using the local implementation.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
This introduces a Python filesystem API on `Transport` that is implemented
entirely with eval/exec provided by the underlying transport subclass.
Updates existing mpremote filesystem commands (and `edit) to use this API.
Also re-implements recursive `cp` to allow arbitrary source / destination.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
This is a step towards making the transport expose a Python API rather than
functions that mostly print to stdout.
Most use cases of `transport.eval()` are to get some state back from the
device, so have it return as a value directly by default.
Updates uses of `transport.eval()` to remove the parse argument where it
now isn't needed, make the `rtc` command use eval/exec, and update the
`mip` command to use eval's parsing.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
In MSVC debug builds with debug error reporting set to showing a dialog (to
allow attaching the debugger), any application which imports the logging
module and leaves the default handlers would result in this dialog because
logging.shutdown is called at exit and that flushes the default handler
which has stderr as its stream.
This commit fixes that by not fsync'ing stdin/out/err.
Also adds a comment related to checking whether a file is stdin/out/err,
which is difficult to fix properly.
Signed-off-by: stijn <stijn@ignitron.net>
Allowing passing keyword arguments to a native base's __init__, i.e.
`make_new` in the C code. Previously only positional arguments were
allowed.
The main trade-off in this commit is that every call to the native base's
`make_new` is now going to be preceded by a call to
`mp_map_init_fixed_table` even though most of what that does is unused and
instead it merely serves as a way to pass the number of keyword arguments.
Fixes issue #15465.
Signed-off-by: stijn <stijn@ignitron.net>
Uses newer TinyUSB synopsys/dwc2 driver for esp32s2 and esp32s3 rather than
the IDF tinyusb component. This allows re-use of other tinyusb integration
code and features shared between ports.
Signed-off-by: Andrew Leech <andrew@alelec.net>
The cyw43-driver uses `printf` by default for `CYW43_PRINTF`, but on the
rp2 port `printf` only goes to a UART output and not to USB CDC.
By defining `CYW43_PRINTF` to `mp_printf`, all the messages from the
cyw43-driver are seen on USB CDC.
For example this allows `network.WLAN().config(trace=1)` to show async
WALN events.
Signed-off-by: Damien George <damien@micropython.org>
The version of the assembly code for the GC helper that was committed
ended up being a version that had an opcode typo in.
The code was tested and working, but an undo operation too many when
cleaning up the file before committing checked in the wrong version.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The `MICROPY_FORCE_PLAT_ALLOC_EXEC` config option was made obsolete by
commit 9796625457, so remove it.
Signed-off-by: Damien George <damien@micropython.org>
Zephyr v3.7.0 added a new feature to allow getting devices by their
devicetree node labels. Use this feature in the MicroPython Zephyr port
to simplify constructing machine module objects, including Pin, SPI,
I2C, and UART. It's still possible to use the more verbose device names
(e.g., gpio@400ff040, i2c@40066000, spi@4002c000), but now we can also
use their devicetree node labels (e.g., gpiob, i2c0, spi0).
Node labels aren't standardized across all SoC families because they
generally try to follow their respective SoC hardware user manual naming
convention, however many boards define common labels for devices routed
to Arduino headers (e.g., arduino_i2c, arduino_serial, and arduino_spi).
That means I2C("arduino_i2c") will work on quite a few boards (>100 in
the main Zephyr tree).
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Refactors Zephyr device lookup operations into a common helper function
to reduce boilerplate code that was repeated in multiple modules.
Suggested-by: Damien George <damien@micropython.org>
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Updates the Zephyr port build instructions and CI to use the latest
Zephyr release tag.
Tested on frdm_k64f.
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Zephyr v3.4.0 changed the SPI chip select from a pointer to a struct
member to allow using the existing SPI dt-spec macros in C++.
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Zephyr v3.4.0 changed the declaration of the main function to return an
int to allow building Zephyr without the -ffreestanding compiler flag.
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Zephyr v3.2.0 deprecated the devicetree label property as a base
property, which had been used as the device name string for
device_get_binding(). The device name string is now the devicetree node
name appended with its unit-address. Update Zephyr port documentation
to reflect this change.
Signed-off-by: Maureen Helm <maureen.helm@intel.com>
Zephyr v3.2.0 deprecated include/zephyr/zephyr.h in favor of
include/zephyr/kernel.h since it only included that header.
Signed-off-by: Maureen Helm <maureen.helm@intel.com>
Zephyr v3.1.0 moved all public headers to include/zephyr. Updates a few
Zephyr include paths that were missed in
4fd54a4756.
Signed-off-by: Maureen Helm <maureen.helm@intel.com>
The ESP32 port contains a workaround to avoid having a certain function
in `py/parse.c` being generated incorrectly. The compiler in question
is not part of any currently supported version of ESP-IDF anymore, and the
problem inside the compiler (well, assembler in this case) has been
corrected a few years ago.
This commit removes all traces of that workaround from the source tree.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Necessary to fix "mpremote run" over hardware UART.
Bisect shows bug was introduced by d420b4e4, but looks like made more
complex by 01c046d2. Specifically: resetting and re-initialising the REPL
UART during soft reset clears the FIFO before it's done printing the "MPY:
soft reboot" line.
Fixed by adding a UART TX flush in the deinit path.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit fixes the addition of a stray separator before the number
when printing an MPZ-backed integer and the first group is three digits
long.
This fixes#8984.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
lwIP was recently updated in a89ac9e24a
to STABLE-2_2_0_RELEASE, and this introduced a change in the configuration
variable `DHCP_DOES_ARP_CHECK`, renaming it to `LWIP_DHCP_DOES_ACD_CHECK`.
This commit fixes the ports lwIP settings to use the new configuration
option.
Without this option, connecting to a WiFi access-point takes about 12.5
seconds. With this option (ie disabling DHCP ARP checks) connecting takes
about 4 seconds.
Tested on an RPI_PICO_W and PYBD_SF2.
Signed-off-by: Damien George <damien@micropython.org>
This tracing was originally needed for three reasons:
1. To trace object/raw-code pointers embedded in native code, eg from
@micropython.native functions.
2. To trace pointers to BSS/rodata from relocated viper code.
3. For libffi tracing.
The tracing in point 1 was made unnecessary long ago in commit
7d4b6cc868 (see also commit
bbccb0f630 which removed scanning of native
code on the esp8266 port).
Since the previous commit, point 2 is no longer needed.
For point 3, this was made unnecessary in the recent commit
9796625457.
Signed-off-by: Damien George <damien@micropython.org>
- Code size saving as all of these functions are very similar.
- Resolves the "TODO" of the plain read and write functions not propagating
errors. An error in the underlying block device now causes VFatFs to
return EIO, for example.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
A positive result here can result in eventual memory corruption
as littlefs expects the result of a cache read/write function to be
0 or a negative integer for an error.
Closes#13046
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Most ports using TinyUSB now schedule the USB tasks from the USB interrupt.
This commit updates the renesas-ra port to use this new pattern.
Signed-off-by: Andrew Leech <andrew@alelec.net>
The renesas-ra port board definitions contain auto-generated files which
are not easy to understand for someone unfamiliar with the port. This
commit adds some notes to the README to assist other developers who want to
work on these.
The configuration.xml file for the `ARDUINO_PORTENTA_C33` was provided by
@iabdalkader.
Signed-off-by: Andrew Leech <andrew@alelec.net>
The UART driver enables a pull-up on RX/CTS pins by default. This can
cause UART to fail to receive in certain situations, eg with RS485
transceivers.
This commit adds compile-time configuration options to set the pull mode on
the RX and CTS pins of each UART.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit adds the `VIRT_RV32` board to the list of targets for
calculating code size changes as part of the CI pipeline.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit adds the Qemu-based RISC-V 32 bits `VIRT_RV32` board to the
list of ports/boards to be built for measuring code size changes.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This updates the Ubuntu OS image the code size CI tasks run on, from
20.04-LTS to 22.04-LTS. This is needed because 20.04 didn't have
packages that are needed to build RISC-V 32 code.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
When testing the Unix port with FFI tests enabled, the FFI helper
library that's built as part of the testing process is not removed after
the tests session end.
This commit adds the built library to the gitignore list, so it doesn't
mark the sourcetree as dirty if a test run for the Unix port was started
in the past.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit clears the upper 32 bits of returned `uint32_t` values,
which are handled as `unsigned int`s by the MicroPython runtime and
thus could be extended to 64 bits on some platforms.
RV64 holds 32-bit values as signed integers when held in registers, but
the code handling the FFI unsigned int case did not take this into
account. That introduced test failures when a 32-bit value had its most
significant bit set, as when performing the value extension from 32 to
64 bits, the upper half of the value would be filled with ones.
On 32 bit platforms this change should be converted to a no-op, and
on other 64 bit platforms that aren't RISC-V it shouldn't hurt as the
value being manipulated is expected to only hold valid bits in its lower
half.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit lets the RV64 port use the version of libffi that is bundled
as a submodule in the MicroPython source tree, as the packaged libffi
library coming from Ubuntu's RISC-V repository trashes foreign function
call results on exit.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit removes custom FFI closures alloc/free functions, in favour
of using the tracked allocation facility to allocate memory for FFI
callback objects.
This stems from linking issues in the Arm port when updating LibFFI to
the latest stable version, as the overridden alloc/free functions didn't
replace LibFFI's (unlike in other ports). The original code did no
effective cleanup for allocated callback objects, so there is no real
impact when switching allocation strategy.
The tracked allocation feature used to be enabled only if the Bluetooth
stack integration was enabled. This commit also enables tracked
allocation support if FFI support is enabled.
Co-authored-by: Damien George <damien@micropython.org>
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Libffi is updated to the latest stable version (v3.4.6) as the version
of libffi that was linked by the repository predates the introduction of
RISC-V processors (both 32 and 64 bits).
This is necessary as the packaged version of libffi used by the CI for
RISC-V 64 turned out to simply not work correctly, whilst a source-built
version of libffi worked just fine.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit adds a new `RingIO` type which exposes the internal ring-buffer
code for general use in Python programs. It has the stream interface
making it similar to `StringIO` and `BytesIO`, except `RingIO` has a fixed
buffer size and is automatically safe when reads and writes are in
different threads or an IRQ.
This new type is enabled at the "extra features" ROM level.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This is for boards not covered by the Olimex ESP32 PoE implementation. The
major setting is about the PHY interface configuration.
Tested with esp-idf v5.0.4 and Olimex ESP32 EVB boards.
Signed-off-by: shiggy <mail@shiggytech.de>
Added the "long" modffi tests. The tests could not be added to the existing
ffi_types test because two .exp files were required for the 32-bit and
64-bit results. Code common to both the ffi_types and type "long" tests was
factored into ffi_int_base. ffi_types was renamed to ffi_int_types to group
the related tests under the "ffi_int" prefix.
Signed-off-by: Michael Sawyer <mjfsawyer@gmail.com>
Casting an ffi_arg to a signed int may truncate the value. E.g., when the
ffi_arg is 64-bit and the signed int is 32-bit. Also, casting an ffi_arg
to a larger signed type will not sign extend the value. E.g., when the
ffi_arg is 32-bit and the larger signed type is int64_t. If the value is
signed, it should be cast to ffi_sarg, which is the same size as ffi_arg.
Signed-off-by: Michael Sawyer <mjfsawyer@gmail.com>
Native .mpy files targetting armv6m (eg RP2040) cannot currently have more
than about 2kiB of native code (between the start of the file and the init
function).
This commit fixes that by using bigger jumps to jump to the init function.
Signed-off-by: Damien George <damien@micropython.org>
The Unix port's Arm target CI steps have been updated to be more in
line with the other targets (the MicroPython binary doesn't need an
environment variable to be set in order to run now).
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The FFI helper definition was accidentally omitted when committing the
necessary shell code for building RV64 Unix builds in the CI
environment.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The Unix port's MIPS target CI steps have been updated to be more in
line with the other targets (the MicroPython binary now runs as a
dynamic executable), and the test exceptions for ffi have been lifted.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Removing the now-unused (see previous commit for details) `--write-exp` and
`--list-tests` options helps to simplify the rather complex logic in
`run-tests.py`.
Signed-off-by: Damien George <damien@micropython.org>
With the recent qemu (d9a0fdda9a and
0426934969) and zephyr
(05cad7b56f) changes to how their tests are
run, two things became unused:
- The tinytest framework, which embedded a set of tests and their expected
output within firmware, so these tests could be run stand-alone.
- The `--write-exp` and `--list-tests` options to `tests/run-tests.py`,
which were needed primarily to generated the expected test output for
tinytest (also the associated `tests/run-tests-exp.py/.sh` scripts are
now unused).
This commit removes the tinytest component and all its helper code. This
eliminates a maintenance burden.
Signed-off-by: Damien George <damien@micropython.org>
If GIL is disabled then there's threat of a race condition if some other
code specifically requests USB processing (i.e. to unblock stdio), while
a scheduled TinyUSB callback is already running on another thread.
Relies on the change in the parent commit, where scheduler is restricted
to main thread if GIL is disabled.
Fixes#15390 - "TinyUSB callback can't recurse" exceptions on rp2 when
using _thread module and USB serial I/O.
Adds a unit test for stdin functioning correctly in threads (fails on rp2
port without this fix).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Otherwise it's very difficult to reason about thread safety in a
scheduler callback, as it can run at any time on any thread - including
racing against any bytecode operation on any thread.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This change helps detect if the filesystem is invalid, by also including
the first mount attempt within the try-except. Then the FAT is reformatted
if needed.
Fixes issue #15779.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
The `#if` check only checks that `MICROPY_PY_NETWORK_CYW43` and
`MICROPY_HW_PIN_EXT_COUNT` are defined. This is a reasonable assumption
for the Pico W, but causes conflicts if someone wants to attach an external
IO expander to their Pico W and have its pins appear as Pin objects.
This commit addresses this by adding the additional checks, letting board
builds include wireless but separately choose whether the external IO pins
come from the cyw43 or not.
Signed-off-by: Christopher Parrott <chris@pimoroni.com>
Original commit was by @millosolomillo from 2022, but CI no longer accepts
their auto-generated GitHub commit email...
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The STM32F429DISC board definition did not have DAC enabled, however the
micro/board supports it so this commit enables the feature.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
Some boards like the nrf52840dk crash immediatelly after boot when
k_yield() is executed in this function. It also makes the REPL randomly
lock up on other boards like the nucleo_wb55rg.
Signed-off-by: danicampora <danicampora@gmail.com>
So that certain tests can be skipped when running on this target. These
thread tests do not pass because the zephyr port cannot create more than 4
threads at once.
Signed-off-by: Damien George <damien@micropython.org>
So that more tests can run successfully, and so users by default have more
heap for applications. Thin minimal configuration still has a 16k GC heap.
Signed-off-by: Damien George <damien@micropython.org>
All these features are enabled at the
`MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES` level, and are required to get
more of the thread tests passing.
Signed-off-by: danicampora <danicampora@gmail.com>
The standard Zephyr console implementation doesn't make use of
`tty_set_rx_timeout()` and therefore all the functions to receive
characters block indefinitely until data is received (including
`console_read()`).
This commit also releases the GIL where it applies, e.g. the REPL and the
time sleep functions.
Signed-off-by: danicampora <danicampora@gmail.com>
This commit implements the `_thread` module on the zephyr port.
Due to the fact that we are still using a rather old version of Zephyr,
`CONFIG_DYNAMIC_THREAD` is not available and therefore the stack for
threads cannot be allocated dynamically, only at compile time. So for the
time being and for the purpose of this commit, a maximum of 4 Zephyr
threads (besides the main thread) can be created. Once we manage to update
to the latest version of Zephyr this won't be a problem anymore.
Configuration for the nrf52840dk is added as part of this change, because
this board was used to test the threading support.
The Zephyr option `CONFIG_THREAD_CUSTOM_DATA` is used to enable threading
on a per board basis. The `thread.conf` file is added as a convenient way
to enable threading.
Signed-off-by: danicampora <danicampora@gmail.com>
Set the UF2 firmware images family to Microchip SAMD21 or SAMD51. This
helps tools such as file to identify built firmware.
Signed-off-by: Alexandre Iooss <erdnaxe@crans.org>
Do NOT use `mp_hal_delay_us()` for short delays. This was initially done
to make short delays precise, but it does not allow for scheduling. Leave
using `mp_hal_delay_us()` to user code if needed.
Signed-off-by: robert-hh <robert@hammelrath.com>
The upper 32 bit of the 64 bit ticks register was taken before disabling
the interrupts. That may have caused a wrong return values. Besides that,
the function may cause trouble when called in an IRQ context, because it
unconditionally enables IRQ.
Signed-off-by: robert-hh <robert@hammelrath.com>
Fixes a compile error if STM32 port is compiled with:
make BOARD=(..) MICROPY_PY_LWIP=1 MICROPY_PY_LWIP_SLIP=1
`sio_send()` and `sio_tryread()` now use `mp_get_stream`.
Signed-off-by: Carl Treudler <cjt@users.sf.net>
As reported in #14430 the Xtensa compiler can add R_XTENSA_ASM_EXPAND
relocation relaxation entries in object files, and they were not
supported by mpy_ld.
This commit adds handling for that entry, doing nothing with it, as it
is only of real use for an optimising linker.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
- Present the default build dependencies in one place at the top, and make
a separate section about building standalone.
- Add steps for the "minimal" variant as well.
- Document that building standalone requires autoconf and libtool.
- Allow MICROPY_STANDALONE to be set as an environment variable.
Fixes issue #11313.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The printed type for stdio streams indicates "FileIO", which is a binary IO
stream. Stdio is not binary by design, and its printed type should
indicate a text stream. "TextIOWrapper" suits that purpose, and is used
by VfsPosix files.
Signed-off-by: timdechant <timdechant.git@gmail.com>
Currently both the qemu-arm and qemu-riscv ports share a lot of code and
functionality. This commit merges the qemu-riscv port into the qemu-arm
port. The only real differences between the two are the toolchains used to
build the code, and the initialisation/startup framework. Everything else
is pretty much the same, so this brings the following benefits:
- less code duplication
- less burden on maintenance
- generalised qemu port, could in the future support other architectures
A new board `VIRT_RV32` has been added to the qemu-arm port which is the
existing RISC-V board from the qemu-riscv port. To build it:
$ make BOARD=VIRT_RV32 repl
To cleanly separate the code for the different architectures, startup code
has been moved to ports/qemu-arm/mcu/<arch>/.
Signed-off-by: Damien George <damien@micropython.org>
Now that some ports support multiple architectures (eg esp32 has both
Xtensa and RISC-V CPUs) it's no longer possible to set mpy-cross flags
based on the target, eg `./run-tests.py --target esp32`. Instead this
commit makes it so the `-march=xxx` argument to mpy-cross is detected
automatically via evaluation of `sys.implementation._mpy`.
Signed-off-by: Damien George <damien@micropython.org>
Regression introduced by 5e692d04 now at MICROPY_HW_USB_CDC is set.
The ARDUINO_NANO_ESP32 specifically builds shared/tinyusb/mp_usb_cdc.c
for the 1200bps reset behaviour. However MicroPython esp32 doesn't yet
use the rest of the shared/tinyusb functionality.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This fixes issue of ESP32-S3 switching its config over to USB serial/JTAG
instead of native USB.
The the existing logic was hard to follow, adding this config macro makes
it easier to see which USB is in use and to have board definitions that
enable/disable different USB levels.
This commit also drops (nominal) support for manually setting
CONFIG_ESP_CONSOLE_USB_CDC in sdkconfig. No included board configs use this
and it didn't seem to work (if secondary console was set to the default USB
Serial/JTAG then there is no serial output on any port, and if secondary
console was set to None then linking fails.) Can be re-added if there's a
use case for it.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Regression in 0a11832cd in IDF 5.0.x where macro
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED is not defined.
With this patch, ESP32-S3 still USB Serial/JTAG incorrectly (now on all
ESP-IDF versions).
Closes#15701
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Allows mpremote file transfer to work correctly when mpremote is used over
the ST-link USB/UART REPL port.
Fixes issue #8386.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This allows UART RX to function while flash erase/writes operations are
under way, preventing lost serial data so long as it fits in the UART RX
buffer.
This enables (among other things) mpremote to successfully copy files to
boards that use a UART REPL.
Enable via the following option placed in `mpconfigboard.mk`:
MICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM = 1
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This allows enabling lwIP debugging output. For example, to enable PPP
debugging add the following to `mpconfigboard.h`:
#define LWIP_DEBUG 1
#define PPP_DEBUG LWIP_DBG_ON
Signed-off-by: Damien George <damien@micropython.org>
When timeout=0 (non-blocking mode) the UART should still wait for each
character to go out. Otherwise non-blocking mode with CTS enabled is
useless because it can only write one character at a time.
Signed-off-by: Damien George <damien@micropython.org>
This commit adds a new `network.PPP` interface which works on any port that
has bare-metal lwIP, eg rp2, stm32, mimxrt.
It has been tested on stm32. A board needs to enable
`MICROPY_PY_NETWORK_PPP_LWIP` and then it can use it as follows:
import network
ppp = network.PPP(uart)
ppp.connect()
while not ppp.isconnected():
pass
# use `socket` module as usual, etc
ppp.disconnect()
Usually the application must first configure the cellular/etc UART link to
get it connected and in to PPP mode first (eg ATD*99#), before handing over
control to `network.PPP`.
The PPP interface automatically configures the UART IRQ callback to call
PPP.poll() on incoming data.
Signed-off-by: Damien George <damien@micropython.org>
This updates lwIP from STABLE-2_1_3_RELEASE, which was released in November
2021. The latest STABLE-2_2_0_RELEASE was released in September 2023.
Signed-off-by: Damien George <damien@micropython.org>
These all require hardware connections, so live in a different directory.
Except for the IRQ_BREAK test of ESP32 devices a single UART with loopback
is sufficient.
General:
SAMD21: Due to the limited flash size only SAMD21 devices with external
flash support uart.irq().
IRQ_BREAK:
ESP32 needs different UART devices for creating and sensing a break.
Lacking a second UART the test is skipped for ESP32S2 and ESP32C3. RP2
does not pass the test reliable at 115200 baud, reason to be found.
Thus the upper limit is set to 57600 Baud.
Coverage:
esp32 pass when different UART devices are used.
rp2 pass up to 57600 baud
IRQ_RX:
SAMD21: Being a slow device it needs data to be sent byte-by-byte at
9600 baud, since the IRQ callback is scheduled delayed and then the
flags do not match any more. The data matches since it is queued in
the FIFO resp. ringbuffer.
CC3200: The test cannot be performed since no calls are accepted in the
IRQ handler like u.read(). Skipped.
Coverage:
cc3200 fail due to major differences in the implementation.
esp32 pass
nrf pass
renesas-ra pass
samd pass see the notes.
stm32 pass
IRQ_RXIDLE:
STM32: With PyBoard the IRQ is called several times, but only once with
the flag IRQ_RXIDLE set.
Coverage:
esp32 pass
mimxrt pass
renesas-ra pass
rp2 pass
samd pass for both SAMD21 and SAMD51
stm32 fail. see notes.
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: robert-hh <robert@hammelrath.com>
The test checks whether the message created by the IRQ handler appears
about at the end of the data sent by UART.
Supported MCUs resp. boards:
- RP2040
- Teensy 4.x
- Adafruit ItsyBitsy M0
- Adafruit ItsyBitsy M4
- NRF52 (Arduino Nano Connect 33 BLE)
Signed-off-by: Damien George <damien@micropython.org>
These docs now match the code in `extmod/machine_uart.c`. IRQ trigger
support still need to be updated for each port (to be done in a follow-up
commit).
Signed-off-by: Damien George <damien@micropython.org>
The UART.IRQ_IDLE callback is called about two character times after the
last byte, or 1 ms, whichever is larger. For the irq, timer 0 is used.
machine_timer.c had to be reworked to make it's mechanisms available for
machine_uart.c.
The irq.flags() value is change only at a requested event. Otherwise keep
the state.
Signed-off-by: robert-hh <robert@hammelrath.com>
Allowing to define the trigger UART.IRQ_RXIDLE as well as UART.IRQ_RX. The
delay for the IRQ_RXIDLE interrupt is about 3 character times or 1-2 ms,
whichever is larger.
The irq.flags() value is changed only with an expected event. Do not
change it otherwise.
Signed-off-by: robert-hh <robert@hammelrath.com>
With the softtimer the minimal delay between the end of a message and the
trigger is 2 ms. For baud rates <= 9600 baud it's three character times.
Tested with baud rates up tp 115200 baud. The timer used for RXIDLE is
running only during UART receive, saving execution cycles when the timer is
not needed.
The irq.flags() value is changed only with an expected event. Do not
change it otherwise.
Signed-off-by: robert-hh <robert@hammelrath.com>
Just adding the event symbol. No code change required, and no impact on
code execution time when the event is not selected.
Tested with STM32F4xx, STM32F7xx and STM32H7xx.
Signed-off-by: robert-hh <robert@hammelrath.com>
Supported triggers: UART.IRQ_RX and UART.IRQ_TXIDLE. It will probably work
on other boards as well, but so far untested.
The irq.flags() value is changed only when requested by a triggered event.
Do not change it otherwise.
Signed-off-by: robert-hh <robert@hammelrath.com>
This commit fixes a bug in the existing driver, that the UART baud rate
could not be changed without reset or power cycle. It adds as well
functionality to UART.deinit().
Signed-off-by: robert-hh <robert@hammelrath.com>
The renesas-ra port supports calling a handler to be called on every byte
received by UART. For consistency with other ports, the symbol IRQ_RX
is added as the trigger name.
Side change: Add the received UART data to the REPL input buffer only if it
is the REPL UART. Otherwise, every UART would act as REPL input.
Signed-off-by: robert-hh <robert@hammelrath.com>
Supported triggers are: IRQ_RXIDLE and IRQ_TXIDLE.
When IRQ_RXIDLE is set, the handler will be called 3 character times after
the data in burst stopped.
When IRQ_TXIDLE is set, the handler will be called immediately after the
data has been sent.
This commit requires a change to fsl_lpuart.c, because the existing code
does not support under-run appropriately.
The irq.flags() value is cleared only at an expected event. Do not change
it otherwise.
Signed-off-by: robert-hh <robert@hammelrath.com>
Supported for all SAMD51 devices and SAMD21 with external flash. For
interrupt events, IRQ_RX and IRQ_TXIDLE are provided.
IRQ_RX is called for every received byte. This may not be useful for high
data rates, but can be used to build a wrapper class providing an
IRQ_RXIDLE event or to signal just the first byte of a message.
IRQ_TXIDLE is called only when messages are longer than 5 bytes and
triggers when still 5 bytes are due to be sent.
The SAMD hardware does not support implementing IRQ_RXIDLE.
Signed-off-by: robert-hh <robert@hammelrath.com>
Supported trigger names: IRQ_RXIDLE, IRQ_TXIDLE, IRQ_BREAK
- IRQ_RXIDLE: The handler for IRQ_RXIDLE is called reliably 31 UART bit
times after the last incoming data.
- IRQ_TXIDLE: This IRQ is triggered after at least >5 characters are sent
at once. It is triggered when the TX FIFO falls below 4 elements. At
that time, up to 5 bytes may still be in the FIFO and output shift
register.
- IRQ_BREAK: The IRQ triggers if a BREAK state is detected at RX.
Properties & side effects:
- After a BREAK, a valid character must be received before another break
can be detected.
- Each break puts a 0xff character into the input buffer.
The irq.flags() value is cleared only with a new wanted event. Do not
change the flags otherwise.
Signed-off-by: robert-hh <robert@hammelrath.com>
`ssl.wrap_socket()` is deprecated in CPython, so use `SSLContext` instead,
so the example is a good example to copy.
Signed-off-by: Damien George <damien@micropython.org>
The main changes here are to pass the address family and socket type to
`getaddrinfo()`, and then use the result of the address lookup when
creating the socket, so it has the correct address family.
This allows both IPv4 and IPv6 to work, because the socket is created with
the correct AF_INETx type for the address.
Also add some more comments to the examples to explain what's going on.
Fixes issue #15580.
Signed-off-by: Damien George <damien@micropython.org>
Currently, the qemu-arm (and qemu-riscv) port has two build modes:
- a simple test that executes a Python string; and
- a full test that uses tinytest to embed all tests within the firmware,
then executes that and captures the output.
This is very different to all the other ports. A difficulty with using
tinytest is that with the large number of tests the firmware overflows its
virtual flash size. It's also hard to run tests via .mpy files and with
the native emitter. Being different to the other ports also means an extra
burden on maintenance.
This commit reworks the qemu-arm port so that it has a single build target
that creates a standard firmware which has a REPL. When run under
qemu-system-arm, the REPL acts like any other bare-metal port, complete
with soft reset (use machine.reset() to turn it off and exit
qemu-system-arm).
This approach gives many benefits:
- allows playing with a REPL without hardware;
- allows running the test suite as it would on a bare-metal board, by
making qemu-system-arm redirect the UART serial of the virtual device to
a /dev/pts/xx file, and then running run-tests.py against that serial
device;
- skipping tests is now done via the logic in `run-tests.py` and no longer
needs multiple places to define which tests to skip
(`tools/tinytest-codegen.py`, `ports/qemu-arm/tests_profile.txt` and also
`tests/run-tests.py`);
- allows testing/using mpremote with the qemu-arm port.
Eventually the qemu-riscv port would have a similar change.
Prior to this commit the test results were:
743 tests ok. (121 skipped)
With this commit the test results are:
753 tests performed (22673 individual testcases)
753 tests passed
138 tests skipped
More tests are skipped because more are included in the run. But overall
more tests pass.
Signed-off-by: Damien George <damien@micropython.org>
With this change, the zephyr port is tested against the standard test suite
via the following scheme:
- the zephyr port is built with the `qemu_cortex_m3` board and the
`prj_minimal.conf` configuration
- `qemu-system-arm` runs `zephyr.elf`
- the zephyr console is redirected to a pts/pty
- `tests/run-tests.py` is run in bare-metal mode against the pts/pty device
This allows testing the zephyr port as though it were a physical board
attached over a serial port.
Signed-off-by: Damien George <damien@micropython.org>
It needs to be at least this big for `tools/pyboard.py` to work, which is
used (among other things) by `tests/run-tests.py`.
Signed-off-by: Damien George <damien@micropython.org>
Commit f573e73bae rewored the zephyr port to
build MicroPython as a cmake target, and since that commit the
`make-bin-testsuite` helper script no longer works (it requires a Makefile)
and hence the tinytest test framework can no longer be run.
Instead of fixing this, remove the option to use tinytest. Boards running
zephyr can use the standard `tests/run-tests.py` script to run tests in the
usual way.
Signed-off-by: Damien George <damien@micropython.org>
The pts line printed by qemu-system-arm goes to stdout, not stderr.
Redirect stderr to stdout in case other tools do print to stderr.
Signed-off-by: Damien George <damien@micropython.org>
This adds support for the WIZNET5K nic to use IPv6 with the LWIP stack.
Additionally, if LWIP_IPV6 is disabled, the device is configured to drop
all IPv6 packets to reduce load on the MCU.
Signed-off-by: Jared Hancock <jared@greezybacon.me>
Small code size and binary size optimisation for the fix merged in
4d6d84983f.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Currently for samd21 some features are disable because of limited memory.
With the ability to trade firmware and filesystem space, a user may wish to
selectively enable some of these features. This change allows them to be
enabled in board `mpconfigboard.h` or on the build command line for
example. The selectively enable functions are: MICROPY_PY_FRAMEBUF,
MICROPY_PY_SELECT, MICROPY_PY_ONEWIRE and MICROPY_PY_ASYNCIO.
Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
When MicroPython is used as a submodule and built from the containing
project, e.g. for the embed port, `make submodules` fails because it goes
looking for the sub-sub-module paths in the outer repository instead of in
the micropython repository. Fix this by invoking git inside the micropython
submodule.
Signed-off-by: Christian Walther <cwalther@gmx.ch>
The original OSPIFLASH settings in the `mpconfigboard.h` contained some
mistakes that prevented the firmware from compiling. These are now
corrected and the firmware can be built with support for OSPI flash.
Note: external storage in OSPI flash is not yet configured on this board.
Signed-off-by: nspsck <teng.jiang94@gmail.com>
Added a #if-block to `system_stm32.c` to check whether
`MICROPY_HW_RCC_OSPI_CLKSOURCE` is defined. If that is the case, the
clock source for the OSPI will be changed to the specified source.
Signed-off-by: nspsck <teng.jiang94@gmail.com>
Added a if-statement to `octospi.c` to detect if the targeted MCU is one of
the STM32H7 series. If that is the case, another set of variables are used
for the `mp_hal_pin_config_alt_static_speed()` function, as well as for
register `OCTOSPI1->CR`. This allows the STM32H723 and STM32H7B3 series
MCU to use octo-spi flash like the STM32H573 series MCU.
Signed-off-by: nspsck <teng.jiang94@gmail.com>
There is a gap in support for the PVD interrupt on STM32WBxx and STM32WLxx.
This has been tested on NUCLEO_WB55 with the example code:
from pyb import Pin, ExtInt
def callback(line):
print(line)
PVD = 16
exti = ExtInt(PVD, ExtInt.IRQ_RISING_FALLING, Pin.PULL_DOWN, callback)
exti.swint()
Before this commit the CPU locks up as soon as the final line is run.
After this commit it prints "16".
Fixes issue #15548.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
There are some missing images at MicroPython Downloads. This commit
attempts to resolve all the current issues, and add product URLs where
missing.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
IDF 3 builds are very old now (it seems like the last successful builds are
from 2021), and the current IDF 5 is stable. So remove IDF 3 variants.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
By default, the peripheral clock for UART and SPI is set to 48 MHz and will
not be affected by the MCU clock change. This can be changed by a second
argument to `machine.freq(freq, peripheral_freq)`. The second argument
must be either 48 MHz or identical with the first argument.
Note that UART and SPI baud rates may have to be re-configured after
changing the MCU clock.
Signed-off-by: robert-hh <robert@hammelrath.com>
As a side effect, the peripheral clock will be set to 48Mhz and both UART
and I2C will not be affected by CPu speed changed using `machine.freq()`.
With the change the UART baud rate range is 50 to 3_000_000.
Signed-off-by: robert-hh <robert@hammelrath.com>
If `MICROPY_PY_THREAD` is set to 0 (ie: a user C module wishes to use core1
exclusively) then the test of `core1_entry` would fail to compile with an
"undeclared identifier" error. Fix it by wrapping in `MICROPY_PY_THREAD`.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
The RV32 emitter used an additional temporary register, as certain code
sequences required extra storage. This commit removes its usage in all
but one case, using REG_TEMP2 instead.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The RV32 emitter sometimes generated short load opcodes even when it
was not supposed to. This commit fixes an off-by-one error in its
offset eligibility range calculation and corrects one case of offset
calculation, operating on the raw label index number rather than its
effective offset in the stack (C.LW assumes all loads are
word-aligned).
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The RV32 emitter always scheduled short jumps even outside the emit
compiler pass. Running the full test suite through the native emitter
instead of just the tests that depend on the emitter at runtime (as in,
`micropython/native_*` and `micropython/viper_* tests`) uncovered more
places where the invalid behaviour was still present.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Skip whitespace characters between pairs of hex numbers.
This makes `bytes.fromhex()` compatible with cpython.
Includes simple test in `tests/basic/builtin_str_hex.py`.
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
The extra limit for C3 dates from 6823514 which added C3 support.
Measuring the minimum stack margins that can pass the stress tests I
measured 768 bytes for ESP32-S3 and 512 bytes for ESP32-C3 on ESP-IDF
V5.2.2 and similar on V5.0.4. i.e. The ESP32-C3 actually needs less stack
margin not more!
I think the extra margin for ESP32-C3 probably arose from:
1. Some toolchain inefficiency in the IDF V4.x RISC-V compiler codegen,
that has since been improved.
OR
2. The race condition that was fixed in e3955f42 where sometimes the limit
wasn't set correctly at all. This seems to trigger more on C3, presumably
some timing artifact, and I'd believe that some binaries might be more
susceptible than others due to random factors.
OR
3. Commit 6007f3e206 which enabled custom
NLR handling for ESP32-C3.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This value should have been adjusted when the new cstack API was adopted in
e3955f421d, as otherwise the stack limit is too small especially on
ESP32-C3 where the stack limit was 6144 - 2048 - 2048.
Some extra margin is needed for bluetooth irq because invoke_irq_handler()
isn't a top-level task function, NimBLE calls through multiple layers
first. Measuring this overhead on IDF V5.2.2 (by putting an abort() in
invoke_irq_handler() and then measuring the stack size) yielded 672 bytes
on ESP32-S3 and 612 bytes on ESP32-C3, similar to the size reported in
cd66aa05cf.
Sticking with 1024 bytes for added safety margin. This means on Xtensa the
total margin for the BLE task stays the same (2048 bytes) as before
switching to cstack.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
If verbose debugging is enabled there is some stdout output happening
before the GIL is ready (for example, GC initialisation), and the code
assumed that no string printing occurred before the interpreter was fully
initialised. Printing long strings would operate without holding the GIL,
which would crash if string output would happen too early in the startup
process.
This commit addresses that issue, making sure verbose debugging output will
work even before the interpreter is fully initialised (as if it is not yet
ready there's no GIL to take care of).
Also, the threshold that would indicate whether a string is "long" (and
thus requiring a GIL release/lock operation) or not was hardcoded to 20
bytes. This commit makes that configurable, maintaining 20 bytes as a
default.
Fixes issue #15408.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Commit a66bd7a489 added the
ESP32_GENERIC_C3_USB board (now merged with ESP32_GENERIC_C3) and changed
the brownout detector from the default level 7 (~2.51V) to level 4
(~2.92V).
Raising the level again seems to fix random BOD resets on some of the
cheaper ESP32-C3 dev boards (that likely skimp on power supply
capacitance).
Specifically, this change prevents random resets running multi_bluetooth
tests on ESP32-C3 "SuperMini" board.
Also removed from the LOLIN_C3_MINI board as it seems this config is a copy
of the generic one.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The ESP-IDF default on C3 is primary UART0, secondary USB serial/jtag.
Previously MicroPython configured the primary as USB Serial/JTAG and
manually worked with the UART0 console. However UART0 console stopped
working this way in v5.2.2.
The big change is that CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is no longer set,
as primary console is UART0. However
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is set and IDF provides a
macro CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED which is set if either
primary or secondary esp_console is USB serial/jtag. So need to use that
macro instead.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Saves code size, MicroPython doesn't appear to rely on any of the missing
formatters (64-bit integers, c99-style named arguments).
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Replaces the deprecated ESP32 calibration API with the "line" method
instead.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Update to the test added in 1e98c4cb75,
changes the SPI pins for ESP32-C3 (IO 18 and 19 are the native USB pins).
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Necessary to pass CI when testing the V2 preview APIs.
Also adds an extra coverage test for the legacy stackctrl API, to maintain
coverage and check for any regression.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This change moves that complexity out into the stack checker and fixes the
bug where stack margin wasn't set correctly by ESP32-C3 threads.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Currently the stack limit margin is hard-coded in each port's call to
`mp_stack_set_limit()`, but on threaded ports it's fiddlier and can lead to
bugs (such as incorrect thread stack margin on esp32).
This commit provides a new API to initialise the C Stack in one function
call, with a config macro to set the margin. Where possible the new call
is inlined to reduce code size in thread-free ports.
Intended replacement for `MP_TASK_STACK_LIMIT_MARGIN` on esp32.
The previous `stackctrl.h` API is still present and unmodified apart from a
deprecation comment. However it's not available when the
`MICROPY_PREVIEW_VERSION_2` macro is set.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
These were changed in v1.11 (2019). Prepare to remove the compatibility
macros as part of V2 changes.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
`mbedtls_pk_parse_key()` expects `key_len` to include the NULL terminator
for PEM data but not for DER encoded data. This also applies to
`mbedtls_x509_crt_parse()` and `cert_len`.
Since all PEM data contains "-----BEGIN" this is used to check if the data
is PEM (as per mbedtls code).
This can be done for both v2 and v3 of mbedtls since the fundamental
behaviour/expectation did not change. What changed is that in v3 the
PKCS#8 DER parser now checks that the passed key buffer is fully utilized
and no bytes are remaining (all other DER formats still do not check this).
Signed-off-by: Peter Züger <zueger.peter@icloud.com>
`get_lan()`: If the ethernet MAC address is uninitialised, set it to the
address reserved by the ESP32 for the ETH interface.
SPI LAN devices may be initialised with a MAC address of 00:00:00:00:00:00.
So check that a valid unicast MAC address has been set (using
`LAN.config(mac=...)`) when initialising the LAN interface.
Fixes#15425.
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
This PR ensures that `network.LAN.active(True/False)` will succeed if the
LAN is already in the desired state.
Currently, `lan.active(True)` will raise an `OSError` exception if the LAN
is already in the desired state. This is inconsistent with
`network.WLAN.active(True/False)` and causes `lan.active(True)` to raise an
exception after a soft reset (causing common network startup scripts to
fail for LAN interfaces).
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
The reason for this change is that it makes allows custom code, that needs
to use an MPU region, to find a free one by using this macro or starting
from the max number and downwards, without concern that it might change in
the future.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Add native gchelper support for 64 bits RISC-V RV64I targets.
Now that RV64 is under CI, this also enables platform-specific ghelper
in the Unix port.
Also changes the data type holding the register contents to something more
appropriate, so in the remote eventuality somebody wants to use this with
RV128 all they have to do is update the `__riscv_xlen` check.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Updating a set must use `.update()` rather than `.add()`.
Also apply the same pattern to qemu-riscv to prevent the same issue when
directories/files are added to that port's `tests_profile.txt` file.
Signed-off-by: Damien George <damien@micropython.org>
Based on machine_i2s_rate, allows testing basic SPI functionality and
timings.
Implemented and confirmed working for rp2, esp32, and pyboard.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Finalisers that run during `gc_sweep_all()` may run native code, for
example if an open file is closed and the underlying block device is
implemented in native code, then the filesystem driver (eg FAT) may call
into the native code.
Therefore, native code must be freed after the call to `gc_sweep_all()`.
That can only be achieved if the GC heap is not used to store the list of
allocated native code blocks. Instead, this commit makes the native code
blocks a linked list.
Signed-off-by: Damien George <damien@micropython.org>
Without this commit, math.gamma(-float("inf")) returns inf instead of
raising a math domain ValueError. Needed for float/math_domain_special.py
test to pass on esp32.
Root cause is an upstream libm bug, has been reported to ESP-IDF.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This is needed for a workaround on esp32 port (in child commit),
which produces incorrect results otherwise.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The `emit_load_reg_with_object()` helper function will clobber `REG_TEMP0`.
This is currently OK on architectures where `REG_RET` and `REG_TEMP0` are
the same (all architectures except RV32), because all callers of
`emit_load_reg_with_object()` use either `REG_RET` or `REG_TEMP0` as the
destination register. But on RV32 these registers are different and so
when `REG_RET` is the destination, `REG_TEMP0` is clobbered, leading to
incorrectly generated machine code.
This commit fixes the issue simply by using `REG_TEMP0` as the destination
register for all uses of `emit_load_reg_with_object()`, and adds a comment
to make sure the caller of this function is careful.
Signed-off-by: Damien George <damien@micropython.org>
Add `machine_i2s_deinit_all` to teardown any active I2S instances on soft
reset. Prior to this fix, code using I2S required a try/finally in order
to avoid a hard fault on soft reset.
Fixes issue #14339.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
This change has no impact on vanilla MicroPython builds, but is intended to
avoid RP2's PIO implementation from trampling PIO usage in USER_C_MODULES.
This is consistent with PIOs tracking of used state machines and managed
programs, and makes working with PIO in USER_C_MODULES much less of an
uphill battle.
Since PIO deinit runs before gc_sweep_all it's impossible to work around
this wrinkle otherwise. A module finalizer does not get the opportunity to
put the PIOs back into a state which wont crash rp2_pio_deinit.
Changes are:
- init: Avoid exclusive handlers being added to all PIOs and add them only
when needed.
- deinit: Only remove handlers we have set.
- rp2_pio_irq: Add the exlusive handler if needed.
- rp2_state_machine_irq: Add the exclusive handler if needed.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
Reduce mimimum heap requirement. This value allows more room for large,
static buffers in user C modules (such as graphics buffers or otherwise)
which might be allocated outside of MicroPython's heap to guarantee
alignment or avoid fragmentation.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
Add MICROPY_DEF_BOARD as per esp32 port, allows board variants to override
the board name with:
list(APPEND MICROPY_DEF_BOARD
MICROPY_HW_BOARD_NAME="New Board Name"
)
Signed-off-by: Phil Howard <phil@gadgetoid.com>
ESP-IDF driver always requires at least two DMA buffers, so ensure that's
the case.
Failures during initialisation were being lost because ESP_ERROR_CHECK is
configured as a no-op, so the failure was deferred until read() or write()
was called on the port. Raise an error from init, instead.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Introduce SRC_USERMOD_LIB_ASM to allow users to include assembly files as
part of their user modules. It could be used to include optimized
functions or outputs of other programming languages.
Signed-off-by: George Hopkins <george-hopkins@null.net>
It seems like at some point Espressif NimBLE team changed
nimble_port_init and nimble_port_deinit to manage HCI init
internally:
https://github.com/espressif/esp-nimble/commit/f8a79b04c9743543b8959727d7
This change is included in all the IDF versions that MicroPython supports.
As a result, existing code that called esp_nimble_hci_deinit() explicitly
would trigger a use-after-free bug and heap corruption (specifically this
calls through to ble_transport_deinit() which calls os_mempool_free(). The
second time this writes out to a bunch of memory pools where the backing
buffers have already been freed.)
Symptoms were intermittent random crashes after de-activating Bluetooth
(running multi_bluetooth/ble_gatt_data_transfer.py could sometimes
reproduce). Setting Heap Poisoning to Comprehensive in menuconfig caused
the bug to be detected every time.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Swap FMC banks to remap the SDRAM bank1 address to 0x60000000. Arduino's
M4 firmware uses address 0x60000000 by default. When the elf loader tries
to load that it will fail because by default NOR/PSRAM is mapped at that
address, not SDRAM bank1. (Note that the region at 0xC0000000 has an XN
attribute by default, so switching the M4 firmware address will not work.)
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Previously it was truncating the first digit of the version if the major
number had more than one digit.
Signed-off-by: Andrew Leech <andrew@alelec.net>
The RV32 code emitter assumed that the arch-specific NLR was used
instead of the setjmp/longjmp based NLR code. If the latter NLR
provider was chosen, the emitter would allocate space on the stack
for the NLR buffer but would not fill it in.
This change turns off setjmp()-based NLR and GCREGS for the ESP32C3
target, in favour of more platform-tailored alternatives. As setjmp()
NLR is now disabled by default, the RV32 emitter can be safely enabled
by default as well for the target in question.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Before, the input was still set to `pin.irq()` mode, only the handler was
disabled. That prevented switching the pin between input and output mode.
Signed-off-by: robert-hh <robert@hammelrath.com>
Consolidate CDC, UART and NUS stdio interfaces into the one handler.
Allows any/all of them to be enabled separately.
Updates UART REPL to use similar define to other platforms:
`MICROPY_HW_ENABLE_UART_REPL`.
USB now uses the shared/tinyusb CDC implementation.
Signed-off-by: Andrew Leech <andrew@alelec.net>
The `sslcontext_server_client_ciphers.py` test was using stat to test for
the .der files after it already tried to open them for reading. That is
now fixed. And `sslcontext_server_client.py` is adjusted to use the same
pattern for skipping the test.
Signed-off-by: Damien George <damien@micropython.org>
Install the mingw variant of Python since it behaves more like a 'real'
Windows CPython than the msys2 variant: os.name == 'nt', not 'posix'. Note
that os.sep is still '/' though so we don't actually need to skip the
import_file test. This way one single Python version can be used both for
running run-tests.py and getting the expected test output.
Signed-off-by: stijn <stijn@ignitron.net>
Use explicit casts to suppress warnings about implicit conversions, add a
workaround for constant expression conditional, and make functions static
inline (as is done in the rest of the codebase) to suppress 'warning C4505:
unreferenced function with internal linkage has been removed'.
(Follow up to fix commit 908ab1ceca)
Signed-off-by: stijn <stijn@ignitron.net>
This fixes various null dereferencing and out-of-bounds access because
super_attr assumes the held obj is effectively an object of the held type,
which is now verified.
Fixes issue #12830.
Signed-off-by: stijn <stijn@ignitron.net>
This adds a CPython diff that explains why calling `super().__init__()` is
required in MicroPython when subclassing a native type (because `__new__`
and `__init__` are not separate functions).
Signed-off-by: David Lechner <david@pybricks.com>
When subclassing a native type, calling native members in `__init__` before
`super().__init__()` has been called could cause a crash. In this
situation, `self` in `mp_convert_member_lookup` is the
`native_base_init_wrapper_obj`. The check added in this commit ensures
that an `AttributeError` is raised before this happens, which is consistent
with other failed lookups.
Also fix a typo in a related comment.
Signed-off-by: Laurens Valk <laurens@pybricks.com>
This adds a separate `AdvancedTimer` class that demonstrates a few more
advanced concepts usch as custom handlers for printing and attributes.
Signed-off-by: Laurens Valk <laurens@pybricks.com>
Having IPv6 support is important, especially for IoT-Devices which might be
many, requiring individual IP-addresses. In particular direct access via
link-local addresses and having deterministic SLAAC-addresses can be quite
convenient. Also in IPv6-only networks or for connecting to IPv6-only
services, this is very useful.
For the Pico W, there is enough flash and RAM that enabling IPv6 by default
is the right choice.
Should IPv6 support in a network exist (i.e. there are Router
Advertisements), but not provide connectivity, connecting by domain name
should not be a problem as DNS will default to return the IPv4-address (if
that exists), unless reconfigured at runtime to prefer IPv6.
In any case a user can disable obtaining SLAAC-addresses with:
<nic>.ipconfig(autoconf6=False)
Signed-off-by: Felix Dörre <felix@dogcraft.de>
Updates rp2 port to always resume from idle within 1ms max.
When rp2 port went tickless the behaviour of machine.idle() changed as
there is no longer a tick interrupt to wake it up every millisecond. On a
quiet system it would now block indefinitely. No other port does this.
See parent commit for justification of why this change is useful.
Also adds a test case that fails without this change.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
A lot of existing code (i.e. micropython-lib lps22h, lcd160cr sensor
drivers, lora sync_modem driver, usb-device-hid) calls machine.idle()
inside a tight loop that is polling some condition. This reduces the power
usage compared to constantly looping, but can be faster than calling a
sleep function. However on a tickless port there's not always an interrupt
before the condition they are polling for, so it's difficult to restructure
this code if machine.idle() doesn't have any upper limit on execution time.
This commit specifies an upper limit of 1ms before machine.idle() resumes
execution. This is already the case for all ports except rp2.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
If core1 executes `mp_wfe_or_timeout()` then it needs to receive an
interrupt or a SEV to resume execution, but the soft timer interrupt only
fires on core 0. This fix adds a SEV to the soft timer interrupt handler.
This issue was masked by the issue fixed in the previous commit, as WFE
previously wasn't suspending properly.
Verified via the existing thread_sleep2 test.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Fixes a regression introduced in 3af006efb3
where WFE never blocked in `mp_wfe_or_timeout()` function and would
busy-wait instead. This increases power consumption measurably.
Root cause is that `mp_wfe_or_timeout()` calls soft timer functions that
(after the regression) call `recursive_mutex_enter()` and
`recursive_mutex_exit()`. The exit calls
`lock_internal_spin_unlock_with_notify()` and the default pico-sdk
implementation of this macro issues a SEV which negates the WFE that
follows it, meaning the CPU never suspends.
See https://forums.raspberrypi.com/viewtopic.php?p=2233908 for more
details.
The fix in this comment adds a custom "nowait" variant mutex that doesn't
do WFE/SEV, and uses this one for PendSV. This will use more power when
there's contention for the PendSV mutex as the other core will spin, but
this shouldn't happen very often.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This contains a workaround to silence a possibly incorrect warning when
building the Unix port with GCC targeting RISC-V 64 bits.
Fixes issue #12838.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The ESP32C3 has only two timers in one group. In the code this is
reflected as two groups with one timer.
Signed-off-by: robert-hh <robert@hammelrath.com>
Before the fix in parent commit, some of these tests hung indefinitely.
After, they seem to consistently pass.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Explicitly yield each time a thread mutex is unlocked.
Key to understanding this bug is that Python threads run at equal RTOS
priority, and although ESP-IDF FreeRTOS (and I think vanilla FreeRTOS)
scheduler will round-robin equal priority tasks in the ready state it does
not make a similar guarantee for tasks moving between ready and waiting.
The pathological case of this bug is when one Python thread task is busy
(i.e. never blocks) it will hog the CPU more than expected, sometimes for
an unbounded amount of time. This happens even though it periodically
unlocks the GIL to allow another task to run.
Assume T1 is busy and T2 is blocked waiting for the GIL. T1 is executing
and hits a condition to yield execution:
1. T1 calls MP_THREAD_GIL_EXIT
2. FreeRTOS sees T2 is waiting for the GIL and moves it to the Ready list
(but does not preempt, as T2 is same priority, so T1 keeps running).
3. T1 immediately calls MP_THREAD_GIL_ENTER and re-takes the GIL.
4. Pre-emptive context switch happens, T2 wakes up, sees GIL is not
available, and goes on the waiting list for the GIL again.
To break this cycle step 4 must happen before step 3, but this may be a
very narrow window of time so it may not happen regularly - and
quantisation of the timing of the tick interrupt to trigger a context
switch may mean it never happens.
Yielding at the end of step 2 maximises the chance for another task to run.
Adds a test that fails on esp32 before this fix and passes afterwards.
Fixes issue #15423.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The comparison between the given unmount string and existing mount strings
were made by the given string, which leads to buffer overflow.
Fixes issue #13006.
Signed-off-by: Junwha <qbit@unist.ac.kr>
Fixes various null dereferencing, out-of-bounds memory accesses and
`assert(0)` failures in the case of an invalid `uctypes` descriptor.
By design `uctypes` can crash because it accesses arbitrary memory, but at
least describing the descriptor layout should be forced to be correct and
not crash.
Fixes issue #12702.
Signed-off-by: stijn <stijn@ignitron.net>
Fixes use-after-free when accessing the database after it is closed with
`btree_close`. `btree_close` always succeeds when called with an
already-closed database.
The new test checks that operations that access the underlying database
(get, set, flush, seq) fail with a `ValueError` when the btree is already
closed. It also checks that closing and printing the btree succeed when
the btree is already closed.
Fixes issue #12543.
Signed-off-by: Michael Vornovitsky <michaelvornovitskiy@outlook.com>
This simplifies configuration by removing the `MICROPY_PY_OS_SEP` option
and instead including `os.sep` if `MICROPY_VFS` is enabled. That matches
the configuration of all existing ports that enabled `os.sep` (they also
had `MICROPY_VFS` enabled), and brings consistency to other ports.
Fixes issue #15116.
Signed-off-by: Damien George <damien@micropython.org>
The current situation with SystemExit and soft reset is the following:
- `sys.exit()` follows CPython and just raises `SystemExit`.
- On the unix port, raising `SystemExit` quits the application/MicroPython,
whether at the REPL or in code (this follows CPython behaviour).
- On bare-metal ports, raising `SystemExit` at the REPL does nothing,
raising it in code will stop the code and drop into the REPL.
- `machine.soft_reset()` raises `SystemExit` but with a special flag set,
and bare-metal targets check this flag when it propagates to the
top-level and do a soft reset when they receive it.
The original idea here was that a bare-metal target can't "quit" like the
unix port can, and so dropping to the REPL was considered the same as
"quit". But this bare-metal behaviour is arguably inconsistent with unix,
and "quit" should mean terminate everything, including REPL access.
This commit changes the behaviour to the following, which is more
consistent:
- Raising `SystemExit` on a bare-metal port will do a soft reset (unless
the exception is caught by the application).
- `machine.soft_reset()` is now equivalent to `sys.exit()`.
- unix port behaviour remains unchanged.
Tested running the test suite on an stm32 board and everything still
passes, in particular tests that skip by raising `SystemExit` still
correctly skip.
Signed-off-by: Damien George <damien@micropython.org>
During execution of `boot.py` the USB device is not yet initialized. Any
attempt to write to the CDC (eg calling `print()`) would lock up the
device. This commit skips writing when the USB device is not initialized.
Any output from `boot.py` is lost, but the device does not lock up.
Also removed unnecessary declaration of `tusb_init()`.
Signed-off-by: robert-hh <robert@hammelrath.com>
This commit makes it so that PyProxy objects are reused (on the JavaScript
side) when they correspond to an existing Python object that is the same
object.
For example, proxying the same Python function to JavaScript, the same
PyProxy instance is now used. This means that if `foo` is a Python
function then accessing it on the JavaScript side such as
`api.globals().get("foo")` has the property that:
api.globals().get("foo") === api.globals().get("foo")
Prior to this commit the above was not true because new PyProxy instances
were created each time `foo` was accessed.
Signed-off-by: Damien George <damien@micropython.org>
These are old, unused, and most of them no longer compile. The `gc_test()`
function is superseded by the test suite.
Signed-off-by: Damien George <damien@micropython.org>
Also put this function inside the `MICROPY_PY_BUILTINS_SLICE` guard,
because it's only usable when that option is enabled.
Signed-off-by: Damien George <damien@micropython.org>
These TODOs don't need to be done:
- Calling functions with keyword arguments is less common than without
them, so adding an extra byte overhead to all calls regardless of whether
they use keywords or not would overall increase generated bytecode size.
- Restricting `range` objects to machine-sized ints has been adequate for
a long time now, so no need to change that and make it more complicated
and slower.
- Printing spaces in tab completion does not need to be optimised.
Signed-off-by: Damien George <damien@micropython.org>
Follow up to 2e852522b1: instead of having
.exp files for the get_event_loop tests, tweak them so they are compatible
with CPython 3.12. This requires calling `asyncio.set_event_loop()` so
there is an active event loop and `asyncio.get_event_loop()` succeeds
without a warning.
Signed-off-by: Damien George <damien@micropython.org>
This adds some more baudrate option as they are available in the termios.h
header - up to a point that seems reasonable in an embedded context.
Signed-off-by: Lennart Schierling <Lennart@binarylabs.dev>
macos-11.0 is no longer available.
With this change in the macos version, some tests which previously failed
now pass, and some different tests now fail. Exclude those that fail from
the CI until they can be fixed properly.
Signed-off-by: Damien George <damien@micropython.org>
The `re_exec` symbol is the name of a FreeBSD regex function, so needs to
be renamed to avoid a clash when building on FreeBSD. (This clash was
fixed once before but then accidentally reintroduced by the u-module
renaming in 7f5d5c72718af773db751269c6ae14037b9c0727.)
Fixes issue #15430.
clarify as helper function
Being able to send data out in LSB format can be useful, and having support
in the low-level driver is much better than requiring Python code to
reorder the bits before sending them / after receiving them. In particular
if the hardware does not support the LSB format (eg RP2040) then one needs
to use the SoftSPI in LSB mode.
For this change a default definition of `MICROPY_PY_MACHINE_SPI_MSB/_LSB`
was added to `py/mpconfig.h`, making them available to all ports. The
identical defines in `esp32/mpconfigport.h` were deleted.
Resolves issues #5340, #11404.
Signed-off-by: robert-hh <robert@hammelrath.com>
The only AP security mode supported is actually WPA/WPA2 not WEP. The
firmware command `0x19` starts the AP using `WIFI_AUTH_WPA_WPA2_PSK`
mode.
There are no functional changes in this commit, it just fixes the constant
names and removes the useless sanity checks for WEP.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
The limit is set by a `MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX` define, which
defaults to 1 and is set for stm32 to 4.
For stm32 this fixes a regression introduced in commit
e1ec6af654 where the maximum number of
arguments was changed from 4 to 1.
Signed-off-by: robert-hh <robert@hammelrath.com>
A target may have enough RAM to run the n=433 test but then run out of RAM
on the n=432 test. So allow the test to skip on the n=432 case before it
prints any output.
Signed-off-by: Damien George <damien@micropython.org>
Because the main thread executes `thread_entry()` it means there's an
additional one added to `count`, so the test must wait for the count to
reach `n_thread + 1`.
Signed-off-by: Damien George <damien@micropython.org>
Use new function mp_obj_new_str_from_cstr() where appropriate. It
simplifies the code, and makes it smaller too.
Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
There were lots of places where this pattern was duplicated, to convert a
standard C string to a MicroPython string:
x = mp_obj_new_str(s, strlen(s));
This commit provides a simpler method that removes this code duplication:
x = mp_obj_new_str_from_cstr(s);
This gives clearer, and probably smaller, code.
Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
The change closes the gap in the API when an integer is used as Pin
reference. With the change, e.g. ADC(26), ADC(Pin(26)) and ADC("GP26")
behave identically and the GPIO is initialised in ACD/high-Z mode.
Only when using ADC channel numbers 0-3 are the corresponding GPIO left
uninitialised, and then the user is responsible for configuring the GPIO.
Signed-off-by: robert-hh <robert@hammelrath.com>
There are three changes here:
- Fix `rp2_pio_print` to use `pio_get_index()` too, since it had its own
copy of the ternary expression.
- Remove a ternary from `rp2_pio_state_machine` and calculate it from
`pio_get_index`.
- Remove a ternary on `GPIO_FUNC_PIO0` vs `GPIO_FUNC_PIO1`. These
constants are sequentially ordered so we can calculate them too.
Signed-off-by: Phil Howard <github@gadgetoid.com>
The `PIO_NUM` macro was defined when `rp2_pio.c` was first conceived.
There's now a Pico SDK function for this, `pio_get_index()`, which is
already used in some parts of the code.
This commit removes `PIO_NUM` in favour of using `pio_get_index()`
everywhere.
Signed-off-by: Phil Howard <github@gadgetoid.com>
As per discussion in #15347, non-standard binary literals have been
removed in favour of their hexadecimal counterparts.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Before this change, long/mpz ints propagated into all future calculations,
even if their value could fit in a small-int object. With this change, the
result of a big-int binary op will now be converted to a small-int object
if the value fits in a small-int.
For example, a relatively common operation like `x = a * b // c` where
a,b,c all small ints would always result in a long/mpz int, even if it
didn't need to, and then this would impact all future calculations with
x.
This adds +24 bytes on PYBV11 but avoids heap allocations and potential
surprises (e.g. `big-big` is now a small `0`, and can safely be accessed
with MP_OBJ_SMALL_INT_VALUE).
Performance tests are unchanged on PYBV10, except for `bm_pidigits.py`
which makes heavy use of big-ints and gains about 8% in speed.
Unix coverage tests have been updated to cover mpz code that is now
unreachable by normal Python code (removing the unreachable code would lead
to some surprising gaps in the internal C functions and the functionality
may be needed in the future, so it is kept because it has minimal
overhead).
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit changes a few code sequences to use more compressed opcodes
where possible. The sequences in question are the ones that show up the
most in the test suite and require the least amount of code changes, namely
short offset loads from memory to RET/ARG registers, indirect calls through
the function table, register-based jumps, locals' offset calculation,
reg-is-null jumps, and register comparisons.
There are no speed losses or gains from these changes, but there is an
average 15-20% generated code size reduction.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Pico SDK defines `__dsb()` and `__sev()` so use those instead of the CMSIS
equivalents. This matches the use of `__wfi()` in lieu of `__WFI()` and
lowers the dependency on CMSIS headers.
And then, move the include of "RP2040.h" from the widely-included
"mphalport.h" to specific source files that need this header, to keep its
inclusion contained.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
It looks like the variants for this board were never being built properly,
because the auto-build system used the variant name from `board.json` which
did not match the variant names in the original `mpconfigboard.mk`. Eg
`FLASH_2MB` in `board.json` but `FLASH_2M` in `mpconfigboard.mk`.
This mistake is apparent since 5dff78f38e,
which made it a build error to specify an invalid variant.
Fix this by using the correct variant names in `board.json`.
Signed-off-by: Damien George <damien@micropython.org>
In JavaScript when accessing an attribute such as `obj.attr` a value of
`undefined` is returned if the attribute does not exist. This is unlike
Python semantics where an `AttributeError` is raised. Furthermore, in some
cases in JavaScript (eg a Proxy instance) `attr in obj` can return false
yet `obj.attr` is still valid and returns something other than `undefined`.
So the source of truth for whether a JavaScript attribute exists is to just
right away attempt `obj.attr`.
To more closely match these JavaScript semantics when proxying a JavaScript
object through to Python, change the attribute lookup logic on a `JsProxy`
so that it immediately attempts `obj.attr` instead of first testing if the
attribute exists via `attr in obj`.
This allows JavaScript objects which dynamically create attributes to work
correctly on the Python side, with both `obj.attr` and `obj["attr"]`. Note
that `obj["attr"]` already works in all cases because it immediately does
the subscript access without first testing if the attribute exists.
As a benefit, this new behaviour matches the Pyodide behaviour.
Signed-off-by: Damien George <damien@micropython.org>
Following how esp32 has been reworked, each variant now has a corresponding
`mpconfigvariant_VARIANT.mk` file associated with it. The base variant
also has a `mpconfigvariant.mk` file because it has options that none of
the other variants use.
Signed-off-by: Damien George <damien@micropython.org>
This commit reworks board variants on the esp32 port. It's a simple change
that moves the board variant configuration from an "if" statement within
`mpconfigboard.cmake` into separate files for each variant, with the name
of the variant encoded in the filename: `mpconfigvariant_VARIANT.cmake`.
Optionally, the base variant can have its own options in
`mpconfigvariant.cmake` (this is an optional file, but all other variants
of the base must have a corresponding mpconfigvariant file).
There are two benefits to this:
- The build system now gives an error if the variant that you specified
doesn't exist (because the mpconfigvariant file must exist with the
variant name you specify).
- No more error-prone if-logic needed in the .cmake files.
The way to build a variant is unchanged, still via:
$ make BOARD_VARIANT=VARIANT
Signed-off-by: Damien George <damien@micropython.org>
This is a fix for an algorithmic error in mpremote mip, that throws an
error due to a '\n' used in the concatenation and split when there is more
than one lib path in `sys.path`.
Signed-off-by: Jos Verlinde <Jos.Verlinde@microsoft.com>
Allow inclusion of large integer constants in frozen files using long-long
representation (mpy-cross option -mlongint-impl=longlong).
Signed-off-by: Yoctopuce <dev@yoctopuce.com>
Compiling using arm-none-eabi-gcc 14.1.0 with -O2 will give warnings about
possible overflow indexing extint arrays, such as `pyb_extint_callback`.
This is due to `machine_pin_obj_t.pin` having a bit-width of 5, and so a
possible value up to 31, which is usually larger than
`PYB_EXTI_NUM_VECTORS`.
To fix this, change `machine_pin_obj_t.pin` to a bit-width of 4. Only 4
bits are needed for ST MCUs, which have up to 16 pins per port.
Signed-off-by: Damien George <damien@micropython.org>
The `mp_event_wait_ms()` function may return earlier than the requested
timeout, and if that happens repeatedly (eg due to lots of USB data and
IRQs) then the loop waiting for CDC TX FIFO space to become available may
exit much earlier than MICROPY_HW_USB_CDC_TX_TIMEOUT, even when there is
no space.
Fix this by using `mp_hal_ticks_ms()` to compute a more accurate timeout.
The `basics/int_big_mul.py` test fails on RPI_PICO without this fix.
Signed-off-by: Damien George <damien@micropython.org>
Provides pull request submitters with contributor documentation, and
prompts them to provide relevant information about testing, and how they
came to implement this change.
Sections are deliberately small so they don't crowd out the GitHub Pull
Request description text field.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
If `array.append()` fails with an exception due to heap exhaustion, the
next attempt to grow the buffer will cause a buffer overflow because the
free slot count is increased before performing the allocation, and will
stay as if the allocation succeeded.
Signed-off-by: Yoctopuce <dev@yoctopuce.com>
Follow-up to a84c7a0ed9, this commit works most of the time but has an
intermittent bug where USB doesn't resume as expected after waking from
light sleep.
Turns out waking calls clocks_init() which will re-initialise the USB PLL.
Most of the time this is OK but occasionally it seems like the clock
glitches the USB peripheral and it stops working until the next hard reset.
Adds a machine.lightsleep() test that consistently hangs in the first
two dozen iterations on rp2 without this fix. Passed over 100 times in a
row with this fix.
The test is currently rp2-only as it seems similar lightsleep USB issues
exist on other ports (both pyboard and ESP32-S3 native USB don't send any
data to the host after waking, until they receive something from the host
first.)
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Adapts pico-sdk clocks_init() into clocks_init_optional_usb() which takes
an argument to initialise USB clocks or not.
To avoid a code size increase the SDK clocks_init() function is linker
wrapped to become clocks_init_optional_usb(true).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
mp_thread_begin_atomic_section() is expected to be recursive (i.e. for
nested machine.disable_irq() calls, or if Python code calls disable_irq()
and then the Python runtime calls mp_handle_pending() which also enters an
atomic section to check the scheduler state).
On rp2 when not using core1 the atomic sections are recursive.
However when core1 was active (i.e. _thread) then there was a bug that
caused the core to live-lock if an atomic section recursed.
Adds a test case specifically for mutual exclusion and recursive atomic
sections when using two threads. Without this fix the test immediately
hangs on rp2.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Fixes and improvements to `int.to_bytes()` are:
- No longer overflows if byte size is 0 (closes#13041).
- Raises OverflowError in any case where number won't fit into byte length
(now matches CPython, previously MicroPython would return a truncated
bytes object).
- Document that `micropython int.to_bytes()` doesn't implement the optional
signed kwarg, but will behave as if `signed=True` when the integer is
negative (this is the current behaviour). Add tests for this also.
Requires changes for small ints, MPZ large ints, and "long long" large
ints.
Adds a new set of unit tests for ints between 32 and 64 bits to increase
coverage of "long long" large ints, which are otherwise untested.
Tested on unix port (64 bit small ints, MPZ long ints) and Zephyr STM32WB
board (32 bit small ints, long long large ints).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Prior to this fix the current working path in the remote VFS would always
be prepended to the requested path to get the full path, even if the
requested path was already absolute, ie starting with "/".
So `os.chdir("/remote/dir1")` would set the working path to "/dir1/", and
a subsequent call with an absolute path like `os.listdir("/remote/dir2")`
would try to list the directory "/dir1/dir2/".
Fixes issue #15308.
Signed-off-by: Damien George <damien@micropython.org>
The code generating the entry to the finally handler of an async-with
statement was simply wrong for the case of the native emitter. Among other
things the layout of the stack was incorrect.
This is fixed by this commit. The setup of the async-with finally handler
is now put in a dedicated emit function, for both the bytecode and native
emitters to implement in their own way (the bytecode emitter is unchanged,
just factored to a function).
With this fix all of the async-with tests now work when using the native
emitter.
Signed-off-by: Damien George <damien@micropython.org>
A value thrown/injected into a native generator needs to be stored in a
dedicated variable outside `nlr_buf_t`, following the `inject_exc` variable
in `py/vm.c`.
Signed-off-by: Damien George <damien@micropython.org>
This emitter prints out pseudo-machine instructions, instead of the usual
output of the native emitter. It can be enabled on any port via
`MICROPY_EMIT_NATIVE_DEBUG` (make sure other native emitters are disabled)
but the easiest way to use it is with mpy-cross:
$ mpy-cross -march=debug file.py
Signed-off-by: Damien George <damien@micropython.org>
This turns on the native RV32IMC code generator for the QEMU-based
RISC-V port, and removes tests that relies on native code generation
from the exclusion list (ie enables these tests).
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Selected load/store code sequences have been optimised for RV32IMC when the
chance to use fewer and smaller opcodes was possible.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
MPY files can now hold generated RV32IMC native code. This can be
accomplished by passing the `-march=rv32imc` flag to mpy-cross.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This adds a native code generation backend for RISC-V RV32I CPUs, currently
limited to the I, M, and C instruction sets.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Otherwise GC stays disabled (not re-enabled by soft reset) and later test
runs fail with MemoryError.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This fixes a minor issue in the changes made by
7dff38fdc1: the type flags for deque were
meant to be conditionalized based on MICROPY_PY_COLLECTIONS_DEQUE_ITER, but
the computed conditionalized value wasn't used.
Signed-off-by: Dan Halbert <halbert@halwitz.org>
This allows increasing the Python recursion depth if needed.
Also increase the default to 2k words. There is enough RAM in the
browser/node context for this to be increased, and having a larger pystack
allows more complex code to run without hitting the limit.
Signed-off-by: Damien George <damien@micropython.org>
In the webassembly port there is no asyncio run loop running at the top
level. Instead the Python asyncio run loop is scheduled through setTimeout
and run by the outer JavaScript event loop. Because tasks can become
runable from an external (to Python) event (eg a JavaScript callback), the
run loop must be scheduled whenever a task is pushed to the asyncio task
queue, otherwise tasks may be waiting forever on the queue.
Signed-off-by: Damien George <damien@micropython.org>
Allows passing in a callback to `TaskQueue()` that is called when something
is pushed on to the queue.
Signed-off-by: Damien George <damien@micropython.org>
This change allows doing a top-level await on an asyncio primitive like
Task and Event.
This feature enables a better interaction and synchronisation between
JavaScript and Python, because `api.runPythonAsync` can now be used (called
from JavaScript) to await on the completion of asyncio primitives.
Signed-off-by: Damien George <damien@micropython.org>
Unlike most other Zephyr libraries, libkernel.a is not built as a
whole-archive.
This change also fixes a linker error observed on nucleo_wb55rg while
preparing an upgrade to Zephyr v3.5.0, caused by an undefined reference to
`z_impl_k_busy_wait`.
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
This adds a QEMU-based bare metal RISC-V 32 bits port. For the time being
only QEMU's "virt" 32 bits board is supported, using the ilp32 ABI and the
RV32IMC architecture.
The top-level README and the run-tests.py files are updated for this new
port.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
All of these files are first-party code written from scratch as part of
this repository, and were added when the top-level MIT license was active,
so they have an MIT license by default. Tracing back the git history show
the original authors/source/copyright as follows:
- main.c, mpconfigport.h: copied from the bare-arm port [1].
- test_main.c: added in [2].
- mphalport.h: added in [3] then updated in [4].
- mps2.ld, nrf51.ld, stm32.ld, uart.h: added in [4].
- imx6.ld, uart.c, startup.c: added in [4] and updated in [5].
[1] Commit c557215822 in 2014, the initial
bare-arm port; see related ee857853d6.
[2] Commit c1c32d65af in 2014, initial
qemu-arm CI tests.
[3] Commit b0a15aa735 in 2016, enabling
extmods and their tests.
[4] Commit e7332b0584 in 2018, big refactor.
[5] Commit b84406f313 in 2021, adding
Cortex-A9 support.
Signed-off-by: Damien George <damien@micropython.org>
This makes the code a bit simpler to understand for the three cases of
timeout behaviour (-1, 0, non-zero), and eliminates a dependency on the
(slow) `mp_hal_delay_ms(100)` call.
Signed-off-by: Damien George <damien@micropython.org>
If the socket timeout is 0 then a failed socket.connect() raises
EINPROGRESS (which is what the lwIP bindings already did), but if the
socket timeout is non-zero then a failed socket.connect() should raise
ETIMEDOUT. The latter is fixed in this commit.
A test is added for these timeout cases.
Signed-off-by: Damien George <damien@micropython.org>
Currently, `cyw43_delay_ms()` calls `mp_hal_delay_ms()` which uses PendSV
to set up a timer and wait for an interrupt, using wfe. But in the cyw43
initialisation stage PendSV is disabled and so this delay suspends on the
wfe instruction for an indefinite amount of time.
Work around this by changing the implementation of `cyw43_delay_ms()` to a
busy loop.
Fixes issue #15220.
Signed-off-by: Damien George <damien@micropython.org>
Support for raw str/bytes already exists, and extending that to raw
f-strings is easy. It also reduces code size because it eliminates an
error message.
Signed-off-by: Damien George <damien@micropython.org>
This is quite a simple and small change to support concatenation of
adjacent f-strings, and improve compatibility with CPython.
Signed-off-by: Damien George <damien@micropython.org>
fdilibm was originally meant to see _IEEE_LIBM defined from outside the
libm code, not it being hardcoded in. Picolibc assumes this assumption
holds true and attempts to define itself, conflicting with the existing
definition.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This adds a RISC-V RV32 semihosting implementation, with all defined
system calls exposed to the user.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Make room for RISC-V semihosting code, by renaming the existing
`semihosting.[ch]` files into `semihosting_arm.[ch]`.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
When no usable manifest directives are found (as opposed to no manifest
being set in the makefile), non-compiling code was generated for the
empty frozen constants pool block.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
At startup, buffer initial stdout / MicroyPthon banner so that it can be
sent to the host on initial connection of the USB serial port. This
buffering also works for when the CDC becomes disconnected and the device
is still printing to stdout, and when CDC is reconnected the most recent
part of stdout (depending on how big the internal USB FIFO is) is flushed
to the host.
This change is most obvious when you've first plugged in a MicroPython
device (or hit reset), when it's a board that uses USB (CDC) serial in the
chip itself for the REPL interface. This doesn't apply to UART going via a
separate USB-serial chip.
The stm32 port already has this buffering behaviour (it doesn't use
TinyUSB) and this commit extends such behaviour to rp2, mimxrt, samd and
renesas-ra ports, which do use TinyUSB.
Signed-off-by: Andrew Leech <andrew@alelec.net>
This implements network.ipconfig() and network.WLAN.ipconfig() when the
ninaw10 driver is used for WLAN.
Due to a omission in the ninaw10 driver stack, setting the DNS address has
no effect. But the interface is kept here just in case it's fixed
eventually.
dhcp4 and has_dhcp4 are dummy arguments. Ninaw10 seems to always use DHCP.
Signed-off-by: robert-hh <robert@hammelrath.com>
This tool is used to compute size differences in the firmware (eg as part
of CI), but it doesn't currently check any firmware that has bare-metal
lwIP/networking, making it hard to see how firmware size changes when
networking related changes are made.
So, change the board selection for the rp2 port to RPI_PICO_W. Changes in
size to standard RPI_PICO firmware will be very similar to other bare-metal
boards like PYBV10.
Signed-off-by: Damien George <damien@micropython.org>
Assuming that ${MICROPY_PORT_DIR}/boards/${MICROPY_BOARD} is equal to
${MICROPY_BOARD_DIR} is not valid, because the latter could point to a path
outside the main MicroPython repository.
Replace this path with the canonical ${MICROPY_BOARD_DIR} so that pins.csv
is correctly located when building against out-of-tree board definitions.
Additionally remove MICROPY_BOARDS_DIR to discourage similar mistakes.
Signed-off-by: Phil Howard <phil@gadgetoid.com>
Without this change going to lightsleep stops the USB peripheral clock, and
can lead to either the device going into a weird state or the host deciding
to issue a bus reset.
This change only keeps the USB peripheral clocks enabled if the USB device
is currently active and a host has configured the device. This means the
USB device continues to respond to host transfers and (presumably) will
even complete pending endpoint transfers. All other requests are NAKed
while still asleep, but the interaction with the host seems to resume
correctly on wake
Otherwise, if USB is not active or configured by a host, USB clocks are
disabled, the same as before.
With the change, one can issue a `machine.lightsleep(...)` with USB CDC
connected and the USB CDC remains connected during the sleep and resumes
when the lightsleep finishes.
Tested on a RPi Pico, the power consumption is:
- During normal idle at the REPL, about 15.3mA.
- During lightsleep, prior to this change, about 1.35mA.
- During lightsleep, with this change and USB CDC connected, about 3.7mA.
If power consumption should be as low as possible when USB is connected,
one can use `machine.USBDevice` to disable the USB before entering
lightsleep.
As discussed at https://github.com/orgs/micropython/discussions/14401
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
To avoid undefined references to `mp_thread_begin_atomic_section()` /
`mp_thread_end_atomic_section()`, replace them with the
`MICROPY_BEGIN_ATOMIC_SECTION` / `MICROPY_END_ATOMIC_SECTION`
macros. That way, it's possible to build again with `MICROPY_PY_THREAD`
disabled (made possible by efa54c27b9).
Fixes commit 19844b4983.
Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This fixes the build for some esp32 and nrf boards (for example
`ARDUINO_NANO_33_BLE_SENSE` and `ARDUINO_NANO_ESP32`) due to commit
c98789a6d8. Changes are:
- Allow the CDC TX/RX functions in `mp_usbd_cdc.c` to be enabled
separately to those needed for `MICROPY_HW_USB_CDC_1200BPS_TOUCH`.
- Add `MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC` option as a temporary
workaround for the nrf port to use.
- Declare `mp_usbd_line_state_cb()` in a header as a public function.
- Fix warning with type cast of `.callback_line_state_changed`.
Signed-off-by: Damien George <damien@micropython.org>
Update to the issue forms added earlier this year, that seem to generally
be working well. Improvements in this commit:
- No longer generates TODO checklists in new issues.
- Issue bodies (and therefore email previews) no longer start with the same
fixed checklist text for each new issue.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
There are a few TinyUSB CDC functions used for stdio that are currently
replicated across a number of ports. Not surprisingly in a couple of cases
these have started to diverge slightly, with additional features added to
one of them.
This commit consolidates a couple of key shared functions used directly by
TinyUSB based ports, and makes those functions available to all.
Signed-off-by: Andrew Leech <andrew@alelec.net>
Since C99, `FLT_EVAL_METHOD` should be left for the compiler/libc to
define. Its redefinition breaks compilation with picolibc as the
target's libc, since it defines said symbol in math.h before the libm
define is evaluated by the compiler.
In its place, there is a check to make sure floating point type sizes
are what are expected to be, triggering a compilation error if those
assumptions are no longer valid.
Co-authored-by: Angus Gratton <angus@redyak.com.au>
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Previously, this was subject to races incrementing/decrementing
the counter variable pendsv_lock.
Technically, all that's needed here would be to make pendsv_lock an atomic
counter.
This implementation fulfils a stronger guarantee: it also provides mutual
exclusion for the core which calls pendsv_suspend(). This is because the
current use of pendsv_suspend/resume in MicroPython is to ensure exclusive
access to softtimer data structures, and this does require mutual
exclusion.
The conceptually cleaner implementation would split the mutual exclusion
part out into a softtimer-specific spinlock, but this increases the
complexity and doesn't seem like it makes for a better implementation in
the long run.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The best_effort_wfe_or_timeout() and sleep_us() pico-sdk functions use the
pico-sdk alarm pool internally, and that has a bug.
Some usages inside pico-sdk (notably multicore_lockout_start_blocking())
will still end up calling best_effort_wfe_or_timeout(), although usually
with "end_of_time" as the timeout value so it should avoid any alarm pool
race conditions.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Progress towards removing pico-sdk alarm pool, due to a known issue.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
In CPython 3.12 these invalid str/bytes/fstring escapes will issue a
SyntaxWarning, and so differ to MicroPython.
Signed-off-by: Damien George <damien@micropython.org>
Otherwise CPython gives a deprecation warning.
This test is not actually testing inversion of bools, rather that bit of
the test is used to compute the pass/fail result.
Signed-off-by: Damien George <damien@micropython.org>
This brings in:
- fixes to: aiohttp, tarfile, lora, gzip
- fixes and improvements to aioble
- deprecation of cbor2 decoder and encoder modules
- new usb package
- new pyusb package
Signed-off-by: Damien George <damien@micropython.org>
The `cert` argument passed to the verify callback is actually a memoryview.
And the `depth` argument seems to start at 1 for the tested URL.
Signed-off-by: Damien George <damien@micropython.org>
The three-argument form of `.throw()` is deprecated since CPython 3.12. So
split out into separate tests (with .exp files) the parts of the generator
tests that test more than one argument.
Signed-off-by: Damien George <damien@micropython.org>
And use `asyncio.new_event_loop()` where possible. This change is needed
because CPython 3.12 deprecated the `get_event_loop()` function.
Signed-off-by: Damien George <damien@micropython.org>
Eventually this needs to be made a generic call to the underlying VFS. But
for now this prevents `disk_ioctl()` crashing on non-FAT filesystems.
Signed-off-by: Damien George <damien@micropython.org>
The `run-natmodtests.py` script now properly excludes tests that don't use
the corresponding native module.
Signed-off-by: Damien George <damien@micropython.org>
Python code is no longer needed to implement keyword arguments in
`btree.open()`, it can now be done in C.
Signed-off-by: Damien George <damien@micropython.org>
Also define `mp_type_bytearray`. These all help to write native modules.
Signed-off-by: Brian Pugh <bnp117@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
This adds support for the TCP_NODELAY socket option for lwIP sockets.
Generally, TCP sockets use the Nagle algorithm and will send data when
an ACK is received or after all previously-sent data has already been
ACKed.
If the TCP_NODELAY option is set for a socket, every write to the socket
will trigger a packet to be sent.
Signed-off-by: Jared Hancock <jared@greezybacon.me>
This adds support to use the Nagle algorithm implemented already in lwIP to
determine when TCP data should be sent.
As currently written, MicroPython will only create packets if there is <25%
remaining in the send buffer. Using it, sending a small message of ~50
bytes will not trigger output of the message on the network. So it will
remained queued until the TCP interval timer expires, which can be up to
500ms.
Using Nagle's algorithm, the first write, no matter how small, will
generate a packet on the network. And sending lots of data still makes
efficient use of the link.
In addition to this, an application designer may choose to always create
packets for every write by setting the TCP_NODELAY socket option. That's
also implemented in this commit.
This allows querying the GC heap size/used/free values, as well as the
number of alive JsProxy and PyProxy objects, referenced by proxy_c_ref and
proxy_js_ref.
Signed-off-by: Damien George <damien@micropython.org>
And clear the corresponding `proxy_c_ref[c_ref]` entry when the finaliser
runs. This then allows the C side to (eventually) garbage collect the
corresponding Python object.
Signed-off-by: Damien George <damien@micropython.org>
And clear the corresponding `proxy_js_ref[js_ref]` entry when the finaliser
runs. This then allows the JavaScript side to (eventually) free the
corresponding JavaScript object.
Signed-off-by: Damien George <damien@micropython.org>
So it's possible to know when an external C function is being called at the
top-level, eg by JavaScript without any intermediate C->JS->C calls.
Signed-off-by: Damien George <damien@micropython.org>
Instead of raising KeyError. These semantics match JavaScript behaviour
and make it much more seamless to pass Python dicts through to JavaScript
as though they were JavaScript {} objects.
Signed-off-by: Damien George <damien@micropython.org>
This adds a new undefined singleton to Python, that corresponds directly to
JavaScript `undefined`. It's accessible via `js.undefined`.
Signed-off-by: Damien George <damien@micropython.org>
This reverts part of commit fa23e4b093, to
make it so that Python `None` converts to JavaScript `null` (and JavaScript
`null` already converts to Python `None`). That's consistent with how the
`json` module converts these values back and forth.
Signed-off-by: Damien George <damien@micropython.org>
When a fatal error occurs it's important to know which precise version it
occurred on in order to be able to decode the crash dump information such
as the backtrace.
By wrapping around the built-in IDF panic handler we can print some extra
information whenever a fatal error occurs. The message links to a new wiki
page which contains additional information on how to debug ESP32 issues,
and links to the bug reporting issue template.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Fixes automatic baudrate calculation results.
Default clock source on this SoC is HSE not PCLK1. We could fix this by
switching to PCLK1 instead, but two extra complications:
- PCLK1 on this board is a 42.5MHz and the Pyboard CAN sample_point
calculation requires an exact match, which is harder to hit with this
source frequency.
- Would be a breaking change for any existing Python code on this board,
i.e. specifying brp, bs1, bs2 to initialise CAN.
In the future it might be worth looking switching to the PLL source on this
SoC instead, as this is a much higher frequency that would give higher
quality BRS bitrate matches (probably too high without using the second
divider going into the CAN peripheral though, so more code changes needed
also).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
And change Py None conversion so it converts to JS undefined.
The semantics for conversion of these objects are then:
- Python None -> JavaScript undefined
- JavaScript undefined -> Python None
- JavaScript null -> Python None
This follows Pyodide:
https://pyodide.org/en/stable/usage/type-conversions.html
Signed-off-by: Damien George <damien@micropython.org>
This commit defines a new `JsException` exception type which is used on the
Python side to wrap JavaScript errors. That's then used when a JavaScript
Promise is rejected, and the reason is then converted to a `JsException`
for the Python side to handle.
This new exception is exposed as `jsffi.JsException`.
Signed-off-by: Damien George <damien@micropython.org>
Non-blocking SSL streams can be difficult to get right, so provide a
working example, of a HTTPS client.
Signed-off-by: Damien George <damien@micropython.org>
It's better for discoverability to have these examples named `https_xxx.py`
rather than `http_xxx_ssl.py`.
Signed-off-by: Damien George <damien@micropython.org>
Only when dynamic USB devices are enabled.
The issue here is that when the USB reset triggers, the dynamic USB device
reset callback is called from inside the TinyUSB task.
If that callback tries to print something then it'll call through to
tud_cdc_write_flush(), but TinyUSB hasn't finished updating state yet to
know it's no longer configured. Subsequently it may try to queue a transfer
and then the low-level DCD layer panics.
By explicitly stalling the endpoint first, usbd_edpt_claim() will fail and
tud_cdc_write_flush() returns immediately.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The W5100 and W5100S only have 4 available sockets and 16kB of socket
buffer. Allocating 16kB to either the receive or transmit buffer of a
single socket is not allowed, so the current setup does not change the
allocation for socket 0 from the reset default. ctlwizchip is returning -1
to indicate the error, but the response isn't being inspected and probably
doesn't need to be.
Signed-off-by: Jared Hancock <jared@greezybacon.me>
For ESP32C3/S2/S3 IDFv5 exposes new internal temperature API which is
different to the base ESP32, IDFv4.
Thanks to @robert-hh for cleaner code and testing sensor capability in
these devices.
See discussion #10443.
Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
JavaScript semantics are such that the caller of an async function does not
need to await that function for it to run to completion. This commit makes
that behaviour also apply to top-level async Python code run via
`runPythonAsync()`.
Signed-off-by: Damien George <damien@micropython.org>
The `reason` in a rejected promise should be an instance of `Error`. That
leads to better error messages on the JavaScript side.
Signed-off-by: Damien George <damien@micropython.org>
Different MCUs have different requirements for the minimum number of bytes
that can be written to internal flash.
Signed-off-by: Damien George <damien@micropython.org>
The calculations `num_word32 / 4` and `num_word32 / 8` were rounding down
the number of words to program to flash, and therefore possibly truncating
the data (eg mboot could miss writing the final few words of the firmware).
That's fixed in this commit by adding extra logic to program any remaining
words. And the logic for H5 and H7 is combined.
Signed-off-by: Damien George <damien@micropython.org>
In case there is a power failure after during this operation, the key must
be the last thing that is written, to indicate valid data.
Signed-off-by: Damien George <damien@micropython.org>
Although the original motivation given for the workaround[1] is correct,
nlr.o and nlrthumb.o are linked with a small enough distance that the
problem does not occur, and the workaround isn't necessary. The distance
between the b instruction and its target (nlr_push_tail) is just 64
bytes[2], well within the ±2046 byte range addressable by an
unconditional branch instruction in Thumb mode.
The workaround induces a relocation in the text section (textrel), which
isn't supported everywhere, notably not on musl-libc[3], where it causes
a crash on start-up. With the workaround removed, micropython works on an
ARMv5T Linux system built with musl-libc.
This commit changes nlrthumb.c to use a direct jump by default, but
leaves the long jump workaround as an option for those cases where it's
actually needed.
[1]: commit dd376a239d
Author: Damien George <damien.p.george@gmail.com>
Date: Fri Sep 1 15:25:29 2017 +1000
py/nlrthumb: Get working again on standard Thumb arch (ie not Thumb2).
"b" on Thumb might not be long enough for the jump to nlr_push_tail so
it must be done indirectly.
[2]: Excerpt from objdump -d micropython:
000095c4 <nlr_push_tail>:
95c4: b510 push {r4, lr}
95c6: 0004 movs r4, r0
95c8: f02d fd42 bl 37050 <mp_thread_get_state>
95cc: 6943 ldr r3, [r0, #20]
95ce: 6023 str r3, [r4, #0]
95d0: 6144 str r4, [r0, #20]
95d2: 2000 movs r0, #0
95d4: bd10 pop {r4, pc}
000095d6 <nlr_pop>:
95d6: b510 push {r4, lr}
95d8: f02d fd3a bl 37050 <mp_thread_get_state>
95dc: 6943 ldr r3, [r0, #20]
95de: 681b ldr r3, [r3, #0]
95e0: 6143 str r3, [r0, #20]
95e2: bd10 pop {r4, pc}
000095e4 <nlr_push>:
95e4: 60c4 str r4, [r0, #12]
95e6: 6105 str r5, [r0, #16]
95e8: 6146 str r6, [r0, #20]
95ea: 6187 str r7, [r0, #24]
95ec: 4641 mov r1, r8
95ee: 61c1 str r1, [r0, #28]
95f0: 4649 mov r1, r9
95f2: 6201 str r1, [r0, #32]
95f4: 4651 mov r1, sl
95f6: 6241 str r1, [r0, #36] @ 0x24
95f8: 4659 mov r1, fp
95fa: 6281 str r1, [r0, #40] @ 0x28
95fc: 4669 mov r1, sp
95fe: 62c1 str r1, [r0, #44] @ 0x2c
9600: 4671 mov r1, lr
9602: 6081 str r1, [r0, #8]
9604: e7de b.n 95c4 <nlr_push_tail>
[3]: https://www.openwall.com/lists/musl/2020/09/25/4
Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
This allows a simple way to run the existing asyncio tests under the
webassembly port, which doesn't support `asyncio.run()`.
Signed-off-by: Damien George <damien@micropython.org>
This commit adds a significant portion of the existing MicroPython asyncio
module to the webassembly port, using parts of the existing asyncio code
and some custom JavaScript parts.
The key difference to the standard asyncio is that this version uses the
JavaScript runtime to do the actual scheduling and waiting on events, eg
Promise fulfillment, timeouts, fetching URLs.
This implementation does not include asyncio.run(). Instead one just uses
asyncio.create_task(..) to start tasks and then returns to the JavaScript.
Then JavaScript will run the tasks.
The implementation here tries to reuse as much existing asyncio code as
possible, and gets all the semantics correct for things like cancellation
and asyncio.wait_for. An alternative approach would reimplement Task,
Event, etc using JavaScript Promise's. That approach is very difficult to
get right when trying to implement cancellation (because it's not possible
to cancel a JavaScript Promise).
Signed-off-by: Damien George <damien@micropython.org>
When a Promise is rejected on the JavaScript side, the reject reason should
be thrown into the encapsulating generator on the Python side.
Signed-off-by: Damien George <damien@micropython.org>
An exception on the Python side should be passed to the Promise reject
callback on the JavaScript side.
Signed-off-by: Damien George <damien@micropython.org>
Otherwise Emscripten allocates it on the Emscripten C stack, which will
overflow for large amounts of code.
Fixes issue #14307.
Signed-off-by: Damien George <damien@micropython.org>
In modularize mode, the `_createMicroPythonModule()` constructor must be
await'ed on, before `Module` is ready to use.
Signed-off-by: Damien George <damien@micropython.org>
Two cases, one assigning to a slice.
Closes https://github.com/micropython/micropython/issues/13283
Second is extending a slice from itself, similar logic.
In both cases the problem occurs when m_renew causes realloc to move the
buffer, leaving a dangling pointer behind.
There are more complex and hard to fix cases when either argument is a
memoryview into the buffer, currently resizing to a new address breaks
memoryviews into that object.
Reproducing this bug and confirming the fix was done by running the unix
port under valgrind with GC-aware extensions.
Note in default configurations with GIL this bug exists but has no impact
(the free buffer won't be reused while the function is still executing, and
is no longer referenced after it returns).
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit swaps the order of the `flags` and `name` struct initialisers
for `mp_obj_type_t`, to fix an incompatibility with C++. The original
order of the initialiser didn't match the definition of the type, and
although that's still legal C, it's not legal C++.
Signed-off-by: Vonasmic <kasarkal123@gmail.com>
When `lightsleep()` is called from within a thread the interrupts may not
be enabled on current core, and thus the call to `lightsleep()` never
completes.
Fixes issue #14092.
Signed-off-by: Simon Wood <simon@mungewell.org>
In the case where an OUT control transfer triggers with wLength==0 (i.e.
all data sent in the SETUP phase, and no additional data phase) the
callbacks were previously implemented to return b"" (i.e. an empty buffer
for the data phase).
However this didn't actually work as intended because b"" can't provide a
RW buffer (needed for OUT transfers with a data phase to write data into),
so actually the endpoint would stall.
The symptom was often that the device process the request (if processing
it in the SETUP phase when all information was already available), but the
host sees the endpoint stall and eventually returns an error.
This commit changes the behaviour so returning True from the SETUP phase of
a control transfer queues a zero length status response.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This optimises the case where a Python function is, for example, stored to
a JavaScript attribute and then later retrieved from Python. The Python
function no longer needs to be a proxy with double proxying needed for the
call from Python -> JavaScript -> Python.
Signed-off-by: Damien George <damien@micropython.org>
Use the existing metal log handling mechanism instead of overriding the
metal_log, which causes build issues when logging is enabled.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Ports that use axtls cannot run the `test_tls_sites.py` test because the
sites it connects to use advanced ciphers. So skip this test on such
ports, and add a new, simpler test that doesn't require certificate
verification and works with axtls.
Signed-off-by: Damien George <damien@micropython.org>
Supporting `verify_mode` and `CERT_NONE` is required for the new `ssl.py`
code, as well as `requests` to work.
Signed-off-by: Damien George <damien@micropython.org>
This is required because the .mpy native ABI was changed by the
introduction of `mp_proto_fun_t`, see commits:
- 416465d81e
- 5e3006f117
- e2ff00e811
And three `mp_binary` functions were added to `mp_fun_table` in
commit d2276f0d41.
Signed-off-by: Damien George <damien@micropython.org>
These are needed to read/write array.array objects, which is useful in
native code to provide fast extensions that work with big arrays of data.
Signed-off-by: Damien George <damien@micropython.org>
Change provided by @ironss-iotec.
Tested with Adafruit, SEEED and MiniFig boards for non-interference.
Fixes issue #14190.
Signed-off-by: robert-hh <robert@hammelrath.com>
Using a define for MICROPY_HW_SPIFLASH_BAUDRATE in mpconfigboard.h. If not
defined the default is 24MHz.
Signed-off-by: robert-hh <robert@hammelrath.com>
For all MCUs: run the test for USB clock recovery mode fallback after USB
has been started.
For samd21: change DFLL48 config from the open loop mode variant to sync
with the XOSC32KULP. Matches better the 48MHz value.
Signed-off-by: robert-hh <robert@hammelrath.com>
Other constants such as `machine.Pin.OUT` are defined on the class that
uses them, rather than at the module level. This commit makes that the
case for WLAN network interfaces, adding IF_xxx and SEC_xxx constants.
The SEC_xxx constants are named as such to match the `security` keyword
that they are used with. And the IF_xxx constants have IF as a prefix so
they are grouped together as names.
This scheme of putting constants on the class means that only the available
features (eg security configurations) are made available as constants. It
also means that different network interfaces (eg WLAN vs LAN) can keep
their own specific constants within their class, such as PHY_xxx for LAN.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
The default CYW43 WiFi AP settings were missing the security mode, leaving
the AP in open mode by default. That's changed by this commit to use
WPA/WPA2 by default.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
When defining custom USB devices, longer strings may be needed. Eventually
the memory for string descriptors can be allocated on demand, but for now
this bigger value should be reasonable.
Signed-off-by: Damien George <damien@micropython.org>
Updates a few code comments that were out of date or poorly worded. No code
changes.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Previously, constructing the singleton USBDevice object was enough to
trigger a USB disconnect on soft reset. Now it also has to be active.
The only case where this changes the behaviour is if the USBDevice object
has been constructed but never set to active (no more disconnect in this
case). Otherwise, behaviour is the same.
This change was requested by hippy on the raspberrypi forums.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
When PWM constructor was created without specifying a device or setting
both freq and duty rate, it was not tagged as used, and further calls to
get a PWM object may get the same PWM device assigned.
Fixes#13494.
Signed-off-by: robert-hh <robert@hammelrath.com>
Exceptions in pin interrupt handlers would end up crashing MicroPython with
a "FATAL: uncaught exception".
In addition, MicroPython would get stuck trying to output this error
message, or generally any print output from inside a pin interrupt handler,
through the UART after the first character, so that only "F" was visible.
The reason was a matching interrupt priority between the running pin
interrupt and the UARTE interrupt signaling completion of the output
operation. Fix that by increasing the UARTE interrupt priority.
Code taken from the stm32 port and adapted.
Signed-off-by: Christian Walther <cwalther@gmx.ch>
Under some circumstances, after a hard reset, the low-frequency clock would
not be running. This caused time.ticks_ms() to return 0, time.sleep_ms()
to get stuck, and other misbehavior. A soft reboot would return it to a
working state.
The cause was a race condition that was hit when the bootloader would
itself turn LFCLK on, but turn it off again shortly before launching the
main application (this apparently happens with the Adafruit bootloader
from https://github.com/fanoush/ds-d6/tree/master/micropython). Stopping
the clock is an asynchronous operation and it continues running for a short
time after the stop command is given. When MicroPython checked whether to
start it by looking at the LFCLKSTAT register (nrf_clock_lf_is_running)
during that time, it would mistakenly not be started again. What
MicroPython should be looking at is not whether the clock is running at
this time, but whether a start/stop command has been given, which is
indicated by the LFCLKRUN register (nrf_clock_lf_start_task_status_get).
It is not clearly documented, but empirically LFCLKRUN is not just set when
the LFCLKSTART task is triggered, but also cleared when the LFCLKSTOP task
is triggered, which is exactly what we need.
The matter is complicated by the fact that the nRF52832 has an anomaly
(see [errata](https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev3/ERR/nRF52832/Rev3/latest/anomaly_832_132.html?cp=5_2_1_0_1_33))
where starting the LFCLK will not work between 66µs and 138µs after it last
stopped. Apply a workaround for that. See nrfx_clock_lfclk_start() in
micropython/lib/nrfx/drivers/src/nrfx_clock.c for reference, but we are not
using that because it also does other things and makes the code larger.
Signed-off-by: Christian Walther <cwalther@gmx.ch>
It destroys a few manual alignments, but these seem minor compared to
the benefit of automated code style consistency.
Signed-off-by: Christian Walther <cwalther@gmx.ch>
Trying to use an external board definition according to
https://github.com/micropython/micropython-example-boards on the nrf port
failed with "Invalid BOARD specified". Replacing all ocurrences of
"boards/$(BOARD)" with "$(BOARD_DIR)" following the example of
stm32/Makefile fixes that.
Signed-off-by: Christian Walther <cwalther@gmx.ch>
The documentation for `freeze()` says that:
- If `script` is `None`, all files in `path` will be frozen.
- If `script` is an iterable then `freeze()` is called on all items of the
iterable.
This commit makes sure this behaviour is followed when an empty tuple/list
is passed in for `script` (previously an empty tuple/list froze all files).
Fixes issue #14125.
Signed-off-by: Damien George <damien@micropython.org>
According to the datasheet, the IEN bit to enable the interrupt is in the
MR2 register, not the MR register.
This is just cleanup as the interrupt appears to be enabled by default
after resetting the chip.
Tested on W5100S_EVB_PICO.
During a build the ESP-IDF downloads managed components in the
ports/esp32/managed_components directory, which shouldn't be spellchecked.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
If the heap allocation fails we will crash if we continue, so at least we
can show a clear error message so one can figure out memory allocation was
the problem (instead of just seeing some arbitrary null pointer error
later).
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Newer versions of gcc (14 and up) have more sophisticated dead-code
detection, and the asm clobbers list needs to contain "memory" to inform
the compiler that the asm code actually does something.
Tested that adding this "memory" line does not change the generated code on
ARM Thumb2, x86-64 and Xtensa targets (using gcc 13.2).
Fixes issue #14115.
Signed-off-by: Damien George <damien@micropython.org>
This allows running tests with a .js/.mjs suffix, and also .py tests using
node and the webassembly port.
Signed-off-by: Damien George <damien@micropython.org>
This commit adds a pyscript variant for use in https://pyscript.net/.
The configuration is:
- No ASYNCIFY, in order to keep the WASM size down and have good
performance.
- MICROPY_CONFIG_ROM_LEVEL_FULL_FEATURES to enable most features.
- Custom manifest that includes many of the python-stdlib libraries.
- MICROPY_GC_SPLIT_HEAP_AUTO to increase GC heap size instead of doing a
collection when memory is exhausted. This is needed because ASYNCIFY is
disabled. Instead the GC collection is run at the top-level before
executing any Python code.
- No MICROPY_VARIANT_ENABLE_JS_HOOK because there is no asynchronous
keyboard input to interrupt a running script.
Signed-off-by: Damien George <damien@micropython.org>
With this commit, `interpreter.runPythonAsync(code)` can now be used to run
Python code that uses `await` at the top level. That will yield up to
JavaScript and produce a thenable, which the JavaScript runtime can then
resume. Also implemented is the ability for Python code to await on
JavaScript promises/thenables. For example, outer JavaScript code can
await on `runPythonAsync(code)` which then runs Python code that does
`await js.fetch(url)`. The entire chain of calls will be suspended until
the fetch completes.
Signed-off-by: Damien George <damien@micropython.org>
This commit improves the webassembly port by adding:
- Proxying of Python objects to JavaScript with a PyProxy type that lives
on the JavaScript side. PyProxy implements JavaScript Proxy traps such
as has, get, set and ownKeys, to make Python objects have functionality
on the JavaScript side.
- Proxying of JavaScript objects to Python with a JsProxy type that lives
on the Python side. JsProxy passes through calls, attributes,
subscription and iteration from Python to JavaScript.
- A top-level API on the JavaScript side to construct a MicroPython
interpreter instance via `loadMicroPython()`. That function returns an
object that can be used to execute Python code, access the Python globals
dict, access the Emscripten filesystem, and other things. This API is
based on the API provided by Pyodide (https://pyodide.org/). As part of
this, the top-level file is changed from `micropython.js` to
`micropython.mjs`.
- A Python `js` module which can be used to access all JavaScript-side
symbols, for example the DOM when run within a browser.
- A Python `jsffi` module with various helper functions like
`create_proxy()` and `to_js()`.
- A dedenting lexer which automatically dedents Python source code if every
non-empty line in that source starts with a common whitespace prefix.
This is very helpful when Python source code is indented within a string
within HTML or JavaScript for formatting reasons.
Signed-off-by: Damien George <damien@micropython.org>
This commit cleans up and generalises the Makefile, adds support for
variants (following the unix port) and adds the "standard" variant as the
default variant.
Signed-off-by: Damien George <damien@micropython.org>
When enabled the GC will not reclaim any memory on a call to
`gc_collect()`. Instead it will grow the heap.
Signed-off-by: Damien George <damien@micropython.org>
Enabled by MICROPY_COMPILE_ALLOW_TOP_LEVEL_AWAIT. When enabled, this means
that scope such as module-level functions and REPL statements can yield.
The outer C code must then handle this yielded generator.
Signed-off-by: Damien George <damien@micropython.org>
This workaround makes sure that all ringbuf functions that may be called
from an ISR are placed in IRAM. See
https://github.com/espressif/esp-idf/issues/13378
Note that this means that all esp32-og builds get non-ISR ringbuf functions
placed in flash now, whereas previously it was just the spiram variant.
This might be a good thing (e.g. free up some IRAM for native/viper).
Fixes issue #14005.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This fixes a bug where a random Python object may become
un-garbage-collectable until an enclosing Python file (compiled on device)
finishes executing.
Details:
The mp_parse_tree_t structure is stored on the stack in top-level functions
such as parse_compile_execute() in pyexec.c (and others).
Although it quickly falls out of scope in these functions, it is usually
still in the current stack frame when the compiled code executes. (Compiler
dependent, but usually it's one stack push per function.)
This means if any Python object happens to allocate at the same address as
the (freed) root parse tree chunk, it's un-garbage-collectable as there's a
(dangling) pointer up the stack referencing this same address.
As reported by @GitHubsSilverBullet here:
https://github.com/orgs/micropython/discussions/14116#discussioncomment-8837214
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit implements the 'e' half-float format: 10-bit mantissa, 5-bit
exponent. It uses native _Float16 if supported by the compiler, otherwise
uses custom bitshifting encoding/decoding routines.
Signed-off-by: Matthias Urlichs <matthias@urlichs.de>
Signed-off-by: Damien George <damien@micropython.org>
This commit implements a new <AbstractNIC>.ipconfig() function for the NIC
classes that use lwIP, to set and retrieve network configuration for a NIC.
Currently this method supports:
- ipconfig("addr4"): obtain a tuple (addr, netmask) of the currently
configured ipv4 address
- ipconfig("addr6"): obtain a list of tuples (addr, state,
prefered_lifetime, valid_lifetime) of all currently active ipv6
addresses; this includes static, slaac and link-local addresses
- ipconfig("has_dhcp4"): whether ipv4 dhcp has supplied an address
- ipconfig("has_autoconf6"): if there is a valid, non-static ipv6 address
- ipconfig(addr4="1.2.3.4/24"): to set the ipv4 address and netmask
- ipconfig(addr6="2a01::2"): to set a static ipv6 address; note that this
does not configure an interface route, as this does not seem supported by
lwIP
- ipconfig(autoconf6=True): to enable ipv6 network configuration with slaac
- ipconfig(gw4="1.2.3.1"): to set the ipv4 gateway
- ipconfig(dhcp4=True): enable ipv4 dhcp; this sets ipv4 address, netmask,
gateway and a dns server
- ipconfig(dhcp4=False): stops dhcp, releases the ip, and clears the
configured ipv4 address.
- ipconfig(dhcp6=True): enable stateless dhcpv6 to obtain a dns server
There is also a new global configuration function network.ipconfig() that
supports the following:
- network.ipconfig(dns="2a01::2"): set the primary dns server (can be a
ipv4 or ipv6 address)
- network.ipconfig(prefer=6): to prefer ipv6 addresses to be returned as
dns responses (falling back to ipv4 if the host does not have an ipv6
address); note that this does not flush the dns cache, so if a host is
already in the dns cache with its v4 address, subsequent lookups will
return that address even if prefer=6 is set
This interface replaces NIC.ifconfig() completely, and ifconfig() should be
marked as deprecated and removed in a future version.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
The C-based SPI flash driver is needed because the
`_copy_file_to_raw_filesystem()` function must copy from a filesystem (eg
FAT) to another part of flash, and the same C code must be used for both
reading (from FAT) and writing (to flash).
Signed-off-by: Damien George <damien@micropython.org>
This is enabled by default if MBOOT_FSLOAD is enabled, although a board
can explicitly disable it by `#define MBOOT_VFS_RAW (0)`.
Signed-off-by: Damien George <damien@micropython.org>
ASM_NOT_REG is optional, it can be synthesised by xor(reg, -1).
ASM_NEG_REG can also be synthesised with a subtraction, but most
architectures have a dedicated instruction for it.
Signed-off-by: Damien George <damien@micropython.org>
So that the MicroPython-specific behaviour can be isolated, and the CPython
compatible test don't need a .exp file.
Signed-off-by: Damien George <damien@micropython.org>
The argument to MP_BC_MAKE_FUNCTION (raw code index) was being encoded as a
byte instead of a variable unsigned int. That meant that if there were
more than 128 merged mpy files the encoding would be invalid.
Fix that by using `mp_encode_uint(idx)` to encode the raw code index. And
also use `Opcode` constants for the opcode values to make it easier to
understand the code.
Signed-off-by: Damien George <damien@micropython.org>
Add `pop()`, `appendleft()`, and `extend()` methods, support iteration
and indexing, and initializing from an existing sequence.
Iteration and indexing (subscription) have independent configuration flags
to enable them. They are enabled by default at the same level that
collections.deque is enabled (the extra features level).
Also add tests for checking new behavior.
Signed-off-by: Damien George <damien@micropython.org>
This provides a MicroPython-specific berkeley-db configuration in
extmod/berkeley-db/berkeley_db_config_port.h, and cleans up the include
path for this library.
Fixes issue #13092.
Signed-off-by: Damien George <damien@micropython.org>
This updates the berkeley-db-1.xx submodule URL to a repository hosted
under the micropython organisation, and makes the following changes:
- Moves the berkeley-db header files to a single directory within the
submodule, and references all these headers with a much fuller path,
which prevents symbol clashes (eg with esp32 and queue.h).
- Removes unused/non-working files from berkeley-db, which removes all
symlinks in that repo (symlinks don't play well under Windows).
- Allows injecting an external configuration header into berkeley-db, so
the configuration doesn't have to be provided by -Dxx=yy flags to the
compiler (and possibly clashing with other symbols).
- Removes the advertising clause from the BSD 4-clause license of
berkeley-db (see relevant commit and README.Impt.License.Change for
details).
Signed-off-by: Damien George <damien@micropython.org>
When an exception is handled and the stream is closed, but while this
happens, another exception occurs or dupterm is deactivated for another
reason, the initial deactivation crashes, because its dupterm is removed.
Co-authored-by: Damien George <damien@micropython.org>
Signed-off-by: Felix Dörre <felix@dogcraft.de>
RemoteProc provides an API to load firmware and control remote processors.
Note: port-specific operations must be implemented to support this class.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This module implements OpenAMP's basic initialization and shared resources
support, and provides support for OpenAMP's RPMsg component, by providing
an `endpoint` type (a logical connection on top of RPMsg channel) which can
be used to communicate with the remote core.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Add a MicroPython platform for libmetal, based on the generic platform.
The MicroPython platform uses common mp_hal_xxx functions and allows ports
to customize default configurations for libmetal.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
OpenAMP framework provides a standard inter processor communications
infrastructure for RTOS and bare metal environments. There are 3 major
components in OpenAMP: libmetal, remoteproc and RPMsg. libmetal provides
abstraction of the low-level underlying hardware, remoteproc is used for
processor Life Cycle Management (LCM) like loading firmware, starting,
stopping a core etc., and RPMsg is a bus infrastructure that enables Inter
Processor Communications (IPC) between different cores.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This new machine-module driver provides a "USBDevice" singleton object and
a shim TinyUSB "runtime" driver that delegates the descriptors and all of
the TinyUSB callbacks to Python functions. This allows writing arbitrary
USB devices in pure Python. It's also possible to have a base built-in
USB device implemented in C (eg CDC, or CDC+MSC) and a Python USB device
added on top of that.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Previously USB was always enabled, but this created some conflicts when
adding guards to other files on other ports.
Note the configuration with USB disabled hasn't been tested and probably
won't build or run without further work.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
`BLE().config(addr_mode=...)` is not safe to call if the NimBLE stack is
not yet active (because it tries to acquire mutexes which should be
initialized first).
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Disabled by default, but enabled on all boards that previously had
`MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled.
Signed-off-by: Damien George <damien@micropython.org>
If no security mode is provided, use WPA for station and WEP for AP. Note
only WEP is supported in AP mode.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Activate the NIC on calls to connect() or config() if it's not already
active. This change makes the NINA NIC more in line with CYW43 and other
NICs, which allow configuring the NIC before or after it is activated.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Added a 4MiB flash partitioning variant for ESP32S3: adds support for 4MiB
discrete flash boards or ESP32-S3FH4R2 with embedded 4MiB flash based ones.
Tested on the waveshare ESP32-S3 Mini w/ESP32-S3FH4R2.
Signed-off-by: Stanislav Ponomarev <me@stasponomarev.com>
If the `timeout_char` parameter is not given, we should still configure the
UART to ensure the UART is always initialized consistently. So the default
of 0 gets applied correctly, or if, for example, the baudrate was changed
the char timeout isn't still based on the old baudrate causing weird
behaviour, etc.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Prior to this commit, the pin defined for power would be used by the
esp_idf driver to reset the PHY. That worked, but sometimes the MDIO
configuration started before the power was fully settled, leading to an
error.
With the change in this commit, the power for the PHY is independently
enabled in network_lan.c with a 100ms delay to allow the power to settle.
A separate define for a reset pin is provided, even if the PHY reset
pin is rarely connected.
Fixes issue #14013.
Signed-off-by: robert-hh <robert@hammelrath.com>
On these targets it's possible to enter the bootloader by setting a bit in
an RTC register before resetting.
Structure it in a way that a board can still provide a custom bootloader
handler. The handler here will be the default if none is provided, for any
board based on the supported targets.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
Currently only the Arduino Nano ESP32 defines a machine.bootloader handler
for ESP32. All other boards will intentionally hang.
There is no error message, nor is a NotImplementedError raised. There's no
indication if Micropython has crashed, or if the bootloader was entered but
USB is not working, which is a real problem the ESP32 bootloader has. It's
not possible escape from this hang with ^C or any other means besides
physical access to the reset pin or the ability to cycle power.
Change this to only define an implementation of machine.bootloader() when
there is a handler for it.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
The new IDF v5.2 deprecated the task cleanup callback we use, so support
for the new option has been implemented in the previous commit. This also
requires a change in the sdkconfig, via a new variable
${SDKCONFIG_IDF_VERSION_SPECIFIC} which is used in all mpconfigboard.cmake
files to include an extra sdkconfig file based on the IDF version in use.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
The legacy I2S "shim" is removed and replaced by the new I2S driver. The
new driver fixes a bug where mono audio plays only in one channel.
Application code size is reduced by 2672 bytes with this change. Tested on
ESP32, ESP32+spiram, ESP32-S3 using example code from
https://github.com/miketeachman/micropython-i2s-examples
Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
Adds Dx and Ax named pins for Arduino Gigi, Arduino Nicla Vision and
Arduino Portenta H7. The analog pins include the dual-pad _C pins.
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
This commit adds support for the dual-analog-pads on STM32H7 parts. These
pads/pins are called PA0_C/PA1_C/PC2_C/PC3_C in the datasheet. They each
have an analog switch that can optionally connect them to their normal pin
(eg PA0). When the switch is open, the normal and _C pin are independent
pins/pads.
The approach taken in this commit to make these _C pins available to Python
is:
- put them in their own, independent row in the stm32h7_af.csv definition
file, with only the ADC column defined (they are separate machine.Pin
entities, and doing it this way keeps make-pins.py pretty clean)
- allow a board to reference these pins in the board's pins.csv file by the
name PA0_C etc (so a board can alias them, for example)
- these pins (when enabled in pins.csv) now become available like any other
machine.Pin through both machine.Pin.board and machine.Pin.cpu
- BUT these _C pins have a separate pin type which doesn't have any
methods, because they don't have any functionality
- these _C pins can be used with machine.ADC to construct the appropriate
ADC object, either by passing the string as machine.ADC("PA0_C") or by
passing the object as machine.ADC(machine.Pin.cpu.PA0_C)
- if a board defines both the normal and _C pin (eg both PA0 and PA0_C) in
pins.csv then it must not define the analog switch to be closed (this is
a sanity check for the build, because it doesn't make sense to close the
switch and have two separate pins)
Signed-off-by: Damien George <damien@micropython.org>
This new DMA API corrects possible cache coherency issues on chips with
D-Cache, when working with buffers at arbitrary memory locations (i.e.
supplied by Python code).
The API is used by SPI to fix an issue with corrupt data when reading from
SPI using DMA in certain cases. A regression test is included (it depends
on external hardware connection).
Explanation:
1) It's necessary to invalidate D-Cache after a DMA RX operation completes
in case the CPU reads (or speculatively reads) from the DMA RX region
during the operation. This seems to have been the root cause of issue
#13471 (only when src==dest for this case).
2) More generally, it is also necessary to temporarily mark the first and
last cache lines of a DMA RX operation as "uncached", in case the DMA
buffer shares this cache line with unrelated data. The CPU could
otherwise write the other data at any time during the DMA operation (for
example from an interrupt handler), creating a dirty cache line that's
inconsistent with the DMA result.
Fixes issue #13471.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The existing MPU_CONFIG_DISABLE macro enables the MPU region but disables
all access to it.
The rename is necessary to support an MPU_CONFIG_DISABLE macro that
actually disables the MPU region entirely.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
With LAN8742, LAN8720, LAN83825 and DP83848 as possible options, and the
symbols PHY_LAN8720, PHY_LAN8742, PHY_DP83825 and PHY_DP8348. The default
is PHY_LAN8742 which is the existing behaviour.
The eth_init() parameters for the Portenta H7 board are set to phy_addr=0
and phy_type=LAN8742, which matches the previous defaults and the
schematics.
Tested with LAN8720 and DP83848 breakout boards at 10M Duplex and 100M
Duplex modes.
Signed-off-by: robert-hh <robert@hammelrath.com>
The default value is 0, which is compatible with the existing behaviour.
Implementing that required changes to eth.c as well. The value of phy_addr
is added to the eth_t data type.
Tested with a STM32F767 and a STM32H750 device.
Signed-off-by: robert-hh <robert@hammelrath.com>
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
It's no longer supported by Emscripten (at least at 3.1.55). And it's not
needed when the output is WASM, which it is by default.
Signed-off-by: Damien George <damien@micropython.org>
This sets the BLE key distribution parameters at runtime. This isn't
needed in most ports since we already set the default values in
`extmod/nimble/syscfg/syscfg.h`; however in the ESP32 port that
headerfile is not used, and the default values in the ESP-IDF don't
enable key distribution nor can we change those defaults via
`sdkconfig`. Thus we're setting these values explicitly at runtime.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This moves the runtime initialisation of `ble_hs_cfg` to happen after
`nimble_port_init()`. That is consistent with the order used in NimBLE
examples. On the ESP32 port this is needed because the ESP-IDF sets up
the default RAM secret store callbacks in its implementation of
`nimble_port_init()` (specifically, it calls `esp_nimble_init()` which
in turn calls `ble_store_ram_init()`). We want to override those with
our own callbacks to implement the `IRQ_[GS]ET_SECRET` events in Python.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This test cannot run on boards that have a native USB REPL, so rename it to
indicate that its "special". This makes it easier to run a subset of
tests, for example:
./run-multitests.py multi_bluetooth/ble*.py
./run-multitests.py multi_bluetooth/perf*.py
./run-multitests.py multi_bluetooth/stress*.py
Signed-off-by: Damien George <damien@micropython.org>
Because `mpthreadport.h` is included by `mpthread.h`.
Also remove unnecessary include of `mpthreadport.h` in esp32's `main.c`.
Signed-off-by: Damien George <damien@micropython.org>
This call used to be needed when there was an `emit_bc_pre()` function that
needed to be called at the start of each emitted bytecode. But in
8e7745eb31 that function was removed and now
the call to `mp_emit_bc_adjust_stack_size()` does nothing when adjusting by
0 entries, so it can be removed.
Signed-off-by: Damien George <damien@micropython.org>
For boards with MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES and up.
This gets samd21 boards working (which need the vfs module in _boot.py),
B_L072Z_LRWAN1, and nrf boards with smaller MCUs that use CORE or BASIC
feature levels.
Signed-off-by: robert-hh <robert@hammelrath.com>
Prior to commit 628abf8f25 which added IPv6
support, binding a socket with
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", PORT))
was possible. But, the empty string is not regarded as a valid IP address
by lwip. This commit adds a special case for the empty IP string,
restoring the previous CPython-compatible behaviour.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
When the websocket closes currently, it does not send a proper
"close"-frame, but rather encodes the 0x8800-sequence inside a binary
packet, which is wrong. The close packet is a different kind of websocket
frame, according to https://www.rfc-editor.org/rfc/rfc6455.
This change resolves an error in Firefox when the websocket closes.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
The patch enables SDRAM banks 1 and 2 to be accessible at 0xC0000000 and
0xD0000000 respectively (default mapping) or remapped to addresses
0x60000000 and 0x70000000.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Allows giving more specific advice, provides more links to other places to
ask questions, check details, etc.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
So this header file can expose declarations for contents of the `machine`
module even if that module is disabled. Other parts of the system -- or
third-party code -- may need these declarations, for example when a single
component like MICROPY_PY_MACHINE_UART is enabled with MICROPY_PY_MACHINE
disabled.
Signed-off-by: Damien George <damien@micropython.org>
With this commit, if file open fails, the object will have fd = -1 (closed)
and the finaliser will not attempt to close anything.
Fixes issue #13672.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This combines the argument parsing and checking for the machine.SPI.init()
and machine.SPI() interfaces.
The only real difference was unspecified arguments in init() mean to keep
the same value, while in new they get default values.
Behavior has changed for passing the "id" argument to init(). On other
ports this isn't allowed. But on esp32 it would change the SPI controller
of the static SPI instance to the new id. This results in multiple static
spi objects for the same controller and they would fight over which one has
inconsistent mpy vs esp-idf state. This has been changed to not allow "id"
with init(), like other ports.
In a few causes, a loop is used over arguments that are handled the same
way instead of cut & pasting the same stanza of code for each argument.
The init_internal function had a lot of arguments, which is not efficient
to pass. Pass the args mp_arg_val_t array instead as a single argument.
This reduced both the number of C lines and the compiled code size.
Summary of code size change: Two argument lists of 72 bytes are replaced
by a single shared 72 byte list. New shared argument parsing code is small
enough to be inlined, but is still efficient enough to shrink the overall
code size by 349 bytes of the three argument handlering functions.
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-349 (-349)
Function old new delta
machine_hw_spi_make_new 255 203 -52
machine_hw_spi_init 122 67 -55
machine_hw_spi_init_internal 698 456 -242
Total: Before=1227667, After=1227318, chg -0.03%
add/remove: 2/0 grow/shrink: 0/2 up/down: 92/-144 (-52)
Data old new delta
spi_allowed_args - 72 +72
defaults$0 - 20 +20
allowed_args$1 240 168 -72
allowed_args$0 1080 1008 -72
Total: Before=165430, After=165378, chg -0.03%
add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
The size of the flash varies among MCU variants. Instead of requiring a
build-time variable to configure this, compute it at runtime using the
special device information word accessible through the FLASH_SIZE macro.
This feature is currently only implemented for H5 MCUs, but can be extended
to others.
Signed-off-by: Damien George <damien@micropython.org>
This is now easy to support, since the first machine-word of a native
function tells how to find the prelude, from which the function name can be
extracted in the same way as for bytecode.
Signed-off-by: Damien George <damien@micropython.org>
Now native functions and native generators have similar behaviour: the
first machine-word of their code is an index to get to the prelude. This
simplifies the handling of these types of functions, and also reduces the
size of the emitted native machine code by no longer requiring special code
at the start of the function to load a pointer to the prelude.
Signed-off-by: Damien George <damien@micropython.org>
Viper functions are quite different to native functions and benefit from
being a separate type. For example, viper functions don't have a bytecode-
style prelude, and don't support generators or default arguments.
Signed-off-by: Damien George <damien@micropython.org>
They are no longer used. The new `mp_obj_malloc_with_finaliser()` macros
should be used instead, which force the setting of the `base.type` field.
And there's always `m_malloc_with_finaliser()` if needed.
Signed-off-by: Damien George <damien@micropython.org>
Following 709e8328d9.
Using this helps to reduce code size. And it ensure that the type is
always set as soon as the object is allocated, which is important for the
GC to function correctly.
Signed-off-by: Damien George <damien@micropython.org>
MICROPY_GIT_HASH was removed in 69e34b6b6b
but it is useful for, and used by, third-party code to tell which hash of
MicroPython is used.
Signed-off-by: Damien George <damien@micropython.org>
Follow up to 35dd959133, allows explicitly
adding the unix-ffi library path from the command line.
This option is needed when building unix-ffi manifests in micropython-lib
CI.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Allows bytecode itself to be used instead of an mp_raw_code_t in the simple
and common cases of a bytecode function without any children.
This can be used to further reduce frozen code size, and has the potential
to optimise other areas like importing.
Signed-off-by: Damien George <damien@micropython.org>
To simplify their access and reduce code size.
The `scope_flags` member is only ever used to determine if a function is a
generator or not, so make it reflect that fact as a bool type.
Signed-off-by: Damien George <damien@micropython.org>
The `asm_n_pos_args` and `asm_type_sig` members of `mp_raw_code_t` are only
used for raw codes of type MP_CODE_NATIVE_ASM, which are rare, for example
in frozen code. So using a truncated `mp_raw_code_t` in these cases helps
to reduce frozen code size on targets that have MICROPY_EMIT_INLINE_ASM
enabled.
With this, change in firmware size of RPI_PICO builds is -648.
Signed-off-by: Damien George <damien@micropython.org>
The mp_raw_code_t struct has been reordered and some members resized. The
`n_pos_args` member is renamed to `asm_n_pos_args`, and `type_sig` renamed
to `asm_type_sig` to indicate that these are used only for the inline-asm
emitters. These two members are also grouped together in the struct.
The justifications for resizing the members are:
- `fun_data_len` can be 32-bits without issue
- `n_children` is already limited to 16-bits by
`mp_emit_common_t::ct_cur_child`
- `scope_flags` is already limited to 16-bits by `scope_t::scope_flags`
- `prelude_offset` is already limited to 16-bits by the argument to
`mp_emit_glue_assign_native()`
- it's reasonable to limit the maximim number of inline-asm arguments to 12
(24 bits for `asm_type_sig` divided by 2)
This change helps to reduce frozen code size (and in some cases RAM usage)
in the following cases:
- 64-bit targets
- builds with MICROPY_PY_SYS_SETTRACE enabled
- builds with MICROPY_EMIT_MACHINE_CODE enabled but MICROPY_EMIT_INLINE_ASM
disabled
With this change, unix 64-bit builds are -4080 bytes in size. Bare-metal
ports like rp2 are unchanged (because mp_raw_code_t is still 32 bytes on
those 32-bit targets).
Signed-off-by: Damien George <damien@micropython.org>
With these changes IPv6 works on the rp2 port (and possibly others that use
the lwIP socket implementation).
Things that have been tested and work:
- Neighbour solicitation for v6 link local address.
- Ping of v6 link-local address.
- Receiving a SLAAC address via router advertisement.
- Ping a v6 address allocated via SLAAC.
- Perform an outgoing connection to a routed v6-address (via default
gateway).
- Create a listening IPv6 wildcard socked bound to ::, and trying to access
it via link-local, SLAAC, and IPv4 (to ensure the dual-stack binding
works).
Things that could be improved:
- socket.socket().getaddrinfo only returns the v4 address. It could also
return v6 addresses (getaddrinfo is actively programmed to only return a
single address, and this is the v4-address by default, with fallback to
the v6 address if both are enabled).
Signed-off-by: Felix Dörre <felix@dogcraft.de>
The Python BLE IRQ handler will most likely run on the NimBLE task, so its
C stack must be large enough to accommodate reasonably complicated Python
code (eg a few call depths). So increase this stack size.
Also increase the headroom from 1024 to 2048 bytes. This is needed because
(1) the esp32 architecture uses a fair amount of stack in general; and (2)
by the time execution gets to setting the Python stack top via
`mp_stack_set_top()` in this interlock code, about 600 bytes of stack are
already used, which reduces the amount available for Python.
Fixes issue #12349.
Signed-off-by: Damien George <damien@micropython.org>
In case callbacks must run (eg a disconnect event happens during the
deinit) and the GIL must be obtained to run the callback.
Fixes part of issue #12349.
Signed-off-by: Damien George <damien@micropython.org>
PPP is not that commonly used, let it be turned off in the board config to
save space. It is still on by default.
On an basic ESP32-S3 build, turning off PPP with LWIP still on saves ~35 kB
of codend 4 kB of data.
text data bss dec hex filename
1321257 304296 2941433 4566986 45afca before-ppp-off.elf
1285101 299920 2810305 4395326 43113e after-ppp-off.elf
-------------------------------
-36156 -4376 -56
Note that the BSS segment size includes all NOBITS sections in ELF file.
Some of these are aligned to 64kB chunk sized dummy blocks, I think for
alignment to MMU boundaries, and these went down by 1 block each, so 128
kiB of BSS is not really part of the binary size reduction.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
For mimxrt, nrf, renesas-ra, rp2 and samd ports, this commit implements
similar behaviour to the stm32 port, where USB is only brought up after
boot.py completes execution.
Currently this doesn't add any useful functionality (and may break
workflows that depend on USB-CDC being live in boot.py), however it's a
precondition for more usable workflows with USB devices defined in
Python (allows setting up USB interfaces in boot.py before the device
enumerates for the first time).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The C99 standard states:
6.8.6.4 The return statement Constraints
A return statement with an expression shall not appear in a function
whose return type is void. A return statement without an expression
shall only appear in a function whose return type is void.
And when `-pedantic` is enabled the compiler gives an error.
Signed-off-by: Yoctopuce <dev@yoctopuce.com>
Obtaining the stack-top via a few function calls may yield a pointer which
is too deep within the stack. So require the user to obtain it from a
higher level (or via some other means).
Fixes issue #11781.
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
It's rare to freeze .mpy files without specifying a qstr header from a
firmware build, but it can be useful for testing, eg
`mpy-tool.py -f test.mpy`. Fix this case so static qstrs are properly
excluded from the frozen qstr list.
Signed-off-by: Damien George <damien@micropython.org>
Similar to the previous commit but for MP_BLUETOOTH_IRQ_GATTC_READ_DONE:
the pending_value_handle needs to be reset before calling
mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ
handler, which may in turn call back into BTstack to perform an action like
a write. In that case the pending_value_handle will need to be available
for the write/read/etc to proceed.
Fixes issue #13634.
Signed-off-by: Damien George <damien@micropython.org>
The pending_value_handle needs to be freed and reset before calling
mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ
handler, which may in turn call back into BTstack to perform an action like
a write. In that case the pending_value_handle will need to be available
for the write/read/etc to proceed.
Fixes issue #13611.
Signed-off-by: Damien George <damien@micropython.org>
This commit changes how library packages are searched for when a manifest
file is loaded: there is now simply a list of library paths that is
searched in order for the given package. This list defaults to the
main directories in micropython-lib, but can be added to -- either appended
or prepended -- by using `add_library()`.
In particular the way unix-ffi library packages are searched has changed,
because the `unix_ffi` argument to `require()` is now removed. Instead, if
a build wants to include packages from micropython-lib/unix-ffi, then it
must explicitly add this to the list of paths to search using:
add_library("unix-ffi", "$(MPY_LIB_DIR)/unix-ffi")
Work done in collaboration with Jim Mussared.
Signed-off-by: Damien George <damien@micropython.org>
All the other workflow YAML files use vertical whitespace around top-level
items.
Also remove spurious comment, the features in the linked doc aren't
actually used in this workflow (any more?).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Similar to ruff.yaml, it's simpler to run the codespell command directly
from a workflow file. And developers can run codespell directly from the
command line without the need for options, or just use pre-commit.
This commit also applies a specific version to codespell, same as
pre-commit (introduced in a166d805f4).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The current `ssl` module has quite a few differences to the CPython
implementation. This change moves the MicroPython variant to a new `tls`
module and provides a wrapper module for `ssl` (in micropython-lib).
Users who only rely on implemented comparible behavior can continue to use
`ssl`, while users that rely on non-compatible behavior should switch to
`tls`. Then we can make the facade in `ssl` more strictly adhere to
CPython.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
By moving to GitHub actions, all MicroPython CI builds are now on GitHub
actions. This allows faster parallel builds and saves time by not building
when no relevant files changed.
This reveals a few failing tests, so those are temporarily disabled until
they can be fixed.
Signed-off-by: David Lechner <david@pybricks.com>
Signed-off-by: Damien George <damien@micropython.org>
When compiler optimizations are enabled on the mingw version of gcc, we are
getting failing tests because of rounding issues, for example:
print(float("1e24"))
would print
9.999999999999999e+23
instead of
1e+24
It turns out special compiler options are needed to get GCC to use the SSE
instruction set instead of the 387 coprocessor (which uses 80-bit precision
internall).
Signed-off-by: David Lechner <david@pybricks.com>
Currently, only the processor's SPI2 bus is enabled (though the related
pins are labeled SPI1 in the Portenta H7 documentation). This commit
enables the processor's SPI1 bus, which is accessible via the board's
high-density connectors.
Signed-off-by: Jim Lipsey <github@lipsey.org>
This makes no difference when files are linked directly into a target
application, but on macOS additional steps are needed to index common
symbols in static libraries. See https://stackoverflow.com/a/26581710
By not creating any common symbols, this problem is bypassed.
This will also trigger linker errors if there are cases where the same
symbol is defined in the host application.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
If a return is executed within the try block of a try-finally then the
return value is stored on the top of the Python stack during the execution
of the finally block. In this case the Python stack is one larger than it
normally would be in the finally block.
Prior to this commit, the compiler was not taking this case into account
and could have a Python stack overflow if the Python stack used by the
finally block was more than that used elsewhere in the function. In such
a scenario the last argument of the function would be clobbered by the
top-most temporary value used in the deepest Python expression/statement.
This commit fixes that case by making sure enough Python stack is allocated
to the function.
Fixes issue #13562.
Signed-off-by: Damien George <damien@micropython.org>
The timing of the DMA transfer can vary a bit, so tweak the allowed values.
Also test the return value of `rp2.DMA.irq.flags()` to make sure the IRQ is
correctly signalled.
Signed-off-by: Damien George <damien@micropython.org>
stat_path is only called with stringified vstr_t objects.
Thus, pulling the stringification into the function replaces three
function calls with one, saving a few bytes.
Signed-off-by: Matthias Urlichs <matthias@urlichs.de>
Changes include:
- Some mbedtls source files renamed or deprecated.
- Our `mbedtls_config.h` files are renamed to `mbedtls_config_port.h`, so
they don't clash with mbedtls's new default configuration file named
`mbedtls_config.h`.
- MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE is deprecated.
- MBEDTLS_HAVE_TIME now requires an `mbedtls_ms_time` function to be
defined but it's only used for TLSv1.3 (currently not enabled in
MicroPython so there is a lazy implementation, i.e. seconds * 1000).
- `tests/multi_net/ssl_data.py` is removed (due to deprecation of
MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE), there are the existing
`ssl_cert_rsa.py` and `sslcontext_server_client.py` tests which do very
similar, simple SSL data transfer.
- Tests now use an EC key by default (they are smaller and faster), and the
RSA key has been regenerated due to the old PKCS encoding used by openssl
rsa command, see
https://stackoverflow.com/questions/40822328/openssl-rsa-key-pem-and-der-conversion-does-not-match
(and `tests/README.md` has been updated accordingly).
Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
Running `./do-mp.sh` now generates this `mp_mbedtls_errors.c` file. The
`esp32_mbedtls_errors.c` file is already up-to-date.
Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
Prior to this commit it would skip every second cipher returned from
mbedtls.
The corresponding test is also updated and now passes on esp32, rp2, stm32
and unix.
Signed-off-by: Damien George <damien@micropython.org>
This simplifes the port configuration. It enables quite a few new
features, including the `math` and `cmath` modules, adding about 20k to the
firmware size.
Signed-off-by: Damien George <damien@micropython.org>
This is not enabled on any other MCU port, and is essentially unused on
esp8266 because mp_verbose_flag is always 0. Disabling saves ~7k of flash.
Signed-off-by: Damien George <damien@micropython.org>
The standard Arduino pinout uses LEDR/G/B and LED_BUILTIN (if available).
This patch adds aliases to match the standard pinout, while retaining
LED_RED/GREEN/BLUE for compatibility with existing scripts and examples.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This will apply to bare-arm and minimal, as well as the minimal unix
variant.
Change the default to MICROPY_QSTR_BYTES_IN_HASH=1 for the CORE,BASIC
levels, 2 for >=EXTRA.
Removes explicit setting of MICROPY_QSTR_BYTES_IN_HASH==1 in ports that
don't set the feature level (because 1 is implied by the default level,
CORE). Applies to cc3200, pic16bt, powerpc.
Removes explicit setting for nRF (which sets feature level). Also for samd,
which sets CORE for d21 and FULL for d51. This means that d21 is unchanged
with MICROPY_QSTR_BYTES_IN_HASH==1, but d51 now moves from 1 to 2 (roughly
adds 1kiB).
The only remaining port which explicitly set bytes-in-hash is rp2 because
it's high-flash (hence CORE level) but lowish-SRAM, so it's worthwhile
saving the RAM for runtime qstrs.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Sets MICROPY_QSTR_BYTES_IN_HASH==0 on stm32x0 boards.
This saves e.g. 2kiB on NUCLEO_F091.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This disables using qstr hashes altogether, which saves RAM and flash
(two bytes per interned string on a typical build) as well as code size.
On PYBV11 this is worth over 3k flash.
qstr comparison will now be done just by length then data. This affects
qstr_find_strn although this has a negligible performance impact as, for a
given comparison, the length and first character will ~usually be
different anyway.
String hashing (e.g. builtin `hash()` and map.c) now need to compute the
hash dynamically, and for the map case this does come at a performance
cost.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Required modifying the gen-cpydiff.py code to allow a "preamble" section to
be inserted at the top of any of the generated files.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This reverts the change from ce2058685b.
Without abspath, the build artefacts (object files) for boards with source
files are placed outside the build directory, because the BOARD_DIR
variable starts with "..". For the list of source files added to SRC_C,
none of them can start with "..". The usual fix for that would be to make
the files relative to the top of the MicroPython repo (because of the vpath
rule), eg ports/stm32/boards/$(BOARD). But then the $(wildcard ...)
pattern won't find files in this directory.
So abspath is necessary, although it will prevent building when there is a
space in the path. A better solution for spaces needs to be found.
Signed-off-by: Damien George <damien@micropython.org>
These were added back in commit c4935f3049
because the tests required CPython 3.8, which was quite new at the time.
But CPython 3.8 was released over 4 years ago (October 2019) and the CI
test runners, and developers, have this (or a more recent) CPython version.
Removing the .exp files also helps keep MicroPython semantics the same as
CPython.
The asyncio_fair.py test it adjusted slightly to have more deterministic
timing and output.
Signed-off-by: Damien George <damien@micropython.org>
Make can't handle paths with spaces, see https://savannah.gnu.org/bugs/?712
The following workarounds exist:
- When using make's built-in functions:
- Use relative paths wherever possible to avoid spaces in the first
place.
- All spaces in paths can be escaped with backslashes; quotes don't
work.
- Some users use the shell to temporarily rename directories, or to
create symlinks without spaces.
- When using make to pass commands to the system's shell, enclose paths in
quotes. While make will still interpret quoted strings with spaces as
multiple words, the system's shell will correctly parse the resulting
command.
This commit contains the following fixes:
- In ports/stm32/mboot/Makefile: Use relative paths to avoid spaces when
using built-in functions.
- In all other files: Use quotes to enclose paths when make is used to call
shell functions.
All changes have been tested with a directory containing spaces.
Signed-off-by: Iksas <iksas@mailbox.org>
The irq service routine cleared the RT interrupt bit on TX interrupt. This
opens the possibility that an RT interrupt is missed.
Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
The `_start` function prototype is now declared as no-return, so `main()`
can't return.
To fix this, `main()` is replaced with `_start`.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
In CMSIS 5.9.0, the compiler headers define `__VECTOR_TABLE`, which will be
substituted with its corresponding value (e.g., `__Vectors` for gcc).
However, the linker script in this port can't include compiler headers when
it's processed, so `__VECTOR_TABLE` is used as the literal variable name,
which results in an undefined linker error.
To fix this, the two possible values of `__VECTOR_TABLE` are both defined
in the linker script.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Adds support to asyncio.gather() for the case that one or more (or all)
sub-tasks finish and/or raise an exception before the gather starts.
Signed-off-by: Damien George <damien@micropython.org>
Switch the RTC clock source to Sub-clock (XCIN). This board has an
accurate LSE crystal, and it should be used for the RTC clock
source.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
No longer require importlib_metadata on new Python versions as it is
included in the standard distribution.
Signed-off-by: Jochen Sprickerhof <git@jochen.sprickerhof.de>
- Completes a longstanding TODO in the code, to not ignore
the optional family, type, proto and flags arguments to
socket.getaddrinfo().
- Note that passing family=socket.AF_INET6 will now cause queries
to fail (OSError -202). Previously this argument was ignored so
IPV4 results were returned instead.
- Optional 'type' argument is now always copied into the result. If not
set, results have type SOCK_STREAM.
- Fixes inconsistency where previously querying mDNS local suffix (.local)
hostnames returned results with socket type 0 (invalid), but all other
queries returned results with socket type SOCK_STREAM (regardless of
'type' argument).
- Optional proto argument is now returned in the result tuple, if supplied.
- Optional flags argument is now passed through to lwIP. lwIP has handling
for AI_NUMERICHOST, AI_V4MAPPED, AI_PASSIVE (untested, constants for
these are not currently exposed in the esp32 socket module).
- Also fixes a possible memory leak in an obscure code path
(lwip_getaddrinfo apparently sometimes returns a result structure with
address "0.0.0.0" instead of failing, and this structure would have been
leaked.)
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This was originally needed because the .c --> .o rule is:
$(BUILD)/%.o: %.c
and because the generated frozen_content.c is inside build-FOO, it must
therefore generate build-FOO/build-FOO/frozen_content.o.
But 2eda513870 added a new build rule for
pins.c that can also be used for frozen_content.c.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
CPython says thread identifier is a "nonzero integer", so rp2 should use a
1-indexed core number rather than 0-indexed. This fixes the
thread/thread_ident1 test failure on rp2 port.
Unfortunately this may be a breaking change for rp2 code which makes a
hard-coded comparison of thread identifier to 0 or 1.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
If there are any free chunks found then it's better to sweep the filesystem
and use the available chunks, rather than error out with ENOSPC when there
is in fact a bit of space remaining.
Signed-off-by: Damien George <damien@micropython.org>
Compare the full absolute path instead of relying on the path form
passed by the user.
For instance, this will make
python3 run-tests.py -d basics
python3 run-tests.py -d ./basics
python3 run-tests.py -d ../tests/basics
python3 run-tests.py -d /full/path/to/basics
all behave the same by correctly treating the bytes_compare3 and
builtin_help tests as special, whereas previously only the first
invocation would do that and hence result in these tests to fail
when called with a different path form.
Signed-off-by: stijn <stijn@ignitron.net>
Increases firmware size by +140 bytes and uses +4 extra bytes of RAM, but
allows the test suite to run without crashing.
Signed-off-by: Damien George <damien@micropython.org>
Flash sectors should start counting at 0 for each bank. This commit makes
sure that is the case on all H5 and H7 MCUs, by using `get_page()` instead
of `flash_get_sector_info()`.
Signed-off-by: Damien George <damien@micropython.org>
This commit removes the need for a separate `flash_cache_sector_id`
variable, instead using `flash_cache_sector_start` to indicate which sector
is curretly cached (and -1 indicates no sector).
Signed-off-by: Damien George <damien@micropython.org>
An erase sector sits in a given flash bank and some MCUs have two flash
banks. If trying to erase a range of sectors and that range crosses from
one flash bank into the next, the original implementation of
`flash_erase()` would not handle this case and would do the wrong thing.
This commit changes `flash_erase()` to only erase a single sector, which
sidesteps the need to handle flash-bank-crossing. Most callers of this
function only need to erase a single sector anyway.
Signed-off-by: Damien George <damien@micropython.org>
Newer STM32 parts have homogeneous flash layout, and in this case the MCU
configuration and page/sector calculation can be simplified. The affected
functions are `flash_is_valid_addr()` and `flash_get_sector_info()`, which
are now simpler for homogeneous flash.
Signed-off-by: Damien George <damien@micropython.org>
This commit replaces the linker symbol `_mboot_writable_flash_start` with
`_mboot_protected_flash_start` and `_mboot_protected_flash_end_exclusive`,
to provide better configuration of the protected flash area.
Signed-off-by: Damien George <damien@micropython.org>
Following ad806df857 where the
MICROPY_PY_PENDSV_ENTER/REENTER/EXIT macro definitions were moved to
mphalport.h.
Signed-off-by: Damien George <damien@micropython.org>
Codespell doesn't pick up "re-used" or "re-uses", and ignores the tests/
directory, so fix these manually.
Signed-off-by: Damien George <damien@micropython.org>
Implement the typical 're-run the failed tests' most test runners have, for
convenience. Accessible via the new --run-failures argument, and
implemented using a json file containing a list of the failed tests.
Signed-off-by: stijn <stijn@ignitron.net>
Otherwise running the tests can take a long time when the server is a slow
target (RP2040 takes 23 seconds for a handshake when using 4096-bit RSA).
Also add instructions on how to generate elliptic curve key/certs.
Signed-off-by: Damien George <damien@micropython.org>
This matches the behaviour of run-tests.py, which sets cwd to the directory
containing the test script, which helps to isolate the filesystem.
It means that the SSL tests no longer need to know the name of their
containing directory to find the certificate files, and helps to run these
tests on bare-metal.
Signed-off-by: Damien George <damien@micropython.org>
The existing thread_sleep1.py test only tests execution, not accuracy, of
time.sleep. Also the existing test only tests sleep(0) on targets like rp2
that can only create a single thread.
The new test in this commit checks for timing accuracy on the main thread
and one other thread when they run at the same time.
Signed-off-by: Damien George <damien@micropython.org>
The aim of this commit is to make it so that the existing thread tests can
be used to test the _thread module on the rp2 port. The rp2 port only
allows up to one thread to be created at a time, and does not have the GIL
enabled.
The following changes have been made:
- run-tests.py skips mutation tests on rp2, because there's no GIL.
- run-tests.py skips other tests on rp2 that require more than one thread.
- The tests stop trying to start a new thread after there is an OSError,
which indicates that the system cannot create more threads.
- Some of these tests also now run the test function on the main thread,
not just the spawned threads.
- In some tests the output printing is adjusted so it's the same regardless
of how many threads were spawned.
- Some time.sleep(1) are replaced with time.sleep(0) to make the tests run
a little faster (finish sooner when the work is done).
For the most part the tests are unchanged for existing platforms like esp32
and unix.
Signed-off-by: Damien George <damien@micropython.org>
Prior to this commit there is a potential deadlock in
mp_thread_begin_atomic_section(), when obtaining the atomic_mutex, in the
following situation:
- main thread calls mp_thread_begin_atomic_section() (for whatever reason,
doesn't matter)
- the second core is running so the main thread grabs the mutex via the
call mp_thread_mutex_lock(&atomic_mutex, 1), and this succeeds
- before the main thread has a chance to run save_and_disable_interrupts()
a USB IRQ comes in and the main thread jumps off to process this IRQ
- that USB processing triggers a call to the dcd_event_handler() wrapper
from commit bcbdee2357
- that then calls mp_sched_schedule_node()
- that then attempts to obtain the atomic section, calling
mp_thread_begin_atomic_section()
- that call then blocks trying to obtain atomic_mutex
- core0 is now deadlocked on itself, because the main thread has the mutex
but the IRQ handler (which preempted the main thread) is blocked waiting
for the mutex, which will never be free
The solution in this commit is to use mutex enter/exit functions that also
atomically disable/restore interrupts.
Fixes issues #12980 and #13288.
Signed-off-by: Damien George <damien@micropython.org>
Using the multicore lockout feature in the general atomic section makes it
much more difficult to get correct.
Signed-off-by: Damien George <damien@micropython.org>
This commit enables additional features for SAMD21 with external flash:
- Viper and native code support. On a relatively slow devices, viper and
native code can be helpful.
- Freeze the asyncio scripts and add the select module.
- Enable Framebuffer support.
- Enable UART flow control.
- Enable a few more features from the extra features set.
Drop onewire and asyncio support from SAMD21 firmware without external
flash, leaving a little bit more room for future extensions. Asyncio was
anyhow incomplete.
Signed-off-by: robert-hh <robert@hammelrath.com>
RTC is enabled on all boards. Therefore the conditional compile is not
needed. Removing it simplifies the source code a little bit.
Signed-off-by: robert-hh <robert@hammelrath.com>
Fixes a wrong assignment for Sparkfun SAMD51 Thing Plus, and updates the
sample script for printing the pin info table.
Signed-off-by: robert-hh <robert@hammelrath.com>
* Please search existing issues before raising a new issue. For questions about MicroPython or for help using MicroPython, or any sort of "how do I?" requests, please use the Discussions tab or raise a documentation request instead.
* In your issue, please include a clear and concise description of what the bug is, the expected output, and how to replicate it.
* If this issue involves external hardware, please include links to relevant datasheets and schematics.
* If you are seeing code being executed incorrectly, please provide a minimal example and expected output (e.g. comparison to CPython).
* For build issues, please include full details of your environment, compiler versions, command lines, and build output.
* Please provide as much information as possible about the version of MicroPython you're running, such as:
- firmware file name
- git commit hash and port/board
- version information shown in the REPL (hit Ctrl-B to see the startup message)
* Remove all placeholder text above before submitting.
Please provide as much detail as you can, it really helps us find and fix bugs faster.
#### Not a bug report?
* If you have a question \"How Do I ...?\", please post it on [GitHub Discussions](https://github.com/orgs/micropython/discussions/) or [Discord](https://discord.gg/RB8HZSAExQ) instead of here.
* For missing or incorrect documentation, or feature requests, then please [choose a different issue type](https://github.com/micropython/micropython/issues/new/choose).
#### Existing issue?
* Please search for [existing issues](https://github.com/micropython/micropython/issues) matching this bug before reporting.
- type:input
id:port-board-hw
attributes:
label:Port, board and/or hardware
description:|
Which MicroPython port(s) and board(s) are you using?
placeholder:|
esp32 port, ESP32-Fantastic board.
validations:
required:true
- type:textarea
id:version
attributes:
label:MicroPython version
description:|
To find the version:
1. Open a serial REPL.
2. Type Ctrl-B to see the startup message.
3. Copy-paste that output here.
If the issue is about building MicroPython, please provide output of `git describe --dirty` and as much information as possible about the build environment.
If the version or configuration is modified from the official MicroPython releases or the master branch, please tell us the details of this as well.
placeholder:|
MicroPython v6.28.3 on 2029-01-23; PyBoard 9 with STM32F9
validations:
required:true
- type:textarea
id:steps-reproduce
attributes:
label:Reproduction
description:|
What steps will reproduce the problem? Please include all details that could be relevant about the environment, configuration, etc.
If there is Python code to reproduce this issue then please either:
a. Type it into a code block below ([code block guide](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks)), or
b. Post longer code to a [GitHub gist](https://gist.github.com/), or
c. Create a sample project on GitHub.
For build issues, please provide the exact build commands that you ran.
placeholder:|
1. Copy paste the code provided below into a new file
2. Use `mpremote run` to execute it on the board.
validations:
required:true
- type:textarea
id:expected
attributes:
label:Expected behaviour
description:|
What did you expect MicroPython to do? If comparing output with CPython or a different MicroPython port/version then please provide that output here.
placeholder:|
Expected to print "Hello World".
Here is the correct output, seen with previous MicroPython version v3.14.159:
> [...]
- type:textarea
id:what-happened
attributes:
label:Observed behaviour
description:|
What actually happened? Where possible please paste exact output, or the complete build log, etc. Very long output can be linked in a [GitHub gist](https://gist.github.com/).
placeholder:|
This unexpected exception appears:
> [...]
validations:
required:true
- type:textarea
id:additional
attributes:
label:Additional Information
description:|
Is there anything else that might help to resolve this issue?
value:No,I've provided everything above.
- type:dropdown
id:code-of-conduct
attributes:
label:Code of Conduct
description:|
Do you agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone?
options:
- "Yes, I agree"
multiple:true
validations:
required:true
- type:markdown
attributes:
value:|
Thanks for taking the time to help improve MicroPython.
about: Report areas of the documentation or examples that need improvement
title: 'docs: '
labels: documentation
assignees: ''
---
* Please search existing issues before raising a new issue. For questions about MicroPython or for help using MicroPython, or any sort of "how do I?" requests, please use the Discussions tab instead.
* Describe what was missing from the documentation and/or what was incorrect/incomplete.
* If possible, please link to the relevant page on https://docs.micropython.org/
* Remove all placeholder text above before submitting.
description:Report areas of the documentation or examples that need improvement
title:"docs: "
labels:["documentation"]
body:
- type:markdown
attributes:
value:|
This form is for reporting issues with the documentation or examples provided with MicroPython.
If you have a general question \"How Do I ...?\", please post it on [GitHub Discussions](https://github.com/orgs/micropython/discussions/) or [Discord](https://discord.gg/RB8HZSAExQ) instead of here.
#### Existing issue?
* Please search for [existing issues](https://github.com/micropython/micropython/issues) before reporting a new one.
- type:input
id:page
attributes:
label:Documentation URL
description:|
Does this issue relate to a particular page in the [online documentation](https://docs.micropython.org/en/latest/)? If yes, please paste the URL of the page:
placeholder:|
https://docs.micropython.org/en/latest/
- type:textarea
id:version
attributes:
label:Description
description:|
Please describe what was missing from the documentation and/or what was incorrect/incomplete.
validations:
required:true
- type:dropdown
id:code-of-conduct
attributes:
label:Code of Conduct
description:|
Do you agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone?
options:
- "Yes, I agree"
multiple:true
validations:
required:true
- type:markdown
attributes:
value:|
Thanks for taking the time to help improve MicroPython.
* Please search existing issues before raising a new issue. For questions about MicroPython or for help using MicroPython, or any sort of "how do I?" requests, please use the Discussions tab or raise a documentation request instead.
* Describe the feature you'd like to see added to MicroPython. In particular, what does this feature enable and why is it useful. MicroPython aims to strike a balance between functionality and code size, so please consider whether this feature can be optionally enabled and whether it can be provided in other ways (e.g. pure-Python library).
* For core Python features, where possible please include a link to the relevant PEP.
* For new architectures / ports / boards, please provide links to relevant documentation, specifications, and toolchains. Any information about the popularity and unique features about this hardware would also be useful.
* For features for existing ports (e.g. new peripherals or microcontroller features), please describe which port(s) it applies too, and whether this is could be an extension to the machine API or a port-specific module?
* For drivers (e.g. for external hardware), please link to datasheets and/or existing drivers from other sources.
* Who do you expect will implement the feature you are requesting? Would you be willing to sponsor this work?
* Remove all placeholder text above before submitting.
This form is for requesting features or improvements in MicroPython.
#### Get feedback first
Before submitting a new feature idea here, suggest starting a discussion on [Discord](https://discord.gg/RB8HZSAExQ) or [GitHub Discussions](https://github.com/orgs/micropython/discussions/) to get early feedback from the community and maintainers.
#### Not a MicroPython core feature?
* If you have a question \"How Do I ...?\", please post it on GitHub Discussions or Discord instead of here.
* Could this feature be implemented as a pure Python library? If so, please open the request on the [micropython-lib repository](https://github.com/micropython/micropython-lib/issues) instead.
#### Existing issue?
* Please search for [existing issues](https://github.com/micropython/micropython/issues) before opening a new one.
- type:textarea
id:feature
attributes:
label:Description
description:|
Describe the feature you'd like to see added to MicroPython. What does this feature enable and why is it useful?
* For core Python features, where possible please include a link to the relevant PEP or CPython documentation.
* For new architectures / ports / boards, please provide links to relevant documentation, specifications, and toolchains. Any information about the popularity and unique features about this hardware would also be useful.
* For features for existing ports (e.g. new peripherals or microcontroller features), please describe which port(s) it applies to, and whether this is could be an extension to the machine API or a port-specific module?
* For drivers (e.g. for external hardware), please link to datasheets and/or existing drivers from other sources.
If there is an existing discussion somewhere about this feature, please add a link to it as well.
validations:
required:true
- type:textarea
id:size
attributes:
label:Code Size
description:|
MicroPython aims to strike a balance between functionality and code size. Can this feature be optionally enabled?
If you believe the usefulness of this feature would outweigh the additional code size, please explain. (It's OK to say you're unsure here, we're happy to discuss this with you.)
- type:dropdown
id:implementation
attributes:
label:Implementation
description:|
What is your suggestion for implementing this feature?
(See also: [How to sponsor](https://github.com/sponsors/micropython#sponsors), [How to submit a Pull Request](https://github.com/micropython/micropython/wiki/ContributorGuidelines).)
options:
- I hope the MicroPython maintainers or community will implement this feature
- I intend to implement this feature and would submit a Pull Request if desirable
- I would like to sponsor development of this feature
multiple:true
validations:
required:true
- type:dropdown
id:code-of-conduct
attributes:
label:Code of Conduct
description:|
Do you agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone?
options:
- "Yes, I agree"
multiple:true
validations:
required:true
- type:markdown
attributes:
value:|
Thanks for taking the time to suggest improvements for MicroPython.
description:Report a security issue or vulnerability in MicroPython
labels:["security"]
body:
- type:markdown
attributes:
value:|
This form is for reporting security issues in MicroPython that are not readily exploitable.
1. For issues that are readily exploitable or have high impact, please email contact@micropython.org instead.
1. If this is a question about security, please ask it in [Discussions](https://github.com/orgs/micropython/discussions/) or [Discord](https://discord.gg/RB8HZSAExQ) instead.
#### Existing issue?
* Please search for [existing issues](https://github.com/micropython/micropython/issues) before reporting a new one.
- type:input
id:port-board-hw
attributes:
label:Port, board and/or hardware
description:|
Which MicroPython port(s) and board(s) are you using?
placeholder:|
esp32 port, ESP32-Duper board.
- type:textarea
id:version
attributes:
label:MicroPython version
description:|
To find the version:
1. Open a serial REPL.
2. Type Ctrl-B to see the startup message.
3. Copy-paste that output here.
If the version or configuration is modified from the official MicroPython releases or the master branch, please tell us the details of this as well.
placeholder:|
MicroPython v6.28.3 on 2029-01-23; PyBoard 9 with STM32F9
- type:textarea
id:report
attributes:
label:Issue Report
description:|
Please provide a clear and concise description of the security issue.
* What does this issue allow an attacker to do?
* How does the attacker exploit this issue?
validations:
required:true
- type:dropdown
id:code-of-conduct
attributes:
label:Code of Conduct
description:|
Do you agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone?
.. Preamble section inserted into generated output
Positional-only Parameters
--------------------------
To save code size, many functions that accept keyword arguments in CPython only accept positional arguments in MicroPython.
MicroPython marks positional-only parameters in the same way as CPython, by inserting a ``/`` to mark the end of the positional parameters. Any function whose signature ends in ``/`` takes *only* positional arguments. For more details, see `PEP 570 <https://peps.python.org/pep-0570/>`_.
Example
~~~~~~~
For example, in CPython 3.4 this is the signature of the constructor ``socket.socket``::
The ``/`` at the end of the parameters indicates that they are all positional-only in MicroPython. The following code works in CPython but not in most MicroPython ports::
import socket
s = socket.socket(type=socket.SOCK_DGRAM)
MicroPython will raise an exception::
TypeError: function doesn't take keyword arguments
The following code will work in both CPython and MicroPython::
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -373,7 +373,7 @@ functions are defined in ``os`` module:
Mounts a block device (like an ``SD`` object) in the specified mount
point. Example::
os.mount(sd, '/sd')
vfs.mount(sd, '/sd')
..function:: unmount(path)
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.