aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPertti Erkkilä <[email protected]>2023-08-24 14:15:18 +0300
committerGitHub <[email protected]>2023-08-24 13:15:18 +0200
commit806498f099835492ba18e525b446e31a26d3dce1 (patch)
treea11c20ed02a256e72c7b768ff25550079618e605
parente3bc6da9e4d37c0cfc71a47ff30ed7274253bbc7 (diff)
downloadtinygo-806498f099835492ba18e525b446e31a26d3dce1.tar.gz
tinygo-806498f099835492ba18e525b446e31a26d3dce1.zip
nRF52: set SPI TX/RX lengths even data is empty. Fixes #3868 (#3877)
machine/hrf: Set SPI TX/RX lengths even data is empty. Fixes #3868
-rw-r--r--src/machine/machine_nrf52xxx.go31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/machine/machine_nrf52xxx.go b/src/machine/machine_nrf52xxx.go
index c4605d582..e35cb0201 100644
--- a/src/machine/machine_nrf52xxx.go
+++ b/src/machine/machine_nrf52xxx.go
@@ -288,24 +288,27 @@ func (spi SPI) Tx(w, r []byte) error {
// supported.
for len(r) != 0 || len(w) != 0 {
// Prepare the SPI transfer: set the DMA pointers and lengths.
- if len(r) != 0 {
- spi.Bus.RXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&r[0]))))
- n := uint32(len(r))
- if n > 255 {
- n = 255
+ // read buffer
+ nr := uint32(len(r))
+ if nr > 0 {
+ if nr > 255 {
+ nr = 255
}
- spi.Bus.RXD.MAXCNT.Set(n)
- r = r[n:]
+ spi.Bus.RXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&r[0]))))
+ r = r[nr:]
}
- if len(w) != 0 {
- spi.Bus.TXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&w[0]))))
- n := uint32(len(w))
- if n > 255 {
- n = 255
+ spi.Bus.RXD.MAXCNT.Set(nr)
+
+ // write buffer
+ nw := uint32(len(w))
+ if nw > 0 {
+ if nw > 255 {
+ nw = 255
}
- spi.Bus.TXD.MAXCNT.Set(n)
- w = w[n:]
+ spi.Bus.TXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&w[0]))))
+ w = w[nw:]
}
+ spi.Bus.TXD.MAXCNT.Set(nw)
// Do the transfer.
// Note: this can be improved by not waiting until the transfer is