← index #18820PR #15467
Off-topic · high · value 4.125
QUERY · ISSUE

ports/zephyr fails to compile with CONFIG_BT=y : 'CONFIG_BT_DEVICE_NAME_MAX' undeclared

openby stuartlangridgeopened 2026-02-15updated 2026-02-25
bugport-zephyr

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

CANDIDATE · PULL REQUEST

ports/zephyr: Add threading support on the nrf52840DK.

mergedby danicamporaopened 2024-07-15updated 2024-09-06
port-zephyr

This PR attempts to implement the _thread module on the Zephyr port. Three important remarks about this PR:

  1. Due to the fact that we are still using a rather old version of Zephyr, CONFIG_DYNAMIC_THREAD is not available and therefore the stack for threads cannot be allocated dynamically, only at compile time. So for the time being and for the purpose of these PR, a maximum of 4 Zephyr threads (besides the main thread) can be created. Once we manage to update to the latest version of Zephyr this won't be a problem anymore.

  2. For some reason, threads get blocked forever before calling mp_thread_start(); inside thread_entry() (see modthread.c, line 174), because MP_THREAD_GIL_ENTER() never returns. I'm unable to understand why this is happening, since this implementation of mpthreadport for the Zephyr port is following the same approach used by the ESP32 port. I suspect there's some kind of incompatibility with the rest of the Micropython options enabled for the Zephyr port, and I hope that @dpgeorge can shed some light in here. For this reason MICROPY_PY_THREAD_GIL is disabled at the moment. This obviously needs to be fixed before this PR is merged.

  3. Some of the tests in the tests/thread folder run successfully, and some other don't most likely because MICROPY_PY_THREAD_GIL is not enabled.

A simple test that runs OK:

import _thread
import time

def thread_entry(num):
    for i in range(3):
        time.sleep(1 + (num * 0.5))
        print("Thread {} running...".format(num))

_thread.start_new_thread(thread_entry, (0,))
_thread.start_new_thread(thread_entry, (1,))
_thread.start_new_thread(thread_entry, (2,))
_thread.start_new_thread(thread_entry, (3,))

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied