Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2024
27
0
61 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.41 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.   * Copyright (c) 2024 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21.  
  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24.  
  25. /* USER CODE END Includes */
  26.  
  27. /* Private typedef -----------------------------------------------------------*/
  28. /* USER CODE BEGIN PTD */
  29.  
  30. /* USER CODE END PTD */
  31.  
  32. /* Private define ------------------------------------------------------------*/
  33. /* USER CODE BEGIN PD */
  34.  
  35. /* USER CODE END PD */
  36.  
  37. /* Private macro -------------------------------------------------------------*/
  38. /* USER CODE BEGIN PM */
  39.  
  40. /* USER CODE END PM */
  41.  
  42. /* Private variables ---------------------------------------------------------*/
  43.  
  44. /* USER CODE BEGIN PV */
  45.  
  46. /* USER CODE END PV */
  47.  
  48. /* Private function prototypes -----------------------------------------------*/
  49. void SystemClock_Config(void);
  50. static void MX_GPIO_Init(void);
  51. /* USER CODE BEGIN PFP */
  52.  
  53. /* USER CODE END PFP */
  54.  
  55. /* Private user code ---------------------------------------------------------*/
  56. /* USER CODE BEGIN 0 */
  57.  
  58. /* USER CODE END 0 */
  59.  
  60. /**
  61.   * @brief  The application entry point.
  62.   * @retval int
  63.   */
  64. int main(void)
  65. {
  66.  
  67.   /* USER CODE BEGIN 1 */
  68.  
  69.   /* USER CODE END 1 */
  70.  
  71.   /* MCU Configuration--------------------------------------------------------*/
  72.  
  73.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  74.   HAL_Init();
  75.  
  76.   /* USER CODE BEGIN Init */
  77.  
  78.   /* USER CODE END Init */
  79.  
  80.   /* Configure the system clock */
  81.   SystemClock_Config();
  82.  
  83.   /* USER CODE BEGIN SysInit */
  84.  
  85.   /* USER CODE END SysInit */
  86.  
  87.   /* Initialize all configured peripherals */
  88.   MX_GPIO_Init();
  89.   /* USER CODE BEGIN 2 */
  90.  
  91.   /* USER CODE END 2 */
  92.  
  93.   /* Infinite loop */
  94.   /* USER CODE BEGIN WHILE */
  95.   while (1)
  96.   {
  97.       HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_4);
  98.       HAL_Delay(1000);
  99.       /* USER CODE END WHILE */
  100.     /* USER CODE BEGIN 3 */
  101.   }
  102.   /* USER CODE END 3 */
  103. }
  104.  
  105. /**
  106.   * @brief System Clock Configuration
  107.   * @retval None
  108.   */
  109. void SystemClock_Config(void)
  110. {
  111.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  112.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  113.  
  114.   /** Initializes the RCC Oscillators according to the specified parameters
  115.   * in the RCC_OscInitTypeDef structure.
  116.   */
  117.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  118.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  119.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  120.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  121.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  122.   {
  123.     Error_Handler();
  124.   }
  125.  
  126.   /** Initializes the CPU, AHB and APB buses clocks
  127.   */
  128.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  129.                               |RCC_CLOCKTYPE_PCLK1;
  130.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  131.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  132.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  133.  
  134.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  135.   {
  136.     Error_Handler();
  137.   }
  138. }
  139.  
  140. /**
  141.   * @brief GPIO Initialization Function
  142.   * @param None
  143.   * @retval None
  144.   */
  145. static void MX_GPIO_Init(void)
  146. {
  147.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  148. /* USER CODE BEGIN MX_GPIO_Init_1 */
  149. /* USER CODE END MX_GPIO_Init_1 */
  150.  
  151.   /* GPIO Ports Clock Enable */
  152.   __HAL_RCC_GPIOA_CLK_ENABLE();
  153.  
  154.   /*Configure GPIO pin Output Level */
  155.   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
  156.  
  157.   /*Configure GPIO pin : PA4 */
  158.   GPIO_InitStruct.Pin = GPIO_PIN_4;
  159.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  160.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  161.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  162.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  163.  
  164. /* USER CODE BEGIN MX_GPIO_Init_2 */
  165. /* USER CODE END MX_GPIO_Init_2 */
  166. }
  167.  
  168. /* USER CODE BEGIN 4 */
  169.  
  170. /* USER CODE END 4 */
  171.  
  172. /**
  173.   * @brief  This function is executed in case of error occurrence.
  174.   * @retval None
  175.   */
  176. void Error_Handler(void)
  177. {
  178.   /* USER CODE BEGIN Error_Handler_Debug */
  179.   /* User can add his own implementation to report the HAL error return state */
  180.   __disable_irq();
  181.   while (1)
  182.   {
  183.   }
  184.   /* USER CODE END Error_Handler_Debug */
  185. }
  186.  
  187. #ifdef  USE_FULL_ASSERT
  188. /**
  189.   * @brief  Reports the name of the source file and the source line number
  190.   *         where the assert_param error has occurred.
  191.   * @param  file: pointer to the source file name
  192.   * @param  line: assert_param error line source number
  193.   * @retval None
  194.   */
  195. void assert_failed(uint8_t *file, uint32_t line)
  196. {
  197.   /* USER CODE BEGIN 6 */
  198.   /* User can add his own implementation to report the file name and line number,
  199.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  200.   /* USER CODE END 6 */
  201. }
  202. #endif /* USE_FULL_ASSERT */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement