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

Adding Blinky features in my Example

Hi,

I am working on a project where I am sending and receiving Encrypted string data from my phone with nRF Toolbox to the nRF52840 DK. The basic paring is established along with bonding.

I am able to send and receive strings from both the sides too. Now I added a button to the nRF Toolbox UART feature.

Now when I press the button an led on the nRF52840 DK should glow. I am done with the app side but I wanted to add the blinky features to the nRF52840. But I am getting a FATAL ERROR.

I didn't do many changes in my code. I just added the below functions to my code can you please tell me the error.

static void led_write_handler(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t led_state)
{
    if (led_state)
    {
        bsp_board_led_on(LEDBUTTON_LED);
        NRF_LOG_INFO("Received LED ON!");
    }
    else
    {
        bsp_board_led_off(LEDBUTTON_LED);
        NRF_LOG_INFO("Received LED OFF!");
    }
}

static void services_init(void)
{
    uint32_t err_code;
    ble_nus_init_t     nus_init;
    ble_lbs_init_t     init     = {0};
    
    // Initialize NUS.
    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);

    //Initialize LBS.
    init.led_write_handler = led_write_handler;

    err_code = ble_lbs_init(&m_lbs, &init);
    APP_ERROR_CHECK(err_code);
}
 

  • I am getting a FATAL ERROR.

    Where, exactly, do you get that fatal error?

    Have you enabled the RTT logging? That should give you more information ...

  • I'm not sure if you know, but the FATAL error as you see in your logging occurs in most cases due to the APP_ERROR_CHECK. So, a quick way of detecting where this occurs is of course to simply add a logging statement before the APP_ERROR statements in your code (or at least where you expect it would go wrong). Printing the location and err_code in most cases will do. Don't forget to place a NRF_LOG_FLUSH() after each logging statement to have it printed before the next statement.

  • Hi,

    I possibly knew where the error was but I didn't know how to check for the error. Thanks for providing the solution.

    I added the log statement as given below in the services_init function.

    NRF_LOG_INFO("The err_code is %d",err_code);
    NRF_LOG_FLUSH() ;

    static void services_init(void)
    {
        uint32_t err_code;
        ble_nus_init_t     nus_init;
        ble_lbs_init_t     init     = {0};
        
        // Initialize NUS.
        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);
    
        //Initialize LBS.
        init.led_write_handler = led_write_handler;
    
        err_code = ble_lbs_init(&m_lbs, &init);
        NRF_LOG_INFO("The err_code is %d",err_code);
        NRF_LOG_FLUSH() ;
        APP_ERROR_CHECK(err_code);
    }

    From the logs, the err_code is 4 which means No Memory for operation.

    What should I do to increase the memory??

    The Set Section Placement Macros list is attached below. Can you tell me what should I change in this and by how much?

    FLASH_PH_START=0x0
    FLASH_PH_SIZE=0x100000
    RAM_PH_START=0x20000000
    RAM_PH_SIZE=0x40000
    FLASH_START=0x26000
    FLASH_SIZE=0xda000
    RAM_START=0x20003980
    RAM_SIZE=0x3c680

  • Hi,

    I could rectify the error by going through this thread.

    Thank you for guiding me.

  • Hi, I have a small doubt in my code.

    I have added the LBS service function from the blinky example to my code along with the turning OFF and ON of the led function.

    static void led_write_handler(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t led_state)
    {
        if (led_state)
        {
            bsp_board_led_on(LEDBUTTON_LED);
            NRF_LOG_INFO("Received LED ON!");
        }
        else
        {
            bsp_board_led_off(LEDBUTTON_LED);
            NRF_LOG_INFO("Received LED OFF!");
        }
    }

    //Initialize LBS.
        init.led_write_handler = led_write_handler;
    
        err_code = ble_lbs_init(&m_lbs, &init);
        APP_ERROR_CHECK(err_code);

    Now when I try to add the LBS_UUID_SERVICE in advertising_init() function as given below:-

    #define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN
    
    #define LBS_SERVICE_UUID_TYPE   m_lbs.uuid_type
    
    static ble_uuid_t m_adv_uuids[] = {
                                         {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE},
                                         {LBS_UUID_SERVICE, LBS_SERVICE_UUID_TYPE}
                                      };

    The NUS UUID type is working fine but the LBS UUID type is giving me the error given below:-

    Compiling ‘main.c’
    2> C:\nRF5_SDK_15.2.0_9412b96\nRF5_SDK_15.2.0_9412b96\examples\ble_central_and_peripheral\experimental\ble_app_multirole_lesc\main.c:70:41: error: initializer element is not constant

    Can you please tell where Am I going wrong???

Related