Skip to content

Commit 57e436d

Browse files
committed
I2C configures on H20
1 parent b53a259 commit 57e436d

7 files changed

Lines changed: 69 additions & 10 deletions

File tree

ports/zephyr-cp/boards/nordic/nrf54h20dk/autogen_board_info.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ sharpdisplay = false
8989
socketpool = false
9090
spitarget = false
9191
ssl = false
92-
storage = false
92+
storage = true # Zephyr board has flash
9393
struct = true
9494
supervisor = false
9595
synthio = false
@@ -110,7 +110,7 @@ vectorio = false
110110
warnings = false
111111
watchdog = false
112112
wifi = false
113-
zephyr_i2c = false
113+
zephyr_i2c = true # Zephyr board has zephyr_i2c
114114
zephyr_kernel = false
115115
zephyr_serial = true # Zephyr board has zephyr_serial
116116
zlib = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE=4096
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
&gpio6 {
2+
status = "okay";
3+
zephyr,pm-device-runtime-auto;
4+
};
5+
6+
&exmif {
7+
status = "okay";
8+
zephyr,pm-device-runtime-auto;
9+
};
10+
11+
&mx25uw63 {
12+
status = "okay";
13+
};
14+
15+
/*
16+
* SDA = P2.11
17+
* SCL = P2.10
18+
*/
19+
20+
&pinctrl {
21+
i2c130_default: i2c130_default {
22+
group1 {
23+
psels = <NRF_PSEL(TWIM_SDA, 2, 11)>,
24+
<NRF_PSEL(TWIM_SCL, 2, 10)>;
25+
};
26+
};
27+
28+
i2c130_sleep: i2c130_sleep {
29+
group1 {
30+
psels = <NRF_PSEL(TWIM_SDA, 2, 11)>,
31+
<NRF_PSEL(TWIM_SCL, 2, 10)>;
32+
low-power-enable;
33+
};
34+
};
35+
};
36+
37+
&i2c130 {
38+
clock-frequency = <I2C_BITRATE_STANDARD>;
39+
pinctrl-0 = <&i2c130_default>;
40+
pinctrl-1 = <&i2c130_sleep>;
41+
pinctrl-names = "default", "sleep";
42+
zephyr,concat-buf-size = <256>;
43+
memory-regions = <&cpuapp_dma_region>;
44+
status = "okay";
45+
};
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
&mx25um51245g {
2-
/delete-node/ partitions;
3-
};

ports/zephyr-cp/common-hal/zephyr_i2c/I2C.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/device.h>
13+
#include <zephyr/kernel.h>
1314

1415
void common_hal_zephyr_i2c_i2c_construct(zephyr_i2c_i2c_obj_t *self,
1516
const struct device *i2c_device, uint32_t frequency, uint32_t timeout) {
@@ -21,17 +22,20 @@ void common_hal_zephyr_i2c_i2c_construct(zephyr_i2c_i2c_obj_t *self,
2122
// Configure I2C speed
2223
uint32_t i2c_cfg = I2C_MODE_CONTROLLER;
2324
if (frequency <= 100000) {
24-
i2c_cfg |= I2C_SPEED_STANDARD;
25+
i2c_cfg |= I2C_SPEED_SET(I2C_SPEED_STANDARD);
2526
} else if (frequency <= 400000) {
26-
i2c_cfg |= I2C_SPEED_FAST;
27+
i2c_cfg |= I2C_SPEED_SET(I2C_SPEED_FAST);
2728
} else if (frequency <= 1000000) {
28-
i2c_cfg |= I2C_SPEED_FAST_PLUS;
29+
i2c_cfg |= I2C_SPEED_SET(I2C_SPEED_FAST_PLUS);
2930
} else {
30-
i2c_cfg |= I2C_SPEED_HIGH;
31+
i2c_cfg |= I2C_SPEED_SET(I2C_SPEED_HIGH);
3132
}
3233

3334
int ret = i2c_configure(i2c_device, i2c_cfg);
3435
if (ret != 0) {
36+
printk("Device: %s\n", i2c_device->name);
37+
printk("Device address: %08x\n", i2c_device);
38+
printk("I2C configuration failed: %d\n", ret);
3539
mp_raise_OSError_msg(MP_ERROR_TEXT("I2C configuration failed"));
3640
}
3741
}

ports/zephyr-cp/cptools/zephyr2cp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# GPIO flags defined here: include/zephyr/dt-bindings/gpio/gpio.h
1313
GPIO_ACTIVE_LOW = 1 << 0
1414

15+
MINIMUM_RAM_SIZE = 1024
16+
1517
MANUAL_COMPAT_TO_DRIVER = {
1618
"renesas_ra_nv_flash": "flash",
1719
"nordic_nrf_uarte": "serial",
@@ -266,10 +268,15 @@ def zephyr_dts_to_cp_board(portdir, builddir, zephyrbuilddir): # noqa: C901
266268
if "compatible" in node.props:
267269
compatible = node.props["compatible"].to_strings()
268270
logger.debug(f"{node.name}: {status}")
271+
logger.debug(f"compatible: {compatible}")
269272
chosen = None
270273
if node in path2chosen:
271274
chosen = path2chosen[node]
272275
logger.debug(f" chosen: {chosen}")
276+
if not compatible and chosen == "zephyr,sram":
277+
# The designated sram region may not have any compatible properties,
278+
# so we assume it is compatible with mmio
279+
compatible.append("mmio")
273280
for c in compatible:
274281
underscored = c.replace(",", "_").replace("-", "_")
275282
driver = COMPAT_TO_DRIVER.get(underscored, None)
@@ -296,7 +303,8 @@ def zephyr_dts_to_cp_board(portdir, builddir, zephyrbuilddir): # noqa: C901
296303
info = (node.labels[0], start, end, size, node.path)
297304
if chosen == "zephyr,sram":
298305
rams.insert(0, info)
299-
elif status == "okay":
306+
elif status == "okay" and size > MINIMUM_RAM_SIZE:
307+
logger.debug(f"Adding RAM info: {info}")
300308
rams.append(info)
301309
if not driver:
302310
driver = MANUAL_COMPAT_TO_DRIVER.get(underscored, None)

ports/zephyr-cp/supervisor/flash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ void supervisor_flash_init(void) {
111111
const struct device *d = flashes[i];
112112

113113
printk("flash %p %s\n", d, d->name);
114+
if (!device_is_ready(d)) {
115+
printk(" not ready\n");
116+
continue;
117+
}
114118
if (covered_by_areas[i]) {
115119
printk(" covered by flash area\n");
116120
continue;

0 commit comments

Comments
 (0)