Commit Graph

1275 Commits

Author SHA1 Message Date
Damien George
97af1001ae rp2/machine_uart: Make it so TX is done only when no longer busy.
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>
2024-10-22 10:17:05 +11:00
Phil Howard
e6093c0fbd rp2/rp2_pio: Add support for RP2350A/B variants in PIO interface.
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>
2024-10-15 12:09:48 +11:00
Andrew Leech
6d799378ba esp32: Add support for esp32c6.
This commit adds general support for ESP32-C6 SoCs.

Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-09 23:29:38 +11:00
Damien George
e5eeaa7df8 docs/reference/mpremote: Update docs to mention new features.
Signed-off-by: Damien George <damien@micropython.org>
2024-10-09 16:39:06 +11:00
Maureen Helm
a9803f4711 zephyr: Allow using devicetree node labels to construct machine objects.
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>
2024-10-01 20:02:01 -05:00
Maureen Helm
545d4efb55 zephyr: Upgrade to Zephyr v3.7.0.
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>
2024-10-02 07:49:53 +10:00
Maureen Helm
2407c46dac docs/zephyr: Update docs to reflect device name changes.
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>
2024-10-02 07:49:30 +10:00
Andrew Leech
7e14680a83 py/objringio: Add micropython.RingIO() interface for general use.
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>
2024-09-19 18:00:44 +10:00
Angus Gratton
52a593cdb1 py/scheduler: Only run callbacks on the main thread if GIL is disabled.
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>
2024-09-19 13:17:01 +10:00
Angus Gratton
fb069f9d06 docs/library: Document machine.Pin.toggle() method.
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>
2024-09-19 12:04:39 +10:00
Damien George
8feb714b4d docs/library: Document math.log with two arguments.
The functionality is there but was not documented.

Signed-off-by: Damien George <damien@micropython.org>
2024-09-17 11:22:26 +10:00
Damien George
3d53b39a2a docs/reference: Fix pyboard.py filesystem cp example with three files.
Fix documentation to match behaviour (directories are not preserved).

Fixes issue #11101.

Signed-off-by: Damien George <damien@micropython.org>
2024-09-17 11:20:17 +10:00
Paul Grayson
0d8388673e docs/esp32: Update pin access example with addresses for ESP32-S3.
Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-17 11:18:47 +10:00
robert-hh
1a6279ba37 samd/mphalport: Simplify mp_hal_delay_ms().
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>
2024-09-06 17:43:49 +10:00
Damien George
35b6a66b0b docs/library: Document the network.PPP class.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-29 23:47:55 +10:00
robert-hh
03b1b6d8e6 docs/library/machine.UART: Extend the documentation for UART.irq.
For more ports and trigger options, based on the current state of the code.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-29 16:48:09 +10:00
Damien George
9bbe61607a docs/library/machine.UART: Fix UART.irq docs to match current code.
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>
2024-08-29 16:34:45 +10:00
robert-hh
7270b871c2 rp2/modmachine: Set the peripheral frequency with machine.freq().
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>
2024-08-20 12:26:45 +10:00
robert-hh
76dd4facb9 docs/mimxrt/quickref: Add a note about machine.RTC() subseconds.
Telling that subseconds is not supported and returns always 0.  This was
changed in 913f9ad5ad.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-08-20 12:07:23 +10:00
Tim Weber
d1685a3f5f docs/library/neopixel: Mention bitstream timing tuple.
Signed-off-by: Tim Weber <scy@scy.name>
2024-08-01 12:04:58 +10:00
George Hopkins
066243ea74 py/py.mk: Add SRC_USERMOD_LIB_ASM to include assembly files.
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>
2024-08-01 12:01:18 +10:00
Angus Gratton
81daba31c5 docs: Specify that machine.idle() returns at least every 1ms.
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>
2024-07-23 16:42:42 +10:00
Felix Dörre
4d16a9cced docs: Update docs to replace ifconfig with ipconfig.
Follow up to 1c6012b0b5

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-07-05 16:06:04 +10:00
robert-hh
f36a5654a8 docs/rp2/quickref: Document the use of channel numbers for ADC.
Signed-off-by: robert-hh <robert@hammelrath.com>
2024-07-04 11:50:47 +10:00
Felix Dörre
57008a1e69 extmod/machine_usb_device: Add USBDevice.remote_wakeup method.
This simply exposes the TinyUSB function.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-07-02 10:23:26 +10:00
Angus Gratton
908ab1ceca py/objint: Fix int.to_bytes() buffer size checks.
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>
2024-06-24 14:07:00 +10:00
Alessandro Gatti
99f5659cf5 mpy-cross: Add RISC-V RV32IMC support in MPY files.
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>
2024-06-21 15:06:29 +10:00
Damien George
5f6e689124 LICENSE,docs: Update copyright year range to include 2024.
Signed-off-by: Damien George <damien@micropython.org>
2024-05-27 23:39:16 +10:00
Damien George
abd1f28bc2 docs/library/asyncio: Document that ThreadSafeFlag now works on unix.
ThreadSafeFlag works on the unix port since commit
df08c38c28.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-15 14:13:30 +10:00
Olivier Lenoir
e816b49c44 docs/reference: Document how to mip install packages from GitLab.
Signed-off-by: Olivier Lenoir <olivier.len02@gmail.com>
2024-05-15 13:35:27 +10:00
Angus Gratton
c3301da176 docs/library/machine.USBDevice: Update note about packages in mp-lib.
Also fix a small typo.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-09 15:48:26 +10:00
Rick Sorensen
63c30a2dfc esp32/modesp32: Add mcu_temperature() function for C3/S2/S3 devices.
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>
2024-05-07 17:29:22 +10:00
Rick Sorensen
595f86155a docs/esp32/quickref: Add note about different ESP32 varieties.
Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
2024-05-07 17:28:25 +10:00
Matt Trentini
b1ac266bb5 docs/develop/optimizations: Fix typo identified in issue 14391.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-04-29 09:20:28 +10:00
Angus Gratton
d11ca092f7 shared/tinyusb: Fix dynamic USB control callbacks for wLength==0.
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>
2024-04-17 12:39:47 +10:00
Damien George
628a37e6cf docs/reference/mpyfiles: Document change in .mpy sub-version.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-28 16:21:35 +11:00
Amirreza Hamzavi
57de9da352 docs/library/machine.RTC: Add docs for RTC.memory() method.
Co-Authored-By: glenn20 <glenn20@users.noreply.github.com>

Signed-off-by: Amirreza Hamzavi <amirrezahamzavi2000@gmail.com>
2024-03-26 17:59:06 +11:00
Matthias Urlichs
e520fa2e0f py/binary: Support half-float 'e' format in struct pack/unpack.
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>
2024-03-20 14:13:49 +11:00
Nicko van Someren
77f08b72ca docs/library/rp2.DMA: Add documentation for rp2 DMA support.
Signed-off-by: Nicko van Someren <nicko@nicko.org>
2024-03-19 17:10:54 +11:00
Damien George
d92dff881c docs/library/collections: Update deque docs to describe new features.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 10:09:11 +11:00
iabdalkader
e5ca06a06f docs/library/openamp: Document the new openamp module.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00
Angus Gratton
9d0d262be0 extmod/machine_usb_device: Add support for Python USB devices.
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>
2024-03-15 14:22:11 +11:00
robert-hh
cdfc6c159f esp32/network_lan: Add a separate argument to set PHY power pin.
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>
2024-03-08 16:55:08 +11:00
Phil Howard
dda9b9c6da all: Prune trailing whitespace.
Prune trailing whitespace across the whole project (almost), done
automatically with:

    grep -IUrl --color "[[:blank:]]$" --exclude-dir=.git --exclude=*.exp |\
        xargs sed -i 's/[[:space:]]*$//'

Exceptions:
- Skip third-party code in lib/ and drivers/cc3100/
- Skip generated code in bluetooth_init_cc2564C_1.5.c
- Preserve command output whitespace in docs, eg:
  docs/esp8266/tutorial/repl.rst

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-03-07 16:25:17 +11:00
Angus Gratton
decf8e6a8b all: Remove the "STATIC" macro and just use "static" instead.
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>
2024-03-07 14:20:42 +11:00
Daniël van de Giessen
678707c8b0 docs/library/bluetooth: Add note that ESP32 supports pairing/bonding.
Pairing and bonding was fixed for the ESP32 in the two previous commits.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2024-02-29 14:33:22 +11:00
Damien George
e2ff00e811 py/emitglue: Introduce mp_proto_fun_t as a more general mp_raw_code_t.
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>
2024-02-16 14:17:01 +11:00
Damien George
35dd959133 tools/manifestfile.py: Change library search to use a list of paths.
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>
2024-02-08 17:16:10 +11:00
Jos Verlinde
2bdaa1bede docs/library/sys.rst: Document implementation.version.releaselevel.
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
2024-02-07 15:51:25 +11:00
Damien George
4c56b39051 docs: Use vfs module instead of os.
Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 13:25:10 +11:00