- /**
- ******************************************************************************
- * [url=home.php?mod=space&uid=288409]@file[/url] USB_Host/FWupgrade_Standalone/Src/main.c
- * [url=home.php?mod=space&uid=187600]@author[/url] MCD Application Team
- * [url=home.php?mod=space&uid=895143]@version[/url] V1.0.1
- * [url=home.php?mod=space&uid=212281]@date[/url] 26-February-2014
- * [url=home.php?mod=space&uid=247401]@brief[/url] USB host Firmware Upgrade demo main file
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- USBH_HandleTypeDef hUSBHost;
- FW_ApplicationTypeDef Appli_state = APPLICATION_DISCONNECT;
- uint32_t JumpAddress;
- pFunction Jump_To_Application;
- /* Private function prototypes -----------------------------------------------*/
- static void SystemClock_Config(void);
- static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id);
- static void FW_InitApplication(void);
- /* Private functions ---------------------------------------------------------*/
- /**
- * @brief Main program
- * @param None
- * @retval None
- */
- int main(void)
- {
- /* Configure KEY Button */
- BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
-
- /* Unlock the Flash to enable the flash control register access */
- FLASH_If_FlashUnlock();
-
- /* Test if User button on the STM324xG_EVAL is pressed */
- if (BSP_PB_GetState(BUTTON_KEY) != GPIO_PIN_RESET)
- {
- /* Check Vector Table: Test if user code is programmed starting from address
- "APPLICATION_ADDRESS" */
- if ((((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0xFF000000 ) == 0x20000000) || \
- (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0xFF000000 ) == 0x10000000))
- {
- /* Jump to user application */
- JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
- Jump_To_Application = (pFunction) JumpAddress;
- /* Initialize user application's Stack Pointer */
- __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
- Jump_To_Application();
- }
- }
-
- /* STM32F4xx 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 168 Mhz */
- SystemClock_Config();
-
- /* Init FW upgrade Application */
- FW_InitApplication();
-
- /* Init Host Library */
- USBH_Init(&hUSBHost, USBH_UserProcess, 0);
-
- /* Add Supported Class */
- USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
-
- /* Start Host Process */
- USBH_Start(&hUSBHost);
-
- /* Run Application (Blocking mode)*/
- while (1)
- {
- /* USB Host Background task */
- USBH_Process(&hUSBHost);
-
- /* FW Menu Process */
- FW_UPGRADE_Process();
- }
- }
- /**
- * @brief FW application Init.
- * @param None
- * @retval None
- */
- static void FW_InitApplication(void)
- {
- /* Configure the LEDs */
- BSP_LED_Init(LED3);
- BSP_LED_Init(LED4);
- }
- /**
- * @brief User Process
- * @param phost: Host Handle
- * @param id: Host Library user message ID
- * @retval None
- */
- static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
- {
- switch(id)
- {
- case HOST_USER_SELECT_CONFIGURATION:
- break;
-
- case HOST_USER_DISCONNECTION:
- Appli_state = APPLICATION_DISCONNECT;
- break;
-
- case HOST_USER_CLASS_ACTIVE:
- Appli_state = APPLICATION_READY;
- break;
-
- case HOST_USER_CONNECTION:
- Appli_state = APPLICATION_CONNECT;
- break;
-
- default:
- break;
- }
- }
- /**
- * @brief System Clock Configuration
- * The system Clock is configured as follow :
- * System Clock source = PLL (HSE)
- * SYSCLK(Hz) = 168000000
- * HCLK(Hz) = 168000000
- * AHB Prescaler = 1
- * APB1 Prescaler = 4
- * APB2 Prescaler = 2
- * HSE Frequency(Hz) = 8000000
- * PLL_M = 8
- * PLL_N = 336
- * PLL_P = 2
- * PLL_Q = 7
- * VDD(V) = 3.3
- * Main regulator output voltage = Scale1 mode
- * Flash Latency(WS) = 5
- * @param None
- * @retval None
- */
- static void SystemClock_Config(void)
- {
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- RCC_OscInitTypeDef RCC_OscInitStruct;
-
- /* 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 = 8;
- RCC_OscInitStruct.PLL.PLLN = 336;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
- RCC_OscInitStruct.PLL.PLLQ = 7;
- HAL_RCC_OscConfig(&RCC_OscInitStruct);
-
-
- /* 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;
- HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
- }
- #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
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|