8000 zephyr: Upgrade to Zephyr v3.7.0. by MaureenHelm · Pull Request #9335 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

zephyr: Upgrade to Zephyr v3.7.0. #9335

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 11 commits into from
Oct 3, 2024
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
9 changes: 9 additions & 0 deletions .github/workflows/ports_zephyr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: jlumbroso/free-disk-space@main
with:
# Only free up a few things so this step runs quickly.
android: false
dotnet: true
haskell: true
large-packages: false
docker-images: false
swap-storage: false
- uses: actions/checkout@v4
- name: Install packages
run: source tools/ci.sh && ci_zephyr_setup
Expand Down
20 changes: 10 additions & 10 deletions docs/zephyr/quickref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Use the :ref:`machine.Pin <machine.Pin>` class::

from machine import Pin

pin = Pin(("GPIO_1", 21), Pin.IN) # create input pin on GPIO1
pin = Pin(("gpiob", 21), Pin.IN) # create input pin on GPIO port B
print(pin) # print pin port and number

pin.init(Pin.OUT, Pin.PULL_UP, value=1) # reinitialize pin
Expand All @@ -47,14 +47,14 @@ Use the :ref:`machine.Pin <machine.Pin>` class::
pin.on() # set pin to high
pin.off() # set pin to low

pin = Pin(("GPIO_1", 21), Pin.IN) # create input pin on GPIO1
pin = Pin(("gpiob", 21), Pin.IN) # create input pin on GPIO port B

pin = Pin(("GPIO_1", 21), Pin.OUT, value=1) # set pin high on creation
pin = Pin(("gpiob", 21), Pin.OUT, value=1) # set pin high on creation

pin = Pin(("GPIO_1", 21), Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor
pin = Pin(("gpiob", 21), Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor

switch = Pin(("GPIO_2", 6), Pin.IN) # create input pin for a switch
switch.irq(lambda t: print("SW2 changed")) # enable an interrupt when switch state is changed
switch = Pin(("gpioc", 6), Pin.IN) # create input pin for a switch
switch.irq(lambda t: print("SW2 changed")) # enable an interrupt when switch state is changed

Hardware I2C bus
----------------
Expand All @@ -63,7 +63,7 @@ Hardware I2C is accessed via the :ref:`machine.I2C <machine.I2C>` class::

from machine import I2C

i2c = I2C("I2C_0") # construct an i2c bus
i2c = I2C("i2c0") # construct an i2c bus
print(i2c) # print device name

i2c.scan() # scan the device for available I2C slaves
Expand All @@ -84,11 +84,11 @@ Hardware SPI is accessed via the :ref:`machine.SPI <machine.SPI>` class::

from machine import SPI

spi = SPI("SPI_0") # construct a spi bus with default configuration
spi = SPI("spi0") # construct a spi bus with default configuration
spi.init(baudrate=100000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB) # set configuration

# equivalently, construct spi bus and set configuration at the same time
spi = SPI("SPI_0", baudrate=100000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB)
spi = SPI("spi0", baudrate=100000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB)
print(spi) # print device name and bus configuration

spi.read(4) # read 4 bytes on MISO
Expand Down Expand Up @@ -146,7 +146,7 @@ Use the :ref:`zsensor.Sensor <zsensor.Sensor>` class to access sensor data::
import zsensor
from zsensor import Sensor

accel = Sensor("FXOX8700") # create sensor object for the accelerometer
accel = Sensor("fxos8700") # create sensor object for the accelerometer

accel.measure() # obtain a measurement reading from the accelerometer

Expand Down
4 changes: 2 additions & 2 deletions docs/zephyr/tutorial/repl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ 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 zephyr-v3.1.0 ***
MicroPython v1.19.1-9-g4fd54a475 on 2022-06-17; zephyr-frdm_k64f with mk64f12
*** Booting Zephyr OS build v3.7.0 ***
MicroPython v1.24.0-preview.179.g5b85b24bd on 2024-08-05; zephyr-frdm_k64f with mk64f12
Type "help()" for more information.
>>>

Expand Down
1 change: 1 addition & 0 deletions ports/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set(MICROPY_SOURCE_PORT
modzsensor.c
mphalport.c
uart_core.c
zephyr_device.c
zephyr_storage.c
mpthreadport.c
)
Expand Down
26 changes: 13 additions & 13 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.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).
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.7.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.7.0
$ west update

With Zephyr installed you may then need to configure your environment,
Expand Down Expand Up @@ -107,26 +107,26 @@ To blink an LED:
import time
from machine import Pin

LED = Pin(("GPIO_1", 21), Pin.OUT)
LED = Pin(("gpiob", 21), Pin.OUT)
while True:
LED.value(1)
time.sleep(0.5)
LED.value(0)
time.sleep(0.5)

The above code uses an LED location for a FRDM-K64F board (port B, pin 21;
following Zephyr conventions port are identified by "GPIO_x", where *x*
starts from 0). You will need to adjust it for another board (using board's
reference materials). To execute the above sample, copy it to clipboard, in
MicroPython REPL enter "paste mode" using Ctrl+E, paste clipboard, press
Ctrl+D to finish paste mode and start execution.
following Zephyr conventions port are identified by their devicetree node
label. You will need to adjust it for another board (using board's reference
materials). To execute the above sample, copy it to clipboard, in MicroPython
REPL enter "paste mode" using Ctrl+E, paste clipboard, press Ctrl+D to finish
paste mode and start execution.

To respond to Pin change IRQs, on a FRDM-K64F board run:

from machine import Pin

SW2 = Pin(("GPIO_2", 6), Pin.IN)
SW3 = Pin(("GPIO_0", 4), Pin.IN)
SW2 = Pin(("gpioc", 6), Pin.IN)
SW3 = Pin(("gpioa", 4), Pin.IN)

SW2.irq(lambda t: print("SW2 changed"))
SW3.irq(lambda t: print("SW3 changed"))
Expand All @@ -138,14 +138,14 @@ Example of using I2C to scan for I2C slaves:

from machine import I2C

i2c = I2C("I2C_0")
i2c = I2C("i2c0")
i2c.scan()

Example of using SPI to write a buffer to the MOSI pin:

from machine import SPI

spi = SPI("SPI_0")
spi = SPI("spi0")
spi.init(baudrate=500000, polarity=1, phase=1, bits=8, firstbit=SPI.MSB)
spi.write(b'abcd')

Expand Down
10 changes: 3 additions & 7 deletions ports/zephyr/machine_i2c.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/i2c.h>

#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "py/mperrno.h"
#include "extmod/modmachine.h"
#include "zephyr_device.h"

#if MICROPY_PY_MACHINE_I2C

Expand Down Expand Up @@ -64,12 +65,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

const char *dev_name = mp_obj_str_get_str(args[ARG_id].u_obj);
const struct device *dev = device_get_binding(dev_name);

if (dev == NULL) {
mp_raise_ValueError(MP_ERROR_TEXT("device not found"));
}
const struct device *dev = zephyr_device_find(args[ARG_id].u_obj);

if ((args[ARG_scl].u_obj != MP_OBJ_NULL) || (args[ARG_sda].u_obj != MP_OBJ_NULL)) {
mp_raise_NotImplementedError(MP_ERROR_TEXT("explicit choice of scl/sda is not implemented"));
Expand Down
9 changes: 3 additions & 6 deletions ports/zephyr/machine_pin.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/gpio.h>

#include "py/runtime.h"
Expand All @@ -38,6 +38,7 @@
#include "extmod/modmachine.h"
#include "shared/runtime/mpirq.h"
#include "modmachine.h"
#include "zephyr_device.h"

#if MICROPY_PY_MACHINE

Expand Down Expand Up @@ -131,12 +132,8 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
}
mp_obj_t *items;
mp_obj_get_array_fixed_n(args[0], 2, &items);
const char *drv_name = mp_obj_str_get_str(items[0]);
const struct device *wanted_port = zephyr_device_find(items[0]);
int wanted_pin = mp_obj_get_int(items[1]);
const struct device *wanted_port = device_get_binding(drv_name);
if (!wanted_port) {
mp_raise_ValueError(MP_ERROR_TEXT("invalid port"));
}

machine_pin_obj_t *pin = m_new_obj(machine_pin_obj_t);
pin->base = machine_pin_obj_template;
Expand Down
14 changes: 5 additions & 9 deletions ports/zephyr/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
#include <stdint.h>
#include <string.h>

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

#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "py/mperrno.h"
#include "extmod/modmachine.h"
#include "zephyr_device.h"

#if MICROPY_PY_MACHINE_SPI

Expand Down Expand Up @@ -81,12 +82,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

const char *dev_name = mp_obj_str_get_str(args[ARG_id].u_obj);
const struct device *dev = device_get_binding(dev_name);

if (dev == NULL) {
mp_raise_ValueError(MP_ERROR_TEXT("device not found"));
}
const struct device *dev = zephyr_device_find(args[ARG_id].u_obj);

if ((args[ARG_sck].u_obj != MP_OBJ_NULL) || (args[ARG_miso].u_obj != MP_OBJ_NULL) || (args[ARG_mosi].u_obj != MP_OBJ_NULL)) {
mp_raise_NotImplementedError(MP_ERROR_TEXT("explicit choice of sck/miso/mosi is not implemented"));
Expand All @@ -102,7 +98,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
args[ARG_bits].u_int << 5 |
SPI_LINES_SINGLE),
.slave = 0,
.cs = NULL
.cs = {},
};

machine_hard_spi_obj_t *self = mp_obj_malloc(machine_hard_spi_obj_t, &machine_spi_type);
Expand Down Expand Up @@ -157,7 +153,7 @@ static void machine_hard_spi_init(mp_obj_base_t *obj, size_t n_args, const mp_ob
.frequency = baudrate,
.operation = operation,
.slave = 0,
.cs = NULL
.cs = {},
};

self->config = cfg;
Expand Down
8 changes: 3 additions & 5 deletions ports/zephyr/machine_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
// This file is never compiled standalone, it's included directly from
// extmod/machine_uart.c via MICROPY_PY_MACHINE_UART_INCLUDEFILE.

< 1241 span class='blob-code-inner blob-code-marker js-skip-tagsearch' data-code-marker="-">#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>

#include "py/mperrno.h"
#include "zephyr_device.h"

// The UART class doesn't have any constants for this port.
#define MICROPY_PY_MACHINE_UART_CLASS_CONSTANTS
Expand Down Expand Up @@ -75,10 +76,7 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);

machine_uart_obj_t *self = mp_obj_malloc(machine_uart_obj_t, &machine_uart_type);
self->dev = device_get_binding(mp_obj_str_get_str(args[0]));
if (!self->dev) {
mp_raise_ValueError(MP_ERROR_TEXT("Bad device name"));
}
self->dev = zephyr_device_find(args[0]);

mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
Expand Down
6 changes: 3 additions & 3 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 @@ -100,8 +100,8 @@ static void vfs_init(void) {
mp_obj_t args[] = { mp_obj_new_str_from_cstr(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)
mp_obj_t args[] = { MP_OBJ_NEW_SMALL_INT(FLASH_AREA_ID(storage)), MP_OBJ_NEW_SMALL_INT(4096) };
#elif defined(CONFIG_FLASH_MAP) && FIXED_PARTITION_EXISTS(storage_partition)
mp_obj_t args[] = { MP_OBJ_NEW_SMALL_INT(FIXED_PARTITION_ID(storage_partition)), 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";
#endif
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/modsocket.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/modtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* THE SOFTWARE.
*/

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

#include "py/obj.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
8 changes: 3 additions & 5 deletions ports/zephyr/modzsensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

#include "py/runtime.h"

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

#if MICROPY_PY_ZSENSOR

Expand All @@ -41,10 +42,7 @@ typedef struct _mp_obj_sensor_t {
static mp_obj_t sensor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
mp_obj_sensor_t *o = mp_obj_malloc(mp_obj_sensor_t, type);
o->dev = device_get_binding(mp_obj_str_get_str(args[0]));
if (o->dev == NULL) {
mp_raise_ValueError(MP_ERROR_TEXT("dev not found"));
}
o->dev = zephyr_device_find(args[0]);
return MP_OBJ_FROM_PTR(o);
}

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
Loading
Loading
0