[bsp][stm32]添加 RTC 时钟源选择

This commit is contained in:
zylx 2019-03-19 18:21:51 +08:00
parent c9d88a8e51
commit b941e6c730
21 changed files with 179 additions and 29 deletions

View File

@ -68,11 +68,11 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
RTC_DateStruct.Year = p_tm->tm_year - 100;
RTC_DateStruct.WeekDay = p_tm->tm_wday + 1;
if(HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK)
if (HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK)
{
return -RT_ERROR;
}
if(HAL_RTC_SetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN) != HAL_OK)
if (HAL_RTC_SetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN) != HAL_OK)
{
return -RT_ERROR;
}
@ -87,9 +87,17 @@ static void rt_rtc_init(void)
__HAL_RCC_PWR_CLK_ENABLE();
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
#ifdef BSP_RTC_USING_LSI
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
#else
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
#endif
HAL_RCC_OscConfig(&RCC_OscInitStruct);
}
@ -99,7 +107,11 @@ static rt_err_t rt_rtc_config(struct rt_device *dev)
HAL_PWR_EnableBkUpAccess();
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
#ifdef BSP_RTC_USING_LSI
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
#else
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
#endif
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
RTC_Handler.Instance = RTC;
@ -110,13 +122,31 @@ static rt_err_t rt_rtc_config(struct rt_device *dev)
#if defined(SOC_SERIES_STM32F1)
RTC_Handler.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
RTC_Handler.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
#elif defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
RTC_Handler.Init.AsynchPrediv = 0X7F;
#ifndef SOC_SERIES_STM32F0
RTC_Handler.Init.SynchPrediv = 0XFF;
#elif defined(SOC_SERIES_STM32F0)
/* set the frequency division */
#ifdef BSP_RTC_USING_LSI
RTC_Handler.Init.AsynchPrediv = 0XA0;
RTC_Handler.Init.SynchPrediv = 0xFA;
#else
RTC_Handler.Init.AsynchPrediv = 0X7F;
RTC_Handler.Init.SynchPrediv = 0x0130;
#endif
#endif /* BSP_RTC_USING_LSI */
RTC_Handler.Init.HourFormat = RTC_HOURFORMAT_24;
RTC_Handler.Init.OutPut = RTC_OUTPUT_DISABLE;
RTC_Handler.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RTC_Handler.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
/* set the frequency division */
#ifdef BSP_RTC_USING_LSI
RTC_Handler.Init.AsynchPrediv = 0X7D;
#else
RTC_Handler.Init.AsynchPrediv = 0X7F;
#endif /* BSP_RTC_USING_LSI */
RTC_Handler.Init.SynchPrediv = 0XFF;
RTC_Handler.Init.HourFormat = RTC_HOURFORMAT_24;
RTC_Handler.Init.OutPut = RTC_OUTPUT_DISABLE;
RTC_Handler.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
@ -142,7 +172,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
if(set_rtc_time_stamp(*(rt_uint32_t *)args))
if (set_rtc_time_stamp(*(rt_uint32_t *)args))
{
result = -RT_ERROR;
}
@ -154,7 +184,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops rtc_ops =
const static struct rt_device_ops rtc_ops =
{
RT_NULL,
RT_NULL,

View File

@ -46,7 +46,7 @@ STM32F091RC-NuCLEO 开发板是 ST 官方推出的一款基于 ARM Cortex-M0 内
| I2C | 支持 | |
| TIMER | 支持 | |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| PWM | 支持 | |
| FLASH | 支持 | |
| IWG | 支持 | |

View File

@ -133,11 +133,23 @@ menu "On-chip Peripheral Drivers"
bool "Enable on-chip FLASH"
default n
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -46,7 +46,7 @@ ATK-NANO STM32F103 是正点原子推出的一款基于 ARM Cortex-M3 内核的
| UART | 支持 | UART1/2/3 |
| SPI | 支持 | SPI1/2 |
| I2C | 支持 | 软件 I2C |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| ADC | 支持 | |
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |

View File

@ -178,11 +178,23 @@ menu "On-chip Peripheral Drivers"
bool "Enable on-chip FLASH"
default n
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -54,7 +54,7 @@
| SPI | 支持 | SPI1/2/3 |
| I2C | 支持 | 软件 I2C |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |
| SDIO | 暂不支持 | 即将支持 |

View File

@ -250,11 +250,23 @@ menu "On-chip Peripheral Drivers"
default n
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -53,7 +53,7 @@
| SPI | 支持 | SPI1/2/3 |
| I2C | 支持 | 软件 I2C |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |
| PWM | 支持 | |

View File

@ -193,11 +193,23 @@ menu "On-chip Peripheral Drivers"
default 25
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -54,7 +54,7 @@ armfly-v6 STM32F429 是安富莱推出的一款基于 ARM Cortex-M4 内核的开
| SPI | 支持 | SPI1/2/5 |
| I2C | 支持 | 软件 I2C |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |
| SDIO | 支持 | |

View File

@ -182,11 +182,23 @@ menu "On-chip Peripheral Drivers"
default n
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -54,7 +54,7 @@
| SPI | 支持 | SPI1/2/5 |
| I2C | 支持 | 软件 I2C |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |
| SDIO | 支持 | |

View File

@ -219,11 +219,23 @@ menu "On-chip Peripheral Drivers"
default n
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -55,7 +55,7 @@
| SPI | 支持 | SPI1/2/5 |
| I2C | 支持 | 软件 I2C |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |
| SDIO | 暂不支持 | 即将支持 |

View File

@ -204,11 +204,23 @@ menu "On-chip Peripheral Drivers"
default 23
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -55,7 +55,7 @@
| SPI | 支持 | |
| I2C | 支持 | 软件 I2C |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| PWM | 支持 | |
| SDIO | 支持 | |

View File

@ -216,11 +216,23 @@ menu "On-chip Peripheral Drivers"
default 117
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -56,7 +56,7 @@
| SPI | 支持 | SPI1/x/x |
| I2C | 支持 | 软件 I2C |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |
| SDIO | 支持 | |

View File

@ -188,11 +188,23 @@ menuconfig BSP_USING_SPI
default 23
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"

View File

@ -65,7 +65,7 @@
| I2C | 支持 | |
| TIM | 支持 | |
| ADC | 支持 | |
| RTC | 支持 | |
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
| WDT | 支持 | |
| PWM | 支持 | |
| USB Device | 暂不支持 | 即将支持 |

View File

@ -210,11 +210,23 @@ menu "On-chip Peripheral Drivers"
default n
endif
config BSP_USING_ONCHIP_RTC
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
select RT_USING_LIBC
default n
if BSP_USING_ONCHIP_RTC
choice
prompt "Select clock source"
default BSP_RTC_USING_LSE
config BSP_RTC_USING_LSE
bool "RTC USING LSE"
config BSP_RTC_USING_LSI
bool "RTC USING LSI"
endchoice
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"