rksheth wrote on Tuesday, July 28, 2015:
Some info first:
HW: STM32F407 Discovery board
Compiler: gcc-arm-none-eabi-4_8-2014q2
Yes, demo code (and a fair bit of my code) runs fine on this device.
I’m implementing a USART trace logging feature to be used in a multi-task environment. The idea is that multiple tasks can send a message to the “debugQueue” and the “debugTask” will sequentially service them and write them out over USART. In order to implement this, I created a queue of the following type:
typedef struct{
uint16_t size;
trace_level_t level;
char buffer[UART_BUF_SIZE];
} debug_queue_msg_t;
I have tested the basic UART code and know that it works correctly.
What I am finding is that the strings that I place in the message buffer come out garbled when they are received by the debugTask.
Here’s an example:
I have inspected the message in GDB immediately before sending:
xQueueSend(debugQueue, &msg, 0);
and immediately after receiving it in the debugTask:
xQueueReceive(debugQueue, &msg, portMAX_DELAY );
Former:
(gdb) p msg
$2 = {size = 33, level = TRACE_MED, buffer = “SPEED HARD SET TO 0.75 DUTY CYCLE”, ‘\245’ <repeats 67 times>}
Latter:
(gdb) p msg
$3 = {size = 33, level = TRACE_MED,
buffer = “S”, ‘\245’ <repeats 72 times>, “\375\377\377\377\000\000\000\000”, ‘\245’ <repeats 16 times>, “\275\024”}
As you can see, the first character is still present but the rest of the string has been overwritten.
Not sure if I’m missing something obvious or if there’s something I don’t understand about using queues with FreeRTOS.
I should also point out that I’m aware that placing a 100 byte buffer within the queue message is not ideal - but I’m not sure whether there’s a fundamental issue with that or if it’s just bad practice because introduces some extra writes.
Any advice is appreciated!