Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.14 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   ** This notice applies to any and all portions of this file
  7.   * that are not between comment pairs USER CODE BEGIN and
  8.   * USER CODE END. Other portions of this file, whether
  9.   * inserted by the user or by software development tools
  10.   * are owned by their respective copyright owners.
  11.   *
  12.   * COPYRIGHT(c) 2017 STMicroelectronics
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. #include "stm32f1xx_hal.h"
  41.  
  42. /* USER CODE BEGIN Includes */
  43.  
  44. /* USER CODE END Includes */
  45.  
  46. /* Private variables ---------------------------------------------------------*/
  47.  
  48. /* USER CODE BEGIN PV */
  49. /* Private variables ---------------------------------------------------------*/
  50.  
  51. /* USER CODE END PV */
  52.  
  53. /* Private function prototypes -----------------------------------------------*/
  54. void SystemClock_Config(void);
  55. static void MX_GPIO_Init(void);
  56.  
  57. /* USER CODE BEGIN PFP */
  58. /* Private function prototypes -----------------------------------------------*/
  59.  
  60. /* USER CODE END PFP */
  61.  
  62. /* USER CODE BEGIN 0 */
  63.  
  64. /* USER CODE END 0 */
  65.  
  66. int main(void)
  67. {
  68.  
  69.   /* USER CODE BEGIN 1 */
  70.  
  71.   /* USER CODE END 1 */
  72.  
  73.   /* MCU Configuration----------------------------------------------------------*/
  74.  
  75.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  76.   HAL_Init();
  77.  
  78.   /* USER CODE BEGIN Init */
  79.  
  80.   /* USER CODE END Init */
  81.  
  82.   /* Configure the system clock */
  83.   SystemClock_Config();
  84.  
  85.   /* USER CODE BEGIN SysInit */
  86.  
  87.   /* USER CODE END SysInit */
  88.  
  89.   /* Initialize all configured peripherals */
  90.   MX_GPIO_Init();
  91.  
  92.   /* USER CODE BEGIN 2 */
  93.   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
  94.   HAL_Delay(200);
  95.   /* USER CODE END 2 */
  96.  
  97.   /* Infinite loop */
  98.   /* USER CODE BEGIN WHILE */
  99.   while (1)
  100.   {
  101.   /* USER CODE END WHILE */
  102.  
  103.   /* USER CODE BEGIN 3 */
  104.  
  105.       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
  106.       HAL_Delay(400);
  107.       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
  108.       HAL_Delay(200);
  109.   }
  110.   /* USER CODE END 3 */
  111.  
  112. }
  113.  
  114. /** System Clock Configuration
  115. */
  116. void SystemClock_Config(void)
  117. {
  118.  
  119.   RCC_OscInitTypeDef RCC_OscInitStruct;
  120.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  121.  
  122.     /**Initializes the CPU, AHB and APB busses clocks
  123.     */
  124.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  125.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  126.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  127.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  128.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  129.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  130.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  131.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  132.   {
  133.     _Error_Handler(__FILE__, __LINE__);
  134.   }
  135.  
  136.     /**Initializes the CPU, AHB and APB busses clocks
  137.     */
  138.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  139.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  140.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  141.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  142.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  143.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  144.  
  145.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  146.   {
  147.     _Error_Handler(__FILE__, __LINE__);
  148.   }
  149.  
  150.     /**Configure the Systick interrupt time
  151.     */
  152.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  153.  
  154.     /**Configure the Systick
  155.     */
  156.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  157.  
  158.   /* SysTick_IRQn interrupt configuration */
  159.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  160. }
  161.  
  162. /** Configure pins as
  163.         * Analog
  164.         * Input
  165.         * Output
  166.         * EVENT_OUT
  167.         * EXTI
  168. */
  169. static void MX_GPIO_Init(void)
  170. {
  171.  
  172.   GPIO_InitTypeDef GPIO_InitStruct;
  173.  
  174.   /* GPIO Ports Clock Enable */
  175.   __HAL_RCC_GPIOC_CLK_ENABLE();
  176.   __HAL_RCC_GPIOD_CLK_ENABLE();
  177.   __HAL_RCC_GPIOA_CLK_ENABLE();
  178.   __HAL_RCC_GPIOB_CLK_ENABLE();
  179.  
  180.   /*Configure GPIO pin Output Level */
  181.   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
  182.  
  183.   /*Configure GPIO pin : PB5 */
  184.   GPIO_InitStruct.Pin = GPIO_PIN_5;
  185.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  186.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  187.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  188.  
  189. }
  190.  
  191. /* USER CODE BEGIN 4 */
  192.  
  193. /* USER CODE END 4 */
  194.  
  195. /**
  196.   * @brief  This function is executed in case of error occurrence.
  197.   * @param  None
  198.   * @retval None
  199.   */
  200. void _Error_Handler(char * file, int line)
  201. {
  202.   /* USER CODE BEGIN Error_Handler_Debug */
  203.   /* User can add his own implementation to report the HAL error return state */
  204.   while(1)
  205.   {
  206.   }
  207.   /* USER CODE END Error_Handler_Debug */
  208. }
  209.  
  210. #ifdef USE_FULL_ASSERT
  211.  
  212. /**
  213.    * @brief Reports the name of the source file and the source line number
  214.    * where the assert_param error has occurred.
  215.    * @param file: pointer to the source file name
  216.    * @param line: assert_param error line source number
  217.    * @retval None
  218.    */
  219. void assert_failed(uint8_t* file, uint32_t line)
  220. {
  221.   /* USER CODE BEGIN 6 */
  222.   /* User can add his own implementation to report the file name and line number,
  223.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  224.   /* USER CODE END 6 */
  225.  
  226. }
  227.  
  228. #endif
  229.  
  230. /**
  231.   * @}
  232.   */
  233.  
  234. /**
  235.   * @}
  236. */
  237.  
  238. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement