Stuck in SPI data transfer

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
nplayle
 
Posts: 1
Joined: Tue Mar 21, 2023 6:14 pm

Stuck in SPI data transfer

Post by nplayle »

Hi,

I'm trying to develop a reasonably simple program using a feather M0 (specifically the Adafruit Feather M0 RFM69 Packet Radio: https://learn.adafruit.com/adafruit-fea ... cket-radio).

I'm running into an issue with the program crashing after somewhere between a few seconds to a few minutes. At first, I thought it was a memory leak, but now I'm not so sure. I hooked up a jlink to the device and found the following:

The issue is that the code seems to be getting stuck in the transferDataSpi function, the call stack is shown below.
call_stack.PNG
call_stack.PNG (13.33 KiB) Viewed 34 times
The code is stuck at: `while(sercom->SPI.INTFLAG.bit.RXC == 0);`

The carrier board consists of an ADC, a shift register, and the RFM radio on the SPI bus. In these particular crashes, the feather is not connected to the carrier board. The ADC and shift register provide no feedback or IRQs to the chip, so the FW has no idea they aren't present.

The code so far seems to be getting stuck in the transferDataSpi function:

Code: Select all

uint8_t SERCOM::transferDataSPI(uint8_t data)
{
  sercom->SPI.DATA.bit.DATA = data; // Writing data into Data register

  while(sercom->SPI.INTFLAG.bit.RXC == 0); // Waiting Complete Reception

  return sercom->SPI.DATA.bit.DATA;  // Reading data
}
I have caught it once in the readAdc function and once in the read_digital_ins function I have, both of which call SPI.transfer.

It's not really clear to me how the code could be getting stuck here since this is just a busy wait? Has anyone seen this before?
I'm guessing it might be a race condition with the RFM69 radio because it is able to use IRQs, but it's not clear to me how this is getting stuck...
Anyways, continuing to debug this, and will report back any findings.

Thanks!

edit:
Since i'm sure it will be asked, my calls to SPI.transfer are wrapped in begin/end transaction. as an example, this is the ADC read function:

Code: Select all

uint16_t wb_hardware::read_adc128(uint8_t channel)
{
    uint16_t rxData;

    //SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE2));
    SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE3));

    digitalWrite(HW_ADC_CS_N, LOW);

     uint8_t high = SPI.transfer(channel << 3U);
     uint8_t low = SPI.transfer(0x00);

    digitalWrite(HW_ADC_CS_N, HIGH);

    rxData = (high << 8U) | low;

    SPI.endTransaction();

    return rxData;
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”