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

esp32-p4 support - march=rv32imafc #19

Closed
georgik opened this issue Jun 21, 2024 · 3 comments · Fixed by #25
Closed

esp32-p4 support - march=rv32imafc #19

georgik opened this issue Jun 21, 2024 · 3 comments · Fixed by #25
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@georgik
Copy link

georgik commented Jun 21, 2024

The build of ESP32 Led strip example for ESP32-P4 which is RISC-V IMACF requires:

  1. Correction in linker mentioned in esp32-led-strip-sdk unable to build in VS Code using PlatformIO #17 (comment)

  2. Correction of build script, because of linking problem:

esp-idf/main/_swiftcode.o: can't link soft-float modules with single-float modules
failed to merge target specific data of file esp-idf/main/_swiftcode.o

The solution is to add -Xcc -march=rv32imafc -Xcc -mabi=ilp32f to the swiftc command line to ensure the Swift compiler uses the same architecture and ABI as the C and C++ compilers.
Plus, add -Xlinker -march=rv32imafc -Xlinker -mabi=ilp32f to pass these flags to the linker.

Updated main/CMakeLists.txt look like this:

idf_component_register(
    SRCS "Dummy.c"
    INCLUDE_DIRS "."
)

execute_process(COMMAND xcrun -f swiftc OUTPUT_VARIABLE SWIFTC OUTPUT_STRIP_TRAILING_WHITESPACE)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_swiftcode.o
    COMMAND
        ${SWIFTC}
        -target riscv32-none-none-eabi
        -Xfrontend -function-sections -enable-experimental-feature Embedded -wmo -parse-as-library -Osize
        -Xcc -march=rv32imafc -Xcc -mabi=ilp32f
        -Xlinker -march=rv32imafc -Xlinker -mabi=ilp32f
        $$\( echo '$<TARGET_PROPERTY:__idf_main,INCLUDE_DIRECTORIES>' | tr '\;' '\\n' | sed -e 's/\\\(.*\\\)/-Xcc -I\\1/g' \)
        $$\( echo '${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}'           | tr ' '  '\\n' | sed -e 's/\\\(.*\\\)/-Xcc -I\\1/g' \)
        -import-bridging-header ${CMAKE_CURRENT_LIST_DIR}/BridgingHeader.h
        ${CMAKE_CURRENT_LIST_DIR}/Main.swift
        ${CMAKE_CURRENT_LIST_DIR}/LedStrip.swift
        -c -o ${CMAKE_CURRENT_BINARY_DIR}/_swiftcode.o
    DEPENDS
        ${CMAKE_CURRENT_LIST_DIR}/BridgingHeader.h
        ${CMAKE_CURRENT_LIST_DIR}/Main.swift
        ${CMAKE_CURRENT_LIST_DIR}/LedStrip.swift
)
add_custom_target(main-swiftcode DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_swiftcode.o)

target_link_libraries(__idf_main
    ${CMAKE_CURRENT_BINARY_DIR}/_swiftcode.o
)
add_dependencies(__idf_main main-swiftcode)
@rauhul
Copy link
Collaborator

rauhul commented Jun 21, 2024

Is there a way we can adjust this Cmake file to support both boards?

@erhankur
Copy link
Contributor

Quick solution;

idf_component_register(
    SRCS "Dummy.c"
    INCLUDE_DIRS "."
)

idf_build_get_property(target IDF_TARGET)
idf_build_get_property(arch IDF_TARGET_ARCH)

if("${arch}" STREQUAL "xtensa")
    message(FATAL_ERROR "Target not supported ${target}")
endif()

if(${target} STREQUAL "esp32c2" OR ${target} STREQUAL "esp32c3")
    set(march_flag "rv32imc_zicsr_zifencei")
    set(mabi_flag "ilp32")
elseif(${target} STREQUAL "esp32p4")
    set(march_flag "rv32imafc_zicsr_zifencei")
    set(mabi_flag "ilp32f")
else()
    set(march_flag "rv32imac_zicsr_zifencei")
    set(mabi_flag "ilp32")
endif()

#execute_process(COMMAND xcrun -f swiftc OUTPUT_VARIABLE SWIFTC OUTPUT_STRIP_TRAILING_WHITESPACE)
set(SWIFTC $ENV{TOOLCHAINS}/usr/bin/swiftc)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_swiftcode.o
    COMMAND
        ${SWIFTC}
        -target riscv32-none-none-eabi
        -Xfrontend -function-sections -enable-experimental-feature Embedded -static -wmo -parse-as-library -Osize
        -Xcc -march=${march_flag} -Xcc -mabi=${mabi_flag}
        -Xlinker -march=${march_flag} -Xlinker -mabi=${mabi_flag}
        .....

@rauhul
Copy link
Collaborator

rauhul commented Jun 28, 2024

@erhankur would you be interested in submitting a PR which includes these changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants