Skip to content

Instantly share code, notes, and snippets.

@Anwaarullah
Created February 25, 2021 19:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anwaarullah/9b24569c836bb66bb45cac311095130f to your computer and use it in GitHub Desktop.
Save Anwaarullah/9b24569c836bb66bb45cac311095130f to your computer and use it in GitHub Desktop.
#
# Set the target used for the standard project build.
#
macro(__target_init)
# Input is IDF_TARGET environement variable
set(env_idf_target "esp32c3")
if(NOT env_idf_target)
# IDF_TARGET not set in environment, see if it is set in cache
if(IDF_TARGET)
set(env_idf_target "esp32c3")
else()
set(env_idf_target "esp32c3")
message(STATUS "IDF_TARGET not set, using default target: ${env_idf_target}")
endif()
# else()
# # IDF_TARGET set both in environment and in cache, must be the same
# if(NOT ${IDF_TARGET} STREQUAL ${env_idf_target})
# message(FATAL_ERROR "IDF_TARGET in CMake cache does not match "
# "IDF_TARGET environment variable. To change the target, clear "
# "the build directory and sdkconfig file, and build the project again")
# endif()
endif()
# IDF_TARGET will be used by Kconfig, make sure it is set
set(ENV{IDF_TARGET} ${env_idf_target})
# Finally, set IDF_TARGET in cache
set(IDF_TARGET ${env_idf_target} CACHE STRING "IDF Build Target")
# Check if IDF_ENV_FPGA environment is set
set(env_idf_env_fpga $ENV{IDF_ENV_FPGA})
if(${env_idf_env_fpga})
idf_build_set_property(__IDF_ENV_FPGA "y")
message(NOTICE "IDF_ENV_FPGA is set, building for FPGA environment")
endif()
endmacro()
#
# Check that the set build target and the config target matches.
#
function(__target_check)
# Should be called after sdkconfig CMake file has been included.
idf_build_get_property(idf_target IDF_TARGET)
if(NOT ${idf_target} STREQUAL ${CONFIG_IDF_TARGET})
message(FATAL_ERROR "CONFIG_IDF_TARGET in sdkconfig does not match "
"IDF_TARGET environment variable. To change the target, delete "
"sdkconfig file and build the project again.")
endif()
endfunction()
#
# Used by the project CMake file to set the toolchain before project() call.
#
macro(__target_set_toolchain)
idf_build_get_property(idf_path IDF_PATH)
# First try to load the toolchain file from the tools/cmake/directory of IDF
set(toolchain_file_global ${idf_path}/tools/cmake/toolchain-${IDF_TARGET}.cmake)
if(EXISTS ${toolchain_file_global})
set(CMAKE_TOOLCHAIN_FILE ${toolchain_file_global})
else()
__component_get_target(component_target ${IDF_TARGET})
if(NOT component_target)
message(FATAL_ERROR "Unable to resolve '${IDF_TARGET}' for setting toolchain file.")
endif()
get_property(component_dir TARGET ${component_target} PROPERTY COMPONENT_DIR)
# Try to load the toolchain file from the directory of IDF_TARGET component
set(toolchain_file_component ${component_dir}/toolchain-${IDF_TARGET}.cmake)
if(EXISTS ${toolchain_file_component})
set(CMAKE_TOOLCHAIN_FILE ${toolchain_file_component})
else()
message(FATAL_ERROR "Toolchain file toolchain-${IDF_TARGET}.cmake not found,"
"checked ${toolchain_file_global} and ${toolchain_file_component}")
endif()
endif()
endmacro()
@iamcalledusman
Copy link

Hi @Anwaarullah

Thank you for the code file . I am facing an issue if you can help me .

i have followed the link as mentioned below in your youtube channel .Which was about the ESP-IDF

https://www.youtube.com/watch?v=Lc6ausiKvQM

At the end of doing all the steps i am able to install and compile the "blink" project provided in examples .

But the issue i faced is that when i downloaded in to my esp32-c3 board . I got the following error as attached image file .

screenshot

After that i followed your full video . And when i made changes in "Target.cmake" file as mentioned by you and compile the " blink "project. Then i got the following error .
esp32_c3

Thanks in Advance for your help!

@iamcalledusman
Copy link

Hi @Anwaarullah

Thank you for the code file . I am facing an issue if you can help me .

i have followed the link as mentioned below in your youtube channel .Which was about the ESP-IDF

https://www.youtube.com/watch?v=Lc6ausiKvQM

At the end of doing all the steps i am able to install and compile the "blink" project provided in examples .

But the issue i faced is that when i downloaded in to my esp32-c3 board . I got the following error as attached image file .

screenshot

After that i followed your full video . And when i made changes in "Target.cmake" file as mentioned by you and compile the " blink "project. Then i got the following error .
esp32_c3

Thanks in Advance for your help!

Thank you so much ! for your support and wonderful job! when i followed your video then i am able to see

I (121355) example: Turning the LED ON!
I (122355) example: Turning the LED OFF!
I (123355) example: Turning the LED ON!
I (124355) example: Turning the LED OFF!

Sorry ! it was my mistake ,i selected ESP-IDF version 4.2 . it must be selected master (development board ) .

thanks Again !

Best Regards !

Muhammad Usman

@iamcalledusman
Copy link

Hi @Anwaarullah!

Thank you so much ! for your support and wonderful job! when i followed your video then i am able to see

I (121355) example: Turning the LED ON!
I (122355) example: Turning the LED OFF!
I (123355) example: Turning the LED ON!
I (124355) example: Turning the LED OFF!

Sorry ! it was my mistake ,i selected ESP-IDF version 4.2 . it must be selected master (development board ) .

thanks Again !

Best Regards !

Muhammad Usman

@Anwaarullah
Copy link
Author

Thanks for sharing what caused the issue and how you solved it.

@iamcalledusman
Copy link

Hi @Anwaarullah Again !

Led Blink Example worked well ! But when i compiled the "Hello_World" then it gives the following error

-T esp32c3.peripherals.ld -L C:/Users/luisr/esp/esp-idf/components/esp_rom/esp32c3/ld -T esp32c3.rom.ld -T esp32c3.rom.api.ld -T esp32c3.rom.libgcc.ld -T esp32c3.rom.newlib.ld -L C:/Users/luisr/esp/esp-idf/components/bootloader/subproject/main/ld/esp32c3 -T bootloader.ld && cd ."
riscv32-esp-elf-gcc.exe: error: world/hello_world/build/bootloader/bootloader.map: No such file or directory
ninja: build stopped: subcommand failed.
[2/332] Linking C static library esp-idf\soc\libsoc.a
ninja: build stopped: subcommand failed.
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command cmake --build ." terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Can you please help me in this regard ?

Thanks

@iamcalledusman
Copy link

Hi, @Anwaarullah Again!

Need your help, as I mentioned at the start of this post that issue was resolved. After 2 months of working ESP-IDF stop working by generating errors. So I have to reinstall the esp-IDF and espressif tools. But unfortunately, esp32_c3 reboots again and again with the same error as mentioned at the start of the post. Can you help me in this regard?

111253006-3032f780-8634-11eb-9ad9-304368e1af83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment