Fix up STM

Enable the Alarm IRQ earlier and correct bit clearing.
This commit is contained in:
Scott Shawcroft 2020-04-08 14:41:57 -07:00
parent 9e34da44c3
commit 01941c027b
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
3 changed files with 12 additions and 6 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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();
}