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

Stuck in vPortEnterCritical

Posted by znatok on April 18, 2014

Hi, What can be a reason to stuck (or get exception) in call to vPortEnterCritical ?

Can one task that enters critical section dead lock with another task that is trying to enter critical section? Can theoretically task that enters critical section intentionally let other task to run? What if task in critical section will try to block on semaphore for instance?

A few background. I'm on STM32F2xx running lwip. I've used vPortEnterCritical to implement (port) sysarchprotect required by lwip. Lwip suggests use mutex or semaphore for this purpose although I though my approach was also good until got stuck.


Stuck in vPortEnterCritical

Posted by rtel on April 18, 2014

If you are stuck actually inside the vPortEnterCritical() function then the only real reason can be that you are calling it when the Cortex-M3 is in a unprivileged mode. It is just a sequential piece of code, so there is nowhere to get stuck. If you are using the standard Cortex-M FreeRTOS port (as opposed to the MPU version) then all code should be privileged so that should never happen.

I would however suggest that critical sections would definitely not be the way to provide the thread safety in lwIP. For one thing the critical section is likely to be very long, making you system very unresponsive to interrupts. The second being you might be waiting in the critical section for an interrupt that the critical section has itself disabled - hence deadlock.

If you are using an STM32 then make sure you are using a recent version of FreeRTOS and that you have configASSERT() defined - as the recent versions have additional assert points specifically to trap the most common mistakes people make when setting interrupt priorities on those parts (especially with regards to the split between preemption and sub priority).

http://www.freertos.org/FAQHelp.html

Regards.


Stuck in vPortEnterCritical

Posted by znatok on April 18, 2014

Hi, Thanks for your reply. I know about interrupts issue and I have set all my interrupts to single level that guaranty no interrupts preemption.

I went forward and did following:

sysprott sysarchprotect(void) { xtrace("lock"); vTaskDelay(30); vPortEnterCritical(); xtrace("done"); vTaskDelay(20); return 1; }

void sysarchunprotect(sysprott pval) { ( void ) pval; xtrace("unlock"); vPortExitCritical(); }

The end of my trace looks like: lock done unlock lock And here I stuck. Assuming some bogous code changes privileged mode where can I look for it in Cortex-M3 registers and what exception should I expect in case of violation. Also manual mention some stack usage changes for vPortEnterCritical (NOTE: This may alter the stack (depending on the portable implementation) so must be used with care!) Can I expect some stack issue? Maybe overflow?


Stuck in vPortEnterCritical

Posted by davedoors on April 18, 2014

I don't think the print messages tell you anything about where your code is stuck, you need to have a debugger to tell you that, especially as you presumably have lots of tasks that could be calling the function. If it is stuck there then I would guess it is more likely to be stuck in the xtrace() function than in vPortEnterCrtitical(). The Cortex port will not change the stack.

I know about interrupts issue and I have set all my interrupts to single level that guaranty no interrupts preemption.

but again that is no guarantee it will do what you want if you have the preemption bits set to anything other than 'all bits are preemption bits'. On the STM32 that is not the default state. Did you read the links already posted? Did you use FreeRTOS 8 with configASSERT defined? (or v7.6.0) as already suggested?


Stuck in vPortEnterCritical

Posted by znatok on April 18, 2014

Hi, It is not an Interrupt issue. I'm using 16 sub priorities so I'm guaranteed to have no Int preemption. Besides this is a code that runs a lot. The problem occurs always in the same place (same flow) and in very specific condition. I have to specially configure some network functionality to get where. I'm on FreeRTOS 7.5.2

I did some optimization and write trace directly to UART data register: sysprott sysarchprotect(void) { ((uint16_t)(0x40004C04))='L'; vTaskDelay(2); vPortEnterCritical(); ((uint16_t)(0x40004C04))='d'; vTaskDelay(2); return 1; }

void sysarchunprotect(sysprott pval) { ( void ) pval; vPortExitCritical(); ((uint16_t)(0x40004C04))='U'; vTaskDelay(2); }

Yet I end up with ...LdULdUL I can try to go inside vPortEnterCritical and try to find last instructions being executed.


Stuck in vPortEnterCritical

Posted by davedoors on April 18, 2014

I dont think we can give up our public holiday time for free to help you any further for three reasons. 1) You have not followed the advice already provided to see if it fixes the problem so there seems little point in providing more. 2) You are using sub priorities which the big bold red text on the pages you have been referred to twice already tells STM32 users that they need to change that. 3) From your posts it sounds like you are doing this without a debugger so you don't actually know what your chip is doing when it stops operating, and your guess as to what it is doing is going to be better than ours as you have the hardware in front of you.


Stuck in vPortEnterCritical

Posted by znatok on April 19, 2014

OK, I'm sorry for neglecting your suggestions and going to work first on first 2 points in your email. Just one small question should I have at least v7.6.0 for ASSERTION ?

You are right I have no debugger. HW does not support it so I have to do tricks. I'll keep you posted after finishing steps 1,2 above.


[ 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