Skip to content

nRF52xxx spi.TX and empty parameter causes invalid operation #3868

@perttierkkila

Description

@perttierkkila

When using empty parameter for spi.TX, previous TXD/RXD.MAXCNT values are not reseted and causes weird operations depending what was done before. Fixing is easy and tested to work with nRF52833.

File machine_nrf52xxx.go, line 291 and forward:

	if len(r) != 0 {
		spi.Bus.RXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&r[0]))))
		n := uint32(len(r))
		if n > 255 {
			n = 255
		}
		spi.Bus.RXD.MAXCNT.Set(n)
		r = r[n:]
	}

	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.TXD.MAXCNT.Set(n)
		w = w[n:]
	}

Change to:

	if len(r) != 0 {
		spi.Bus.RXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&r[0]))))
		n := uint32(len(r))
		if n > 255 {
			n = 255
		}
		spi.Bus.RXD.MAXCNT.Set(n)
		r = r[n:]
	} else {
		spi.Bus.RXD.MAXCNT.Set(0)
	}

	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.TXD.MAXCNT.Set(n)
		w = w[n:]
	} else {
		spi.Bus.TXD.MAXCNT.Set(0)
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions