Use FreeRTOS on STM32f4

jimmjimm wrote on Tuesday, April 01, 2014:

Hi, i try to use FreeRtos on my program which run on Stm32f4 mcu.
and i meet a problem when i try to read data from sdio the whole system stuck at function"SD_WaitReadOperation" of
while(((SDIO->STA & SDIO_FLAG_RXACT)) && (timeout > 0))
{
timeout–;
}
this line.
i thought is transfer bit is not clear and try trace my program found the DMA interrupt is not running that i cant fix it cause the program is working totally fine when i didnt use rtos…

there is how i init interrupts
void NVIC_Configurationsd(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

and there is two interrupts
void SDIO_IRQHandler(void)
{
vTaskEnterCritical();
HAL_NVIC_ClearPendingIRQ(SDIO_IRQ_ISR);
SD_ProcessIRQSrc();
vTaskExitCritical();
}

void SD_SDIO_DMA_IRQHANDLER(void)
{
vTaskEnterCritical();
HAL_NVIC_ClearPendingIRQ(SIDO_DMA_IRQn_ISR);
SD_ProcessDMAIRQ();
vTaskExitCritical();
}

i found SDIO_IRQ is working but DMA is not how the rtos effect this interrupt anyone got any idea?

dumarjo wrote on Tuesday, April 01, 2014:

Hi,

I don’t know if this will help you but here my init of the sd card with
a stm32f4 MCU with freeRTOS

DSTATUSsdio_disk_initialize (void)
{
NVIC_InitTypeDef NVIC_InitStructure;
SD_Error res = SD_OK;

if(sdio_Init == STA_NOINIT)
{


	/* Configure the NVIC Preemption Priority Bits */
	  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

	  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
	  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
	  NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
	  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	  NVIC_Init(&NVIC_InitStructure);

	  NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
	  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
	  NVIC_Init(&NVIC_InitStructure);

	  SD_DeInit();

	  res =  SD_Init();
	  sdio_Init =0;

	if(res == SD_OK)
	  {
		res = (SD_Error)0x0;
	  }
}

return ((DSTATUS)res);
}

Jonathan

Le 2014-04-01 06:07, Jimmy SHEN a écrit :

Hi, i try to use FreeRtos on my program which run on Stm32f4 mcu.
and i meet a problem when i try to read data from sdio the whole
system stuck at function"SD_WaitReadOperation" of
while(((SDIO->STA & SDIO_FLAG_RXACT)) && (timeout > 0))
{
timeout–;
}
this line.
i thought is transfer bit is not clear and try trace my program found
the DMA interrupt is not running that i cant fix it cause the program
is working totally fine when i didnt use rtos…

there is how i init interrupts
void NVIC_Configurationsd(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

//Configure the NVIC Preemption Priority Bits //
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

and there is two interrupts
void SDIO_IRQHandler(void)
{
vTaskEnterCritical();
HAL_NVIC_ClearPendingIRQ(SDIO_IRQ_ISR);
SD_ProcessIRQSrc();
vTaskExitCritical();
}

void SD_SDIO_DMA_IRQHANDLER(void)
{
vTaskEnterCritical();
HAL_NVIC_ClearPendingIRQ(SIDO_DMA_IRQn_ISR);
SD_ProcessDMAIRQ();
vTaskExitCritical();
}

i found SDIO_IRQ is working but DMA is not how the rtos effect this
interrupt anyone got any idea?


Use FreeRTOS on STM32f4
https://sourceforge.net/p/freertos/discussion/382005/thread/725438de/?limit=25#1831


Sent from sourceforge.net because you indicated interest in
SourceForge.net: Log In to SourceForge.net

To unsubscribe from further messages, please visit
SourceForge.net: Log In to SourceForge.net


This message has been scanned for viruses and
dangerous content by MailScanner http://www.mailscanner.info/, and is
believed to be clean.


Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.

jimmjimm wrote on Thursday, April 03, 2014:

thanks a lot but its not working for me. im still stuck at this point and get really no idea about how to solve it, anyone can help?

tblackmon wrote on Thursday, April 03, 2014:

Not sure of the issue here, but I don’t believe you are supposed to call any FreeRTOS API from within an ISR unless it ends with FromISR.

Also, it just so happens that the processor you are using tends to have enough issues to require special notes about it.

http://www.freertos.org/RTOS-Cortex-M3-M4.html

Hopefully, your answer is somewhere in there.

rtel wrote on Thursday, April 03, 2014:

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

This is definitely wrong. The preemption priority cannot be above the maximum system call interrupt priority, and the maximum system call priority cannot be 0 (0 being the highest).

Likewise for the priority being set for the other interrupt.

Todd has already posted the link that describes how to set the interrupt priorities. I would also recommend using an up to date version of FreeRTOS with configASSERT() defined as the latest versions will automatically trigger an assert if you get these setting wrong. See FreeRTOS - Open Source RTOS Kernel for small embedded systems for a link to the assert documentation, as well as a lot of other documentation … like:

vTaskEnterCritical();

You cannot call that function from an interrupt. In fact, the function is not part of the documented API and should not even be called directly from a task, and definitely never called directly on a Cortex-M part. If you want a critical section inside an interrupt you need to use portSET_INTERRUPT_MASK_FROM_ISR()/portCLEAR_INTERRUPT_MASK_FROM_ISR(). Search for those functions inside FreeRTOS/Source/queue.c to see how they are used.

Regards.

trilogik wrote on Saturday, April 05, 2014:

Hi!

I am using the processor mentioned in this thread and although having read the pages mentioned here - and several others - and thereby finding the bug I had, I still have some unanswered questions:

  1. One may define the priority of an interrupt at maximum at configMAX_SYSCALL_INTERRUPT_PRIORITY. Does this also apply to standard tasks? Or may common tasks get any priority? And if they get a priority (logically) higher than an ISR, are they served with a higher priority, or do ISRs always come first and only have an own priority scheme in between several ISRs?

  2. It is said int the FAQ, that one needs to assign an ISR priority less than configMAX_SYSCALL_INTERRUPT_PRIORITY in order to get a stable system (“Therefore, any interrupt service routine that uses an RTOS API function must have its priority manually set to a value that is numerically equal to or greater than the configMAX_SYSCALL_INTERRUPT_PRIORITY setting.”). If I use an ISR, that does not inherit an API function, which priority setting may I use? As said by Real Time Engineers Ltd. in the last post, NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; would be wrong. But in the example given by the thread-starter, I don’t see no FreeRTOS-API call. So my question: May I - as stated - only use configMAX_SYSCALL_INTERRUPT_PRIORITY for ISRs with API calls, or is this a general guide of bevaiour for ISRs, no matter, if I use FreeRTOS API calls in the ISR or not?

Thanks for any hint in advance,
Dennis

richard_damon wrote on Saturday, April 05, 2014:

  1. TASKS do not have an interrupt priority. The task priority is a completely different thing than an interrupt priority. Interrupts will always interrupt a task (unless the task is in a critical section or disables interrupts), so in one sense, all interrupts are normally of a higher “priority” than tasks.

  2. If an interrupt makes no reference to any FreeRTOS API, then it can be of any interrupt priority supported by the hardware. I find there are generally very few of this type of interrupt, as it becomes tricky for the tasks to interact with these. You might have a periodic task checking global variables or the high priority interrupt might trigger a lower priority interrupt that can call the FreeRTOS API.