mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
machine: use larger SPI MAXCNT on nrf52833 and nrf52840
These chips have a larger upper limit for the DMA transfer than the nrf52832. For best performance, we should be splitting the transfer in as large blocks as possible on the given hardware.
This commit is contained in:
committed by
Ron Evans
parent
26ee3fb93e
commit
8a31ae14a0
@@ -69,3 +69,5 @@ const eraseBlockSizeValue = 4096
|
||||
func eraseBlockSize() int64 {
|
||||
return eraseBlockSizeValue
|
||||
}
|
||||
|
||||
const spiMaxBufferSize = 255 // from the datasheet: TXD.MAXCNT and RXD.MAXCNT
|
||||
|
||||
@@ -90,3 +90,5 @@ const eraseBlockSizeValue = 4096
|
||||
func eraseBlockSize() int64 {
|
||||
return eraseBlockSizeValue
|
||||
}
|
||||
|
||||
const spiMaxBufferSize = 0xffff // from the datasheet: TXD.MAXCNT and RXD.MAXCNT
|
||||
|
||||
@@ -108,3 +108,5 @@ const eraseBlockSizeValue = 4096
|
||||
func eraseBlockSize() int64 {
|
||||
return eraseBlockSizeValue
|
||||
}
|
||||
|
||||
const spiMaxBufferSize = 0xffff // from the datasheet: TXD.MAXCNT and RXD.MAXCNT
|
||||
|
||||
@@ -301,18 +301,16 @@ func (spi *SPI) Transfer(w byte) (byte, error) {
|
||||
// padded until they fit: if len(w) > len(r) the extra bytes received will be
|
||||
// dropped and if len(w) < len(r) extra 0 bytes will be sent.
|
||||
func (spi *SPI) Tx(w, r []byte) error {
|
||||
// Unfortunately the hardware (on the nrf52832) only supports up to 255
|
||||
// bytes in the buffers, so if either w or r is longer than that the
|
||||
// transfer needs to be broken up in pieces.
|
||||
// The nrf52840 supports far larger buffers however, which isn't yet
|
||||
// supported.
|
||||
// Unfortunately the hardware (on the nrf52832) only supports a limited
|
||||
// amount of bytes in the buffers (depending on the chip), so if either w or
|
||||
// r is longer than that the transfer needs to be broken up in pieces.
|
||||
for len(r) != 0 || len(w) != 0 {
|
||||
// Prepare the SPI transfer: set the DMA pointers and lengths.
|
||||
// read buffer
|
||||
nr := uint32(len(r))
|
||||
if nr > 0 {
|
||||
if nr > 255 {
|
||||
nr = 255
|
||||
if nr > spiMaxBufferSize {
|
||||
nr = spiMaxBufferSize
|
||||
}
|
||||
spi.Bus.RXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&r[0]))))
|
||||
r = r[nr:]
|
||||
@@ -322,8 +320,8 @@ func (spi *SPI) Tx(w, r []byte) error {
|
||||
// write buffer
|
||||
nw := uint32(len(w))
|
||||
if nw > 0 {
|
||||
if nw > 255 {
|
||||
nw = 255
|
||||
if nw > spiMaxBufferSize {
|
||||
nw = spiMaxBufferSize
|
||||
}
|
||||
spi.Bus.TXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&w[0]))))
|
||||
w = w[nw:]
|
||||
|
||||
Reference in New Issue
Block a user