Skip to content

Merged fixes for zephyr 4.0 #16879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/library/zephyr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Functions

Returns the thread id of the current thread, which is used to reference the thread.

.. function:: thread_analyze()
.. function:: thread_analyze(cpu)

Runs the Zephyr debug thread analyzer on the current thread and prints stack size statistics in the format:
Runs the Zephyr debug thread analyzer on the current thread on the given cpu
and prints stack size statistics in the format:

"``thread_name``-20s: STACK: unused ``available_stack_space`` usage ``stack_space_used``
/ ``stack_size`` (``percent_stack_space_used`` %); CPU: ``cpu_utilization`` %"
Expand All @@ -35,6 +36,9 @@ Functions
For more information, see documentation for Zephyr `thread analyzer
<https://docs.zephyrproject.org/latest/guides/debug_tools/thread-analyzer.html#thread-analyzer>`_.

Note that the ``cpu`` argument is only used in Zephyr v4.0.0 and
newer and ignored otherwise.

.. function:: shell_exec(cmd_in)

Executes the given command on an UART backend. This function can only be accessed if ``CONFIG_SHELL_BACKEND_SERIAL``
Expand Down
2 changes: 1 addition & 1 deletion docs/zephyr/tutorial/repl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ With your serial program open (PuTTY, screen, picocom, etc) you may see a
blank screen with a flashing cursor. Press Enter (or reset the board) and
you should be presented with the following text::

*** Booting Zephyr OS build v3.7.0 ***
*** Booting Zephyr OS build v4.0.0 ***
MicroPython v1.24.0-preview.179.g5b85b24bd on 2024-08-05; zephyr-frdm_k64f with mk64f12
Type "help()" for more information.
>>>
Expand Down
15 changes: 9 additions & 6 deletions ports/zephyr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ MicroPython port to Zephyr RTOS
This is a work-in-progress port of MicroPython to Zephyr RTOS
(http://zephyrproject.org).

This port requires Zephyr version v3.7.0, and may also work on higher
versions. All boards supported
by Zephyr (with standard level of features support, like UART console)
should work with MicroPython (but not all were tested).
This port tries to support all Zephyr versions supported upstream,
i.e. currently v3.7 (LTS), v4.0 and the development branch. The CI is
setup to use the latest version, i.e. v4.0.

All boards supported by Zephyr (with standard level of features
support, like UART console) should work with MicroPython (but not all
were tested).

Features supported at this time:

Expand Down Expand Up @@ -39,13 +42,13 @@ setup is correct.
If you already have Zephyr installed but are having issues building the
MicroPython port then try installing the correct version of Zephyr via:

$ west init zephyrproject -m https://github.com/zephyrproject-rtos/zephyr --mr v3.7.0
$ west init zephyrproject -m https://github.com/zephyrproject-rtos/zephyr --mr v4.0.0

Alternatively, you don't have to redo the Zephyr installation to just
switch from master to a tagged release, you can instead do:

$ cd zephyrproject/zephyr
$ git checkout v3.7.0
$ git checkout v4.0.0
$ west update

With Zephyr installed you may then need to configure your environment,
Expand Down
5 changes: 5 additions & 0 deletions ports/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <string.h>

#include <zephyr/kernel.h>
#include <zephyr/version.h>
#ifdef CONFIG_NETWORKING
#include <zephyr/net/net_context.h>
#endif
Expand Down Expand Up @@ -97,7 +98,11 @@ static void vfs_init(void) {
int ret = 0;

#ifdef CONFIG_DISK_DRIVER_SDMMC
#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(4, 0, 0)
mp_obj_t args[] = { mp_obj_new_str_from_cstr(DT_PROP(DT_INST(0, zephyr_sdmmc_disk), disk_name)) };
#else
mp_obj_t args[] = { mp_obj_new_str_from_cstr(CONFIG_SDMMC_VOLUME_NAME) };
#endif
bdev = MP_OBJ_TYPE_GET_SLOT(&zephyr_disk_access_type, make_new)(&zephyr_disk_access_type, ARRAY_SIZE(args), 0, args);
mount_point_str = "/sd";
#elif defined(CONFIG_FLASH_MAP) && FIXED_PARTITION_EXISTS(storage_partition)
Expand Down
10 changes: 8 additions & 2 deletions ports/zephyr/modzephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/version.h>
#include <zephyr/debug/thread_analyzer.h>
#include <zephyr/shell/shell.h>
#include <zephyr/shell/shell_uart.h>
Expand All @@ -48,11 +49,16 @@ static mp_obj_t mod_current_tid(void) {
static MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid);

#ifdef CONFIG_THREAD_ANALYZER
static mp_obj_t mod_thread_analyze(void) {
static mp_obj_t mod_thread_analyze(mp_obj_t cpu_in) {
#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(4, 0, 0)
unsigned int cpu = mp_obj_get_int(cpu_in);
thread_analyzer_print(cpu);
#else
thread_analyzer_print();
#endif
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_analyze_obj, mod_thread_analyze);
static MP_DEFINE_CONST_FUN_OBJ_1(mod_thread_analyze_obj, mod_thread_analyze);
#endif

#ifdef CONFIG_SHELL_BACKEND_SERIAL
Expand Down
1 change: 0 additions & 1 deletion ports/zephyr/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ CONFIG_NET_IPV6=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=n
CONFIG_TEST_RANDOM_GENERATOR=y

CONFIG_NET_CONFIG_SETTINGS=y
Expand Down
6 changes: 3 additions & 3 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,9 @@ function ci_windows_build {
########################################################################################
# ports/zephyr

ZEPHYR_DOCKER_VERSION=v0.26.13
ZEPHYR_SDK_VERSION=0.16.8
ZEPHYR_VERSION=v3.7.0
ZEPHYR_DOCKER_VERSION=v0.27.4
ZEPHYR_SDK_VERSION=0.17.0
ZEPHYR_VERSION=v4.0.0

function ci_zephyr_setup {
IMAGE=ghcr.io/zephyrproject-rtos/ci:${ZEPHYR_DOCKER_VERSION}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy