H753_CPP_SPI_BT817_EVE_01 1.0
STM32H753 drives a Bridgetek BT817 (ME817EV + DP-0701-01A) over SPI: a chip-ID start-up check, then Bridgetek's simple demo through the STM32_Bridgetek_EVE_API library
Loading...
Searching...
No Matches
main.c File Reference

: Main program body More...

#include "main.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "eve_example.h"

Go to the source code of this file.

Macros

#define EVE_REG_ID   0x302000UL
 
#define EVE_REG_CPURESET   0x302020UL
 
#define EVE_RAM_CHIPID   0x0C0000UL
 
#define EVE_REG_ID_VALUE   0x7CU
 
#define EVE_CMD_ACTIVE   0x00U
 
#define EVE_CMD_CLKEXT   0x44U
 
#define EVE_CMD_RST_PULSE   0x68U
 
#define EVE_CMD_CLKSEL   0x61U
 
#define EVE_CLKSEL_72MHZ   0x46U
 
#define EVE_SPI_RETRIES   3U
 
#define EVE_SPI_TIMEOUT_MS   10U
 
#define EVE_BOOT_TIMEOUT_MS   300U
 
#define EVE_ENGINE_TIMEOUT_MS   3000U
 
#define EVE_MAX_READ_BYTES   4U
 

Functions

static bool eveSpiIsTransient (HAL_StatusTypeDef status)
 Decides whether a failed HAL SPI call is worth retrying.
 
static void eveSpiTransaction (const uint8_t *tx, uint8_t *rx, uint16_t length)
 Runs one complete SPI transaction with the BT817 (CS low, transfer, CS high). Retries the whole transaction on transient errors, up to EVE_SPI_RETRIES, then reports the reason and calls Error_Handler().
 
static void eveHostCommand (uint8_t command, uint8_t parameter)
 Sends a 3-byte BT817 host command (command, parameter, 0x00).
 
static void eveReadMemory (uint32_t address, uint8_t *data, uint16_t length)
 Reads bytes from BT817 memory: 3 address bytes (top two bits 00 = read), one dummy byte, then the data (datasheet 4.1.3).
 
static bool eveWaitForRegister (uint32_t address, uint8_t expected, uint32_t timeoutMs, uint8_t *lastValue)
 Polls an 8-bit BT817 register until it holds the expected value or a timeout passes.
 
static void evePrintNoAnswerHelp (uint8_t misoValue)
 Prints the wiring checklist used when the BT817 does not answer.
 
static void eveChipIdTest (void)
 BT817 bring-up test: resets the chip on PD#, starts its clock, waits for boot, then checks REG_ID (0x7C), REG_CPURESET (0) and the chip ID (08 17 01 00). Prints PASS, or the reason for the failure and calls Error_Handler().
 
int8_t platform_calib_init (void)
 Tell the Bridgetek example whether touch calibration can be stored.
 
int8_t platform_calib_write (struct touchscreen_calibration *calib)
 Store touch calibration values (not supported in this project).
 
int8_t platform_calib_read (struct touchscreen_calibration *calib)
 Read stored touch calibration values (not supported in this project).
 
int main (void)
 The application entry point.
 

Variables

static const bool runChipIdTest = true
 true = run our chip-ID start-up check before Bridgetek's example; false = skip it.
 

Detailed Description

: Main program body

Attention

Copyright (c) 2026 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.

Definition in file main.c.

Macro Definition Documentation

◆ EVE_BOOT_TIMEOUT_MS

#define EVE_BOOT_TIMEOUT_MS   300U

Boot can take up to 300 ms (4.9.4)

Definition at line 88 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_CLKSEL_72MHZ

#define EVE_CLKSEL_72MHZ   0x46U

CLKSEL parameter: 6 x 12 MHz, PLL range 1 (Bridgetek EVE_HAL.c)

Definition at line 85 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_CMD_ACTIVE

#define EVE_CMD_ACTIVE   0x00U

Host command ACTIVE

Definition at line 81 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_CMD_CLKEXT

#define EVE_CMD_CLKEXT   0x44U

Host command CLKEXT (external crystal)

Definition at line 82 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_CMD_CLKSEL

#define EVE_CMD_CLKSEL   0x61U

Host command CLKSEL (system clock select)

Definition at line 84 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_CMD_RST_PULSE

#define EVE_CMD_RST_PULSE   0x68U

Host command RST_PULSE (core reset)

Definition at line 83 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_ENGINE_TIMEOUT_MS

#define EVE_ENGINE_TIMEOUT_MS   3000U

Wait for REG_CPURESET; the touch engine waits for the touch controller to boot

Definition at line 89 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_MAX_READ_BYTES

#define EVE_MAX_READ_BYTES   4U

Largest read this test needs

Definition at line 90 of file main.c.

Referenced by eveReadMemory().

◆ EVE_RAM_CHIPID

#define EVE_RAM_CHIPID   0x0C0000UL

Chip ID, 08 17 01 00 for a BT817

Definition at line 79 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_REG_CPURESET

#define EVE_REG_CPURESET   0x302020UL

REG_CPURESET, 0 = engines running

Definition at line 78 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_REG_ID

#define EVE_REG_ID   0x302000UL

REG_ID, always reads 0x7C once booted

Definition at line 77 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_REG_ID_VALUE

#define EVE_REG_ID_VALUE   0x7CU

Expected REG_ID value

Definition at line 80 of file main.c.

Referenced by eveChipIdTest().

◆ EVE_SPI_RETRIES

#define EVE_SPI_RETRIES   3U

Attempts per SPI transaction

Definition at line 86 of file main.c.

Referenced by eveSpiTransaction().

◆ EVE_SPI_TIMEOUT_MS

#define EVE_SPI_TIMEOUT_MS   10U

HAL timeout per SPI transaction

Definition at line 87 of file main.c.

Referenced by eveSpiTransaction().

Function Documentation

◆ eveChipIdTest()

static void eveChipIdTest ( void )
static

BT817 bring-up test: resets the chip on PD#, starts its clock, waits for boot, then checks REG_ID (0x7C), REG_CPURESET (0) and the chip ID (08 17 01 00). Prints PASS, or the reason for the failure and calls Error_Handler().

Note
Not thread-safe or ISR-safe: blocking SPI and HAL_Delay(); call once from main() after MX_GPIO_Init() and MX_SPI1_Init(), before the main loop.

Definition at line 240 of file main.c.

References EVE_BOOT_TIMEOUT_MS, EVE_CLKSEL_72MHZ, EVE_CMD_ACTIVE, EVE_CMD_CLKEXT, EVE_CMD_CLKSEL, EVE_CMD_RST_PULSE, EVE_ENGINE_TIMEOUT_MS, EVE_RAM_CHIPID, EVE_REG_CPURESET, EVE_REG_ID, EVE_REG_ID_VALUE, eveHostCommand(), evePrintNoAnswerHelp(), eveReadMemory(), and eveWaitForRegister().

Referenced by main().

◆ eveHostCommand()

static void eveHostCommand ( uint8_t command,
uint8_t parameter )
static

Sends a 3-byte BT817 host command (command, parameter, 0x00).

Parameters
commandHost command byte, e.g. EVE_CMD_CLKEXT or EVE_CMD_ACTIVE.
parameterSecond byte; 0x00 for most commands, the clock setting for CLKSEL.
Note
Not thread-safe or ISR-safe (see eveSpiTransaction()).

Definition at line 156 of file main.c.

References eveSpiTransaction().

Referenced by eveChipIdTest().

◆ evePrintNoAnswerHelp()

static void evePrintNoAnswerHelp ( uint8_t misoValue)
static

Prints the wiring checklist used when the BT817 does not answer.

Parameters
misoValueThe last byte read back, to show whether MISO looks stuck.

Definition at line 221 of file main.c.

Referenced by eveChipIdTest().

◆ eveReadMemory()

static void eveReadMemory ( uint32_t address,
uint8_t * data,
uint16_t length )
static

Reads bytes from BT817 memory: 3 address bytes (top two bits 00 = read), one dummy byte, then the data (datasheet 4.1.3).

Parameters
address22-bit BT817 memory address.
dataDestination for the bytes read.
lengthNumber of bytes to read, 1 to EVE_MAX_READ_BYTES.
Note
Not thread-safe or ISR-safe (see eveSpiTransaction()).

Definition at line 172 of file main.c.

References EVE_MAX_READ_BYTES, and eveSpiTransaction().

Referenced by eveChipIdTest(), and eveWaitForRegister().

◆ eveSpiIsTransient()

static bool eveSpiIsTransient ( HAL_StatusTypeDef status)
static

Decides whether a failed HAL SPI call is worth retrying.

Parameters
statusThe HAL status returned by the SPI call.
Returns
true for transient communication errors (busy, timeout, or a transfer-error flag), false for errors a retry cannot fix.
Note
Not thread-safe: reads hspi1's error code; called from main() only.

Definition at line 99 of file main.c.

Referenced by eveSpiTransaction().

◆ eveSpiTransaction()

static void eveSpiTransaction ( const uint8_t * tx,
uint8_t * rx,
uint16_t length )
static

Runs one complete SPI transaction with the BT817 (CS low, transfer, CS high). Retries the whole transaction on transient errors, up to EVE_SPI_RETRIES, then reports the reason and calls Error_Handler().

Parameters
txBytes to send (must hold length bytes).
rxBuffer for the bytes clocked back (must hold length bytes).
lengthNumber of bytes to clock.
Note
Not thread-safe or ISR-safe: blocking HAL_SPI_TransmitReceive on hspi1 and the EVE_CS pin, with no locking. Called from main() before the loop.

Definition at line 124 of file main.c.

References EVE_SPI_RETRIES, EVE_SPI_TIMEOUT_MS, and eveSpiIsTransient().

Referenced by eveHostCommand(), and eveReadMemory().

◆ eveWaitForRegister()

static bool eveWaitForRegister ( uint32_t address,
uint8_t expected,
uint32_t timeoutMs,
uint8_t * lastValue )
static

Polls an 8-bit BT817 register until it holds the expected value or a timeout passes.

Parameters
addressRegister address.
expectedValue to wait for.
timeoutMsHow long to keep polling, in milliseconds.
lastValueReceives the last value read (for the failure report).
Returns
true if the expected value was read in time, false on timeout.
Note
Not thread-safe or ISR-safe (see eveSpiTransaction()).

Definition at line 200 of file main.c.

References eveReadMemory().

Referenced by eveChipIdTest().

◆ main()

int main ( void )

The application entry point.

Return values
int

Definition at line 372 of file main.c.

References eveChipIdTest(), and runChipIdTest.

◆ platform_calib_init()

int8_t platform_calib_init ( void )

Tell the Bridgetek example whether touch calibration can be stored.

Called by the vendor example (touch.c). This project has no storage for calibration yet, so it reports "not supported" and the example asks for a new calibration after every reset. Thread safety: safe from any context; it touches no shared state.

Return values
1Storing touchscreen settings is not supported.

Definition at line 337 of file main.c.

◆ platform_calib_read()

int8_t platform_calib_read ( struct touchscreen_calibration * calib)

Read stored touch calibration values (not supported in this project).

Parameters
calibWhere the values would be written (left unchanged).

Thread safety: safe from any context; it touches no shared state.

Return values
-1No stored settings are available.

Definition at line 360 of file main.c.

◆ platform_calib_write()

int8_t platform_calib_write ( struct touchscreen_calibration * calib)

Store touch calibration values (not supported in this project).

Parameters
calibCalibration values from the BT817 (unused).

Thread safety: safe from any context; it touches no shared state.

Return values
-1The settings were not stored.

Definition at line 348 of file main.c.

Variable Documentation

◆ runChipIdTest

const bool runChipIdTest = true
static

true = run our chip-ID start-up check before Bridgetek's example; false = skip it.

Definition at line 55 of file main.c.

Referenced by main().