Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP-IDF integration #708

Closed
BartJozwicki opened this issue Dec 5, 2023 · 8 comments · May be fixed by #717
Closed

ESP-IDF integration #708

BartJozwicki opened this issue Dec 5, 2023 · 8 comments · May be fixed by #717

Comments

@BartJozwicki
Copy link

Hello it's an issue/question, I would like to use HomeSpan library in VScode ESP-IDF extension I have added arduino as component and run across multiple problems. First was no "core_version.h" file I solved that, then terminal complains about undetected files in src/extras/Pixel.h:139:30, no sodium.h file etc. I was wondering if there is an easy way to use this library outside Arduino ?

@HomeSpan
Copy link
Owner

HomeSpan commented Dec 5, 2023

I don't use VSCode but I believe others have used this successfully via Platform IO.

@frankonski
Copy link
Contributor

I only use VSCode, plain and simple, with only the following VSCode extensions installed:

  • Arduino
  • C/C++
  • C/C++ Extension Pack
  • C/C++ Themes
  • Expressif IDF
  • Serial Monitor

I can get my project to build just fine using tasks defined in task.json. The initial trick is to let Espressif IDF extension configure itself, and make sure you add your custom HomeSpan library location in c_cpp_properties.json. This is to make Espressif IDF and Intellisense happy.

Then in task.json, this is what I have:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Compile",
        "type": "shell",
        "command": "${config:arduino-cli-location}",
        "args": [
          "compile",
          "--fqbn",
          "esp32:esp32:esp32wrover",
          "--config-file",
          "${workspaceFolder}\\.vscode\\arduino.yaml",
          "--build-path",
          "${workspaceFolder}\\build_task",
          "--verbose",
          "--library",
          "${config:homespan.root}",
          "${workspaceFolder}\\${config:projectName}.ino"
        ],
        "options": {
          "shell": {
            "executable": "cmd.exe",
            "args": [
              "/c"
            ]
          }
        },
        "group": {
          "kind": "build",
          "isDefault": true
        },
        "problemMatcher": {
          "base": "$gcc",
          "fileLocation": "absolute"
        }
      },
      {
        "label": "OTA Upload",
        "type": "shell",
        "command": "python",
        "args": [
          "%LOCALAPPDATA%\\Arduino15\\packages\\esp32\\hardware\\esp32\\${config:arduino-esp32-version}\\tools\\espota.py",
          "-i",
          "${config:ota-host}",
          "-p",
          "${config:ota-port}",
          "-a",
          "${config:ota-password}",
          "-f",
          "${workspaceFolder}\\build_task\\${config:projectName}.ino.bin",
          "-r"
        ],
        "options": {
          "shell": {
            "executable": "cmd.exe",
            "args": [
              "/c"
            ]
          }
        },
        "problemMatcher": [
          "$espIdf"
        ]
      },
      {
        "label": "COM Upload app only",
        "type": "shell",
        "command": "${config:esp-tool-location}",
        "args": [
          "--chip",
          "esp32",
          "--port",
          "${config:idf.portWin}",
          "--baud",
          "115200",
          "--before",
          "default_reset",
          "--after",
          "hard_reset",
          "write_flash",
          "-z",
          "--flash_mode",
          "dio",
          "--flash_size",
          "detect",
          "--flash_freq",
          "keep",
          "0x10000",
          "${workspaceFolder}\\build_task\\${config:projectName}.ino.bin"
        ],
        "options": {
          "shell": {
            "executable": "cmd.exe",
            "args": [
              "/c"
            ]
          }
        },
        "problemMatcher": []
      },
      {
        "label": "COM Upload with partitions",
        "type": "shell",
        "command": "${config:esp-tool-location}",
        "args": [
          "--chip",
          "esp32",
          "--port",
          "${config:idf.portWin}",
          "--baud",
          "115200",
          "--before",
          "default_reset",
          "--after",
          "hard_reset",
          "write_flash",
          "-z",
          "--flash_mode",
          "dio",
          "--flash_size",
          "detect",
          "--flash_freq",
          "keep",
          "0x1000",
          "${workspaceFolder}\\build_task\\${config:projectName}.ino.bootloader.bin",
          "0x8000",
          "${workspaceFolder}\\build_task\\${config:projectName}.ino.partitions.bin",
          "0xe000",
          "%LOCALAPPDATA%\\Arduino15\\packages\\esp32\\hardware\\esp32\\${config:arduino-esp32-version}\\tools\\partitions\\boot_app0.bin",
          "0x10000",
          "${workspaceFolder}\\build_task\\${config:projectName}.ino.bin"
        ],
        "options": {
          "shell": {
            "executable": "cmd.exe",
            "args": [
              "/c"
            ]
          }
        },
        "problemMatcher": []
      }
    ]
  }

and settings.json must define a couple properties like these:

"projectName": "my-esp32-project",
"idf.portWin": "COM3",
"idf.flashType": "UART",
"arduino-cli-location" : "%USERPROFILE%\\Documents\\arduino-cli_0.34.2_Windows_64bit\\arduino-cli.exe"
"esp-tool-location" : "%LOCALAPPDATA%\\Arduino15\\packages\\esp32\\tools\\esptool_py\\4.5.1\\esptool.exe",
"arduino-esp32-version": "2.0.14",
"ota-password" : "homespan-ota",
"ota-host" : "my-esp32-project.local",
"ota-port" : "3232",
"homespan.root" : "%USERPROFILE%\\Documents\\Arduino\\libraries\\HomeSpan",

homespan.root location that should point to what you downloaded using Arduino IDE, or what you got from a git clone. Your choice.

@dzungpv
Copy link

dzungpv commented Dec 19, 2023

@BartJozwicki I have used HomeSpan with ESP IDF and work fine. You must use as IDF component and build with ESP IDF version 4.4.6.
Create new CMakeLists.txt file in root of HomeSpan folder with content:

set(COMPONENT_SRCDIRS
"src"
)
 
set(COMPONENT_ADD_INCLUDEDIRS
"src"
)
 
set(COMPONENT_REQUIRES
"arduino-esp32"
"libsodium"
"app_update"
)
 
register_component()
 
target_compile_definitions(${COMPONENT_TARGET} PUBLIC -DESP32)
target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti)  

@hbf-sthlm
Copy link

@frankonski,

Thank you for explaining your solution.

Which version of ESP-IDF are you using? I am using 5.1.2 and worry that I may have to downgrade to 4.x in order to use Homespan with ESP-IDF in VS Code.

@HomeSpan
Copy link
Owner

HomeSpan commented Jan 3, 2024

According to Espressif, version 5 of the IDF has breaking changes. The Espressif team is still working through an Arduino version, though they say it will also have some breaking changes.

Recommend using IDF 4.X with HomeSpan.

@hbf-sthlm
Copy link

Got it. Thanks for the fast response.

@frankonski
Copy link
Contributor

@hbf-sthlm

Which version of ESP-IDF are you using? I am using 5.1.2 and worry that I may have to downgrade to 4.x in order to use Homespan with ESP-IDF in VS Code.

I don't directly use ESP IDF. My VSCode project (that uses HomeSpan) calls arduino-cli version 0.34.2.
And I use arduino-cli to download esp32:esp32:

arduino-cli core install esp32:esp32

This esp32 Arduino package automatically comes with its own build of ESP-IDF, which, when looking at the build output, shows -DIDF_VER=\"v4.4.6-dirty\"

So I guess it is an Arduino-specific version of ESP-IDF based on version 4.4.6?

@hbf-sthlm
Copy link

@frankonski

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants