Skip to content

esp32-p4 support - march=rv32imafc #19

Description

@georgik

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions