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>
This commit renames the NORETURN macro, indicating to the compiler
that a function does not return, into MP_NORETURN to maintain the same
naming convention of other similar macros.
To maintain compaitiblity with existing code NORETURN is aliased to
MP_NORETURN, but it is also deprecated for MicroPython v2.
This changeset was created using a similar process to
decf8e6a8b ("all: Remove the "STATIC"
macro and just use "static" instead."), with no documentation or python
scripts to change to reflect the new macro name.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
These both need to fit a pointer, so make them `intptr_t` and `uintptr_t`,
similar to other ports.
Signed-off-by: Anton Blanchard <antonb@tenstorrent.com>
This commit adds the required functionality for a peripheral to create
services at runtime, using `BLE.register_services()`.
The feature is enabled on the nrf52840dk_nrf52840 board.
Note that the `CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION=n` option must be used
so that BLE notifications/indications can be sent even if not subscribed.
Signed-off-by: danicampora <danicampora@gmail.com>
This enables listing all flash area partitions automagically instead of
just sotrage_partitions. It uses the label, and the ID when not present.
Signed-off-by: Vdragon <mail@massdriver.space>
This enables using the newer USB stack and its CDC ACM for the REPL.
To switch to it, board file must contain `CONFIG_USB_DEVICE_STACK_NEXT=y`
and `CONFIG_USBD_CDC_ACM_CLASS=y`. In the case of a board that is a
platform that supports the older device stack, `CONFIG_USB_DEVICE_STACK=n`
may be necessary.
Signed-off-by: Vdragon <mail@massdriver.space>
Add support for the nrf5340dk. This DK has a MX25R64 8mb external QSPI
flash chip.
Compile using:
$ west build -b nrf5340dk/nrf5340/cpuapp
Signed-off-by: Patrick Joy <patrick@thinktransit.com.au>
Enables the ability to use frozen modules in the zephyr port.
Enabled by adding `CONFIG_MICROPY_FROZEN_MODULES` to the board
configuration file. Manually set manifest path with
`CONFIG_MICROPY_FROZEN_MANIFEST`.
Signed-off-by: Vdragon <mail@massdriver.space>
Implement PWM support using standard zephyr APIs, exposed as the standard
MicroPython `machine.PWM` class.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Updates the Zephyr port build instructions. The CI is updated to use
Zephyr docker image 0.27.4, SDK 0.17.0 and the latest Zephyr release
tag.
Tested on max32690fthr and frdm_k64f.
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Signed-off-by: Detlev Zundel <dzu@member.fsf.org>
Commit 07a8e3253a2d8a2076c9c83c4ed4158fa3fbb2a2 removes
CONFIG_MMC_VOLUME_NAME from the Kconfig space. Instead we need to use
the device tree to find the "disk-name" property of "zephyr,mmc-disk"
devices.
Signed-off-by: Detlev Zundel <dzu@member.fsf.org>
Commit 1b6e0f64796dfd6f86a8679ea6d24e1fca1e63a8 for Zephyr v4.0.0
changed the function "thread_analyzer_print" to require a cpu argument
and allow thread analysis on each cpu separately. The argument is
ignored when THREAD_ANALYZER_AUTO_SEPARATE_CORES=n which is the
default on single core machines.
Promote this change to the MicroPython zephyr module.
Signed-off-by: Detlev Zundel <dzu@member.fsf.org>
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
The (deprecated) kconfig option NET_SOCKETS_POSIX_NAMES was removed in
commit abad505bdeed6102061767f45acd63323973f564 so remove it from our
configuration.
As the option has been deprecated longer, this also works for v3.7 and
v4.0 the other still supported versions.
Signed-off-by: Detlev Zundel <dzu@member.fsf.org>
Simple `machine.Timer` implementation in-line with the rest of the
MicroPython ports.
Note: Only virtual timers are supported (not linked to any particular
hardware peripheral).
Tested with the nRF5340 and the nRF52840.
Signed-off-by: danicampora <danicampora@gmail.com>
Simple implementation in-line with the rest of the MicroPython ports
Tested on the nRF52832 and the nRF5340.
Signed-off-by: danicampora <danicampora@gmail.com>
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>
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 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>
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>
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>
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>
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>
MicroPython code may rely on the return value of sys.stdout.buffer.write()
to reflect the number of bytes actually written. While in most scenarios a
write() operation is successful, there are cases where it fails, leading to
data loss. This problem arises because, currently, write() merely returns
the number of bytes it was supposed to write, without indication of
failure.
One scenario where write() might fail, is where USB is used and the
receiving end doesn't read quickly enough to empty the receive buffer. In
that case, write() on the MicroPython side can timeout, resulting in the
loss of data without any indication, a behavior observed notably in
communication between a Pi Pico as a client and a Linux host using the ACM
driver.
A complex issue arises with mp_hal_stdout_tx_strn() when it involves
multiple outputs, such as USB, dupterm and hardware UART. The challenge is
in handling cases where writing to one output is successful, but another
fails, either fully or partially. This patch implements the following
solution:
mp_hal_stdout_tx_strn() attempts to write len bytes to all of the possible
destinations for that data, and returns the minimum successful write
length.
The implementation of this is complicated by several factors:
- multiple outputs may be enabled or disabled at compiled time
- multiple outputs may be enabled or disabled at runtime
- mp_os_dupterm_tx_strn() is one such output, optionally containing
multiple additional outputs
- each of these outputs may or may not be able to report success
- each of these outputs may or may not be able to report partial writes
As a result, there's no single strategy that fits all ports, necessitating
unique logic for each instance of mp_hal_stdout_tx_strn().
Note that addressing sys.stdout.write() is more complex due to its data
modification process ("cooked" output), and it remains unchanged in this
patch. Developers who are concerned about accurate return values from
write operations should use sys.stdout.buffer.write().
This patch might disrupt some existing code, but it's also expected to
resolve issues, considering that the peculiar return value behavior of
sys.stdout.buffer.write() is not well-documented and likely not widely
known. Therefore, it's improbable that much existing code relies on the
previous behavior.
Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
Also move MICROPY_PY_PENDSV_ENTER/REENTER/EXIT to mphalport.h, for ports
where these are not already there.
This helps separate the hardware implementation of these macros from the
MicroPython configuration (eg for renesas-ra and stm32, the IRQ static
inline helper functions can now be moved to irq.h).
Signed-off-by: Damien George <damien@micropython.org>
Minor changes for consistency are:
- nrf gains: unique_id(), freq() [they do nothing]
- samd: deepsleep() now resets after calling lightsleep()
- esp32: lightsleep()/deepsleep() no longer take kw arg "sleep", instead
it's positional to match others. also, passing 0 here will now do a 0ms
sleep instead of acting like nothing was passed.
reset_cause() no longer takes any args (before it would just ignore them)
- mimxrt: freq() with an argument and lightsleep() both raise
NotImplementedError
Signed-off-by: Damien George <damien@micropython.org>
And use it in all ports. The ports are unchanged, except esp8266 which now
just returns None from this function instead of the time elapsed (to match
other ports), and qemu-arm which gains this function.
Signed-off-by: Damien George <damien@micropython.org>
This is a code factoring to have the dict for the machine module in one
location, and all the ports use that same dict. The machine.soft_reset()
function implementation is also factored because it's the same for all
ports that did already implement it. Eventually more functions/bindings
can be factored.
All ports remain functionally the same, except:
- cc3200 port: gains soft_reset, mem8, mem16, mem32, Signal; loses POWER_ON
(which was a legacy constant, replaced long ago by PWRON_RESET)
- nrf port: gains Signal
- qemu-arm port: gains soft_reset
- unix port: gains soft_reset
- zephyr port: gains soft_reset, mem8, mem16, mem32
Signed-off-by: Damien George <damien@micropython.org>