Error: Previous declaration of 'Serial3' in OpenPLC 4.2 with the use of new STM32 3.0.0 board package

Hi,

I have this clone controller:

Which worked well before on OpenPLC 3.0 version using STM32 2.7.1 board package.

But recentlty I installed the new OpenPLC v4.2, also I installed STM32 3.0.0 board package using Arduino IDE board manager, which OpenPLC uses the same path to build its projects.

So when I wanted to compile a simple project, I got this error:

[27-08-26 13:40:59]: Arduino compile failed: Compilation failed with code 1


[27-08-26 13:40:59]: H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src\arduino.cpp:37:16: error: conflicting declaration 'arduino::HardwareSerial Serial3'


[27-08-26 13:40:59]:    37 | HardwareSerial Serial3(PC11_ALT1, PC_10_ALT1);                      //needed to use Serial3 for RS485 - also define PA14 as TxPin


[27-08-26 13:40:59]:       |                ^~~~~~~


[27-08-26 13:40:59]: In file included from C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/WSerial.h:5,


[27-08-26 13:40:59]:                  from C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/wiring.h:103,


[27-08-26 13:40:59]:                  from C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/Arduino.h:37,


[27-08-26 13:40:59]:                  from H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src\arduino.cpp:5:


[27-08-26 13:40:59]: C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/Serial.h:232:14: note: previous declaration as 'Uart Serial3'


[27-08-26 13:40:59]:   232 |  extern Uart Serial3;


[27-08-26 13:40:59]:       |              ^~~~~~~


[27-08-26 13:40:59]: Multiple libraries were found for "OpenPLCUserLib.h"


[27-08-26 13:40:59]:   Used: C:\Users\wopre\AppData\Local\Temp\openplc-precompile-23de1952502a-12584\OpenPLCUserLib


[27-08-26 13:40:59]:   Not used: H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src


[27-08-26 13:40:59]: Error during build: exit status 1


[27-08-26 13:40:59]: STruC++ compilation failed:


[27-08-26 13:40:59]: Compilation failed with code 1
H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src\arduino.cpp:37:16: error: conflicting declaration 'arduino::HardwareSerial Serial3'
   37 | HardwareSerial Serial3(PC11_ALT1, PC_10_ALT1);                      //needed to use Serial3 for RS485 - also define PA14 as TxPin
      |                ^~~~~~~
In file included from C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/WSerial.h:5,
                 from C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/wiring.h:103,
                 from C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/Arduino.h:37,
                 from H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src\arduino.cpp:5:
C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino/Serial.h:232:14: note: previous declaration as 'Uart Serial3'
  232 |  extern Uart Serial3;
      |              ^~~~~~~
Multiple libraries were found for "OpenPLCUserLib.h"
  Used: C:\Users\wopre\AppData\Local\Temp\openplc-precompile-23de1952502a-12584\OpenPLCUserLib
  Not used: H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src
Error during build: exit status 1


[27-08-26 13:40:59]: Arduino compilation failed


[27-08-26 13:40:59]: Stopping compilation process.


[27-08-26 13:40:59]: -------------------------------------------------------------------------------------------------------------

So, I have an error because `Serial3` is declared in STM32 3.0.0 core line 232 at:

C:\Users\wopre\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\3.0.0\cores\arduino\Serial.h

And then OpenPLC also declares it too during project build process at the start of file:

H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src\arduino.cpp

C:\Users\wopre\AppData\Local\Programs\open-plc-editor\resources\sources\hal\fx3u-14-WS3U.cpp

And also the project's build source folder:

H:\projects_electronics_programming\openPLC projects\openPLC 4.2 projects\build\WS3U-14Mx\src\arduino.cpp

And if I edit anything, OpenPLC overwrites it.

I tried to solve it with ChatGPT and Gemini but no luck :slight_smile:

try changing HardwareSerial to Uart, e.g.

Uart Serial3(PC11_ALT1, PC_10_ALT1);

I can't, because OpenPLC will overwrite any current build source files.

could you try in the main program before including header files etc

#define HardwareSerial Uart

with one of my STM32 programs this compiled OK

#define HardwareSerial Uart

HardwareSerial Serial2(PA3, PA2);

EDIT: try winding back to the STM32 2.x.x library?
e.g. when I installed STM32 2.12.0

HardwareSerial Serial2(PA3, PA2);

compiled OK

It's a ladder code in OpenPLC IDE, it's like this:

=

I can't embed any text code for a ladder code system.

it is using STM32 3.0.0
image

using the Arduino IDE Board Manager could you instal STM32 2.12.0?

and try building with that version of STM32?

Yeah but OpenPLC the new version v4.2 will remove any older packages of STM32, and install the new 3.0.0. That's why I'm stuck at this.

Just some thoughts. I have no experience with either STM boards or OpenPLC.

  1. From memory there was a topic in the last two weeks with a similar issue with the STM32 board package.
  2. If rolling back the STM32 package is not possible it might be possible to use an older version of OpenPLC that does not force the latest STM32 board package.
  3. If (2) is not an option, contact the OpenPLC people.

Yep, absolutely. The older OpenPLC worked, I shouldn't push it for now as the new release need some time to fix these issue.