Closed PaulStoffregen closed 10 years ago
thank you paul!!!
You're right I should have put packed in there. I do this on ARM all the time to avoid alignment issues, especially on the M0 which can't do unaligned access, but didn't cross my mind to worry about it on Arduino since I did all the testing on an AVR.
If this library is ever used on other faster (non-ARM) processors, the same timing problem will likely come up. Hopefully that comment in the code will help.
I didn't put SPI transactions into this pull request. I wanted to keep it simple & only about ARM compatibility.
At the time, nobody had complained about conflicts with another library, so I wondered when/if the SPI interrupt conflict would turn up? Turns out, not long at all...
http://forum.pjrc.com/threads/27069-Adafruit_nrf8001-and-SDFat-problem-on-teensy-3-1
I've already written a patch. https://github.com/PaulStoffregen/Adafruit_nRF8001/commit/842aa5c9f04af0f9e4c7c9a54d26bb9a311a7683
Before submitting this, I want to do some more rigorous testing, watching the waveforms on my oscilloscope, and of course it'll be nice to hear from that customer if the patch works on their project.
Anyway, just want to let you know this is coming soon. So far, Arduino 1.5.8 and Teensyduino 1.20 are the only releases with SPI transactions. Thanksfully, the Arduino devs have realized how important this is. Arduino 1.0.7 is supposed to coming later this month, mainly to bring SPI transaction support. :)
These changes fix problems on 32 bit ARM. I tested with Teensy 3.1, Arduino Uno, and Teensy 2.0. One customer also verified it works. :-)
The packed attribute is needed on all the event structs. The library collects incoming bytes into a buffer, then casts a pointer to the buffer to these structs. On 8 bit AVR, all structs are automatically packed, so this has no effect on AVR. On 32 bit platforms, the compiler defaults to aligning 16 and 32 bit data types to 2 and 4 byte boundaries. The packed attribute is needed to make the code work the same as AVR.
The other minor change is 2 delays added. They're only compiled for ARM chips. I didn't want to take any chance of altering how the library works on AVR.