nRF5340 DK BLE code crashing while integration.

Hi,
I am facing an issue while integrating BLE with the rest of my code. The code crashes when I try to start BLE outside of main().

Currently, I have placed the BLE initialization at the beginning of main(), and it starts and advertises successfully. However, the code crashes during the bonding process.

  • I am using two threads in my application.

I am using nrf5340, 2.6.1 SDK and 2.6.1 toolchain manager.

This are my configuration.

# Enable the UART driver
CONFIG_UART_ASYNC_API=y
# CONFIG_NRFX_UARTE0=y
# CONFIG_SERIAL=y

# Enable GPIO
CONFIG_GPIO=y
CONFIG_LOG_DEFAULT_LEVEL=4

# Configure printk to use UART console
# CONFIG_CONSOLE=y
# CONFIG_UART_CONSOLE=y

# Configure heap memory
CONFIG_HEAP_MEM_POOL_SIZE=8192

# Bluetooth configuration
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="XXXXXXXXXX"
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1

CONFIG_MAIN_STACK_SIZE=8192
CONFIG_BT_RX_STACK_SIZE=4096

# Enable the NUS service
CONFIG_BT_NUS=y

# Enable bonding and settings
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

# Enable DK LED and Buttons library
CONFIG_DK_LIBRARY=y

# Increase stack sizes
CONFIG_MAIN_STACK_SIZE= 12288
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE= 12288

# Configure logging
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_LOG_PRINTK=y

# Enable assertions
CONFIG_ASSERT=y

# Enable Security Management Protocol
CONFIG_BT_SMP=y

# Enable filtering accept list and privacy
CONFIG_BT_FILTER_ACCEPT_LIST=y
CONFIG_BT_PRIVACY=y
CONFIG_BT_SMP_ENFORCE_MITM=y
CONFIG_BT_SMP_SC_ONLY=y  
# enabling this because to disable the legacy paring.

# Enable NUS service authentication
CONFIG_BT_NUS_AUTHEN=y
CONFIG_BT_SMP_APP_PAIRING_ACCEPT=y
CONFIG_BT_ECC=y

# Enable bonding support
CONFIG_BT_BONDABLE=y
CONFIG_BT_GATT_SERVICE_CHANGED=y



CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251


CONFIG_BT_DATA_LEN_UPDATE=y




# Enable nordic security backend and PSA APIs
CONFIG_NRF_SECURITY=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y

CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE= 12288

CONFIG_PSA_WANT_GENERATE_RANDOM=y
CONFIG_PSA_WANT_KEY_TYPE_AES=y
CONFIG_PSA_WANT_ALG_CBC_NO_PADDING=y






CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
###########################################

CONFIG_I2C=y


CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_AUTO=y

CONFIG_FPU=y
CONFIG_FP_HARDABI=y



######################################
# power management....
CONFIG_POWEROFF=y

CONFIG_PM=n

CONFIG_BT_CTLR_LOW_LAT=n
# CONFIG_BT_LL_SOFT=n
CONFIG_BT_LL_SW_SPLIT=y

CONFIG_CLOCK_CONTROL=y
CONFIG_CLOCK_CONTROL_NRF=y
# CONFIG_BT_CTLR_CLOCK_CONTROL=y

CONFIG_INIT_STACKS=y
CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_AUTO=y

CONFIG_FAULT_DUMP=2
# CONFIG_BT_LOG_LEVEL=4


this is BLE start code 

int BLE_Start()
{
    int err;

    err = bt_enable(NULL);
    if (err) {
        LOG_ERR("Bluetooth initialization failed (err: %d)", err);
        return err;
    }
    LOG_INF("Bluetooth initialized");

    err = bt_nus_init(&nus_cb);
    if (err) {
        LOG_ERR("Failed to initialize NUS service (err: %d)", err);
        return err;
    }
    LOG_INF("NUS service initialized");

    bt_conn_cb_register(&connection_callbacks);
    bt_conn_auth_cb_register(&conn_auth_callbacks);
    bt_conn_auth_info_cb_register(&conn_auth_callbacks_info);
    LOG_INF("Bluetooth callbacks registered");

    if (IS_ENABLED(CONFIG_SETTINGS)) {
        err = settings_load();
        if (err) {
            LOG_ERR("Settings load failed (err: %d)", err);
            return err;
        }
        LOG_INF("Settings loaded");
    }

    return 0;
}


Please help me resolve this issue, as I am in the final stage of my project completion!

Parents
  • Hi!

    The code crashes when I try to start BLE outside of main().
    Currently, I have placed the BLE initialization at the beginning of main(), and it starts and advertises successfully. However, the code crashes during the bonding process.

    So you are seeing 2 different crashes.

    Could you post the crash info for this? Any log output, etc that shows this?

  • Hi,

    In the first case, when BLE is initialized outside main(), the logs stop without any error.

    In the second case, during the bonding process, after entering the BLE-generated passcode, the bonding completes on the application side but not on the controller side. At this point, the logs stop without any error.

Reply Children
Related