Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


STM32F205 xPortPendSVHandler Problem

Posted by Pandi Vijayaraj on July 21, 2012

I'm facing a problem while writing an UART application in STM32F205 using FreeRTOS.
I have two tasks one will send data out through UART and other will read data coming in through the same UART and process it.
I have assigned the Receiving task with priority (tskIDLE_PRIORITY+2) and writing task with the priority (tskIDLE_PRIORITY+1).
UART IRQ uses TXE interrupt to send data out and it receives a data for every occurance of the RXNE interrupt and places the data into a buffer, from which my receiving task will read.

I have used the NVIC Configurations as instructed in FreeRTOS manual


NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;


My Receive Task is blocked on a Binary semaphore which is actually released by IRQ handelr for every byte reception.
IRQ handler uses these calls to release the Semaphore

xSemaphoreGiveFromISR(ParseSem, &xHigherPriorityTaskWoken);

My application works as i expected.
I dont face any problem when I send minimal amount of data out. If i periodically send data lessthan 50 bytes for a long time no problem.
If i try to send 300 bytes continuously, i'm receiving some of the data what i'm sending out and HardFault ocuurs.
I suspect a corruption in NVIC, it handles TXE as RXNE and my IRQ reads in the same data that is sent out.

Call Stack indicates the hardFault occurance in " xPortPendSVHandler+29 ".
If I trace this leads to xPortPendSVHandler

ldr r0, [r1]/* The first item in pxCurrentTCB is the task top of stack. */

I can't make much out of this hint. Also I tried to debug in many ways, like using Queue instead of Semaphore as shown in FreeRTOS example. But HardFault can't be prevented.


RE: STM32F205 xPortPendSVHandler Problem

Posted by Richard on July 23, 2012
If the fault is occurring on that line, then it looks like you have a RAM corruption somewhere that has corrupted the value loaded into R1 prior to that line of code.

Do you have stack overflow detection switched on?
Is your UART in an error state (overrun error, for example) that is not being handled?
How is your UART processing received bytes (placing them in a circular buffer, for example)?


RE: STM32F205 xPortPendSVHandler Problem

Posted by Pandi Vijayaraj on July 23, 2012
Yes I have enabled stack overflow checking in my code. I have used the "vApplicationStackOverflowHook" to just print the name of the task having corrupted stack. But this vApplicationStackOverflowHook is never executed. Aiso i checked the size of stacks for all the tasks in FreeRTOS plugin for IAR. It is showing all the tasks having size >256.

My UART IRQ handler will receive a byte for every RXNE interrupt and copies it to a circular buffer. Then it will signal to a task using a semaphore.
For debugging purpose i tweaked this logic and implemented similar to a FreeRTOS demo program given for Cortex-M3. IRQ reads a byte for every RXNE interrupt and palces it in a queue. The corresponding task is blocked on the queue.
in this way i'm making sure data is read immediately after the occurrence of interrupt. But then also hardfault occurs.

Actually i should not receive the same data what i'm sending out. But i'm receiving some unwanted RXNE interrupts and reading the same data i'm sending out.

if i check UART overrun error flag after hardfault, it is set.

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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner