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);
}
 

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

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

Children
Related