main.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. *
  7. * COPYRIGHT(c) 2017 STMicroelectronics
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. * 1. Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "main.h"
  35. #include "stm32f0xx_hal.h"
  36. /* USER CODE BEGIN Includes */
  37. /* USER CODE END Includes */
  38. /* Private variables ---------------------------------------------------------*/
  39. /* USER CODE BEGIN PV */
  40. /* Private variables ---------------------------------------------------------*/
  41. uint32_t morg=0;
  42. /* USER CODE END PV */
  43. /* Private function prototypes -----------------------------------------------*/
  44. void SystemClock_Config(void);
  45. void Error_Handler(void);
  46. static void MX_GPIO_Init(void);
  47. /* USER CODE BEGIN PFP */
  48. /* Private function prototypes -----------------------------------------------*/
  49. /* USER CODE END PFP */
  50. /* USER CODE BEGIN 0 */
  51. /* USER CODE END 0 */
  52. int main(void)
  53. {
  54. /* USER CODE BEGIN 1 */
  55. /* USER CODE END 1 */
  56. /* MCU Configuration----------------------------------------------------------*/
  57. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  58. HAL_Init();
  59. /* Configure the system clock */
  60. SystemClock_Config();
  61. /* Initialize all configured peripherals */
  62. MX_GPIO_Init();
  63. /* USER CODE BEGIN 2 */
  64. /* USER CODE END 2 */
  65. /* Infinite loop */
  66. /* USER CODE BEGIN WHILE */
  67. while (1)
  68. {
  69. /* USER CODE END WHILE */
  70. /* USER CODE BEGIN 3 */
  71. GPIOA -> BSRR=0b100000;
  72. for (morg=0;morg<10000;morg++);
  73. GPIOA -> BRR=0b100000;
  74. for (morg=0;morg<10000;morg++);
  75. }
  76. /* USER CODE END 3 */
  77. }
  78. /** System Clock Configuration
  79. */
  80. void SystemClock_Config(void)
  81. {
  82. RCC_OscInitTypeDef RCC_OscInitStruct;
  83. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  84. /**Initializes the CPU, AHB and APB busses clocks
  85. */
  86. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  87. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  88. RCC_OscInitStruct.HSICalibrationValue = 16;
  89. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  90. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  91. {
  92. Error_Handler();
  93. }
  94. /**Initializes the CPU, AHB and APB busses clocks
  95. */
  96. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  97. |RCC_CLOCKTYPE_PCLK1;
  98. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  99. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  100. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  101. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  102. {
  103. Error_Handler();
  104. }
  105. /**Configure the Systick interrupt time
  106. */
  107. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  108. /**Configure the Systick
  109. */
  110. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  111. /* SysTick_IRQn interrupt configuration */
  112. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  113. }
  114. /** Configure pins as
  115. * Analog
  116. * Input
  117. * Output
  118. * EVENT_OUT
  119. * EXTI
  120. */
  121. static void MX_GPIO_Init(void)
  122. {
  123. GPIO_InitTypeDef GPIO_InitStruct;
  124. /* GPIO Ports Clock Enable */
  125. __HAL_RCC_GPIOA_CLK_ENABLE();
  126. /*Configure GPIO pin Output Level */
  127. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
  128. /*Configure GPIO pin : PA5 */
  129. GPIO_InitStruct.Pin = GPIO_PIN_5;
  130. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  131. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  132. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  133. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  134. }
  135. /* USER CODE BEGIN 4 */
  136. /* USER CODE END 4 */
  137. /**
  138. * @brief This function is executed in case of error occurrence.
  139. * @param None
  140. * @retval None
  141. */
  142. void Error_Handler(void)
  143. {
  144. /* USER CODE BEGIN Error_Handler */
  145. /* User can add his own implementation to report the HAL error return state */
  146. while(1)
  147. {
  148. }
  149. /* USER CODE END Error_Handler */
  150. }
  151. #ifdef USE_FULL_ASSERT
  152. /**
  153. * @brief Reports the name of the source file and the source line number
  154. * where the assert_param error has occurred.
  155. * @param file: pointer to the source file name
  156. * @param line: assert_param error line source number
  157. * @retval None
  158. */
  159. void assert_failed(uint8_t* file, uint32_t line)
  160. {
  161. /* USER CODE BEGIN 6 */
  162. /* User can add his own implementation to report the file name and line number,
  163. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  164. /* USER CODE END 6 */
  165. }
  166. #endif
  167. /**
  168. * @}
  169. */
  170. /**
  171. * @}
  172. */
  173. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/