Porting nRF Desktop to Xiao BLE Sense

Hello folks,

Help would be much appreciated. I'm trying to port the nRF Desktop example.

I'll start with the environment.

===== Environment =====

  • Windows 11 Machine (MINGW bash terminal)
  • VSCode 1.86 + NRF Connect for VSCode v2023.11.301
  • Toolchain and SDK for nrfConnect v2.5.0

===== Hardware =====

  • Xiao BLE Sense (nRF52840)

===== Objective =====

  • Port the nRF Desktop example (which works like a charm on the nRF52840dk) to our production board -- the Xiao BLE Sense

This is a large undertaking, and as such, I'm trying to minimize the amount of content that actually GETS ported.

So my simplified objective is:

  • Replicate the nRF Desktop Bluetooth functionality (CAF-custom BLE Bond, State, Adv, Peer Control) minimally on Xiao BLE Sense

===== What I've tried so far =====

I wanted a minimal version of nRF Desktop, so I carefully started paring down the functionality.

  1. I cloned the nrf_desktop sample under the name "mini_desktop" and built it for the nRF52840dk.
  2. I went into prj.conf and gradually disabled KConfig options that were not included in the orange items from my simplified objective.
  3. Checked the build summary (nRF Connect extension tab)
    1. Source files -- the files that were no longer included due to KConfig were removed (placed in temp subdirectory and excluded from CMakeLists)
    2. Config files -- same as above
  4. Went through KConfig options, fragments, and h files from configuration
    1. Temporarily disabled each file, re-enabling any file that caused build faults
  5. Ended up with a significantly smaller build with the following structure

mini_desktop/
┣ configuration/
┃ ┣ common/
┃ ┃ ┣ dev_descr.h
┃ ┃ ┣ hid_keyboard_leds.h
┃ ┃ ┣ hid_keymap.h
┃ ┃ ┣ hid_report_consumer_ctrl.h
┃ ┃ ┣ hid_report_desc.c
┃ ┃ ┣ hid_report_desc.h
┃ ┃ ┣ hid_report_keyboard.h
┃ ┃ ┣ hid_report_mouse.h
┃ ┃ ┣ hid_report_system_ctrl.h
┃ ┃ ┣ hid_report_user_config.h
┃ ┃ ┣ led_state.h
┃ ┃ ┣ port_state.h
┃ ┃ ┗ settings_loader_def.h
┃ ┣ nrf52840dk_nrf52840/
┃ ┃ ┣ app.overlay
┃ ┃ ┣ buttons_def.h
┃ ┃ ┣ click_detector_def.h
┃ ┃ ┣ hid_keyboard_leds_def.h
┃ ┃ ┣ hid_keyboard_leds_def_keyboard.h
┃ ┃ ┣ hid_keymap_def.h
┃ ┃ ┣ hid_keymap_def_keyboard.h
┃ ┃ ┣ led_state_def.h
┃ ┃ ┣ pm_static.yml
┃ ┃ ┣ pm_static_fast_pair.yml
┃ ┃ ┣ pm_static_release.yml
┃ ┃ ┣ port_state_def.h
┃ ┃ ┗ prj.conf
┃ ┗ xiao_ble_sense/
┃   ┣ app.overlay
┃   ┣ buttons_def.h
┃   ┣ click_detector_def.h
┃   ┣ hid_keyboard_leds_def.h
┃   ┣ hid_keyboard_leds_def_keyboard.h
┃   ┣ hid_keymap_def.h
┃   ┣ hid_keymap_def_keyboard.h
┃   ┣ led_state_def.h
┃   ┣ pm_static.yml
┃   ┣ pm_static_fast_pair.yml
┃   ┣ pm_static_release.yml
┃   ┣ port_state_def.h
┃   ┗ prj.conf
┣ dts/
┃ ┗ bindings/
┃   ┗ battery-charger.yaml
┣ src/
┃ ┣ events/
┃ ┃ ┣ battery_event.c
┃ ┃ ┣ battery_event.h
┃ ┃ ┣ ble_dongle_peer_event.c
┃ ┃ ┣ ble_dongle_peer_event.h
┃ ┃ ┣ ble_event.c
┃ ┃ ┣ ble_event.h
┃ ┃ ┣ CMakeLists.txt
┃ ┃ ┣ config_event.c
┃ ┃ ┣ config_event.h
┃ ┃ ┣ cpu_load_event.c
┃ ┃ ┣ cpu_load_event.h
┃ ┃ ┣ hids_event.c
┃ ┃ ┣ hids_event.h
┃ ┃ ┣ hid_event.c
┃ ┃ ┣ hid_event.h
┃ ┃ ┣ Kconfig
┃ ┃ ┣ motion_event.c
┃ ┃ ┣ motion_event.h
┃ ┃ ┣ passkey_event.c
┃ ┃ ┣ passkey_event.h
┃ ┃ ┣ selector_event.c
┃ ┃ ┣ selector_event.h
┃ ┃ ┣ usb_event.c
┃ ┃ ┣ usb_event.h
┃ ┃ ┣ wheel_event.c
┃ ┃ ┗ wheel_event.h
┃ ┣ hw_interface/
┃ ┃ ┣ board.c
┃ ┃ ┣ CMakeLists.txt
┃ ┃ ┣ Kconfig
┃ ┃ ┗ Kconfig.board
┃ ┣ modules/
┃ ┃ ┣ bas.c
┃ ┃ ┣ ble_bond.c
┃ ┃ ┣ CMakeLists.txt
┃ ┃ ┣ dev_descr.c
┃ ┃ ┣ hids.c
┃ ┃ ┣ hid_state.c
┃ ┃ ┣ hid_state_pm.c
┃ ┃ ┣ Kconfig
┃ ┃ ┣ Kconfig.bas
┃ ┃ ┣ Kconfig.ble_bond
┃ ┃ ┣ Kconfig.caf_ble_adv.default
┃ ┃ ┣ Kconfig.caf_ble_state.default
┃ ┃ ┣ Kconfig.caf_power_manager.default
┃ ┃ ┣ Kconfig.caf_settings_loader.default
┃ ┃ ┣ Kconfig.dev_descr
┃ ┃ ┣ Kconfig.hids
┃ ┃ ┣ Kconfig.hid_forward
┃ ┃ ┣ Kconfig.hid_state
┃ ┃ ┣ Kconfig.led_state
┃ ┃ ┗ led_state.c
┃ ┣ util/
┃ ┃ ┣ bt_le_adv_prov_uuid16.c
┃ ┃ ┣ CMakeLists.txt
┃ ┃ ┣ config_channel_transport.c
┃ ┃ ┣ config_channel_transport.h
┃ ┃ ┣ hwid.c
┃ ┃ ┣ hwid.h
┃ ┃ ┗ Kconfig
┃ ┗ main.c
┣ CMakeLists.txt
┣ Kconfig
┣ Kconfig.ble
┣ Kconfig.debug
┣ Kconfig.defaults
┣ Kconfig.hid
┣ nrf_desktop.ld
┣ README.rst
┗ sample.yaml

And the following prj.conf

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
################################################################################
# Application Configuration

# (Leave alone, disabled by default)
CONFIG_DESKTOP_INIT_LOG_MOTION_EVENT=n
CONFIG_DESKTOP_INIT_LOG_HID_REPORT_EVENT=n
CONFIG_DESKTOP_INIT_LOG_HID_REPORT_SENT_EVENT=n
CONFIG_CAF_INIT_LOG_KEEP_ALIVE_EVENTS=n

# Bluetooth role defines
CONFIG_DESKTOP_ROLE_HID_PERIPHERAL=y
CONFIG_DESKTOP_PERIPHERAL_TYPE_MOUSE=y
CONFIG_DESKTOP_DEVICE_PID=0x52DE
CONFIG_DESKTOP_HID_BOOT_INTERFACE_MOUSE=y

# (Disable 01) Motion Buttons
    # CONFIG_DESKTOP_MOTION_BUTTONS_ENABLE=y
    # CONFIG_DESKTOP_MOTION_BUTTONS_UP_KEY_ID=0
    # CONFIG_DESKTOP_MOTION_BUTTONS_DOWN_KEY_ID=3
    # CONFIG_DESKTOP_MOTION_BUTTONS_LEFT_KEY_ID=2
    # CONFIG_DESKTOP_MOTION_BUTTONS_RIGHT_KEY_ID=1

CONFIG_CAF_BUTTONS=y
CONFIG_CAF_BUTTONS_POLARITY_INVERSED=y
CONFIG_CAF_BUTTONS_PM_KEEP_ALIVE=n

CONFIG_CAF_CLICK_DETECTOR=y

CONFIG_CAF_LEDS=y

# (Disable 03) USB
    # CONFIG_DESKTOP_USB_ENABLE=y

CONFIG_DESKTOP_BLE_USE_DEFAULT_ID=y

CONFIG_DESKTOP_BLE_PEER_CONTROL=y
CONFIG_DESKTOP_BLE_PEER_CONTROL_BUTTON=0x0000
CONFIG_DESKTOP_BLE_PEER_ERASE_ON_START=y

# (Disable 04) LOW LATENCY
    # CONFIG_DESKTOP_BLE_SECURITY_FAIL_TIMEOUT_S=10
    # CONFIG_DESKTOP_BLE_LOW_LATENCY_LOCK=y
    # CONFIG_DESKTOP_HFCLK_LOCK_ENABLE=y

# # (Change 06) Manually disabling DESKTOP_LATENCY
# CONFIG_DESKTOP_BLE_LATENCY_ENABLE=n

# (Disable 02) DFU tasks
    # CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE=y
    # CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=y

################################################################################
# Zephyr Configuration

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1536
CONFIG_ISR_STACK_SIZE=1536
CONFIG_MAIN_STACK_SIZE=840
CONFIG_BT_RX_STACK_SIZE=2048
CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
CONFIG_BT_HCI_TX_STACK_SIZE=1536

CONFIG_BOOT_BANNER=n

CONFIG_NUM_COOP_PRIORITIES=10
CONFIG_NUM_PREEMPT_PRIORITIES=11

CONFIG_HEAP_MEM_POOL_SIZE=512

CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
CONFIG_SYSTEM_CLOCK_NO_WAIT=y

CONFIG_HW_STACK_PROTECTION=y
CONFIG_RESET_ON_FATAL_ERROR=n

CONFIG_GPIO=y

CONFIG_REBOOT=y

CONFIG_SPEED_OPTIMIZATIONS=y

CONFIG_PWM=y

CONFIG_LED=y
CONFIG_LED_PWM=y

CONFIG_BT_MAX_PAIRED=2
CONFIG_BT_ID_MAX=3

# (Disable 05) Low Latency reduction part 2
    # CONFIG_BT_CTLR_SDC_LLPM=y
    # CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y
    # CONFIG_BT_CONN_TX_MAX=4

CONFIG_ENTROPY_CC3XX=n



################################################################################
# Assert (Default)
CONFIG_ASSERT=y
CONFIG_ASSERT_LEVEL=2

################################################################################
# Force enable logging (user)
CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3

# Desktop Logging (default)
CONFIG_DESKTOP_LOG=y

# (Value Changed above @Force Enable Logging)
    # CONFIG_SERIAL=n
    # CONFIG_CONSOLE=n
    # CONFIG_UART_CONSOLE=n

################################################################################
# Bootloader Configuration

    # CONFIG_SECURE_BOOT=y
    # CONFIG_BUILD_S1_VARIANT=y
    # CONFIG_FW_INFO=y
    # CONFIG_FW_INFO_FIRMWARE_VERSION=1
    # CONFIG_SB_SIGNING_KEY_FILE="b0_private.pem"


===== Git repository containing mini-desktop =====

As I type this all out, I'm realizing that the easiest thing for me to do would be to provide a link to a git repository.

Here are my current efforts https://github.com/FinnWBiggs/mini_desktop

===== The Problem =====

Building for xiao fails during linking as follows:

[308/316] Linking C executable zephyr\zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
cmd.exe /C "cd . && C:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe  -gdwarf-4 @CMakeFiles\zephyr_pre0.rsp -o zephyr\zephyr_pre0.elf  && cmd.exe /C "cd /D C:\Users\finnb\Documents\auli\mini_desktop\build_xiao\zephyr && C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.exe -E true""
c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr/subsys/random/libsubsys__random.a(rand32_xoshiro128.c.obj): in function `xoshiro128_initialize':
C:/ncs/v2.5.0/zephyr/subsys/random/rand32_xoshiro128.c:51: undefined reference to `__device_dts_ord_101'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

===== Seeking source of problem =====

Exploring the nature of __device_dts_ord_101 leads me to check devicetree_generated.h

Item 101 of that list is /soc/crypto@5002a000, which I can validate exists in my device tree specifications

That node is specified at "C:\ncs\v2.5.0\zephyr\dts\arm\nordic\nrf52840.dtsi" and has the status "okay".

===== Conclusion =====

What should I do to finish porting mini-desktop to the Xiao BLE Sense?

Thank you for any help you can provide

    - Finn

  • Hello Finn,

    Thank you for providing the complete project. When comparing the generated zephyr.dts files for the 'nrf52840dk_nrf52840' and 'xiao_ble_sense' in the build folders, I noticed that they use different entropy sources. The build logs also points to an issue with the RNG configuration.

    Modifying the entropy device in app.overlay enabled me to successfully build your project:

    diff --git a/configuration/xiao_ble_sense/app.overlay b/configuration/xiao_ble_sense/app.overlay
    index 5a7aeed..507cfad 100644
    --- a/configuration/xiao_ble_sense/app.overlay
    +++ b/configuration/xiao_ble_sense/app.overlay
    @@ -11,6 +11,9 @@
     // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
     // You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html
     / {
    +    chosen {
    +        zephyr,entropy = &rng;
    +    };
         aliases {
             // led0 = &led0;
             sw0 = &button0;
    

    Best regards,

    Vidar

  • Hi Vidar,

    Thank you very much! There's still lots to do to get this working but I am very grateful for your help clearing this roadblock and I'm looking forward to it.

    Best,

        - Finn

Related