mirror of
https://github.com/ghidraninja/game-and-watch-doom.git
synced 2025-12-18 19:16:00 +01:00
640 lines
20 KiB
C
640 lines
20 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 "buttons.h"
|
|
#include "flash.h"
|
|
#include "lcd.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 ---------------------------------------------------------*/
|
|
|
|
LTDC_HandleTypeDef hltdc;
|
|
|
|
OSPI_HandleTypeDef hospi1;
|
|
|
|
// SAI_HandleTypeDef hsai_BlockA1;
|
|
|
|
SPI_HandleTypeDef hspi2;
|
|
|
|
/* USER CODE BEGIN PV */
|
|
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
void SystemClock_Config(void);
|
|
static void MX_GPIO_Init(void);
|
|
static void MX_LTDC_Init(void);
|
|
static void MX_SPI2_Init(void);
|
|
static void MX_OCTOSPI1_Init(void);
|
|
// static void MX_SAI1_Init(void);
|
|
// static void MX_NVIC_Init(void);
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* 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_LTDC_Init();
|
|
MX_SPI2_Init();
|
|
MX_OCTOSPI1_Init();
|
|
// MX_SAI1_Init();
|
|
|
|
/* Initialize interrupts */
|
|
// MX_NVIC_Init();
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
lcd_init(&hspi2, &hltdc);
|
|
memset(framebuffer, 0x00, 320*240*2);
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
/* Infinite loop */
|
|
/* USER CODE BEGIN WHILE */
|
|
flash_memory_map(&hospi1);
|
|
|
|
// Sanity check, sometimes this is triggered
|
|
uint32_t add = 0x90000000;
|
|
uint32_t* ptr = (uint32_t*)add;
|
|
if(*ptr == 0x88888888) {
|
|
Error_Handler();
|
|
}
|
|
|
|
uint16_t color = 0x0000;
|
|
uint32_t i =0;
|
|
|
|
D_DoomMain();
|
|
|
|
while (1)
|
|
{
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
uint32_t buttons = buttons_get();
|
|
if(buttons & B_Left) {
|
|
color = 0xf000;
|
|
}
|
|
if(buttons & B_Right) {
|
|
color = 0x0f00;
|
|
}
|
|
if(buttons & B_Up) {
|
|
color = 0x00f0;
|
|
}
|
|
if(buttons & B_Down) {
|
|
|
|
color = *ptr&0xff;
|
|
}
|
|
|
|
for(int x=0; x < 320; x++) {
|
|
for(int y=0; y < 240; y++) {
|
|
// framebuffer[(y*320)+x] = i;
|
|
if(((x + i)/10 % 2 == 0) && (((y + i)/10 % 2 == 0))){
|
|
framebuffer[(y*320)+x] = color;
|
|
} else {
|
|
framebuffer[(y*320)+x] = 0xffff;
|
|
}
|
|
}
|
|
}
|
|
|
|
HAL_Delay(20);
|
|
i++;
|
|
}
|
|
/* 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)) {}
|
|
/** Macro to configure the PLL clock source
|
|
*/
|
|
__HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSI);
|
|
/** 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_LTDC|RCC_PERIPHCLK_SPI2
|
|
|RCC_PERIPHCLK_OSPI|RCC_PERIPHCLK_CKPER;
|
|
PeriphClkInitStruct.PLL3.PLL3M = 4;
|
|
PeriphClkInitStruct.PLL3.PLL3N = 9;
|
|
PeriphClkInitStruct.PLL3.PLL3P = 2;
|
|
PeriphClkInitStruct.PLL3.PLL3Q = 2;
|
|
PeriphClkInitStruct.PLL3.PLL3R = 24;
|
|
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_3;
|
|
PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOWIDE;
|
|
PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
|
|
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 LTDC Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_LTDC_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN LTDC_Init 0 */
|
|
|
|
/* USER CODE END LTDC_Init 0 */
|
|
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
LTDC_LayerCfgTypeDef pLayerCfg1 = {0};
|
|
|
|
/* USER CODE BEGIN LTDC_Init 1 */
|
|
|
|
/* USER CODE END LTDC_Init 1 */
|
|
hltdc.Instance = LTDC;
|
|
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IIPC;
|
|
hltdc.Init.HorizontalSync = 9;
|
|
hltdc.Init.VerticalSync = 1;
|
|
hltdc.Init.AccumulatedHBP = 60;
|
|
hltdc.Init.AccumulatedVBP = 7;
|
|
hltdc.Init.AccumulatedActiveW = 380;
|
|
hltdc.Init.AccumulatedActiveH = 247;
|
|
hltdc.Init.TotalWidth = 392;
|
|
hltdc.Init.TotalHeigh = 255;
|
|
hltdc.Init.Backcolor.Blue = 0;
|
|
hltdc.Init.Backcolor.Green = 0;
|
|
hltdc.Init.Backcolor.Red = 0;
|
|
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
pLayerCfg.WindowX0 = 0;
|
|
pLayerCfg.WindowX1 = 320;
|
|
pLayerCfg.WindowY0 = 0;
|
|
pLayerCfg.WindowY1 = 240;
|
|
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
pLayerCfg.Alpha = 255;
|
|
pLayerCfg.Alpha0 = 255;
|
|
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
|
|
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
|
|
pLayerCfg.FBStartAdress = 0x24000000;
|
|
pLayerCfg.ImageWidth = 320;
|
|
pLayerCfg.ImageHeight = 240;
|
|
pLayerCfg.Backcolor.Blue = 0;
|
|
pLayerCfg.Backcolor.Green = 255;
|
|
pLayerCfg.Backcolor.Red = 0;
|
|
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
pLayerCfg1.WindowX0 = 0;
|
|
pLayerCfg1.WindowX1 = 0;
|
|
pLayerCfg1.WindowY0 = 0;
|
|
pLayerCfg1.WindowY1 = 0;
|
|
pLayerCfg1.Alpha = 0;
|
|
pLayerCfg1.Alpha0 = 0;
|
|
pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
|
|
pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
|
|
pLayerCfg1.FBStartAdress = GFXMMU_VIRTUAL_BUFFER0_BASE;
|
|
pLayerCfg1.ImageWidth = 0;
|
|
pLayerCfg1.ImageHeight = 0;
|
|
pLayerCfg1.Backcolor.Blue = 0;
|
|
pLayerCfg1.Backcolor.Green = 0;
|
|
pLayerCfg1.Backcolor.Red = 0;
|
|
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg1, 1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN LTDC_Init 2 */
|
|
|
|
/* USER CODE END LTDC_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @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 = 20;
|
|
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 SPI2 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_SPI2_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN SPI2_Init 0 */
|
|
|
|
/* USER CODE END SPI2_Init 0 */
|
|
|
|
/* USER CODE BEGIN SPI2_Init 1 */
|
|
|
|
/* USER CODE END SPI2_Init 1 */
|
|
/* SPI2 parameter configuration*/
|
|
hspi2.Instance = SPI2;
|
|
hspi2.Init.Mode = SPI_MODE_MASTER;
|
|
hspi2.Init.Direction = SPI_DIRECTION_2LINES_TXONLY;
|
|
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
hspi2.Init.NSS = SPI_NSS_SOFT;
|
|
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
hspi2.Init.CRCPolynomial = 0x0;
|
|
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
|
|
hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
|
|
hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
|
|
hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
|
hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
|
hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
|
|
hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
|
|
hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
|
|
hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
|
|
hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
|
|
if (HAL_SPI_Init(&hspi2) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN SPI2_Init 2 */
|
|
|
|
/* USER CODE END SPI2_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 : 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 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 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);
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN 4 */
|
|
|
|
void EnableMemMapped(void) {
|
|
// OSPI_RegularCmdTypeDef sCommand;
|
|
OSPI_MemoryMappedTypeDef sMemMappedCfg;
|
|
|
|
OSPI_RegularCmdTypeDef sCommand = {
|
|
.Instruction = 0xeb, // 4READ
|
|
.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE,
|
|
.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD,
|
|
.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE,
|
|
.AddressMode = HAL_OSPI_ADDRESS_4_LINES,
|
|
.OperationType = HAL_OSPI_OPTYPE_READ_CFG,
|
|
.FlashId = 0,
|
|
.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE,
|
|
.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS,
|
|
.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_DISABLE,
|
|
.DataMode = HAL_OSPI_DATA_4_LINES,
|
|
.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE,
|
|
.DQSMode = HAL_OSPI_DQS_DISABLE,
|
|
.AddressSize = HAL_OSPI_ADDRESS_24_BITS,
|
|
.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD, // HAL_OSPI_SIOO_INST_ONLY_FIRST_CMD
|
|
// .SIOOMode = HAL_OSPI_SIOO_INST_ONLY_FIRST_CMD,
|
|
.DummyCycles = 4,
|
|
// .AlternateBytesSize = 1, //HAL_OSPI_ALTERNATE_BYTES_8_BITS, // ??? firmware uses '1' ??
|
|
.AlternateBytesSize = HAL_OSPI_ALTERNATE_BYTES_8_BITS, // ??? firmware uses '1' ??
|
|
.NbData = 1, // Data length
|
|
.AlternateBytes = 0x00,
|
|
};
|
|
|
|
// sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
|
|
// sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_8_LINES;
|
|
// sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
|
|
// sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
|
|
// sCommand.AddressMode = HAL_OSPI_ADDRESS_8_LINES;
|
|
// sCommand.AddressSize = HAL_OSPI_ADDRESS_32_BITS;
|
|
// sCommand.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_ENABLE;
|
|
// sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
|
|
// sCommand.DataMode = HAL_OSPI_DATA_8_LINES;
|
|
// sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_ENABLE;
|
|
// sCommand.DQSMode = HAL_OSPI_DQS_ENABLE;
|
|
// sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
|
|
// sCommand.Address = 0;
|
|
// sCommand.NbData = 1;
|
|
/* Memory-mapped mode configuration for Linear burst write operations */
|
|
// sCommand.OperationType = HAL_OSPI_OPTYPE_WRITE_CFG;
|
|
// sCommand.Instruction = 0x66; /* 4PP / 4 x page program */ // LINEAR_BURST_WRITE;
|
|
// sCommand.DummyCycles = 0; //DUMMY_CLOCK_CYCLES_SRAM_WRITE;
|
|
// if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) !=
|
|
// HAL_OK) {
|
|
// Error_Handler();
|
|
// }
|
|
// HAL_Delay(100);
|
|
|
|
// sCommand.OperationType = HAL_OSPI_OPTYPE_WRITE_CFG;
|
|
// sCommand.Instruction = 0x99; /* 4PP / 4 x page program */ // LINEAR_BURST_WRITE;
|
|
// sCommand.DummyCycles = 0; //DUMMY_CLOCK_CYCLES_SRAM_WRITE;
|
|
// if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) !=
|
|
// HAL_OK) {
|
|
// Error_Handler();
|
|
// }
|
|
// HAL_Delay(100);
|
|
|
|
|
|
|
|
sCommand.OperationType = HAL_OSPI_OPTYPE_WRITE_CFG;
|
|
sCommand.Instruction = 0x38; /* 4PP / 4 x page program */ // LINEAR_BURST_WRITE;
|
|
sCommand.DummyCycles = 0; //DUMMY_CLOCK_CYCLES_SRAM_WRITE;
|
|
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) !=
|
|
HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
/* Memory-mapped mode configuration for Linear burst read operations */
|
|
sCommand.OperationType = HAL_OSPI_OPTYPE_READ_CFG;
|
|
sCommand.Instruction = 0xEB; /* 4READ */ //LINEAR_BURST_READ;
|
|
sCommand.DummyCycles = 8; //DUMMY_CLOCK_CYCLES_SRAM_READ;
|
|
|
|
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) !=
|
|
HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
/*Disable timeout counter for memory mapped mode*/
|
|
sMemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;
|
|
sMemMappedCfg.TimeOutPeriod = 0;
|
|
/*Enable memory mapped mode*/
|
|
if (HAL_OSPI_MemoryMapped(&hospi1, &sMemMappedCfg) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
}
|
|
/* 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(500);
|
|
lcd_backlight_on();
|
|
HAL_Delay(500);
|
|
}
|
|
/* 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****/
|