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