Attempting to setup Counter top value causes firmware to reboot

I'm running NCSv2.6.0 on some custom hardware, with an nRF52832 IC fitted.  I'm trying to trigger an ADC measurement every ~ 300usec using a Counter, so need to set the Counter top value to trigger the callback function at the appropriate time.

I have some standalone firmware that does what I want, and can test this on my custom hardware and confirm that it works, but whenever I try and "port" this across to my working firmware to include this functionality in the overall functionality of the device, any calls I make to either set up the counter, or start the counter, cause the firmware to reboot. I don't get any fatal error or any log info to indicate why its rebooting, so I can't work out what is the cause.

The key difference between the version that works, and the version that doesn't, is the working version doesn't have a child image and fixed partitions.  Non-working version has these as it is using OTA.

These are the appropriate CONFIG settings I have:

# Enable I2C
CONFIG_I2C=y
CONFIG_COUNTER=y
CONFIG_PCF85063A=y

#Timer
CONFIG_TIMER=y
CONFIG_TIMING_FUNCTIONS=y
CONFIG_NRF_RTC_TIMER=y
CONFIG_NRFX_TIMER0=y

I have my counter configured as follows:

#define TIMER DT_NODELABEL(timer0)
const struct device *counter_dev = DEVICE_DT_GET(TIMER);

void counter_callback(const struct device *dev, void *user_data)
{
	// Do some stuff
}

struct counter_top_cfg counter_config = {
	.ticks = SAMPLE_PERIOD_50HZ, 
	.callback = counter_callback,
	.user_data = NULL,
	.flags = COUNTER_TOP_CFG_RESET_WHEN_LATE | COUNTER_CONFIG_INFO_COUNT_UP | COUNTER_ALARM_CFG_ABSOLUTE,
};

void counter_init (void)
{
	if (!device_is_ready(counter_dev)) {
        LOG_ERR("counter_dev is not ready");
    } else {
        counter_set_top_value(counter_dev, &counter_config);
    }
}

When I make a call to counter_init(), and it calls counter_set_top_value(counter_dev, &counter_config), its at that point that my firmware seems to reboot.  If I comment the call to counter_set_top_value(counter_dev, &counter_config) out, the rest of the code runs without issue.

I'm really struggling to see what I'm doing wrong here!  Can anyone assist?

Thanks and regards,

Mike

  • Hi Mike,

    For debugging, you may try disabling the 'CONFIG_RESET_ON_FATAL_ERROR' setting to see if the error handler is invoked. I also noticed that you are using TIMER instance 0. This instance is reserved for the Softdevice controller / MPSL and should not be used if you are using BLE. Do you experience the same issue if you switch to a different TIMER instance?

    Best regards,

    Vidar

  • Hi Vidar,

    THANKYOU!!!!!  Wow, I have been struggling with this issue on and off for weeks.  Changing:

    #define TIMER DT_NODELABEL(timer0)
    to
    #define TIMER DT_NODELABEL(timer1)
    fixed the problem!!  The other code, where things work, doesn't utilise BLE, hence why it wasn't an issue that presented itself.
    I'm off to celebrate with a beer (its 4.30pm here in Australia) :-)
    Cheers/skål,
    Mike
Related