OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [demo_freeRTOS/] [makefile] - Blame information for rev 54

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 zero_gravi
#################################################################################################
2
# << NEORV32 - Application Makefile >>                                                          #
3
# ********************************************************************************************* #
4
# Make sure to add the riscv GCC compiler's bin folder to your PATH environment variable.       #
5
# ********************************************************************************************* #
6
# BSD 3-Clause License                                                                          #
7
#                                                                                               #
8
# Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
9
#                                                                                               #
10
# Redistribution and use in source and binary forms, with or without modification, are          #
11
# permitted provided that the following conditions are met:                                     #
12
#                                                                                               #
13
# 1. Redistributions of source code must retain the above copyright notice, this list of        #
14
#    conditions and the following disclaimer.                                                   #
15
#                                                                                               #
16
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
17
#    conditions and the following disclaimer in the documentation and/or other materials        #
18
#    provided with the distribution.                                                            #
19
#                                                                                               #
20
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
21
#    endorse or promote products derived from this software without specific prior written      #
22
#    permission.                                                                                #
23
#                                                                                               #
24
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
25
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
26
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
27
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
28
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
29
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
30
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
31
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
32
# OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
33
# ********************************************************************************************* #
34
# The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
35
#################################################################################################
36
 
37
 
38
# *****************************************************************************
39
# USER CONFIGURATION
40
# *****************************************************************************
41
# User's application sources (*.c, *.cpp, *.s, *.S); add additional files here
42
APP_SRC ?= $(wildcard ./*.c) $(wildcard ./*.s) $(wildcard ./*.cpp) $(wildcard ./*.S)
43
 
44
# User's application include folders (don't forget the '-I' before each entry)
45
APP_INC ?= -I .
46
# User's application include folders - for assembly files only (don't forget the '-I' before each entry)
47
ASM_INC ?= -I .
48
 
49
# Optimization
50
EFFORT ?= -Os
51
 
52
# Compiler toolchain
53
RISCV_TOOLCHAIN ?= riscv32-unknown-elf
54
 
55
# CPU architecture and ABI
56
MARCH ?= -march=rv32i
57
MABI  ?= -mabi=ilp32
58
 
59
# User flags for additional configuration (will be added to compiler flags)
60
USER_FLAGS ?=
61
 
62 34 zero_gravi
# Serial port for executable upload via bootloer
63
COM_PORT ?= /dev/ttyUSB0
64
 
65 22 zero_gravi
# Relative or absolute path to the NEORV32 home folder
66
NEORV32_HOME ?= ../../..
67
# *****************************************************************************
68
 
69
 
70
 
71
# -----------------------------------------------------------------------------
72 33 zero_gravi
# FreeRTOS
73
# -----------------------------------------------------------------------------
74
ifneq (,$(findstring RUN_FREERTOS_DEMO,$(USER_FLAGS)))
75
# FreeRTOS home folder (adapt this!)
76 36 zero_gravi
FREERTOS_HOME ?= /mnt/n/Projects/FreeRTOSv10.4.1
77 33 zero_gravi
 
78 36 zero_gravi
# FreeRTOS RISC-V specific
79
APP_SRC += $(wildcard $(FREERTOS_HOME)/FreeRTOS/Source/portable/GCC/RISC-V/*.c)
80
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Source/portable/GCC/RISC-V/portASM.S
81 33 zero_gravi
 
82 36 zero_gravi
APP_INC += -I $(FREERTOS_HOME)/FreeRTOS/Source/portable/GCC/RISC-V
83
 
84 33 zero_gravi
# FreeRTOS core
85 36 zero_gravi
APP_SRC += $(wildcard $(FREERTOS_HOME)/FreeRTOS/Source/*.c)
86
APP_SRC += $(wildcard $(FREERTOS_HOME)/FreeRTOS/Source/portable/MemMang/heap_4.c)
87 33 zero_gravi
 
88 36 zero_gravi
APP_INC += -I $(FREERTOS_HOME)/FreeRTOS/Source/include
89 33 zero_gravi
 
90 36 zero_gravi
# FreeRTOS sources for the full_demo
91
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/blocktim.c
92
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/dynamic.c
93
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c
94
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/GenQTest.c
95
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/recmutex.c
96
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/TaskNotify.c
97
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c
98
APP_SRC += $(FREERTOS_HOME)/FreeRTOS/Demo/Common/Minimal/TimerDemo.c
99 33 zero_gravi
 
100 36 zero_gravi
APP_INC += -I $(FREERTOS_HOME)/FreeRTOS/Demo/Common/include
101 33 zero_gravi
 
102
# NEORV32 specific
103
ASM_INC += -DportasmHANDLE_INTERRUPT=SystemIrqHandler
104
 
105
APP_INC += -I chip_specific_extensions/neorv32
106
 
107
ASM_INC += -I chip_specific_extensions/neorv32
108 36 zero_gravi
 
109
# Demo application
110
APP_SRC += blinky_demo/main_blinky.c
111
APP_SRC += full_demo/main_full.c
112
APP_SRC += full_demo/RegTest.s
113 33 zero_gravi
endif
114
 
115 36 zero_gravi
# -----------------
116
# FreeRTOS-Plus-CLI
117
# -----------------
118
ifneq (,$(findstring FREERTOS_PLUS_CLI,$(USER_FLAGS)))
119
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c
120 33 zero_gravi
 
121 36 zero_gravi
APP_INC += -I $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI
122
endif
123 33 zero_gravi
 
124 36 zero_gravi
# -----------------
125
# FreeRTOS-Plus-TCP
126
# -----------------
127
ifneq (,$(findstring FREERTOS_PLUS_TCP,$(USER_FLAGS)))
128
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c
129
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c
130
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
131
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
132
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
133
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c
134
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
135
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c
136
APP_SRC += $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c
137
 
138
APP_INC += -I $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include
139
APP_INC += -I $(FREERTOS_HOME)/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC
140
endif
141
 
142
 
143
 
144 33 zero_gravi
# -----------------------------------------------------------------------------
145 22 zero_gravi
# NEORV32 framework
146
# -----------------------------------------------------------------------------
147
# Path to NEORV32 linker script and startup file
148
NEORV32_COM_PATH = $(NEORV32_HOME)/sw/common
149
# Path to main NEORV32 library include files
150
NEORV32_INC_PATH = $(NEORV32_HOME)/sw/lib/include
151
# Path to main NEORV32 library source files
152
NEORV32_SRC_PATH = $(NEORV32_HOME)/sw/lib/source
153
# Path to NEORV32 executable generator
154
NEORV32_EXG_PATH = $(NEORV32_HOME)/sw/image_gen
155
# Path to NEORV32 core rtl folder
156
NEORV32_RTL_PATH = $(NEORV32_HOME)/rtl/core
157
# Marker file to check for NEORV32 home folder
158
NEORV32_HOME_MARKER = $(NEORV32_INC_PATH)/neorv32.h
159
 
160
# Core libraries (peripheral and CPU drivers)
161
CORE_SRC  = $(wildcard $(NEORV32_SRC_PATH)/*.c)
162
# Application start-up code
163
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S
164
 
165
# Linker script
166
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
167
 
168
# Main output files
169
APP_EXE  = neorv32_exe.bin
170
APP_ASM  = main.asm
171
APP_IMG  = neorv32_application_image.vhd
172
BOOT_IMG = neorv32_bootloader_image.vhd
173
 
174
 
175
# -----------------------------------------------------------------------------
176
# Sources and objects
177
# -----------------------------------------------------------------------------
178
# Define all sources
179
SRC  = $(APP_SRC)
180
SRC += $(CORE_SRC)
181
 
182
# Define all object files
183
OBJ = $(SRC:%=%.o)
184
 
185
 
186
# -----------------------------------------------------------------------------
187
# Tools and flags
188
# -----------------------------------------------------------------------------
189
# Compiler tools
190
CC      = $(RISCV_TOOLCHAIN)-gcc
191
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
192
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
193
SIZE    = $(RISCV_TOOLCHAIN)-size
194
 
195
# Host native compiler
196 43 zero_gravi
CC_X86 = g++ -Wall -O -g
197 22 zero_gravi
 
198
# NEORV32 executable image generator
199
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
200
 
201
# Compiler & linker flags
202
CC_OPTS  = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles
203
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
204 32 zero_gravi
# This accelerates instruction fetch after branches when C extension is enabled (irrelevant when C extension is disabled)
205
CC_OPTS += -falign-functions=4 -falign-labels=4 -falign-loops=4 -falign-jumps=4
206 22 zero_gravi
CC_OPTS += $(USER_FLAGS)
207
 
208
 
209
# -----------------------------------------------------------------------------
210
# Application output definitions
211
# -----------------------------------------------------------------------------
212
.PHONY: check info help elf_info clean clean_all bootloader
213
.DEFAULT_GOAL := help
214
 
215
# 'compile' is still here for compatibility
216
exe:     $(APP_ASM) $(APP_EXE)
217
compile: $(APP_ASM) $(APP_EXE)
218
install: $(APP_ASM) $(APP_IMG)
219
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG)
220
 
221
# Check if making bootloader
222
# Use different base address and legth for instruction memory/"rom" (BOOTMEM instead of IMEM)
223 32 zero_gravi
# Also define "make_bootloader" for crt0.S
224
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
225 22 zero_gravi
 
226
 
227
# -----------------------------------------------------------------------------
228
# Image generator targets
229
# -----------------------------------------------------------------------------
230
# install/compile tools
231
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
232
        @echo Compiling $(IMAGE_GEN)
233
        @$(CC_X86) $< -o $(IMAGE_GEN)
234
 
235
 
236
# -----------------------------------------------------------------------------
237
# General targets: Assemble, compile, link, dump
238
# -----------------------------------------------------------------------------
239
# Compile app *.s sources (assembly)
240
%.s.o: %.s
241
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
242
 
243
# Compile app *.S sources (assembly + C pre-processor)
244
%.S.o: %.S
245
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
246
 
247
# Compile app *.c sources
248
%.c.o: %.c
249
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
250
 
251
# Compile app *.cpp sources
252
%.cpp.o: %.cpp
253
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
254
 
255
# Link object files and show memory utilization
256
main.elf: $(OBJ)
257 54 zero_gravi
        @$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@ -lm
258 22 zero_gravi
        @echo "Memory utilization:"
259
        @$(SIZE) main.elf
260
 
261
# Assembly listing file (for debugging)
262
$(APP_ASM): main.elf
263 36 zero_gravi
        @$(OBJDUMP) -d -S -z  $< > $@
264 22 zero_gravi
 
265
# Generate final executable from .text + .rodata + .data (in THIS order!)
266
main.bin: main.elf $(APP_ASM)
267
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
268
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
269
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
270
        @cat text.bin rodata.bin data.bin > $@
271
        @rm -f text.bin rodata.bin data.bin
272
 
273
 
274
# -----------------------------------------------------------------------------
275
# Application targets: Generate binary executable, install (as VHDL file)
276
# -----------------------------------------------------------------------------
277
# Generate NEORV32 executable image for upload via bootloader
278
$(APP_EXE): main.bin $(IMAGE_GEN)
279
        @set -e
280
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
281
        @echo "Executable ($(APP_EXE)) size in bytes:"
282
        @wc -c < $(APP_EXE)
283
 
284
# Generate NEORV32 executable VHDL boot image
285
$(APP_IMG): main.bin $(IMAGE_GEN)
286
        @set -e
287
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
288
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
289
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
290
 
291
 
292
# -----------------------------------------------------------------------------
293
# Bootloader targets
294
# -----------------------------------------------------------------------------
295
# Create and install bootloader VHDL init image
296
$(BOOT_IMG): main.bin $(IMAGE_GEN)
297
        @set -e
298
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
299
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
300
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
301
 
302
# Just an alias that
303
bootloader: $(BOOT_IMG)
304
 
305
 
306
# -----------------------------------------------------------------------------
307
# Check toolchain
308
# -----------------------------------------------------------------------------
309
check: $(IMAGE_GEN)
310
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
311
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
312
$(error NEORV32_HOME folder not found!)
313
endif
314
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
315
        @echo "---------------- Check: $(CC) ----------------"
316
        @$(CC) -v
317
        @echo "---------------- Check: $(OBJDUMP) ----------------"
318
        @$(OBJDUMP) -V
319
        @echo "---------------- Check: $(OBJCOPY) ----------------"
320
        @$(OBJCOPY) -V
321
        @echo "---------------- Check: $(SIZE) ----------------"
322
        @$(SIZE) -V
323
        @echo "---------------- Check: NEORV32 image_gen ----------------"
324
        @$(IMAGE_GEN) -help
325
        @echo "---------------- Check: Native GCC ----------------"
326
        @$(CC_X86) -v
327
        @echo
328
        @echo "Toolchain check OK"
329
 
330
 
331
# -----------------------------------------------------------------------------
332 34 zero_gravi
# Upload executable via serial port to bootloader
333
# -----------------------------------------------------------------------------
334
upload: $(APP_EXE)
335
        @sh $(NEORV32_EXG_PATH)/uart_upload.sh $(COM_PORT) $(APP_EXE)
336
 
337
 
338
# -----------------------------------------------------------------------------
339 22 zero_gravi
# Show configuration
340
# -----------------------------------------------------------------------------
341
info:
342
        @echo "---------------- Info: Project ----------------"
343
        @echo "Project folder:        $(shell basename $(CURDIR))"
344
        @echo "Source files:          $(APP_SRC)"
345
        @echo "Include folder(s):     $(APP_INC)"
346
        @echo "ASM include folder(s): $(ASM_INC)"
347
        @echo "---------------- Info: NEORV32 ----------------"
348
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
349
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
350
        @echo "Core source files:"
351
        @echo "$(CORE_SRC)"
352
        @echo "Core include folder:"
353
        @echo "$(NEORV32_INC_PATH)"
354
        @echo "---------------- Info: Objects ----------------"
355
        @echo "Project object files:"
356
        @echo "$(OBJ)"
357
        @echo "---------------- Info: RISC-V CPU ----------------"
358
        @echo "MARCH:      $(MARCH)"
359
        @echo "MABI:       $(MABI)"
360
        @echo "---------------- Info: Toolchain ----------------"
361
        @echo "Toolchain:  $(RISCV_TOLLCHAIN)"
362
        @echo "CC:         $(CC)"
363
        @echo "OBJDUMP:    $(OBJDUMP)"
364
        @echo "OBJCOPY:    $(OBJCOPY)"
365
        @echo "SIZE:       $(SIZE)"
366
        @echo "---------------- Info: Compiler Libraries ----------------"
367
        @echo "LIBGCC:"
368
        @$(CC) -print-libgcc-file-name
369
        @echo "SEARCH-DIRS:"
370
        @$(CC) -print-search-dirs
371
        @echo "---------------- Info: Flags ----------------"
372
        @echo "USER_FLAGS: $(USER_FLAGS)"
373
        @echo "CC_OPTS:    $(CC_OPTS)"
374
        @echo "---------------- Info: Host Native GCC Flags ----------------"
375
        @echo "CC_X86:     $(CC_X86)"
376
 
377
 
378
# -----------------------------------------------------------------------------
379
# Show final ELF details (just for debugging)
380
# -----------------------------------------------------------------------------
381
elf_info: main.elf
382
        @$(OBJDUMP) -x main.elf
383
 
384
 
385
# -----------------------------------------------------------------------------
386
# Help
387
# -----------------------------------------------------------------------------
388
help:
389
        @echo "<<< NEORV32 Application Makefile >>>"
390
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
391
        @echo "Targets:"
392
        @echo " help       - show this text"
393
        @echo " check      - check toolchain"
394
        @echo " info       - show makefile/toolchain configuration"
395
        @echo " exe        - compile and generate  executable for upload via bootloader"
396
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
397
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image (for application)"
398
        @echo " clean      - clean up project"
399
        @echo " clean_all  - clean up project, core libraries and image generator"
400
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
401 34 zero_gravi
        @echo " upload     - upload  executable via serial port  to bootloader"
402 22 zero_gravi
 
403
 
404
# -----------------------------------------------------------------------------
405
# Clean up
406
# -----------------------------------------------------------------------------
407
clean:
408
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd
409
 
410
clean_all: clean
411
        @rm -f $(OBJ) $(IMAGE_GEN)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.