Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.10 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   *
  7.   * COPYRIGHT(c) 2016 STMicroelectronics
  8.   *
  9.   * Redistribution and use in source and binary forms, with or without modification,
  10.   * are permitted provided that the following conditions are met:
  11.   *   1. Redistributions of source code must retain the above copyright notice,
  12.   *      this list of conditions and the following disclaimer.
  13.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  14.   *      this list of conditions and the following disclaimer in the documentation
  15.   *      and/or other materials provided with the distribution.
  16.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  17.   *      may be used to endorse or promote products derived from this software
  18.   *      without specific prior written permission.
  19.   *
  20.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.   *
  31.   ******************************************************************************
  32.   */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32f4xx_hal.h"
  35.  
  36. /* USER CODE BEGIN Includes */
  37.  
  38. /* USER CODE END Includes */
  39.  
  40. /* Private variables ---------------------------------------------------------*/
  41.  
  42. /* USER CODE BEGIN PV */
  43. /* Private variables ---------------------------------------------------------*/
  44.  
  45. /* USER CODE END PV */
  46.  
  47. /* Private function prototypes -----------------------------------------------*/
  48. void SystemClock_Config(void);
  49. void Error_Handler(void);
  50.  
  51. /* USER CODE BEGIN PFP */
  52. /* Private function prototypes -----------------------------------------------*/
  53.  
  54. /* USER CODE END PFP */
  55.  
  56. /* USER CODE BEGIN 0 */
  57.  
  58. /* USER CODE END 0 */
  59.  
  60. int main(void)
  61. {
  62.  
  63.   /* USER CODE BEGIN 1 */
  64.  
  65.   /* USER CODE END 1 */
  66.  
  67.   /* MCU Configuration----------------------------------------------------------*/
  68.  
  69.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  70.   HAL_Init();
  71.  
  72.   /* Configure the system clock */
  73.   SystemClock_Config();
  74.  
  75.   /* Initialize all configured peripherals */
  76.  
  77.   /* USER CODE BEGIN 2 */
  78.     __GPIOD_CLK_ENABLE();
  79.     GPIO_InitTypeDef GPIO_InitStructure;
  80.  
  81.     GPIO_InitStructure.Pin = GPIO_PIN_12;
  82.  
  83.     GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  84.     GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
  85.     GPIO_InitStructure.Pull = GPIO_NOPULL;
  86.     HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
  87.   /* USER CODE END 2 */
  88.  
  89.   /* Infinite loop */
  90.   /* USER CODE BEGIN WHILE */
  91.   while (1)
  92.   {
  93.   /* USER CODE END WHILE */
  94.  
  95.   /* USER CODE BEGIN 3 */
  96.       HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
  97.       HAL_Delay(500);
  98.       HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
  99.       HAL_Delay(500);
  100.   }
  101.   /* USER CODE END 3 */
  102.  
  103. }
  104.  
  105. /** System Clock Configuration
  106. */
  107. void SystemClock_Config(void)
  108. {
  109.  
  110.   RCC_OscInitTypeDef RCC_OscInitStruct;
  111.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  112.  
  113.   __HAL_RCC_PWR_CLK_ENABLE();
  114.  
  115.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  116.  
  117.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  118.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  119.   RCC_OscInitStruct.HSICalibrationValue = 16;
  120.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  121.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  122.   RCC_OscInitStruct.PLL.PLLM = 8;
  123.   RCC_OscInitStruct.PLL.PLLN = 120;
  124.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  125.   RCC_OscInitStruct.PLL.PLLQ = 4;
  126.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  127.   {
  128.     Error_Handler();
  129.   }
  130.  
  131.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  132.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  133.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  134.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  135.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  136.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  137.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  138.   {
  139.     Error_Handler();
  140.   }
  141.  
  142.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  143.  
  144.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  145.  
  146.   /* SysTick_IRQn interrupt configuration */
  147.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  148. }
  149.  
  150. /* USER CODE BEGIN 4 */
  151.  
  152. /* USER CODE END 4 */
  153.  
  154. /**
  155.   * @brief  This function is executed in case of error occurrence.
  156.   * @param  None
  157.   * @retval None
  158.   */
  159. void Error_Handler(void)
  160. {
  161.   /* USER CODE BEGIN Error_Handler */
  162.   /* User can add his own implementation to report the HAL error return state */
  163.   while(1)
  164.   {
  165.   }
  166.   /* USER CODE END Error_Handler */
  167. }
  168.  
  169. #ifdef USE_FULL_ASSERT
  170.  
  171. /**
  172.    * @brief Reports the name of the source file and the source line number
  173.    * where the assert_param error has occurred.
  174.    * @param file: pointer to the source file name
  175.    * @param line: assert_param error line source number
  176.    * @retval None
  177.    */
  178. void assert_failed(uint8_t* file, uint32_t line)
  179. {
  180.   /* USER CODE BEGIN 6 */
  181.   /* User can add his own implementation to report the file name and line number,
  182.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  183.   /* USER CODE END 6 */
  184.  
  185. }
  186.  
  187. #endif
  188.  
  189. /**
  190.   * @}
  191.   */
  192.  
  193. /**
  194.   * @}
  195. */
  196.  
  197. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement