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 

Fullscreen
1
2
3
4
static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifiers. */
{
{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

to

Fullscreen
1
2
3
4
static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifier. */
{
{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
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);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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!

  • Hi, the ram size will be the problem check that. Mean while can you change your sda and scl pin to 3 and 4 and check. You can use any pins for twi. To check whether the problem belongs there.

    Cheers

  • Hello,

    thanks for your reply. I tried using pins 3 and 4 for the TWI as you suggested, but I get the same problem when I try to register the UART service instead of the default one.

    I don't fully get the problem you mention with the ram size....If I am registering an UUID instead of another this can create RAM problems? I think I am missing something...I am trying to have a look in the forum but I am not able to find anything useful so far....Do you have a more precise hint?

    Thanks a lot

  • 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.

    Fullscreen
    1
    2
    3
    4
    static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifiers. */
    {
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    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 

    Fullscreen
    1
    2
    3
    4
    static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifiers. */
    {
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    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,

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

     

     

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • 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

    Fullscreen
    1
    2
    3
    4
    static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifiers. */
    {
    {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

1 2