Guest User

Untitled

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