mirror of
https://github.com/ghidraninja/game-and-watch-flashloader.git
synced 2025-12-17 01:16:08 +01:00
603 lines
19 KiB
C
603 lines
19 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file : main.c
|
|
* @brief : Main program body
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
|
* All rights reserved.</center></h2>
|
|
*
|
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|
* the "License"; You may not use this file except in compliance with the
|
|
* License. You may obtain a copy of the License at:
|
|
* opensource.org/licenses/BSD-3-Clause
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "main.h"
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
/* USER CODE BEGIN Includes */
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "buttons.h"
|
|
#include "flash.h"
|
|
#include "sha256.h"
|
|
|
|
/* 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 ---------------------------------------------------------*/
|
|
|
|
OSPI_HandleTypeDef hospi1;
|
|
|
|
SPI_HandleTypeDef hspi2;
|
|
|
|
/* USER CODE BEGIN PV */
|
|
|
|
uint8_t logbuf[1024 * 4];
|
|
uint32_t log_idx;
|
|
|
|
// This tells the loader how much and where to program in the flash
|
|
__attribute__((used)) __attribute__((section (".persistent"))) uint32_t program_size;
|
|
__attribute__((used)) __attribute__((section (".persistent"))) uint32_t program_address;
|
|
|
|
// This is set by openocd in order to guarantee that we don't start flashing by accident
|
|
__attribute__((used)) __attribute__((section (".persistent"))) uint32_t program_magic;
|
|
|
|
// This can be read by openocd to see when programming is done
|
|
__attribute__((used)) __attribute__((section (".persistent"))) uint32_t program_done;
|
|
|
|
// Control if chip should be erased or not
|
|
__attribute__((used)) __attribute__((section (".persistent"))) uint32_t program_erase;
|
|
|
|
// Number of 16KB blocks to be erased from flash address 0
|
|
__attribute__((used)) __attribute__((section (".persistent"))) int32_t program_erase_bytes;
|
|
|
|
// The expected sha256 of the loaded binary
|
|
__attribute__((used)) __attribute__((section (".persistent"))) uint8_t program_expected_sha256[128];
|
|
|
|
// The calculated sha256 of the external flash after programming
|
|
__attribute__((used)) __attribute__((section (".persistent"))) uint8_t program_calculated_sha256[128];
|
|
|
|
// Size of the flash
|
|
// TODO: Make configurable from openocd
|
|
// Number of address bits. 20=1M, 24=16M
|
|
uint32_t program_device_size = 24;
|
|
|
|
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
void SystemClock_Config(void);
|
|
static void MX_GPIO_Init(void);
|
|
static void MX_OCTOSPI1_Init(void);
|
|
static void MX_NVIC_Init(void);
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
void HAL_Delay(uint32_t Delay)
|
|
{
|
|
while (Delay--) {
|
|
// Accurate at 48MHz sysclock
|
|
for (int i = 0; i < 2 * 48000 / 3; i++) {
|
|
__NOP();
|
|
}
|
|
}
|
|
}
|
|
void lcd_backlight_off() {
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
|
|
}
|
|
void lcd_backlight_on() {
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
|
|
}
|
|
|
|
int _write(int file, char *ptr, int len)
|
|
{
|
|
if (log_idx + len + 1 > sizeof(logbuf)) {
|
|
log_idx = 0;
|
|
}
|
|
|
|
memcpy(&logbuf[log_idx], ptr, len);
|
|
log_idx += len;
|
|
logbuf[log_idx + 1] = '\0';
|
|
|
|
return len;
|
|
}
|
|
|
|
/* 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_OCTOSPI1_Init();
|
|
|
|
|
|
/* Initialize interrupts */
|
|
MX_NVIC_Init();
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
// Check that the magic has been set correctly
|
|
if (program_magic != 0xdeadbeef) {
|
|
Error_Handler();
|
|
}
|
|
|
|
program_done = 0;
|
|
|
|
uint32_t ram_address = 0x24000000;
|
|
uint8_t *ram = (uint8_t*)ram_address;
|
|
|
|
// Calculate sha256 hash of the RAM first
|
|
sha256_to_string(program_calculated_sha256, (const BYTE*) ram, program_size);
|
|
|
|
if (strncmp((char *)program_calculated_sha256, (char *)program_expected_sha256, 64) != 0) {
|
|
// Hashes don't match even in RAM, openocd loading failed.
|
|
program_done = 0xbadcafee;
|
|
Error_Handler();
|
|
}
|
|
|
|
// SPI_MODE or QUAD_MODE
|
|
quad_mode_t quad_mode = SPI_MODE;
|
|
|
|
// VENDOR_MX: MX25U8035F, Nintendo Stock Flash
|
|
// VENDOR_ISSI: IS25WP128F, 128Mb large flash
|
|
spi_chip_vendor_t vendor = VENDOR_MX;
|
|
|
|
OSPI_Init(&hospi1, quad_mode, vendor);
|
|
|
|
// Set to 0 if you only want to enable flash read memory mapping
|
|
#if 1
|
|
|
|
if (program_erase) {
|
|
if (program_erase_bytes == 0) {
|
|
OSPI_NOR_WriteEnable(&hospi1);
|
|
OSPI_ChipErase(&hospi1);
|
|
} else {
|
|
uint32_t address = program_address;
|
|
while (program_erase_bytes > 0) {
|
|
OSPI_NOR_WriteEnable(&hospi1);
|
|
if ((address & 0xFFFF) || (program_erase_bytes < 64*1024)) {
|
|
// Erase 4K blocks in case the address is not 64kB aligned or less than 64kB to erase
|
|
printf("Erasing sector (4kB): 0x%08lx\n", address);
|
|
OSPI_SectorErase(&hospi1, address);
|
|
|
|
program_erase_bytes -= 4*1024;
|
|
address += 4*1024;
|
|
} else if (program_erase_bytes >= 64*1024) {
|
|
printf("Erasing block (64kB): 0x%08lx\n", address);
|
|
OSPI_BlockErase(&hospi1, address);
|
|
|
|
program_erase_bytes -= 64*1024;
|
|
address += 64*1024;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
OSPI_Program(&hospi1, program_address, ram, program_size);
|
|
#endif
|
|
|
|
OSPI_EnableMemoryMappedMode(&hospi1);
|
|
|
|
// Calculate sha256 hash of the external flash
|
|
sha256_to_string(program_calculated_sha256, (const BYTE*) (0x90000000 + program_address), program_size);
|
|
|
|
if (strncmp((char *)program_calculated_sha256, (char *)program_expected_sha256, 64) != 0) {
|
|
// Hashes don't match, programming failed
|
|
program_done = 0xbadf000d;
|
|
Error_Handler();
|
|
}
|
|
|
|
// Flashing done!
|
|
program_done = 0xcafef00d;
|
|
|
|
while(1) {
|
|
HAL_Delay(1000);
|
|
lcd_backlight_off();
|
|
HAL_Delay(1000);
|
|
lcd_backlight_on();
|
|
}
|
|
/* 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};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
|
|
/** Supply configuration update enable
|
|
*/
|
|
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
|
/** Configure the main internal regulator output voltage
|
|
*/
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
|
|
|
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
|
|
/** 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_DIV1;
|
|
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 = 140;
|
|
RCC_OscInitStruct.PLL.PLLP = 2;
|
|
RCC_OscInitStruct.PLL.PLLQ = 2;
|
|
RCC_OscInitStruct.PLL.PLLR = 2;
|
|
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
|
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
|
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
|
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_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
|
|
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
|
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI2|RCC_PERIPHCLK_OSPI
|
|
|RCC_PERIPHCLK_CKPER;
|
|
PeriphClkInitStruct.OspiClockSelection = RCC_OSPICLKSOURCE_CLKP;
|
|
PeriphClkInitStruct.CkperClockSelection = RCC_CLKPSOURCE_HSI;
|
|
PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_CLKP;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief NVIC Configuration.
|
|
* @retval None
|
|
*/
|
|
static void MX_NVIC_Init(void)
|
|
{
|
|
/* OCTOSPI1_IRQn interrupt configuration */
|
|
HAL_NVIC_SetPriority(OCTOSPI1_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(OCTOSPI1_IRQn);
|
|
}
|
|
|
|
/**
|
|
* @brief OCTOSPI1 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_OCTOSPI1_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN OCTOSPI1_Init 0 */
|
|
|
|
/* USER CODE END OCTOSPI1_Init 0 */
|
|
|
|
OSPIM_CfgTypeDef sOspiManagerCfg = {0};
|
|
|
|
/* USER CODE BEGIN OCTOSPI1_Init 1 */
|
|
|
|
/* USER CODE END OCTOSPI1_Init 1 */
|
|
/* OCTOSPI1 parameter configuration*/
|
|
hospi1.Instance = OCTOSPI1;
|
|
hospi1.Init.FifoThreshold = 4;
|
|
hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
|
|
hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_MACRONIX;
|
|
hospi1.Init.DeviceSize = program_device_size; // Number of address bits. 20=1M, 24=16M
|
|
hospi1.Init.ChipSelectHighTime = 2;
|
|
hospi1.Init.FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE;
|
|
hospi1.Init.ClockMode = HAL_OSPI_CLOCK_MODE_0;
|
|
hospi1.Init.WrapSize = HAL_OSPI_WRAP_NOT_SUPPORTED;
|
|
hospi1.Init.ClockPrescaler = 1;
|
|
hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
|
|
hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_DISABLE;
|
|
hospi1.Init.ChipSelectBoundary = 0;
|
|
hospi1.Init.ClkChipSelectHighTime = 0;
|
|
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_BYPASSED;
|
|
hospi1.Init.MaxTran = 0;
|
|
hospi1.Init.Refresh = 0;
|
|
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
sOspiManagerCfg.ClkPort = 1;
|
|
sOspiManagerCfg.NCSPort = 1;
|
|
sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
|
|
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN OCTOSPI1_Init 2 */
|
|
|
|
/* USER CODE END OCTOSPI1_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_GPIOE_CLK_ENABLE();
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIO_Speaker_enable_GPIO_Port, GPIO_Speaker_enable_Pin, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_8|GPIO_PIN_4, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_RESET);
|
|
|
|
/*Configure GPIO pin : GPIO_Speaker_enable_Pin */
|
|
GPIO_InitStruct.Pin = GPIO_Speaker_enable_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(GPIO_Speaker_enable_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PE4 PE5 PE6 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_4|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_AF6_SAI1;
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : BTN_PAUSE_Pin BTN_GAME_Pin BTN_TIME_Pin */
|
|
GPIO_InitStruct.Pin = BTN_PAUSE_Pin|BTN_GAME_Pin|BTN_TIME_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PC0 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF11_LTDC;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PA4 PA5 PA6 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
|
|
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 pins : PA7 PA8 PA9 PA11 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PB0 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF9_LTDC;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PE13 PE15 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PB10 PB11 PB14 PB8 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_14|GPIO_PIN_8;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PB12 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_12;
|
|
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);
|
|
|
|
/*Configure GPIO pins : PD8 PD1 PD4 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_1|GPIO_PIN_4;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : BTN_A_Pin BTN_Left_Pin BTN_Down_Pin BTN_Right_Pin
|
|
BTN_Up_Pin BTN_B_Pin */
|
|
GPIO_InitStruct.Pin = BTN_A_Pin|BTN_Left_Pin|BTN_Down_Pin|BTN_Right_Pin
|
|
|BTN_Up_Pin|BTN_B_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PD10 PD3 PD6 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_3|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_AF14_LTDC;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PC6 PC7 PC10 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_10;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PC9 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_LTDC;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PA10 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_LTDC;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PD2 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF9_LTDC;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PB5 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF11_LTDC;
|
|
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 */
|
|
while(1) {
|
|
// Blink display to indicate failure
|
|
lcd_backlight_off();
|
|
HAL_Delay(200);
|
|
lcd_backlight_on();
|
|
HAL_Delay(200);
|
|
}
|
|
/* 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,
|
|
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
/* USER CODE END 6 */
|
|
}
|
|
#endif /* USE_FULL_ASSERT */
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|