cancel
Showing results for 
Search instead for 
Did you mean: 

freertos and uart

BHure.1
Associate III

I am trying to capture UART message once a button is pressed. I have implemented the functions to do that and while debugging i see the steps required to do that.

However, when the UART communication happen, i get strange messages (check photo)

Note: i am not using a Queue nor a separate to do the UART comm. However, you can see a GUI_Task mentioned in the UART message (that is the main task and this is not used within the code)

My code is the following:

if(xx==0)

   {

    HAL_UART_Transmit(&huart2, pData, sizeof(pData), HAL_MAX_DELAY);

    char newline[2] = "\r\n";

   HAL_UART_Transmit(&huart2, (uint8_t *) newline, sizeof(newline), 1);

    xx++;

   }

   HAL_Delay(1000);

   char in[8];

   HAL_UART_Receive(&huart2, (uint8_t *)in, 8, 1000);

   HAL_UART_Transmit(&huart2, (uint8_t *)in, 8, 1);

   HAL_UART_Transmit(&huart2, (uint8_t *) "mata", 28, 1);

    HAL_UART_Receive_DMA(&huart2, pData1, sizeof(pData1));

   HAL_Delay(2000);

   HAL_UART_Transmit(&huart2, pData1, sizeof(pData1),1);

    xx=0;

 return valoare;

8 REPLIES 8
Alexandre RENOUX
Principal

Hello BHure.1,

You are talking about a photo but I cannot see any.

We lack information to be able to help you. What board are you using ? What IDE ? TouchGFX version ? Every time you post something you should give as much details as possible about the setup to get a quick and useful answer. Also, you code is insufficient. Unfortunately, this does not help figuring out the problem.

Maybe you can also enclose your project.

/Alexandre

Hello Renoux,

Discovery Board is F429. IDE: Stm32CubeIDE ; Touchgfx: 4.16

0693W000008yXPVQA2.jpg 

I attached the photo.

Michael K
Senior III

I bet it's a stack overflow. When I was first starting with FreeRTOS and TouchGFX i would wonder why some of my arrays would sometimes get populated with the words "TouchGFX_Task", among other garbage. Try increasing the task stack size in CubeMX.

HAL_UART_Transmit(&huart2, pData, sizeof(pData), HAL_MAX_DELAY);

Is pData an array or a pointer? If it's an array you should be fine, but if it's a pointer, sizeof(pData) will return the size of a pointer (usually 4bytes).

BHure.1
Associate III

Well, i defined them as arrays.

uint8_t pData[6]="send\n";

uint8_t pData1[30];

Do you think the issue is that i did not make a different task for running the UART? My plan was using SPI to get the value from a sensor, but i have the same issue of not retrieving the values.

No, I think the issue is a some sort of overflow. Somehow you are trying to read or write outside of the bounds of your arrays and into the section where FreeRTOS stores it's stack information (edit: or where your program stores other strings)

HAL_UART_Transmit(&huart2, (uint8_t *) "mata", 28, 1);

Just noticed this. Dangerous! Is it even defined behavior to cast a string literal as uint8_t*? Even if you can, your string is 5 characters (m, a, t, a, \0) and you telling the function send 28. No wonder you are reading strange information.

Edit: did a bit more digging and yes, that behavior is defined but absolutely having 28 in the length field is the reason you are having that issue. The UART functions don't care about null terminators!

Thanks for the input. I added the value of the sent buffer to check Still why pData (as "send") that is structured with sizeof() is not showing up?

Is the if statement even being entered? Is xx ever == 0? Why do you run xx++ only to set it to zero at the end of the snippet? It makes no sense in the context of the code you've provided. Step through it with a debugger and make sure your program flow is as you intend.

Well, the same code works ok when not using touchgfx + freertos (as intended).

This is the uart channel . You can see the send message, but no response from the receptor.

A lot of NUL flags. What's wrong?

0693W000008ydqhQAA.png