STM32F4 Interrupt + FreeRTOS

fjullien wrote on Thursday, July 24, 2014:

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(;:wink: {
// 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.

rtel wrote on Thursday, July 24, 2014:

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 ) 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.

fjullien wrote on Thursday, July 24, 2014:

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 :wink:

I’ll get back to this later.

Thanks for your answer anyway.

Franck.