Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

task in stuck in running queue stm32f407

Posted by https://www.google.com/accounts on August 24, 2013
Hello,
I am using stm32f407 with freertos 7.5.0. I have an ethernet task (it has the highest priority) which gets stuck in running queue and is not getting executed anymore. All other tasks with lower priority are actually running in the system.

Selected portion of the code is displayed below. On startup i have created a binary semaphore which is given by the interrupt handler whenever a packet is received. I have tried to implement a NAPI sort of behaviour so i am disabling the interrupt and it is reenabled later when descriptor chain is traversed. There is a high priority task running which takes the above mentioned semaphore and calls a function to traverse the descriptor chain. After some time, 15-20 minutes of packet processing (flood ping), my ethernet thread which was supposedly waiting on the semaphore stops responding i.e. my led 2 stops blinking and since my function which enables ethernet interrupt is not called, so does my interrupts.
Now there is a low priority blinker task which is responsible for blinking another led. That keeps on running. Via gdb i can see idle task getting scheduled regularly. the state of all the tasks as reported by vTaskList() is
Eth_if R 4 302 2
IDLE R 0 38 6
tcpip_thr B 3 858 1
blinker B 0 93 3
Tmr Svc B 2 224 7
server S 0 39 4
data_hand S 4 38 5




xSemaphoreHandle eth_Semaphore = NULL;

//ethernet interrupt handler
void ETH_handler(void)
{
uint32_t tmp,tmp2;
signed portBASE_TYPE sem_ret;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

tmp = ETHDMA->SR;
/* Frame received */
if ( tmp & ETH_DMASR_RS)
{
//received a packet
/* Give the semaphore to wakeup LwIP task */
ETH_STATS(stats.ints.rs);
sem_ret = xSemaphoreGiveFromISR( eth_Semaphore, &xHigherPriorityTaskWoken );
if (sem_ret == pdPASS)
{
eth_int_ds++;
NVIC_DISABLE_INT(ETH_IRQn);
}
}
if( xHigherPriorityTaskWoken != pdFALSE )
{
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}
}

void ethernetif_input( void * pvParameters ) // task named eth_if
{
struct pbuf *p,*n;
char i=0;
eth_start(); // enables the ethernt interrupt and creates a binary semaphore vSemaphoreCreateBinary(eth_Semaphore);

for( ;; )
{
if (xSemaphoreTake( eth_Semaphore, 100)==pdTRUE) //blocking time is 100 ticks
{
//traverse the descriptors and send to lwip from here
//currently lwip code is commented out to debug the problem
}
if (i%2)
led_off(LED_RED2);
else
led_on(LED_RED2);
}
}

RE: task in stuck in running queue stm32f407

Posted by https://www.google.com/accounts on August 24, 2013
Forgot to add priorities of various taks and interrupt


#define configUSE_PREEMPTION 1
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
#define configIDLE_SHOULD_YIELD 1
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5

NVIC_SET_PRIORITY(ETH_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);

xTaskCreate(ethernetif_input, (signed char*) "Eth_if", 350 , NULL, 4, NULL) ;


RE: task in stuck in running queue stm32f407

Posted by MEdwards on August 24, 2013
“I am using stm32f407 with freertos 7.5.0”


If you are using the ST peripheral drivers then you should update to 7.5.2. 7.5.2 is just for STM32 users. See the change history
http://www.freertos.org/History.txt

“if( xHigherPriorityTaskWoken != pdFALSE )
{
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}”


You don't need the if(){} because that is done for you inside the portEND_SWITCHING_ISR() macro.

When the ethernet task gets stuck, place a break point in the ethernet interrupt to see if it is still getting called. It might be that its interrupt was never enabled again.

RE: task in stuck in running queue stm32f407

Posted by MEdwards on August 24, 2013
“NVIC_SET_PRIORITY(ETH_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);”


Where is that function coming from? Again if you are using the STM32 peripheral driver libraries you also need to set the mapping of priority bits so all bits are preemption priority. The ST libraries crash if you leave it at its default value. See the red text on this link
http://www.freertos.org/RTOS-Cortex-M3-M4.html

Do that, and also set configASSERT() to a null loop if you have not done so already. If you are using V7.5.2 that will trap any configuration mistake.

RE: task in stuck in running queue stm32f407

Posted by https://www.google.com/accounts on August 24, 2013
Hi,
thanks for helping me. below is the defination of the NVIC_SET_PRIORITY
Also as stm32f407 has 4 bits of priority, i am using a priority group value of 3 instead of 4. A value of 3 means 4 bits are being used for group priority (arm reference manual). And my code does work for some time before it dies out.

#define __NVIC_PRIO_BITS 4

static inline void NVIC_SET_PRIORITY(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHPR[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M System Interrupts */
else {
NVIC->IPR[((uint32_t)(IRQn)/4)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */
}


RE: task in stuck in running queue stm32f407

Posted by MEdwards on August 24, 2013
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); sets the value to 3, so it sounds like you have it right.

Are you using V7.5.2 yet? If so you will know if you have it wrong.

“And my code does work for some time before it dies out.”


That is what would happen if you had it wrong.

RE: task in stuck in running queue stm32f407

Posted by https://www.google.com/accounts on August 25, 2013
Hi,

upgraded to 7.5.2. it seems that problem was in the NVIC_SET_PRIORITY. fixed that and system seems stable
thanks


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists