VS CODE: use one source code for different devices (e.g. ESP32 WROOM, ESP32C6)

cpehonk
Posts: 16
Joined: Sat Nov 09, 2019 3:41 pm

VS CODE: use one source code for different devices (e.g. ESP32 WROOM, ESP32C6)

Postby cpehonk » Wed Aug 14, 2024 7:24 pm

Hi All!

I would like to know if it is possible to have one main folder with code in VS CODE, but to target to different processor types with different *.bin names. To give an example:
I have written some code primarily for the ESP32-WROOM module. Now, I would like to target an ESP32C6 module from the same code base, but with different target binary files: e.g. esp32wroom.bin and esp32c6.bin.
What must I do within the solution folder in VS CODE to address both?
Any hints?

Thanks in advance
Chris

cpehonk
Posts: 16
Joined: Sat Nov 09, 2019 3:41 pm

Re: VS CODE: use one source code for different devices (e.g. ESP32 WROOM, ESP32C6)

Postby cpehonk » Thu Sep 05, 2024 5:28 pm

If anybody is interested: solved my problem by adding some cmake custom commands to the CMakeList.txt file in the project root folder.

Greetings
Christoph

DrMickeyLauer
Posts: 163
Joined: Sun May 22, 2022 2:42 pm

Re: VS CODE: use one source code for different devices (e.g. ESP32 WROOM, ESP32C6)

Postby DrMickeyLauer » Fri Sep 06, 2024 11:20 am

Care to elaborate? I'm always curious about ways to solve this problem.

Conceptually, I like how platformio solves it, however I don't like the additional non-standard abstractions it comes with.

I'm using different board directories where each of it has a dedicated `sdkconfig`, while the code directories are embedded via softlinks.

cpehonk
Posts: 16
Joined: Sat Nov 09, 2019 3:41 pm

Re: VS CODE: use one source code for different devices (e.g. ESP32 WROOM, ESP32C6)

Postby cpehonk » Sat Sep 07, 2024 1:03 pm

No problem ;) It cost me several days to figure out. But this is my (quite simple) solution and it works fine.

In my project structure on disk I added a "Binaries" folder where cmake copies the required files.
Additionally, I saved a "sdkconfig.defaults.xxx" for each target architecture I use (here: "esp32" & "esp32c6").

I added the following commands right after the "project()" command in the main CMakeList.txt file:

Code: Select all

set(CPU_BIN "Binaries/${PROJECT_NAME}_${IDF_TARGET}.bin")
set(CPU_ELF "Binaries/${PROJECT_NAME}_${IDF_TARGET}.elf")
set(CPU_JSON "Binaries/project_description_${IDF_TARGET}.json")

#file(REMOVE ${PROJECT_DIR}/${CPU_BIN})
#file(REMOVE ${PROJECT_DIR}/${CPU_ELF})
#file(REMOVE ${PROJECT_DIR}/${CPU_JSON})

add_custom_command(
    TARGET app
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
            ${PROJECT_DIR}/build/${PROJECT_NAME}.bin
            ${PROJECT_DIR}/${CPU_BIN}
    VERBATIM
)

add_custom_command(
    TARGET app
    POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy
                ${PROJECT_DIR}/build/${PROJECT_NAME}.elf
                ${PROJECT_DIR}/${CPU_ELF}
)

add_custom_command(
    TARGET app
    POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy
                ${PROJECT_DIR}/build/project_description.json
                ${PROJECT_DIR}/${CPU_JSON}
)
In case of trying to decode a core dump you need all these three files. Each time you compile these files are replaced or even created if they dont exist before.

Hope this helps!

Greetings
Christoph

Who is online

Users browsing this forum: Basalt and 370 guests