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

Ble template app and UART crash

Good morning everyone,

I am facing a weird problem concerning the use of the UART service.

I am currently using the NRF52832DK to develop an application. In a nutshell, I am reading a temperature via a TWI-connected sensor every 2 seconds, and I want to send it to a smartphone using the UART service.

I started developing my application from the ble_template app, and so far everything works fine: I was able to set a timer for the periodic reading, and I am able to correctly read the data from the TWI.

The problem starts when I try to use the UART profile.

First of all, if I simply change the name of the available service from 

static ble_uuid_t m_adv_uuids[] =                                               /**< Universally unique service identifiers. */
{
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
};

to

static ble_uuid_t m_adv_uuids[]          =                                          /**< Universally unique service identifier. */
{
    {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
};

the application crashes. By "Crashes" I mean that if I enable the UART log I see that "Fatal Error" is printed out almost immediately; if I disable 

the UART log (I saw on the forum that UART log is not available if using the UART as a service), then I don't see any communication on the TWI, nor I see

LEDs blinking for advertising; I reasonably assume that the app is not starting.

If I leave unchanged the name of the service, I got an error in another part of the code, namely in the uart_init function (copied from the ble_uart_app example), and 

again I got a fatal error and nothing running.

Finally, if I don't call the uart_init, but I only try to start the services (services_init), I got in the following function

static void services_init(void)
{
    uint32_t       err_code;
    ble_nus_init_t nus_init;

    memset(&nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = nus_data_handler;

    err_code = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(err_code);
}

an error code 4, which I saw means "NO MEMORY FOR OPERATION".

I read a lot of similar problems, and I tried all the suggested configurations (deactivating UART log, importing all the correct files and dependencies and so on), I followed the Service,Configuration and Advertising tutorials and I am currently out of ideas.....

A sidenote: the ble_uart_app example as it is, works without problems.

I suspect I am missing a small configuration detail, but I have really no idea what it could be....

I am using softdevice 132, pins P0.11 and P0.12 for SDA and SCL and the UART example pins.

Thank you for your help!

Parents
  • Hi again,

    after some digging in the forum, I partially solved my problem following this discussion and setting NRF_SDH_BLE_SERVICE_CHANGED to 0.

     I still have a problem when I try to change the value in the array of advertised services....If I leave everything like it is now, i.e.

    static ble_uuid_t m_adv_uuids[] =                                               /**< Universally unique service identifiers. */
    {
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };

    the application works, and I can correctly receive data on an ipad using the UART from the NRF Toolbox.

    If I try to change the code to 

    static ble_uuid_t m_adv_uuids[] =                                               /**< Universally unique service identifiers. */
    {
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };

    The application crashes immediately, meaning that I am not even able to start  the debugger.

    I suspect there is something I am still missing in the sdk_config.h file, but I cannot figure out what is wrong....

    I already commented out NRF_LOG_BACKEND_UART_ENABLED and NRF_LOG_BACKEND_UART_TX_PIN.

    Thank you,

Reply
  • Hi again,

    after some digging in the forum, I partially solved my problem following this discussion and setting NRF_SDH_BLE_SERVICE_CHANGED to 0.

     I still have a problem when I try to change the value in the array of advertised services....If I leave everything like it is now, i.e.

    static ble_uuid_t m_adv_uuids[] =                                               /**< Universally unique service identifiers. */
    {
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };

    the application works, and I can correctly receive data on an ipad using the UART from the NRF Toolbox.

    If I try to change the code to 

    static ble_uuid_t m_adv_uuids[] =                                               /**< Universally unique service identifiers. */
    {
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };

    The application crashes immediately, meaning that I am not even able to start  the debugger.

    I suspect there is something I am still missing in the sdk_config.h file, but I cannot figure out what is wrong....

    I already commented out NRF_LOG_BACKEND_UART_ENABLED and NRF_LOG_BACKEND_UART_TX_PIN.

    Thank you,

Children
  • Try to place the m_adv_uuids in the scan response packet, as shown in the NUS example.

     

     

    static void advertising_init(void)
    {
        uint32_t               err_code;
        ble_advertising_init_t init;
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance = false;
        init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    
        init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.srdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }

  • Hi,

    thank you for the hint, put it is already there. Actually my code look exactly as the one you posted :). 

    The app is not able to start if I change the name of the m_adv_uuids.

    I just realized there was an error in my post; the code not working is when I define the m_adv_uuids as follows

    static ble_uuid_t m_adv_uuids[] =                                               /**< Universally unique service identifiers. */
    {
            {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
    };

  • You should debug to find the reason why the code is not working. If you are using Keil, see this post.

  • Hi again,

    and thanks for the reply. Normally, I use a forum only once the debug and other techniques did not help me finding the solution to a weird problem, like in this case. 

Related