LPUART可以选择HSI时钟,LSE时钟和D3PCLK1时钟:
1、LPUART时钟选择LSE(32768Hz),最高速度是10922bps,最低8bps。
2、LPUART时钟选择HSI(64MHz),最高值是21MHz,最小值15625bps。
3、LPUART时钟选择D3PCLK1(100MHz),最大值33Mbps,最小值24414bps。
/* 使用LSE(32768Hz),最高速度是10922bps,最低8bps */
#if defined (LPUART_CLOCK_SOURCE_LSE)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
RCC_PeriphCLKInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_LSE;
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
}
/* LPUART时钟选择HSI(64MHz),最高值是21MHz,最小值15625bps */
#elif defined (LPUART_CLOCK_SOURCE_HSI)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
RCC_PeriphCLKInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_HSI;
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
}
/* LPUART时钟选择D3PCLK1(100MHz),最大值33Mbps,最小值24414bps */
#elif defined (LPUART_CLOCK_SOURCE_D3PCLK1)
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
RCC_PeriphCLKInitStruct.Lptim1ClockSelection = RCC_LPUART1CLKSOURCE_D3PCLK1;
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
#else
#error Please select the LPTIM Clock source inside the bsp_lpuart_fifo.c file
#endif |