Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
perttierkkila opened this issue Aug 14, 2023 · 1 comment
Closed

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

perttierkkila opened this issue Aug 14, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@perttierkkila
Copy link
Contributor

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)
	}
@deadprogram deadprogram added the bug Something isn't working label Aug 14, 2023
@deadprogram
Copy link
Member

@perttierkkila thanks for the report. Would you like to submit a PR with fix?

perttierkkila pushed a commit to perttierkkila/tinygo that referenced this issue Aug 21, 2023
@deadprogram deadprogram added the next-release Will be part of next release label Aug 24, 2023
@deadprogram deadprogram removed the next-release Will be part of next release label Aug 26, 2023
deadprogram pushed a commit that referenced this issue Sep 17, 2023
machine/hrf: Set SPI TX/RX lengths even data is empty. Fixes #3868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants