# Task Notification Problems

**URL:** <https://forums.freertos.org/t/task-notification-problems/11840>\
**Category:** Kernel\
**Created:** [February 24, 2021, 10:30pm UTC](https://forums.freertos.org/t/task-notification-problems/11840 "2021-02-24T22:30:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![C-Coder](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@C-Coder](https://forums.freertos.org/u/C-Coder)\
**Post date:** [February 24, 2021, 10:30pm UTC](https://forums.freertos.org/t/task-notification-problems/11840/1 "2021-02-24T22:30:50Z")

</div>

I’m having trouble with task notifications and am sure it’s something stupid that I’m missing. My environment is such:

NXP LPC4330  
NXP MCUXpresso 10.3.1  
Segger j-link Ultra+ with J-Link 642b software  
FreeRTOSv202012.00

Initially I just want 2 of my own tasks running. One that blinks an LED (tskIDLE\_PRIORITY + 1UL) and one that processes data via USB 0 (tskIDLE\_PRIORITY + 2UL). We can ignore the LED task as it works without issue. The USB task is where things go awry. I want it to read 27 bytes into a receive buffer, copy the 27 bytes to a transmit buffer, and then send the 27 bytes back. In the read function, I have this:

…  
ulTaskNotifyTakeIndexed(0, pdFALSE, portMAX\_DELAY);  
…

(I want it to act like a counting semaphore just in case I fall behind on reading). In the USB ISR, I have this:

…  
xTaskNotifyIndexedFromISR(g\_pUSBTaskHandle, 0, 0, eIncrement, &xHigherPriorityTaskWoken);|  
portYIELD\_FROM\_ISR(xHigherPriorityTaskWoken);|  
…

where g\_pUSBTaskHandle is defined as:

TaskHandle\_t g\_pUSBTaskHandle = 0;

and the task is created as:

xTaskCreate(vUSBTask, “USBTask”, 10 \* configMINIMAL\_STACK\_SIZE, NULL, (tskIDLE\_PRIORITY + 2UL), &g\_pUSBTaskHandle);

with configMINIMAL\_STACK\_SIZE defined as:

#define configMINIMAL\_STACK\_SIZE ((unsigned short)1024/_130_/)

I can debug both this embedded side and the host PC application at the same time. If I slowly step through each, everything runs as expected. The PC application sends 27 bytes, the arm executes the ISR, it sends the notification and the task wakes up and sends the data back. However, if I let both the embedded side and the PC side run uninterrupted, then at random times different things happen on the embedded side.

Sometimes the USB task on the embedded side appears to hang in ulTaskGenericNotifyTake. Viewing the task handle in the debugger shows ulNotifiedValue[0] = 1, and ucNotifyState[0] = 2.

Sometimes the USB task just disappears altogether in the debugger.

Sometimes I get a hard fault and cannot (or maybe do not know the best way how to) determine what caused the hard fault.

If I don’t use notifications, and instead have the USB task do a busy loop waiting for a variable to change (signaling that the ISR happened), then the embedded side will run at least for several hours (have not let it run longer).

Any help?

Thanks,

C-Coder

---

<div class="post-metadata">

**Author:** ![C-Coder](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@C-Coder](https://forums.freertos.org/u/C-Coder)\
**Post date:** [February 24, 2021, 11:09pm UTC](https://forums.freertos.org/t/task-notification-problems/11840/2 "2021-02-24T23:09:35Z")

</div>

Somehow I just finally got the configASSERT stuff to work (not sure why it wasn’t working before, but obviously something wasn’t correct). Now when the ISR runs, it gets into the xTaskGenericNotifyFromISR and the configASSERT(ucCurrentPriority \>= ucMaxSysCallPriority ) fails. ucCurrentPriority = 0, and ucMaxSysCallPriority = 160. I’ve read:

> **[FreeRTOS - The Free RTOS configuration constants and configuration options -...](https://www.freertos.org/a00110.html#kernel_priority)**
>
> FreeRTOS is a portable, open source, mini Real Time kernel. A free RTOS for small embedded systems. This page describes and explains the constants used to configure FreeRTOS.

and

> **[RTOS for ARM Cortex-M](https://www.freertos.org/RTOS-Cortex-M3-M4.html)**
>
> Setting RTOS interrupt priorities on a ARM Cortex-M microcontroller

but I’m not certain what I need to change where. I do know that these are defined as such:

#define configPRIO\_BITS \_\_NVIC\_PRIO\_BITS  
#define \_\_NVIC\_PRIO\_BITS 3 /\*!\< Number of Bits used for Priority Levels \*/

Thanks,

C-Coder

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 24, 2021, 11:52pm UTC](https://forums.freertos.org/t/task-notification-problems/11840/3 "2021-02-24T23:52:47Z")

</div>

What is the value of `configMAX_SYSCALL_INTERRUPT_PRIORITY` in your `FreeRTOSConfig.h` and what is the priority of the USB ISR which calls `xTaskNotifyIndexedFromISR`?

You need to ensure that the logical priority of the USB ISR is less than or equal to `configMAX_SYSCALL_INTERRUPT_PRIORITY`. Note that for Cortex-M, numerically higher priority means logically lower priority.

Thanks.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [February 25, 2021, 12:11am UTC](https://forums.freertos.org/t/task-notification-problems/11840/4 "2021-02-25T00:11:32Z")

</div>

Sounds like you need to set the priority of the USB interrupt, and it still has the default of 0, which for ARM processors is the HIGHEST priority, and above the max allowed.

---

<div class="post-metadata">

**Author:** ![C-Coder](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@C-Coder](https://forums.freertos.org/u/C-Coder)\
**Post date:** [February 25, 2021, 4:02am UTC](https://forums.freertos.org/t/task-notification-problems/11840/5 "2021-02-25T04:02:59Z")

</div>

Guarav,

```auto
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	5

#define configPRIO_BITS __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 3 /*!< Number of Bits used for Priority Levels */

```

I’m not seeing any calls to NVIC\_SetPriority, so I probably need to add one or more in.

C-Coder

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 25, 2021, 4:26am UTC](https://forums.freertos.org/t/task-notification-problems/11840/6 "2021-02-25T04:26:39Z")

</div>

Yes, you need to lower the priority of USB interrupt.

Thanks.

---

<div class="post-metadata">

**Author:** ![C-Coder](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@C-Coder](https://forums.freertos.org/u/C-Coder)\
**Post date:** [February 25, 2021, 3:10pm UTC](https://forums.freertos.org/t/task-notification-problems/11840/7 "2021-02-25T15:10:36Z")

</div>

That’s all it took.

Cheers mate!
