Skip to content

Commit 3bb994d

Browse files
authored
Allow interrupts in stm32f103xx (#1466)
machine/stm32f103xx: allow interrupts in stm32f103xx
1 parent b3bd891 commit 3bb994d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/runtime/runtime_stm32f103xx.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ func sleepTicks(d timeUnit) {
120120
for d != 0 {
121121
ticks() // update timestamp
122122
ticks := uint32(d) // current scaling only supports 100 usec to 6553 msec
123-
timerSleep(ticks)
123+
if !timerSleep(ticks) {
124+
return
125+
}
124126
d -= timeUnit(ticks)
125127
}
126128
}
@@ -141,7 +143,8 @@ func ticks() timeUnit {
141143
}
142144

143145
// ticks are in microseconds
144-
func timerSleep(ticks uint32) {
146+
// returns false if an interrupt occured
147+
func timerSleep(ticks uint32) bool {
145148
timerWakeup.Set(0)
146149

147150
// STM32 timer update event period is calculated as follows:
@@ -188,10 +191,19 @@ func timerSleep(ticks uint32) {
188191
// Enable the timer.
189192
stm32.TIM3.CR1.SetBits(stm32.TIM_CR1_CEN)
190193

191-
// wait till timer wakes up
192-
for timerWakeup.Get() == 0 {
193-
arm.Asm("wfi")
194+
wait:
195+
arm.Asm("wfi")
196+
if timerWakeup.Get() != 0 {
197+
return true
194198
}
199+
200+
if hasScheduler {
201+
return false
202+
} else {
203+
// keep looping until the routine exits or is interrupted
204+
goto wait
205+
}
206+
195207
}
196208

197209
func handleTIM3(interrupt.Interrupt) {

0 commit comments

Comments
 (0)