main.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN PTD */
  27. /* USER CODE END PTD */
  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN PD */
  30. /* USER CODE END PD */
  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN PM */
  33. /* USER CODE END PM */
  34. /* Private variables ---------------------------------------------------------*/
  35. UART_HandleTypeDef huart2;
  36. /* USER CODE BEGIN PV */
  37. /* USER CODE END PV */
  38. /* Private function prototypes -----------------------------------------------*/
  39. void SystemClock_Config(void);
  40. static void MX_GPIO_Init(void);
  41. static void MX_USART2_UART_Init(void);
  42. static void MX_NVIC_Init(void);
  43. /* USER CODE BEGIN PFP */
  44. ADF4153_settings_t ADF4153_st =
  45. {
  46. 10000000, // RFIN is 25Mhz
  47. 500000, // Channel spacing is 150 Khz
  48. 10, // 12-bit fractional value
  49. 8, // 9-bit integer value
  50. ADF4153_FASTLOCK_DISABLED, // Fast-Lock
  51. 16, // 12-bit interpolator modulus value
  52. 1, // 4-bit R Counter
  53. ADF4153_PRESCALER_4_5, // Prescale
  54. ADF4153_MUXOUT_LOGICHIGH, // Muxout
  55. ADF4153_LOAD_NORMAL, // Load Control
  56. ADF4153_CR_DISABLED, // Counter Reset
  57. ADF4153_CP_DISABLED, // CP Three-state
  58. ADF4153_PD_DISABLED, // Power-down
  59. ADF4153_LDP_24, // LDP
  60. ADF4153_PD_POL_POSITIVE, // PD Polarity
  61. ADF4153_CP_CURRENT_0_63, // Current settings
  62. ADF4153_REF_DOUBLER_DIS, // Reference doubler
  63. 1, // Resync
  64. ADF4153_LOW_SPUR_MODE // Noise and Spur mode
  65. };
  66. /* USER CODE END PFP */
  67. /* Private user code ---------------------------------------------------------*/
  68. /* USER CODE BEGIN 0 */
  69. int _write (int file, uint8_t *ptr, uint16_t len)
  70. {
  71. HAL_UART_Transmit (&huart2, ptr, len, 10);
  72. return len;
  73. }
  74. PLL_Setting_st Pll_test = {
  75. PLL_CLK_GPIO_Port,
  76. PLL_CLK_Pin,
  77. PLL_DATA_GPIO_Port,
  78. PLL_DATA_Pin,
  79. PLL_EN_GPIO_Port,
  80. PLL_EN_Pin,
  81. };
  82. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  83. {
  84. if(GPIO_Pin == GPIO_PIN_12){
  85. ADF_Module_Ctrl(Pll_test,0x324000,0x144051,0x0017c2,0x0003c7);
  86. }
  87. }
  88. /* USER CODE END 0 */
  89. /**
  90. * @brief The application entry point.
  91. * @retval int
  92. */
  93. int main(void)
  94. {
  95. /* USER CODE BEGIN 1 */
  96. /* USER CODE END 1 */
  97. /* MCU Configuration--------------------------------------------------------*/
  98. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  99. HAL_Init();
  100. /* USER CODE BEGIN Init */
  101. /* USER CODE END Init */
  102. /* Configure the system clock */
  103. SystemClock_Config();
  104. /* USER CODE BEGIN SysInit */
  105. /* USER CODE END SysInit */
  106. /* Initialize all configured peripherals */
  107. MX_GPIO_Init();
  108. MX_USART2_UART_Init();
  109. /* Initialize interrupts */
  110. MX_NVIC_Init();
  111. /* USER CODE BEGIN 2 */
  112. setbuf(stdout, NULL);
  113. printf("UART Start \r\n");
  114. ADF4153_Init(ADF4153_st);
  115. ADF_Module_Ctrl(Pll_test,0x324000,0x144051,0x0017c2,0x0003c7);
  116. // ADF_Module_Ctrl(Pll_test,0x2EC000,0x104051,0x16C2,0x383);
  117. /* USER CODE END 2 */
  118. /* Infinite loop */
  119. /* USER CODE BEGIN WHILE */
  120. while (1)
  121. {
  122. #if 1 // PYJ.2019.07.22_BEGIN --
  123. /*
  124. printf("\r\nUART Start \r\n");
  125. HAL_Delay(100000);
  126. */
  127. // if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_12) == GPIO_PIN_SET){
  128. // }else{
  129. // ADF_Module_Ctrl(Pll_test,0x324000,0x144051,0x0017c2,0x0003c7);
  130. HAL_Delay(1);
  131. // }
  132. // HAL_Delay(??1);
  133. // HAL_GPIO_TogglePin(Pll_test.PLL_DATA_PORT, Pll_test.PLL_DATA_PIN);
  134. // HAL_GPIO_TogglePin(Pll_test.PLL_ENABLE_PORT, Pll_test.PLL_ENABLE_PIN);
  135. //printf("==================================\r\n");
  136. //ADF4153_SetFrequency(754000000);
  137. //printf("==================================\r\n");
  138. #else
  139. #endif // PYJ.2019.07.22_END --
  140. // printf("%d\r\n",MOD_Calc(10000,500));
  141. /* USER CODE END WHILE */
  142. /* USER CODE BEGIN 3 */
  143. }
  144. /* USER CODE END 3 */
  145. }
  146. /**
  147. * @brief System Clock Configuration
  148. * @retval None
  149. */
  150. void SystemClock_Config(void)
  151. {
  152. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  153. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  154. /** Configure the main internal regulator output voltage
  155. */
  156. __HAL_RCC_PWR_CLK_ENABLE();
  157. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  158. /** Initializes the CPU, AHB and APB busses clocks
  159. */
  160. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  161. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  162. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  163. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  164. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  165. RCC_OscInitStruct.PLL.PLLM = 16;
  166. RCC_OscInitStruct.PLL.PLLN = 336;
  167. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  168. RCC_OscInitStruct.PLL.PLLQ = 4;
  169. RCC_OscInitStruct.PLL.PLLR = 2;
  170. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  171. {
  172. Error_Handler();
  173. }
  174. /** Initializes the CPU, AHB and APB busses clocks
  175. */
  176. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  177. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  178. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  179. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  180. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  181. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  182. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  183. {
  184. Error_Handler();
  185. }
  186. }
  187. /**
  188. * @brief NVIC Configuration.
  189. * @retval None
  190. */
  191. static void MX_NVIC_Init(void)
  192. {
  193. /* EXTI15_10_IRQn interrupt configuration */
  194. HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
  195. HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  196. }
  197. /**
  198. * @brief USART2 Initialization Function
  199. * @param None
  200. * @retval None
  201. */
  202. static void MX_USART2_UART_Init(void)
  203. {
  204. /* USER CODE BEGIN USART2_Init 0 */
  205. /* USER CODE END USART2_Init 0 */
  206. /* USER CODE BEGIN USART2_Init 1 */
  207. /* USER CODE END USART2_Init 1 */
  208. huart2.Instance = USART2;
  209. huart2.Init.BaudRate = 115200;
  210. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  211. huart2.Init.StopBits = UART_STOPBITS_1;
  212. huart2.Init.Parity = UART_PARITY_NONE;
  213. huart2.Init.Mode = UART_MODE_TX_RX;
  214. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  215. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  216. if (HAL_UART_Init(&huart2) != HAL_OK)
  217. {
  218. Error_Handler();
  219. }
  220. /* USER CODE BEGIN USART2_Init 2 */
  221. /* USER CODE END USART2_Init 2 */
  222. }
  223. /**
  224. * @brief GPIO Initialization Function
  225. * @param None
  226. * @retval None
  227. */
  228. static void MX_GPIO_Init(void)
  229. {
  230. GPIO_InitTypeDef GPIO_InitStruct = {0};
  231. /* GPIO Ports Clock Enable */
  232. __HAL_RCC_GPIOC_CLK_ENABLE();
  233. __HAL_RCC_GPIOH_CLK_ENABLE();
  234. __HAL_RCC_GPIOA_CLK_ENABLE();
  235. __HAL_RCC_GPIOB_CLK_ENABLE();
  236. /*Configure GPIO pin Output Level */
  237. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3|PLL_EN_Pin|PLL_DATA_Pin|PLL_CLK_Pin, GPIO_PIN_RESET);
  238. /*Configure GPIO pin Output Level */
  239. HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
  240. /*Configure GPIO pin : B1_Pin */
  241. GPIO_InitStruct.Pin = B1_Pin;
  242. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  243. GPIO_InitStruct.Pull = GPIO_NOPULL;
  244. HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
  245. /*Configure GPIO pins : PC3 PLL_EN_Pin PLL_DATA_Pin PLL_CLK_Pin */
  246. GPIO_InitStruct.Pin = GPIO_PIN_3|PLL_EN_Pin|PLL_DATA_Pin|PLL_CLK_Pin;
  247. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  248. GPIO_InitStruct.Pull = GPIO_NOPULL;
  249. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  250. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  251. /*Configure GPIO pin : LD2_Pin */
  252. GPIO_InitStruct.Pin = LD2_Pin;
  253. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  254. GPIO_InitStruct.Pull = GPIO_NOPULL;
  255. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  256. HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
  257. /*Configure GPIO pin : PA12 */
  258. GPIO_InitStruct.Pin = GPIO_PIN_12;
  259. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  260. GPIO_InitStruct.Pull = GPIO_NOPULL;
  261. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  262. }
  263. /* USER CODE BEGIN 4 */
  264. /* USER CODE END 4 */
  265. /**
  266. * @brief This function is executed in case of error occurrence.
  267. * @retval None
  268. */
  269. void Error_Handler(void)
  270. {
  271. /* USER CODE BEGIN Error_Handler_Debug */
  272. /* User can add his own implementation to report the HAL error return state */
  273. /* USER CODE END Error_Handler_Debug */
  274. }
  275. #ifdef USE_FULL_ASSERT
  276. /**
  277. * @brief Reports the name of the source file and the source line number
  278. * where the assert_param error has occurred.
  279. * @param file: pointer to the source file name
  280. * @param line: assert_param error line source number
  281. * @retval None
  282. */
  283. void assert_failed(uint8_t *file, uint32_t line)
  284. {
  285. /* USER CODE BEGIN 6 */
  286. /* User can add his own implementation to report the file name and line number,
  287. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  288. /* USER CODE END 6 */
  289. }
  290. #endif /* USE_FULL_ASSERT */
  291. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/