Skip to main content
Graduate II
March 22, 2024
Question

Problems with osMessageQueue

  • March 22, 2024
  • 1 reply
  • 3793 views

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);

 

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    March 22, 2024

    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.

    Graduate II
    March 22, 2024

    @mƎALLEm 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.

    Technical Moderator
    March 22, 2024

    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.