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?

I’m having the same issue but with the Websockets2_generic library. I’ve sent the posts that suggest removing parts of the library.json but I’ve not been able to make that work.

Full platformio.ini and minimal src/main.cpp code or we can’t help.

This is the platformio.ini file that I just got to work. (By work I mean compile and load on to the board, not sure if all the features are working.)

; 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

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
upload_protocol = dfu
monitor_speed = 115200
lib_deps = 
    khoih-prog/WebSockets2_Generic@^1.13.2
    ;Functional-Vlpp
    ;DoubleResetDetector_Generic

lib_ignore =
    ; ArduinoJson
    ; DoubleResetDetector_Generic
    DueFlashStorage
    ESP_AT_Lib
    Ethernet_Generic
    EthernetENC
    EthernetWebServer
    EthernetWebServer_STM32
    FlashStorage_RTL8720
    FlashStorage_SAMD
    ; FlashStore_STM32
    FlashStore_STM32F1
    ; Functional-Vlpp
    QNEthernet
    SinricPro_Generic
    STM32duino LwIP
    STM32Ethernet
    UIPEthernet
    WebServer_WT32_ETH01
    ; WebSockets_Generic
    WiFi101
    WiFi101_Generic
    WiFiEspAT
    WiFiMulti_Generic
    WiFiNINA_Generic
    ; WifiWebServer

This is the main.cpp which is just one of the examples from the websockets2 lib.

/****************************************************************************************************************************
  Portenta_H7-Ethernet_ServerAllFunctionsDemo.ino  
  For Portenta_H7 with Murata WiFi module/shield.
  
  Based on and modified from Gil Maimon's ArduinoWebsockets library https://github.com/gilmaimon/ArduinoWebsockets
  to support STM32F/L/H/G/WB/MP1, nRF52 and SAMD21/SAMD51 boards besides ESP8266 and ESP32
  
  The library provides simple and easy interface for websockets (Client and Server).
  
  Example first created on: 10.05.2018
  Original Author: Markus Sattler
  
  Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic
  Licensed under MIT license
 *****************************************************************************************************************************/
#include <SPI.h>
#include <Arduino.h>

#include "defines.h"

#include <WebSockets2_Generic.h>

#include <WiFiWebServer.h>

using namespace websockets2_generic;

WebsocketsServer SocketsServer;

int status = WL_IDLE_STATUS;

#define WEBSOCKETS_PORT     8080

// Change pins according to your boards
#define RED_LED     LEDR
#define GREEN_LED   LEDG
#define BLUE_LED    LEDB

// For Portenta_H7
#define LED_ON      LOW
#define LED_OFF     HIGH

WiFiWebServer server(80);

String IPAddressToString(IPAddress _address)
{
  String str = String(_address[0]);
  str += ".";
  str += String(_address[1]);
  str += ".";
  str += String(_address[2]);
  str += ".";
  str += String(_address[3]);
  return str;
}

void setup()
{ 
  Serial.begin(115200);
  while (!Serial && millis() < 5000);

  Serial.print("\nStarting Portenta_H7_ServerAllFunctionsDemo using WiFi on "); Serial.println(BOARD_NAME);
  Serial.println(WEBSOCKETS2_GENERIC_VERSION);

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE)
  {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  Serial.print(F("Connecting to SSID: "));
  Serial.println(ssid);

  status = WiFi.begin(ssid, password);

  delay(1000);
   
  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED)
  {
    delay(500);
        
    // Connect to WPA/WPA2 network
    status = WiFi.status();
  }

  if (WiFi.status() == WL_CONNECTED)
  {
    Serial.print("Connected to Wifi, IP address: ");
    Serial.println(WiFi.localIP());
  }
  else
  {
    Serial.println("No WiFi");
    return;
  }

  SocketsServer.listen(WEBSOCKETS_PORT);
 
  Serial.print(SocketsServer.available() ? "WebSockets Server Running and Ready on " : "Server Not Running on ");
  Serial.println(BOARD_NAME);
  Serial.print("IP address: ");
  Serial.print(WiFi.localIP());
  Serial.print(", Port: ");
  Serial.println(WEBSOCKETS_PORT);    // Websockets Server Port
  
  // handle index
  server.on("/", []()
  {
    String wsServer = String("ws://") + IPAddressToString(WiFi.localIP()) + ":" + WEBSOCKETS_PORT + "/";
    Serial.print("wsServer: ");
    Serial.println(wsServer);

        
    // send index.html
    server.send(200, "text/html", "<html><head><script>var connection = new WebSocket(wsServer, ['arduino']);connection.onopen = function () {  connection.send('Connect ' + new Date()); }; connection.onerror = function (error) {    console.log('WebSocket Error ', error);};connection.onmessage = function (e) {  console.log('Server: ', e.data);};function sendRGB() {  var r = parseInt(document.getElementById('r').value).toString(16);  var g = parseInt(document.getElementById('g').value).toString(16);  var b = parseInt(document.getElementById('b').value).toString(16);  if(r.length < 2) { r = '0' + r; }   if(g.length < 2) { g = '0' + g; }   if(b.length < 2) { b = '0' + b; }   var rgb = '#'+r+g+b;    console.log('RGB: ' + rgb); connection.send(rgb); }</script></head><body>LED Control:<br/><br/>R: <input id=\"r\" type=\"range\" min=\"0\" max=\"255\" step=\"1\" oninput=\"sendRGB();\" /><br/>G: <input id=\"g\" type=\"range\" min=\"0\" max=\"255\" step=\"1\" oninput=\"sendRGB();\" /><br/>B: <input id=\"b\" type=\"range\" min=\"0\" max=\"255\" step=\"1\" oninput=\"sendRGB();\" /><br/></body></html>");
  });

  server.begin();
  
  digitalWrite(RED_LED,   LED_OFF);
  digitalWrite(GREEN_LED, LED_OFF);
  digitalWrite(BLUE_LED,  LED_OFF);
}

WebsocketsClient* client = NULL;

void loop()
{
  server.handleClient();

  client = new WebsocketsClient;

  if (client)
  {
    *client = SocketsServer.accept();
  
    if (client->available())
    {
      WebsocketsMessage msg = client->readNonBlocking();
  
      // log
      Serial.print("Got Message: ");
      Serial.println(msg.data());
  
      // return echo
      client->send("Echo: " + msg.data());
  
      // close the connection
      client->close();
    }

    delete client;
  }
}

Since I did not really understand what this library really depended on I excluded all the libraries that it includes by default then started adding them back in based on the complier errors until it worked… I would be very grateful for a quick explanation of how this websockets 2 library functions.

Dear community, opening this topic as people searching for help on building the AsyncMqtt_Generic for the Portenta H7 might run into this thread and find some useful up-to date information in early 2024.

Using ArduinoCore-mbed 3.5.4 made it possible for me to compile the project succesfully.

Initially when I tried to compile the example with the most recent ArduinoCore-mbed 4.0.10, I got an error:

Compiling .pio\build\opta\lib031\Portenta_H7_AsyncTCP@src-604b5ceafe255af4b260b9758b724419\Portenta_H7_AsyncTCP.cpp.o
In file included from .pio\libdeps\opta\Portenta_H7_AsyncTCP@src-604b5ceafe255af4b260b9758b724419\src\AsyncPrinter.h:52:0,
                 from .pio\libdeps\opta\Portenta_H7_AsyncTCP@src-604b5ceafe255af4b260b9758b724419\src\AsyncPrinter.cpp:52:
.pio\libdeps\opta\Portenta_H7_AsyncTCP@src-604b5ceafe255af4b260b9758b724419\src\Portenta_H7_AsyncTCP.h:109:12: fatal error: lwip/ip_addr.h: No such file or directory
   #include "lwip/ip_addr.h"
            ^~~~~~~~~~~~~~~~
compilation terminated.

Now for me it is not entirely clear what is actually the breaking change between ArduinoCore-mbed 3.5.4 and 4.0.10. Is there anyone who can point to this error, or has a fix for this problem.

It seems that something fishy is going on with the lwip from mbed and the portenta h7, but all the files seem to be in the repo:

Small sidenote: my target is an arduino Opta, but it is essentially the same as the Portenta H7. In any case the example platformio.ini has the portenta h7 as target.

platform = ststm32
board = portenta_h7_m7
framework = arduino
build_flags = 
	-D ETHERNET_USE_PORTENTA_H7
  
platform_packages = 
	platformio/framework-arduino-mbed@^4.0.10
	platformio/framework-mbed @^6.61700.0
	platformio/tool-dfuutil-arduino @^1.11.0
	platformio/tool-openocd@^3.1200.0
	platformio/tool-stm32duino@^1.0.1
	platformio/toolchain-gccarmnoneeabi @ >=1.60301.0,<1.80000.0

lib_compat_mode = strict
lib_ldf_mode = deep+


lib_deps = 
   khoih-prog/AsyncMQTT_Generic@^1.5.0
   Portenta_H7_AsyncTCP=https://github.com/maxgerhardt/Portenta_H7_AsyncTCP/archive/refs/heads/withdeps.zip

lib_ignore =
   STM32Ethernet
   STM32duino LwIP
   WiFi
   Teensy41_AsyncTCP
   ESPAsync_WiFiManager
   WebServer_WT32_ETH01
   STM32AsyncTCP
   AsyncTCP_SSL

Main.cpp (not so much)

#include <Arduino.h>
#include "rtos.h"
#include "MCUboot.h"
using namespace std::chrono_literals;

void setup() {
 return;
}

void loop() {
  // put your main code here, to run repeatedly:


  while (true)
  {
    rtos::ThisThread::sleep_for(1s);
  }
  
}

maybe @maxgerhardt might have a solution, as i have seen he has quite some knowledge of the plarformio build system.