# A interrupt problem with PIC32

**URL:** <https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047>\
**Category:** Kernel\
**Created:** [January 20, 2010, 9:01pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047 "2010-01-20T21:01:33Z")\
**Posts on this page:** 15\
**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:** [January 20, 2010, 9:01pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/1 "2010-01-20T21:01:33Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Wednesday, January 20, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#f027):

When I use xSemaphoreGiveFromISR in one of my ISR (ipl3), my code hangs. In RTOS viewer, the xTickCount is zero all the time and only shows 3 out of 8 tasks in the viewer. This topic could be discussed before. After searching and reading this forum, I am still not sure what would cause it and how to correct it. Could you give me the possible reasons that you can guess based upon my description? Or, let me know what else I can provide to solve it.&nbsp; I’ll check with it tomorrow. Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 20, 2010, 9:15pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/2 "2010-01-20T21:15:17Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Wednesday, January 20, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#a2c2):

Is the priority of the interrupt equal to or lower than configMAX\_SYSCALL\_INTERRUPT\_PRIORITY? Do you have stack overflow checking on?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 20, 2010, 10:44pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/3 "2010-01-20T22:44:03Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Wednesday, January 20, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#7c80):

my configMAX\_SYSCALL\_INTERRUPT\_PRIORITY is equal to 0x03, which is equal to the ISR priority level.  
I’ll try to figure out if your 2nd question true or not tomorrow. Thanks for the reply.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 21, 2010, 4:10pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/4 "2010-01-21T16:10:07Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Thursday, January 21, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#ec8a):

I set a break point inside the function vApplicationStackOverflowHook( void ), I did&nbsp; not observe a break, so, I assume that there is no overflow happened.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 3:22pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/5 "2010-01-29T15:22:18Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#f5f0):

After days working on it, I found that my code hangs at \_general\_exception\_handler. It always happen when the code running in function:  
xQueueGenericSendFromISR  
line:  
if( pxQueue-\>uxMessagesWaiting \<= pxQueue-\>uxLength )  
after stepping off this line, my code ends up general exception. Any clue?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 3:28pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/6 "2010-01-29T15:28:10Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#306f):

Sorry, I changed “\<” to “\<=” in  
if( pxQueue-\>uxMessagesWaiting \<= pxQueue-\>uxLength )  
but the same result.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 4:01pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/7 "2010-01-29T16:01:32Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#4d21):

If the interrupt priority is correct, then I’m going for stack overflow or some other form of data corruption within the queue. It might be that the PIC is raising an exception before the stack overflow is checked.

Have you written the ISR \*exactly\* as per the examples?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 4:20pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/8 "2010-01-29T16:20:22Z")

</div>

**[woops\_](https://sourceforge.net/u/woops_/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#8126):

PIC32 has a separate interrupt stack. Only the task stacks are checked for overflowing.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 4:30pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/9 "2010-01-29T16:30:18Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#7925):

one more update:  
I checked the \*pxQueue in Watch window. what I caught are when code stop at line:  
if( pxQueue-\>uxMessagesWaiting \< pxQueue-\>uxLength ) (it always can stop here, but here is the key)  
then in watch window,  
1. If the uxMessagesWaiting value is 0x00000000 and uxLength value is 0x00000001, my code will run fine.  
2. If the uxMessagesWaiting value is 0x00000000 and uxLength value is 0x40976000, the code must end up general exceptioni. (this happen most of time).  
In case 1, I type pxQueue-\>uxMessagesWaiting and pxQueue-\>uxLength in watch window, they both show value 0xA00038B0.  
in case 2, they both show value 0x40976000  
I am not able to interpret the phenomenon.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 4:36pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/10 "2010-01-29T16:36:38Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#1aad):

\>\>Have you written the ISR \*exactly\* as per the examples?  
I got not only one ISR using xSemaphoreGiveFromISR, but only one is not working. I use copy and paste technic to write my ISR, chen change parameters, so…

\>\>PIC32 has a separate interrupt stack. Only the task stacks are checked for overflowing.  
I doubled the configISR\_STACK\_SIZE, but seem not working.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 7:58pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/11 "2010-01-29T19:58:01Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#0e09):

How to prevent interrupt which calls API function occurring before scheduler start? this might solve my problem.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 8:04pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/12 "2010-01-29T20:04:27Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#11df):

Seem that it is taken care by FreeRTOS automatically. Am I right?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 8:39pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/13 "2010-01-29T20:39:07Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#4068):

Provided you don’t change the interrupt bits yourself, then yes it should be taken care of.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 8:40pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/14 "2010-01-29T20:40:46Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#e954):

Inspect xSchedulerRunning from the exception handler to see if the scheduler was actually started before it crashed.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 29, 2010, 8:47pm UTC](https://forums.freertos.org/t/a-interrupt-problem-with-pic32/1047/15 "2010-01-29T20:47:17Z")

</div>

**[wne1](https://sourceforge.net/u/wne1/)** wrote on [Friday, January 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2acb9dfb/#16ff):

xSchedulerRunning&nbsp; value is 0x00000001 when I check at general exception handler point.
