build.mk 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ##### Put your SoC build configurations below #####
  2. BOARD ?= gd32vf103v_rvstar
  3. # Variant for Board or SoC
  4. VARIANT ?=
  5. # Please overwrite following variable in Makefile of your application
  6. # System Clock Frequency
  7. # 108MHz in pure int value
  8. SYSCLK ?= 108000000
  9. # Clock source
  10. CLKSRC ?= hxtal
  11. # Don't set HXTAL_VALUE unless you know what you are doing
  12. # when not empty it will define macro HXTAL_VALUE
  13. # see SoC/gd32vf103/Common/Include/gd32vf103_rcu.h
  14. HXTAL_VALUE ?=
  15. # Select USB host or device driver
  16. # host: select host driver
  17. # device: select device driver
  18. # both: select both
  19. USB_DRIVER ?=
  20. # override DOWNLOAD and CORE variable for GD32VF103 SoC
  21. # even though it was set with a command argument
  22. override CORE := n203
  23. override DOWNLOAD := flashxip
  24. DEFAULT_BOARD := gd32vf103v_rvstar
  25. NUCLEI_SDK_SOC_BOARD := $(NUCLEI_SDK_SOC)/Board/$(BOARD)
  26. NUCLEI_SDK_SOC_COMMON := $(NUCLEI_SDK_SOC)/Common
  27. VALID_NUCLEI_SDK_SOC_BOARD := $(wildcard $(NUCLEI_SDK_SOC_BOARD))
  28. ifeq ($(VALID_NUCLEI_SDK_SOC_BOARD),)
  29. $(warning $(BOARD) for $(SOC) doesn't exist, change it to default $(DEFAULT_BOARD)!)
  30. override NUCLEI_SDK_SOC_BOARD := $(NUCLEI_SDK_SOC)/Board/$(DEFAULT_BOARD)
  31. override VALID_NUCLEI_SDK_SOC_BOARD := $(NUCLEI_SDK_SOC_BOARD)
  32. endif
  33. OPENOCD_CFG ?= $(NUCLEI_SDK_SOC_BOARD)/openocd_gd32vf103.cfg
  34. # Misc fixup for board variant
  35. ifeq ($(BOARD), gd32vf103c_longan_nano)
  36. # Board gd32vf103c_longan_nano
  37. ifeq ($(VARIANT), lite)
  38. LINKER_SCRIPT ?= $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/gcc_gd32vf103x8_flashxip.ld
  39. else
  40. LINKER_SCRIPT ?= $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/gcc_gd32vf103xb_flashxip.ld
  41. endif
  42. else # other boards except gd32vf103c_longan_nano
  43. LINKER_SCRIPT ?= $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/gcc_gd32vf103_$(DOWNLOAD).ld
  44. endif
  45. # File existence check for OPENOCD_CFG and LINKER_SCRIPT
  46. ifeq ($(wildcard $(OPENOCD_CFG)),)
  47. $(error The openocd configuration file $(OPENOCD_CFG) for $(SOC) doesn't exist, please check!)
  48. endif
  49. # Allow non-existance of LINKER_SCRIPT, it might be generated
  50. ifeq ($(wildcard $(LINKER_SCRIPT)),)
  51. $(warning The link script file $(LINKER_SCRIPT) for $(SOC) doesn't exist, please check!)
  52. endif
  53. # if JTAGSN is not empty, pass it via openocd command
  54. ifneq ($(JTAGSN),)
  55. OPENOCD_CMD_ARGS += set JTAGSN $(JTAGSN);
  56. endif
  57. # Set RISCV_ARCH and RISCV_ABI
  58. CORE_UPPER := $(call uc, $(CORE))
  59. RISCV_ARCH ?= rv32imac
  60. RISCV_ABI ?= ilp32
  61. # Handle QEMU Emulation
  62. # NOTE: QEMU emulation for gd32vf103 is no longer supported after nuclei release >= 2023.06
  63. QEMU_MACHINE := ${BOARD}
  64. QEMU_CPU := nuclei-n203
  65. ##### Extra compiler options
  66. COMMON_FLAGS += -DSYSTEM_CLOCK=$(SYSCLK)
  67. COMMON_FLAGS += -DSYSCLK_USING_$(call uc, $(CLKSRC))
  68. ifneq ($(HXTAL_VALUE),)
  69. COMMON_FLAGS += -DHXTAL_VALUE=$(HXTAL_VALUE)
  70. endif
  71. ##### Put your Source code Management configurations below #####
  72. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include
  73. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source $(NUCLEI_SDK_SOC_COMMON)/Source/Drivers
  74. # If semihosting is enabled, no stub function is needed
  75. ifeq ($(SEMIHOST),)
  76. ifneq ($(findstring libncrt,$(STDCLIB)),)
  77. # semihosting currently not ported to support libncrt
  78. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/libncrt
  79. else ifneq ($(findstring newlib,$(STDCLIB)),)
  80. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/newlib
  81. else
  82. # no stubs will be used
  83. endif
  84. endif
  85. # GD32VF103 USB Driver Handling
  86. USBDRV_ROOT := $(NUCLEI_SDK_SOC_COMMON)/Source/Drivers/Usb
  87. ifeq ($(USB_DRIVER),both)
  88. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include/Usb
  89. C_SRCDIRS += $(USBDRV_ROOT)
  90. else ifeq ($(USB_DRIVER),host)
  91. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include/Usb
  92. C_SRCS += $(USBDRV_ROOT)/drv_usb_core.c \
  93. $(USBDRV_ROOT)/drv_usb_host.c \
  94. $(USBDRV_ROOT)/drv_usbh_int.c \
  95. $(USBDRV_ROOT)/usbh_*.c
  96. else ifeq ($(USB_DRIVER),device)
  97. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include/Usb
  98. C_SRCS += $(USBDRV_ROOT)/drv_usb_core.c \
  99. $(USBDRV_ROOT)/drv_usb_dev.c \
  100. $(USBDRV_ROOT)/drv_usbd_int.c \
  101. $(USBDRV_ROOT)/usbd_*.c
  102. endif
  103. ASM_SRCS += $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/startup_gd32vf103.S \
  104. $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/intexc_gd32vf103.S
  105. # Add extra board related source files and header files
  106. ifneq ($(VALID_NUCLEI_SDK_SOC_BOARD),)
  107. INCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Include
  108. C_SRCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Source
  109. endif