cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f411RE and TouchGFX

viha_123
Associate II

Hi, I've been trying a project focusing on GUI display on TouchGFX GFX01M1 with STM32f411RET6 NUCLEO board. I have seen videos in youtube related to TouchGFX and they say that there is a need for FMC interface and LTDC in STM32CubeIDE. But for STM32f411RET6 board there is no FMC and LTDC in STM32CubeIDE, which is essential for interfacing TouchGFX with STM32f411RET6 board. I have thought of using SPI pins but for that I'm needing TFT ili9341 display. I want to implement my project with TouchGFX GFX01M1 only. Kindly suggest me a correct way to do this.

Thank you,

K.M.Vihasitha

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Mohammad MORADI ESFAHANIASL ,

Thanks for your concern and getting back! I have tried a completely different approach than the one you have mentioned above. I have taken the code of ili9341 display and integrated that with  X-NUCLEO-GFX01M1 display. This worked for me and I have got the output on  X-NUCLEO-GFX01M1 display.

Thank you,

K.M.Vihasitha

View solution in original post

10 REPLIES 10

Hello @viha_123 ,

First of all, I should mention that the display module you are considering using is called X-NUCLEO-GFX01M1 , and it is not related to TouchGFX. 

As you mentioned, you need to use SPI to communicate with your display module, and the process for doing that differs from using LTDC. There is a documentation available here to show you the process required for dealing with SPI or FMC displays.
Unfortunately, there is no TouchGFX Board Setup available for the STM32F411, hence you need to start a new project from STM32CubeMX and proceed from there. There is a comprehensive tutorial in the TouchGFX Board bring up documentation that can assist you throughout this journey.

It is also worth mentioning that there are a few TouchGFX Board Setups that use SPI displays, which you can use as inspiration for your custom project. For instance, you can take a look at STM32 NUCLEO-G071RB or STM32 NUCLEO-WB55RG 

STM32 NUCLEO-G071RB TouchGFX Board SetupSTM32 NUCLEO-G071RB TouchGFX Board Setup

 

I hope this helps you. Don't hesitate to ask more questions 

Mohammad MORADI
ST Software Developer | TouchGFX

Hi! Thanks for the reply! Really appreciate it! Sorry for the late reply, but can you please tell what are the correct pins for using SPI with the X-NUCLEO-GFX01M1 and NUCLEO-F411RE board? As I find it in the SPI display expansion boards for STM32 Nucleo-64 - User manual the pins are not matching, as SPI1 is disabled in the board, I'm finding that the hardware is not matching. Kindly give me a suggestion.

Thank you,

K.M.Vihasitha

Why ? On page is marked as compatible X-NUCLEO-GFX01M1 - Display expansion board for STM32 NUCLEO - STMicroelectronics

And SPI displays minimum conect is GND MOSI CLK for touch and bidireect next pins...

But if I try to do that in STM32CubeIDE I'm not able to get anything on the display, the display is just white as a screen. I'm attaching the code of main.c implemented in STM32CubeIDE :

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi1;
 
UART_HandleTypeDef huart2;
 
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_SPI1_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
void TFT_LCD_WriteCommand(uint8_t command)
  {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); // Set D/C pin low for command mode
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, &command, sizeof(command), HAL_MAX_DELAY);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
  }
void TFT_LCD_WriteData(uint8_t data)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); // Set D/C pin high for data mode
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
HAL_SPI_Transmit(&hspi1, &data, sizeof(data), HAL_MAX_DELAY);
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
}
void TFT_LCD_Init(void) {
    // Perform display initialization sequence
    // Example initialization sequence:
    // - Send initialization commands over SPI
 
    // Example: Send initialization command to turn on display
    TFT_LCD_WriteCommand(0x29);
}
 
void TFT_LCD_DrawPattern(void) {
    // Draw a simple pattern on the display
    // Example: Draw a red rectangle
    // - Set drawing area
    // - Send pixel data
 
    // Example: Set drawing area (x1=10, y1=10, x2=50, y2=50)
    TFT_LCD_WriteCommand(0x2A); // Column address set
    TFT_LCD_WriteData(0x00);    // Start column high byte
    TFT_LCD_WriteData(0x0A);    // Start column low byte
    TFT_LCD_WriteData(0x00);    // End column high byte
    TFT_LCD_WriteData(0x32);    // End column low byte
 
    TFT_LCD_WriteCommand(0x2B); // Row address set
    TFT_LCD_WriteData(0x00);    // Start row high byte
    TFT_LCD_WriteData(0x0A);    // Start row low byte
    TFT_LCD_WriteData(0x00);    // End row high byte
    TFT_LCD_WriteData(0x32);    // End row low byte
 
    TFT_LCD_WriteCommand(0x2C); // Memory write
 
    // Example: Send red pixel data (16-bit color: 5 bits for red, 6 bits for green, 5 bits for blue)
    for (int i = 0; i < (40 * 40); ++i) {
        TFT_LCD_WriteData(0xF8); // Red
        TFT_LCD_WriteData(0x00); // Green
    }
}
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_SPI1_Init();
  /* USER CODE BEGIN 2 */
  // Initialize the display
     TFT_LCD_Init();
 
     // Draw a pattern on the display
     TFT_LCD_DrawPattern();
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 16;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Initializes the CPU, AHB and APB buses 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();
  }
}
 
/**
  * @brief SPI1 Initialization Function
  * @PAram None
  * @retval None
  */
static void MX_SPI1_Init(void)
{
 
  /* USER CODE BEGIN SPI1_Init 0 */
 
  /* USER CODE END SPI1_Init 0 */
 
  /* USER CODE BEGIN SPI1_Init 1 */
 
  /* USER CODE END SPI1_Init 1 */
  /* SPI1 parameter configuration*/
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 10;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI1_Init 2 */
 
  /* USER CODE END SPI1_Init 2 */
 
}
 
/**
  * @brief USART2 Initialization Function
  * @PAram None
  * @retval None
  */
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;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART2_Init 2 */
 
  /* USER CODE END USART2_Init 2 */
 
}
 
/**
  * @brief GPIO Initialization Function
  * @PAram None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
 
  /*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PA0 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PB3 */
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
}
 
/* USER CODE BEGIN 4 */
 
/* USER CODE END 4 */
 
/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

Please go through it.

I'm also attaching the .ioc screenshot. Kindly give me a solution regarding this.

Place code into 

hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

and start diag with this line. Display dont work with any clock set, read pdf for max.

Second issue maybe lcd init isnt ok only one cmd...

For sending data using SPI, you don't need to use TFT_LCD function. STM32CubeMX does contain some helper functions to send data easily. 
Again, I suggest you to continue your process based on the available documentations, especially using this documentation .
There are also other examples in STM32CubeMX to demonstrate how to set up SPI communications. When you open STM32CubeMX,  select File -> New Project. Then, in the opened window, select Example Selector tab, under the MCU/MPU section enter the name of the MCU (STM32F411RET6) and the select a relevant example, for instance, SPI_FullDuplex_ComPolling. Then you will get the source code for how to set up the SPI configuration.

Example SelectorExample Selector

Good luck 

Mohammad MORADI
ST Software Developer | TouchGFX

Sorry for the late reply!

Thanks for the reply, I have gained a new insight on the project by this solution. I will try this.

Hello @viha_123 ,

Did you manage to progress with your project?

Mohammad MORADI
ST Software Developer | TouchGFX

Hello @Mohammad MORADI ESFAHANIASL ,

Thanks for your concern and getting back! I have tried a completely different approach than the one you have mentioned above. I have taken the code of ili9341 display and integrated that with  X-NUCLEO-GFX01M1 display. This worked for me and I have got the output on  X-NUCLEO-GFX01M1 display.

Thank you,

K.M.Vihasitha