Age | Commit message (Collapse) | Author |
|
Avoiding the double timeout when used with the UART class.
`stream.readinto1()` returns after the first timeout.
Fixes issue #17611.
Signed-off-by: robert-hh <robert@hammelrath.com>
|
|
Do not try to read/write again after timeout happened once.
Fixes issue #17611.
Signed-off-by: robert-hh <robert@hammelrath.com>
|
|
This adds the ability to expose CPU-specific features/extensions to
scripts when the `platform` module is compiled in, by implementing
`platform.processor()`. Right now this is only available on
bare-metal RV32 and RV64.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
|
|
Cleans up 24234937747e6d7fd920d21358fb26b826398e1a, and fixes builds
that include LFS but not MICROPY_ENABLE_FINALISER.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
|
|
When disconnecting from PPP the modem sends a confirmation. This message
is received, like all messages, through the poll() method. lwIP may then
immediately call our status callback with code PPPERR_USER to indicate
the connection was closed. Our callback then immediately proceeds to
free the PCB. Thus, during each new iteration of the loop in poll() we
must check if we haven't disconnected in the meantime to prevent calling
the pppos_input_tcpip with a PCB that is now NULL.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
|
|
If while a polling operation is active the stream is removed we should
stop polling data from that stream.
This was already the intended behaviour, but implemented incorrectly.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
|
|
The lwIP includes are now port-specific.
The `sys_arch_{,un}protect` functions are not used according to line 34
of `extmod/lwip-include/lwipopts_common.h`.
Neither have been touched in nearly a decade.
Signed-off-by: Thomas Watson <twatson52@icloud.com>
|
|
This factors code out of the ports and into the common `time.localtime`
implementation in `extmod/modtime.c`. That helps to reduce code
duplication, prevent errors in implementation, and reduce code size on
some ports (mimxrt and stm32 at least).
Signed-off-by: Damien George <damien@micropython.org>
|
|
There's a slight code size increase paid for by using setpixel_checked for
the last pixel of a line, instead of repeating the checks inline.
Signed-off-by: Jeff Epler <jepler@gmail.com>
|
|
If mp_int_t is wider than int, then the tests such as `xend < 0` can fail
even when the amount of scrolling requested is out of range. This resulted
in a segmentation fault when attempting an out-of-bounds access to the
framebuffer.
Signed-off-by: Jeff Epler <jepler@gmail.com>
|
|
`socket.getaddrinfo()` supports the specification of an address family;
however, the LwIP implementation does not use it. This change allows the
application to specify the address family request in DNS resolution. If
no family is specified, it falls back to the default preference
configured with `network.ipconfig()`.
Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
|
|
Pattern objects have two additional parameters for the ::search and ::match
methods to define the starting and ending position of the subject within
the string to be searched.
This allows for searching a sub-string without creating a slice. However,
one caveat of using the start-pos rather than a slice is that the start
anchor (`^`) remains anchored to the beginning of the text.
Signed-off-by: Jared Hancock <jared@greezybacon.me>
|
|
If PPP is still connected, freeing the PCB will fail and thus instead we
should trigger a disconnect and wait for the lwIP callback to actually
free the PCB.
When PPP is not connected we should check if the freeing failed, warn
the user if so, and only mark the connection as inactive if not.
When all this happens during garbage collection the best case is that
the PPP connection is already dead, which means the callback will be
called immediately and cleanup will happen correctly. The worst case is
that the connection is still alive, thus we are unable to free the PCB
(lwIP won't let us) and it remains referenced in the netif_list, meaning
a use-after-free happens later when lwIP traverses that linked list.
This change does not fully prevent that, but it *does* improve how the
PPP.active(False) method on the ESP32 port behaves: It no longer
immediately tries to free (and fails), but instead triggers a disconnect
and lets the cleanup happen correctly through the status callback.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
|
|
The status callback runs on the lwIP tcpip_thread, and thus must use the
non-thread-safe API because the thread-safe API would cause a deadlock.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
|
|
This commit implements a generic I2C target/peripheral/"slave" device,
called `machine.I2CTarget`. It can work in two separate modes:
- A general device with interrupts/events/callbacks for low-level I2C
operations like address match, read request and stop.
- A memory device that allows reading/writing a specific region of memory
(or "registers") on the target I2C device.
To make a memory device is very simple:
from machine import I2CTarget
mem = bytearray(8)
i2c = I2CTarget(addr=67, mem=mem)
That's all that's needed to start the I2C target. From then on it will
respond to any I2C controller on the bus, allowing reads and writes to the
mem bytearray.
It's also possible to register to receive events. For example to be
notified when the memory is read/written:
from machine import I2CTarget
def irq_handler(i2c_target):
flags = i2c_target.irq().flags()
if flags & I2CTarget.IRQ_END_READ:
print("controller read target at addr", i2c_target.memaddr)
if flags & I2CTarget.IRQ_END_WRITE:
print("controller wrote target at addr", i2c_target.memaddr)
mem = bytearray(8)
i2c = I2CTarget(addr=67, mem=mem)
i2c.irq(irq_handler)
Instead of a memory device, an arbitrary I2C device can be implemented
using all the events (see docs).
This is based on the discussion in #3935.
Signed-off-by: Damien George <damien@micropython.org>
|
|
Contrary to the docs, mbedtls can return more than just
MBEDTLS_ERR_SSL_ALLOC_FAILED when `mbedtls_ssl_setup()` fails. At least
MBEDTLS_ERR_MD_ALLOC_FAILED was also seen on ESP32_GENERIC, but there
could possibly be other error codes.
To cover all these codes, just check if `ret` is non-0, and in that case
do a `gc_collect()` and retry the init.
Signed-off-by: Damien George <damien@micropython.org>
|
|
As timeout is of type `mp_uint_t`, it must be printed with UINT_FMT.
Before, the compiler plugin produced an error in the PYBD_SF6 build, which
is a nanboxing build with 64-bit ints.
Signed-off-by: Jeff Epler <jepler@gmail.com>
|
|
When this configuration flag is set, VfsPosix instances can be written.
Otherwise, they will always be created "read only".
This flag is useful when fuzzing micropython: Without VfsPosix, the fuzzing
input script cannot be read; but with writable VfsPosix, fuzzing scripts
can potentially perform undesired operations on the host filesystem.
Signed-off-by: Jeff Epler <jepler@gmail.com>
|
|
Otherwise operations such as unlink can be performed on a nominally
read-only VfsPosix.
Signed-off-by: Jeff Epler <jepler@gmail.com>
|
|
Back in LFS2 version 2.6 they updated the on-disk version from 2.0 to 2.1
which broke back compatibility (aka older versions could no long read new
version disk format), see
https://github.com/littlefs-project/littlefs/releases/tag/v2.6.0
Then in LFS2 v2.7 an optional `config->disk_version` was added to force the
library to use an older disk format instead, see:
https://github.com/littlefs-project/littlefs/releases/tag/v2.7.0
This commit simply exposes `config->disk_version` as a compile time option
if LFS2_MULTIVERSION is set, otherwise there is no change in behavior.
This is Useful for compatibility with older LFS versions.
Note: LFS2_MULTIVERSION needs to be defined at the make / CFLAGS level,
setting it in mpconfigboard.h doesn't work as it's not included in the
`lfs2.c` file in any way.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
|
|
This is an annoying regression caused by including mpconfig.h in 36922df -
the mimxrt platform headers define ARRAY_SIZE and mbedtls also defines in
some source files, using a different parameter name which is a warning in
gcc.
Technically mimxrt SDK is to blame here, but as this isn't a named warning
in gcc the only way to work around it in the mimxrt port would be to
disable all warnings when building this particular mbedTLS source file.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
- DTLS spec recommends HelloVerify and Anti Replay protection be enabled,
and these are enabled in the default mbedTLS config. Implement them here.
- To help compensate for the possible increase in code size, add a
MICROPY_PY_SSL_DTLS build config macro that's enabled for EXTRA and
above by default.
This allows bare metal mbedTLS ports to use DTLS with HelloVerify support.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
This is already enabled in the ESP-IDF mbedTLS config, so provide an
implementation of the cookie store functions. This allows DTLS connections
between two esp32 boards.
The session cookie store is a very simple dictionary associated with the
SSLContext. To work, the server needs to reuse the same SSLContext (but
cookies are never cleaned up, so a server with a high number of clients
should recycle the context periodically.)
Server code still needs to handle the MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED
error by waiting for the next UDP packet from the client.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
Really lwIP should provide this, to deregister all callbacks on the given
netif.
Signed-off-by: Damien George <damien@micropython.org>
|
|
This is code makes sure that time functions work properly on a
reasonable date range, on all platforms, regardless of the epoch.
The suggested minimum range is 1970 to 2099.
In order to reduce code footprint, code to support far away dates
is only enabled specified by the port.
New types are defined to identify timestamps.
The implementation with the smallest code footprint is when
support timerange is limited to 1970-2099 and Epoch is 1970.
This makes it possible to use 32 bit unsigned integers for
all timestamps.
On ARM4F, adding support for dates up to year 3000 adds
460 bytes of code. Supporting dates back to 1600 adds
another 44 bytes of code.
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
|
|
Add check to prevent calling recv on a socket in the listening state. This
prevents a crash/hard fault when user code mistakenly tries to recv on the
listening socket instead of on the accepted connection.
Add corresponding test case to demonstrate the bug.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
|
|
Testing shows that for frequencies which the esp8266 can handle -- up to
about 1kHz -- `machine.time_pulse_us()` now gives more accurate results.
Prior to this commit it would measure on average about 1us lower, but now
the average is much closer to the true value. For example a pulse that is
1000us long, it would measure between 998 and 1000us. Now it measures
between 999us and 1001us.
Signed-off-by: Damien George <damien@micropython.org>
|
|
This implementation is based on the esp8266 custom implementation, and
further optimised for size and accuracy.
Testing on PYBD_SF2 and RPI_PICO2_W shows that it is at least as good as
the original implementation in performance.
Signed-off-by: Damien George <damien@micropython.org>
|
|
If the error reporting mode is at least "normal", report a failure due to a
complex regex with a different message.
Fixes issue #17150.
Signed-off-by: Jeff Epler <jepler@gmail.com>
|
|
Most extmod network drivers were being defined on a per-port basis,
duplicating code and making enabling a driver on a new port harder.
This consolidates extmod driver declarations and removes the existing
per-port definitions of them.
This commit has been verified to be a no-op in terms of firmware change.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
|
|
Currently the `FrameBuffer.blit(buf, x, y)` method requires the `buf`
argument to be another `FrameBuffer`, which is quite restrictive because it
doesn't allow blit'ing read-only memory/data.
This commit extends `blit()` to allow the `buf` argument to be a tuple or
list of the form:
(buffer, width, height, format[, stride])
where `buffer` can be anything with the buffer protocol and may be
read-only, eg `bytes`.
Also, the palette argument to `blit()` may be of the same form.
The form of this tuple/list was chosen to be the same as the signature of
the `FrameBuffer` constructor (that saves quite a bit of code size doing it
that way).
Signed-off-by: Damien George <damien@micropython.org>
|
|
If the BLE radio stops responding before deinit is called the function can
get stuck waiting for an event that is never received, particularly if the
radio is external or on a separate core.
This commit adds a timeout, similar to the timeout already used in the init
function. Updated for nimble, btstack, esp32 and zephyr bindings.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
|
|
Implements MSG_PEEK and MSG_DONTWAIT.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
esp32 port will disconnect if active(0) is called on a STA
interface, but rp2 port stays associated without this change.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
This commit makes the JSON parser raise an exception when handling
objects or arrays whose declaration is incomplete, as in missing the
closing marker (brace or bracket) and if the missing marker would have
been the last non-whitespace character in the incoming string.
Since CPython's JSON parser would raise an exception in such a case,
unlike MicroPython's, this commit aligns MicroPython's behaviour with
CPython.
This commit fixes issue #17141.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
|
|
OSError errno values should be positive.
Signed-off-by: Damien George <damien@micropython.org>
|
|
The ESP32 PPP implementation predates the generic
implementation in extmod. The new extmod
implementation has a few advantages such as a
better deinitialisation procedure (the ESP32
implemementation would not clean up properly and
cause crashes if recreated) and using the UART IRQ
functionality instead of running a task to read
data from the UART.
This change restructures the ESP implementation to
be much closer to the new extmod version, while
also bringing a few tiny improvements from the
ESP32 version to the extmod version. The diff
between extmod/network_ppp_lwip.c and
ports/esp32/network_ppp.c is now a small set of
easy to review ESP32 port-specific changes.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
|
|
This commit renames the NORETURN macro, indicating to the compiler
that a function does not return, into MP_NORETURN to maintain the same
naming convention of other similar macros.
To maintain compaitiblity with existing code NORETURN is aliased to
MP_NORETURN, but it is also deprecated for MicroPython v2.
This changeset was created using a similar process to
decf8e6a8bb940d5829ca3296790631fcece7b21 ("all: Remove the "STATIC"
macro and just use "static" instead."), with no documentation or python
scripts to change to reflect the new macro name.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
|
|
The bare-metal lwIP socket interface is currently quite limited when used
for UDP streams, because it only allows one outstanding incoming UDP
packet. If one UDP packet is waiting to be socket.recv'd and another one
comes along, then the second one is simply dropped.
This commit implements a queue for incoming UDP and raw packets. The queue
depth is fixed at compile time, and is currently 4.
This allows better use of UDP connections, eg more efficient. It also
makes DTLS work better which sometimes has a queue of UDP packets (eg
during the connection phase).
Signed-off-by: Damien George <damien@micropython.org>
|
|
Avoids the new Wunterminated-string-literal when compiled with gcc 15.1.
Also split out the duplicate string to a top-level array (probably the
duplicate string literal was interned, so unlikely to have any impact.)
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
This means the fix from dd1465e7 will also apply to stm32 and mimxrt ports
that use CYW43.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
This is only a surface level refactor, some deeper refactoring would be
possible with (for example) the SDIO interface in mimxrt and stm32, or the
BTHCI interface which is is similar on supported ports. But sticking to
cases where the macros are the same across all ports.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
|
Getting this to work required fixing a small issue in `lfs2_util.h`, which
has been submitted upstream.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
|
|
This commit fixes three open issues related to the asyncio scheduler
exiting prematurely when the main task queue is empty, in cases where
CPython would not exit (for example, because the main task is not done
because it's on a different queue).
In the first case, the scheduler exits because running a task via
`run_until_complete` did not schedule any dependent tasks.
In the other two cases, the scheduler exits because the tasks are queued in
an event queue.
Tests have been added which reproduce the original issues. These test
cases document the unauthorized use of `Event.set()` from a soft IRQ, and
are skipped in unsupported environments (webassembly and native emitter).
Fixes issues #16759, #16569 and #16318.
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
|
|
Rename `bthci` to `bthci_uart` for consistency with the CYW43 driver and to
distinguish it from HCI backends that use a different transport.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
|
|
Required in MICROPY_PREVIEW_VERSION_2.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
|
|
Required in MICROPY_PREVIEW_VERSION_2.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
|
|
The cyw43-driver now provides the Bluetooth initialisation code, making
`drivers/cyw43/cywbt.c` obsolete. To use the new code a port must enable
the `CYW43_ENABLE_BLUETOOTH_OVER_UART` option.
Some ports have yet to migrate to the new code, so in the meantime they can
explicitly add the old source to their source list and continue to use it
without change.
Signed-off-by: Damien George <damien@micropython.org>
|
|
This file is part of the updated cyw43-driver. It will only be used if
`CYW43_USE_SPI` is enabled.
Signed-off-by: Damien George <damien@micropython.org>
|
|
Rather than having Make calling CMake to generate a list of submodules and
then run a Make target (which is complex and prone to masking other
errors), implement the submodule update logic in CMake itself.
Internal CMake-side changes are that GIT_SUBMODULES is now a CMake list,
and the trigger variable name is changed from ECHO_SUBMODULES to
UPDATE_SUBMODULES.
The run is otherwise 100% a normal CMake run now, so most of the other
special casing can be removed.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
|