Mercurial > public > ostc4
annotate Small_CPU/Src/rtc.c @ 1036:5865f0aeb438 Puls_Integration
Radio data integration:
Added functionality for displaying radio data as debug message. The USART3 has been configurated for receiption and a function for the visualization of the data has been added to the demo unit (draft implementation). For activation the radio as well as the logger functionality needs to be activated via compile switch. Note that at the moment bluetooth and radio DMA may not be operated in parallel.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 10 Aug 2025 15:28:59 +0200 |
| parents | c386ae6635e4 |
| children |
| 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 | |
| 1000 | 38 void RTC_GetDate(RTC_DateTypeDef* psdatestructure) |
| 39 { | |
| 40 HAL_RTC_GetDate(&RTCHandle, psdatestructure, RTC_FORMAT_BIN); | |
| 41 } | |
| 42 | |
| 38 | 43 void RTC_SetTime(RTC_TimeTypeDef stimestructure) |
| 44 { | |
| 45 | |
| 46 stimestructure.SubSeconds = 0; | |
|
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
47 stimestructure.TimeFormat = RTC_HOURFORMAT_24; |
| 38 | 48 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; |
| 49 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
| 50 | |
| 51 if(HAL_RTC_SetTime(&RTCHandle, &stimestructure, FORMAT_BIN) != HAL_OK) | |
| 52 { | |
| 53 RTC_Error_Handler(); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 | |
| 58 void RTC_SetDate(RTC_DateTypeDef sdatestructure) | |
| 59 { | |
| 60 if(HAL_RTC_SetDate(&RTCHandle, &sdatestructure, FORMAT_BIN) != HAL_OK) | |
| 61 { | |
| 62 RTC_Error_Handler(); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 | |
| 67 /* | |
| 68 static void RTC_CalendarConfig(void) | |
| 69 { | |
| 70 RTC_DateTypeDef sdatestructure; | |
| 71 RTC_TimeTypeDef stimestructure; | |
| 72 | |
| 73 //##-1- Configure the Date ################################################# | |
| 74 // Set Date: Monday April 14th 2014 | |
| 75 sdatestructure.Year = 0; | |
| 76 sdatestructure.Month = RTC_MONTH_JANUARY; | |
| 77 sdatestructure.Date = 1; | |
| 78 sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY; | |
| 79 | |
| 80 if(HAL_RTC_SetDate(&RTCHandle,&sdatestructure,FORMAT_BCD) != HAL_OK) | |
| 81 { | |
| 82 RTC_Error_Handler(); | |
| 83 } | |
| 84 | |
| 85 //##-2- Configure the Time ################################################# | |
| 86 // Set Time: 02:00:00 | |
| 87 stimestructure.Hours = 0; | |
| 88 stimestructure.Minutes = 0; | |
| 89 stimestructure.Seconds = 0; | |
| 90 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; | |
| 91 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
| 92 | |
| 93 if(HAL_RTC_SetTime(&RTCHandle,&stimestructure,FORMAT_BCD) != HAL_OK) | |
| 94 { | |
| 95 RTC_Error_Handler(); | |
| 96 } | |
| 97 | |
| 98 //##-3- Writes a data in a RTC Backup data Register0 ####################### | |
| 99 // HAL_RTCEx_BKUPWrite(&RTCHandle,RTC_BKP_DR0,0x32F2); | |
| 100 } | |
| 101 */ | |
| 102 | |
| 103 | |
| 104 /* ##-1- Configure the RTC peripheral ####################################### | |
| 105 Configure RTC prescaler and RTC data registers | |
| 106 RTC configured as follow: | |
| 107 - Hour Format = Format 24 | |
| 108 - Asynch Prediv = Value according to source clock | |
| 109 - Synch Prediv = Value according to source clock | |
| 110 - OutPut = Output Disable | |
| 111 - OutPutPolarity = High Polarity | |
| 112 - OutPutType = Open Drain | |
| 113 */ | |
| 114 | |
| 115 | |
| 116 void MX_RTC_init(void) | |
| 117 { | |
|
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
118 /* Initialize RTC */ |
| 38 | 119 RTCHandle.Instance = RTC; |
| 120 RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
| 121 RTCHandle.Init.AsynchPrediv = 127; | |
| 122 RTCHandle.Init.SynchPrediv = 255; | |
| 123 RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
| 124 RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
| 125 RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
| 126 HAL_RTC_Init(&RTCHandle); | |
| 127 } | |
| 128 | |
| 129 | |
| 130 void RTC_StopMode_2seconds(void) | |
| 131 { | |
| 132 /* Enable Power Control clock */ | |
| 133 __HAL_RCC_PWR_CLK_ENABLE(); | |
| 134 | |
| 135 /* Disable Wake-up timer */ | |
| 136 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 137 | |
| 138 /* Enable Wake-up timer */ | |
| 139 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x1000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
| 140 | |
| 141 /* FLASH Deep Power Down Mode enabled */ | |
| 142 HAL_PWREx_EnableFlashPowerDown(); | |
| 143 | |
| 144 /*## Enter Stop Mode #######################################################*/ | |
| 145 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); | |
| 146 | |
| 147 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
| 148 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
| 149 SYSCLKConfig_STOP(); | |
| 150 | |
| 151 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 152 } | |
| 153 | |
| 154 | |
| 155 void RTC_Stop_11ms(void) | |
| 156 { | |
| 157 /* Disable Wake-up timer */ | |
| 158 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 159 | |
| 160 /* Enable Wake-up timer */ | |
| 161 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x18-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
| 162 | |
| 163 /* FLASH Deep Power Down Mode enabled */ | |
| 164 HAL_PWREx_DisableFlashPowerDown(); | |
| 165 | |
| 166 /*## Enter Stop Mode #######################################################*/ | |
| 167 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); | |
| 168 | |
| 169 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
| 170 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
| 171 SYSCLKConfig_STOP(); | |
| 172 | |
| 173 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
| 174 } | |
| 175 | |
| 176 | |
| 177 static void RTC_Error_Handler(void) | |
| 178 { | |
| 179 while(1); | |
| 180 } | |
| 181 | |
| 182 | |
| 183 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
