C 7
My code 2 By Hightechrobo on 17th October 2024 04:00:14 PM
  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. /* USER CODE END PD */
  35.  
  36. /* Private macro -------------------------------------------------------------*/
  37. /* USER CODE BEGIN PM */
  38.  
  39. /* USER CODE END PM */
  40.  
  41. /* Private variables ---------------------------------------------------------*/
  42.  
  43. /* USER CODE BEGIN PV */
  44.  
  45. /* USER CODE END PV */
  46.  
  47. /* Private function prototypes -----------------------------------------------*/
  48. void SystemClock_Config(void);
  49. static void MX_GPIO_Init(void);
  50. /* USER CODE BEGIN PFP */
  51.  
  52. /* USER CODE END PFP */
  53.  
  54. /* Private user code ---------------------------------------------------------*/
  55. /* USER CODE BEGIN 0 */
  56.  
  57. /* USER CODE END 0 */
  58.  
  59. /**
  60.   * @brief  The application entry point.
  61.   * @retval int
  62.   */
  63. int main(void)
  64. {
  65.   /* USER CODE BEGIN 1 */
  66.  
  67.   /* USER CODE END 1 */
  68.  
  69.   /* MCU Configuration--------------------------------------------------------*/
  70.  
  71.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  72.   HAL_Init();
  73.  
  74.   /* USER CODE BEGIN Init */
  75.  
  76.   /* USER CODE END Init */
  77.  
  78.   /* Configure the system clock */
  79.   SystemClock_Config();
  80.  
  81.   /* USER CODE BEGIN SysInit */
  82.  
  83.   /* USER CODE END SysInit */
  84.  
  85.   /* Initialize all configured peripherals */
  86.   MX_GPIO_Init();
  87.   /* USER CODE BEGIN 2 */
  88.  
  89.   /* USER CODE END 2 */
  90.  
  91.   /* Infinite loop */
  92.   /* USER CODE BEGIN WHILE */
  93.   while (1)
  94.   {
  95.     /* USER CODE END WHILE */
  96.     HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
  97.     HAL_Delay(500);
  98.     HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
  99.     HAL_Delay(500);
  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.   /** Initializes the CPU, AHB and APB buses clocks
  126.   */
  127.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  128.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  129.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  130.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  131.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  132.   RCC_ClkInitStruct.APB2CLKDivider = 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.  
  149.   /* GPIO Ports Clock Enable */
  150.   __HAL_RCC_GPIOA_CLK_ENABLE();
  151.   __HAL_RCC_GPIOB_CLK_ENABLE();
  152.  
  153.   /*Configure GPIO pin Output Level */
  154.   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
  155.  
  156.   /*Configure GPIO pin : PB9 */
  157.   GPIO_InitStruct.Pin = GPIO_PIN_9;
  158.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  159.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  160.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  161.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  162.  
  163. }
  164.  
  165. /* USER CODE BEGIN 4 */
  166.  
  167. /* USER CODE END 4 */
  168.  
  169. /**
  170.   * @brief  This function is executed in case of error occurrence.
  171.   * @retval None
  172.   */
  173. void Error_Handler(void)
  174. {
  175.   /* USER CODE BEGIN Error_Handler_Debug */
  176.   /* User can add his own implementation to report the HAL error return state */
  177.   __disable_irq();
  178.   while (1)
  179.   {
  180.   }
  181.   /* USER CODE END Error_Handler_Debug */
  182. }
  183.  
  184. #ifdef  USE_FULL_ASSERT
  185. /**
  186.   * @brief  Reports the name of the source file and the source line number
  187.   *         where the assert_param error has occurred.
  188.   * @param  file: pointer to the source file name
  189.   * @param  line: assert_param error line source number
  190.   * @retval None
  191.   */
  192. void assert_failed(uint8_t *file, uint32_t line)
  193. {
  194.   /* USER CODE BEGIN 6 */
  195.   /* User can add his own implementation to report the file name and line number,
  196.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  197.   /* USER CODE END 6 */
  198. }
  199. #endif /* USE_FULL_ASSERT */

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.