Closed St007 closed 7 years ago
How do you set RH_PLATFORM
macro? Could you try lib_ignore option in platformio.ini
?
[env:myenv]
platfrorm =..
lib_ignore = SPI
Hi, Thank you for quick replay. In the file RadioHead.h (attached to my initial message) there several lines: `#if defined(AVR_ATtiny84) || defined(AVR_ATtiny85) || defined(AVR_ATtiny24) || defined(AVR_ATtiny44) || defined(AVR_ATtiny45) || defined(AVR_ATtinyX4) || defined(AVR_ATtinyX5) || defined(AVR_ATtiny2313) || defined(AVR_ATtiny4313) || defined(AVR_ATtinyX313)
and the platform.ini is as follow :
[env:digispark-tiny] platform = atmelavr framework = arduino board = digispark-tiny
Adding lib_ignore = SPI solves the problem, but I still can't understand the source of the problem (I spent a lot of hours to figure the problem) and if it is safe to use Platformio for next projects.
Could you define manually RH_PLATFORM_ATTINY
?
[env:...]
build_flags = -DRH_PLATFORM_ATTINY
I'll explain later all details...
If I remove lib_ignore = SPI and add this
[env:digispark-tiny]
build_flags = -DRH_PLATFORM_ATTINY
compilation fails with same error as initially (not defined SPI). However RadioHead.h has warnings in case if RH_PLATFORM_ATTINY is defined and these warnings are visible, so everything is ok, RH_PLATFORM_ATTINY is defined.
#ifdef RH_PLATFORM_ATTINY
#warning Arduino TinyCore does not support hardware SPI. Use software SPI instead.
#else
#include <SPI.h>
#define RH_HAVE_HARDWARE_SPI
#define RH_HAVE_SERIAL
#endif
But as I mentioned at the beginning, the SPI is included and compilation fails.
Please try pio run -t clean
and rebuild in verbose mode using pio run -v
. Do you this macro in CLI?
Ok, let's me explain in details. We introduced Library Dependency Finder (LDF) in PlatformIO 3.0. The role of this machinery is to automatically find project dependencies. LDF analyzes #include
from source files and builds internal dependency map "on-the-fly". If you don't like it, you can turn-off this feature. See Dependency Finder Mode.
In 99% LDF works awesome!!! Super fast and reliable. Why is it cool? Because it doesn't depend on external GCC tools. We don't call gcc -E
to fetch dependency for the one file. For example, Arduino IDE does it. This is expensive operation... Arduino IDE can use gcc -E
because it doesn't provide project management and normal library/dependency manager. In the most cases, newbies use 1 file(sketch) as a project... PlatformIO developers have big projects with dozens of files and dozens of library dependencies. Using gcc -E
will increase build process in 10x time... Currently, PlatformIO Build System is No.1 in comparison with Arduino IDE, Make or CMake 3-rd party build systems for embedded. PlatformIO needs 1-3sec to build the whole project with the framework, where others need 15 sec and more for the same project.
Of course, this super optimization has a side effect. As I've told before, we don't call gcc -E
per each file and use Python implementation that interprets (emulates) C/C++ Preprocessor conditional syntax (#ifdef, if, defined, else, and elif). The issue here, that we don't know about internal(built-in) macros in compiler. These macors such as __AVR_ATtinyX313__
and etc are not visible for our Python-based build system. The solution here is to hint our build system about internal macros.
Finally, as LDF doesn't see __AVR_ATtiny84__
and etc, the RH_PLATFORM_ATTINY
is not defined on the pre-processing stage. That is why LDF sees #include <SPI.h>
.
P.S: Try to define some marcos in platformio.ini
and check in project source files. In this case, LDF will work correctly.
Thank you very much, this clearly explains the behavior I was stuck with.
When I tried to compile project for Digispark (Attiny85) it fails with errors about not defined SPI registers. It is true, Attiny85 does not have SPI, but somehow platformio decides took it and create folder SPI in .pioenvs
I found why this happens ( but it must not happen ! ) . The bug that there is some includes of SPI.h but they are not active (paced in #ifdef section). Platformio includes all that can be found also if it actually not included after processing macros. Temporary solved by manually deleting of all includes of SPI.h and only then project was compiled. Here is defined RH_PLATFORM_ATTINY and no SPI definitions must be included, but platformio thinks in different way. (Forgive me I'm saying Platformio, for end-user it is like Platformio bug)
RadioHead.h