Guest User

Untitled

a guest
Jan 19th, 2022
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.23 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) 2022 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. //#include<stdio.h>
  25. //#include<string.h>
  26. #include<math.h>
  27. /* USER CODE END Includes */
  28.  
  29. /* Private typedef -----------------------------------------------------------*/
  30. /* USER CODE BEGIN PTD */
  31.  
  32. /* USER CODE END PTD */
  33.  
  34. /* Private define ------------------------------------------------------------*/
  35. /* USER CODE BEGIN PD */
  36. /* USER CODE END PD */
  37.  
  38. /* Private macro -------------------------------------------------------------*/
  39. /* USER CODE BEGIN PM */
  40.  
  41. /* USER CODE END PM */
  42.  
  43. /* Private variables ---------------------------------------------------------*/
  44. UART_HandleTypeDef huart2;
  45.  
  46. /* USER CODE BEGIN PV */
  47.  
  48. /* USER CODE END PV */
  49.  
  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);
  52. static void MX_GPIO_Init(void);
  53. static void MX_USART2_UART_Init(void);
  54. /* USER CODE BEGIN PFP */
  55.  
  56. /* USER CODE END PFP */
  57.  
  58. /* Private user code ---------------------------------------------------------*/
  59. /* USER CODE BEGIN 0 */
  60.  
  61. /* USER CODE END 0 */
  62.  
  63. /**
  64.   * @brief  The application entry point.
  65.   * @retval int
  66.   */
  67. int main(void)
  68. {
  69.   /* USER CODE BEGIN 1 */
  70.  
  71.   /* USER CODE END 1 */
  72.  
  73.   /* MCU Configuration--------------------------------------------------------*/
  74.  
  75.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  76.   HAL_Init();
  77.  
  78.   /* USER CODE BEGIN Init */
  79.  
  80.   /* USER CODE END Init */
  81.  
  82.   /* Configure the system clock */
  83.   SystemClock_Config();
  84.  
  85.   /* USER CODE BEGIN SysInit */
  86.  
  87.   /* USER CODE END SysInit */
  88.  
  89.   /* Initialize all configured peripherals */
  90.   MX_GPIO_Init();
  91.   MX_USART2_UART_Init();
  92.   /* USER CODE BEGIN 2 */
  93. int count = 0;
  94. float cleanSignal = 0.0;
  95. void process(){
  96.     cleanSignal = 3.0 * sin (count * 3.14159f / 180);
  97. }
  98.   /* USER CODE END 2 */
  99.  
  100.   /* Infinite loop */
  101.   /* USER CODE BEGIN WHILE */
  102.   while (1)
  103.   {
  104.     /* USER CODE END WHILE */
  105.  
  106.     /* USER CODE BEGIN 3 */
  107.       HAL_UART_Transmit(&huart2, (uint8_t *) &cleanSignal, sizeof(cleanSignal), HAL_MAX_DELAY);
  108.       count++;
  109.  
  110.       process();
  111.   }
  112.   /* USER CODE END 3 */
  113. }
  114.  
  115. /**
  116.   * @brief System Clock Configuration
  117.   * @retval None
  118.   */
  119. void SystemClock_Config(void)
  120. {
  121.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  122.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  123.  
  124.   /** Initializes the RCC Oscillators according to the specified parameters
  125.   * in the RCC_OscInitTypeDef structure.
  126.   */
  127.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  128.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  129.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  130.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  131.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  132.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  133.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  134.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  135.   {
  136.     Error_Handler();
  137.   }
  138.   /** Initializes the CPU, AHB and APB buses clocks
  139.   */
  140.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  141.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  142.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  143.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  144.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  145.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  146.  
  147.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  148.   {
  149.     Error_Handler();
  150.   }
  151. }
  152.  
  153. /**
  154.   * @brief USART2 Initialization Function
  155.   * @param None
  156.   * @retval None
  157.   */
  158. static void MX_USART2_UART_Init(void)
  159. {
  160.  
  161.   /* USER CODE BEGIN USART2_Init 0 */
  162.  
  163.   /* USER CODE END USART2_Init 0 */
  164.  
  165.   /* USER CODE BEGIN USART2_Init 1 */
  166.  
  167.   /* USER CODE END USART2_Init 1 */
  168.   huart2.Instance = USART2;
  169.   huart2.Init.BaudRate = 9600;
  170.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  171.   huart2.Init.StopBits = UART_STOPBITS_1;
  172.   huart2.Init.Parity = UART_PARITY_NONE;
  173.   huart2.Init.Mode = UART_MODE_TX_RX;
  174.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  175.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  176.   if (HAL_UART_Init(&huart2) != HAL_OK)
  177.   {
  178.     Error_Handler();
  179.   }
  180.   /* USER CODE BEGIN USART2_Init 2 */
  181.  
  182.   /* USER CODE END USART2_Init 2 */
  183.  
  184. }
  185.  
  186. /**
  187.   * @brief GPIO Initialization Function
  188.   * @param None
  189.   * @retval None
  190.   */
  191. static void MX_GPIO_Init(void)
  192. {
  193.  
  194.   /* GPIO Ports Clock Enable */
  195.   __HAL_RCC_GPIOD_CLK_ENABLE();
  196.   __HAL_RCC_GPIOA_CLK_ENABLE();
  197.   __HAL_RCC_GPIOB_CLK_ENABLE();
  198.  
  199. }
  200.  
  201. /* USER CODE BEGIN 4 */
  202.  
  203. /* USER CODE END 4 */
  204.  
  205. /**
  206.   * @brief  This function is executed in case of error occurrence.
  207.   * @retval None
  208.   */
  209. void Error_Handler(void)
  210. {
  211.   /* USER CODE BEGIN Error_Handler_Debug */
  212.   /* User can add his own implementation to report the HAL error return state */
  213.   __disable_irq();
  214.   while (1)
  215.   {
  216.   }
  217.   /* USER CODE END Error_Handler_Debug */
  218. }
  219.  
  220. #ifdef  USE_FULL_ASSERT
  221. /**
  222.   * @brief  Reports the name of the source file and the source line number
  223.   *         where the assert_param error has occurred.
  224.   * @param  file: pointer to the source file name
  225.   * @param  line: assert_param error line source number
  226.   * @retval None
  227.   */
  228. void assert_failed(uint8_t *file, uint32_t line)
  229. {
  230.   /* USER CODE BEGIN 6 */
  231.   /* User can add his own implementation to report the file name and line number,
  232.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  233.   /* USER CODE END 6 */
  234. }
  235. #endif /* USE_FULL_ASSERT */
  236.  
  237.  
Advertisement
Add Comment
Please, Sign In to add comment