cancel
Showing results for 
Search instead for 
Did you mean: 

UART2 is not working with TouchGFX while it's working without! Help needed

rahulz916
Associate II

Hello Everyone, I am using STM32H747I-DISCO.I am using Fanout board MB1280C

The USART2 is not working Can you please help me 
I am just trying to print some message at startup but nothing is happening,

Thanks in Advance.

 

MX_GPIO_Init();

MX_MDMA_Init();

MX_FMC_Init();

MX_QUADSPI_Init();

MX_DMA2D_Init();

MX_DSIHOST_DSI_Init();

MX_LTDC_Init();

MX_CRC_Init();

MX_JPEG_Init();

MX_USART2_UART_Init();



MX_TouchGFX_Init();

/* Call PreOsInit function */

MX_TouchGFX_PreOSInit();

/* USER CODE BEGIN 2 */

debug_print("\r\nsystem is up\r\n");

/* USER CODE END 2 */



/* Init scheduler */

osKernelInitialize();



/* USER CODE BEGIN RTOS_MUTEX */

/* add mutexes, ... */

/* USER CODE END RTOS_MUTEX */



/* USER CODE BEGIN RTOS_SEMAPHORES */

/* add semaphores, ... */

/* USER CODE END RTOS_SEMAPHORES */



/* USER CODE BEGIN RTOS_TIMERS */

/* start timers, add new ones, ... */

/* USER CODE END RTOS_TIMERS */



/* USER CODE BEGIN RTOS_QUEUES */

/* add queues, ... */

/* USER CODE END RTOS_QUEUES */



/* Create the thread(s) */

/* creation of TouchGFXTask */

TouchGFXTaskHandle = osThreadNew(TouchGFX_Task, NULL, &TouchGFXTask_attributes);



/* creation of videoTask */

videoTaskHandle = osThreadNew(videoTaskFunc, NULL, &videoTask_attributes);



/* USER CODE BEGIN RTOS_THREADS */

/* add threads, ... */

/* USER CODE END RTOS_THREADS */



/* USER CODE BEGIN RTOS_EVENTS */

/* add events, ... */

/* USER CODE END RTOS_EVENTS */



/* Start scheduler */

osKernelStart();



/* We should never get here as control is now taken by the scheduler */



/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */



/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}



void debug_print(const char *message)

{

HAL_UART_Transmit(&huart2, (uint8_t *)message, strlen(message), HAL_MAX_DELAY);

}





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.Init.ClockPrescaler = UART_PRESCALER_DIV1;

huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

if (HAL_UART_Init(&huart2) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN USART2_Init 2 */



/* USER CODE END USART2_Init 2 */



}







void HAL_UART_MspInit(UART_HandleTypeDef* huart)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};

if(huart->Instance==USART2)

{

/* USER CODE BEGIN USART2_MspInit 0 */



/* USER CODE END USART2_MspInit 0 */



/** Initializes the peripherals clock

*/

PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;

PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)

{

Error_Handler();

}



/* Peripheral clock enable */

__HAL_RCC_USART2_CLK_ENABLE();



__HAL_RCC_GPIOD_CLK_ENABLE();

/**USART2 GPIO Configuration

PD5 ------> USART2_TX

PD6 ------> USART2_RX

*/

GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.Alternate = GPIO_AF7_USART2;

HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);



/* USART2 interrupt Init */

HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);

HAL_NVIC_EnableIRQ(USART2_IRQn);

/* USER CODE BEGIN USART2_MspInit 1 */



/* USER CODE END USART2_MspInit 1 */



}
4 REPLIES 4
Peter BENSCH
ST Employee

Where do you expect something to happen?

You have programmed PD5 and PD6 as RX/TX - have you looked at the schematics to see how they are connected to STMOd+?
Hint: have a look at SB33 and SB35.

Regards
/Peter

In order 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.
mƎALLEm
ST Employee

Hello @rahulz916 ,

First please review how to post a thread in this community, especially on How to insert your code. I've edited your post to follow the community rules.

Second, your question is not related to TouchGFX subject, so why are you posting it in the STM32 MCUs TouchGFX and GUI forum board? I'm moving the post to the STM32 MCU products forum board.

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.
rahulz916
Associate II

I am trying to print using this:   
HAL_UART_Transmit(&huart2, (uint8_t *)message, strlen(message), HAL_MAX_DELAY);
I have checked the pins that are connected to Stmod+ Fan Out board.

I checked without RTOS and  uart2 is working fine. But I need this uart2 along with touchgfx enabled. I am attaching the pinouts of fanout board

Thank you for helping.Screenshot 2025-07-08 110739.png

So if USART2 is working without RTOS and it's not working with TouchGFX. That's not a hardware issue. We need to move the post to the TouchGFX forum board.

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.