Guest User

Untitled

a guest
Dec 13th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.81 KB | None | 0 0
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19. /* USER CODE END Header */
  20.  
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23. #include "stm32f1xx_hal_tim.h"
  24.  
  25. /* Private includes ----------------------------------------------------------*/
  26. /* USER CODE BEGIN Includes */
  27.  
  28. /* USER CODE END Includes */
  29.  
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* USER CODE BEGIN PTD */
  32.  
  33. /* USER CODE END PTD */
  34.  
  35. /* Private define ------------------------------------------------------------*/
  36. /* USER CODE BEGIN PD */
  37. /* USER CODE END PD */
  38.  
  39. /* Private macro -------------------------------------------------------------*/
  40. /* USER CODE BEGIN PM */
  41.  
  42. /* USER CODE END PM */
  43.  
  44. /* Private variables ---------------------------------------------------------*/
  45. RTC_HandleTypeDef hrtc;
  46.  
  47. TIM_HandleTypeDef htim4;
  48.  
  49. /* USER CODE BEGIN PV */
  50.  
  51. /* USER CODE END PV */
  52.  
  53. /* Private function prototypes -----------------------------------------------*/
  54. void SystemClock_Config(void);
  55. static void MX_GPIO_Init(void);
  56. static void MX_TIM4_Init(void);
  57. static void MX_RTC_Init(void);
  58. /* USER CODE BEGIN PFP */
  59.  
  60. /* USER CODE END PFP */
  61.  
  62. /* Private user code ---------------------------------------------------------*/
  63. /* USER CODE BEGIN 0 */
  64.  
  65. HAL_TIM_Base_Start(&htim4);
  66. HAL_TIM_Base_Start_IT(&htim4);
  67.  
  68. /* USER CODE END 0 */
  69.  
  70. /**
  71.   * @brief  The application entry point.
  72.   * @retval int
  73.   */
  74. int main(void)
  75. {
  76.   /* USER CODE BEGIN 1 */
  77.  
  78.   /* USER CODE END 1 */
  79.  
  80.  
  81.   /* MCU Configuration--------------------------------------------------------*/
  82.  
  83.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  84.   HAL_Init();
  85.  
  86.   /* USER CODE BEGIN Init */
  87.  
  88.   /* USER CODE END Init */
  89.  
  90.   /* Configure the system clock */
  91.   SystemClock_Config();
  92.  
  93.   /* USER CODE BEGIN SysInit */
  94.  
  95.   /* USER CODE END SysInit */
  96.  
  97.   /* Initialize all configured peripherals */
  98.   MX_GPIO_Init();
  99.   MX_TIM4_Init();
  100.   MX_RTC_Init();
  101.   /* USER CODE BEGIN 2 */
  102.  
  103.   /* USER CODE END 2 */
  104.  
  105.   /* Infinite loop */
  106.   /* USER CODE BEGIN WHILE */
  107.   while (1)
  108.   {
  109.     /* USER CODE END WHILE */
  110.  
  111.     /* USER CODE BEGIN 3 */
  112.   }
  113.   /* USER CODE END 3 */
  114. }
  115.  
  116. /**
  117.   * @brief System Clock Configuration
  118.   * @retval None
  119.   */
  120. void SystemClock_Config(void)
  121. {
  122.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  123.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  124.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  125.  
  126.   /** Initializes the CPU, AHB and APB busses clocks
  127.   */
  128.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
  129.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  130.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  131.   RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  132.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  133.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  134.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  135.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  136.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  137.   {
  138.     Error_Handler();
  139.   }
  140.   /** Initializes the CPU, AHB and APB busses clocks
  141.   */
  142.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  143.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  144.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  145.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  146.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  147.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  148.  
  149.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  150.   {
  151.     Error_Handler();
  152.   }
  153.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  154.   PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  155.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  156.   {
  157.     Error_Handler();
  158.   }
  159. }
  160.  
  161. /**
  162.   * @brief RTC Initialization Function
  163.   * @param None
  164.   * @retval None
  165.   */
  166. static void MX_RTC_Init(void)
  167. {
  168.  
  169.   /* USER CODE BEGIN RTC_Init 0 */
  170.  
  171.   /* USER CODE END RTC_Init 0 */
  172.  
  173.   RTC_TimeTypeDef sTime = {0};
  174.   RTC_DateTypeDef DateToUpdate = {0};
  175.  
  176.   /* USER CODE BEGIN RTC_Init 1 */
  177.  
  178.   /* USER CODE END RTC_Init 1 */
  179.   /** Initialize RTC Only
  180.   */
  181.   hrtc.Instance = RTC;
  182.   hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
  183.   hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
  184.   if (HAL_RTC_Init(&hrtc) != HAL_OK)
  185.   {
  186.     Error_Handler();
  187.   }
  188.  
  189.   /* USER CODE BEGIN Check_RTC_BKUP */
  190.    
  191.   /* USER CODE END Check_RTC_BKUP */
  192.  
  193.   /** Initialize RTC and set the Time and Date
  194.   */
  195.   sTime.Hours = 0x0;
  196.   sTime.Minutes = 0x0;
  197.   sTime.Seconds = 0x0;
  198.  
  199.   if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
  200.   {
  201.     Error_Handler();
  202.   }
  203.   DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
  204.   DateToUpdate.Month = RTC_MONTH_JANUARY;
  205.   DateToUpdate.Date = 0x1;
  206.   DateToUpdate.Year = 0x0;
  207.  
  208.   if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
  209.   {
  210.     Error_Handler();
  211.   }
  212.   /* USER CODE BEGIN RTC_Init 2 */
  213.  
  214.   /* USER CODE END RTC_Init 2 */
  215.  
  216. }
  217.  
  218. /**
  219.   * @brief TIM4 Initialization Function
  220.   * @param None
  221.   * @retval None
  222.   */
  223. static void MX_TIM4_Init(void)
  224. {
  225.  
  226.   /* USER CODE BEGIN TIM4_Init 0 */
  227.  
  228.   /* USER CODE END TIM4_Init 0 */
  229.  
  230.   TIM_SlaveConfigTypeDef sSlaveConfig = {0};
  231.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  232.  
  233.   /* USER CODE BEGIN TIM4_Init 1 */
  234.  
  235.   /* USER CODE END TIM4_Init 1 */
  236.   htim4.Instance = TIM4;
  237.   htim4.Init.Prescaler = 36000;
  238.   htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
  239.   htim4.Init.Period = 2000;
  240.   htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  241.   htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  242.   if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
  243.   {
  244.     Error_Handler();
  245.   }
  246.   sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
  247.   sSlaveConfig.InputTrigger = TIM_TS_ITR0;
  248.   if (HAL_TIM_SlaveConfigSynchro(&htim4, &sSlaveConfig) != HAL_OK)
  249.   {
  250.     Error_Handler();
  251.   }
  252.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  253.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  254.   if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
  255.   {
  256.     Error_Handler();
  257.   }
  258.   /* USER CODE BEGIN TIM4_Init 2 */
  259.  
  260.   /* USER CODE END TIM4_Init 2 */
  261.  
  262. }
  263.  
  264. /**
  265.   * @brief GPIO Initialization Function
  266.   * @param None
  267.   * @retval None
  268.   */
  269. static void MX_GPIO_Init(void)
  270. {
  271.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  272.  
  273.   /* GPIO Ports Clock Enable */
  274.   __HAL_RCC_GPIOC_CLK_ENABLE();
  275.   __HAL_RCC_GPIOD_CLK_ENABLE();
  276.   __HAL_RCC_GPIOA_CLK_ENABLE();
  277.  
  278.   /*Configure GPIO pin Output Level */
  279.   HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
  280.  
  281.   /*Configure GPIO pin : LED_Pin */
  282.   GPIO_InitStruct.Pin = LED_Pin;
  283.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  284.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  285.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  286.   HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
  287.  
  288. }
  289.  
  290. /* USER CODE BEGIN 4 */
  291.  
  292. /* USER CODE END 4 */
  293.  
  294. /**
  295.   * @brief  This function is executed in case of error occurrence.
  296.   * @retval None
  297.   */
  298. void Error_Handler(void)
  299. {
  300.   /* USER CODE BEGIN Error_Handler_Debug */
  301.   /* User can add his own implementation to report the HAL error return state */
  302.  
  303.   /* USER CODE END Error_Handler_Debug */
  304. }
  305.  
  306. #ifdef  USE_FULL_ASSERT
  307. /**
  308.   * @brief  Reports the name of the source file and the source line number
  309.   *         where the assert_param error has occurred.
  310.   * @param  file: pointer to the source file name
  311.   * @param  line: assert_param error line source number
  312.   * @retval None
  313.   */
  314. void assert_failed(uint8_t *file, uint32_t line)
  315. {
  316.   /* USER CODE BEGIN 6 */
  317.   /* User can add his own implementation to report the file name and line number,
  318.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  319.   /* USER CODE END 6 */
  320. }
  321. #endif /* USE_FULL_ASSERT */
  322.  
  323. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  324.  
  325. 16:59:59 **** Rebuild of configuration Debug for project cube 2 ****
  326. Info: Internal Builder is used for build
  327. arm-atollic-eabi-gcc -c -mthumb -mcpu=cortex-m3 -std=gnu11 -D__weak=__attribute__((weak)) -D__packed=__attribute__((__packed__)) -DUSE_HAL_DRIVER -DSTM32F103xB -I../Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -Os -ffunction-sections -fdata-sections -g -fstack-usage -Wall -specs=nano.specs -o Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.o ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c
  328. arm-atollic-eabi-gcc -c -mthumb -mcpu=cortex-m3 -std=gnu11 -D__weak=__attribute__((weak)) -D__packed=__attribute__((__packed__)) -DUSE_HAL_DRIVER -DSTM32F103xB -I../Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -Os -ffunction-sections -fdata-sections -g -fstack-usage -Wall -specs=nano.specs -o Src\main.o ..\Src\main.c
  329. ..\Src\main.c:65:20: error: expected declaration specifiers or '...' before '&' token
  330.  HAL_TIM_Base_Start(&htim4);
  331.                     ^
  332. ..\Src\main.c:66:23: error: expected declaration specifiers or '...' before '&' token
  333.  HAL_TIM_Base_Start_IT(&htim4);
  334.                        ^
Add Comment
Please, Sign In to add comment