diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2020-04-08 14:41:57 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2020-04-08 14:41:57 -0700 |
| commit | 01941c027b7391897db90fc0a8c1155ca4e37c47 (patch) | |
| tree | 49ccbbbeef135cc43b6b5dbbd79bfb1125181c56 | |
| parent | 9e34da44c37ccb592a54c325832528fe3b0389bf (diff) | |
Fix up STM
Enable the Alarm IRQ earlier and correct bit clearing.
| -rw-r--r-- | ports/stm/common-hal/busio/SPI.c | 4 | ||||
| -rw-r--r-- | ports/stm/common-hal/pulseio/PulseIn.c | 2 | ||||
| -rw-r--r-- | ports/stm/supervisor/port.c | 12 |
3 files changed, 12 insertions, 6 deletions
diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index 7e25e0a57..a7a801170 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -178,9 +178,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, } //handle typedef selection, errors - if ( (self->sck != NULL && self->mosi != NULL && self->miso != NULL) || - (self->sck != NULL && self->mosi != NULL && miso == NULL) || - (self->sck != NULL && self->miso != NULL && mosi == NULL)) { + if (self->sck != NULL && (self->mosi != NULL || self->miso != NULL)) { SPIx = mcu_spi_banks[self->sck->spi_index - 1]; } else { if (spi_taken) { diff --git a/ports/stm/common-hal/pulseio/PulseIn.c b/ports/stm/common-hal/pulseio/PulseIn.c index c44d03cf0..2536ae73b 100644 --- a/ports/stm/common-hal/pulseio/PulseIn.c +++ b/ports/stm/common-hal/pulseio/PulseIn.c @@ -117,7 +117,7 @@ void pulsein_reset(void) { void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu_pin_obj_t* pin, uint16_t maxlen, bool idle_state) { #if !(HAS_BASIC_TIM) - mp_raise_NotImplementedError(translate("PulseOut not supported on this chip")); + mp_raise_NotImplementedError(translate("PulseIn not supported on this chip")); #else // STM32 has one shared EXTI for each pin number, 0-15 uint8_t p_num = pin->number; diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c index 2bc247926..75ee71f89 100644 --- a/ports/stm/supervisor/port.c +++ b/ports/stm/supervisor/port.c @@ -79,6 +79,8 @@ safe_mode_t port_init(void) { HAL_RTC_Init(&_hrtc); + HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn); + return NO_SAFE_MODE; } @@ -182,10 +184,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) { - RTC->ISR = ~RTC_FLAG_ALRAF; + __HAL_RTC_ALARM_CLEAR_FLAG(&_hrtc, RTC_FLAG_ALRAF); + __HAL_RTC_ALARM_EXTI_CLEAR_FLAG(); HAL_RTC_DeactivateAlarm(&_hrtc, RTC_ALARM_A); + alarmed_already = true; } // Enable 1/1024 second tick. @@ -227,6 +231,7 @@ void port_interrupt_after_ticks(uint32_t ticks) { alarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&_hrtc, &alarm, RTC_FORMAT_BIN); + alarmed_already = false; } void port_sleep_until_interrupt(void) { @@ -235,6 +240,9 @@ void port_sleep_until_interrupt(void) { __set_FPSCR(__get_FPSCR() & ~(0x9f)); (void) __get_FPSCR(); } + if (alarmed_already) { + return; + } __WFI(); } |
