Fix linking to make initVariant() work #6809
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
The builder script compiles the sources of the variant folder to a
.a
library (env.BuildLibary()
) which is then linked into the final.elf
firmware in the order<variant .a> <core .a>
.This however prevents the
_weak
initVariant() function to be linked properly and be executed. This effectively means that the initVariant() code of some boards, which is very critical for e.g. powering up the I2C bus or Neopixels on some Adafruit boards is not executed, and so the same sketch code behaves differently between the Arduino IDE and PlatformIO. This was noticed in the I2C case in platformio/platform-espressif32#815.The Arduino IDE links the variant sources as an object file as can be seen in the verbose compile commands
With this fix applied, i.e., using
env.BuildSources()
instead ofenv.BuildLibrary()
, the PlatformIO linker process now uses object files tooAnd the
initVariant()
function is called again properly.Tests scenarios
I have tested my Pull Request on Arduino-esp32 core v2.0.3 with configuration
on a regular ESP32Dev board. The code
prints "0" before the fix, indicating that the initVariant code for this boardw as not executed since the Neopixel I2C power pin is still at LOW.
Prints "1" after the fix, indicating initVariant() is now properly called and the pin is now HIGH.
Related links
Actually resolves issue platformio/platform-espressif32#815.