aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2020-06-08 16:25:31 +0200
committerRon Evans <[email protected]>2020-06-08 19:54:41 +0200
commit169d5f17b879a05145ce47ea4fb4af898b23b9d8 (patch)
tree54d35e7817c938557712c6da7c5eec622caf4668 /src
parent9ed5eae6a939541b73dfcf2786cee3188ec6b125 (diff)
downloadtinygo-169d5f17b879a05145ce47ea4fb4af898b23b9d8.tar.gz
tinygo-169d5f17b879a05145ce47ea4fb4af898b23b9d8.zip
nrf: fix bug in SPI.Tx
There was what appears to be a race condition in the Tx function. While it would work fine in many cases, when there were interrupts (such as when using BLE), the function would just hang waiting for `EVENTS_READY` to arrive. I think what was happening was that the `spi.Bus.RXD.Get()` would start the next transfer, which would complete (and generate an event) before `EVENTS_READY` was reset to 0. The fix is easy: clear `EVENTS_READY` before doing something that can trigger an event. I believe I've seen this bug before on the PineTime but I couldn't find the issue back then.
Diffstat (limited to 'src')
-rw-r--r--src/machine/machine_nrf.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go
index 382dd05c2..3d65ad578 100644
--- a/src/machine/machine_nrf.go
+++ b/src/machine/machine_nrf.go
@@ -443,13 +443,13 @@ func (spi SPI) Tx(w, r []byte) error {
spi.Bus.TXD.Set(uint32(b))
for spi.Bus.EVENTS_READY.Get() == 0 {
}
- _ = spi.Bus.RXD.Get()
spi.Bus.EVENTS_READY.Set(0)
+ _ = spi.Bus.RXD.Get()
}
for spi.Bus.EVENTS_READY.Get() == 0 {
}
- _ = spi.Bus.RXD.Get()
spi.Bus.EVENTS_READY.Set(0)
+ _ = spi.Bus.RXD.Get()
default:
// write/read