cancel
Showing results for 
Search instead for 
Did you mean: 

Control Pins and communicate via usart issue

FLine.1
Associate II

Helleo,

I am newbie in Touchgfx and I try developing first project.

I am willing to data transfer stm32746 to pc via usart and control pins.

When I click the button stm doesnt send data via usart or stm doesnt control pins.

Screen1View.cpp codes:

#include <gui/screen1_screen/Screen1View.hpp>
#include "stm32f7xx_hal.h"
extern UART_HandleTypeDef huart2;
 
Screen1View::Screen1View()
{
 
}
 
void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
}
 
void Screen1View::tearDownScreen()
{
    Screen1ViewBase::tearDownScreen();
}
 
void Screen1View::led_on()
{
 
/*	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_2|GPIO_PIN_5
	                          |GPIO_PIN_3, GPIO_PIN_SET);
*/
	//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_5);
	//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_6);
   // textArea1.setVisible(true);
	char com_cevap[12] ="adc_veri\r\n ";
	HAL_UART_Transmit(&huart2, (uint8_t *) &com_cevap, 12, 200);
    btndurum.setAlpha(254);
    btndurum.invalidate();
 
}
 
void Screen1View::led_off()
{
/*	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_2|GPIO_PIN_5
	                          |GPIO_PIN_3, GPIO_PIN_RESET);
*/
	//HAL_GPIO_WritePin(GPIOD, GPIO_PIN_5, GPIO_PIN_RESET);
	//HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_RESET);
    btndurum.setAlpha(50);
    btndurum.invalidate();
 
}

0693W000006GtqXQAS.png 

please tell me whats wrong? Could i control pins or data transfer in button click?

I use STMCubeIDe 1.5.1, Visual Studio 2019 and last framework.TouchGfx 4.15

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief III

DISCO-F746NG | Mbed read image with pinout description

View solution in original post

22 REPLIES 22
MM..1
Chief III

You need debug your code, because from your info we cant help.

Yes you can control activated GPIO , or use quick transfers. For slow is better use IT DMA or next thread in RTOS.

FLine.1
Associate II

hello,

If you have sample project about uart, please share it.

I added my debug file. How can i get sample videos touchgfx.

You missunderstand me , Debug folder, that you zip is totaly unusable for help you.

FLine.1
Associate II

i added . if you have a video for education and share i appreciate.

Try this in your main.c

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
char giden[10]="";
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
....
....
 
void StartTaskUart(void const * argument)
{
  /* USER CODE BEGIN StartTaskUart */
  /* Infinite loop */
  for(;;)
  {
	  if(giden[0]!=0) {
		  HAL_UART_Transmit(&huart2, (uint8_t *)giden,10,30);
		  giden[0]=0;
	  }
 
    osDelay(10);
  }
  /* USER CODE END StartTaskUart */
}
 

and screenview.cpp

#include <gui/screen1_screen/Screen1View.hpp>
#include "stm32f7xx_hal.h"
#include "string.h"
 
extern char giden[];
 
Screen1View::Screen1View()
{
 
}
 
void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
}
 
void Screen1View::tearDownScreen()
{
    Screen1ViewBase::tearDownScreen();
}
 
void Screen1View::veri_gonder()
{
	//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_5);
	//HAL_Delay(200); ??? DONT USE DELAYS IN GUI !!!
	strcpy(giden, "start\n\r");	// checked in thread and send
 
}
 
void Screen1View::veri_stop()
{
	//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_6);
	//	HAL_Delay(200);
//	char giden[10]="stop\n\r";
	if(giden[0]==0) strcpy(giden, "stop\n\r");
}
 

zzzzz
Senior

When include some C headers in Cpp, put them inside external C. like this:

#include <gui/screen1_screen/Screen1View.hpp>

extern "C"

{

#include "stm32f7xx_hal.h"

#include "cmsis_os.h"

#include "UART.h" // put huart2 here

}

...

Then debug it, make sure HAL_UART_Transmit in your button callback is being called.

And for you see interactions example :

#include <gui/screen1_screen/Screen1View.hpp>
#include <touchgfx/Color.hpp>
//#include "stm32f7xx_hal.h"
#include "string.h"
 
extern char giden[];
 
Screen1View::Screen1View()
{
 
}
 
void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
}
 
void Screen1View::tearDownScreen()
{
    Screen1ViewBase::tearDownScreen();
}
 
void Screen1View::veri_gonder()
{
	//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_5);
	strcpy(giden, "start\n\r");	// checked in thread and send
 
	btnGonder.setLabelColor(touchgfx::Color::getColorFrom24BitRGB(0, 255, 255));
}
 
void Screen1View::veri_stop()
{
	//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_6);
	if(giden[0]==0) strcpy(giden, "stop\n\r");
 
	btnGonder.setLabelColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
	btnGonder.invalidate();
}
 

Yes and when you try call it directly include extern, not create new.

UART_HandleTypeDef huart2; is new empty handle

instead use

extern UART_HandleTypeDef huart2;

or with extern "C" as writed zzzzz

FLine.1
Associate II

Hello

Thank you for replies.

I created new project and added two button with two interaction.

I set uart2 D5 and D6 pins.115200 baud and polling connecting not IT or DMA.

I coded like you but same result . i cant send data from stm32746 to pc via uart.

main.c

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
char giden[10] = "adbcde\r\n";
 
/* USER CODE END 0 */
 
static void MX_USART2_UART_Init(void)
{
 
  /* USER CODE BEGIN USART2_Init 0 */
 
  /* USER CODE END USART2_Init 0 */
 
  /* USER CODE BEGIN USART2_Init 1 */
 
  /* USER CODE END USART2_Init 1 */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART2_Init 2 */
 
  /* USER CODE END USART2_Init 2 */
 
}

uart task i created in main.c

/* USER CODE END Header_StartTask_Uart */
void StartTask_Uart(void const * argument)
{
  /* USER CODE BEGIN StartTask_Uart */
  /* Infinite loop */
  for(;;)
  {
	  if (giden[0] != 0) {//icinde deger varsa
		  HAL_UART_Transmit(&huart2, (uint8_t *)giden, 10 ,30);
		  giden[0] = 0;
 
	}
 
    osDelay(1000);
  }
  /* USER CODE END StartTask_Uart */
}

screen1view.cpp

#include <gui/screen1_screen/Screen1View.hpp>
/*
extern "C"
{
	#include "stm32f7xx_hal.h"
	#include "cmsis_os.h"
	UART_HandleTypeDef huart2;
}
*/
 
#include "string.h"
 
extern char giden[];
 
Screen1View::Screen1View()
{
 
}
 
void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
}
 
void Screen1View::tearDownScreen()
{
    Screen1ViewBase::tearDownScreen();
}
 
void Screen1View::basla()
{
	strcpy(giden, "basla\n\r");
	btnBasla.invalidate();
 
}
 
void Screen1View::bitir()
{
	if (giden[0] == 0) {
		strcpy(giden, "durdu\n\r");
 
	}
	btn_bitir.invalidate();
}

0693W000006HKpqQAG.png0693W000006HKplQAG.png0693W000006HKpgQAG.png