Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

hard fault when taking semaphore in FreeRTOS

Hi,

I'm trying to use a GPIO interrupt and a semaphore to trigger a free rtos taskm but whenever I run xSemaphoreTake i get a hard fault error.

// Semaphore to signal interrupt pin change
SemaphoreHandle_t m_ppg_semaphore;

static void ppg_test_task(void *pvParameter){
    UNUSED_PARAMETER(pvParameter);

    m_ppg_semaphore = xSemaphoreCreateBinary();
    ASSERT(NULL != m_ppg_semaphore);

    gpio_init();

    //volatile enum ppgInterupt ppgState = notReady;
    // Read the interrupt registers to clear them
    //uint8_t buffer;
    //bool stay = false;
    while (true) {
        bool temp = xSemaphoreTake(m_ppg_semaphore, portMAX_DELAY);

        // Turn an LED on to signify the start of data reading
        bsp_board_led_invert(BSP_BOARD_LED_3);
        }
}

void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
    BaseType_t yield_req = pdFALSE;

    /* The returned value may be safely ignored, if error is returned it only means that
    * the semaphore is already given (raised). */
    UNUSED_VARIABLE(xSemaphoreGiveFromISR(m_ppg_semaphore, &yield_req));
    portYIELD_FROM_ISR(yield_req);
}
/**
 * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
 * and configures GPIOTE to give an interrupt on pin change.
 */
static void gpio_init(void) {
    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(INT_IN, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(INT_IN, true);

    NRF_LOG_INFO("GPIO Configured");
}

Parents Reply Children
No Data
Related