STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_rcc.c
Go to the documentation of this file.
1 
86 /* Includes ------------------------------------------------------------------*/
87 #include "stm32f7xx_hal.h"
88 
98 #ifdef HAL_RCC_MODULE_ENABLED
99 
100 /* Private typedef -----------------------------------------------------------*/
101 /* Private define ------------------------------------------------------------*/
102 /* Private macro -------------------------------------------------------------*/
107 #define MCO1_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
108 #define MCO1_GPIO_PORT GPIOA
109 #define MCO1_PIN GPIO_PIN_8
110 
111 #define MCO2_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
112 #define MCO2_GPIO_PORT GPIOC
113 #define MCO2_PIN GPIO_PIN_9
114 
118 /* Private variables ---------------------------------------------------------*/
127 /* Private function prototypes -----------------------------------------------*/
128 /* Exported functions ---------------------------------------------------------*/
129 
216 void HAL_RCC_DeInit(void)
217 {
218  /* Set HSION bit */
220 
221  /* Reset CFGR register */
222  CLEAR_REG(RCC->CFGR);
223 
224  /* Reset HSEON, CSSON, PLLON, PLLI2S */
226 
227  /* Reset PLLCFGR register */
228  CLEAR_REG(RCC->PLLCFGR);
229  SET_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM_4 | RCC_PLLCFGR_PLLN_6 | RCC_PLLCFGR_PLLN_7 | RCC_PLLCFGR_PLLQ_2 | ((uint32_t)0x20000000U));
230 
231  /* Reset PLLI2SCFGR register */
232  CLEAR_REG(RCC->PLLI2SCFGR);
234 
235  /* Reset HSEBYP bit */
237 
238  /* Disable all interrupts */
239  CLEAR_REG(RCC->CIR);
240 
241  /* Update the SystemCoreClock global variable */
243 }
244 
259 __weak HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
260 {
261  uint32_t tickstart = 0;
262 
263  /* Check the parameters */
265 
266  /*------------------------------- HSE Configuration ------------------------*/
267  if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
268  {
269  /* Check the parameters */
270  assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));
271  /* When the HSE is used as system clock or clock source for PLL, It can not be disabled */
274  {
275  if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
276  {
277  return HAL_ERROR;
278  }
279  }
280  else
281  {
282  /* Set the new HSE configuration ---------------------------------------*/
283  __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);
284 
285  /* Check the HSE State */
286  if(RCC_OscInitStruct->HSEState != RCC_HSE_OFF)
287  {
288  /* Get Start Tick*/
289  tickstart = HAL_GetTick();
290 
291  /* Wait till HSE is ready */
293  {
294  if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
295  {
296  return HAL_TIMEOUT;
297  }
298  }
299  }
300  else
301  {
302  /* Get Start Tick*/
303  tickstart = HAL_GetTick();
304 
305  /* Wait till HSE is bypassed or disabled */
307  {
308  if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
309  {
310  return HAL_TIMEOUT;
311  }
312  }
313  }
314  }
315  }
316  /*----------------------------- HSI Configuration --------------------------*/
317  if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
318  {
319  /* Check the parameters */
320  assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
322 
323  /* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
326  {
327  /* When HSI is used as system clock it will not disabled */
328  if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
329  {
330  return HAL_ERROR;
331  }
332  /* Otherwise, just the calibration is allowed */
333  else
334  {
335  /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
337  }
338  }
339  else
340  {
341  /* Check the HSI State */
342  if((RCC_OscInitStruct->HSIState)!= RCC_HSI_OFF)
343  {
344  /* Enable the Internal High Speed oscillator (HSI). */
346 
347  /* Get Start Tick*/
348  tickstart = HAL_GetTick();
349 
350  /* Wait till HSI is ready */
352  {
353  if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
354  {
355  return HAL_TIMEOUT;
356  }
357  }
358 
359  /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
361  }
362  else
363  {
364  /* Disable the Internal High Speed oscillator (HSI). */
366 
367  /* Get Start Tick*/
368  tickstart = HAL_GetTick();
369 
370  /* Wait till HSI is ready */
372  {
373  if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
374  {
375  return HAL_TIMEOUT;
376  }
377  }
378  }
379  }
380  }
381  /*------------------------------ LSI Configuration -------------------------*/
382  if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
383  {
384  /* Check the parameters */
385  assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState));
386 
387  /* Check the LSI State */
388  if((RCC_OscInitStruct->LSIState)!= RCC_LSI_OFF)
389  {
390  /* Enable the Internal Low Speed oscillator (LSI). */
392 
393  /* Get Start Tick*/
394  tickstart = HAL_GetTick();
395 
396  /* Wait till LSI is ready */
398  {
399  if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
400  {
401  return HAL_TIMEOUT;
402  }
403  }
404  }
405  else
406  {
407  /* Disable the Internal Low Speed oscillator (LSI). */
409 
410  /* Get Start Tick*/
411  tickstart = HAL_GetTick();
412 
413  /* Wait till LSI is ready */
415  {
416  if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
417  {
418  return HAL_TIMEOUT;
419  }
420  }
421  }
422  }
423  /*------------------------------ LSE Configuration -------------------------*/
424  if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE)
425  {
426  /* Check the parameters */
427  assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState));
428 
429  /* Enable Power Clock*/
431 
432  /* Enable write access to Backup domain */
433  PWR->CR1 |= PWR_CR1_DBP;
434 
435  /* Wait for Backup domain Write protection disable */
436  tickstart = HAL_GetTick();
437 
438  while((PWR->CR1 & PWR_CR1_DBP) == RESET)
439  {
440  if((HAL_GetTick() - tickstart ) > RCC_DBP_TIMEOUT_VALUE)
441  {
442  return HAL_TIMEOUT;
443  }
444  }
445 
446  /* Set the new LSE configuration -----------------------------------------*/
447  __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
448  /* Check the LSE State */
449  if((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF)
450  {
451  /* Get Start Tick*/
452  tickstart = HAL_GetTick();
453 
454  /* Wait till LSE is ready */
456  {
457  if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
458  {
459  return HAL_TIMEOUT;
460  }
461  }
462  }
463  else
464  {
465  /* Get Start Tick*/
466  tickstart = HAL_GetTick();
467 
468  /* Wait till LSE is ready */
470  {
471  if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
472  {
473  return HAL_TIMEOUT;
474  }
475  }
476  }
477  }
478  /*-------------------------------- PLL Configuration -----------------------*/
479  /* Check the parameters */
480  assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
481  if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
482  {
483  /* Check if the PLL is used as system clock or not */
485  {
486  if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
487  {
488  /* Check the parameters */
489  assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
490  assert_param(IS_RCC_PLLM_VALUE(RCC_OscInitStruct->PLL.PLLM));
491  assert_param(IS_RCC_PLLN_VALUE(RCC_OscInitStruct->PLL.PLLN));
492  assert_param(IS_RCC_PLLP_VALUE(RCC_OscInitStruct->PLL.PLLP));
493  assert_param(IS_RCC_PLLQ_VALUE(RCC_OscInitStruct->PLL.PLLQ));
494 
495  /* Disable the main PLL. */
497 
498  /* Get Start Tick*/
499  tickstart = HAL_GetTick();
500 
501  /* Wait till PLL is ready */
503  {
504  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
505  {
506  return HAL_TIMEOUT;
507  }
508  }
509 
510  /* Configure the main PLL clock source, multiplication and division factors. */
511  WRITE_REG(RCC->PLLCFGR, (RCC_OscInitStruct->PLL.PLLSource | \
512  RCC_OscInitStruct->PLL.PLLM | \
513  (RCC_OscInitStruct->PLL.PLLN << POSITION_VAL(RCC_PLLCFGR_PLLN)) | \
514  (((RCC_OscInitStruct->PLL.PLLP >> 1) -1) << POSITION_VAL(RCC_PLLCFGR_PLLP)) | \
515  (RCC_OscInitStruct->PLL.PLLQ << POSITION_VAL(RCC_PLLCFGR_PLLQ))));
516  /* Enable the main PLL. */
518 
519  /* Get Start Tick*/
520  tickstart = HAL_GetTick();
521 
522  /* Wait till PLL is ready */
524  {
525  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
526  {
527  return HAL_TIMEOUT;
528  }
529  }
530  }
531  else
532  {
533  /* Disable the main PLL. */
535 
536  /* Get Start Tick*/
537  tickstart = HAL_GetTick();
538 
539  /* Wait till PLL is ready */
541  {
542  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
543  {
544  return HAL_TIMEOUT;
545  }
546  }
547  }
548  }
549  else
550  {
551  return HAL_ERROR;
552  }
553  }
554  return HAL_OK;
555 }
556 
583 HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
584 {
585  uint32_t tickstart = 0;
586 
587  /* Check the parameters */
588  assert_param(IS_RCC_CLOCKTYPE(RCC_ClkInitStruct->ClockType));
589  assert_param(IS_FLASH_LATENCY(FLatency));
590 
591  /* To correctly read data from FLASH memory, the number of wait states (LATENCY)
592  must be correctly programmed according to the frequency of the CPU clock
593  (HCLK) and the supply voltage of the device. */
594 
595  /* Increasing the CPU frequency */
596  if(FLatency > (FLASH->ACR & FLASH_ACR_LATENCY))
597  {
598  /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
599  __HAL_FLASH_SET_LATENCY(FLatency);
600 
601  /* Check that the new number of wait states is taken into account to access the Flash
602  memory by reading the FLASH_ACR register */
603  if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
604  {
605  return HAL_ERROR;
606  }
607  }
608 
609  /*-------------------------- HCLK Configuration --------------------------*/
610  if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
611  {
612  assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
613  MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
614  }
615 
616  /*------------------------- SYSCLK Configuration ---------------------------*/
617  if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
618  {
619  assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
620 
621  /* HSE is selected as System Clock Source */
622  if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
623  {
624  /* Check the HSE ready flag */
626  {
627  return HAL_ERROR;
628  }
629  }
630  /* PLL is selected as System Clock Source */
631  else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
632  {
633  /* Check the PLL ready flag */
635  {
636  return HAL_ERROR;
637  }
638  }
639  /* HSI is selected as System Clock Source */
640  else
641  {
642  /* Check the HSI ready flag */
644  {
645  return HAL_ERROR;
646  }
647  }
648 
649  __HAL_RCC_SYSCLK_CONFIG(RCC_ClkInitStruct->SYSCLKSource);
650  /* Get Start Tick*/
651  tickstart = HAL_GetTick();
652 
653  if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
654  {
656  {
657  if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
658  {
659  return HAL_TIMEOUT;
660  }
661  }
662  }
663  else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
664  {
666  {
667  if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
668  {
669  return HAL_TIMEOUT;
670  }
671  }
672  }
673  else
674  {
676  {
677  if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
678  {
679  return HAL_TIMEOUT;
680  }
681  }
682  }
683  }
684 
685  /* Decreasing the number of wait states because of lower CPU frequency */
686  if(FLatency < (FLASH->ACR & FLASH_ACR_LATENCY))
687  {
688  /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
689  __HAL_FLASH_SET_LATENCY(FLatency);
690 
691  /* Check that the new number of wait states is taken into account to access the Flash
692  memory by reading the FLASH_ACR register */
693  if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
694  {
695  return HAL_ERROR;
696  }
697  }
698 
699  /*-------------------------- PCLK1 Configuration ---------------------------*/
700  if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
701  {
702  assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
703  MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
704  }
705 
706  /*-------------------------- PCLK2 Configuration ---------------------------*/
707  if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
708  {
709  assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
710  MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3));
711  }
712 
713  /* Update the SystemCoreClock global variable */
715 
716  /* Configure the source of time base considering new system clocks settings*/
718 
719  return HAL_OK;
720 }
721 
767 void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
768 {
769  GPIO_InitTypeDef GPIO_InitStruct;
770  /* Check the parameters */
771  assert_param(IS_RCC_MCO(RCC_MCOx));
772  assert_param(IS_RCC_MCODIV(RCC_MCODiv));
773  /* RCC_MCO1 */
774  if(RCC_MCOx == RCC_MCO1)
775  {
776  assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource));
777 
778  /* MCO1 Clock Enable */
779  MCO1_CLK_ENABLE();
780 
781  /* Configure the MCO1 pin in alternate function mode */
782  GPIO_InitStruct.Pin = MCO1_PIN;
783  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
784  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
785  GPIO_InitStruct.Pull = GPIO_NOPULL;
786  GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
787  HAL_GPIO_Init(MCO1_GPIO_PORT, &GPIO_InitStruct);
788 
789  /* Mask MCO1 and MCO1PRE[2:0] bits then Select MCO1 clock source and prescaler */
790  MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO1 | RCC_CFGR_MCO1PRE), (RCC_MCOSource | RCC_MCODiv));
791  }
792  else
793  {
794  assert_param(IS_RCC_MCO2SOURCE(RCC_MCOSource));
795 
796  /* MCO2 Clock Enable */
797  MCO2_CLK_ENABLE();
798 
799  /* Configure the MCO2 pin in alternate function mode */
800  GPIO_InitStruct.Pin = MCO2_PIN;
801  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
802  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
803  GPIO_InitStruct.Pull = GPIO_NOPULL;
804  GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
805  HAL_GPIO_Init(MCO2_GPIO_PORT, &GPIO_InitStruct);
806 
807  /* Mask MCO2 and MCO2PRE[2:0] bits then Select MCO2 clock source and prescaler */
808  MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO2 | RCC_CFGR_MCO2PRE), (RCC_MCOSource | (RCC_MCODiv << 3)));
809  }
810 }
811 
821 void HAL_RCC_EnableCSS(void)
822 {
823  SET_BIT(RCC->CR, RCC_CR_CSSON);
824 }
825 
830 void HAL_RCC_DisableCSS(void)
831 {
832  CLEAR_BIT(RCC->CR, RCC_CR_CSSON);
833 }
834 
865 uint32_t HAL_RCC_GetSysClockFreq(void)
866 {
867  uint32_t pllm = 0, pllvco = 0, pllp = 0;
868  uint32_t sysclockfreq = 0;
869 
870  /* Get SYSCLK source -------------------------------------------------------*/
871  switch (RCC->CFGR & RCC_CFGR_SWS)
872  {
873  case RCC_SYSCLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
874  {
875  sysclockfreq = HSI_VALUE;
876  break;
877  }
878  case RCC_SYSCLKSOURCE_STATUS_HSE: /* HSE used as system clock source */
879  {
880  sysclockfreq = HSE_VALUE;
881  break;
882  }
883  case RCC_SYSCLKSOURCE_STATUS_PLLCLK: /* PLL used as system clock source */
884  {
885  /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
886  SYSCLK = PLL_VCO / PLLP */
887  pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
889  {
890  /* HSE used as PLL clock source */
891  pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
892  }
893  else
894  {
895  /* HSI used as PLL clock source */
896  pllvco = ((HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
897  }
898  pllp = ((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> POSITION_VAL(RCC_PLLCFGR_PLLP)) + 1 ) *2);
899 
900  sysclockfreq = pllvco/pllp;
901  break;
902  }
903  default:
904  {
905  sysclockfreq = HSI_VALUE;
906  break;
907  }
908  }
909  return sysclockfreq;
910 }
911 
919 uint32_t HAL_RCC_GetHCLKFreq(void)
920 {
921  return SystemCoreClock;
922 }
923 
930 uint32_t HAL_RCC_GetPCLK1Freq(void)
931 {
932  /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
934 }
935 
942 uint32_t HAL_RCC_GetPCLK2Freq(void)
943 {
944  /* Get HCLK source and Compute PCLK2 frequency ---------------------------*/
946 }
947 
955 void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
956 {
957  /* Set all possible values for the Oscillator type parameter ---------------*/
959 
960  /* Get the HSE configuration -----------------------------------------------*/
961  if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
962  {
963  RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
964  }
965  else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
966  {
967  RCC_OscInitStruct->HSEState = RCC_HSE_ON;
968  }
969  else
970  {
971  RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
972  }
973 
974  /* Get the HSI configuration -----------------------------------------------*/
975  if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
976  {
977  RCC_OscInitStruct->HSIState = RCC_HSI_ON;
978  }
979  else
980  {
981  RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
982  }
983 
984  RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR &RCC_CR_HSITRIM) >> POSITION_VAL(RCC_CR_HSITRIM));
985 
986  /* Get the LSE configuration -----------------------------------------------*/
987  if((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
988  {
989  RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
990  }
991  else if((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
992  {
993  RCC_OscInitStruct->LSEState = RCC_LSE_ON;
994  }
995  else
996  {
997  RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
998  }
999 
1000  /* Get the LSI configuration -----------------------------------------------*/
1001  if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
1002  {
1003  RCC_OscInitStruct->LSIState = RCC_LSI_ON;
1004  }
1005  else
1006  {
1007  RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
1008  }
1009 
1010  /* Get the PLL configuration -----------------------------------------------*/
1011  if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
1012  {
1013  RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
1014  }
1015  else
1016  {
1017  RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
1018  }
1019  RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
1020  RCC_OscInitStruct->PLL.PLLM = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM);
1021  RCC_OscInitStruct->PLL.PLLN = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN));
1022  RCC_OscInitStruct->PLL.PLLP = (uint32_t)((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) + RCC_PLLCFGR_PLLP_0) << 1) >> POSITION_VAL(RCC_PLLCFGR_PLLP));
1023  RCC_OscInitStruct->PLL.PLLQ = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLQ) >> POSITION_VAL(RCC_PLLCFGR_PLLQ));
1024 }
1025 
1034 void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
1035 {
1036  /* Set all possible values for the Clock type parameter --------------------*/
1038 
1039  /* Get the SYSCLK configuration --------------------------------------------*/
1040  RCC_ClkInitStruct->SYSCLKSource = (uint32_t)(RCC->CFGR & RCC_CFGR_SW);
1041 
1042  /* Get the HCLK configuration ----------------------------------------------*/
1043  RCC_ClkInitStruct->AHBCLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_HPRE);
1044 
1045  /* Get the APB1 configuration ----------------------------------------------*/
1046  RCC_ClkInitStruct->APB1CLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_PPRE1);
1047 
1048  /* Get the APB2 configuration ----------------------------------------------*/
1049  RCC_ClkInitStruct->APB2CLKDivider = (uint32_t)((RCC->CFGR & RCC_CFGR_PPRE2) >> 3);
1050 
1051  /* Get the Flash Wait State (Latency) configuration ------------------------*/
1052  *pFLatency = (uint32_t)(FLASH->ACR & FLASH_ACR_LATENCY);
1053 }
1054 
1060 void HAL_RCC_NMI_IRQHandler(void)
1061 {
1062  /* Check RCC CSSF flag */
1064  {
1065  /* RCC Clock Security System interrupt user callback */
1067 
1068  /* Clear RCC CSS pending bit */
1070  }
1071 }
1072 
1077 __weak void HAL_RCC_CSSCallback(void)
1078 {
1079  /* NOTE : This function Should not be modified, when the callback is needed,
1080  the HAL_RCC_CSSCallback could be implemented in the user file
1081  */
1082 }
1083 
1092 #endif /* HAL_RCC_MODULE_ENABLED */
1093 
1101 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define RCC_DBP_TIMEOUT_VALUE
#define CLEAR_BIT(REG, BIT)
Definition: stm32f7xx.h:180
#define RCC_CLOCKTYPE_PCLK1
#define RCC_FLAG_PLLRDY
#define LSI_TIMEOUT_VALUE
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition: stm32f7xx.h:190
#define RCC_CFGR_SW
Definition: stm32f745xx.h:5238
#define IS_RCC_LSE(LSE)
#define RCC_SYSCLKSOURCE_PLLCLK
#define __HAL_RCC_LSI_ENABLE()
Macros to enable or disable the Internal Low Speed oscillator (LSI).
#define GPIO_NOPULL
RCC System, AHB and APB busses clock configuration structure definition.
#define RCC_LSE_BYPASS
#define RCC_BDCR_LSEON
Definition: stm32f745xx.h:5600
void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
#define RCC_CLOCKTYPE_HCLK
#define PLL_TIMEOUT_VALUE
#define TICK_INT_PRIORITY
#define assert_param(expr)
Include module&#39;s header file.
#define RCC_CFGR_MCO2
Definition: stm32f745xx.h:5319
#define RCC_CFGR_PPRE1
Definition: stm32f745xx.h:5271
#define RCC_PLLCFGR_PLLN
Definition: stm32f745xx.h:5213
#define IS_RCC_HSE(HSE)
#define RCC_PLLCFGR_PLLP_0
Definition: stm32f745xx.h:5224
void HAL_RCC_EnableCSS(void)
#define RCC_CLOCKTYPE_SYSCLK
#define HSI_VALUE
Internal High Speed oscillator (HSI) value. This value is used by the RCC HAL module to compute the s...
uint32_t SystemCoreClock
#define RCC_FLAG_HSIRDY
#define RCC_HSI_ON
#define RCC_SYSCLKSOURCE_HSE
#define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(__HSICALIBRATIONVALUE__)
Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
#define IS_RCC_SYSCLKSOURCE(SOURCE)
#define IS_RCC_PCLK(PCLK)
#define IS_RCC_PLL(PLL)
#define RCC_PLL_OFF
#define RCC_FLAG_HSERDY
#define RCC_MCO1
#define __HAL_RCC_HSI_DISABLE()
#define RCC_HSE_BYPASS
#define RCC_CR_PLLI2SON
Definition: stm32f745xx.h:5200
#define RCC_CR_HSEBYP
Definition: stm32f745xx.h:5196
#define RCC_CFGR_MCO1
Definition: stm32f745xx.h:5303
#define IS_RCC_PLLP_VALUE(VALUE)
#define RCC_HSE_OFF
#define FLASH
Definition: stm32f745xx.h:1326
#define RCC_OSCILLATORTYPE_LSI
void HAL_RCC_DeInit(void)
#define IS_RCC_PLLN_VALUE(VALUE)
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
RCC_PLLInitTypeDef PLL
#define RCC_PLL_ON
#define RCC_CFGR_PPRE2
Definition: stm32f745xx.h:5283
#define WRITE_REG(REG, VAL)
Definition: stm32f7xx.h:186
#define __HAL_RCC_GET_IT(__INTERRUPT__)
Check the RCC&#39;s interrupt has occurred or not.
#define RCC_FLAG_LSERDY
#define RCC
Definition: stm32f745xx.h:1325
#define RCC_PLLCFGR_PLLM_4
Definition: stm32f745xx.h:5211
#define PWR_CR1_DBP
Definition: stm32f745xx.h:4979
#define POSITION_VAL(VAL)
Definition: stm32f7xx.h:192
#define RCC_CR_HSITRIM
Definition: stm32f745xx.h:5179
#define __HAL_RCC_LSE_CONFIG(__STATE__)
Macro to configure the External Low Speed oscillator (LSE).
#define __HAL_RCC_PWR_CLK_ENABLE()
#define RCC_PLLCFGR_PLLP
Definition: stm32f745xx.h:5223
#define RCC_SYSCLKSOURCE_STATUS_PLLCLK
#define __HAL_RCC_PLL_DISABLE()
#define HSE_VALUE
Adjust the value of External High Speed oscillator (HSE) used in your application. This value is used by the RCC HAL module to compute the system frequency (when HSE is used as system clock source, directly or through the PLL).
#define __HAL_FLASH_SET_LATENCY(__LATENCY__)
Set the FLASH Latency.
#define RCC_PLLCFGR_PLLSRC_HSE
Definition: stm32f745xx.h:5227
#define RCC_LSI_ON
#define __HAL_RCC_CLEAR_IT(__INTERRUPT__)
Clear the RCC&#39;s interrupt pending bits (Perform Byte access to RCC_CIR[23:16] bits to clear the selec...
#define __HAL_RCC_PLL_ENABLE()
Macros to enable or disable the main PLL.
#define RCC_PLLCFGR_PLLQ_2
Definition: stm32f745xx.h:5232
uint32_t HAL_RCC_GetPCLK1Freq(void)
#define RCC_PLLCFGR_PLLM
Definition: stm32f745xx.h:5206
#define __HAL_RCC_GET_PLL_OSCSOURCE()
Macro to get the oscillator used as PLL clock source.
#define __HAL_RCC_HSI_ENABLE()
Macros to enable or disable the Internal High Speed oscillator (HSI).
#define HSI_TIMEOUT_VALUE
#define __HAL_RCC_GET_FLAG(__FLAG__)
#define __HAL_RCC_SYSCLK_CONFIG(__RCC_SYSCLKSOURCE__)
Macro to configure the system clock source.
#define RCC_PLLI2SCFGR_PLLI2SR_1
Definition: stm32f745xx.h:5651
#define RCC_CFGR_HPRE
Definition: stm32f745xx.h:5254
#define RCC_PLLCFGR_PLLSRC
Definition: stm32f745xx.h:5226
#define IS_RCC_MCO2SOURCE(SOURCE)
#define CLEAR_REG(REG)
Definition: stm32f7xx.h:184
#define RCC_CFGR_MCO2PRE
Definition: stm32f745xx.h:5314
#define RCC_OSCILLATORTYPE_HSI
This file contains all the functions prototypes for the HAL module driver.
const uint8_t AHBPrescTable[16]
#define IS_RCC_CLOCKTYPE(CLK)
uint32_t HAL_RCC_GetSysClockFreq(void)
#define PWR
Definition: stm32f745xx.h:1285
#define RCC_CR_CSSON
Definition: stm32f745xx.h:5197
#define IS_RCC_MCO(MCOX)
#define RCC_PLL_NONE
#define IS_RCC_CALIBRATION_VALUE(VALUE)
const uint8_t APBPrescTable[8]
#define IS_RCC_PLLQ_VALUE(VALUE)
#define IS_FLASH_LATENCY(LATENCY)
GPIO Init structure definition.
#define RCC_SYSCLKSOURCE_STATUS_HSI
#define RCC_CSR_LSION
Definition: stm32f745xx.h:5613
#define HSE_TIMEOUT_VALUE
#define RCC_PLLI2SCFGR_PLLI2SN_6
Definition: stm32f745xx.h:5638
#define FLASH_ACR_LATENCY
Definition: stm32f745xx.h:3843
#define RCC_HSE_ON
#define RCC_PLLCFGR_PLLN_7
Definition: stm32f745xx.h:5221
#define IS_RCC_HSI(HSI)
#define RCC_OSCILLATORTYPE_HSE
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
#define RCC_IT_CSS
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition.
#define RCC_CFGR_MCO1PRE
Definition: stm32f745xx.h:5309
#define SET_BIT(REG, BIT)
Definition: stm32f7xx.h:178
void HAL_RCC_DisableCSS(void)
#define RCC_BDCR_LSEBYP
Definition: stm32f745xx.h:5602
uint32_t HAL_RCC_GetHCLKFreq(void)
#define RCC_HSI_OFF
#define RCC_CR_HSEON
Definition: stm32f745xx.h:5194
#define IS_RCC_PLLM_VALUE(VALUE)
#define IS_RCC_HCLK(HCLK)
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
#define IS_RCC_PLLSOURCE(SOURCE)
#define IS_RCC_OSCILLATORTYPE(OSCILLATOR)
#define RCC_FLAG_LSIRDY
void HAL_RCC_CSSCallback(void)
#define RCC_CR_HSITRIM_4
Definition: stm32f745xx.h:5184
#define RCC_PLLI2SCFGR_PLLI2SN_7
Definition: stm32f745xx.h:5639
#define IS_RCC_MCO1SOURCE(SOURCE)
#define GPIO_AF0_MCO
#define GPIO_MODE_AF_PP
#define IS_RCC_LSI(LSI)
#define __HAL_RCC_HSE_CONFIG(__STATE__)
Macro to configure the External High Speed oscillator (HSE).
HAL_StatusTypeDef
HAL Status structures definition.
#define RCC_OSCILLATORTYPE_LSE
#define RCC_PLLCFGR_PLLQ
Definition: stm32f745xx.h:5229
#define RCC_CLOCKTYPE_PCLK2
#define RCC_LSI_OFF
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
#define RCC_SYSCLKSOURCE_STATUS_HSE
#define RCC_CFGR_SWS
Definition: stm32f745xx.h:5246
uint32_t HAL_RCC_GetPCLK2Freq(void)
#define RCC_LSE_TIMEOUT_VALUE
#define RCC_LSE_OFF
#define CLOCKSWITCH_TIMEOUT_VALUE
#define __HAL_RCC_LSI_DISABLE()
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
This function configures the source of the time base. The time source is configured to have 1ms time ...
#define RCC_CR_HSION
Definition: stm32f745xx.h:5177
void HAL_RCC_NMI_IRQHandler(void)
#define RCC_PLLCFGR_PLLSRC_HSI
Definition: stm32f745xx.h:5228
#define RCC_PLLCFGR_PLLN_6
Definition: stm32f745xx.h:5220
#define IS_RCC_MCODIV(DIV)
#define __HAL_RCC_GET_SYSCLK_SOURCE()
Macro to get the clock source used as system clock.
#define RCC_LSE_ON
#define RCC_CR_PLLON
Definition: stm32f745xx.h:5198