This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

CLI_BLE_UART fails initialization

I'm trying to add BLE_UART functionality to a custom board, on top of the already existing USB (and working) USB_CDC CLI. I'm using SDK 15.3.0 and softdevice S340

I used as a starting point the ble_app_cli_pca10056_s140 example from the SDK (experimental), but without using task_manager

The relevant parts of my code are as follows ([...] represents code that is not relevant)

NRF_CLI_CDC_ACM_DEF(m_cli_cdc_acm_transport);
NRF_CLI_DEF(m_cli_cdc_acm, "usb_cli:~$ ", &m_cli_cdc_acm_transport.transport, '\r', 4);

NRF_CLI_BLE_UART_DEF(cli_ble_uart, &m_gatt, 64, 32);
NRF_CLI_DEF(m_ble_cli, "cli_ble:~$ ", &cli_ble_uart.transport, '\r', 8);

[...]

int main(void)
{

[...]

    APP_ERROR_CHECK(nrf_cli_init(&m_cli_cdc_acm, NULL, true, true, NRF_LOG_SEVERITY_INFO));
    APP_ERROR_CHECK(nrf_cli_ble_uart_service_init());	
	APP_ERROR_CHECK(nrf_cli_start(&m_cli_cdc_acm));
	
    // Enter main loop.
    for (;;)
    {    [...] }
}

Finally, I added the CLI_BLE_UART initialization inside ble_evt_handler() as follows

        case BLE_GAP_EVT_CONNECTED:
            [...]
            nrf_cli_ble_uart_config_t config = { .conn_handle = m_conn_handle };
            err_code = nrf_cli_init(&m_ble_cli, &config, true, true, NRF_LOG_SEVERITY_INFO);

nrf_cli_init() fails. I followed the calls and the stack sequence is

cli_ble_uart_init() --- blcm_link_ctx_get() --- ble_conn_state_conn_idx() --- ble_conn_state_valid() --- nrf_atflags_get() which returns false, causing every function in sequence to return an error

In order to make everything work up to this point, I had to make a few changes to sdk_config.h, both enabling modules and increasing the Gatt attribute table and VS count, since the existing application already has 3 VS UUIDs and needed a bigger table

#define NRF_CLI_BLE_UART_ENABLED 1
#define NRF_CLI_BLE_UART_MAX_CLIENTS 1
#define BLE_NUS_ENABLED 1
#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 4224 
#define NRF_SDH_BLE_VS_UUID_COUN 4		// was 3, number of vendor specific UUID already in the application

I'm clearly missing something else, but I cannot figure out why those calls are failing (I'm not familiar enough with the flags to understand why nrf_atflags_get() returns false when called with the connection handle for BLE_UART. I'm hoping it's obvious to someone else...

I tried following step by step both the example and my code, and as far as I can tell, every call in that chain above seems to have valid parameters and, apart from address differences, look pretty much identical

Parents
  • Hi 

    Wouldn't the usbd_ble_uart example be a more natural place to start for what you are trying to do?

    This example combines the usbd_cdc example with the app_ble_uart example. The only thing left to do is that you might have to replace the NUS server/peripheral with the NUS client/central, depending on which side you are implementing. 

    Best regards
    Torbjørn

  • I'm confused on how it would help me, sorry.

    I need to implement a BLE CLI UART functionality in existing code. I already successfully added the USB CLI functionality. I do not need generic BLE UART functionality.My code uses 4 custom UUID VS, and that seems to be somehow a problem (not sure)

    The existing BLE CLI UART example seems a much better starting point than a completely unrelated BLE UART example, given that I do not need generic UART and, as far as I can see, nrf_cli_ble_uart_service_init() is supposed to already initialize the Nordic NUS service for me. I call that function roughly the same way as the example, but somehow it doesn't seem to properly initialize the necessary functionality, given that a successive call to cli_ble_uart_init() reports something missing and fails. I know that there must be some sort of initialization problem, but the information I get from the system is not helping me narrow things down (I can provide more info if needed, variable values at critical times, etc)

    What am I missing in your reply? how would that code help me with a failure in cli_ble_uart_init()? There is no CLI functionality in the example you mention

    EDIT: to add more information, after looking further into the different behavior of the example app and my code, I can see that the variable m_bcs is properly initialized in the example, and all zero in my case. m_bcs is initialized inside ble_conn_state.c in the ble_evt_handler() function

    In my case, that function is never called. The weird thing I don't understand is how it's being called in the example. The stack trace reports tha is being called from nrf_sdh_ble_evts_poll() in nrf_sdh_ble.c which is in turn called by nrf_sdh_evts_poll() in nrf_sdh.c when an SWI2_EGU2_IRQ2 happens at the moment I attempt to connect to the device from another device. That particular event handler is called

    In my case, the same IRQ instead calls ble_evt_handler() in main. What initialization process causes the softdevice to dispatch to the event handler in ble_conn_state.c instead of main?

  • I finally answered my own question. Figuring out the event handler part was the key

    For my project, the critical part was to change the existing 

    #define APP_BLE_OBSERVER_PRIO           0

    in sdk_config.h to

    #define APP_BLE_OBSERVER_PRIO           3 

    I guess it was explained here https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.3.0%2Flib_softdevice_handler.html, but that became obvious only after knowing that was the problem all around

    Leaving this here in case anyone else bumps into this in the future

  • Good to hear you found the issue, and thanks for sharing it here. 

    I will consider the case closed then Slight smile

Reply Children
No Data
Related