# STM32F4 Interrupt + FreeRTOS

**URL:** <https://forums.freertos.org/t/stm32f4-interrupt-freertos/5626>\
**Category:** Kernel\
**Created:** [July 24, 2014, 8:27am UTC](https://forums.freertos.org/t/stm32f4-interrupt-freertos/5626 "2014-07-24T08:27:20Z")\
**Posts on this page:** 3\
**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:** [July 24, 2014, 8:27am UTC](https://forums.freertos.org/t/stm32f4-interrupt-freertos/5626/1 "2014-07-24T08:27:20Z")

</div>

**[fjullien](https://sourceforge.net/u/fjullien/)** wrote on [Thursday, July 24, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/f5b3530c/#4f72):

Hello,

I know it is a recurrent topic but after I read all a could find about this, I still have a problem using interrupts in combination with FreeRTOS.

I’m using libopencm3. On my board I can run the libopencm3 USB stack in interrupt mode without problem. But, if I run a FreeRTOS task, it mess up things (I get my device always connect/disconnect). I didn’t look at the root cause of this connect/disconnect problem. However I suspect the usbd\_poll function (called in the USB ISR) to be preempted. My ISR is as simple as this:

> void otg\_fs\_isr(void)  
> {  
> usbd\_poll(msc\_dev);  
> }

And my task (I know, there is no vTaskDelay):

> static portTASK\_FUNCTION(vLEDFlashTask, pvParameters)  
> {  
> (void) pvParameters;  
> int i = 0;
> 
> for(;😉 {  
> // It waits for TX reg empty then send the char  
> usart\_send\_blocking(USART1, ‘A’);  
> gpio\_toggle(GPIOG, GPIO6);  
> }  
> }

I did setup all the priority bits as pre-emption priority:

> // Same as NVIC\_PriorityGroupConfig( NVIC\_PriorityGroup\_4 )  
> scb\_set\_priority\_grouping(SCB\_AIRCR\_PRIGROUP\_GROUP16\_NOSUB);

My ISR priority is 1:

> nvic\_set\_priority(NVIC\_OTG\_FS\_IRQ, 1);

I also tried to change the system handler priority for systick, svcall and pendsv (as for what I understood are priority ‘0’ by default):

> SCB\_SHPR(SCB\_SHPR\_PRI\_11\_SVCALL) = 12;  
> SCB\_SHPR(SCB\_SHPR\_PRI\_14\_PENDSV) = 13;  
> SCB\_SHPR(SCB\_SHPR\_PRI\_15\_SYSTICK) = 14;

However if I remove the usart\_send\_blocking call in the task, it works as expected. Anyone as a clue ?

Thanks in advance,

Franck.

---

<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:** [July 24, 2014, 8:35am UTC](https://forums.freertos.org/t/stm32f4-interrupt-freertos/5626/2 "2014-07-24T08:35:46Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, July 24, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/f5b3530c/#be5b):

I’m afraid I don’t know anything about this library, or its implementation. Are you aware that ST provide STM32Cube? ( [http://www.st.com/stm32cube](http://www.st.com/stm32cube) ) That has USB drivers and FreeRTOS included.

> My ISR priority is 1:

Is your interrupt making use of FreeRTOS API functions? If so then I can’t image 1 will be a correct value for this. What is configMAX\_SYSCALL\_INTERRUPT\_PRIORITY set to?

> I also tried to change the system handler priority for  
> systick, svcall and pendsv (as for what I understood are  
> priority ‘0’ by default):

The systick and pendsv priorities will be overwritten to their correct values by FreeRTOS anyway, and the svcall priority is not used other than to kick the kernel off.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 24, 2014, 7:24pm UTC](https://forums.freertos.org/t/stm32f4-interrupt-freertos/5626/3 "2014-07-24T19:24:28Z")

</div>

**[fjullien](https://sourceforge.net/u/fjullien/)** wrote on [Thursday, July 24, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/f5b3530c/#404d):

My interrupt does not use FreeRTOS API.

AFAIR, configMAX\_SYSCALL\_INTERRUPT\_PRIORITY is set to 5 (I don’t have access to my code right now).

Anyway, I think I’ll move to STM32CubeMX. I can’t spend too much time here. I just wanted to avoid STMCube, Windows and Atollic 😉

I’ll get back to this later.

Thanks for your answer anyway.

Franck.
