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
#define configKERNEL_INTERRUPT_PRIORITY 255 #define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 #define configLIBRARY_KERNEL_INTERRUPT_PRIORITY 15 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
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); portEND_SWITCHING_ISR(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.