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>
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>
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>
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>
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>
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>
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>
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>
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 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 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>
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>
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>
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>
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>
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>
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>
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>
Add `load_cert_chain`, `load_verify_locations`, `get_ciphers` and
`set_ciphers` SSLContext methods in ssl library, and update asyncio
`open_connection` and `start_server` methods with ssl support.
Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
The behaviour described in the docs was not correct for either port.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
If you have a variable frequency and pulse width, and you want to optimize
pulse resolution, then you must do a calculation beforehand to ensure you
normalize the array to keep all list values within bound. That calculation
requires RMT.source_freq(), RMT.clock_div(), and this 32767 constant.
Signed-off-by: Mark Blakeney <mark.blakeney@bullet-systems.net>
To create an esp32.RMT() instance with an optimum (i.e. highest resolution)
clock_div is currently awkward because you need to know the source clock
frequency to calculate the best clock_div, but unfortunately that is only
currently available as an source_freq() method on the instance after you
have already created it. So RMT.source_freq() should really be a class
method, not an instance method. This change is backwards compatible for
existing code because you can still reference that function from an
instance, or now also, from the class.
Signed-off-by: Mark Blakeney <mark.blakeney@bullet-systems.net>