PlatformIO Community

Arduino example fails to build, stm32_def.h: No such file or directory

Hello

I’m having trouble using a library from the registry: AsyncMqtt_Generic for the portenta_H7_m7 board. The author has provided examples and and a platformio.ini file, but even though they do compile in the Arduino IDE, they do not compile in Platform IO. I have reached out to the author, and he sugested this forum.

The problem seems to be wrong/missing dependencies, the first error I get is a
fatal error: stm32_def.h: No such file or directory.

This goes away if I add board_build.core = maple to the ini file, but this results in errors like:
fatal error: Udp.h: No such file or directory
fatal error: Arduino.h: No such file or directory
fatal error: IPAddress.h: No such file or directory
… and also in the C/C++ configurations:
Cannot find: C:/Users/Marius/.platformio/packages/framework-arduino-mbed/cores/maple
I have a feeling that this is related to the package Arduino_Core_STM32 not being correctly installed, but I can’t figure out how to install this…

Any tips on how I should proceed to fix these issues?

My current platformio.ini configuration:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
lib_compat_mode = strict
lib_deps =
    me-no-dev/AsyncTCP@>=1.1.1
    h ttps://github.com/khoih-prog/STM32AsyncTCP.git
    stm32duino/STM32duino LwIP@>=2.1.2
    stm32duino/STM32Ethernet@^1.3.0
    khoih-prog/ESPAsync_WiFiManager@>=1.12.2
    khoih-prog/Portenta_H7_AsyncTCP@>=1.3.0
    khoih-prog/Teensy41_AsyncTCP@>=1.0.0
    lorol/LittleFS_esp32@>=1.0.6
    khoih-prog/WebServer_WT32_ETH01@>=1.4.1
    khoih-prog/AsyncTCP_SSL@>=1.2.0
    khoih-prog/AsyncMQTT_Generic@^1.5.0

Oof, there is some weirdness going on there. I had to fix two library.json errors in the Portenta H7 AsyncTCP library (Commits · maxgerhardt/Portenta_H7_AsyncTCP · GitHub) and ignored a bunch of non-fitting libraries. PlatformIO’s library dependency finder isn’t yet the best for these extreme cases.

You can use

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
lib_deps =
   khoih-prog/AsyncMQTT_Generic@^1.5.0
   Portenta_H7_AsyncTCP=https://github.com/maxgerhardt/Portenta_H7_AsyncTCP/archive/refs/heads/withdeps.zip
   Ethernet
   SocketWrapper
;lib_compat_mode = strict
lib_ldf_mode = deep+
lib_ignore =
   STM32Ethernet
   STM32duino LwIP
   WiFi
   Teensy41_AsyncTCP
   ESPAsync_WiFiManager
   WebServer_WT32_ETH01
   STM32AsyncTCP
   AsyncTCP_SSL

as the platformio.ini

with src/main.cpp from AsyncMQTT_Generic/FullyFeatured_PortentaH7_Ethernet.ino at main · khoih-prog/AsyncMQTT_Generic · GitHub but with added

#include <Arduino.h>

at the top, and src/defines.h straight from AsyncMQTT_Generic/defines.h at main · khoih-prog/AsyncMQTT_Generic · GitHub.

Which should get you to

Linking .pio\build\portenta_h7_m7\firmware.elf
Checking size .pio\build\portenta_h7_m7\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.1% (used 63136 bytes from 523624 bytes)
Flash: [===       ]  25.3% (used 199200 bytes from 786432 bytes)
Building .pio\build\portenta_h7_m7\firmware.bin
Adding dfu suffix to firmware.bin
dfu-suffix (dfu-util) 0.9

Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Suffix successfully added to file
==============================[SUCCESS] Took 37.07 seconds ==============================[

Edit Simplified platformio.ini, no more build_flags, reordered includes – don’t include Portenta_H7_AsyncTCP.h in src/main.cpp after all.

Hello @maxgerhardt , thank you so much for replying.

The old errors are gone, but now instead I get errors related to WifiClient.h:
fatal error: WiFiClient.h: No such file or directory

I don’t need wifi, but I tried removing it from the ignore list in platformio.ini anyway, now the build doesn’t fail until the linking phase where it stops with:

Linking .pio\build\portenta_h7_m7\firmware.elf
.pio\build\portenta_h7_m7\libc9a\libEthernet.a(Ethernet.cpp.o):(.bss.Ethernet+0x0): multiple definition of `Ethernet'
.pio\build\portenta_h7_m7\lib47c\libEthernet.a(Ethernet.cpp.o):(.bss.Ethernet+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\portenta_h7_m7\firmware.elf] Error 1

Also I get a waring early on related to the AsyncTCP library, I guess the link to your fork is the issue?

Library Manager: Warning! Could not install dependency {'owner': 'khoih-prog', 'name': 'Portenta_H7_AsyncTCP', 'version': '>=1.3.0', 'platforms': ['ststm32']} for package 'AsyncMQTT_Generic'

Ah, please remove the .pio folder of the project and build again. Old artefact libraries might still be in there.

No that’s an error from the AsyncMQTT_Generic library due to Fix platform value for Portenta by maxgerhardt · Pull Request #1 · khoih-prog/Portenta_H7_AsyncTCP · GitHub, but it actually helps here because that way a different Portenta_H7_AsyncTCP can be loaded from my fork.

Even after deleting .pio I still get the same errors.

Wifi ignored
fatal error: WiFiClient.h: No such file or directory

Wifi not ignored:

Linking .pio\build\portenta_h7_m7\firmware.elf
.pio\build\portenta_h7_m7\libc9a\libEthernet.a(Ethernet.cpp.o):(.bss.Ethernet+0x0): multiple definition of `Ethernet'
.pio\build\portenta_h7_m7\lib47c\libEthernet.a(Ethernet.cpp.o):(.bss.Ethernet+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\portenta_h7_m7\firmware.elf] Error 1

Weird. Please download this project

and in the CLIpio upgrade --dev before building.

Do you have global libraries installed? If yes please delete them from C:\Users\<user>\.platformio\lib.

It might also help to do

pio platform update ststm32

Okay the build failure is actually reproducable in, Create build.yml · maxgerhardt/pio-portenta-asynmqtt@baa5401 · GitHub, but was working on my local machine. Need to check why.

Okay, thanks again for looking into this!

Actually, can you build the project once, then delete the wrong Ethernet library from .pio\libdeps\<env>\Ethernet and build the project again?

I’m sorry, which files or folders should I delete?
I tried deleting the whole Ethernet folder \.pio\libdeps\portenta_h7_m7\Ethernet, but that one is immediately recreated on the next build which yields the same error.