Title / Description
Code /** ****************************************************************************** * @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****/
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code