PIO&VSCode compilation failed but Arduino IDE work

Hi!
I use:
latest platform io on
esp8266
software serial is 5.3.0
When I compile clean project with softwareSerial library - I have an error. and I don’t understand why. But on Arduino IDE it compiled.
The author of the library refers to the fact that the library passed the tests and works. Unfortunately he does not offer any help.

My platfromio.ini

>     [env:esp12e]
>     platform = espressif8266
>     board = esp12e
>     framework = arduino
> 
>     lib_deps =
>          # Using library Id
>          168
>          EspSoftwareSerial@5.3.0

And error:

    `In file included from .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/SoftwareSerial.h:27:0,
                     from .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp:23:
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: error: expected ';' at end of member declaration
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:27: error: ISO C++ forbids declaration of 'pushpeek' with no type [-fpermissive]
         T& IRAM_ATTR pushpeek()
                               ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:157:10: error: expected ';' at end of member declaration
         bool IRAM_ATTR push();
              ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:157:10: error: redeclaration of 'bool circular_queue<T>::IRAM_ATTR'
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: note: previous declaration 'T& circular_queue<T>::IRAM_ATTR'
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:157:25: error: ISO C++ forbids declaration of 'push' with no type [-fpermissive]
         bool IRAM_ATTR push();
                             ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:164:10: error: expected ';' at end of member declaration
         bool IRAM_ATTR push(T&& val);
              ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:164:10: error: redeclaration of 'bool circular_queue<T>::IRAM_ATTR'
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: note: previous declaration 'T& circular_queue<T>::IRAM_ATTR'
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:164:32: error: ISO C++ forbids declaration of 'push' with no type [-fpermissive]
         bool IRAM_ATTR push(T&& val);
                                    ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:171:10: error: expected ';' at end of member declaration
         bool IRAM_ATTR push(const T& val)
              ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:171:10: error: redeclaration of 'bool circular_queue<T>::IRAM_ATTR'
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: note: previous declaration 'T& circular_queue<T>::IRAM_ATTR'
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:171:37: error: ISO C++ forbids declaration of 'push' with no type [-fpermissive]
         bool IRAM_ATTR push(const T& val)
                                         ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:253:16: error: expected initializer before 'circular_queue'
     bool IRAM_ATTR circular_queue<T>::push()
                    ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:268:16: error: expected initializer before 'circular_queue'
     bool IRAM_ATTR circular_queue<T>::push(T&& val)
                    ^
    In file included from .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/SoftwareSerial.h:27:0,
                     from src\main.cpp:6:
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: error: expected ';' at end of member declaration
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:27: error: ISO C++ forbids declaration of 'pushpeek' with no type [-fpermissive]
         T& IRAM_ATTR pushpeek()
                               ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:157:10: error: expected ';' at end of member declaration
         bool IRAM_ATTR push();
              ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:157:10: error: redeclaration of 'bool circular_queue<T>::IRAM_ATTR'
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: note: previous declaration 'T& circular_queue<T>::IRAM_ATTR'
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:157:25: error: ISO C++ forbids declaration of 'push' with no type [-fpermissive]
         bool IRAM_ATTR push();
                             ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:164:10: error: expected ';' at end of member declaration
         bool IRAM_ATTR push(T&& val);
              ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:164:10: error: redeclaration of 'bool circular_queue<T>::IRAM_ATTR'
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: note: previous declaration 'T& circular_queue<T>::IRAM_ATTR'
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:164:32: error: ISO C++ forbids declaration of 'push' with no type [-fpermissive]
         bool IRAM_ATTR push(T&& val);
                                    ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:171:10: error: expected ';' at end of member declaration
         bool IRAM_ATTR push(const T& val)
              ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:171:10: error: redeclaration of 'bool circular_queue<T>::IRAM_ATTR'
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:145:8: note: previous declaration 'T& circular_queue<T>::IRAM_ATTR'
         T& IRAM_ATTR pushpeek()
            ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:171:37: error: ISO C++ forbids declaration of 'push' with no type [-fpermissive]
         bool IRAM_ATTR push(const T& val)
                                         ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:253:16: error: expected initializer before 'circular_queue'
     bool IRAM_ATTR circular_queue<T>::push()
                    ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:268:16: error: expected initializer before 'circular_queue'
     bool IRAM_ATTR circular_queue<T>::push(T&& val)
                    ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp: In member function 'void SoftwareSerial::enableRx(bool)':
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp:140:121: error: 'attachInterruptArg' was not declared in this scope
                 attachInterruptArg(digitalPinToInterrupt(m_rxPin), reinterpret_cast<void (*)(void*)>(rxBitISR), this, CHANGE);

     ^
    In file included from .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/SoftwareSerial.h:27:0,
                     from .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp:23:
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h: In instantiation of 'circular_queue<T>::circular_queue(size_t) [with T = unsigned char; size_t = unsigned int]':
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp:58:122:   required from here
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:62:5: error: uninitialized reference member 'circular_queue<unsigned char>::IRAM_ATTR' [-fpermissive]
         circular_queue(const size_t capacity) : m_bufSize(capacity + 1), m_buffer(new T[m_bufSize])
         ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h: In instantiation of 'circular_queue<T>::circular_queue(size_t) [with T = unsigned int; size_t = unsigned int]':
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp:60:170:   required from here
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:62:5: error: uninitialized reference member 'circular_queue<unsigned int>::IRAM_ATTR' [-fpermissive]
    src\main.cpp:96:33: error: no matching function for call to 'SoftwareSerial::SoftwareSerial(int, int, bool, int)'
     SoftwareSerial ss(5,10,false,128);
                                     ^
    src\main.cpp:96:33: note: candidate is:
    In file included from src\main.cpp:6:0:
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/SoftwareSerial.h:47:5: note: SoftwareSerial::SoftwareSerial()
         SoftwareSerial();
         ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/SoftwareSerial.h:47:5: note:   candidate expects 0 arguments, 4 provided
    src\main.cpp: In function 'void setup()':
    src\main.cpp:101:16: error: no matching function for call to 'SoftwareSerial::begin(int)'
       ss.begin(9600);
                    ^
    src\main.cpp:101:16: note: candidate is:
    In file included from src\main.cpp:6:0:
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/SoftwareSerial.h:51:10: note: void SoftwareSerial::begin(uint32_t, int8_t, int8_t, SoftwareSerialConfig, bool, int, int)
         void begin(uint32_t baud, int8_t rxPin, int8_t txPin = -1,
              ^
    .pio\libdeps\esp12e\EspSoftwareSerial_ID168\src/SoftwareSerial.h:51:10: note:   candidate expects 7 arguments, 1 provided
    *** [.pio\build\esp12e\src\main.cpp.o] Error 1
    *** [.pio\build\esp12e\lib435\EspSoftwareSerial_ID168\SoftwareSerial.cpp.o] Error 1`
    ```

The compilation fails because the IRAM_ATTR macro is not defined. This macro has been introduced recently in the ESP8266 core for Arduino (see master branch) but is not yet part of any officially released version (see latest version 2.5.2).

As a consequence, it’s neither part of the Arduino IDE nor PlatformIO. Both uses version 2.5.2 of the Arduino core.

If I compile the below simple program in the Arduino IDE, it takes SoftwareSerial from the Arduino core, even if I install the EspSoftwareSerial library:

#include <Arduino.h>
#include <SoftwareSerial.h>

void setup() { }

void loop() { }

It even warns me:

Multiple libraries were found for "SoftwareSerial.h"
 Used: /Users/me/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/libraries/SoftwareSerial
 Not used: /Users/me/Documents/Arduino/libraries/EspSoftwareSerial

So my conclusion is:

  • The latest version of EspSoftwareSerial is not compatible with any officially released ESP8266 Arduino core.
  • In the Arduino IDE, you are likely using the built-in library instead of EspSoftwareSerial.

The easiest approach to fix it is:

  • Remove EspSoftwareSerial@5.3.0 from your platformio.ini
  • Delete .pio folder in your project folder
  • Compile again
2 Likes

The usage of IRAM_ATTR and the circular buffers was introduced in version 5.2.0 of the EspSoftwareSerial library (which is only two weeks new now) … so you either need to:

a) use the version of the library shipped with the current 2.5.2 release version of the ESP8266 core (which is 5.0.4, and does not need to be listed in lib_deps, but note you need to look at the right version of the example code as 5.2.0 also introduces breaking changes to the constructors - hence the version bump)

- OR -

b) use the latest ESP8266 Arduino core as it is on github right now… by changing your platformio.ini to the follow (note: this is effectively bleeding edge, as this is not the latest ‘well-tested release version’ but the current development code). So I don’t recommend it unless you really need the newer features of EspSoftwareSerial, and are willing to put up with any bugs in the ESP8266 Arduino core that haven’t been squashed or identified yet.

[env:esp12e]
platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
board = esp12e
framework = arduino
lib_deps =
  EspSoftwareSerial@5.3.1
2 Likes

Yes! Really it work!!! Thank you!