[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


            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:

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 (


        swtch "github.com/soypat/ether-swtch"

func main() {
        // 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

        machine.SPI0.Configure(machine.SPIConfig{Frequency: 8e6})

        e := enc28j60.New(spiCS, machine.SPI0)
        enc28j60.SDB = true
        err := e.Init(MAC)
        if err != nil {

        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 {

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