[llvm-bugs] [Bug 50959] New: [AVR] Struct pointer is nil after a for loop which reads SPI
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jul 1 15:30:28 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50959
Bug ID: 50959
Summary: [AVR] Struct pointer is nil after a for loop which
reads SPI
Product: llgo
Version: unspecified
Hardware: Other
OS: other
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedbugs at nondot.org
Reporter: pwhittingslow at itba.edu.ar
CC: llvm-bugs at lists.llvm.org
Below is the link to the particular commit which implemented a workaround to
the bug:
https://github.com/soypat/enc28j60/commit/c7cbf9e0f0b06c53e394035f548f8b92b5f14997#diff-4f427d2b022907c552328e63f137561f6de92396d7a6e8f6c2ea1bcf0db52654L18
This issue was observed in an Arduino Mega 2560. Compiling with tinygo default
settings (opt=z i believe)
As mentioned in the comment in the commit, moving the declaration of the Packet
struct variable after the for loop fixed the issue. The program being tested
was the following (please take a look at the comments):
```
package main
import (
"machine"
"unsafe"
"github.com/soypat/net"
"github.com/soypat/enc28j60"
swtch "github.com/soypat/ether-swtch"
)
func main() {
println("start")
// SPI Chip select pin. Can be any Digital pin
var spiCS = machine.D53
// Inline declarations so not used as RAM
var (
MAC = net.HardwareAddr{0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xFF}
// MyIP = net.IP{192, 168, 1, 5} //static setup is the only one
available
)
machine.SPI0.Configure(machine.SPIConfig{Frequency: 8e6})
e := enc28j60.New(spiCS, machine.SPI0)
enc28j60.SDB = true
err := e.Init(MAC)
if err != nil {
println(err.Error())
}
c := swtch.NewTCPConn(e, nil, MAC)
// Decode calls e.NextPacket() which returns the Packet
// Packet's Read() method is called in Decode() which panics due to
accessing nil `ic` field
// Repeating these calls in main() does no reproduce the issue.
// I could not manage to get a MWE working.
err = c.Decode()
if err != nil {
println(err.Error())
}
}
```
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210701/373a5a25/attachment.html>
More information about the llvm-bugs
mailing list