Ignore:
Timestamp:
Dec 2, 2024, 10:55:02 AM (6 weeks ago)
Author:
Zed
Message:

RTC module was activated.

Location:
ctrl/firmware/Main/CubeMX/Core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ctrl/firmware/Main/CubeMX/Core/Inc/stm32h7xx_hal_conf.h

    r13 r39  
    6868/* #define HAL_RAMECC_MODULE_ENABLED   */
    6969/* #define HAL_RNG_MODULE_ENABLED   */
    70 /* #define HAL_RTC_MODULE_ENABLED   */
     70#define HAL_RTC_MODULE_ENABLED
    7171/* #define HAL_SAI_MODULE_ENABLED   */
    7272/* #define HAL_SD_MODULE_ENABLED   */
  • ctrl/firmware/Main/CubeMX/Core/Src/main.c

    r38 r39  
    4242/* Private variables ---------------------------------------------------------*/
    4343
     44RTC_HandleTypeDef hrtc;
     45
    4446/* USER CODE BEGIN PV */
    4547
     
    4951void SystemClock_Config(void);
    5052static void MPU_Config(void);
     53static void MX_GPIO_Init(void);
     54static void MX_RTC_Init(void);
    5155/* USER CODE BEGIN PFP */
    5256
     
    97101
    98102  /* Initialize all configured peripherals */
     103  MX_GPIO_Init();
     104  MX_RTC_Init();
    99105  /* USER CODE BEGIN 2 */
    100106
     
    118124void SystemClock_Config(void)
    119125{
    120   RCC_OscInitTypeDef RCC_OscInitStruct {};
    121   RCC_ClkInitTypeDef RCC_ClkInitStruct {};
     126  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
     127  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
    122128
    123129  /** Supply configuration update enable
     
    127133  /** Configure the main internal regulator output voltage
    128134  */
    129   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
     135  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
    130136
    131137  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
     138
     139  /** Configure LSE Drive Capability
     140  */
     141  HAL_PWR_EnableBkUpAccess();
     142  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
    132143
    133144  /** Initializes the RCC Oscillators according to the specified parameters
    134145  * in the RCC_OscInitTypeDef structure.
    135146  */
    136   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
    137   RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
    138   RCC_OscInitStruct.HSICalibrationValue = 64;
    139   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
     147  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
     148  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
     149  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
     150  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
     151  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
     152  RCC_OscInitStruct.PLL.PLLM = 25;
     153  RCC_OscInitStruct.PLL.PLLN = 200;
     154  RCC_OscInitStruct.PLL.PLLP = 2;
     155  RCC_OscInitStruct.PLL.PLLQ = 2;
     156  RCC_OscInitStruct.PLL.PLLR = 2;
     157  RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_0;
     158  RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;
     159  RCC_OscInitStruct.PLL.PLLFRACN = 0;
    140160  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    141161  {
     
    148168                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
    149169                              |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
    150   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
     170  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    151171  RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
    152172  RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
     
    162182}
    163183
     184/**
     185  * @brief RTC Initialization Function
     186  * @param None
     187  * @retval None
     188  */
     189static void MX_RTC_Init(void)
     190{
     191
     192  /* USER CODE BEGIN RTC_Init 0 */
     193
     194  /* USER CODE END RTC_Init 0 */
     195
     196  /* USER CODE BEGIN RTC_Init 1 */
     197
     198  /* USER CODE END RTC_Init 1 */
     199
     200  /** Initialize RTC Only
     201  */
     202  hrtc.Instance = RTC;
     203  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
     204  hrtc.Init.AsynchPrediv = 127;
     205  hrtc.Init.SynchPrediv = 255;
     206  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
     207  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
     208  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
     209  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
     210  if (HAL_RTC_Init(&hrtc) != HAL_OK)
     211  {
     212    Error_Handler();
     213  }
     214  /* USER CODE BEGIN RTC_Init 2 */
     215
     216  /* USER CODE END RTC_Init 2 */
     217
     218}
     219
     220/**
     221  * @brief GPIO Initialization Function
     222  * @param None
     223  * @retval None
     224  */
     225static void MX_GPIO_Init(void)
     226{
     227/* USER CODE BEGIN MX_GPIO_Init_1 */
     228/* USER CODE END MX_GPIO_Init_1 */
     229
     230  /* GPIO Ports Clock Enable */
     231  __HAL_RCC_GPIOC_CLK_ENABLE();
     232  __HAL_RCC_GPIOH_CLK_ENABLE();
     233
     234/* USER CODE BEGIN MX_GPIO_Init_2 */
     235/* USER CODE END MX_GPIO_Init_2 */
     236}
     237
    164238/* USER CODE BEGIN 4 */
    165239
     
    170244void MPU_Config(void)
    171245{
    172   MPU_Region_InitTypeDef MPU_InitStruct {};
     246  MPU_Region_InitTypeDef MPU_InitStruct = {0};
    173247
    174248  /* Disables the MPU */
  • ctrl/firmware/Main/CubeMX/Core/Src/stm32h7xx_hal_msp.c

    r13 r39  
    7777}
    7878
     79/**
     80* @brief RTC MSP Initialization
     81* This function configures the hardware resources used in this example
     82* @param hrtc: RTC handle pointer
     83* @retval None
     84*/
     85void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
     86{
     87  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
     88  if(hrtc->Instance==RTC)
     89  {
     90  /* USER CODE BEGIN RTC_MspInit 0 */
     91
     92  /* USER CODE END RTC_MspInit 0 */
     93
     94  /** Initializes the peripherals clock
     95  */
     96    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
     97    PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
     98    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
     99    {
     100      Error_Handler();
     101    }
     102
     103    /* Peripheral clock enable */
     104    __HAL_RCC_RTC_ENABLE();
     105  /* USER CODE BEGIN RTC_MspInit 1 */
     106
     107  /* USER CODE END RTC_MspInit 1 */
     108
     109  }
     110
     111}
     112
     113/**
     114* @brief RTC MSP De-Initialization
     115* This function freeze the hardware resources used in this example
     116* @param hrtc: RTC handle pointer
     117* @retval None
     118*/
     119void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
     120{
     121  if(hrtc->Instance==RTC)
     122  {
     123  /* USER CODE BEGIN RTC_MspDeInit 0 */
     124
     125  /* USER CODE END RTC_MspDeInit 0 */
     126    /* Peripheral clock disable */
     127    __HAL_RCC_RTC_DISABLE();
     128  /* USER CODE BEGIN RTC_MspDeInit 1 */
     129
     130  /* USER CODE END RTC_MspDeInit 1 */
     131  }
     132
     133}
     134
    79135/* USER CODE BEGIN 1 */
    80136
Note: See TracChangeset for help on using the changeset viewer.