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

SWI2_IRQHandler trouble?

Edit: I'm using the softdevice S110, 8.0.0, Nrf51822 chip, Keil uv5.12

Edit #2: Added more detail and revised certain description.

  • What's the problem?

My program constantly crash into hard fault handler when 1. My android device is reading GATT related parameters (like service table) -OR- 2. having the program running for a while (I did not measure it but it is expected to be around 15 minutes, which is fairly short).

  • Primary Suspect

I looked up the call stack window and the trouble seems to be lying within SWI2_IRQHandler, (picture below) sadly, the erro_code and LOCAL_ERR_CODE are all out of scope so I can't really see what they are (teach me how to if you will! Thanks a lot) but I'm assuming it's "out of memory" error, related to the scheduler cache/queue. It could also be a memory leak somewhere, and the PC ran into the twilight zone.

image description

So my questions:

  1. Assuming that is the case (no memory), where to modify the queue size of the scheduler? I came to the understanding after a little cursory research that it is initialized usually for example in something like this:

    static void scheduler_init(void) { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); }

but I have either removed these lines of code when adopting my current project from the ble heart rate sensor example or there wasn't any to begin with.

  1. In the screen cap, before going to HardFault_Handler, there is an address "0x00002774" between them. What is that all about?

  2. How should I look up the err_code? I've placed a breakpoint here: image description

and that is how I got the call stack screenshot. And to be honest, I'm not even 100% sure which part of SWI2_IRQHandler is problematic, but nevertheless I am fairly certain it's when reading services table during establishing a GATT connection (my android device has a little log window which prints reliable information about what the app is doing) and the program crashes when

err_code = sd_evt_get(&evt_id);

got called a SECOND time.

  • How did I find that out?

Well first please allow me to clear something up.

Keil's debugging features are... rather buggy. Especially when it comes to setting a count for a breakpoint. The proper step (I could be wrong but highly unlikely) to set a "counting" breakpoint, (i.e. a breakpoint that will not break the program first time it got hit but after the number of times designated by you) is to press "ctrl-B", double-click the breakpoint you want to set a count for, set the count, then click "define" button. That's where the buggy part is: it will remind you that you are duplicating a breakpoint, but let you do it anyway. And during actual execution, keil will remind you that it found a problem: a breakpoint was multiple-ly defined.

You see I suspect the error is with the sd_evt_get() function inside the SWI2_IRQHandler, more specifically, these code, with the most probably culprit highlighted by a comment:(these code is in softdevice_handler.c, some being softdevice function so they are not transparent to me when it comes to actual implementation)

void intern_softdevice_events_execute(void)
{
if (!m_softdevice_enabled)
{
    // SoftDevice not enabled. This can be possible if the SoftDevice was enabled by the
    // application without using this module's API (i.e softdevice_handler_init)

    return;
}

bool no_more_soc_evts = (m_sys_evt_handler == NULL);
#ifdef BLE_STACK_SUPPORT_REQD
bool no_more_ble_evts = (m_ble_evt_handler == NULL);
#endif
#ifdef ANT_STACK_SUPPORT_REQD
bool no_more_ant_evts = (m_ant_evt_handler == NULL);
#endif

for (;;)
{
    uint32_t err_code;

    if (!no_more_soc_evts)
    {
        uint32_t evt_id;

        // Pull event from SOC.
        err_code = sd_evt_get(&evt_id);//This is where the potentially problematic function is called
        
        if (err_code == NRF_ERROR_NOT_FOUND)
        {
            no_more_soc_evts = true;
        }

To validate my suspicion, I set the breakpoint at

        if (err_code == NRF_ERROR_NOT_FOUND)

and set the count for that breakpoint to 1. The program will hit the breakpoint immediately when my android app starts to connect the chip, indicating that the function above it,

err_code = sd_evt_get(&evt_id);

was successfully executed (1st time around). But if I set the breakpoint count to 2, and commence the connection process again, keil will remind me that it found a problem: a breakpoint was multiple-ly defined. And then it goes straight to hardfault handler. I believe this tells me that the "sd_evt_get" function will only be properly executed ONCE but will crash the 2nd time around, when an android device is trying to establish a GATT connection with it.

I'm rather lost on this one, can someone please help me?

@petter @martinbl @joh2 @david-edwin @bjorn-spockeli

Parents Reply Children
No Data
Related