# Regarding NVIC\_SetPriority() is set before the scheduler(vTaskStartScheduler) is started

**URL:** <https://forums.freertos.org/t/regarding-nvic-setpriority-is-set-before-the-scheduler-vtaskstartscheduler-is-started/15069>\
**Category:** Kernel\
**Created:** [May 13, 2022, 12:45pm UTC](https://forums.freertos.org/t/regarding-nvic-setpriority-is-set-before-the-scheduler-vtaskstartscheduler-is-started/15069 "2022-05-13T12:45:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prince](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@Prince](https://forums.freertos.org/u/Prince)\
**Post date:** [May 13, 2022, 12:45pm UTC](https://forums.freertos.org/t/regarding-nvic-setpriority-is-set-before-the-scheduler-vtaskstartscheduler-is-started/15069/1 "2022-05-13T12:45:49Z")

</div>

1. I am enabling the pheripherals and setting the priority with NVIC\_SetPriority() before the creation of FreeRTOS task and before starting the scheduler.

OBSERVATION:-

1. The interrupt set before creating task and staring of scheduler are not getting enable.

2. The control goes to default handler and the kernel stops working.

3. I have also tried disabling the interrupt before FreeRTOS scheduler is started then the code get stuck inside configASSERT that is because i am not setting priority correctly.

4. What if we call FreeRTOS ISR safe API from one of the ARM controller timer will that have any affect on FreeRTOS operations ?

Thanks and Regards  
Prince Tripathi

---

<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:** [May 13, 2022, 2:40pm UTC](https://forums.freertos.org/t/regarding-nvic-setpriority-is-set-before-the-scheduler-vtaskstartscheduler-is-started/15069/2 "2022-05-13T14:40:44Z")

</div>

This sounds like an error in the port layer, possibly in the code to setup and start the tic timer. I remember a similar error in the Xylinx Zync port where that code reset the NVIC, so any previous setup was lost.

It might help if you indicated what port you are using.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 13, 2022, 8:45pm UTC](https://forums.freertos.org/t/regarding-nvic-setpriority-is-set-before-the-scheduler-vtaskstartscheduler-is-started/15069/3 "2022-05-13T20:45:12Z")

</div>

> [@Prince](#):
>
> The interrupt set before creating task and staring of scheduler are not getting enable.

Do you mean they don’t get enabled, or they do get enabled but are masked? FreeRTOS will leave interrupts masked between calls to the FreeRTOS API and the scheduler being started to ensure interrupts don’t attempt a context switch before the scheduler starts.

> [@Prince](#):
>
> The control goes to default handler and the kernel stops working.

If the default handle executes then either you have not installed the interrupt handler in the vector table, or you have changed the vector base address since install the interrupt vector.

> [@Prince](#):
>
> - I have also tried disabling the interrupt before FreeRTOS scheduler is started then the code get stuck inside configASSERT that is because i am not setting priority correctly.

As per #1 - FreeRTOS does that already - at the processor level rather than on an interrupt by interrupt level though.

> [@Prince](#):
>
> What if we call FreeRTOS ISR safe API from one of the ARM controller timer will that have any affect on FreeRTOS operations ?

You don’t say when you want to call it - but if it is before the scheduler starts then it is probably ok provided you don’t use FreeRTOS objects that may attempt to use the scheduler, and don’t try to perform a context switch.

---

<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:** [May 16, 2022, 10:30am UTC](https://forums.freertos.org/t/regarding-nvic-setpriority-is-set-before-the-scheduler-vtaskstartscheduler-is-started/15069/4 "2022-05-16T10:30:39Z")

</div>

Just to add to what Richard already mentioned:

> [@Prince](#):
>
> The control goes to default handler and the kernel stops working.

Try to find out the interrupt which is firing.

> [@Prince](#):
>
> code get stuck inside configASSERT that is because i am not setting priority correctly.

If it is Cortex-M, then you need to correctly set the interrupt priority. Here is some useful information - [RTOS for ARM Cortex-M](https://www.freertos.org/RTOS-Cortex-M3-M4.html)

Thanks.
