Advertising Beacon Start Gives Fatal Error

My overall goal is to update the percentage of battery left in the advertiser and then either go to a nine second sleep to conserve as much power as possible and then wake up and repeat the process.  Right now I am trying to see if using a timer event will allow the project to last long enough on a small battery (30mAH) or if I should investigate using some external circuitry to produce a wake up pulse so the battery can be separated from the micro and have minimal draw on the battery.  Any suggestions on how this can be verified would be appreciated.

In addition, I have been attempting to work with the beacon examples and have managed to introduce some kind of fatal error when I start the advertising.  The init seems to be functioning okay but I may be missing an important init step.  I am not sure if that is the case.  I have included what I think are the relevant parts of this code below.  If more is needed just let me know.

I am trying to make an undirected, non-connectable, no timeout advertising beacon with a nine second delay that updates a battery percentage parameter.

//-----------------------------------------------------------------------------
static uint8_t m_beacon_info[APP_BEACON_INFO_LENGTH] =   /**< Information advertised by the Beacon. */
{
 APP_DEVICE_TYPE,     // Manufacturer specific information. Specifies the device type in this implementation.
 APP_ADV_DATA_LENGTH, // Manufacturer specific information. Specifies the length of the
                      // manufacturer specific data in this implementation.
 APP_BEACON_UUID,     // 128 bit UUID value.
 APP_PRD_ID_OFS,      // Manufacturer specific information.  Product ID offset value.
 APP_PCB_REV,         // Manufacturer specific information.  PCB Revision Level.
 APP_FW_MAJ_VERS,     // Manufacturer specific information.  Firmware Major Version
 APP_FW_MIN_VERS,     // Manufacturer specific information.  Firmware Minor Version
 APP_MEASURED_RSSI,   // Manufacturer specific information.  The Beacon's measured TX power in this implementation.
 APP_BATT_PCNT_LVL    // Manufacturer specific information.  The Beacon's measured Battery power in percent
};

//-----------------------------------------------------------------------------
static uint8_array_t ary_beacon_info = 
{
 .size   = 0x0001,          // Number of array entries
 .p_data = m_beacon_info    // pointer to the data
};

//-----------------------------------------------------------------------------
static void advertising_init(void)
{
 uint32_t      loc_err_code;
   ble_advertising_init_t init;

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

   F_Manuf_Data.company_identifier      = APP_COMPANY_IDENTIFIER;
   F_Manuf_Data.data                    = ary_beacon_info;

   init.advdata.name_type               = BLE_ADVDATA_NO_NAME; //BLE_ADVDATA_FULL_NAME;
   init.advdata.include_appearance      = false;
   init.advdata.flags                   = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; // BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
   init.advdata.p_manuf_specific_data   = &F_Manuf_Data;

//   init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
//   init.advdata.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_interval = NON_CONNECTABLE_ADV_INTERVAL;
   init.config.ble_adv_fast_timeout  = 0;  // Never time out APP_ADV_DURATION;

   init.evt_handler = on_adv_evt;

   loc_err_code = ble_advertising_init(&m_advertising, &init);
   APP_ERROR_CHECK(loc_err_code);
}

//-----------------------------------------------------------------------------
static void advertising_start(void)
{
 ret_code_t loc_err_code;

 loc_err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
 APP_ERROR_CHECK(loc_err_code);
 NRF_LOG_INFO("  ble_advertising_start");

 loc_err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
 APP_ERROR_CHECK(loc_err_code);
 NRF_LOG_INFO("  bsp_indication_set");
}

//-----------------------------------------------------------------------------
int main(void)
{
 // Initialize.
 log_init();
 timers_init();
 leds_init();
 power_management_init();
 ble_stack_init();
 advertising_init();

 // Start execution.
 NRF_LOG_INFO("Beacon example started.");
 advertising_start();

 // Enter main loop.
 for (;;)
   {
    idle_state_handle();
   }
}

The defines that I am using are as follows:

#define APP_BEACON_INFO_LENGTH          0x18                               /**< Total length of information advertised by the Beacon. */
#define APP_ADV_DATA_LENGTH             0x16                               /**< Length of manufacturer specific data in the advertisement. */
#define APP_DEVICE_TYPE                 0x02                               /**< 0x02 refers to Beacon. */
#define APP_MEASURED_RSSI               0xB3                               /**< The Beacon's measured RSSI at 1 meter distance in dBm. */
#define APP_BATT_PCNT_LVL               80                                 /**< The percentage amount of battery left. */
#define APP_COMPANY_IDENTIFIER          0x0059                             /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */
#define APP_PRD_ID_OFS                  0x00                               /**< Product ID Offset. */
#define APP_PCB_REV                     0x00                               /**< PCB Revision Level. */
#define APP_FW_MAJ_VERS                 0x00                               /**< Firmware Major Version. */
#define APP_FW_MIN_VERS                 0x80                               /**< Firmware Minor Version. */
#define APP_BEACON_UUID                 0x01, 0x12, 0x23, 0x34, \
                                        0x45, 0x56, 0x67, 0x78, \
                                        0x89, 0x9a, 0xab, 0xbc, \
                                        0xcd, 0xde, 0xef, 0xf0            /**< Proprietary UUID for Beacon. */

I have the nRF_Log enabled and this is what I see continuously:

<info> app_timer: RTC: initialized.

<info> app: Beacon example started.

<error> app: Fatal error

<warning> app: System reset

<info> app_timer: RTC: initialized.

<info> app: Beacon example started.

<error> app: Fatal error

<warning> app: System reset

Any help identifying the fatal error or figuring out why it cannot get past ble_advertising_start would be greatly appreciated.

Parents
  • I can see it says: "<error> app: Fatal error". If you build using Debug instead of Release, then this window should contain more information about the error. Also check out: https://www.youtube.com/watch?v=uP8RYgYGRvI&list=PLx_tBuQ_KSqGHmzdEL2GWEOeix-S5rgTV&index=7 

  • I did as you asked and here are the  results:

    <info> app_timer: RTC: initialized.

    <info> app: Beacon example started.

    <error> app: ERROR 18 [NRF_ERROR_CONN_COUNT]

    PC at: 0x0002EA7D

    <error> app: End of error report

    The line that caused the error to occur was:

    loc_err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);

    That link you gave is a really good link on how to debug your application.  Thank you for that.

    It would appear that when this line of code is called the ERROR 18 is returned.

    Debugging in the code I pulled the current structure of p_advertising and what I see is below:

    advertising_mode                                      BLE_ADV_MODE_FAST (3)      0x2000ffcb          1       enum                          
    p_advertising                                         0x200021c4                 0x2000ffcc          4       ble_advertising_t*            
        *                                                 <struct>                   0x200021c4          1076    struct                        
            initialized                                   true                       0x200021c4          0       _Bool                         
            advertising_start_pending                     false                      0x200021c5          0       _Bool                         
            adv_mode_current                              BLE_ADV_MODE_FAST (3)      0x200021c6          1       enum                          
            adv_modes_config                              <struct>                   0x200021c8          44      struct                        
                ble_adv_on_disconnect_disabled            false                      0x200021c8          0       _Bool                         
                ble_adv_whitelist_enabled                 false                      0x200021c9          0       _Bool                         
                ble_adv_directed_high_duty_enabled        false                      0x200021ca          0       _Bool                         
                ble_adv_directed_enabled                  false                      0x200021cb          0       _Bool                         
                ble_adv_fast_enabled                      true                       0x200021cc          0       _Bool                         
                ble_adv_slow_enabled                      false                      0x200021cd          0       _Bool                         
                ble_adv_directed_interval                 0x00000000                 0x200021d0          4       unsigned int                  
                ble_adv_directed_timeout                  0x00000000                 0x200021d4          4       unsigned int                  
                ble_adv_fast_interval                     0x00003840                 0x200021d8          4       unsigned int                  
                ble_adv_fast_timeout                      0x00000000                 0x200021dc          4       unsigned int                  
                ble_adv_slow_interval                     0x00000000                 0x200021e0          4       unsigned int                  
                ble_adv_slow_timeout                      0x00000000                 0x200021e4          4       unsigned int                  
                ble_adv_extended_enabled                  false                      0x200021e8          0       _Bool                         
                ble_adv_secondary_phy                     0x00000000                 0x200021ec          4       unsigned int                  
                ble_adv_primary_phy                       0x00000000                 0x200021f0          4       unsigned int                  
            conn_cfg_tag                                  0x00                       0x200021f4          1       unsigned char                 
            adv_evt                                       BLE_ADV_EVT_FAST (3)       0x200021f5          1       enum                          
            evt_handler                                   0x0002e95d                 0x200021f8          4       void(const ble_adv_evt_t)*    
            error_handler                                 0x00000000                 0x200021fc          4       void(uint32_t)*               
            adv_params                                    <struct>                   0x20002200          24      struct                        
                properties                                <struct>                   0x20002200          2       struct                        
                    type                                  0x01                       0x20002200          1       unsigned char                 
                    anonymous                             0x00                       0x20002201 <0-0>    1       uint8_t                       
                    include_tx_power                      0x00                       0x20002201 <1-1>    1       uint8_t                       
                p_peer_addr                               0x00000000                 0x20002204          4       const ble_gap_addr_t*         
                interval                                  0x00003840                 0x20002208          4       unsigned int                  
                duration                                  0x0000                     0x2000220c          2       short unsigned int            
                max_adv_evts                              0x00                       0x2000220e          1       unsigned char                 
                channel_mask                              ""                         0x2000220f          0       uint8_t[5]                    
                filter_policy                             0x00                       0x20002214          1       unsigned char                 
                primary_phy                               0x01                       0x20002215          1       unsigned char                 
                secondary_phy                             0x00                       0x20002216          1       unsigned char                 
                set_id                                    0x00                       0x20002217 <0-3>    1       uint8_t                       
                scan_req_notification                     0x00                       0x20002217 <4-4>    1       uint8_t                       
            adv_handle                                    0x00                       0x20002218          1       unsigned char                 
            enc_advdata                                   "\002\001\004\004\377Y"    0x20002219          6       uint8_t[2][238]               
            enc_scan_rsp_data                             ""                         0x200023f5          0       uint8_t[2][238]               
            adv_data                                      <struct>                   0x200025d4          16      struct                        
                adv_data                                  <struct>                   0x200025d4          8       struct                        
                    p_data                                0x20002219                 0x200025d4          4       uint8_t*                      
                    len                                   0x0008                     0x200025d8          2       short unsigned int            
                scan_rsp_data                             <struct>                   0x200025dc          8       struct                        
                    p_data                                0x200023f5                 0x200025dc          4       uint8_t*                      
                    len                                   0x0000                     0x200025e0          2       short unsigned int            
            p_adv_data                                    0x200025d4                 0x200025e4          4       ble_gap_adv_data_t*           
            current_slave_link_conn_handle                0xffff                     0x200025e8          2       short unsigned int            
            peer_address                                  <struct>                   0x200025ea          7       struct                        
                addr_id_peer                              0x00                       0x200025ea <0-0>    1       uint8_t                       
                addr_type                                 0x00                       0x200025ea <1-7>    1       uint8_t                       
                addr                                      ""                         0x200025eb          0       uint8_t[6]                    
            peer_addr_reply_expected                      false                      0x200025f1          0       _Bool                         
            whitelist_temporarily_disabled                false                      0x200025f2          0       _Bool                         
            whitelist_reply_expected                      false                      0x200025f3          0       _Bool                         
            whitelist_in_use                              false                      0x200025f4          0       _Bool                         
    ret                                                   0x00000000                 0x2000ffd4          4       unsigned int                  

    ret = sd_ble_gap_adv_start(p_advertising->adv_handle, p_advertising->conn_cfg_tag);

    Upon further investigation, I am finding that:

    adv_handle is valid and conn_cfg_tag equals 0 when called in the above function.  Since I declared this to be a non-connectable device, the documentation says this parameter is not important.

    Any ideas why the error code 18 is being returned?

  • Try to increase NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and NRF_SDH_BLE_TOTAL_LINK_COUNT, though be aware that when you increase these two configuration the required RAM used by the softdevice will increase. You should get the RAM required from the nrf_sdh_ble_enable() if you debug, you need to update the project settings with the results.

    ret_code_t nrf_sdh_ble_enable(uint32_t * const p_app_ram_start)
    {
        // Start of RAM, obtained from linker symbol.
        uint32_t const app_ram_start_link = *p_app_ram_start;
    
        ret_code_t ret_code = sd_ble_enable(p_app_ram_start);
        if (*p_app_ram_start > app_ram_start_link)
        {
            NRF_LOG_WARNING("Insufficient RAM allocated for the SoftDevice.");
    
            NRF_LOG_WARNING("Change the RAM start location from 0x%x to 0x%x.",
                            app_ram_start_link, *p_app_ram_start);
            NRF_LOG_WARNING("Maximum RAM size for application is 0x%x.",
                            ram_end_address_get() - (*p_app_ram_start));
        }
        else
        {
            NRF_LOG_DEBUG("RAM starts at 0x%x", app_ram_start_link);
            if (*p_app_ram_start != app_ram_start_link)
            {
                NRF_LOG_DEBUG("RAM start location can be adjusted to 0x%x.", *p_app_ram_start);
    
                NRF_LOG_DEBUG("RAM size for application can be adjusted to 0x%x.",
                              ram_end_address_get() - (*p_app_ram_start));
            }
        }
    
        if (ret_code == NRF_SUCCESS)
        {
            m_stack_is_enabled = true;
        }
        else
        {
            NRF_LOG_ERROR("sd_ble_enable() returned %s.", nrf_strerror_get(ret_code));
        }
    
        return ret_code;
    }

  • While I was waiting for a reply, I changed my advertising_start routine to the code below:

    static void advertising_start(void)
    {
     ret_code_t             loc_err_code;
     ble_gap_adv_params_t   loc_adv_params;   /**< Parameters to be passed to the stack when starting advertising. */
    
     // Initialize advertising parameters (used when starting advertising).
     memset(&loc_adv_params, 0, sizeof(loc_adv_params));
    
     loc_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
     loc_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
     loc_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
     loc_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
     loc_adv_params.duration        = 0;       // Never time out.
    
     // Use the connectable handle that was previously created from the init routine and
     // turn it into a non-connectable handle
     loc_err_code = sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, &m_advertising.adv_data, &loc_adv_params);
     APP_ERROR_CHECK(loc_err_code);
    
     loc_err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
     APP_ERROR_CHECK(loc_err_code);
     NRF_LOG_INFO("  ble_advertising_start");
    
     loc_err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
     APP_ERROR_CHECK(loc_err_code);
     NRF_LOG_INFO("  bsp_indication_set");
    }
    
    

    The reason has to do with the original handle being created as a connectable.  Based on what I read, the handle needed to be passed in and the adv_params needed to be updated before the ble_advertising_start is called.

    In any event, the updated code did not change anything.  I still get the ERROR 18 as before in the same spot of the application.

    I will try what you suggest and let you know the results.  Not sure if they info I just provided gives any other clues.

Reply
  • While I was waiting for a reply, I changed my advertising_start routine to the code below:

    static void advertising_start(void)
    {
     ret_code_t             loc_err_code;
     ble_gap_adv_params_t   loc_adv_params;   /**< Parameters to be passed to the stack when starting advertising. */
    
     // Initialize advertising parameters (used when starting advertising).
     memset(&loc_adv_params, 0, sizeof(loc_adv_params));
    
     loc_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
     loc_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
     loc_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
     loc_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
     loc_adv_params.duration        = 0;       // Never time out.
    
     // Use the connectable handle that was previously created from the init routine and
     // turn it into a non-connectable handle
     loc_err_code = sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, &m_advertising.adv_data, &loc_adv_params);
     APP_ERROR_CHECK(loc_err_code);
    
     loc_err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
     APP_ERROR_CHECK(loc_err_code);
     NRF_LOG_INFO("  ble_advertising_start");
    
     loc_err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
     APP_ERROR_CHECK(loc_err_code);
     NRF_LOG_INFO("  bsp_indication_set");
    }
    
    

    The reason has to do with the original handle being created as a connectable.  Based on what I read, the handle needed to be passed in and the adv_params needed to be updated before the ble_advertising_start is called.

    In any event, the updated code did not change anything.  I still get the ERROR 18 as before in the same spot of the application.

    I will try what you suggest and let you know the results.  Not sure if they info I just provided gives any other clues.

Children
No Data
Related