adm34 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Ethernet software bug - SPI access & external interrupts #384

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use a library that has SPI access inside an ISR. 
2. Run the "Webserver" Ethernet example. 
3. Trigger the SPI interrupt on second device while webserver is running.

What is the expected output? What do you see instead?

The system hangs. The SPI data gets corrupted because both SPI buses are active 
at the same time. Since the SPI accesses aren't atomic, if an interrupt occurs 
before the SPI data register is read, its possible that the data will be 
changed after the ISR exits. There is also the issue of the Wiznet chip. If the 
chip is selected, then it does not properly release MISO which will corrupt any 
other device on the SPI. If an interrupt occurs while the Wiznet chip is being 
accessed, and there is an SPI access to a different chip, the access to the 
other chip will be corrupted because of a data collision on MISO.  

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

Arduino IDE version 0021. Windows XP. Custom board.  

Please provide any additional information below.

An example of a fix would be:

uint8_t W5100Class::read(uint16_t _addr)
{
  // DISABLE INTERRUPTS
  cli();

  setSS();
  SPI.transfer(0x0F);
  SPI.transfer(_addr >> 8);
  SPI.transfer(_addr & 0xFF);
  uint8_t _data = SPI.transfer(0);
  resetSS();

  // ENABLE INTERRUPTS
  sei();

  return _data;
}

Original issue reported on code.google.com by akiba.fr...@gmail.com on 21 Oct 2010 at 12:39