summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-04-22 11:10:51 -0700
committerScott Shawcroft <scott@tannewt.org>2020-04-22 11:10:51 -0700
commitb277944cf0b7e35b6c64d668c55bbf05371fb62f (patch)
tree4b7921e4f0b63bb4da44355de3e71f1250a340cb
parentdcb0e50f040c4213a7591253cb3a0bb4ea9a178d (diff)
Fix STM so it matches the correct RTC fields.
-rw-r--r--ports/stm/boards/feather_stm32f405_express/mpconfigboard.h2
-rw-r--r--ports/stm/supervisor/port.c18
2 files changed, 13 insertions, 7 deletions
diff --git a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h
index 59c48f88a..e002bbed1 100644
--- a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h
+++ b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h
@@ -36,7 +36,7 @@
#define BOARD_OSC_DIV (12)
-#define BOARD_HAS_LOW_SPEED_CRYSTAL (0)
+#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
// On-board flash
#define SPI_FLASH_MOSI_PIN (&pin_PB05)
diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c
index ab8cb0be2..779348c02 100644
--- a/ports/stm/supervisor/port.c
+++ b/ports/stm/supervisor/port.c
@@ -321,7 +321,8 @@ uint64_t port_get_raw_ticks(uint8_t* subticks) {
*subticks = subseconds % 32;
}
- return ((uint64_t) 1024) * (seconds_to_date + seconds_to_minute + seconds) + subseconds / 32;
+ uint64_t raw_ticks = ((uint64_t) 1024) * (seconds_to_date + seconds_to_minute + seconds) + subseconds / 32;
+ return raw_ticks;
}
void RTC_WKUP_IRQHandler(void) {
@@ -329,11 +330,12 @@ void RTC_WKUP_IRQHandler(void) {
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&_hrtc, RTC_FLAG_WUTF);
__HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
}
+
volatile bool alarmed_already = false;
void RTC_Alarm_IRQHandler(void) {
- __HAL_RTC_ALARM_CLEAR_FLAG(&_hrtc, RTC_FLAG_ALRAF);
- __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
HAL_RTC_DeactivateAlarm(&_hrtc, RTC_ALARM_A);
+ __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
+ __HAL_RTC_ALARM_CLEAR_FLAG(&_hrtc, RTC_FLAG_ALRAF);
alarmed_already = true;
}
@@ -362,15 +364,19 @@ void port_interrupt_after_ticks(uint32_t ticks) {
alarm.AlarmTime.Minutes = tm.tm_min;
alarm.AlarmTime.Seconds = tm.tm_sec;
alarm.AlarmDateWeekDay = tm.tm_mday;
- alarm.AlarmMask = RTC_ALARMMASK_ALL;
- } else {
+ // Masking here means that the value is ignored so we set none.
alarm.AlarmMask = RTC_ALARMMASK_NONE;
+ } else {
+ // Masking here means that the value is ignored so we set them all. Only the subseconds
+ // value matters.
+ alarm.AlarmMask = RTC_ALARMMASK_ALL;
}
alarm.AlarmTime.SubSeconds = RTC_CLOCK_FREQUENCY -
- ((raw_ticks % (1024)) * 32);
+ ((raw_ticks % 1024) * 32);
alarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
alarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_SET;
+ // Masking here means that the bits are ignored so we set none of them.
alarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
alarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
alarm.Alarm = RTC_ALARM_A;