2024-05-15 20:13:00 +07:00
|
|
|
# https://www.embecosm.com/resources/tool-chain-downloads/#riscv-stable
|
|
|
|
#CROSS_COMPILE ?= riscv32-unknown-elf-
|
|
|
|
|
|
|
|
# Toolchain from https://nucleisys.com/download.php
|
|
|
|
#CROSS_COMPILE ?= riscv-nuclei-elf-
|
|
|
|
|
2023-11-19 18:26:40 -08:00
|
|
|
# Toolchain from https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack
|
|
|
|
CROSS_COMPILE ?= riscv-none-elf-
|
|
|
|
|
2024-05-20 13:24:24 +07:00
|
|
|
CH32_FAMILY = ch32v20x
|
|
|
|
SDK_DIR = hw/mcu/wch/ch32v20x
|
|
|
|
SDK_SRC_DIR = $(SDK_DIR)/EVT/EXAM/SRC
|
2023-11-19 18:26:40 -08:00
|
|
|
|
|
|
|
include $(TOP)/$(BOARD_PATH)/board.mk
|
2024-05-15 20:13:00 +07:00
|
|
|
CPU_CORE ?= rv32imac-ilp32
|
2023-11-19 18:26:40 -08:00
|
|
|
|
|
|
|
CFLAGS += \
|
|
|
|
-mcmodel=medany \
|
|
|
|
-ffunction-sections \
|
|
|
|
-fdata-sections \
|
|
|
|
-ffat-lto-objects \
|
|
|
|
-flto \
|
2024-05-20 13:24:24 +07:00
|
|
|
-DCH32V20x_${MCU_VARIANT} \
|
2023-11-19 18:26:40 -08:00
|
|
|
-DCFG_TUSB_MCU=OPT_MCU_CH32V20X \
|
|
|
|
-DBOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED \
|
|
|
|
|
|
|
|
LDFLAGS_GCC += \
|
2024-05-15 20:13:00 +07:00
|
|
|
-nostdlib -nostartfiles \
|
|
|
|
--specs=nosys.specs --specs=nano.specs \
|
2023-11-19 18:26:40 -08:00
|
|
|
|
2024-05-20 13:24:24 +07:00
|
|
|
LD_FILE = $(FAMILY_PATH)/linker/${CH32_FAMILY}.ld
|
2023-11-19 18:26:40 -08:00
|
|
|
|
|
|
|
SRC_C += \
|
|
|
|
src/portable/wch/dcd_ch32_usbfs.c \
|
2024-05-20 13:24:24 +07:00
|
|
|
$(SDK_SRC_DIR)/Core/core_riscv.c \
|
|
|
|
$(SDK_SRC_DIR)/Peripheral/src/ch32v20x_gpio.c \
|
|
|
|
$(SDK_SRC_DIR)/Peripheral/src/ch32v20x_misc.c \
|
|
|
|
$(SDK_SRC_DIR)/Peripheral/src/ch32v20x_rcc.c \
|
|
|
|
$(SDK_SRC_DIR)/Peripheral/src/ch32v20x_usart.c \
|
|
|
|
|
|
|
|
SRC_S += $(SDK_SRC_DIR)/Startup/startup_ch32v20x_${MCU_VARIANT}.S
|
2023-11-19 18:26:40 -08:00
|
|
|
|
|
|
|
INC += \
|
|
|
|
$(TOP)/$(BOARD_PATH) \
|
2024-05-20 13:24:24 +07:00
|
|
|
$(TOP)/$(SDK_SRC_DIR)/Peripheral/inc \
|
2023-11-19 18:26:40 -08:00
|
|
|
|
|
|
|
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/RISC-V
|
|
|
|
|
|
|
|
# wch-link is not supported yet in official openOCD yet. We need to either use
|
|
|
|
# 1. download openocd as part of mounriver studio http://www.mounriver.com/download or
|
|
|
|
# 2. compiled from modified source https://github.com/dragonlock2/miscboards/blob/main/wch/SDK/riscv-openocd.tar.xz
|
2024-05-15 20:13:00 +07:00
|
|
|
OPENOCD ?= $(HOME)/app/riscv-openocd-wch/src/openocd
|
2023-11-19 18:26:40 -08:00
|
|
|
flash: $(BUILD)/$(PROJECT).elf
|
2024-05-15 20:13:00 +07:00
|
|
|
$(OPENOCD) -f $(TOP)/$(FAMILY_PATH)/wch-riscv.cfg -c init -c halt -c "flash write_image $<" -c reset -c exit
|