Compare commits
No commits in common. "b7debf7eeeded0b10e5b5e12581f343aaab60986" and "7a42fb4780ed9222f46a978622b8b781d04f587b" have entirely different histories.
b7debf7eee
...
7a42fb4780
5 changed files with 46 additions and 307 deletions
|
@ -1,122 +0,0 @@
|
|||
ENTRY( InterruptVector )
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 16K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 2K
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.init :
|
||||
{
|
||||
_sinit = .;
|
||||
. = ALIGN(4);
|
||||
KEEP(*(SORT_NONE(.init)))
|
||||
. = ALIGN(4);
|
||||
_einit = .;
|
||||
} >FLASH AT>FLASH
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.rodata)
|
||||
*(.rodata*)
|
||||
*(.gnu.linkonce.t.*)
|
||||
. = ALIGN(4);
|
||||
} >FLASH AT>FLASH
|
||||
.fini :
|
||||
{
|
||||
KEEP(*(SORT_NONE(.fini)))
|
||||
. = ALIGN(4);
|
||||
} >FLASH AT>FLASH
|
||||
PROVIDE( _etext = . );
|
||||
PROVIDE( _eitcm = . );
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH AT>FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH AT>FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
|
||||
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH AT>FLASH
|
||||
.ctors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
} >FLASH AT>FLASH
|
||||
.dtors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
} >FLASH AT>FLASH
|
||||
.dalign :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE(_data_vma = .);
|
||||
} >RAM AT>FLASH
|
||||
.dlalign :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE(_data_lma = .);
|
||||
} >FLASH AT>FLASH
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__global_pointer$ = . + 0x3fc;
|
||||
*(.gnu.linkonce.r.*)
|
||||
*(.data .data.*)
|
||||
*(.gnu.linkonce.d.*)
|
||||
. = ALIGN(8);
|
||||
*(.sdata .sdata.*)
|
||||
*(.sdata2*)
|
||||
*(.gnu.linkonce.s.*)
|
||||
. = ALIGN(8);
|
||||
*(.srodata.cst16)
|
||||
*(.srodata.cst8)
|
||||
*(.srodata.cst4)
|
||||
*(.srodata.cst2)
|
||||
*(.srodata .srodata.*)
|
||||
. = ALIGN(4);
|
||||
PROVIDE( _edata = .);
|
||||
} >RAM AT>FLASH
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE( _sbss = .);
|
||||
*(.sbss*)
|
||||
*(.gnu.linkonce.sb.*)
|
||||
*(.bss*)
|
||||
*(.gnu.linkonce.b.*)
|
||||
*(COMMON*)
|
||||
. = ALIGN(4);
|
||||
PROVIDE( _ebss = .);
|
||||
} >RAM AT>FLASH
|
||||
PROVIDE( _end = _ebss);
|
||||
PROVIDE( end = . );
|
||||
PROVIDE( _eusrstack = ORIGIN(RAM) + LENGTH(RAM));
|
||||
/DISCARD/ : {
|
||||
*(.note .note.*)
|
||||
*(.eh_frame .eh_frame.*)
|
||||
*(.comment .comment.*)
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
*(.ARM.exidx*)
|
||||
}
|
||||
}
|
|
@ -33,7 +33,8 @@ if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD")
|
|||
set(CMAKE_C_COMPILER riscv32-unknown-elf-gcc)
|
||||
set(CMAKE_CXX_COMPILER riscv32-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)
|
||||
|
@ -43,8 +44,6 @@ elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
|
|||
set(NEWLIB /opt/riscv/riscv32-unknown-elf/include)
|
||||
set(CMAKE_C_COMPILER riscv32-unknown-elf-gcc)
|
||||
set(CMAKE_CXX_COMPILER riscv32-unknown-elf-g++)
|
||||
|
||||
# Without these two lines it freaks out.
|
||||
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT GNU)
|
||||
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT GNU)
|
||||
else()
|
||||
|
@ -68,10 +67,14 @@ endif()
|
|||
# `/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}=1)
|
||||
add_compile_definitions(${MCU})
|
||||
|
||||
#add_definitions(-D${MCU})
|
||||
|
||||
|
@ -110,7 +113,9 @@ set(C_FLAGS_ARCH "\
|
|||
#-------------------
|
||||
|
||||
# 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}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
${C_FLAGS_ARCH} \
|
||||
${OBJECT_GEN_FLAGS}")
|
||||
|
||||
|
||||
#-------------------
|
||||
|
@ -123,8 +128,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS_ARCH} ${OBJECT_GEN_FLAGS}")
|
|||
#-------------------
|
||||
|
||||
#set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_SCRIPT})
|
||||
#set(LINKER_SCRIPT "./src/ch32v003.ld")
|
||||
set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/src/linker_script.ld")
|
||||
set(LINKER_SCRIPT "./src/ch32v003.ld")
|
||||
|
||||
#set(LD_FLAGS "-lgcc")
|
||||
set(LD_FLAGS " \
|
||||
|
@ -132,21 +136,8 @@ set(LD_FLAGS " \
|
|||
-Wl,-Map=${PROJECT_NAME}.map \
|
||||
-lgcc \
|
||||
-T ${LINKER_SCRIPT} \
|
||||
-Wl,--gc-sections"
|
||||
)
|
||||
-Wl,--gc-sections")
|
||||
|
||||
#Allowing this line causes it to attempt compiler tests and if
|
||||
# tosses errors.
|
||||
|
||||
#set(CMAKE_EXE_LINKER_FLAGS_INIT "${LD_FLAGS}")
|
||||
|
||||
|
||||
#target_link_options(my_project PRIVATE -static -nostartfiles -T linker_script.ld)
|
||||
#set(CMAKE_EXE_LINKER_FLAGS_INIT "${LD_FLAGS}")
|
||||
#set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/src/linker_script.ld")
|
||||
|
||||
#set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/linker_script.ld")
|
||||
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${LINKER_SCRIPT}")
|
||||
|
||||
|
||||
#-------------------
|
||||
|
@ -158,7 +149,8 @@ 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)
|
||||
unset(SEMIHOSTING)
|
||||
unset(CMAKE_TOOLCHAIN_FILE)
|
||||
unset(CMAKE_BUILD_TYPE)
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
# Compiler flags
|
||||
add_compile_options(
|
||||
-g
|
||||
-Os
|
||||
-flto
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-fmessage-length=0
|
||||
-msmall-data-limit=8
|
||||
-march=rv32ec
|
||||
-mabi=ilp32e
|
||||
-DCH32V003=1
|
||||
-static-libgcc
|
||||
-nostdlib
|
||||
-Wall
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.c
|
||||
|
@ -14,35 +30,11 @@ target_link_libraries(${PROJECT_NAME}
|
|||
#${CMAKE_SOURCE_DIR}/libgcc.a
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
-Wl,--print-memory-usage
|
||||
-Wl,-Map=${PROJECT_NAME}.map
|
||||
-lgcc
|
||||
-Wl,--gc-sections
|
||||
-T ${CMAKE_SOURCE_DIR}/src/linker_script.ld
|
||||
)
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
-g
|
||||
-Os
|
||||
-flto
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-fmessage-length=0
|
||||
-msmall-data-limit=8
|
||||
-march=rv32ec
|
||||
-mabi=ilp32e
|
||||
-DCH32V003=1
|
||||
-static-libgcc
|
||||
-nostdlib
|
||||
-Wall
|
||||
)
|
||||
target_link_options(${PROJECT_NAME} PRIVATE -static-libgcc)
|
||||
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".elf")
|
||||
|
||||
#target_link_options(${PROJECT_NAME} PRIVATE -static -nostartfiles -T "./linker_script.ld")
|
||||
|
||||
# The other "targets" are size, upload, debug, production, etc
|
||||
|
||||
#if(NOT TARGET size)
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
|
||||
add_library(ch32fun OBJECT
|
||||
ch32fun.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32fun PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_SOURCE_DIR}/inc
|
||||
${CMAKE_SOURCE_DIR}/src/extralibs
|
||||
${CMAKE_SOURCE_DIR}/src/ch32fun
|
||||
)
|
||||
|
||||
target_compile_options(ch32fun PRIVATE
|
||||
# Compiler flags
|
||||
add_compile_options(
|
||||
-g
|
||||
-Os
|
||||
-flto
|
||||
|
@ -26,7 +15,17 @@ target_compile_options(ch32fun PRIVATE
|
|||
-Wall
|
||||
)
|
||||
|
||||
add_library(ch32fun OBJECT
|
||||
ch32fun.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32fun PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_SOURCE_DIR}/inc
|
||||
${CMAKE_SOURCE_DIR}/src/extralibs
|
||||
${CMAKE_SOURCE_DIR}/src/ch32fun
|
||||
)
|
||||
|
||||
#target_link_libraries(ch32fun PRIVATE
|
||||
# ${CMAKE_SOURCE_DIR}/libgcc.a
|
||||
#)
|
||||
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
ENTRY( InterruptVector )
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 16K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 2K
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.init :
|
||||
{
|
||||
_sinit = .;
|
||||
. = ALIGN(4);
|
||||
KEEP(*(SORT_NONE(.init)))
|
||||
. = ALIGN(4);
|
||||
_einit = .;
|
||||
} >FLASH AT>FLASH
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.rodata)
|
||||
*(.rodata*)
|
||||
*(.gnu.linkonce.t.*)
|
||||
. = ALIGN(4);
|
||||
} >FLASH AT>FLASH
|
||||
.fini :
|
||||
{
|
||||
KEEP(*(SORT_NONE(.fini)))
|
||||
. = ALIGN(4);
|
||||
} >FLASH AT>FLASH
|
||||
PROVIDE( _etext = . );
|
||||
PROVIDE( _eitcm = . );
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH AT>FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH AT>FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
|
||||
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH AT>FLASH
|
||||
.ctors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
} >FLASH AT>FLASH
|
||||
.dtors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
} >FLASH AT>FLASH
|
||||
.dalign :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE(_data_vma = .);
|
||||
} >RAM AT>FLASH
|
||||
.dlalign :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE(_data_lma = .);
|
||||
} >FLASH AT>FLASH
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__global_pointer$ = . + 0x3fc;
|
||||
*(.gnu.linkonce.r.*)
|
||||
*(.data .data.*)
|
||||
*(.gnu.linkonce.d.*)
|
||||
. = ALIGN(8);
|
||||
*(.sdata .sdata.*)
|
||||
*(.sdata2*)
|
||||
*(.gnu.linkonce.s.*)
|
||||
. = ALIGN(8);
|
||||
*(.srodata.cst16)
|
||||
*(.srodata.cst8)
|
||||
*(.srodata.cst4)
|
||||
*(.srodata.cst2)
|
||||
*(.srodata .srodata.*)
|
||||
. = ALIGN(4);
|
||||
PROVIDE( _edata = .);
|
||||
} >RAM AT>FLASH
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE( _sbss = .);
|
||||
*(.sbss*)
|
||||
*(.gnu.linkonce.sb.*)
|
||||
*(.bss*)
|
||||
*(.gnu.linkonce.b.*)
|
||||
*(COMMON*)
|
||||
. = ALIGN(4);
|
||||
PROVIDE( _ebss = .);
|
||||
} >RAM AT>FLASH
|
||||
PROVIDE( _end = _ebss);
|
||||
PROVIDE( end = . );
|
||||
PROVIDE( _eusrstack = ORIGIN(RAM) + LENGTH(RAM));
|
||||
/DISCARD/ : {
|
||||
*(.note .note.*)
|
||||
*(.eh_frame .eh_frame.*)
|
||||
*(.comment .comment.*)
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
*(.ARM.exidx*)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue