Hello,
I have a custom board based on the nrf5340 and I am attempting to get bluetooth working.
void ble_gatt_start() { int err; LOG_INF("Starting Ble Gatt Server \n"); err = bt_enable(NULL); if (err) { LOG_ERR("Bluetooth init failed (err %d)\n", err); return; } bt_conn_cb_register(&connection_callbacks); /* Pass application callback functions stored in app_callbacks to the MY LBS service */ err = my_custom_characteristics_init(&app_callbacks); if(err){ LOG_ERR("failed to init Gatt server (err: %d)", err); return; } LOG_INF("Bluetooth initialized\n"); err = bt_le_adv_start(adv_param, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); if (err) { LOG_ERR("Advertising failed to start (err %d)\n", err); return; } LOG_INF("Advertising successfully started\n"); }
The problem lies in the bluetooth initialization step with bt_enable. When I step through the debugger it fails at:
in the bt_enable routine in hci_core.c. No error happens when I check the RTT and the whole debugger just freezes indefinitely.
/* Give cmd_sem allowing to send first HCI_Reset cmd, the only * exception is if the controller requests to wait for an * initial Command Complete for NOP. */ if (!IS_ENABLED(CONFIG_BT_WAIT_NOP)) { k_sem_init(&bt_dev.ncmd_sem, 1, 1); } else { k_sem_init(&bt_dev.ncmd_sem, 0, 1); } k_fifo_init(&bt_dev.cmd_tx_queue); /* TX thread */ k_thread_create(&tx_thread_data, tx_thread_stack, K_KERNEL_STACK_SIZEOF(tx_thread_stack), hci_tx_thread, NULL, NULL, NULL, K_PRIO_COOP(CONFIG_BT_HCI_TX_PRIO), 0, K_NO_WAIT); k_thread_name_set(&tx_thread_data, "BT TX");
What could be the issue?
I am including relevant info from my config and dts files:
prj.conf:
CONFIG_I2C=y CONFIG_BT=y CONFIG_BT_DEVICE_NAME="BT_TEST" CONFIG_PWM=y CONFIG_UART_ASYNC_API=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=y # STEP 12 - Update Data Length and MTU CONFIG_BT_USER_DATA_LEN_UPDATE=y CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 CONFIG_BT_BUF_ACL_RX_SIZE=251 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_L2CAP_TX_MTU=247 CONFIG_BT_HCI=y # Increase stack size for the main thread and System Workqueue CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=16384 CONFIG_MAIN_STACK_SIZE=16384 CONFIG_HW_STACK_PROTECTION=y CONFIG_BT_RX_STACK_SIZE=6000 CONFIG_IDLE_STACK_SIZE=8096 CONFIG_ISR_STACK_SIZE=8096 CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_NRF53_SYNC_RTC=n CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION=y CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_LF_ALWAYS_ON=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n CONFIG_DEBUG=y CONFIG_NO_OPTIMIZATIONS=y
dts:
chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_ns_partition; zephyr,console = &uart2; zephyr,shell-uart = &uart2; zephyr,bt-uart = &uart2; zephyr,bt-mon-uart = &uart2; zephyr,bt-c2h-uart = &uart2; zephyr,bt-hci-ipc = &ipc0; };
defconfig:
CONFIG_SOC_SERIES_NRF53X=y CONFIG_SOC_NRF5340_CPUAPP_QKAA=y CONFIG_BOARD_ATREIDES=y # Enable MPU CONFIG_ARM_MPU=y # Enable hardware stack protection CONFIG_HW_STACK_PROTECTION=y # Enable TrustZone-M CONFIG_ARM_TRUSTZONE_M=y # This Board implies building Non-Secure firmware CONFIG_TRUSTED_EXECUTION_NONSECURE=y # enable GPIO CONFIG_GPIO=y # enable PINCTRL CONFIG_PINCTRL=y # Enable uart driver CONFIG_SERIAL=y # enable console CONFIG_UART_CONSOLE=n CONFIG_CONSOLE=y # Enable RTT CONFIG_USE_SEGGER_RTT=y CONFIG_RTT_CONSOLE=y CONFIG_LOG_BACKEND_RTT=y CONFIG_LOG=y CONFIG_LOG_PRINTK=y CONFIG_PRINTK=y CONFIG_I2C=y CONFIG_SENSOR=y CONFIG_DISK_ACCESS=y CONFIG_LOG=y CONFIG_FILE_SYSTEM=y CONFIG_FAT_FILESYSTEM_ELM=y CONFIG_SPI=y CONFIG_MAIN_STACK_SIZE=16384 CONFIG_DISK_DRIVER_SDMMC=y CONFIG_FS_FATFS_EXFAT=y CONFIG_FS_FATFS_MOUNT_MKFS=y CONFIG_PRINTK=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_NCS_INCLUDE_RPMSG_CHILD_IMAGE=y
I also followed other recommendations from other questions to configure the internal oscillator on the network core by creating a conf file in a child_image folder in my source directory.I had no luck with this as well.