cancel
Showing results for 
Search instead for 
Did you mean: 

Using 2.2"SPI TFT Module (MSP2202; Driver ili9341) with a STM32G431KB

Hello,

as the title says, I wanna use the display with the µC.

 

Aim:

The aim is just to learn to know how to use SPI. And for the begin I want to use only a display with a ready to go driver. The display runs with the driver ili9341. I just wanna give text outputs to the display.

 

Reccources:

I searched an STM-compatible: ILI9341-HAL-Driver-afikson

A website (also with a link to the data sheet) for the display: MSP2202 

STM32G431 User Manual: UM2397 

I use the STM32CubeIDE.

 

What I already configured:

Cube settings (Pinout & Configuration):

  • System Core/RCC: Crystal/Ceramic Resonator
  • Connectivity/SPI1: Full-Duplex Master as mode, without NSS
    • Basic params: Motorola, Size 8 Bit, MSB
    • Clock params: 64 (prescaler), CPOL Low, CPHA 1 Edge
  • I have set the PA11 as GPIO Outpus and named it SPI1_CS for Chip Select (In the User Manual for the G431KB at the pinout table, there is an entry what says that CS for SPI is on this pin and with a notation that it functions as GPIO on page 22 Connector CN4, Pin no. 13 (PA11))
  • I have set PA4 as GPIO output for RESET Pin of the display, same with PA0 for the DC pin of the display

Driver programming files (ili and fonts) editing:

  • After the code generating I added a folder "ili9341" into the folder "Drivers" of my project and added the c and h files of ili9341 and fonts (without the touch files, because I do not use and guess the display even does not have this function).
  • Then I edited the include for including stm hal lib to "#include "stm32g4xx_hal.h" suitable for my controller in the ili9431.c file.
  • After this I edited the entries for the defines (marked with a comment "Redefine if necessary") for spi handler port and the GPIO pin names and pin port names what the header file gives the ili9341.c file. The c file can use the names because this file uses the hal lib at the other hand.
    I got the correct names for the paramaters by main.h in the folder Core/Inc/ over the USER CODE part for private defines.

Source code files editing and IDE settings:

  • Added include path (folder path to foler ili9341) via marking the project and then go to file/properties/C&C++ General/Paths and Symbols viaButton add via button file system
  • Includes in main.c
    /* Private includes ----------------------------------------------------------*/
    /* USER CODE BEGIN Includes */
    #include
    <string.h>
    #include <stdarg.h>
    #include "fonts.h"

    #include "ili9341.h"
    /* USER CODE END Includes */
  • In the main.c

    private function prototype field

    /* USER CODE BEGIN PFP */

    void init() {

    ILI9341_Unselect();

    ILI9341_TouchUnselect();

    ILI9341_Init();

    }

    /* USER CODE END PFP */

    ...
    in main function of main.c

    /* USER CODE BEGIN Init */

    init();

    /* USER CODE END Init */

 

What errors hapened?:

  • First I got an error, that the assembly file "startup_stm32g431kbtx.s" in the folder /Core/Startup/ cannot find "main" at the line 195 "bl main" at the block "LoopFillzerobss"
  • I sadly forgot the measure I took to solve that problem, I guess it was adding the include path for the main.c and main.h at any point
  • Since then I got a new error message, following...
____________________________________________________________________________________________

12:37:42 **** Incremental Build of configuration Debug for project SPI_display_MSP2202_Iili9341 ****

make -j16 all

arm-none-eabi-gcc -mcpu=cortex-m4 -g3 -DDEBUG -c -x assembler-with-cpp -MMD -MP -MF"Core/Startup/startup_stm32g431kbtx.d" -MT"Core/Startup/startup_stm32g431kbtx.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Startup/startup_stm32g431kbtx.o" "../Core/Startup/startup_stm32g431kbtx.s"

../Core/Startup/startup_stm32g431kbtx.s: Assembler messages:

../Core/Startup/startup_stm32g431kbtx.s:155: Error: symbol `Reset_Handler' is already defined

../Core/Startup/startup_stm32g431kbtx.s:169: Error: symbol `CopyDataInit' is already defined

../Core/Startup/startup_stm32g431kbtx.s:174: Error: symbol `LoopCopyDataInit' is already defined

../Core/Startup/startup_stm32g431kbtx.s:185: Error: symbol `FillZerobss' is already defined

../Core/Startup/startup_stm32g431kbtx.s:595: Error: symbol `LoopForever' is already defined

../Core/Startup/startup_stm32g431kbtx.s:609: Error: symbol `Default_Handler' is already defined

../Core/Startup/startup_stm32g431kbtx.s:610: Error: symbol `Infinite_Loop' is already defined

../Core/Startup/startup_stm32g431kbtx.s:624: Error: symbol `g_pfnVectors' is already defined

C:\Users\a4763\AppData\Local\Temp\ccAChdPF.s: Error: invalid operands (.isr_vector and .text.Reset_Handler sections) for `-'

C:\Users\a4763\AppData\Local\Temp\ccAChdPF.s: Error: .size expression for Reset_Handler does not evaluate to a constant

make: *** [Core/Startup/subdir.mk:19: Core/Startup/startup_stm32g431kbtx.o] Error 1

"make -j16 all" terminated with exit code 2. Build might be incomplete.

 

12:37:42 Build Failed. 9 errors, 0 warnings. (took 342ms)

____________________________________________________________________________________________

 

 

My questions:

  1. Of course, how to solve the issue I named before, how the symbols can be already defined? Etc.
  2. The setting in Cube for RCC, what are the parameters to decide to activate it and what clock to choose? I just choosed resonator because I thought it is needed for the SPI CLock, but bypass or resonator??
  3. With the SPI1 Setting I still do not get the difference between half and full duplex because both can send and transmit, so what is the difference?
  4. I could not find what to set for Data Size (I have choosen 8 Bits) and prescaler or indireclty the Baud Rate in the data sheet for the Display, I dont know what to choose. (could not test it anyway because of that error of the assembly file)
  5. At the register card "Clock Configuration" is there a tutorial for this? Until now I never needed that settings to change, but I want to know, how I can use it and understand it if I need this.
  6. The settings in the IDE and the changes in the code files, are they correct? Do I need more or other changes?

 

 

 

Addendum 23.10.24, 14:20:

I forgot to mention, that the main.c is lined weirdly, like it has no permission or something.

andreas_mit_Helm_aus_Holtz_0-1729686066373.png

 

 

 

Addendum 23.10.24, 16:48:

So sorry, I typed a wrong link for the ili9341 lib, I corrected it now. Before it was the one by ardnew.

But the current and correct one is the one by afikson.

2 REPLIES 2

I found the issue.

I cannot help, but because of anything the code part of the assembly file I mentioned until

"

FillZerobss:

str r3, [r2]

adds r2, r2, #4

"

was indeed copied and pasted after the first one, so the symbols was double existent. And that is not all, there was more parts nonsenseful copied. Very weird.

So I decided to create a new project with the settings and code changes I mentioned.

I will comment the results.

So, now I could normally work on my project.

I added includes to main.c:

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

#include <string.h>

#include <stdarg.h>

#include "ili9341.h"

#include "fonts.h"

/* USER CODE END Includes */

 

The while loop in the main function:

 

while (1)

{

/* USER CODE END WHILE */

HAL_Delay(500);

ILI9341_WriteString(0, 0, "TEST", Font_7x10, ILI9341_RED, ILI9341_BLACK);

HAL_Delay(500);

ILI9341_WriteString(0, 0, "HELLO WORLD", Font_7x10, ILI9341_RED, ILI9341_BLACK);

 

/* USER CODE BEGIN 3 */

}

 

So now I can build it without errors or warnings. I connected the controller to the display on my breadboard and played the program to the controller.

The display only displays a white screen. That could be because, I have to set better parameters for the Bits and prescaler for the SPI config in the ioc file (or in the cube).

I will comment again, when I am ready.