Skip to content

Commit ad53ec5

Browse files
committed
Fix native_sim by adding 1:1 pin mapping
1 parent cbcbafb commit ad53ec5

7 files changed

Lines changed: 55 additions & 14 deletions

File tree

‎ports/zephyr-cp/boards/native/native_sim/board.conf‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# No Bluetooth hardware on native_sim
22
CONFIG_BT=n
33

4+
# native_sim has no physical package: use the identity package pin map so
5+
# pin objects (LED, P_00..P_31) resolve to their GPIO controller.
6+
CONFIG_IOBROKER_PACKAGE_ONE_TO_ONE=y
7+
48
CONFIG_EMUL=y
59
CONFIG_GPIO=y
610
CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=n

‎ports/zephyr-cp/boards/native/native_sim_asan/board.conf‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ CONFIG_ASAN=y
44
# No Bluetooth hardware on native_sim
55
CONFIG_BT=n
66

7+
# native_sim has no physical package: use the identity package pin map so
8+
# pin objects (LED, P_00..P_31) resolve to their GPIO controller.
9+
CONFIG_IOBROKER_PACKAGE_ONE_TO_ONE=y
10+
711
CONFIG_EMUL=y
812
CONFIG_GPIO=y
913
CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=n

‎ports/zephyr-cp/cptools/zephyr2cp.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,9 @@ def zephyr_dts_to_cp_board(board_id, portdir, builddir, zephyrbuilddir, mpconfig
956956
port_indexes[label] = int(match.group(1)) if match else len(port_indexes)
957957
# Package pin map selected through the IOBROKER_PACKAGE choice: map each
958958
# SoC pad to the package pin it is bonded to so that the pin objects can
959-
# hand package pins straight to the iobroker module. When no package
960-
# applies to the SoC (IOBROKER_PACKAGE_NONE) there is no map, so the pin
961-
# objects get IOBROKER_NO_PIN instead.
959+
# hand package pins straight to the iobroker module. The 1:1 choice is an
960+
# identity map (package pin number == global pin number); IOBROKER_PACKAGE_NONE
961+
# has no map, so the pin objects get IOBROKER_NO_PIN instead.
962962
package_pin_of_pad = {}
963963
package_pins = None
964964
package_choice = None
@@ -968,8 +968,16 @@ def zephyr_dts_to_cp_board(board_id, portdir, builddir, zephyrbuilddir, mpconfig
968968
if not stripped.startswith("CONFIG_IOBROKER_PACKAGE_") or not stripped.endswith("=y"):
969969
continue
970970
package_choice = stripped[len("CONFIG_IOBROKER_PACKAGE_") : -len("=y")].lower()
971-
if package_choice == "none":
972-
continue
971+
break
972+
if package_choice == "one_to_one":
973+
# Identity map over the enabled GPIO controllers.
974+
package_pins = []
975+
for ioport in sorted(ioports.keys()):
976+
for num in ioports[ioport]:
977+
global_number = port_indexes[ioport] * 32 + num
978+
package_pins.append({"pin": global_number, "pad": global_number})
979+
package_pin_of_pad[global_number] = global_number
980+
elif package_choice not in (None, "none"):
973981
package_toml = (
974982
pathlib.Path(__file__).resolve().parent.parent
975983
/ "modules"
@@ -983,7 +991,6 @@ def zephyr_dts_to_cp_board(board_id, portdir, builddir, zephyrbuilddir, mpconfig
983991
for package_pin_entry in package_pins:
984992
if "pad" in package_pin_entry:
985993
package_pin_of_pad[package_pin_entry["pad"]] = package_pin_entry["pin"]
986-
break
987994
# Board pin names from circuitpython.toml: ``[pins]`` maps a board module
988995
# name to a package pin number or ball id, resolved to a SoC pad with the
989996
# package pin map above. This is independent of Zephyr's devicetree

‎ports/zephyr-cp/modules/iobroker/Kconfig‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ choice IOBROKER_PACKAGE
1818
help
1919
The module resolves requested package pins to SoC pads through the
2020
package pin map selected here. Reference maps shipped with the module
21-
live in packages/; when none applies to the SoC, the NONE option keeps
22-
the map empty and every package pin lookup fails with -EINVAL.
21+
live in packages/; the ONE_TO_ONE option is an identity map for boards
22+
without a transcribed physical package, and NONE keeps the map empty so
23+
every package pin lookup fails with -EINVAL.
24+
25+
config IOBROKER_PACKAGE_ONE_TO_ONE
26+
bool "1:1 (package pin number is the global pin number)"
27+
help
28+
Identity package pin map: package pin N maps to SoC pad N, where the
29+
SoC pad is the global pin numbering (gpio port index * 32 + pin within
30+
the port). Boards without a transcribed physical package, such as the
31+
native simulator, use this so that pin objects can hand the iobroker
32+
module a package pin that resolves to their pad.
2333

2434
config IOBROKER_PACKAGE_NONE
2535
bool "None (package pin lookups fail)"

‎ports/zephyr-cp/modules/iobroker/Kconfig.packages‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# Choice defaults live here too, most-specific first: the development kits'
99
# packages preselect the reference map for their SoC; boards with more than
1010
# one matching package (e.g. nRF52840 modules) set their choice explicitly in
11-
# board.conf; everything else falls back to NONE so package pin lookups fail
12-
# cleanly.
11+
# board.conf; SoCs with no reference map fall back to the 1:1 identity map
12+
# (package pin number == global pin number), which lets their pins resolve.
1313

1414
config IOBROKER_PACKAGE_NRF54L15_QFN48
1515
bool "nRF54L15/10/05 QFN48 (QFAA)"
@@ -67,5 +67,5 @@ choice IOBROKER_PACKAGE
6767
default IOBROKER_PACKAGE_NRF5340_QKAA if SOC_NRF5340_CPUAPP_QKAA
6868
default IOBROKER_PACKAGE_NRF52840_AQFN73 if SOC_NRF52840_QIAA
6969
default IOBROKER_PACKAGE_RP2040_QFN56 if SOC_RP2040
70-
default IOBROKER_PACKAGE_NONE
70+
default IOBROKER_PACKAGE_ONE_TO_ONE
7171
endchoice

‎ports/zephyr-cp/modules/iobroker/README.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ const uint16_t iobroker_reserved_pads[]; // + _pin_count
5959
The package pin map is selected from the module's reference maps:
6060
`Kconfig.packages` offers one option per transcribed package
6161
(`packages/*.toml`), each visible only for the SoCs it applies to and
62-
preselected for the development kits. When no map applies to a SoC the
63-
`IOBROKER_PACKAGE_NONE` choice is used and an empty map is generated, so
62+
preselected for the development kits. SoCs with no reference map fall back to
63+
`IOBROKER_PACKAGE_ONE_TO_ONE`, an identity map where the package pin number
64+
is the global pin number (gpio port index * 32 + pin within the port), so
65+
boards without a transcribed physical package can still resolve their pins.
66+
`IOBROKER_PACKAGE_NONE` is also available and generates an empty map, making
6467
package pin lookups fail with `-EINVAL`. The selected TOML (or the empty
65-
map) is rendered into a build-directory translation unit at build time.
68+
map) is rendered into a build-directory translation unit at build time. The
69+
identity map needs no rendered table: the core applies it directly.
6670
New maps are transcribed from a SoC datasheet with `tools/gen_package.py`
6771
(see the script's docstring; the datasheets live in `datasheets/`).
6872

‎ports/zephyr-cp/modules/iobroker/src/iobroker.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,39 @@ int iobroker_gpio_split(uint16_t number, const struct device **port_out,
3939
int iobroker_gpio_package_pin(uint8_t port, gpio_pin_t pin,
4040
package_pin_t *package_pin_out) {
4141
uint16_t soc_pad = (uint16_t)((uint32_t)port * 32U + pin);
42+
#if defined(CONFIG_IOBROKER_PACKAGE_ONE_TO_ONE)
43+
// Identity map: the package pin is the global pin number.
44+
*package_pin_out = soc_pad;
45+
return 0;
46+
#else
4247
for (size_t i = 0; i < iobroker_package_pin_count; i++) {
4348
if (iobroker_package_pins[i].soc_pad == soc_pad) {
4449
*package_pin_out = iobroker_package_pins[i].package_pin;
4550
return 0;
4651
}
4752
}
4853
return -EINVAL;
54+
#endif
4955
}
5056

5157
int iobroker_package_pin_soc_pad(package_pin_t pin, uint16_t *soc_pad_out) {
5258
if (pin == IOBROKER_NO_PIN) {
5359
*soc_pad_out = IOBROKER_NO_PIN;
5460
return 0;
5561
}
62+
#if defined(CONFIG_IOBROKER_PACKAGE_ONE_TO_ONE)
63+
// Identity map: the package pin is the global pin number.
64+
*soc_pad_out = pin;
65+
return 0;
66+
#else
5667
for (size_t i = 0; i < iobroker_package_pin_count; i++) {
5768
if (iobroker_package_pins[i].package_pin == pin) {
5869
*soc_pad_out = iobroker_package_pins[i].soc_pad;
5970
return 0;
6071
}
6172
}
6273
return -EINVAL;
74+
#endif
6375
}
6476

6577
#if !IOBROKER_ROUTING

0 commit comments

Comments
 (0)