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

Problem in starting advertisement in gpiote interrupt

Hi,
I'm trying to start advertising in gpiote interrupt. I have modified ble_hrs_demo code. I'm suing nrf51-dk with SDK9 and S110. Here are my code snippets(they are not in order here):

static void gpiote_init()
{
ret_code_t err_code;

err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(CLK_PIN, &in_config, clk_pin_handler);
APP_ERROR_CHECK(err_code);
}

static void timers_init(void)
{
uint32_t err_code;

// Initialize timer module.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

// Create timers.
err_code = app_timer_create(&m_tpms_timer_id,
                            APP_TIMER_MODE_SINGLE_SHOT,
                            sensor_meas_timeout_handler);
APP_ERROR_CHECK(err_code);

 }

static void application_timers_start(void)
{
uint32_t err_code;

// Start application timers.
err_code = app_timer_start(m_tpms_timer_id, SENSOR_MEAS_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);

}

static void sensor_meas_timeout_handler(void *p_context)
{
nrf_gpio_pin_toggle(BSP_LED_1);
UNUSED_PARAMETER(p_context);
nrf_drv_gpiote_in_event_enable(CLK_PIN, true);
nrf_gpio_pin_clear(SENSOR_WAKE);
nrf_delay_ms(1);
nrf_gpio_pin_set(SENSOR_WAKE);
}

static void clk_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrf_gpio_pin_toggle(BSP_LED_0);
data |= nrf_gpio_pin_read(DATA_PIN) << (7-count++);
if(count == 8)
{
	data_array[data_count++] = data;
	data = 0x00;
	count = 0;
	if(data_count == DATA_LENGTH+2)
	{
		data_count = 2;
//			nrf_drv_gpiote_in_event_disable(CLK_PIN);
		data_array[0] = DATA_LENGTH;
		data_array[1] = 0x16;
		uint32_t err_code;
		err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
		APP_ERROR_CHECK(err_code);
		
		err_code = sd_ble_gap_adv_data_set(NULL, 0, data_array, sizeof(data_array));
		APP_ERROR_CHECK(err_code);
		application_timers_start();
	}
}
}

The code works fine till I start advertising. I am using the default advertising_init() function from ble_hrs_demo. While debugging, the program ends at Hardfault Handler through function sd_ble_gap_start at line 344 in ble_advertising.c. What could be the reason? Also I want to disable the gpiote on the pin in the interrupt itself, is it possible?
Thanks in advance for help :)

Parents
  • I do not have the code available to verify, but i think

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    

    This above code If I remember correctly passing true means hi_accuracy, which willrequest the GPIOTE interrupt handler to be in higher priority (priority APP_PRIORITY_HIGH = 1). So your gpiote callback will be called with priority 1 (APP_PRIORITY_HIGH), and it is not allowed to make SVC (sd_xxx) calls in this context, otherwise it will trigger the hardfault.

Reply
  • I do not have the code available to verify, but i think

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    

    This above code If I remember correctly passing true means hi_accuracy, which willrequest the GPIOTE interrupt handler to be in higher priority (priority APP_PRIORITY_HIGH = 1). So your gpiote callback will be called with priority 1 (APP_PRIORITY_HIGH), and it is not allowed to make SVC (sd_xxx) calls in this context, otherwise it will trigger the hardfault.

Children
No Data
Related