cancel
Showing results for 
Search instead for 
Did you mean: 

Hi I Have been working in touchgfx for month, now my task is to enable uart function in touchgfx and to print the received things in textarea. For that i had enabled the textarea resource id with buffer size of 30 and enabled the HAL_UART in cubemx

ABabu.1
Associate

Here is the code for the touchgfx i had called the virtual function "data" when screen 1 is entered. Plesae let me know is this was the correct method for UART for printing the received data. If someone had sample code for UART please Post it.

***##screen1view.cpp##***

#include <gui/screen1_screen/Screen1View.hpp>

#include "main.h"

#include "stm32f4xx.h"

#include "stm32f4xx_hal.h"

#include "stm32f4xx_hal_uart.h"

#include "stm32f429i_discovery.h"

extern UART_HandleTypeDef huart5;

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};

 /**Configure the main internal regulator output voltage

 */

 __HAL_RCC_PWR_CLK_ENABLE();

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

 /**Initializes the CPU, AHB and APB busses clocks

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLM = 4;

 RCC_OscInitStruct.PLL.PLLN = 72;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

 RCC_OscInitStruct.PLL.PLLQ = 3;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

   //Error_Handler();

 }

 /**Initializes the CPU, AHB and APB busses clocks

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

                             |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)

 {

  // Error_Handler();

 }

 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;

 PeriphClkInitStruct.PLLSAI.PLLSAIN = 60;

 PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;

 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_4;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)

 {

   //Error_Handler();

 }

}

extern void MX_UART5_Init(void)

{

 /* USER CODE BEGIN UART5_Init 0 */

 /* USER CODE END UART5_Init 0 */

 /* USER CODE BEGIN UART5_Init 1 */

 /* USER CODE END UART5_Init 1 */

 huart5.Instance = UART5;

 huart5.Init.BaudRate = 115200;

 huart5.Init.WordLength = UART_WORDLENGTH_8B;

 huart5.Init.StopBits = UART_STOPBITS_1;

 huart5.Init.Parity = UART_PARITY_NONE;

 huart5.Init.Mode = UART_MODE_TX_RX;

 huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart5.Init.OverSampling = UART_OVERSAMPLING_16;

 if (HAL_UART_Init(&huart5) != HAL_OK)

 {

   //Error_Handler();

 }

 /* USER CODE BEGIN UART5_Init 2 */

 /* USER CODE END UART5_Init 2 */

}

Screen1View::Screen1View()

{

}

void Screen1View::setupScreen()

{

}

void Screen1View::tearDownScreen()

{

}

uint16_t Rxbuffer[30];

void Screen1View::data()

{

while(1)

{

   HAL_GPIO_TogglePin(GPIOG,GPIO_PIN_13); // used for checking the program flow this line works fine

   HAL_UART_Receive_IT(&huart5,Rxbuffer,15);

   Unicode::snprintf(textArea1Buffer, 30, "%d", Rxbuffer);

   textArea1.resizeToCurrentText();

   textArea1.invalidate();

}

}

***##screen1view.hpp##***

#ifndef SCREEN1_VIEW_HPP

#define SCREEN1_VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>

#include <gui/screen1_screen/Screen1Presenter.hpp>

class Screen1View : public Screen1ViewBase

{

public:

   Screen1View();

   virtual ~Screen1View() {}

   virtual void setupScreen();

   virtual void tearDownScreen();

   virtual void data();

protected:

};

#endif // SCREEN1_VIEW_HPP

1 REPLY 1
HP
Senior III

no, don't set up anything like this in the TouchGFX code.

you'd want to keep the UI separate from the hardware interaction code. well, I suppose that you can do it this way but I don't think anybody else does..

Maybe you can use my video on ringbuffers to help you along:

https://www.youtube.com/watch?v=6a_VNVWbYvU

The video is number 6 in a series on how to configure and set up TouchGFX with CubeIde integration so maybe you can get more information from those as well