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

FreeRTOS Task Priority VS Interrupt Priority nRF52840

Hi guys,

I have a 4 thread freeRTOS setup.

  1. BLE - priority 4
  2. TWI - priority 3
  3. LED - priority 2
  4. Logging - priority 1

After running for some time my code always gets caught in an infinite loop inside the vListInsert function of freeRTOS, or hardfaults @ PC:0x20003188 PSR: 0x4000000e (PendSV). It occurs like a random race-condition. Typically this indicates an issue with interrupt priorities. Looking thru my Stack trace, On the BLE thread (4), I get a SAADC IRQ (IRQ priority 6 in sdk_config.h) which triggers a callback function to write the value to the Log Thread (1). Here I try and grab a Semaphore which calls the following sequence, xSemaphoreTake() -> xQueueGenericReceive() -> vTaskPlaceOnEventList() -> vListInsert().

As an FYI I'm trying to Port FreeRTOS to the nRF52840 which i realize doesn't have an official support from Nordic yet.  Just want to double check there is nothing unique about the any vector implementation that might propagate to different behaviour in upper levels of an RTOS.  Thanks for your help.

Parents
  • Keep in mind that if a LOWER priority thread has acquired a resource, it can block a HIGHER priority thread because it cannot release the resource until the higher priority thread gives up. Since you are running the SAADC task when the hang occurs, you need to check your lower priority tasks to see if there is some place where you acquire the same mutex. There's only one lower priority task, and that's the LED one. Check there.

  • Fixed the hardfault issue. Increased the configTOTAL_HEAP_SIZE in FreeRTOSConfig.h to 28000. I'm back at the random occurrence of the vListInsert() loop. I rule out the following causes

    1. Stack overflow - I have hooks to detect this with vApplicationStackOverflowHook().
    2. "Using a queue or semaphore before it has been initialised" Not possible

    Leaves two possibilities:

    1. Incorrect interrupt priority assignment. I've outlined my priorities in my main post. I enter this loop consistently from a call to grab the Semaphore for my Logging Thread (lowest priority). New to freeRTOS, but don't see this as the issue.

    2. Calling API function from within a critical section. This one I'm unsure of. I do manually suspend my threads when they aren't used. I resume them from either other threads waking them up, or incoming data (i.e. Sensor data or xTimer handler hit).

Reply
  • Fixed the hardfault issue. Increased the configTOTAL_HEAP_SIZE in FreeRTOSConfig.h to 28000. I'm back at the random occurrence of the vListInsert() loop. I rule out the following causes

    1. Stack overflow - I have hooks to detect this with vApplicationStackOverflowHook().
    2. "Using a queue or semaphore before it has been initialised" Not possible

    Leaves two possibilities:

    1. Incorrect interrupt priority assignment. I've outlined my priorities in my main post. I enter this loop consistently from a call to grab the Semaphore for my Logging Thread (lowest priority). New to freeRTOS, but don't see this as the issue.

    2. Calling API function from within a critical section. This one I'm unsure of. I do manually suspend my threads when they aren't used. I resume them from either other threads waking them up, or incoming data (i.e. Sensor data or xTimer handler hit).

Children
No Data
Related