mirror of
https://github.com/STMicroelectronics/STM32CubeF7.git
synced 2025-05-03 22:17:13 +08:00
420 lines
12 KiB
C
420 lines
12 KiB
C
/**
|
|
******************************************************************************
|
|
* @file BSP/Src/main.c
|
|
* @author MCD Application Team
|
|
* @brief This example code shows how to use the STM32756G_EVAL BSP Drivers
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© 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;
|
|
__IO uint8_t NbLoop = 1;
|
|
|
|
/* Wave Player Pause/Resume Status. Defined as external in waveplayer.c file */
|
|
__IO uint32_t PauseResumeStatus = IDLE_STATUS;
|
|
|
|
/* Counter for Sel Joystick pressed*/
|
|
__IO uint32_t PressCount = 0;
|
|
|
|
/* Joystick Status */
|
|
static JOYState_TypeDef JoyState = JOY_NONE;
|
|
|
|
|
|
/* Volume of the audio playback */
|
|
/* Initial volume level (from 0% (Mute) to 100% (Max)) */
|
|
__IO uint8_t volume = 60;
|
|
__IO uint8_t VolumeChange = 0;
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
void SystemClock_Config(void);
|
|
static void Display_DemoDescription(void);
|
|
static void CPU_CACHE_Enable(void);
|
|
static void MPU_ConfigNOR(void);
|
|
|
|
BSP_DemoTypedef BSP_examples[]=
|
|
{
|
|
{Joystick_demo, "JOYSTICK", 0},
|
|
{Touchscreen_demo, "TOUCHSCREEN", 0},
|
|
{LCD_demo, "LCD", 0},
|
|
{SD_demo, "SD", 0},
|
|
{EEPROM_demo, "EEPROM", 0},
|
|
{NOR_demo, "NOR", 0},
|
|
{SRAM_demo, "SRAM", 0},
|
|
{SDRAM_demo, "SDRAM", 0},
|
|
{Log_demo, "LCD LOG", 0},
|
|
};
|
|
/* Private functions ---------------------------------------------------------*/
|
|
|
|
/**
|
|
* @brief Main program
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
int main(void)
|
|
{
|
|
/* Set MPU NOR region */
|
|
MPU_ConfigNOR();
|
|
|
|
/* Enable the CPU Cache */
|
|
CPU_CACHE_Enable();
|
|
|
|
/* STM32F7xx HAL library initialization:
|
|
- Configure the Flash ART accelerator on ITCM interface
|
|
- Systick timer is configured by default as source of time base, but user
|
|
can eventually implement his proper time base source (a general purpose
|
|
timer for example or other time source), keeping in mind that Time base
|
|
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
|
|
handled in milliseconds basis.
|
|
- Set NVIC Group Priority to 4
|
|
- Low Level Initialization
|
|
*/
|
|
HAL_Init();
|
|
|
|
/* Configure the system clock to 200 MHz */
|
|
SystemClock_Config();
|
|
|
|
BSP_LED_Init(LED_GREEN);
|
|
BSP_LED_Init(LED_ORANGE);
|
|
BSP_LED_Init(LED_RED);
|
|
BSP_LED_Init(LED_BLUE);
|
|
|
|
|
|
/* Camera power down sequence */
|
|
BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT);
|
|
BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT);
|
|
/* De-assert the camera STANDBY pin (active high) */
|
|
BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_RESET);
|
|
/* Assert the camera RSTI pin (active low) */
|
|
BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET);
|
|
|
|
/* Configure the Tamper push-button in GPIO Mode */
|
|
BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);
|
|
|
|
/*##-1- Initialize the LCD #################################################*/
|
|
/* Initialize the LCD */
|
|
BSP_LCD_Init();
|
|
|
|
BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS);
|
|
|
|
Display_DemoDescription();
|
|
|
|
/* Wait For User inputs */
|
|
while (1)
|
|
{
|
|
|
|
if(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET)
|
|
{
|
|
while (BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET);
|
|
|
|
BSP_examples[DemoIndex++].DemoFunc();
|
|
|
|
if(DemoIndex >= COUNT_OF_EXAMPLE(BSP_examples))
|
|
{
|
|
NbLoop++;
|
|
DemoIndex = 0;
|
|
}
|
|
Display_DemoDescription();
|
|
}
|
|
Toggle_Leds();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief System Clock Configuration
|
|
* The system Clock is configured as follow :
|
|
* System Clock source = PLL (HSE)
|
|
* SYSCLK(Hz) = 200000000
|
|
* HCLK(Hz) = 200000000
|
|
* AHB Prescaler = 1
|
|
* APB1 Prescaler = 4
|
|
* APB2 Prescaler = 2
|
|
* HSE Frequency(Hz) = 25000000
|
|
* PLL_M = 25
|
|
* PLL_N = 400
|
|
* PLL_P = 2
|
|
* PLL_Q = 8
|
|
* VDD(V) = 3.3
|
|
* Main regulator output voltage = Scale1 mode
|
|
* Flash Latency(WS) = 6
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void SystemClock_Config(void)
|
|
{
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
HAL_StatusTypeDef ret = HAL_OK;
|
|
|
|
/* 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 = 400;
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
RCC_OscInitStruct.PLL.PLLQ = 8;
|
|
|
|
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
|
if(ret != HAL_OK)
|
|
{
|
|
while(1) { ; }
|
|
}
|
|
|
|
/* Activate the OverDrive to reach the 200 MHz Frequency */
|
|
ret = HAL_PWREx_EnableOverDrive();
|
|
if(ret != HAL_OK)
|
|
{
|
|
while(1) { ; }
|
|
}
|
|
|
|
/* 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_6);
|
|
if(ret != HAL_OK)
|
|
{
|
|
while(1) { ; }
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Display main demo messages
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void Display_DemoDescription(void)
|
|
{
|
|
char desc[50];
|
|
|
|
/* Set LCD Foreground Layer */
|
|
BSP_LCD_SelectLayer(1);
|
|
|
|
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, 10, (uint8_t *)"STM32756G BSP", CENTER_MODE);
|
|
BSP_LCD_DisplayStringAt(0, 35, (uint8_t *)"Drivers examples", CENTER_MODE);
|
|
|
|
/* Draw Bitmap */
|
|
BSP_LCD_DrawBitmap((BSP_LCD_GetXSize() - 80)/2, 65, (uint8_t *)stlogo);
|
|
|
|
BSP_LCD_SetFont(&Font12);
|
|
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 20, (uint8_t *)"Copyright (c) STMicroelectronics 2016", CENTER_MODE);
|
|
|
|
BSP_LCD_SetFont(&Font16);
|
|
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
|
|
BSP_LCD_FillRect(0, BSP_LCD_GetYSize()/2 + 15, BSP_LCD_GetXSize(), 60);
|
|
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
|
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
|
|
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() / 2 + 30, (uint8_t *)"Press Tamper push-button to start :", CENTER_MODE);
|
|
sprintf(desc,"%s example", BSP_examples[DemoIndex].DemoName);
|
|
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 45, (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_TAMPER) == GPIO_PIN_SET)
|
|
{
|
|
while (BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET);
|
|
return 1 ;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* @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)
|
|
{
|
|
/* If the interruption comes from the Joystick, check which
|
|
Joystick button has been pressed */
|
|
JoyState = BSP_JOY_GetState();
|
|
|
|
if(JoyState == JOY_SEL)
|
|
{
|
|
/* SEL is used to pause and resume the audio playback */
|
|
if (PressCount == 1)
|
|
{
|
|
/* Resume playing Wave status */
|
|
PauseResumeStatus = RESUME_STATUS;
|
|
PressCount = 0;
|
|
}
|
|
else
|
|
{
|
|
/* Pause playing Wave status */
|
|
PauseResumeStatus = PAUSE_STATUS;
|
|
PressCount = 1;
|
|
}
|
|
}
|
|
else if(JoyState == JOY_UP)
|
|
{
|
|
/* UP is used to increment the volume of the audio playback */
|
|
volume ++;
|
|
if (volume > 100)
|
|
{
|
|
volume = 100;
|
|
}
|
|
VolumeChange = 1;
|
|
}
|
|
else if(JoyState == JOY_DOWN)
|
|
{
|
|
/* DOWN is used to decrement the volume of the audio playback */
|
|
volume --;
|
|
if ((int8_t)volume < 50)
|
|
{
|
|
volume = 50;
|
|
}
|
|
VolumeChange = 1;
|
|
}
|
|
|
|
/* Clear MFX IT */
|
|
BSP_IO_ITClear();
|
|
}
|
|
|
|
/**
|
|
* @brief Toggle Leds
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void Toggle_Leds(void)
|
|
{
|
|
BSP_LED_Toggle(LED_GREEN);
|
|
HAL_Delay(50);
|
|
}
|
|
|
|
/**
|
|
* @brief This function is executed in case of error occurrence.
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void Error_Handler(void)
|
|
{
|
|
/* Turn LED REDon */
|
|
BSP_LED_On(LED_RED);
|
|
while(1)
|
|
{
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @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();
|
|
}
|
|
|
|
/**
|
|
* @brief Configure the MPU attributes as as device for NOR.
|
|
* @note The Base Address is 0x60000000.
|
|
* The Region Size is 16MBytes, it is related to NOR memory size.
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MPU_ConfigNOR(void)
|
|
{
|
|
MPU_Region_InitTypeDef MPU_InitStruct;
|
|
|
|
/* Disable the MPU */
|
|
HAL_MPU_Disable();
|
|
|
|
/* Configure the MPU attributes as device for NOR */
|
|
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
|
MPU_InitStruct.BaseAddress = 0x60000000;
|
|
MPU_InitStruct.Size = MPU_REGION_SIZE_16MB;
|
|
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
|
|
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
|
|
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
|
|
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
|
|
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
|
|
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
|
MPU_InitStruct.SubRegionDisable = 0x00;
|
|
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
|
|
|
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
|
|
|
/* Enable the MPU */
|
|
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
|
}
|
|
|
|
#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****/
|