ports/zephyr fails to compile with CONFIG_BT=y : 'CONFIG_BT_DEVICE_NAME_MAX' undeclared
Port, board and/or hardware
nRF52840 Dongle
MicroPython version
micropython 1.27.0 or master: build is zephyr on Ubuntu 24.04.
Reproduction
I am trying to bring up the zephyr port on the nRF52840 dongle (which is supported by Zephyr: the similar nRF52840DK is supported by both zephyr and micropython's zephyr port). If I build micropython with default kernel config as per the instructions (west build -p always -b nrf52840dongle micropython/ports/zephyr, with no ports/zephyr/boards/nrf52840dongle.conf present) then the build is fine and completes, and works when flashed to the device. However, when I turn bluetooth on (by creating ports/zephyr/boards/nrf52840dongle.conf with CONFIG_BT=y in it) and build again with the same command, the build fails, with a bunch of compilation errors to do with missing symbols and the like, as listed below
Expected behaviour
No response
Observed behaviour
end section of the build log (project name shortened to <myproject> just to keep the line lengths down!)
[466/476] Building C object CMakeFiles/micropython.dir/modbluetooth_zephyr.c.obj
FAILED: CMakeFiles/micropython.dir/modbluetooth_zephyr.c.obj
ccache <myproject>/zephyrproject/zephyr/zephyr-sdk-latest/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DFFCONF_H=\"<myproject>/micropython/ports/zephyr/../../lib/oofatfs/ffconf.h\" -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DMICROPY_BOARD_BUILD_NAME=\"ZEPHYR_NRF52840DONGLE\" -DMICROPY_HEAP_SIZE=49152 -DMICROPY_VFS_FAT=1 -DMICROPY_VFS_LFS1=0 -DMICROPY_VFS_LFS2=1 -DMP_CONFIGFILE="<mpconfigport.h>" -DNDEBUG -DNRF52840_XXAA -DNRF54L_CONFIGURATION_56_ENABLE=0 -DPICOLIBC_DOUBLE_PRINTF_SCANF -D_POSIX_THREAD_SAFE_FUNCTIONS=200809L -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -I<myproject>/micropython/ports/zephyr/../.. -I<myproject>/micropython/ports/zephyr -I<myproject>/zephyrproject/zephyr/build -I<myproject>/zephyrproject/zephyr/include -I<myproject>/zephyrproject/zephyr/build/zephyr/include/generated -I<myproject>/zephyrproject/zephyr/soc/nordic -I<myproject>/zephyrproject/zephyr/lib/libc/picolibc/include -I<myproject>/zephyrproject/zephyr/lib/posix/c_lib_ext/getopt -I<myproject>/zephyrproject/zephyr/soc/nordic/nrf52/. -I<myproject>/zephyrproject/zephyr/soc/nordic/common/. -I<myproject>/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/nrfx_glue -I<myproject>/zephyrproject/zephyr/subsys/bluetooth -I<myproject>/zephyrproject/zephyr/drivers/usb/common/nrf_usbd_common/. -I<myproject>/zephyrproject/modules/hal/cmsis_6/CMSIS/Core/Include -I<myproject>/zephyrproject/zephyr/modules/cmsis_6/. -I<myproject>/zephyrproject/modules/hal/nordic/nrfx -I<myproject>/zephyrproject/modules/hal/nordic/nrfx/drivers/include -I<myproject>/zephyrproject/modules/hal/nordic/nrfx/bsp/stable -I<myproject>/zephyrproject/modules/hal/nordic/nrfx/bsp/stable/templates -I<myproject>/zephyrproject/zephyr/modules/hal_nordic/nrfx/. -isystem <myproject>/zephyrproject/zephyr/lib/libc/common/include -fno-strict-aliasing -Os -imacros <myproject>/zephyrproject/zephyr/build/zephyr/include/generated/zephyr/autoconf.h -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mfp16-format=ieee -mtp=soft --sysroot=<myproject>/zephyrproject/zephyr/zephyr-sdk-latest/arm-zephyr-eabi/arm-zephyr-eabi -imacros <myproject>/zephyrproject/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=<myproject>/micropython/ports/zephyr=CMAKE_SOURCE_DIR -fmacro-prefix-map=<myproject>/zephyrproject/zephyr=ZEPHYR_BASE -fmacro-prefix-map=<myproject>/zephyrproject=WEST_TOPDIR -ffunction-sections -fdata-sections -specs=picolibc.specs -std=c17 -std=gnu99 -fomit-frame-pointer -MD -MT CMakeFiles/micropython.dir/modbluetooth_zephyr.c.obj -MF CMakeFiles/micropython.dir/modbluetooth_zephyr.c.obj.d -o CMakeFiles/micropython.dir/modbluetooth_zephyr.c.obj -c <myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c: In function 'mp_bluetooth_gap_set_device_name':
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:367:18: error: 'CONFIG_BT_DEVICE_NAME_MAX' undeclared (first use in this function); did you mean 'CONFIG_BT_DEVICE_NAME'?
367 | char tmp_buf[CONFIG_BT_DEVICE_NAME_MAX + 1];
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| CONFIG_BT_DEVICE_NAME
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:367:18: note: each undeclared identifier is reported only once for each function it appears in
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:367:10: warning: unused variable 'tmp_buf' [-Wunused-variable]
367 | char tmp_buf[CONFIG_BT_DEVICE_NAME_MAX + 1];
| ^~~~~~~
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c: In function 'mp_bluetooth_gap_advertise_start':
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:412:35: error: 'BT_LE_ADV_OPT_CONNECTABLE' undeclared (first use in this function); did you mean 'BT_LE_ADV_OPT_SCANNABLE'?
412 | .options = (connectable ? BT_LE_ADV_OPT_CONNECTABLE : 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| BT_LE_ADV_OPT_SCANNABLE
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:413:15: error: 'BT_LE_ADV_OPT_ONE_TIME' undeclared (first use in this function); did you mean 'BT_LE_ADV_OPT_NO_2M'?
413 | | BT_LE_ADV_OPT_ONE_TIME
| ^~~~~~~~~~~~~~~~~~~~~~
| BT_LE_ADV_OPT_NO_2M
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c: In function 'mp_bluetooth_gap_set_device_name':
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:374:1: warning: control reaches end of non-void function [-Wreturn-type]
374 | }
| ^
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c: At top level:
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:979:13: warning: 'add_descriptor' defined but not used [-Wunused-function]
979 | static void add_descriptor(struct bt_gatt_attr *chrc, struct add_descriptor *d, struct bt_gatt_attr *attr_desc) {
| ^~~~~~~~~~~~~~
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:921:13: warning: 'add_characteristic' defined but not used [-Wunused-function]
921 | static void add_characteristic(struct add_characteristic *ch, struct bt_gatt_attr *attr_chrc, struct bt_gatt_attr *attr_value) {
| ^~~~~~~~~~~~~~~~~~
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:907:13: warning: 'add_service' defined but not used [-Wunused-function]
907 | static void add_service(const struct bt_uuid *u, struct bt_gatt_attr *attr) {
| ^~~~~~~~~~~
<myproject>/micropython/ports/zephyr/modbluetooth_zephyr.c:869:24: warning: 'create_zephyr_uuid' defined but not used [-Wunused-function]
869 | static struct bt_uuid *create_zephyr_uuid(const mp_obj_bluetooth_uuid_t *uuid) {
| ^~~~~~~~~~~~~~~~~~
[468/476] Building C object CMakeFiles/micropy...ini_zephyr/micropython/lib/littlefs/lfs2.c.obj
<myproject>/micropython/lib/littlefs/lfs2.c:508:13: warning: 'lfs2_mlist_isopen' defined but not used [-Wunused-function]
508 | static bool lfs2_mlist_isopen(struct lfs2_mlist *head,
| ^~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build <myproject>/zephyrproject/zephyr/build
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
zephyr: Use Kconfig to configure MicroPython options.
The zephyr port uses Kconfig to enable/disable and configure zephyr
kernel features at build time, such as peripheral drivers, networking,
and usb. Extend the Kconfig infrastructure to include MicroPython
options in mpconfigport.h.
This allows us to combine mpconfigport.h and mpconfigport_minimal.h into
one file, and to configure zephyr and MicroPython options together in
one place. Before this change, it was difficult to enable the
MicroPython machine.i2c class for only boards that have the zephyr i2c
driver enabled. After this change, we can now enable the class in the
same place we enable the driver. For example, in
ports/zephyr/boards/frdm_k64f.conf:
CONFIG_I2C=y
CONFIG_MICROPY_PY_MACHINE_I2C=y
This change also allows us to configure MicroPython options with menuconfig.
Kconfig options are currently added only for MicroPython options that
were explicitly configured in zephyr's mpconfigport.h or
mpconfigport_minimal.h; others can be added in the future for further
refinement. Most options are implicitly default n to optimize for code
size. Those that are default y were previously enabled in both
mpconfigport.h and mpconfigport_minimal.h.
To verify that the MicroPython configuration hasn't changed after moving
options to Kconfig, we can compare flash sizes before and after this
commit, using the zephyr sdk 0.11.3 toolchain and zephyr v2.3.0:
| Before | After | |
|---|---|---|
$ ./make-minimal BOARD=frdm_k64f |
122300 B | 122328 B |
$ make BOARD=frdm_k64f |
239652 B | 239652 B |
The small increase in the minimal configuration is due to the fact that
it now includes the builtin open object.
Signed-off-by: Maureen Helm maureen.helm@nxp.com
$ make BOARD=frdm_k64f menuconfig


