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

Is TIMER2 now being used by Softdevice??

Recently updated to SDK11 + s130 v2.0.1 on an nRF51822 xxAC LFCLKSRC=RC

BLE Advertising no longer works. Localized it to our use of TIMER2 for an implementation of systick();

void systick_init(void)
{
    NRF_TIMER2->MODE          = 0x0000;   // set timer mode
    NRF_TIMER2->TASKS_CLEAR   = 1;        // clear the task first to be usable for later
    NRF_TIMER2->PRESCALER     = 0x0004;   // 16 MHz clock, prescaler 16 -> 1us time step
    NRF_TIMER2->BITMODE       = 0x00;     // set counter to 16 bit resolution
    NRF_TIMER2->CC[0]         = 1000;
    NRF_TIMER2->INTENSET      = (1 << 16);

    NVIC_EnableIRQ(TIMER2_IRQn);          // enable interrupt on Timer 2

    NRF_TIMER2->TASKS_START = 1;          // start timer
}

If we call systick_init(); we no longer get BLE Advertisements. We have not seen anything in the SD Specification, SD API, or release notes regarding changes to TIMER2. Has something changed? If we skip this function, advertising works as it did prior to the update.

  • No nothing has changed with regards usage of TIMER2, the softdevice didn't use it before, it doesn't use it now.

    'no longer get BLE Advertisements' usually translates to 'failed an error check and are in the error handler/hardfault handler'. So if you hit break in the debugger, where are you?

    .. and there are no calls to any softdevice functions from your timer interrupt handler are there?

  • Nope. No overt errors and everything else continues to run perfectly. Never goes to an error handler. One other clue, this function: sd_ble_gap_tx_power_set(NRF51822_TX_POWER_LEVEL_dBm) fails when systick_init() is called. Otherwise, no errors at all.

  • So what do you do when that call fails? Ignore the faliure, error out, reset, try to recover? If you've failed to set the power, I have no idea what invalid state the softdevice is in. Where are you calling the power set function from?

    Wondered if you were compiling against the wrong softdevice headers but lots more wouldn't work if you were doing that, but worth a check.

    It's very unlikely it really has anything to do with TIMER2, the change in SDK has most probably uncovered a bug which was lurking before, a timing-sensitive one. Oh and what's the error return from the power set function?

  • sd_ble_gap_tx_power_set(0x04) returns 0x02 which seems to read like it's a bad parameter. But, if we do not make the call to systick_init() then this passes. I agree with your comment - probably an unrelated issue coming to light because of timing changes.

  • 0x02, that's easy then.

    #define NRF_ERROR_SOFTDEVICE_NOT_ENABLED   (NRF_ERROR_BASE_NUM + 2)
    #define 	NRF_ERROR_BASE_NUM   (0x0)
    

    so you're calling the set tx power before you enable the softdevice. I would hazard a guess that the softdevice init takes a little longer than before and your timer handler goes off and results in your calling the power set in the wrong order. Or something like that.

Related