[BSP/STM32] add support of RTC in g491 (#8377)

This commit is contained in:
Supper Thomas 2023-12-17 21:44:25 +08:00 committed by GitHub
parent 8dee48fdaa
commit 04b2c81745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 19 deletions

View File

@ -13,6 +13,7 @@
#include "board.h"
#include <sys/time.h>
#include <rtdevice.h>
#ifdef BSP_USING_ONCHIP_RTC
@ -193,7 +194,7 @@ static rt_err_t rt_rtc_config(void)
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_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WL) || defined(SOC_SERIES_STM32H7) || defined (SOC_SERIES_STM32WB)
#elif defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G4) || defined(SOC_SERIES_STM32WL) || defined(SOC_SERIES_STM32H7) || defined (SOC_SERIES_STM32WB)
/* set the frequency division */
#ifdef BSP_RTC_USING_LSI

File diff suppressed because one or more lines are too long

View File

@ -56,7 +56,7 @@
/*#define HAL_PCD_MODULE_ENABLED */
/*#define HAL_QSPI_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
#define HAL_RTC_MODULE_ENABLED
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */

View File

@ -44,6 +44,8 @@ IWDG_HandleTypeDef hiwdg;
UART_HandleTypeDef hlpuart1;
RTC_HandleTypeDef hrtc;
TIM_HandleTypeDef htim7;
TIM_HandleTypeDef htim15;
TIM_HandleTypeDef htim16;
@ -62,6 +64,7 @@ static void MX_TIM15_Init(void);
static void MX_TIM16_Init(void);
static void MX_TIM17_Init(void);
static void MX_TIM7_Init(void);
static void MX_RTC_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@ -105,6 +108,7 @@ int main(void)
MX_TIM16_Init();
MX_TIM17_Init();
MX_TIM7_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
@ -133,10 +137,17 @@ void SystemClock_Config(void)
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);
/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI
|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
@ -243,6 +254,43 @@ static void MX_LPUART1_UART_Init(void)
}
/**
* @brief RTC Initialization Function
* @param None
* @retval None
*/
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
}
/**
* @brief TIM7 Initialization Function
* @param None

View File

@ -157,6 +157,63 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
}
/**
* @brief RTC MSP Initialization
* This function configures the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspInit 0 */
/* USER CODE END RTC_MspInit 0 */
/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_RTC_ENABLE();
__HAL_RCC_RTCAPB_CLK_ENABLE();
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
/**
* @brief RTC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
{
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspDeInit 0 */
/* USER CODE END RTC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_RTC_DISABLE();
__HAL_RCC_RTCAPB_CLK_DISABLE();
/* USER CODE BEGIN RTC_MspDeInit 1 */
/* USER CODE END RTC_MspDeInit 1 */
}
}
/**
* @brief TIM_Base MSP Initialization
* This function configures the hardware resources used in this example

View File

@ -13,24 +13,26 @@ Mcu.IP0=IWDG
Mcu.IP1=LPUART1
Mcu.IP2=NVIC
Mcu.IP3=RCC
Mcu.IP4=SYS
Mcu.IP5=TIM7
Mcu.IP6=TIM15
Mcu.IP7=TIM16
Mcu.IP8=TIM17
Mcu.IPNb=9
Mcu.IP4=RTC
Mcu.IP5=SYS
Mcu.IP6=TIM7
Mcu.IP7=TIM15
Mcu.IP8=TIM16
Mcu.IP9=TIM17
Mcu.IPNb=10
Mcu.Name=STM32G491R(C-E)Tx
Mcu.Package=LQFP64
Mcu.Pin0=PC13
Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PB3
Mcu.Pin11=VP_IWDG_VS_IWDG
Mcu.Pin12=VP_SYS_VS_Systick
Mcu.Pin13=VP_SYS_VS_DBSignals
Mcu.Pin14=VP_TIM7_VS_ClockSourceINT
Mcu.Pin15=VP_TIM15_VS_ClockSourceINT
Mcu.Pin16=VP_TIM16_VS_ClockSourceINT
Mcu.Pin17=VP_TIM17_VS_ClockSourceINT
Mcu.Pin12=VP_RTC_VS_RTC_Activate
Mcu.Pin13=VP_SYS_VS_Systick
Mcu.Pin14=VP_SYS_VS_DBSignals
Mcu.Pin15=VP_TIM7_VS_ClockSourceINT
Mcu.Pin16=VP_TIM15_VS_ClockSourceINT
Mcu.Pin17=VP_TIM16_VS_ClockSourceINT
Mcu.Pin18=VP_TIM17_VS_ClockSourceINT
Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin3=PF0-OSC_IN
Mcu.Pin4=PF1-OSC_OUT
@ -39,7 +41,7 @@ Mcu.Pin6=PA3
Mcu.Pin7=PA5
Mcu.Pin8=PA13
Mcu.Pin9=PA14
Mcu.PinsNb=18
Mcu.PinsNb=19
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32G491RETx
@ -132,7 +134,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_LPUART1_UART_Init-LPUART1-false-HAL-true,4-MX_IWDG_Init-IWDG-false-HAL-true,5-MX_TIM15_Init-TIM15-false-HAL-true,6-MX_TIM16_Init-TIM16-false-HAL-true,7-MX_TIM17_Init-TIM17-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_LPUART1_UART_Init-LPUART1-false-HAL-true,4-MX_IWDG_Init-IWDG-false-HAL-true,5-MX_TIM15_Init-TIM15-false-HAL-true,6-MX_TIM16_Init-TIM16-false-HAL-true,7-MX_TIM17_Init-TIM17-false-HAL-true,8-MX_TIM7_Init-TIM7-false-HAL-true,9-MX_RTC_Init-RTC-false-HAL-true
RCC.ADC12Freq_Value=170000000
RCC.ADC345Freq_Value=170000000
RCC.AHBFreq_Value=170000000
@ -187,6 +189,8 @@ SH.GPXTI13.0=GPIO_EXTI13
SH.GPXTI13.ConfNb=1
VP_IWDG_VS_IWDG.Mode=IWDG_Activate
VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate
VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals
VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals
VP_SYS_VS_Systick.Mode=SysTick