Mercurial > public > ostc4
annotate Small_CPU/Src/rtc.c @ 986:5e7ad81e9ac2 BootloaderOstc5
Removed dependencies to OSTC HW version
| author | Ideenmodellierer |
|---|---|
| date | Sun, 30 Mar 2025 21:33:18 +0200 |
| parents | 9b29995d6619 |
| children | c386ae6635e4 |
| rev | line source |
|---|---|
| 38 | 1 /** |
| 2 ****************************************************************************** | |
| 3 * @file rtc.c | |
| 4 * @author heinrichs weikamp gmbh | |
| 5 * @version V0.0.1 | |
| 6 * @date 10-Oct-2014 | |
| 7 * @brief Source code for rtc control | |
| 8 * | |
| 9 @verbatim | |
| 10 ============================================================================== | |
| 11 ##### How to use ##### | |
| 12 ============================================================================== | |
| 13 @endverbatim | |
| 14 ****************************************************************************** | |
| 15 * @attention | |
| 16 * | |
| 17 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
| 18 * | |
| 19 ****************************************************************************** | |
| 20 */ | |
| 21 /* Includes ------------------------------------------------------------------*/ | |
| 22 #include "rtc.h" | |
| 23 #include "stm32f4xx_hal.h" | |
| 24 #include "stm32f4xx_hal_conf.h" | |
| 25 #include "baseCPU2.h" | |
| 26 | |
| 27 RTC_HandleTypeDef RTCHandle; | |
| 28 | |
| 29 static void RTC_Error_Handler(void); | |
| 30 | |
| 31 | |
| 955 | 32 |
| 33 void RTC_GetTime(RTC_TimeTypeDef* pstimestructure) | |
| 34 { | |
| 35 HAL_RTC_GetTime(&RTCHandle, pstimestructure, RTC_FORMAT_BIN); | |
| 36 } | |
| 37 | |
| 38 | 38 void RTC_SetTime(RTC_TimeTypeDef stimestructure) |
| 39 { | |
| 40 | |
| 41 stimestructure.SubSeconds = 0; | |
|
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
42 stimestructure.TimeFormat = RTC_HOURFORMAT_24; |
| 38 | 43 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; |
| 44 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
| 45 | |
| 46 if(HAL_RTC_SetTime(&RTCHandle, &stimestructure, FORMAT_BIN) != HAL_OK) | |
| 47 { | |
| 48 RTC_Error_Handler(); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 | |
| 53 void RTC_SetDate(RTC_DateTypeDef sdatestructure) | |
| 54 { | |
| 55 if(HAL_RTC_SetDate(&RTCHandle, &sdatestructure, FORMAT_BIN) != HAL_OK) | |
| 56 { | |
| 57 RTC_Error_Handler(); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 | |
| 62 /* | |
| 63 static void RTC_CalendarConfig(void) | |
| 64 { | |
| 65 RTC_DateTypeDef sdatestructure; | |
| 66 RTC_TimeTypeDef stimestructure; | |
| 67 | |
| 68 //##-1- Configure the Date ################################################# | |
| 69 // Set Date: Monday April 14th 2014 | |
| 70 sdatestructure.Year = 0; | |
| 71 sdatestructure.Month = RTC_MONTH_JANUARY; | |
| 72 sdatestructure.Date = 1; | |
| 73 sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY; | |
| 74 | |
| 75 if(HAL_RTC_SetDate(&RTCHandle,&sdatestructure,FORMAT_BCD) != HAL_OK) | |
| 76 { | |
| 77 RTC_Error_Handler(); | |
| 78 } | |
| 79 | |
| 80 //##-2- Configure the Time ################################################# | |
| 81 // Set Time: 02:00:00 | |
| 82 stimestructure.Hours = 0; | |
| 83 stimestructure.Minutes = 0; | |
| 84 stimestructure.Seconds = 0; | |
| 85 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; | |
| 86 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
| 87 | |
| 88 if(HAL_RTC_SetTime(&RTCHandle,&stimestructure,FORMAT_BCD) != HAL_OK) | |
| 89 { | |
| 90 RTC_Error_Handler(); | |
| 91 } | |
| 92 | |
| 93 //##-3- Writes a data in a RTC Backup data Register0 ####################### | |
| 94 // HAL_RTCEx_BKUPWrite(&RTCHandle,RTC_BKP_DR0,0x32F2); | |
| 95 } | |
| 96 */ | |
| 97 | |
| 98 | |
| 99 /* ##-1- Configure the RTC peripheral ####################################### | |
| 100 Configure RTC prescaler and RTC data registers | |
| 101 RTC configured as follow: | |
| 102 - Hour Format = Format 24 | |
| 103 - Asynch Prediv = Value according to source clock | |
| 104 - Synch Prediv = Value according to source clock | |
| 105 - OutPut = Output Disable | |
| 106 - OutPutPolarity = High Polarity | |
| 107 - OutPutType = Open Drain | |
| 108 */ | |
| 109 | |
| 110 | |
| 111 void MX_RTC_init(void) | |
| 112 { | |
|
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
113 /* Initialize RTC */ |
| 38 | 114 RTCHandle.Instance = RTC; |
| 115 RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
| 116 RTCHandle.Init.AsynchPrediv = 127; | |
| 117 RTCHandle.Init.SynchPrediv = 255; | |
| 118 RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
| 119 RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
| 120 RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
| 121 HAL_RTC_Init(&RTCHandle); | |
| 122 } | |
| 123 | |
| 124 | |
| 125 void RTC_StopMode_2seconds(void) | |
| 126 { | |
| 127 /* Enable Power Control clock */ | |
| 128 __HAL_RCC_PWR_CLK_ENABLE(); | |
| 129 | |
| 130 /* Disable Wake-up timer */ | |
| 131 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 132 | |
| 133 /* Enable Wake-up timer */ | |
| 134 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x1000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
| 135 | |
| 136 /* FLASH Deep Power Down Mode enabled */ | |
| 137 HAL_PWREx_EnableFlashPowerDown(); | |
| 138 | |
| 139 /*## Enter Stop Mode #######################################################*/ | |
| 140 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); | |
| 141 | |
| 142 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
| 143 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
| 144 SYSCLKConfig_STOP(); | |
| 145 | |
| 146 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 147 } | |
| 148 | |
| 149 | |
| 150 void RTC_Stop_11ms(void) | |
| 151 { | |
| 152 /* Disable Wake-up timer */ | |
| 153 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 154 | |
| 155 /* Enable Wake-up timer */ | |
| 156 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x18-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
| 157 | |
| 158 /* FLASH Deep Power Down Mode enabled */ | |
| 159 HAL_PWREx_DisableFlashPowerDown(); | |
| 160 | |
| 161 /*## Enter Stop Mode #######################################################*/ | |
| 162 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); | |
| 163 | |
| 164 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
| 165 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
| 166 SYSCLKConfig_STOP(); | |
| 167 | |
| 168 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 169 } | |
| 170 | |
| 171 | |
| 172 static void RTC_Error_Handler(void) | |
| 173 { | |
| 174 while(1); | |
| 175 } | |
| 176 | |
| 177 | |
| 178 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
