şljnk
C
code posted
created at 11 Feb 09:25
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
/** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * This notice applies to any and all portions of this file * that are not between comment pairs USER CODE BEGIN and * USER CODE END. Other portions of this file, whether * inserted by the user or by software development tools * are owned by their respective copyright owners. * * Copyright (c) 2018 STMicroelectronics International N.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted, provided that the following conditions are met: * * 1. Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of other * contributors to this software may be used to endorse or promote products * derived from this software without specific written permission. * 4. This software, including modifications and/or derivative works of this * software, must execute solely and exclusively on microcontroller or * microprocessor devices manufactured by or for STMicroelectronics. * 5. Redistribution and use of this software other than as permitted under * this license is void and will automatically terminate your rights under * this license. * * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f7xx_hal.h" #include "main.h" #include "string.h" #include "crc.h" #include "dma.h" #include "dma2d.h" #include "i2c.h" #include "iwdg.h" #include "ltdc.h" #include "tim.h" #include "gpio.h" #include "Project.h" #include "Eeprom.h" #include "Timer.h" #include "Usart.h" #include "External.h" #include "Flash.h" #include "RTC.h" #include "Modem.h" #include "Wifi.h" #include "RFID.h" #include "Message.h" #include "Offline.h" #include "FMCTFT_Main.h" #include "RF433.h" //--------------------------------------------------------------------------------------- // Wifi signal quality �l��lecek /* Private variables ---------------------------------------------------------*/ uint32_t ADC1ConvertedValues[4] = { 0 }; DMA_HandleTypeDef hdma_adc1; IWDG_HandleTypeDef hiwdg; RNG_HandleTypeDef hrng; ADC_HandleTypeDef hadc1; SPI_HandleTypeDef hspi2, hspi4; TIM_HandleTypeDef htim6; TIM_HandleTypeDef htim7; RTC_HandleTypeDef hrtc; RTC_TimeTypeDef sTime; RTC_DateTypeDef sDate; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void WatchdogInit(void); void ExtraInit(void); extern void GRAPHICS_HW_Init(void); extern void GRAPHICS_Init(void); extern void GRAPHICS_MainTask(void); /* Private function prototypes -----------------------------------------------*/ /** * @brief The application entry point. * * @retval None */ int main(void) { /* Declarations */ char TemporaryBuffer[100] = ""; /* Disable watchdog when we are in debug mode */ DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_IWDG_STOP; /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ WatchdogInit(); HAL_IWDG_Refresh(&hiwdg); ExtraInit(); EEPROM_LowLevelInit(); HAL_IWDG_Refresh(&hiwdg); TIMER_InitAll(); HAL_IWDG_Refresh(&hiwdg); USART_External1_Init(115200); HAL_IWDG_Refresh(&hiwdg); EXTERNAL_Init(); HAL_IWDG_Refresh(&hiwdg); FLASH_Init(); HAL_IWDG_Refresh(&hiwdg); RTC_Start(); HAL_IWDG_Refresh(&hiwdg); MODEM_Init(FALSE); HAL_IWDG_Refresh(&hiwdg); WIFI_Init(); HAL_IWDG_Refresh(&hiwdg); RFID_Init(); HAL_IWDG_Refresh(&hiwdg); if( FLASH_INT[ForcedLock].value == 1 ){ USART_PrintDebugMessage(10, "[MAIN] Forced Lock Active!", TRUE, TRUE); } sprintf(TemporaryBuffer,"%s\r%s\r",FIRMWARE_DATE,FIRMWARE_VERSION); USART_PrintDebugMessage(10, TemporaryBuffer, TRUE, TRUE); HAL_GPIO_WritePin(BUZZER_PORT, BUZZER_PIN, GPIO_PIN_SET); UTIL_Delay(50); HAL_GPIO_WritePin(BUZZER_PORT, BUZZER_PIN, GPIO_PIN_RESET); // Start timer6 HAL_TIM_Base_Start(&htim6); HAL_IWDG_Refresh(&hiwdg); // Start timer7 HAL_TIM_Base_Start(&htim7); HAL_IWDG_Refresh(&hiwdg); // PWM MX_TIM4_Init(); if(FLASH_INT[PWMDuty].value > 100){ FLASH_INT[PWMDuty].value = 100; PROJECT_ChangeBacklightPWMDuty(FLASH_INT[PWMDuty].value); }else{ PROJECT_ChangeBacklightPWMDuty(FLASH_INT[PWMDuty].value); } PROJECT_ChangeKonum(FLASH_STR[LocationNew].link); PROJECT_ChangePassword(FLASH_STR[ScreenPassword].link); ChangeRTCClock(); PROJECT_Main(); /* Initialise the graphical hardware */ GRAPHICS_HW_Init(); /* Initialise the graphical stack engine */ GRAPHICS_Init(); /* Graphic application */ GRAPHICS_MainTask(); /* Infinite loop */ while (1) { } } /** * @brief System RTC Clock Configuration * @retval None */ void ChangeRTCClock(void) { /* Declarations */ char hour[3] = "", minute[3] = "", second[3] = ""; char day[3] = "", month[3] = "", year[3] = ""; strncpy(hour, FLASH_STR[Hour].link, 2); hour[2] = 0 ; strncpy(minute, &FLASH_STR[Hour].link[2], 2); minute[2] = 0; strncpy(second, &FLASH_STR[Hour].link[4], 2); second[2] = 0 ; strncpy(day, FLASH_STR[DateStr].link, 2); day[2] = 0 ; strncpy(month, &FLASH_STR[DateStr].link[2], 2); month[2] = 0 ; strncpy(year, &FLASH_STR[DateStr].link[4], 2); year[2] = 0 ; FMCTFT_ChangeRealTime(CONVERT_atoi(day), CONVERT_atoi(month), 2000+CONVERT_atoi(year), CONVERT_atoi(hour), CONVERT_atoi(minute), CONVERT_atoi(second)); } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; /**Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); // Backup access HAL_PWR_EnableBkUpAccess(); /** Configure LSE Drive Capability */ __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /**Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_ON; RCC_OscInitStruct.LSEState = RCC_LSE_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 = 2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Activate the Over-Drive mode */ if (HAL_PWREx_EnableOverDrive() != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |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_DIV4; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_LTDC|RCC_PERIPHCLK_I2C3 |RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_UART5 |RCC_PERIPHCLK_UART7; PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; PeriphClkInitStruct.PLLSAI.PLLSAIN = 384; PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; PeriphClkInitStruct.PLLSAI.PLLSAIQ = 2; PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV2; PeriphClkInitStruct.PLLSAIDivQ = 1; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8; PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1; PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1; PeriphClkInitStruct.Uart5ClockSelection = RCC_UART5CLKSOURCE_PCLK1; PeriphClkInitStruct.Uart7ClockSelection = RCC_UART7CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); /**Configure the Systick */ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); /* SysTick_IRQn interrupt configuration */ HAL_NVIC_SetPriority(SysTick_IRQn, 0, 1); } //---------------------------------------------------------------------- // Initialize watchdog void WatchdogInit(void) { hiwdg.Instance = IWDG; hiwdg.Init.Prescaler = IWDG_PRESCALER_256; hiwdg.Init.Window = 4095; hiwdg.Init.Reload = 4095; // if (HAL_IWDG_Init(&hiwdg) != HAL_OK) // { // _Error_Handler(__FILE__, __LINE__); // } } //------------------------------------------------------------------------------- // Initialize GPIO pins void ExtraInit(void) { /* Declarations */ GPIO_InitTypeDef GPIO_InitStruct; ADC_ChannelConfTypeDef sConfig; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_DMA1_CLK_ENABLE(); __HAL_RCC_DMA2_CLK_ENABLE(); MX_GPIO_Init(); MX_DMA_Init(); MX_CRC_Init(); MX_I2C3_Init(); // Random number generator hrng.Instance = RNG; if (HAL_RNG_Init(&hrng) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } //--------------------------------------------------------------------------------------- /* DMA2_Stream0_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 4, 1); HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn); /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = ENABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 4; hadc1.Init.DMAContinuousRequests = ENABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; if (HAL_ADC_Init(&hadc1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_112CYCLES; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_2; sConfig.Rank = 2; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_7; sConfig.Rank = 3; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_11; sConfig.Rank = 4; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /* Start ADC DMA */ HAL_ADC_Start(&hadc1); HAL_ADC_Start_DMA(&hadc1, ADC1ConvertedValues, 4); //--------------------------------------------------------------------- // Analog pins // A0: Power GSM // A2: Power Vbatt // A7: Power 24V // C1: Power 5V GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_1; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); //---------------------------------------------------------------------- // Output pins GPIO_InitStruct.Pin = STATUS_LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(STATUS_LED_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = BUZZER_PIN; HAL_GPIO_Init(BUZZER_PORT, &GPIO_InitStruct); } /** * @brief Period elapsed callback in non blocking mode * @note This function is called when TIM1 interrupt took place, inside * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment * a global variable "uwTick" used as application time base. * @param htim : TIM handle * @retval None */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { /* USER CODE BEGIN Callback 0 */ /* USER CODE END Callback 0 */ if(htim->Instance == TIM6){ TIMER_InterruptHandler(); } /* USER CODE END Callback 0 */ if(htim->Instance == TIM7){ RF433_Handler(); } /* USER CODE BEGIN Callback 1 */ /* USER CODE END Callback 1 */ } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { } /** * @brief Wake Up Timer callback * @param hrtc : hrtc handle * @retval None */ void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) { } /** * @brief This function is executed in case of error occurrence. * @param file: The file name as string. * @param line: The line in file as a number. * @retval None */ void _Error_Handler(char *file, int line) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ NVIC_SystemReset(); while(1) { } /* 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****/ |
16.6 KB in 10 ms with coderay