Skip to content

Commit 432465b

Browse files
Tobias Badertscherdpgeorge
authored andcommitted
stmhal: L4: Modify rtc.c to support L4 MCU.
1 parent aed1da9 commit 432465b

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

stmhal/rtc.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ void rtc_init_finalise() {
190190

191191
// fresh reset; configure RTC Calendar
192192
RTC_CalendarConfig();
193+
#if defined(MCU_SERIES_L4)
194+
if(__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST) != RESET) {
195+
#else
193196
if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET) {
197+
#endif
194198
// power on reset occurred
195199
rtc_info |= 0x10000;
196200
}
@@ -223,7 +227,7 @@ STATIC HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruc
223227
HAL_PWR_EnableBkUpAccess();
224228
uint32_t tickstart = HAL_GetTick();
225229

226-
#if defined(MCU_SERIES_F7)
230+
#if defined(MCU_SERIES_F7) || defined(MCU_SERIES_L4)
227231
//__HAL_RCC_PWR_CLK_ENABLE();
228232
// Enable write access to Backup domain
229233
//PWR->CR1 |= PWR_CR1_DBP;
@@ -293,7 +297,10 @@ STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) {
293297
// Exit Initialization mode
294298
hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
295299

296-
#if defined(MCU_SERIES_F7)
300+
#if defined(MCU_SERIES_L4)
301+
hrtc->Instance->OR &= (uint32_t)~RTC_OR_ALARMOUTTYPE;
302+
hrtc->Instance->OR |= (uint32_t)(hrtc->Init.OutPutType);
303+
#elif defined(MCU_SERIES_F7)
297304
hrtc->Instance->OR &= (uint32_t)~RTC_OR_ALARMTYPE;
298305
hrtc->Instance->OR |= (uint32_t)(hrtc->Init.OutPutType);
299306
#else
@@ -619,12 +626,21 @@ mp_obj_t pyb_rtc_wakeup(mp_uint_t n_args, const mp_obj_t *args) {
619626
RTC->WPR = 0xff;
620627

621628
// enable external interrupts on line 22
629+
#if defined(MCU_SERIES_L4)
630+
EXTI->IMR1 |= 1 << 22;
631+
EXTI->RTSR1 |= 1 << 22;
632+
#else
622633
EXTI->IMR |= 1 << 22;
623634
EXTI->RTSR |= 1 << 22;
635+
#endif
624636

625637
// clear interrupt flags
626638
RTC->ISR &= ~(1 << 10);
639+
#if defined(MCU_SERIES_L4)
640+
EXTI->PR1 = 1 << 22;
641+
#else
627642
EXTI->PR = 1 << 22;
643+
#endif
628644

629645
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, IRQ_PRI_RTC_WKUP, IRQ_SUBPRI_RTC_WKUP);
630646
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
@@ -638,7 +654,11 @@ mp_obj_t pyb_rtc_wakeup(mp_uint_t n_args, const mp_obj_t *args) {
638654
RTC->WPR = 0xff;
639655

640656
// disable external interrupts on line 22
657+
#if defined(MCU_SERIES_L4)
658+
EXTI->IMR1 &= ~(1 << 22);
659+
#else
641660
EXTI->IMR &= ~(1 << 22);
661+
#endif
642662
}
643663

644664
return mp_const_none;

0 commit comments

Comments
 (0)