diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-19 00:03:18 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-19 00:03:18 -0700 |
commit | e5d891fbb9c672cf8c5ec31d7540a9e55747b3a0 (patch) | |
tree | cf95d840084dbcc10fc0e1fe0d0b0c80e1e23b95 | |
parent | e4a979594d3df9e158051636a373501942caf044 (diff) | |
download | ch573-e5d891fbb9c672cf8c5ec31d7540a9e55747b3a0.tar.gz ch573-e5d891fbb9c672cf8c5ec31d7540a9e55747b3a0.tar.bz2 ch573-e5d891fbb9c672cf8c5ec31d7540a9e55747b3a0.zip |
Switch to use CMake
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 58 | ||||
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | linker/ls.ld (renamed from ls.ld) | 0 | ||||
-rw-r--r-- | src/blinky.c (renamed from blinky.c) | 2 |
5 files changed, 60 insertions, 21 deletions
@@ -1,3 +1,4 @@ *.o *.elf *.bin +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ee1147f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.10) +project (ch537) + +set (CMAKE_SYSTEM_NAME Generic) # Configure for Bare Metal. +set (CMAKE_SYSTEM_PROCESSOR riscv32) + +set (TC_PREFIX riscv32-unknown-elf-) +# set (CMAKE_VERBOSE_MAKEFILE ON) + +include_directories(include linker) + +file (GLOB SOURCES "src/*.c") +file (GLOB LINKER_SCRIPT "linker/*.ld") + +file (REAL_PATH "ch-flash/" CH_FLASH_DIR) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_C_FLAGS "-march=rv32imac -mabi=ilp32 -lgcc -static -nostartfiles -O -std=gnu99" CACHE INTERNAL "C Compiler options") +set(CMAKE_EXE_LINKER_FLAGS "--cref -static -T ${LINKER_SCRIPT}" CACHE INTERNAL "Linker options") + +set (CMAKE_C_COMPILER ${TC_PREFIX}gcc CACHE INTERNAL "C Compiler") +set (CMAKE_OBJCOPY ${TC_PREFIX}objcopy CACHE INTERNAL "Object Copier") +set (CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type") + +set (CMAKE_C_LINK_EXECUTABLE "${TC_PREFIX}ld <LINK_FLAGS> <OBJECTS> -o <TARGET>") +add_executable(main.elf ${SOURCES}) +set_target_properties(main.elf PROPERTIES + LINK_FLAGS "--nostdlib -e 0") + +# Generates the binary with objcopy. +add_custom_command( + OUTPUT main.bin + DEPENDS main.elf + COMMENT "objcopy -O binary main.elf main.bin" + COMMAND ${CMAKE_OBJCOPY} ARGS -O binary main.elf main.bin +) +add_custom_command( + OUTPUT objdump.txt + DEPENDS main.elf + COMMAND ${TC_PREFIX}objdump -D main.elf > objdump.txt +) +add_custom_target(main_bin ALL DEPENDS main.bin objdump.txt) + +# generates the flash binary +add_custom_command( + OUTPUT ${CH_FLASH_DIR}/ch-flash + COMMAND cd ${CH_FLASH_DIR} && make +) + +add_custom_target( + flash + DEPENDS main.bin ch-flash/ch-flash + COMMAND ${CH_FLASH_DIR}/ch-flash -f main.bin +) + +# add_custom_target( +# debug +# COMMAND "${TC_PREFIX}gdb" -tui -ex "tar ext :3333" -ex "file main.elf") diff --git a/Makefile b/Makefile deleted file mode 100644 index ce65816..0000000 --- a/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -CC=riscv32-unknown-elf-gcc -LD=riscv32-unknown-elf-ld -CPY=riscv32-unknown-elf-objcopy - -all: blinky.bin - -blinky.bin: blinky.elf - $(CPY) -O binary blinky.elf blinky.bin - -blinky.o: blinky.c - $(CC) -Os -lgcc -static -nostartfiles -o blinky.o -c blinky.c - -blinky.elf: blinky.o ls.ld - $(LD) --cref -static -T ls.ld -o blinky.elf blinky.o - -flash: all - sudo ~/Projects/isp55e0/isp55e0 -f blinky.bin - -clean: - rm -rf *.o *.elf *.bin @@ -85,6 +85,6 @@ __attribute((naked)) void on_reset(void) void delay(void) { - for (volatile uint32_t i = 0; i < 20000; ++i) + for (volatile uint32_t i = 0; i < 10000; ++i) ; } |