Author Topic: SPIFlash.initialise() hangs intermittently running on moteino  (Read 786 times)

kevin

  • NewMember
  • *
  • Posts: 1
SPIFlash.initialise() hangs intermittently running on moteino
« on: August 03, 2017, 09:18:31 AM »
Hi,

I recently bought some moteinos for a home automation system I am building.  Every now and then a moteinoe would hang, typically when initialising the flash device.

I noticed a few threads discussing this with several suggesting placing a pull down resistor on MISO.  While this works I think the actual root cause is in the SPIFlash library.

Specifically: in the call tree: initialise()->wakeup()->command()->busy()  the flash wakeup command is held up waiting for a non-busy status from a device which is already asleep.  This behaviour is consistent with section 8.2.19 of the Winbond w25x40 data sheet (i.e. ignoring all but Release from Power Down, including status requests).

To fix this I added the following check to the SPIFlash::command() (~line 183):

  // Check for the wakeup command to avoid a deadlock trying to
  // read the status from a sleeping device.
  if (cmd != SPIFLASH_WAKE)

      while(busy());
  select();




« Last Edit: August 04, 2017, 10:56:37 AM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6605
  • Country: us
    • LowPowerLab
Re: SPIFlash.initialise() hangs intermittently running on moteino
« Reply #1 on: August 04, 2017, 11:30:16 AM »
Very good point.
After a flash.sleep() any other command is ignored by the chip so it would lock up the code if anyone would call a command other than flash.wakeup() - in our case this calls while(busy()) which uses getstatus which gets ignored and the command can hang.
I will add this to the code base, thanks for your contribution!

kni

  • NewMember
  • *
  • Posts: 27
  • Country: us
  • The Knight who says Ni
Re: SPIFlash.initialise() hangs intermittently running on moteino
« Reply #2 on: October 12, 2017, 12:42:44 PM »
Bingo.
I think this resolves an intermittent issue I was experiencing with moteinos never waking from sleep.

Since my moteinos in question were attaching interrupts, I kept focusing on my interrupt logic.... somehow I thought the moteino was going to sleep with interrupts disabled. It turns out that was not the issue. Instead, calling flash.sleep, when the flash chip was already asleep, was the root cause of the problem. Mystery solved. Thank you.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6605
  • Country: us
    • LowPowerLab
Re: SPIFlash.initialise() hangs intermittently running on moteino
« Reply #3 on: October 13, 2017, 11:18:59 AM »
kni,
Appreciate your feedback. If you had this in another thread please post an update there and a link to this for the solution.
Thanks!