-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (107 loc) · 3.23 KB
/
Makefile
File metadata and controls
125 lines (107 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
XC32PATH=C:\Program Files\Microchip\xc32\v4.21\bin
HARMONYPATH=
NU32PATH=C:\Users\zdgen\Documents\pic32
PORT=COM3
TERMEMU=C:\Program Files\PuTTY\putty.exe
#This file is used to:
# 1. compile .c files into .o files
# 2. link the .o files into a .elf binary
# 3. convert the .elf into a .hex
# 4. write the .hex file to the pic using the bootloader utility
# The following must be edited by you so that
# make knows where to find the compiler tools (xc32)
# and the harmony library.
#
# XC32PATH is the path to the xc32 bin directory. This directory contains
# tools such as the compiler (xc32-gcc) and hex converter
# (xc32-bin2hex)
# Windows example (note the use of slashes not backslashes):
# XC32PATH=C:/Program Files (x86)/Microchip/xc32/v1.40/bin
# Mac example:
# XC32PATH =/Applications/microchip/xc32/v1.40/bin
#
# HARMONYPATH is the path to the harmony framework directory
# Windows example:
# HARMONYPATH=C:/Program Files (x86)/Microchip/harmony/v1_06
# Mac example:
# HARMONYPATH=/Users/kevin/harmony/v1_06
#
# NU32PATH is the path to the nu32utility.
# You compiled this and named it nu32utility
# Example:
# if your nu32utility is in
# /home/student/PIC32/nu32utilty, then
# NU32PATH=/home/student/PIC32
#
# PORT is the COM port used by the PIC32
# Windows Example:
# PORT=\\.\COM22
# Mac Example:
# PORT=/dev/tty.usbserial=00001024A
#
# TERMEMU is your terminal emulator
# Windows example:
# TERMEMU=C:/Program Files (x86)/PuTTY/putty.exe
# Mac example (screen is pre-installed and already on your execution path
# so you can safely omit the full path)
# TERMEMU=screen
#END user configurable variables
#the c compiler
CC="$(XC32PATH)/xc32-gcc"
#the hexfile maker
HX="$(XC32PATH)/xc32-bin2hex"
#object dumper
OBJDMP="$(XC32PATH)/xc32-objdump"
#the bootloader utility
WRITE="$(NU32PATH)/nu32utility"
#the output target $(TARGET).hex
TARGET=out
#the linker script
LINKSCRIPT=NU32DIPbootloaded.ld
#additional linker flags
LINKFLAGS=-Map=$(TARGET).map
#if we have specified a linker script add it
ifdef LINKSCRIPT
LINKFLAGS:=--script=$(LINKSCRIPT),$(LINKFLAGS)
endif
OBJS := $(patsubst %.c, %.o,$(wildcard *.c))
HDRS := $(wildcard *.h)
PROC = 32MX170F256B
CFLAGS=-g -O1 -x c
#if on windows use a different RM
ifdef ComSpec
RM = del /Q
endif
#what to do when make all
.PHONY : all
all : $(TARGET).hex $(TARGET).dis
# Turn the elf file into a hex file.
$(TARGET).hex : $(TARGET).elf
@echo Creating hex file
$(HX) $(TARGET).elf
# perform disassembly
$(TARGET).dis : $(TARGET).elf
$(OBJDMP) -S $< > $@
# Link all the object files into an elf file.
$(TARGET).elf : $(OBJS)
@echo Linking elf file
$(CC) -mprocessor=$(PROC) -o $(TARGET).elf $(OBJS) -Wl,$(LINKFLAGS)
# Create an object file for each C file.
%.o : %.c $(HDRS)
@echo Creating object file $@
$(CC) $(CFLAGS) -c -mprocessor=$(PROC) -o $@ $<
#path to harmony framework, harmony peripherals, harmony dsp library, harmony libq
.PHONY: clean
# Erase all hex, map, object, and elf files.
clean :
$(RM) *.hex *.map *.o *.elf *.dep *.dis
.PHONY: write
# After making, call the NU32utility to program via bootloader.
write : $(TARGET).hex $(TARGET).dis
$(WRITE) "$(PORT)" $(TARGET).hex
.PHONY: putty
putty :
"$(TERMEMU)" -serial -sercfg 230400 "$(PORT)"
.PHONY: screen
screen :
"$(TERMEMU)" "$(PORT)" 230400