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

in gpiote handler,call xEventGroupSetBitsFromISR will cause hardfault

my project is freertos+nrf52832 based the templete in SDK; A sensor pin is connect to P0.17, and I configure it low to high level trigger interrupt.In the handler I will call xEventGroupSetBitsFromISR to notify task, but when call this function, it will step into hardfault;The hardfault error information as the below:

hardfault: HARD FAULT at 0x000076EC<error> hardfault:   
R0:  0x7325203A  R1:  0x00004A1C  
R2:  0x65646F63  R3:  0x7265202C
<error> hardfault:   
R12: 0x00000003  LR:  0x0000859D  
PSR: 0x01000016<error> 
hardfault: Cause: Data bus error (return address in the stack frame is not related to the instruction that caused the error).

If in the handler, I call xEventGroupSetBits,the program can running normal.

So, what's wrong with it?Does GPIOTE handler is not ISR?

  • That is strange, 

    gpiote_handler is called from the ISR. Can you show me the screenshot of the calltrace of functions when the hardfault happened?

    Also, have you changed any priorities values of the kernel itself?

  •  Controller.7z

    Thanks for you help, I have attched the project, the project is running in PCA10040 Development Kit, When give P0.17 a raise level, it will trigger gpiote ISR, the it will set event bits and cause hardfault.

    void alps_gpio_interrupt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        BaseType_t higher_priority_task_woken, result;
        higher_priority_task_woken = pdFALSE;
    
        if(sample_task_event_handle == NULL)
        {
            NRF_LOG_WARNING("Task event is not create now\r\n");
            return;
        }
    
        if((pin == IMU_RDY_INT_PIN) && (action == NRF_GPIOTE_POLARITY_LOTOHI))
        {
    #if 0
            result = xEventGroupSetBitsFromISR(
                                    sample_task_event_handle, 
                                    IMU_DATA_DRDY_EVENT, 
                                    &higher_priority_task_woken);
            if(result != pdFAIL)
            {
                /* If higher_priority_task_woken is now set to pdTRUE then a context
                switch should be requested. The macro used is port specific and will
                be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
                the documentation page for the port being used. */
                portYIELD_FROM_ISR( higher_priority_task_woken );
            }
    #else
            xEventGroupSetBits(sample_task_event_handle,IMU_DATA_DRDY_EVENT);
    #endif
        }
    }
    
    
    static void sample_task_entry(void * pvParameter)
    {
        UNUSED_PARAMETER(pvParameter);
        EventBits_t event;
    
        while (true)
        {
            event = xEventGroupWaitBits(
                sample_task_event_handle,
                IMU_DATA_DRDY_EVENT,
                pdTRUE,  /* bit should be cleared before returning. */
                pdFALSE, /* Don't wait for both bits, either bit will do. */
                portMAX_DELAY);
            if(event == IMU_DATA_DRDY_EVENT)
            {
                led_toggle(0);
            }
        }
    }

  • I think I have seen this error before in the earlier SDK where there was a bug related to the tick handling. Which SDK version are you using? I can give it a try to reproduce this hardfault with your project once you let me know the SDK version.

  • This SDK should not have that bug i was mentioning before. So it is not related to the suspect i have in mind.

    I will test your project soon and come back to you.

Related