bluzDK / bluzDK-firmware

Firmware for the bluz development kit
Other
15 stars 15 forks source link

SPI Peripheral fails to initialize if SPI.begin is called outside setup.loop #39

Closed eely22 closed 7 years ago

eely22 commented 7 years ago

If SPI.begin is called in a C++ constructor outside of a function in the user app, it will fail to properly initialize that peripheral.

The example is to use the OPCN2 library in the Particle Web IDE. The example app calls the constructor above setup() and this calls SPI.begin. However, subsequent calls to try and use SPI will fail

eely22 commented 7 years ago

The issue had to do with the fix to issue #35. We added code there to turn off SPI as part of the system init. The problem was, this happened after user constructors in the user app were called. So essentially, SPI was enabled from the bootloader, then re-enabled by the user app, then disabled by the fix for issue #35.

The solution here was to make sure we disable SPI from the bootloader before the user constructors are called