# Api in interrupt CM3

**URL:** <https://forums.freertos.org/t/api-in-interrupt-cm3/199>\
**Category:** Kernel\
**Created:** [September 24, 2009, 1:20pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199 "2009-09-24T13:20:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 24, 2009, 1:20pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/1 "2009-09-24T13:20:47Z")

</div>

**[zerbax](https://sourceforge.net/u/zerbax/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#6d83):

I’ve a problem with FreeRtos, i’m programming on CORTEX M3.  
My application is very easy, there is a task that waits on semaphore  
and toggle a led, the semaphore is give by a ISR:

void EXTI9\_5\_IRQHandler(void)  
{

&nbsp;&nbsp;&nbsp;&nbsp; portBASE\_TYPE xHigherPriorityTaskWoken= pdFALSE;

&nbsp;&nbsp;&nbsp;&nbsp; xSemaphoreGiveFromISR(xSem, &amp;xHigherPriorityTaskWoken);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(xHigherPriorityTaskWoken==pdTRUE)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portYIELD();  
}

The problem is that when the API &quot;xSemaphoreGiveFromISR&quot; is called ,  
the programm crashes.  
If i don’t use API the programm runs…  
Can someone help me?  
thanks

---

<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:** [September 24, 2009, 1:55pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/2 "2009-09-24T13:55:20Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#9a07):

Can you check that the semaphore xSem was created correctly and is not NULL.

Also, can you step into the xSemaphoreGiveFromISR() function to see at what point the crash occurs.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 24, 2009, 2:48pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/3 "2009-09-24T14:48:56Z")

</div>

**[zerbax](https://sourceforge.net/u/zerbax/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#1069):

The semaphore is created correctly.  
I see, that xSemaphoreGiveFromISR() runs correctly, the program crashes on portYIELD(), infact doesn’t force context switch…

---

<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:** [September 24, 2009, 2:56pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/4 "2009-09-24T14:56:00Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#e8af):

portYIELD() should not cause a context switch directly - the switch is just pended.&nbsp; Try placing a break point on the function called xPortPendSVHandler() in port.c.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 24, 2009, 3:19pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/5 "2009-09-24T15:19:41Z")

</div>

**[zerbax](https://sourceforge.net/u/zerbax/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#468e):

i can’t place a break point, because i don’t simulate the program…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 24, 2009, 3:27pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/6 "2009-09-24T15:27:16Z")

</div>

**[zerbax](https://sourceforge.net/u/zerbax/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#0ba3):

But i place on the function xPortPendSVHandler() a led that have to toggle, but doesn’t toggle…

---

<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:** [September 24, 2009, 3:35pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/7 "2009-09-24T15:35:52Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#17f7):

&lt;code&gt; i can’t place a break point, because i don’t simulate the program…&lt;/code&gt;

I don’t understand that - are you running in a simulator or on real hardware?

&lt;code&gt;But i place on the function xPortPendSVHandler() a led that have to toggle, but doesn’t toggle…&lt;/code&gt;

xPortPendSVHandler() is a naked function written in assembly - you cannot add code to it unless it too is assembly code.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 24, 2009, 3:39pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/8 "2009-09-24T15:39:48Z")

</div>

**[zerbax](https://sourceforge.net/u/zerbax/)** wrote on [Thursday, September 24, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#c84f):

I’m running in real hardware…  
Regards

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 25, 2009, 12:32pm UTC](https://forums.freertos.org/t/api-in-interrupt-cm3/199/9 "2009-09-25T12:32:48Z")

</div>

**[zerbax](https://sourceforge.net/u/zerbax/)** wrote on [Friday, September 25, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/0aa9c23b/#9ac3):

I’ve tried to take off the function portYIELD, and program runs…  
but now the time between the ISR and handler task is not deterministic…
