2019-08-05 13:14:59 +01:00

389 lines
11 KiB
C

/**
******************************************************************************
* @file BSP/Src/main.c
* @author MCD Application Team
* @brief This example code shows how to use the STM32412G_DISCOVERY BSP Drivers
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2016 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
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stlogo.h"
/** @addtogroup STM32F7xx_HAL_Examples
* @{
*/
/** @addtogroup BSP
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint8_t DemoIndex = 0;
uint8_t NbLoop = 1;
uint32_t i, PsramTest = 0;
/* Global variables ----------------------------------------------------------*/
uint8_t SDDetectIT = 0;
/* Global extern variables ---------------------------------------------------*/
#ifndef USE_FULL_ASSERT
uint16_t ErrorCounter = 0;
#endif
/* Private function prototypes -----------------------------------------------*/
static void SystemClock_Config(void);
static void Display_DemoDescription(void);
static void MPU_ConfigPSRAM(void);
static void CPU_CACHE_Enable(void);
BSP_DemoTypedef BSP_examples[]=
{
{LCD_demo, "LCD", 0},
{Touchscreen_demo1, "TS Polling demo", 0},
{Touchscreen_demo2, "TS Dual Touch demo", 0},
{Touchscreen_demo3, "TS Interrupt demo", 0},
{Log_demo, "LCD LOG", 0},
{PSRAM_demo, "PSRAM", 0},
{PSRAM_DMA_demo, "PSRAM DMA", 0},
{QSPI_demo, "QSPI", 0},
{AudioPlay_demo, "AUDIO PLAY", 0},
{AudioLoopback_demo, "AUDIO REC PLAYBACK", 0},
};
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* Configure the MPU attributes for PSRAM external memory */
MPU_ConfigPSRAM();
/* Enable the CPU Cache */
CPU_CACHE_Enable();
/* STM32F7xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 216 Mhz */
SystemClock_Config();
BSP_LED_Init(LED5);
BSP_LED_Init(LED6);
/* Configure the User Button in GPIO Mode */
BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_GPIO);
/*##-1- Initialize the LCD #################################################*/
/* Initialize the LCD */
BSP_LCD_Init();
/* To choose the portrait orientation uncomment the below line. Note that the
TS should be also modified to portrait orientation and this by uncommenting */
/* ts_status = BSP_TS_InitEx(BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), TS_ORIENTATION_PORTRAIT); */
/* in ts_calibration.c file */
/* BSP_LCD_InitEx(LCD_ORIENTATION_PORTRAIT); */
Display_DemoDescription();
/* Wait For User inputs */
while (1)
{
if(BSP_PB_GetState(BUTTON_WAKEUP) != RESET)
{
HAL_Delay(10);
while (BSP_PB_GetState(BUTTON_WAKEUP) != RESET); /* Wait for button released */
BSP_examples[DemoIndex++].DemoFunc();
if(DemoIndex >= COUNT_OF_EXAMPLE(BSP_examples))
{
/* Increment number of loops which be used by EEPROM example */
NbLoop++;
DemoIndex = 0;
}
Display_DemoDescription();
}
Toggle_Leds();
}
}
/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
void Error_Handler(void)
{
while(1)
{
/* Insert a delay */
HAL_Delay(50);
}
}
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
* System Clock source = PLL (HSE)
* SYSCLK(Hz) = 216000000
* HCLK(Hz) = 216000000
* AHB Prescaler = 1
* APB1 Prescaler = 4
* APB2 Prescaler = 2
* HSE Frequency(Hz) = 25000000
* PLL_M = 25
* PLL_N = 432
* PLL_P = 2
* PLL_Q = 9
* PLL_R = 7
* VDD(V) = 3.3
* Main regulator output voltage = Scale1 mode
* Flash Latency(WS) = 7
* @param None
* @retval None
*/
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
HAL_StatusTypeDef ret = HAL_OK;
/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
if(ret != HAL_OK)
{
Error_Handler();
}
/* Activate the OverDrive to reach the 216 MHz Frequency */
ret = HAL_PWREx_EnableOverDrive();
if(ret != HAL_OK)
{
Error_Handler();
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
if(ret != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief Display main demo messages.
* @param None
* @retval None
*/
static void Display_DemoDescription(void)
{
uint8_t desc[50];
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
/* Clear the LCD */
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
BSP_LCD_Clear(LCD_COLOR_WHITE);
/* Set the LCD Text Color */
BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
/* Display LCD messages */
BSP_LCD_DisplayStringAt(0, 2, (uint8_t *)"STM32F723E BSP", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, 14, (uint8_t *)"Drivers examples", CENTER_MODE);
/* Draw Bitmap */
BSP_LCD_DrawBitmap((BSP_LCD_GetXSize() - 80)/2, 30, (uint8_t *)stlogo);
BSP_LCD_SetFont(&Font12);
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()-12, (uint8_t *)"STMicroelectronics 2016", CENTER_MODE);
BSP_LCD_SetFont(&Font12);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_FillRect(0, BSP_LCD_GetYSize()/2 + 1, BSP_LCD_GetXSize(), 60);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 20, (uint8_t *)"Press button to start :", CENTER_MODE);
sprintf((char *)desc,"%s example", BSP_examples[DemoIndex].DemoName);
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 35, (uint8_t *)desc, CENTER_MODE);
}
/**
* @brief Check for user input.
* @param None
* @retval Input state (1 : active / 0 : Inactive)
*/
uint8_t CheckForUserInput(void)
{
if(BSP_PB_GetState(BUTTON_WAKEUP) != RESET)
{
HAL_Delay(10);
while (BSP_PB_GetState(BUTTON_WAKEUP) != RESET);
return 1 ;
}
return 0;
}
/**
* @brief Toggle Leds.
* @param None
* @retval None
*/
void Toggle_Leds(void)
{
BSP_LED_Toggle(LED6);
HAL_Delay(50);
}
/**
* @brief EXTI line detection callbacks.
* @param GPIO_Pin: Specifies the pins connected EXTI line
* @retval None
*/
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
static uint32_t debounce_time = 0;
if(GPIO_Pin == BUTTON_WAKEUP)
{
/* Prevent debounce effect for user key */
if((HAL_GetTick() - debounce_time) > 50)
{
debounce_time = HAL_GetTick();
}
}
}
/**
* @brief Configure the MPU attributes as Write Back for PSRAM mapped on FMC
* BANK1/BANK2. This function configures two regions.
* @note The Base Address is 0x64000000 (for Display purposes) and
* 0x60000000 (for Audio Record module).
* The Region Size is 512KB, it is related to PSRAM memory size.
* @param None
* @retval None
*/
static void MPU_ConfigPSRAM(void)
{
MPU_Region_InitTypeDef MPU_InitStruct;
/* Disable the MPU */
HAL_MPU_Disable();
/* Configure the MPU attributes for PSRAM with recomended configurations:
Normal memory, Shareable, write-back (Display purposes) */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x64000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Configure the MPU attributes for PSRAM with recomended configurations:
Normal memory, Shareable, write-back */
MPU_InitStruct.BaseAddress = 0x60000000;
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enable the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
/**
* @brief CPU L1-Cache enable.
* @param None
* @retval None
*/
static void CPU_CACHE_Enable(void)
{
/* Enable I-Cache */
SCB_EnableICache();
/* Enable D-Cache */
SCB_EnableDCache();
}
#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 can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif /* USE_FULL_ASSERT */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/