8000 ports/zephyr: Update to Zephyr 3.2.0. by bogdanm · Pull Request #10830 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

ports/zephyr: Update to Zephyr 3.2.0. #10830

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 6 additions & 0 deletions ports/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(micropython)

set(MICROPY_PORT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(MICROPY_BUILD_DIR ${MICROPY_PORT_DIR}/build)
set(MICROPY_DIR ${MICROPY_PORT_DIR}/../..)
set(MICROPY_TARGET micropython)

Expand Down Expand Up @@ -74,7 +75,12 @@ set(MICROPY_SOURCE_LIB
)
list(TRANSFORM MICROPY_SOURCE_LIB PREPEND ${MICROPY_DIR}/lib/)

add_custom_command(OUTPUT ${MICROPY_BUILD_DIR}/gen_dt_node_names.h
DEPENDS ${MICROPY_BUILD_DIR}/zephyr/edt.pickle ${MICROPY_PORT_DIR}/gen_dt_node_names.py
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PORT_DIR}/gen_dt_node_names.py -i ${MICROPY_BUILD_DIR}/zephyr/edt.pickle -o ${MICROPY_BUILD_DIR}/gen_dt_node_names.h)

set(MICROPY_SOURCE_QSTR
${MICROPY_BUILD_DIR}/gen_dt_node_names.h
${MICROPY_SOURCE_PY}
${MICROPY_SOURCE_EXTMOD}
${MICROPY_SOURCE_SHARED}
Expand Down
6 changes: 3 additions & 3 deletions ports/zephyr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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.1.0, and may also work on higher
This port requires Zephyr version v3.2.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).
Expand Down Expand Up @@ -39,13 +39,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.1.0
$ west init zephyrproject -m https://github.com/zephyrproject-rtos/zephyr --mr v3.2.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.1.0
$ git checkout v3.2.0
$ west update

With Zephyr installed you may then need to configure your environment,
Expand Down
68 changes: 68 additions & 0 deletions ports/zephyr/gen_dt_node_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3

import argparse
import os
import sys
import pickle
import re

# This is needed by the "pickle.load" call below
zephyr_base = os.environ["ZEPHYR_BASE"]
sys.path.insert(0, os.path.join(zephyr_base, "scripts", "dts", "python-devicetree", "src"))

# The prefixes to look for in the device tree
prefixes = ("gpio", "spi", "i2c", "uart")

# Prefix for the generated header
header_prefix = """#ifndef MICROPY_INCLUDED_ZEPHYR_GEN_DT_NODE_NAMES_H
#define MICROPY_INCLUDED_ZEPHYR_GEN_DT_NODE_NAMES_H

struct dt_node_name_map {
const char *const gen_name;
const char *const actual_name;
};

static const struct dt_node_name_map dt_node_map[] = {
"""
# Suffix for the generated header
header_sufix = """};

#endif
"""

def main():
parser = argparse.ArgumentParser(description="Generate friendly names for Zephyr DT nodess")
parser.add_argument("-i", "--input", required=True, help="path to edt.pickle")
parser.add_argument("-o", "--output", required=True, help="path to the output file")
args = parser.parse_args()

# Load the representation of the device tree generated by Zephyr
with open(args.input, 'rb') as f:
edt = pickle.load(f)

# Create regular expressions for all prefix that we need to check
all_re = re.compile(fr'^({"|".join(prefixes)})(\d+)$')

# Look in the device tree for all nodes with labels
name_map = {}
for n in edt.nodes:
if n.status == "okay": # consider only nodes that are enabled
# Check prefixes for all labels
for l in n.labels:
found = all_re.match(l)
if found != None:
# Transform name (from "gpio0" to "GPIO_0" and so on)
new_name = found.group(1).upper() + "_" + found.group(2)
name_map[new_name] = n.name
break

# Write data to output file
with open(args.output, "wt") as f:
f.write(header_prefix)
for n in name_map:
f.write(f' {{"{n}", "{name_map[n]}"}},\n')
f.write(" {NULL, NULL}\n")
f.write(header_sufix)

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion ports/zephyr/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <stdint.h>
#include <string.h>

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/i2c.h>

#include "py/runtime.h"
Expand Down
11 changes: 10 additions & 1 deletion ports/zephyr/machine_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
#include <stdint.h>
#include <string.h>

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "shared/runtime/mpirq.h"
#include "modmachine.h"
#include "gen_dt_node_names.h"

#if MICROPY_PY_MACHINE

Expand Down Expand Up @@ -133,6 +134,14 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
const char *drv_name = mp_obj_str_get_str(items[0]);
int wanted_pin = mp_obj_get_int(items[1]);
const struct device *wanted_port = device_get_binding(drv_name);
if (!wanted_port) {
for (const struct dt_node_name_map *m = &dt_node_map[0]; m->gen_name != NULL; m ++) {
if (!strcmp(m->gen_name, drv_name)) {
wanted_port = device_get_binding(m->actual_name);
break;
}
}
}
if (!wanted_port) {
mp_raise_ValueError(MP_ERROR_TEXT("invalid port"));
}
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <stdint.h>
#include <string.h>

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/spi.h>

#include "py/runtime.h"
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/machine_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <stdint.h>
#include <string.h>

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>

#include "py/runtime.h"
Expand Down
4 changes: 2 additions & 2 deletions ports/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <stdio.h>
#include <string.h>

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#ifdef CONFIG_NETWORKING
#include <zephyr/net/net_context.h>
#endif
Expand Down Expand Up @@ -106,7 +106,7 @@ STATIC void vfs_init(void) {
mp_obj_t args[] = { mp_obj_new_str(CONFIG_SDMMC_VOLUME_NAME, strlen(CONFIG_SDMMC_VOLUME_NAME)) };
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) && FLASH_AREA_LABEL_EXISTS(storage)
#elif defined(CONFIG_FLASH_MAP) && FIXED_PARTITION_EXISTS(storage)
mp_obj_t args[] = { MP_OBJ_NEW_SMALL_INT(FLASH_AREA_ID(storage)), MP_OBJ_NEW_SMALL_INT(4096) };
bdev = MP_OBJ_TYPE_GET_SLOT(&zephyr_flash_area_type, make_new)(&zephyr_flash_area_type, ARRAY_SIZE(args), 0, args);
mount_point_str = "/flash";
Expand Down
4 changes: 2 additions & 2 deletions ports/zephyr/modbluetooth_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

#if MICROPY_PY_BLUETOOTH

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include "extmod/modbluetooth.h"

#define DEBUG_printf(...) // printk("BLE: " __VA_ARGS__)
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/modusocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "py/stream.h"

#include <stdio.h>
#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
// Zephyr's generated version header
#include <version.h>
#include <zephyr/net/net_context.h>
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/modutime.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "py/mpconfig.h"
#if MICROPY_PY_UTIME

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>

#include "py/runtime.h"
#include "py/smallint.h"
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/modzephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#if MICROPY_PY_ZEPHYR

#include <stdio.h>
#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/debug/thread_analyzer.h>
#include <zephyr/shell/shell.h>
#include <zephyr/shell/shell_uart.h>
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/modzsensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "py/runtime.h"

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/sensor.h>

#if MICROPY_PY_ZSENSOR
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// Include Zephyr's autoconf.h, which should be made first by Zephyr makefiles
#include "autoconf.h"
// Included here to get basic Zephyr environment (macros, etc.)
#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/spi.h>

// Usually passed from Makefile
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/mpconfigport_minimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// Include Zephyr's autoconf.h, which should be made first by Zephyr makefiles
#include "autoconf.h"
// Included here to get basic Zephyr environment (macros, etc.)
#include <zephyr.h>
#include <zephyr/kernel.h>

// Usually passed from Makefile
#ifndef MICROPY_HEAP_SIZE
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/mphalport.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include "shared/runtime/interrupt_char.h"

void mp_hal_init(void);
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/src/zephyr_getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/drivers/console/uart_console.h>
#include <zephyr/sys/printk.h>
Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/src/zephyr_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/console/console.h>
#include "zephyr_getchar.h"

Expand Down
2 changes: 1 addition & 1 deletion ports/zephyr/zephyr_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ STATIC const mp_rom_map_elem_t zephyr_flash_area_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&zephyr_flash_area_readblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&zephyr_flash_area_writeblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&zephyr_flash_area_ioctl_obj) },
#if FLASH_AREA_LABEL_EXISTS(storage)
#if FIXED_PARTITION_EXISTS(storage)
{ MP_ROM_QSTR(MP_QSTR_STORAGE), MP_ROM_INT(FLASH_AREA_ID(storage)) },
#endif
};
Expand Down
6 changes: 3 additions & 3 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,9 @@ function ci_windows_build {
########################################################################################
# ports/zephyr

ZEPHYR_DOCKER_VERSION=v0.21.0
ZEPHYR_SDK_VERSION=0.13.2
ZEPHYR_VERSION=v3.1.0
ZEPHYR_DOCKER_VERSION=v0.24.3
ZEPHYR_SDK_VERSION=0.15.0
ZEPHYR_VERSION=v3.2.0

function ci_zephyr_setup {
docker pull zephyrprojectrtos/ci:${ZEPHYR_DOCKER_VERSION}
Expand Down
0