rousea wrote on Wednesday, October 27, 2010:
I am developing a project using an STM32 ARM processor and FreeRTOS. there are 3 USARTS, and the RX ISR for each gives a semphore which is taken by task vUSART_RXcharReceived:
void vUSART_RXcharReceived(void* pvParameters){
portTickType TimeOut;
u8 Port;
TimeOut = portMAX_DELAY;
Port = *(u8*)pvParameters;
vSemaphoreCreateBinary(prvHIO.USART_RXcharReceived[Port]);
// Make sure the semaphore is cleared initially
xSemaphoreTake(prvHIO.USART_RXcharReceived[Port], 0);
while (1){
if (xSemaphoreTake(prvHIO.USART_RXcharReceived[Port], TimeOut) == pdPASS){ // If we received a char...
TimeOut = 35000/SysConfig.COMport[Port].BaudRate; // Time for 3.5 chars
if (TimeOut < 2)
TimeOut = 2;
}else{ // End of message
TimeOut = portMAX_DELAY;
xQueueSend(HIO.CheckMessage, &Port, portMAX_DELAY);
}
}
}
There are three insances of this task, one for each USART, and as you see they wait for a break in transmission then add an item to queue HIO.CheckMessage to identify which port now contains a message.
The queue is received by vCheckMessage:
void vCheckMessage(void* pvParameters){
s16 MsgLen, Response = DONE;
u8 DiagnosticsDisplayed;
u8 Port;
HIO.CheckMessage = xQueueCreate(15, sizeof(u8));
while (1){
xQueueReceive(HIO.CheckMessage, &Port, portMAX_DELAY);
|
|
|
}
}
I am testing it using traffic on only one USART. The programme works correctly for the first six messages, then fails, giving a Hard Fault exception, which means it has tried to access an invalid memory address. The fault always occurs as the code is running xQueueSend(HIO.CheckMessage, &Port, portMAX_DELAY) in vUSART_RXcharReceived((). I have pinpointed to error to task vListRemove( ) in FreeRTOS list.c. This copies a value to a pointer
pxList = ( xList * ) pxItemToRemove->pvContainer;
However, when the system fails it is because the value of this pointer is 0 (NULL), so when it is subsequently used the code attempts to write to Flash code space.
I obviously cannot change the code within FreeRTOS, yet I can’t see anything I am doing wrong to cause the problem. When the failure occurs I can look at the memory location of pxItemToRemove and see that all elements appear to hold sensiboe values except pvContainer, which is 0. I can’t put a watch on it to trap when it is set to 0, since it is constantly being updated when the code is running.
Any suggestions?
Regards
Alan Rouse