Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG_patch mbed-rtos mbed
main.c
00001 /** 00002 ****************************************************************************** 00003 * @file main.c 00004 * @author MCD Application Team 00005 * @version V1.1.0 00006 * @date 21-September-2015 00007 * @brief This file provides main program functions 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "main.h" 00030 00031 /** @addtogroup CORE 00032 * @{ 00033 */ 00034 00035 /** @defgroup MAIN 00036 * @brief main file 00037 * @{ 00038 */ 00039 00040 /** @defgroup MAIN_Private_TypesDefinitions 00041 * @{ 00042 */ 00043 /** 00044 * @} 00045 */ 00046 00047 /** @defgroup MAIN_Private_Defines 00048 * @{ 00049 */ 00050 /** 00051 * @} 00052 */ 00053 00054 00055 /** @defgroup MAIN_Private_Macros 00056 * @{ 00057 */ 00058 /** 00059 * @} 00060 */ 00061 00062 00063 /** @defgroup MAIN_Private_Variables 00064 * @{ 00065 */ 00066 /** 00067 * @} 00068 */ 00069 00070 00071 /** @defgroup MAIN_Private_FunctionPrototypes 00072 * @{ 00073 */ 00074 static void MPU_Config(void); 00075 static void CPU_CACHE_Enable(void); 00076 static void SystemClock_Config(void); 00077 static void GUIThread(void const * argument); 00078 static void TimerCallback(void const *n); 00079 00080 #if !defined ( __GNUC__ ) 00081 extern K_ModuleItem_Typedef video_player_board; 00082 #endif 00083 extern K_ModuleItem_Typedef audio_player_board; 00084 extern K_ModuleItem_Typedef games_board; 00085 extern K_ModuleItem_Typedef gardening_control_board; 00086 extern K_ModuleItem_Typedef home_alarm_board; 00087 extern K_ModuleItem_Typedef settings_board; 00088 extern K_ModuleItem_Typedef audio_recorder_board; 00089 extern K_ModuleItem_Typedef vnc_server; 00090 00091 osTimerId lcd_timer; 00092 00093 #if defined ( __ICCARM__ ) /*!< IAR Compiler */ 00094 #pragma location=0x20006024 00095 uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; 00096 #elif defined ( __CC_ARM ) 00097 uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__((at(0x20006024))); 00098 #elif defined ( __GNUC__ ) 00099 uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__((section(".RamData2"))); 00100 #endif 00101 00102 /** 00103 * @} 00104 */ 00105 00106 /** @defgroup MAIN_Private_Functions 00107 * @{ 00108 */ 00109 00110 /** 00111 * @brief Main program 00112 * @param None 00113 * @retval int 00114 */ 00115 int main(void) 00116 { 00117 /* Configure the MPU attributes as Write Through */ 00118 MPU_Config(); 00119 00120 /* Enable the CPU Cache */ 00121 CPU_CACHE_Enable(); 00122 00123 /* STM32F7xx HAL library initialization: 00124 - Configure the Flash ART accelerator on ITCM interface 00125 - Configure the Systick to generate an interrupt each 1 msec 00126 - Set NVIC Group Priority to 4 00127 - Global MSP (MCU Support Package) initialization 00128 */ 00129 HAL_Init(); 00130 00131 /* Configure the system clock @ 200 Mhz */ 00132 SystemClock_Config(); 00133 00134 k_BspInit(); 00135 00136 /* Initialize RTC */ 00137 k_CalendarBkupInit(); 00138 00139 /* Create GUI task */ 00140 osThreadDef(GUI_Thread, GUIThread, osPriorityNormal, 0, 2048); 00141 osThreadCreate (osThread(GUI_Thread), NULL); 00142 00143 /* Add Modules*/ 00144 k_ModuleInit(); 00145 00146 /* Link modules */ 00147 k_ModuleAdd(&audio_player_board); 00148 #if !defined ( __GNUC__ ) 00149 k_ModuleAdd(&video_player_board); 00150 #endif 00151 k_ModuleAdd(&games_board); 00152 k_ModuleAdd(&audio_recorder_board); 00153 k_ModuleAdd(&gardening_control_board); 00154 k_ModuleAdd(&home_alarm_board); 00155 k_ModuleAdd(&vnc_server); 00156 k_ModuleAdd(&settings_board); 00157 00158 /* Initialize GUI */ 00159 GUI_Init(); 00160 00161 WM_MULTIBUF_Enable(1); 00162 GUI_SetLayerVisEx (1, 0); 00163 GUI_SelectLayer(0); 00164 00165 GUI_SetBkColor(GUI_WHITE); 00166 GUI_Clear(); 00167 00168 /* Set General Graphical proprieties */ 00169 k_SetGuiProfile(); 00170 00171 /* Create Touch screen Timer */ 00172 osTimerDef(TS_Timer, TimerCallback); 00173 lcd_timer = osTimerCreate(osTimer(TS_Timer), osTimerPeriodic, (void *)0); 00174 00175 /* Start the TS Timer */ 00176 osTimerStart(lcd_timer, 100); 00177 00178 /* Start scheduler */ 00179 osKernelStart (); 00180 00181 /* We should never get here as control is now taken by the scheduler */ 00182 for( ;; ); 00183 } 00184 00185 /** 00186 * @brief Start task 00187 * @param argument: pointer that is passed to the thread function as start argument. 00188 * @retval None 00189 */ 00190 static void GUIThread(void const * argument) 00191 { 00192 /* Initialize Storage Units */ 00193 k_StorageInit(); 00194 00195 /* Demo Startup */ 00196 k_StartUp(); 00197 00198 /* Show the main menu */ 00199 k_InitMenu(); 00200 00201 /* Gui background Task */ 00202 while(1) { 00203 GUI_Exec(); /* Do the background work ... Update windows etc.) */ 00204 osDelay(20); /* Nothing left to do for the moment ... Idle processing */ 00205 } 00206 } 00207 00208 /** 00209 * @brief Timer callbacsk (40 ms) 00210 * @param n: Timer index 00211 * @retval None 00212 */ 00213 static void TimerCallback(void const *n) 00214 { 00215 k_TouchUpdate(); 00216 } 00217 00218 /** 00219 * @brief System Clock Configuration 00220 * The system Clock is configured as follow : 00221 * System Clock source = PLL (HSE) 00222 * SYSCLK(Hz) = 200000000 00223 * HCLK(Hz) = 200000000 00224 * AHB Prescaler = 1 00225 * APB1 Prescaler = 4 00226 * APB2 Prescaler = 2 00227 * HSE Frequency(Hz) = 25000000 00228 * PLL_M = 25 00229 * PLL_N = 400 00230 * PLL_P = 2 00231 * PLLSAI_N = 384 00232 * PLLSAI_P = 8 00233 * VDD(V) = 3.3 00234 * Main regulator output voltage = Scale1 mode 00235 * Flash Latency(WS) = 6 00236 * @param None 00237 * @retval None 00238 */ 00239 void SystemClock_Config(void) 00240 { 00241 RCC_ClkInitTypeDef RCC_ClkInitStruct; 00242 RCC_OscInitTypeDef RCC_OscInitStruct; 00243 HAL_StatusTypeDef ret = HAL_OK; 00244 00245 /* Enable HSE Oscillator and activate PLL with HSE as source */ 00246 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 00247 RCC_OscInitStruct.HSEState = RCC_HSE_ON; 00248 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 00249 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 00250 RCC_OscInitStruct.PLL.PLLM = 25; 00251 RCC_OscInitStruct.PLL.PLLN = 400; 00252 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 00253 HAL_RCC_OscConfig(&RCC_OscInitStruct); 00254 00255 ret = HAL_PWREx_EnableOverDrive(); 00256 00257 if(ret != HAL_OK) 00258 { 00259 while(1) { ; } 00260 } 00261 00262 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 00263 clocks dividers */ 00264 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); 00265 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 00266 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 00267 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 00268 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 00269 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6); 00270 } 00271 00272 00273 /** 00274 * @brief This function provides accurate delay (in milliseconds) based 00275 * on SysTick counter flag. 00276 * @note This function is declared as __weak to be overwritten in case of other 00277 * implementations in user file. 00278 * @param Delay: specifies the delay duration in milliseconds. 00279 * @retval None 00280 */ 00281 00282 void HAL_Delay (__IO uint32_t Delay) 00283 { 00284 while(Delay) 00285 { 00286 if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) 00287 { 00288 Delay--; 00289 } 00290 } 00291 } 00292 00293 /** 00294 * @brief Configure the MPU attributes as Write Through for SRAM1/2. 00295 * @note The Base Address is 0x20010000 since this memory interface is the AXI. 00296 * The Region Size is 256KB, it is related to SRAM1 and SRAM2 memory size. 00297 * @param None 00298 * @retval None 00299 */ 00300 static void MPU_Config(void) 00301 { 00302 MPU_Region_InitTypeDef MPU_InitStruct; 00303 00304 /* Disable the MPU */ 00305 HAL_MPU_Disable(); 00306 00307 /* Configure the MPU attributes as WT for SRAM */ 00308 MPU_InitStruct.Enable = MPU_REGION_ENABLE; 00309 MPU_InitStruct.BaseAddress = 0x20010000; 00310 MPU_InitStruct.Size = MPU_REGION_SIZE_256KB; 00311 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; 00312 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE; 00313 MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE; 00314 MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE; 00315 MPU_InitStruct.Number = MPU_REGION_NUMBER0; 00316 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0; 00317 MPU_InitStruct.SubRegionDisable = 0x00; 00318 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; 00319 00320 HAL_MPU_ConfigRegion(&MPU_InitStruct); 00321 00322 /* Enable the MPU */ 00323 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); 00324 } 00325 00326 00327 /** 00328 * @brief CPU L1-Cache enable. 00329 * @param None 00330 * @retval None 00331 */ 00332 static void CPU_CACHE_Enable(void) 00333 { 00334 /* Enable branch prediction */ 00335 SCB->CCR |= (1 <<18); 00336 __DSB(); 00337 00338 /* Enable I-Cache */ 00339 SCB_EnableICache(); 00340 00341 /* Enable D-Cache */ 00342 SCB_EnableDCache(); 00343 } 00344 00345 #ifdef USE_FULL_ASSERT 00346 /** 00347 * @brief assert_failed 00348 * Reports the name of the source file and the source line number 00349 * where the assert_param error has occurred. 00350 * @param File: pointer to the source file name 00351 * @param Line: assert_param error line source number 00352 * @retval None 00353 */ 00354 void assert_failed(uint8_t* file, uint32_t line) 00355 { 00356 /* User can add his own implementation to report the file name and line 00357 number,ex: printf("Wrong parameters value: file %s on line %d\r\n", 00358 file, line) */ 00359 00360 /* Infinite loop */ 00361 while (1) 00362 {} 00363 } 00364 00365 #endif 00366 00367 00368 /** 00369 * @} 00370 */ 00371 00372 /** 00373 * @} 00374 */ 00375 00376 /** 00377 * @} 00378 */ 00379 00380 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 14:57:40 by
1.7.2