arduino / arduino/ArduinoCore-megaavr

SPI default configuration fails

Open
#106 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
111
Forks
65
PR merge metrics
No merged PRs in 30d

Description

The SPI configuration is using a SPISettings class from ArduinoCore-API, which is converted to a temporary object of type SPISettingsMegaAVR .
This conversion in https://github.com/arduino/ArduinoCore-megaavr/blob/5717c2a3ac8ecc6e5f382715b7f6225e1c809007/libraries/SPI/src/SPI.h#L179-L181 is using this constructor:
https://github.com/arduino/ArduinoCore-megaavr/blob/5717c2a3ac8ecc6e5f382715b7f6225e1c809007/libraries/SPI/src/SPI.h#L69
There the SPISettingsMegaAVR object is created on the stack, and then destroyed. It does not initialize the SPISettingsMegaAVR that is used in the config() call.
This problem is hidden because it works by sudden and is compiler version dependant. There is a discussion and some test code to reproduce the problem in https://forum.arduino.cc/t/houston-spi-has-a-problem-with-avr-gcc-11-1-0
The assumption that this is a compiler problem was false, its simply an uninitialized SPISettingsMegaAVR object.

A solution would be to use constructor delegation as explained here:
https://www.geeksforgeeks.org/constructor-delegation-c/

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in libraries/SPI/src/SPI.h at the constructor around lines 69 and 179-181, then run the reproduction discussed in the linked Arduino forum thread. Verify that the SPISettings conversion initializes the object used by config() and that the default SPI configuration works across compiler versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.