Added toolchain file
This commit is contained in:
parent
7ef358200b
commit
bc8ee016f3
1 changed files with 151 additions and 0 deletions
151
riscv32-toolchain.cmake
Normal file
151
riscv32-toolchain.cmake
Normal file
|
@ -0,0 +1,151 @@
|
|||
# ###############################
|
||||
# WCH(RISC-V) toolchain file for the ch32v003
|
||||
# ###############################
|
||||
|
||||
# ----------------------------------------
|
||||
# File: riscv64-toolchain.cmake
|
||||
# Description: Cmake file for the WCH controllers. It has two differnt
|
||||
# types of kinds things it can output. It can output or build release binaries
|
||||
# or it output debug builds.
|
||||
# ----------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
##################################################
|
||||
# Configurable Section
|
||||
##################################################
|
||||
# Specify the cross-compiler
|
||||
#set(CROSS_TOOLCHAIN riscv32-unknown-elf-)
|
||||
#set(CROSS_TOOLCHAIN riscv64-unknown-elf-)
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR riscv)
|
||||
set(CMAKE_SYSTEM_PROCESSOR "CUSTOM")
|
||||
set(DEBUG_BINARY 1)
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
|
||||
|
||||
|
||||
# This logic checks the operating system.
|
||||
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD")
|
||||
message("OS:: FreeBSD")
|
||||
set(NEWLIB /usr/local/riscv/riscv64-unknown-elf/include)
|
||||
set(CMAKE_C_COMPILER riscv64-unknown-elf-gcc)
|
||||
set(CMAKE_CXX_COMPILER riscv64-unknown-elf-g++)
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/local/riscv/)
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${NEWLIB}")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${NEWLIB}")
|
||||
# Without these two lines it freaks out.
|
||||
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT GNU)
|
||||
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT GNU)
|
||||
|
||||
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
|
||||
message("OS:: LINUX")
|
||||
else()
|
||||
message("OS:: UNKNOWN?")
|
||||
message("Please add your OS details to the toolchain file.")
|
||||
endif()
|
||||
|
||||
# Find the Newlib
|
||||
|
||||
# Find the ch32v003fun
|
||||
|
||||
#
|
||||
|
||||
|
||||
# ----------------------------------------
|
||||
# MCU Setup
|
||||
# ----------------------------------------
|
||||
|
||||
|
||||
#this really shouldn't be needed as it's also defined in the
|
||||
# `/inc/funconfig.h` file.
|
||||
|
||||
# Specify the exact Chip
|
||||
#set(MCU CH32V003J4M6)
|
||||
#set(MCU CH32V003A4M6)
|
||||
#set(MCU CH32V003F4P6)
|
||||
#set(MCU CH32V003F4U6)
|
||||
set(MCU CH32V003)
|
||||
|
||||
#Define it for the preprocessor as well.
|
||||
add_compile_definitions(${MCU})
|
||||
|
||||
#add_definitions(-D${MCU})
|
||||
|
||||
|
||||
##################################################
|
||||
# Advanced Section
|
||||
##################################################
|
||||
|
||||
|
||||
|
||||
#-------------------
|
||||
# General Flags
|
||||
#-------------------
|
||||
|
||||
set(OBJECT_GEN_FLAGS "\
|
||||
-g \
|
||||
-Os \
|
||||
-flto \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-fmessage-length=0 \
|
||||
-msmall-data-limit=8 ")
|
||||
|
||||
#-------------------
|
||||
# CFLAGS for ARCH
|
||||
#-------------------
|
||||
|
||||
set(C_FLAGS_ARCH "\
|
||||
-march=rv32ec \
|
||||
-mabi=ilp32e \
|
||||
-I${NEWLIB} \
|
||||
-nostdlib")
|
||||
|
||||
#-------------------
|
||||
# CFLAGS
|
||||
#-------------------
|
||||
|
||||
# I'm appending to the existing cflags from the cmake file in the root dir.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
${C_FLAGS_ARCH} \
|
||||
${OBJECT_GEN_FLAGS}")
|
||||
|
||||
|
||||
#-------------------
|
||||
# ASMFLAGS for cross
|
||||
#-------------------
|
||||
|
||||
|
||||
#-------------------
|
||||
# LFLAGS for cross
|
||||
#-------------------
|
||||
|
||||
#set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_SCRIPT})
|
||||
set(LINKER_SCRIPT "./src/ch32v003.ld")
|
||||
|
||||
#set(LD_FLAGS "-lgcc")
|
||||
set(LD_FLAGS " \
|
||||
-Wl,--print-memory-usage \
|
||||
-Wl,-Map=${PROJECT_NAME}.map \
|
||||
-lgcc \
|
||||
-T ${LINKER_SCRIPT} \
|
||||
-Wl,--gc-sections")
|
||||
|
||||
|
||||
|
||||
#-------------------
|
||||
# Print out info
|
||||
#-------------------
|
||||
|
||||
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
|
||||
message(STATUS "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}")
|
||||
message(STATUS "CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}")
|
||||
|
||||
|
||||
|
||||
# Unset all cache
|
||||
unset(SEMIHOSTING)
|
||||
unset(CMAKE_TOOLCHAIN_FILE)
|
||||
unset(CMAKE_BUILD_TYPE)
|
Loading…
Add table
Reference in a new issue