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.
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.
Hello,
Is the failing call to nrf_atfifo_item_alloc() being made by a SDK module or by your own code? NULL is usually handled by returning NRF_ERROR_NO_MEM back to the app, which should not lead to a fault exception. I would suggest to first try enabling the HardFault handling library in your project and see if it could help you find out exactly where the fault occurred.
That's how I found out. The top level call is nrf_sdh_enable_request() from the examples which is the first call in ble_stack_init. This call chain hard faulted as a result of NULL being returned by nrf_atfifo_item_alloc. nrf_sdh_enable_request then failed with code 3 which causes the hard stop.
I don't have the serial port enabled, just running the SEGGER debugger. Due to COVID 19, I'm now working from home and don't yet have access to the debugger.
The halt is a branch instruction to itself, I'm not sure where, it could be the SEGGER startup code but it's definitely caused by return code 3 on nrf_sdh_enable_request() and the following APP_ERROR_CHECK.
You can enable RTT logging if you want debug messages through the debugger. Can you post the CPU registers when it's halted? Are you debugging this in an IDE?
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.
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.
I assumed you were working with a standalone application with everything running on the nRF52 device, not a "serialized setup" with the app code running on a different CPU. Has the application been ported to a different platform (ie not a nordic nRF device)? The atfifo assembly is written for the Cortex m4 architecture.
This is running on an nRF52832 standalone. I'm running the SEGGER IDE (Linux version) JLINK base programmer talking to the board. I don't have a BLE application (phone based) yet, just using nrfconnect but if I can't get bluetooth started, the app is meaningless. Is the 52832 not an M4 device?
Am I using the wrong bluetooth code? This was setup to use softdevice S112.
I see. Your project is not set up correctly then. Some of the function calls you listed in your previous response are only used for serialization (ser_app_hal_hw_init, ser_sd_transport_open,..) so that is why I got confused. I suggest you start with an existing SDK example such as ble_app_blinky and verify that it runs on your board.