forked from WCH-Templates/CH32V203
Updated CMakeLists to work with upstream GCC >=12
The original march option was wrong (RV32E). According to WCH, the instruction set is RV32IMAC. Updating the GCC version broke a ton of things since it better complied with stack alignment requirements that RV32E had, which RV32I was not compatible with. Additionally, newer versions of the RISC-V ISA spec split off the Zicsr and Zifencei instruction from RV32I. GCC versions 12 and newer began using this spec, leading to missing opcode errors. Lastly, "--specs=nosys.specs" and "--specs=nano.specs" allegedly don't go together, and nano is apparently preferred. Also "-mcmodel=medany" is needed apparently. See https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html#index-mcmodel_003dmedany
This commit is contained in:
parent
5aeffc6277
commit
95f0acc88c
1 changed files with 8 additions and 7 deletions
|
@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.10)
|
|||
project(hello-world)
|
||||
|
||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
set(CMAKE_C_COMPILER riscv-none-embed-gcc)
|
||||
set(CMAKE_CXX_COMPILER riscv-none-embed-gcc)
|
||||
set(CMAKE_OBJCOPY riscv-none-embed-objcopy)
|
||||
set(CMAKE_SIZE riscv-none-embed-size)
|
||||
set(CMAKE_C_COMPILER riscv-none-elf-gcc)
|
||||
set(CMAKE_CXX_COMPILER riscv-none-elf-gcc)
|
||||
set(CMAKE_OBJCOPY riscv-none-elf-objcopy)
|
||||
set(CMAKE_SIZE riscv-none-elf-size)
|
||||
|
||||
set_property(SOURCE Startup/startup_ch32v20x_D6.S PROPERTY LANGUAGE C)
|
||||
|
||||
|
@ -21,7 +21,7 @@ include_directories(Peripheral/inc)
|
|||
|
||||
add_definitions(-finline-functions-called-once -g)
|
||||
|
||||
add_definitions(-Wall -march=rv32ec -mabi=ilp32e -msmall-data-limit=0 -msave-restore -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common)
|
||||
add_definitions(-Wall -Wextra -march=rv32imac_zicsr_zifencei -mabi=ilp32 -msmall-data-limit=0 -msave-restore -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -mcmodel=medany --specs=nano.specs)
|
||||
|
||||
file(GLOB SOURCES "Debug/*.c" "Core/*.c" "User/*.c" "Peripheral/src/*.c" "Startup/*.S")
|
||||
|
||||
|
@ -34,5 +34,6 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.siz
|
|||
COMMAND ${CMAKE_SIZE}
|
||||
ARGS --format=berkeley ${CMAKE_PROJECT_NAME}.elf)
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME}.elf ${SOURCES})
|
||||
target_link_options(${CMAKE_PROJECT_NAME}.elf PRIVATE -T ${CMAKE_SOURCE_DIR}/Ld/Link.ld -Os -march=rv32ec -mabi=ilp32e -nostartfiles -Xlinker -gc-sections -static --specs=nano.specs --specs=nosys.specs)
|
||||
add_executable(${CMAKE_PROJECT_NAME}.elf ${SOURCES})
|
||||
|
||||
target_link_options(${CMAKE_PROJECT_NAME}.elf PRIVATE -T ${CMAKE_SOURCE_DIR}/Ld/Link.ld -Os -march=rv32imac_zicsr_zifencei -mabi=ilp32 -mstrict-align -nostartfiles -Xlinker -gc-sections -static --specs=nano.specs -mcmodel=medany)
|
||||
|
|
Loading…
Reference in a new issue