Skip to content

Commit 01941c0

Browse files
committed
Fix up STM
Enable the Alarm IRQ earlier and correct bit clearing.
1 parent 9e34da4 commit 01941c0

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

ports/stm/common-hal/busio/SPI.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
178178
}
179179

180180
//handle typedef selection, errors
181-
if ( (self->sck != NULL && self->mosi != NULL && self->miso != NULL) ||
182-
(self->sck != NULL && self->mosi != NULL && miso == NULL) ||
183-
(self->sck != NULL && self->miso != NULL && mosi == NULL)) {
181+
if (self->sck != NULL && (self->mosi != NULL || self->miso != NULL)) {
184182
SPIx = mcu_spi_banks[self->sck->spi_index - 1];
185183
} else {
186184
if (spi_taken) {

ports/stm/common-hal/pulseio/PulseIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void pulsein_reset(void) {
117117
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu_pin_obj_t* pin,
118118
uint16_t maxlen, bool idle_state) {
119119
#if !(HAS_BASIC_TIM)
120-
mp_raise_NotImplementedError(translate("PulseOut not supported on this chip"));
120+
mp_raise_NotImplementedError(translate("PulseIn not supported on this chip"));
121121
#else
122122
// STM32 has one shared EXTI for each pin number, 0-15
123123
uint8_t p_num = pin->number;

ports/stm/supervisor/port.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ safe_mode_t port_init(void) {
7979

8080
HAL_RTC_Init(&_hrtc);
8181

82+
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
83+
8284
return NO_SAFE_MODE;
8385
}
8486

@@ -182,10 +184,12 @@ void RTC_WKUP_IRQHandler(void) {
182184
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&_hrtc, RTC_FLAG_WUTF);
183185
__HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
184186
}
185-
187+
volatile bool alarmed_already = false;
186188
void RTC_Alarm_IRQHandler(void) {
187-
RTC->ISR = ~RTC_FLAG_ALRAF;
189+
__HAL_RTC_ALARM_CLEAR_FLAG(&_hrtc, RTC_FLAG_ALRAF);
190+
__HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
188191
HAL_RTC_DeactivateAlarm(&_hrtc, RTC_ALARM_A);
192+
alarmed_already = true;
189193
}
190194

191195
// Enable 1/1024 second tick.
@@ -227,6 +231,7 @@ void port_interrupt_after_ticks(uint32_t ticks) {
227231
alarm.Alarm = RTC_ALARM_A;
228232

229233
HAL_RTC_SetAlarm_IT(&_hrtc, &alarm, RTC_FORMAT_BIN);
234+
alarmed_already = false;
230235
}
231236

232237
void port_sleep_until_interrupt(void) {
@@ -235,6 +240,9 @@ void port_sleep_until_interrupt(void) {
235240
__set_FPSCR(__get_FPSCR() & ~(0x9f));
236241
(void) __get_FPSCR();
237242
}
243+
if (alarmed_already) {
244+
return;
245+
}
238246
__WFI();
239247
}
240248

0 commit comments

Comments
 (0)