STSW-STLKT01: Projects/SensorTile/Applications/AudioLoop/Src/cube_hal_l4.c Source File

STSW-STLKT01

cube_hal_l4.c
Go to the documentation of this file.
1 
38 /* Includes ------------------------------------------------------------------*/
39 #include "cube_hal.h"
40 #include "main.h"
41 
48 {
49  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
50  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
51  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
52 
53  __HAL_RCC_PWR_CLK_ENABLE();
54  HAL_PWR_EnableBkUpAccess();
55 
56  /* Enable the LSE Oscilator */
57  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
58  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
59  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
60  {
61  Error_Handler();
62  }
63 
64  /* Enable the CSS interrupt in case LSE signal is corrupted or not present */
65  HAL_RCCEx_DisableLSECSS();
66 
67  /* Enable MSI Oscillator and activate PLL with MSI as source */
68  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
69  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
70  RCC_OscInitStruct.HSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
71  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
72  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
73  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
74  RCC_OscInitStruct.PLL.PLLM = 6;
75  RCC_OscInitStruct.PLL.PLLN = 40;
76  RCC_OscInitStruct.PLL.PLLP = 7;
77  RCC_OscInitStruct.PLL.PLLQ = 4;
78  RCC_OscInitStruct.PLL.PLLR = 4;
79  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
80  {
81  Error_Handler();
82  }
83 
84  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
85  PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
86  if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
87  {
88  Error_Handler();
89  }
90 
91  /* Enable MSI Auto-calibration through LSE */
92  HAL_RCCEx_EnableMSIPLLMode();
93 
94  /* Select MSI output as USB clock source */
95  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
96  PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_MSI;
97  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
98 
99  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
100  clocks dividers */
101  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
102  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
103  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
104  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
105  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
106  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
107  {
108  Error_Handler();
109  }
110 }
111 
112 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void SystemClock_Config(void)
System Clock Configuration.
Definition: cube_hal_l4.c:48
static void Error_Handler(void)
This function is executed in case of error occurrence.
Definition: cube_hal_l4.c:118
Generated by   doxygen 1.8.13