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

Trouble porting CLI over BLE example

Hi,

I have an existing application built on top of the ble_att_mtu_throughput example. I want to send log data over a BLE connection, and I am trying to use the CLI over BLE module to do this.

However, I'm having trouble porting the example to my project. Specifically, using the task manager module immediately triggers a hard fault (BusError or UsageFault_StateError). It fails at the line (inside task_switch)

VLDMIANE    SP!, {S0-S31}  /* If FPCA set, restore FPU registers. */

When not using the task manager module (never call nrf_cli_task_create), the code crashes upon connecting to the server. The CLI over BLE example has no trouble connecting and sending data to this webpage.

The error appears in the sd_ble_gap_phy_update function inside PHY_UPDATE case under ble_evt_handler. Error code returned is 4 (NRF_ERROR_INVALID_STATE). So I'm essentially stuck being unable to send log data over a BLE connection. Any advice would be much appreciated!

case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,
            };
            err_code = sd_ble_gap_phy_update(p_gap_evt->conn_handle, &phys);
            APP_ERROR_CHECK(err_code);
        } break;


  • I don't think that the ble_app_att_mtu_throughput is the best example to start a project with. The reason for this is that it is a bit complex. It is solely written to test throughput, as either a central or a peripheral. This mix makes it hard to understand.

    Perhaps you want to start with e.g. the ble_app_uart example?

    If you insist on using the throughput example, this is found in an experimental folder, so it may require a bit of patching to work with 3rd party devices. Check out how the ble_app_uart example implements the BLE_GAP_EVT_PHY_UPDATE_REQUEST event.

    Best regards,

    Edvin

  • Hi Edvin,

    I had built my project on the ble_app_att_mtu_throughput example because it allows the board to act both as a central and a peripheral (scan and advertise). It seemed like the other programs, like ble_app_uart, were difficult to modify to achieve this configuration. Additionally, ble_app_uart doesn't use the task manager module. It also implements the BLE_GAP_EVT_PHY_UPDATE_REQUEST event the same way as my code currently does.

  • Ok. Does the log say anything before you get the hardfault? Does the hardfault handler give any information? Do you see any logging from the hardfault handler at all? If not, try to replace the NVIC_SystemReset() in the final stage of the hardfault handler with:

    /*lint -save -e14 */
    __WEAK void HardFault_process(HardFault_stack_t * p_stack)
    {
        // Restart the system by default
        //NVIC_SystemReset();
        while (true)
        {
            NRF_LOG_PROCESS();
        }
    }

    BR,
    Edvin

  • Ok, thank you!

    1. I fixed the phy update error by changing the link count in sdk_config. It turned out it wasn’t an error in phy update, it was just being caught and handled in that section of code for some reason. 

    1. It looks like the hard fault is now only happening after nrf_cli_init is called to initialize the ble cli upon the connected event. The hard fault doesn’t happen in this block of code, but soon afterwards.

    2. There’s never any tracing information given. The hard fault doesn’t point to a human-interpretable line or lines of code. 

    I’ll try adding those lines to the hard fault handler, thanks!

  • It should point to some location in the flash. You should check out that address in the .map file to find out what function that hardfaults.

    BR,

    Edvin

Related