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

nRF5 SDK 16 BLE startup, failing nrf_atfifo_item_alloc

During BLE startup call to nrf_sdh_enable_request(), nrf_atfifo_item_alloc fails and returns NULL causing a hard fault.

This sounds like an sdk_config.h problem but I don't know where to start looking.

  • I can't get CPU registers today until I get my new JLINK. I'm using the SEGGER (Microsoft) IDE and GNU compiler. I'll work on abstracting the important code so I don't have to post the whole thing as there's lots of stuff with I2C that are a distraction.

  • Here's an abstraction of the code - this compiles but doesn't load due to setup problems.

    #include <stdlib.h>
    #include <stdint.h>
    #include <stdbool.h>

    #include <nrf.h>
    #include <nrfx_timer.h>
    #include <nrf_sdh.h>

    static nrfx_timer_config_t timerCheckinConfig =
    {.frequency = NRF_TIMER_FREQ_500kHz,
    .mode = NRF_TIMER_MODE_TIMER,
    .bit_width = NRF_TIMER_BIT_WIDTH_32,
    .interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
    .p_context = NULL};

    typedef struct {
    nrfx_timer_t inst;
    uint32_t ms;
    uint32_t ticks;
    uint32_t running;
    uint32_t sinceFlashReset;
    } Metronome;

    Metronome timerCheckin =
    {.inst = NRFX_TIMER_INSTANCE(2),
    .ms = 2,
    .ticks = 0,
    .running = 0,
    .sinceFlashReset = 0 };

    void timerCheckinEventHandler(nrf_timer_event_t etype, void* pContext)
    {
    switch( etype ) {
    case NRF_TIMER_EVENT_COMPARE2: break;
    default: break;
    }
    }

    void timerInit(void)
    {
    nrfx_err_t rc;
    rc = nrfx_timer_init(&timerCheckin.inst, &timerCheckinConfig, timerCheckinEventHandler);
    APP_ERROR_CHECK(rc);
    timerCheckin.ticks = nrfx_timer_ms_to_ticks(&timerCheckin.inst, timerCheckin.ms);
    nrfx_timer_extended_compare(&timerCheckin.inst,
    NRF_TIMER_CC_CHANNEL2,
    timerCheckin.ms,
    NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK,
    true);
    nrfx_timer_enable(&timerCheckin.inst);
    }


    void ble_stack_init(void)
    {
    ret_code_t err_code;
    err_code = nrf_sdh_enable_request();

    // At this point err_code == 3!
    APP_ERROR_CHECK(err_code);
    }


    int main(void)
    {
    timerInit();
    ble_stack_init();
    }

  • Jed Marti said:
    this compiles but doesn't load due to setup problems.

     Is it related to debugger setup, or are you able to load and debug the original project? The nrf_sdh_enable_request() should not return 0x3 and it doesn't make any calls nrf_atfifo_item_alloc() either.

    I will try to run this on a nordic DK if you upload the full project (the simplified version without i2c) as a zip file.

  • Things behaving differently - I switched to the Linux version (a treat by the way) and followed the request sequence for nrf_sdh_enable_request as follows. The error occurs in a critical region which could be a problem for the debugger but:

    nrf_sdh_enable_request
      sdh_request_observer_notify succeeds
      sd_softdevice_enable
         ser_app_hal_hw_init succeeds
         connectivity_reset_low
         nrf_queue_reset
         nrf_queue_reset
         ser_sd_transport_open fails following
           ser_hal_transport_open
            ser_phy_open fails following
             hci_timer_init fails following
               app_timer_create success
                 hci_timer_reset fails
                    app_timer_stop fails return code 4, switch error code to NRF_ERROR_INTERNAL==3 and return up

    Now sounds like something with the timers needed.

    Uploading zip problematic for sponsor.

  • I followed the app_timer_stop a bit farther, it is failing the nrf_atfifo_wspace_req call (which returns NULL). The linker claims I'm only using 25% of RAM so this  must be a memory setup problem. The code in nrf_atfifo_wspace_req is assembly that I'm not competent to interpret.

    nrf_sdh_enable_request
    sdh_request_observer_notify
    sd_softdevice_enable
    ser_app_hal_hw_init
    connectivity_reset_low
    nrf_queue_reset
    nrf_queue_reset
    ser_sd_transport_open
    ser_hal_transport_open
    ser_phy_open
    hci_timer_init
    app_timer_create
    hci_timer_reset
    app_timer_stop fails return code 4,

    further calls by app_timer_stop now...
        timer_req_schedule
          nrf_atfifo_item_alloc returns NULL
            nrf_atfifo_wspace_req --> No calls here, this is what fails.

Related