cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with osMessageQueue

jessie_chiu
Associate III

Hello.

I'm using the STM32U5A9J-DK development board to work on a project to display UART data on the screen textArea, and I've made sure that there are no problems with the communication between the PC and the STM32 UART, and with the process of Model-Presender-View displaying the data on the screen.

 

program flow:

UART signal from PC -> main.c program receives it and saves it to CMSIS queue, get the content of queue from Model.cpp -> pass string through ModelListener.

 

Here is my code:

main.c

 

char RxData[257]; // received data from UART
char Data[257]; // copy from RxData

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
	RxData[Size] = '\0';
	strncpy(Data, RxData, Size+1);

	if (osMessageQueueGetSpace(uartQueueHandle)>0)
	{
		osMessageQueuePut(uartQueueHandle, Data, 0 ,0);
		HAL_UART_Transmit(&huart1, (Data), Size+1, 10); // print Data array
	}

	HAL_UARTEx_ReceiveToIdle_IT(&huart1, RxData, 256);
}

 

After "Data" is put into the Queue, I transmit to PC for display, and then I can receive the full string.

 

Model.cpp

 

char String[257];
//char data[257] = "Hello";

void Model::tick()
{
	if (osMessageQueueGetCount(uartQueueHandle)>0)
	{
		if(osMessageQueueGet(uartQueueHandle, String, 0, 0) == osOK)
		{
			strncpy(RData, String, sizeof(String));
			modelListener -> uart_Data(RData); 
		}
	}
}

 

When I use "String" to receive, then copy it to RData and send it to View to display, the screen will display only 1~2 characters.

jessie_chiu_0-1711089386454.png

Another test I did was to replace "String" with the contents of data[256]. the text was displayed in full without going through the Queue.

 

I suspect it's a queue problem. Is there any way to display the content stored in the queue?

Here is my Queue setting, and my CubeIDE version is 1.15.0.

uartQueueHandle = osMessageQueueNew (2, sizeof(uint8_t), &uartQueue_attributes);

 

9 REPLIES 9
SofLit
ST Employee

Hello,

When you created your message queue how much size you configured for it?

PS: I suppose you solved your issue with UART in this thread

So please close that thread by clicking on "Accept as Solution" on the reply which solved your issue or answered your question. Otherwise share your solution and close it by accepting it by clicking the same button.

Thank you.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@SofLit Thanks for your reply.

This is my queue setting

jessie_chiu_0-1711093656197.png

------

About the previous thread
Yes, the UART communication issue has been resolved. But the struct access problem still exists.

And I'll share the UART solution for this development board later.

Your Queue size is 2.Increase it to the length of your string.

Item size need to be uint8_t as you are sending characters.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@SofLit I've tried to change it to uint8_t in cubeMX, but it automatically changes to uint16_t

Change the Queue size to your string length.

For item size see this thread. Are you using cubemx 6.11?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I've tried to change the Queue size to 10, but nothing is changed.

Hello,

You need to debug your issue by creating a simple project (as done in the other thread for UART) with only FreeRTOS having two tasks one sending messages and the second receiving it and find where it fails.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hi, @SofLit. the problem with the queue receiving incomplete messages is still there, but after I updated Cube MX, I was indeed able to change the data type to uint8_t. 

I would like to ask if it is possible to see the contents of the queue in debugger mode?