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.

Giving this a bump as it is still not solved in my case.
@maxgerhardt have you been able to get this to work on your side?

Has there been a solution tothisyet. I am also getting the error but on a diffrent poject. Compiles OK using Arduino IDE but not platformio.

@maxgerhardt

Do you think it’s correct, better and final to modify the platformio.ini to move the lib_deps to related platforms, e.g. inside [env:portenta_h7_m7], etc.

If OK, I’ll change all of my libraries.

For example

;PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
; ============================================================
; chose environment:
; ESP8266
; ESP32
; SAMD
; NRF52
; STM32
; pico
; ============================================================
;default_envs = ESP8266
;default_envs = ESP32
;default_envs = SAMD
;default_envs = pico
;default_envs = NRF52
;default_envs = STM32
default_envs = portenta_h7_m7
;default_envs = portenta_h7_m4
;default_envs = teensy

[env]
; ============================================================
; Serial configuration
; choose upload speed, serial-monitor speed
; ============================================================
upload_speed = 921600
;upload_port = COM11
;monitor_speed = 9600
;monitor_port = COM11

; Checks for the compatibility with frameworks and dev/platforms
lib_compat_mode = strict
lib_ldf_mode = chain+
;lib_ldf_mode = deep+

lib_deps =  
;
  
build_flags =
; set your debug output (default=Serial)
; -D DEBUG_ESP_PORT=Serial
; comment the folowing line to enable WiFi debugging
; -D NDEBUG

[env:teensy]
platform = teensy
framework = arduino

lib_deps =  
; PlatformIO 4.x
; Teensy41_AsyncTCP@>=1.0.0
; PlatformIO 5.x  
 khoih-prog/Teensy41_AsyncTCP@>=1.0.0

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino

lib_deps =  
; PlatformIO 4.x
; Portenta_H7_AsyncTCP@>=1.3.2

; PlatformIO 5.x  
 khoih-prog/Portenta_H7_AsyncTCP@>=1.3.2

[env:portenta_h7_m4]
platform = ststm32
board = portenta_h7_m4
framework = arduino

lib_deps =  
; PlatformIO 4.x
; Portenta_H7_AsyncTCP@>=1.3.2
; PlatformIO 5.x  
 khoih-prog/Portenta_H7_AsyncTCP@>=1.3.2

[env:pico]
; ============================================================
; Just a sample
; You have to research and fix if there is issue
; ============================================================
platform = raspberrypi
board = pico
framework = arduino
upload_protocol = picotool

lib_deps =  
; PlatformIO 4.x
; AsyncTCP_RP2040W@>=1.0.0

; PlatformIO 5.x  
 khoih-prog/AsyncTCP_RP2040W@>=1.0.0

[env:ESP8266]
platform = espressif8266
framework = arduino

lib_deps =  
; PlatformIO 4.x
; https://github.com/khoih-prog/ESPAsyncTCP.git
; PlatformIO 5.x  
  https://github.com/khoih-prog/ESPAsyncTCP.git

; ============================================================
; Board configuration
; choose your board by uncommenting one of the following lines
; ============================================================
;board = gen4iod
;board = huzzah
;...
;board = esp32doit-devkit-v1

[env:ESP32]
platform = espressif32
framework = arduino

lib_deps =  
; PlatformIO 4.x
; AsyncTCP@>=1.1.1

; PlatformIO 5.x  
 me-no-dev/AsyncTCP@>=1.1.1

; ============================================================
; Board configuration
; choose your board by uncommenting one of the following lines
; ============================================================
;board = esp32cam
;...
;board = nina_w10

[env:STM32]
platform = ststm32
framework = arduino

lib_deps =  
; PlatformIO 4.x
; https://github.com/khoih-prog/STM32AsyncTCP.git
; STM32duino LwIP@>=2.1.2
; STM32duino STM32Ethernet@>=1.3.0
; PlatformIO 5.x  
; philbowles/STM32AsyncTCP
 https://github.com/khoih-prog/STM32AsyncTCP.git
 stm32duino/STM32duino LwIP@>=2.1.2
 stm32duino/STM32duino STM32Ethernet@>=1.3.0

; ============================================================
; Choose your board by uncommenting one of the following lines
; ============================================================

; ============================================================
; Board configuration Nucleo-144
; ============================================================

;board = nucleo_f207zg
;...

;board = feather_f405

; ============================================================
; Board configuration Many more Boards to be filled
; ============================================================

Just updated the main branch for you to try.

Not sure if the above was directed at me or not.
No idea what you mean by

" Do you think it’s correct, better and final to modify the platformio.ini to move the lib_deps to related platforms, e.g. inside [env:portenta_h7_m7] , etc."

I have however removed the MQTT_generic libary and I still get the same error

.pio/libdeps/esp32doit-devkit-v1/STM32Ethernet/src/utility/ethernetif.cpp:48:10: fatal error: stm32_def.h: No such file or directory


  • Looking for stm32_def.h dependency? Check our library registry!
  • CLI > platformio lib search “header:stm32_def.h”
  • Web > PlatformIO Registry

#include “stm32_def.h”
^~~~~~~~~~~~~
compilation terminated.

Cheers Mal

even if you add STM32Ethernet to the lib_ignore = .. section of the platformio.ini?