TEXT 94
Blink_led Guest on 17th October 2024 03:41:42 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.  
  97.     /* USER CODE BEGIN 3 */
  98.     if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_7) == 0){
  99.       HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1);
  100.       HAL_Delay(30);
  101.     }
  102.     else
  103.       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
  104.   }
  105.   /* USER CODE END 3 */
  106. }
  107.  
  108. /**
  109.   * @brief System Clock Configuration
  110.   * @retval None
  111.   */
  112. void SystemClock_Config(void)
  113. {
  114.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  115.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  116.  
  117.   /** Initializes the RCC Oscillators according to the specified parameters
  118.   * in the RCC_OscInitTypeDef structure.
  119.   */
  120.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  121.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  122.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  123.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  124.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  125.   {
  126.     Error_Handler();
  127.   }
  128.   /** Initializes the CPU, AHB and APB buses clocks
  129.   */
  130.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  131.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  132.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  133.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  134.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  135.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  136.  
  137.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  138.   {
  139.     Error_Handler();
  140.   }
  141. }
  142.  
  143. /**
  144.   * @brief GPIO Initialization Function
  145.   * @param None
  146.   * @retval None
  147.   */
  148. static void MX_GPIO_Init(void)
  149. {
  150.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  151.  
  152.   /* GPIO Ports Clock Enable */
  153.   __HAL_RCC_GPIOB_CLK_ENABLE();
  154.   __HAL_RCC_GPIOA_CLK_ENABLE();
  155.  
  156.   /*Configure GPIO pin Output Level */
  157.   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
  158.  
  159.   /*Configure GPIO pin : PB1 */
  160.   GPIO_InitStruct.Pin = GPIO_PIN_1;
  161.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  162.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  163.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  164.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  165.  
  166.   /*Configure GPIO pin : PB7 */
  167.   GPIO_InitStruct.Pin = GPIO_PIN_7;
  168.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  169.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  170.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  171.  
  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. {
  184.   /* USER CODE BEGIN Error_Handler_Debug */
  185.   /* User can add his own implementation to report the HAL error return state */
  186.   __disable_irq();
  187.   while (1)
  188.   {
  189.   }
  190.   /* USER CODE END Error_Handler_Debug */
  191. }
  192.  
  193. #ifdef  USE_FULL_ASSERT
  194. /**
  195.   * @brief  Reports the name of the source file and the source line number
  196.   *         where the assert_param error has occurred.
  197.   * @param  file: pointer to the source file name
  198.   * @param  line: assert_param error line source number
  199.   * @retval None
  200.   */
  201. void assert_failed(uint8_t *file, uint32_t line)
  202. {
  203.   /* USER CODE BEGIN 6 */
  204.   /* User can add his own implementation to report the file name and line number,
  205.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  206.   /* USER CODE END 6 */
  207. }
  208. #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.