Skip to content

Latest commit

 

History

History

1-HOWTO

Piu' sotto, al termine della lingua inglese trovi il testo in italiano. Below English text you'll find the Italian version



HOW TO setup a project with this software

CubeMX setup


  • create a new project on STM32CubeIDE
  • enable one or two (one port for display and one for touch sensor) SPI port.
(here description is using ONE single SPI port for both: display and touch sensor)

SPI configuration is:

Mode value
mode Full-Duplex Master
NSS Disable
Parameter value
Frame format Motorola
Data size 8 bit
First bit MSB first
Baud Rate irrelevant (parameter is set by software)
CPOL low
CPHA 1 Edge
CRC calculation disabled
NSS type Output Sw

If you use SPI in "polling mode", do not enable Interrupt and DMA and not consider the below table: go over
If you use SPI in "interrupt mode", do not enable DMA and consider only the NVIC information in the below table
If you use SPI in "DMA mode", enable both Interrupt and DMA following the below table.

SPI config label Value
DMA settings enable only TX DMA
NVIC settings enable SPI global interrupt


  • assign these names to SPI pins:
SPI pin Pinname to assign Speed relevance
MISO TOUCH_MISO X
MOSI DISPL_MOSI X
SCK DISPL_SCK X

"Speed relevance" (here above and below):
"X" means that pin speed affects the defined SPI boudrate handling: rise (step by step from LOW to VERY HIGH) pins speed if you see uC cannot handle the defined communication speed (more information on your uC datasheet).
As per GPIO software guidelines, STM suggests keeping the lower GPIO speed allowing your project handling, reducing power consumption and EMI.


  • Enable 1 EXTI interrupt pin:
pinname to assign Interrupt mode pull-up/down
TOUCH_INT External interrupt-falling edge pull-up

Then enable the corresponding interrupt in the "NVIC session" of "System Core" configuration.


  • Enable 5 more pins as GPIO_Output:
pinname to assign output level speed relevance mode pull-up/down
DISPL_LED low - see here No pull-up/down
DISPL_DC - X Output push pull No pull-up/down
DISPL_RST low - Output push pull No pull-up/down
DISPL_CS high X Output push pull No pull-up/down
TOUCH_CS hlgh X Output push pull No pull-up/down


  • TouchGFX timer (only if "TouchGFX Full Mode")


Skip this step if you are setting-up a project in "Direct Mode" or "TouchGFX Button Mode"

Set-up a basic timer just having a loop 60 times per second, generating a "period elapsed" interrupt:

  • set PSC and ARR as per uC clock giving the timer a period of 1/60 s
  • enable timer interrupt

Source and header files

  • Copy the .c files into the /Core/Src folder in your STM32CubeIDE project
  • Copy the .h files into the /Core/Inc folder in your STM32CubeIDE project
  • into the /Core/Inc folder, open the main.h file and add an include directive for every .h file copied. In this order:

(main.h)
...
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "fonts.h"
#include "z_displ_ILI9XXX.h"
#include "z_displ_ILI9XXX_test.h"
#include "z_touch_XPT2046.h"
#include "z_touch_XPT2046_test.h"
#include "z_touch_XPT2046_menu.h"
/* USER CODE END Includes */
...

PLEASE NOTE

  • In a "TouchGFX" project you need only "z_displ_ILI9XXX.h", "z_displ_ILI9XXX.c", "z_touch_XPT2046.h" and "z_touch_XPT2046.c"
  • In a "Direct handling" project you need "_test" files (.c and .h) only if you want to use graphics test/demo functions, you don't need to add it in the production project.
  • Adding "z_touch_XPT2046_test", compiler will ask you to enable printf library into project properties (follow warnings instructions)

Next steps



Wiring/collegamenti (single port)



HOW TO: come configurare un progetto con questo software


Configurazione CubeMX


  • crea un nuovo progetto su STM32CubeIDE
  • attiva una porta SPI con questa configurazione:
Parametro Valore
mode Full-Duplex Master
NSS Disable
Parametro Valore
Frame format Motorola
Data size 8 bit
First bit MSB first
Baud Rate irrilevante (il parametro è impostato via software)
CPOL low
CPHA Edge
CRC calculation disabled
NSS type Output Hw

Se usi SPI in "polling mode" non attivare Interrupt e DMA sulla SPI e non considerare la tabella sotto: procedi oltre
Se usi SPI in "interrupt mode" non attivare DMA e considera solo NVIC settings nella tabella sotto
Se usi SPI in "DMA mode" abilita sia Interrupt sia DMA e segui la tabella sotto

Etichetta SPI Valore
DMA settings attiva solo TX DMA
NVIC settings attiva SPI global interrupt


  • assegnare questi nomi ai pin SPI:
Pin SPI Nome da assegnare Rilevanza velocità
MISO TOUCH_MISO X
MOSI DISPL_MOSI X
SCK DISPL_SCK X

"Rilevanza velocità" (qui sopra e sotto):
"X" significa che la velocità del pin ha effetti sulla velocità della porta SPI: aumenta (per gradi da LOW to VERY HIGH) la velocità dei pin se vedi che il uC non riesce a gestire la velocità di comunicazione assegnata (maggiori informazioni sul datasheet del tuo uC).
Come indicato in "GPIO software guidelines", STM suggerisce di mantenere la minore velocità GPIO che permette la gestione del tuo progetto, ciò per ridurre consumi ed EMI.


  • Attivare 1 pin come EXTI interrupt:
Nome pin da assegnare Interrupt mode pull-up/down
TOUCH_INT External interrupt-falling edge pull-up

Poi,
abilitare il corrispondente interrupt nella "NVIC session" della configurazione "System Core".


  • Attivare altri 5 pin come GPIO_Output:
Nome pin da assegnare output level rilevanza velocità mode pull-up/down
DISPL_LED low - vedi here No pull-up/down
DISPL_DC - X Output push pull No pull-up/down
DISPL_RST low - Output push pull No pull-up/down
DISPL_CS high X Output push pull No pull-updown
TOUCH_CS hlgh X Output push pull No pull-up/down


  • TouchGFX timer (solo se in "TouchGFX Full Mode")


Salta questo passaggio se imposti un progetto in "Direct Mode" o "TouchGFX Button Mode"

Imposta un basic timer che semplicemente abbia un ciclo di 1/60 di secondo, e che genera un "period elapsed" interrupt:

  • imposta PSC and ARR in funzione del clock del uC assegnando al timer un periodo di 1/60 s
  • attiva l'interrupt del timer

File sorgente e di testata

  • Copia i file .c nella cartella /Core/Src del progetto STM32CubeIDE
  • Copia i file .h nella cartella /Core/Inc del progetto STM32CubeIDE

  • Nella cartella /Core/Inc, apri il file main.h e aggiungi la direttiva include (nella sezione "USER CODE BEGIN Includes"?) per ogni file .h copiato.
(main.h)
...
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "fonts.h"
#include "z_displ_ILI9XXX.h"
#include "z_displ_ILI9XXX_test.h"
#include "z_touch_XPT2046.h"
#include "z_touch_XPT2046_test.h"
#include "z_touch_XPT2046_menu.h"
/* USER CODE END Includes */
...

NOTA BENE:

  • In un progetto "TouchGFX" ti servono solo "z_displ_ILI9XXX.h"y, "z_displ_ILI9XXX.c", "z_touch_XPT2046.h" and "z_touch_XPT2046.c"
  • In un progetto "a gestione diretta" i file "_test" (.c and .h)devono essere copiati nel progetto solo se vuoi usare le funzioni di demo e test. Non servono nella versione di produzione.
  • Aggiungendo i file "z_touch_XPT2046_test", il compilatore chiederà di attivare la libreria "printf" nelle proprietà del progetto (seguire le indicazioni dei warning)

Prossimi passi