I installed PlatformiO today and was trying a very basic code on my M5Stack Core2. Everytime I hit build I get the below error, i.e. I haven’t even gotten to the upload part.
fatal error: M5Core2.h: No such file or directory
main.c
#include <M5Core2.h>
void setup() {
M5.Lcd.begin(); // Initialize M5Stack
M5.Lcd.clear(); // Clear the contents displayed on the screen
}
void loop() {
}
Why did you create a ESP-IDF project with a C source file? M5Core2 is an Arduino library writen in C++. Your whole src/main.c code also screams “Arduino” with its setup() and loop().
I’m pretty sure I tried renaming the file to main.cpp to see if the error goes away, and I just did that and it’s still the same. I looked at only examples on Github as a starting point.
I closed the VS Code session I had and deleted everything except platform.ini and main.cpp (I renamed this from main.c) in the project folder. Then PlatformiO did the rebuild and the same error pops up. I manually did a Full Clean and Build, and then did an Intellisense rebuild right after it. And it’s still the same.
I feel that what I am facing might be related to the below Github issue.
I did get the below error after deleting all files, which is different from the regular include errors I’ve been getting.
Processing m5stack-core2 (platform: espressif32; board: m5stack-core2; framework: espidf)
------------------------------------------------------------------
Library Manager: Installing m5stack/M5Core2 @ ^0.1.9
Unpacking [####################################] 100%
Library Manager: M5Core2@0.1.9 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/m5stack-core2.html
PLATFORM: Espressif 32 (6.8.1) > M5Stack Core2
HARDWARE: ESP32 240MHz, 4.31MB RAM, 16MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-espidf @ 3.50300.0 (5.3.0)
- tool-cmake @ 3.16.4
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- tool-idf @ 1.0.1
- tool-mconf @ 1.4060000.20190628 (406.0.0)
- tool-ninja @ 1.9.0
- tool-riscv32-esp-elf-gdb @ 11.2.0+20220823
- tool-xtensa-esp-elf-gdb @ 11.2.0+20230208
- toolchain-esp32ulp @ 1.23800.240113 (2.38.0)
- toolchain-xtensa-esp-elf @ 13.2.0+20240530
Reading CMake configuration...
-- Could NOT find Git (missing: GIT_EXECUTABLE)
-- git rev-parse returned ''
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/Users/MPANICKER/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.exe
-- Check for working C compiler: C:/Users/MPANICKER/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.exe
-- Check for working C compiler: C:/Users/MPANICKER/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Users/MPANICKER/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-g++.exe
-- Check for working CXX compiler: C:/Users/MPANICKER/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- git rev-parse returned ''
-- Could not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32
-- Configuring incomplete, errors occurred!
See also "C:/Users/MPANICKER/Documents/PlatformIO/Projects/MattecPlatformiO/.pio/build/m5stack-core2/CMakeFiles/CMakeOutput.log".
See also "C:/Users/MPANICKER/Documents/PlatformIO/Projects/MattecPlatformiO/.pio/build/m5stack-core2/CMakeFiles/CMakeError.log".
CMake Warning at C:/Users/MPANICKER/.platformio/packages/framework-espidf/tools/cmake/git_submodules.cmake:4 (message):
Git executable was not found. Git submodule checks will not be executed.
If you have any build issues at all, start by adding git executable to the
PATH and rerun cmake to not see this warning again.
Call Stack (most recent call first):
C:/Users/MPANICKER/.platformio/packages/framework-espidf/tools/cmake/idf.cmake:41 (include)
C:/Users/MPANICKER/.platformio/packages/framework-espidf/tools/cmake/project.cmake:29 (include)
CMakeLists.txt:2 (include)
CMake Error at C:/Users/MPANICKER/.platformio/packages/framework-espidf/tools/cmake/component.cmake:225 (message):
CMake Error at
C:/Users/MPANICKER/.platformio/packages/framework-espidf/tools/cmake/scripts/component_get_requirements.cmake:3
(include):
include could not find load file:
C:/Users/MPANICKER/Documents/PlatformIO/Projects/MattecPlatformiO/.pio/build/m5stack-core2/build_properties.temp.cmake
Call Stack (most recent call first):
C:/Users/MPANICKER/.platformio/packages/framework-espidf/tools/cmake/build.cmake:586 (__component_get_requirements)
C:/Users/MPANICKER/.platformio/packages/framework-espidf/tools/cmake/project.cmake:710 (idf_build_process)
CMakeLists.txt:3 (project)
Was the choice of “ESP-IDF” versus “Arduino” as framework concious or an accident?
All you have to do is use the project wizard to create an Arduino framework project for the m5stack-core2 board to use the M5Core2 library, not ESP-IDF**.
The library refuses to be included because the framework requirements of the library are not being met: Being arduino.
lol, that was my error. I was trying to stick with ESP-IDF to get access to more features and I didn’t put much thought into the framework. Now that I look at it more, I’ve only seen one project being done using ESP-IDF on the Core2.
What advantages would I have in using the ESP-IDF framework instead of Arduino. The main functions in my project would require HTTP requests to an API, JSON parsing and then displaying the content on the display either using the M5Stack library or LVGL and I believe all of this could be accomplished using the Arduino framework for PlatformiO
Arduino-ESP32 is a component on top of ESP-IDF. With the latest PlatformIO supported core v2.0.17, that is ESP-IDF v4.4.7. Quite old, considering the v3.x core is built on ESP-IDF 5.1.4, but it still works. There are currently some issues with mainline PlatformIO supporting the 3.x core.
If you only stay within the libraries and core functions of the Arduino core, you won’t notice a difference.
Should I then avoid using the M5Core2 library and instead use the new M5Unified library. I did see that there was a message at compilation saying that the M5Core2 library might be getting depreciated.
Looking at the compatibility information the ESP-IDF also seems to be supported. Should I declare the ESP-IDF version to use with the code?
The ESP-IDF framework expects the symbol app_main to exist with C-linkage, not C++ linkage. C++ name mangling would result in the app_main function generating a different symbol name than simply app_main. Hence, since you write this in a .cpp file, you need the extern "C" on that particular function, to prevent C++ name mangling and enabling ESP-IDF to find the symbol.