Skip to content

Instantly share code, notes, and snippets.

@andyturk
Last active February 28, 2020 09:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andyturk/951e279835a5116bdfec to your computer and use it in GitHub Desktop.
Save andyturk/951e279835a5116bdfec to your computer and use it in GitHub Desktop.
# override definitions in local_vars.mk
-include local_vars.mk
# PSoC Creator information
# The first two variables only exist in a Windows environment with PSoC Creator
# so they're conditional. The other CY... variables are useful on all platforms
# Note that this Makefile usually exists one level up from the .cydsn directory
ifeq ($(OS),Windows_NT)
CYCREATOR ?= C:/Program\ Files\ \(x86\)/Cypress/PSoC\ Creator/3.0/PSoC\ Creator
CYLIBDIR ?= $(CYCREATOR)/psoc/content/cycomponentlibrary/CyComponentLibrary.cylib/CortexM3/ARM_GCC_473/Debug
endif
CYLIB = CyComponentLibrary.a
CYGENERATED_SOURCE = $(CYDSN)/Generated_Source
CYSCATTER = $(CYGENERATED_SOURCE)/PSoC5/cm3gcc.ld
CYNAME = $(basename $(notdir $(CYDSN)))
# These two must be defined on a per-project basis
CYDSN = disp.cydsn
CYDEVICE = CY8C5868AXI-LP035
# J-Link information
JLINK_ROOT ?= /Applications/SEGGER/JLink
JLINKEXE := $(JLINK_ROOT)/JLinkExe
JLINKGDBSERVER := $(JLINK_ROOT)/JLinkGDBServer
JLINKDEVICE = CY8C5868xxxLP
JLINKGDBCMD = $(JLINKGDBSERVER) -if SWD -device $(JLINKDEVICE) >/tmp/jlink.log 2>&1
# The following command string (between define/endef) flashes a code to a PSoC5
# The trick here is to define a multi-line variable in make and then export it
# to the subshell that will run JLinkExe
define JLINK_FLASH_PSOC5_CMD
speed 1000
device $(JLINKDEVICE)
halt
r
erase
loadbin $(BUILD)/$(CYNAME).hex 0x00000000
r
g
exit
endef
#
export JLINK_FLASH_PSOC5_CMD
# Toolchain configuration
BINUTILS_ROOT ?= /usr/local/arm/gcc-arm-none-eabi-4_7-2013q1
TARGET := arm-none-eabi
CC := $(BINUTILS_ROOT)/bin/$(TARGET)-gcc
CXX := $(BINUTILS_ROOT)/bin/$(TARGET)-g++
AS := $(BINUTILS_ROOT)/bin/$(TARGET)-as
OBJCOPY := $(BINUTILS_ROOT)/bin/$(TARGET)-objcopy
# Where build products go
# Note that the $(CYLIB) library is copied from the PSoC Creator installation
# into $(LIB) directory. This library isn't really a build product, so it's not
# actually removed by the clean target.
BUILD := build
OBJ = $(BUILD)/obj
LIB = lib
# Sources and libraries that live outside this project
LIBAKT ?= submodules/libakt
# Source files
ASM_SRC += $(CYGENERATED_SOURCE)/PSoC5/CyBootAsmGnu.s
C_SRC += $(wildcard $(CYGENERATED_SOURCE)/PSoC5/*.c)
C_SRC += $(wildcard $(CYDSN)/*.c)
CXX_SRC += $(wildcard $(CYDSN)/*.cc)
# Object files
OBJECTS = $(addprefix $(OBJ)/, $(C_SRC:.c=.o) $(CXX_SRC:.cc=.o) $(ASM_SRC:.s=.o))
ASFLAGS += -I$(CYGENERATED_SOURCE)/PSoC5
ASFLAGS += -mcpu=cortex-m3
ASFLAGS += -mthumb
CFLAGS += -I$(CYGENERATED_SOURCE)/PSoC5
CFLAGS += -I$(LIBAKT)
CFLAGS += -Wno-main
CFLAGS += -g
CFLAGS += -Wall
CFLAGS += -mcpu=cortex-m3
CFLAGS += -mthumb
CFLAGS += -ffunction-sections
CFLAGS += -Wa,-alh=$(@:.o=.lst)
CFLAGS += -fdata-sections
CXXFLAGS += $(CFLAGS)
CXXFLAGS += -fno-rtti
CXXFLAGS += -fno-exceptions
CXXFLAGS += -fms-extensions
CXXFLAGS += -Wno-pmf-conversions
CXXFLAGS += -Wno-unused-parameter
CXXFLAGS += -Wno-psabi
CXXFLAGS += -std=c++11
LDFLAGS += -march=armv7-m
LDFLAGS += -mfix-cortex-m3-ldrd
LDFLAGS += -mthumb
LDFLAGS += -specs=nano.specs
LDFLAGS += -Wl,--gc-sections
DIRS += $(BUILD) $(LIB)
DIRS += $(sort $(dir $(OBJECTS)))
default : $(BUILD)/$(CYNAME).hex
help :
@echo "The following targets are available:"
@echo " make default -- compiles and links"
@echo " make flashit -- erases everything and programs nRF soft device code"
@echo " make clean -- nukes build products"
@echo " make cylib -- on Windows, copies libraries out of PSoC Creator installation"
@echo " make info -- stuff for debugging this Makefile"
clean :
@rm -rf $(BUILD) JLink.log
info :
@echo USER: $(USER)
@echo C_SRC $(C_SRC)
@echo CXX_SRC: $(CXX_SRC)
@echo ASM_SRC $(ASM_SRC)
@echo OBJECTS: $(OBJECTS)
$(DIRS) :
@echo Creating $(@)
@mkdir -p $(@)
ifeq ($(OS),Windows_NT)
cylib :
cp $(CYLIBDIR)/$(CYLIB) $(LIB)/$(CYLIB)
else
cylib :
@echo The cylib target must be run from a Windows command prompt
$(LIB)/$(CYLIB) : $(LIB)
@echo $(CYLIB) must be copied from the PSoC Creator installation
@echo "From a Windows command prompt, please execute 'gmake cylib'"
@false
endif
$(BUILD)/$(CYNAME).elf : $(OBJECTS) $(LIB)/$(CYLIB) $(MAKEFILE_LIST) | $(BUILD)
@echo Linking $(@)
$(CC) \
-Xlinker -Map=$(patsubst %.elf,%.map,$(@)) \
$(LDFLAGS) \
-T$(CYSCATTER) \
-o $(@) $(OBJECTS) $(CYLIBS)
%.bin : %.elf
@echo Converting $(<) to $(@)
@$(OBJCOPY) -O binary $(<) $(@)
%.hex : %.elf
@echo Converting $(<) to $(@)
@$(OBJCOPY) -O ihex $(<) $(@)
%.bin : %.hex
@echo Converting $(X) to $(@)
@$(OBJCOPY) -O ihex $(<) $(@)
$(OBJECTS) : | $(DIRS)
$(OBJ)/%.o : %.c
@echo Compiling $(<F)
@$(CC) $(CFLAGS) -c $< -o $(@)
$(OBJ)/%.o : %.cc
@echo Compiling $(<F)
@$(CXX) $(CXXFLAGS) -c $< -o $(@)
$(OBJ)/%.E : %.c
@$(CC) $(CFLAGS) -E -c $< -o $(@)
$(OBJ)/%.E : %.cc
@$(CXX) $(CXXFLAGS) -E -c $< -o $(@)
$(OBJ)/%.o : %.s
@echo Assembling $(<F)
@$(AS) $(ASFLAGS) $< -o $(@)
flashit : $(BUILD)/$(CYNAME).hex
@echo "$$JLINK_FLASH_PSOC5_CMD" | $(JLINKEXE)
$(BUILD)/.gdbinit : $(BUILD)
@rm -f $(@)
@echo "shell $(JLINKGDBCMD)&" >> $(@)
@echo "target remote :2331" >> $(@)
@echo "monitor reset" >> $(@)
.PHONY : clean info default flashit cylib
-*- mode: compilation; default-directory: "~/code/PSoC/Sync/" -*-
Compilation started at Fri Jun 13 16:19:39
(cd ~/code/PSoC/Sync;make clean flashit)
Creating build
Creating build/obj/disp.cydsn/
Creating build/obj/disp.cydsn/Generated_Source/PSoC5/
Compiling BACKLIGHT.c
Compiling CS.c
Compiling Cm3Start.c
Compiling CyDmac.c
Compiling CyFlash.c
Compiling CyLib.c
Compiling CySpc.c
Compiling DMA1_dma.c
Compiling DONE.c
Compiling LED3.c
Compiling LED4.c
Compiling MOSI.c
Compiling RESET.c
Compiling RS_DC.c
Compiling SCLK.c
Compiling SPI.c
Compiling SPI_INT.c
Compiling SPI_IntClock.c
Compiling SPI_PM.c
Compiling SW1.c
Compiling TX_NOT_FULL.c
Compiling cyPm.c
Compiling cyfitter_cfg.c
Compiling cymetadata.c
Compiling cyutils.c
Compiling main.cc
disp.cydsn/main.cc: In function 'void dma_setup()':
disp.cydsn/main.cc:37:12: warning: unused variable 'i' [-Wunused-variable]
disp.cydsn/main.cc:38:7: warning: unused variable 'active' [-Wunused-variable]
disp.cydsn/main.cc:39:11: warning: unused variable 'current_td' [-Wunused-variable]
disp.cydsn/main.cc:39:23: warning: unused variable 'state' [-Wunused-variable]
disp.cydsn/main.cc:39:30: warning: unused variable 'err' [-Wunused-variable]
disp.cydsn/main.cc: In member function 'virtual void Blink::run()':
disp.cydsn/main.cc:95:3: warning: unused variable 'pexit' [-Wunused-variable]
disp.cydsn/main.cc: In member function 'virtual void Blink2::run()':
disp.cydsn/main.cc:110:3: warning: unused variable 'pexit' [-Wunused-variable]
Assembling CyBootAsmGnu.s
Linking build/disp.elf
/usr/local/arm/gcc-arm-none-eabi-4_7-2013q1/bin/arm-none-eabi-gcc \
-Xlinker -Map=build/disp.map \
-march=armv7-m -mfix-cortex-m3-ldrd -mthumb -specs=nano.specs -Wl,--gc-sections \
-Tdisp.cydsn/Generated_Source/PSoC5/cm3gcc.ld \
-o build/disp.elf build/obj/disp.cydsn/Generated_Source/PSoC5/BACKLIGHT.o build/obj/disp.cydsn/Generated_Source/PSoC5/CS.o build/obj/disp.cydsn/Generated_Source/PSoC5/Cm3Start.o build/obj/disp.cydsn/Generated_Source/PSoC5/CyDmac.o build/obj/disp.cydsn/Generated_Source/PSoC5/CyFlash.o build/obj/disp.cydsn/Generated_Source/PSoC5/CyLib.o build/obj/disp.cydsn/Generated_Source/PSoC5/CySpc.o build/obj/disp.cydsn/Generated_Source/PSoC5/DMA1_dma.o build/obj/disp.cydsn/Generated_Source/PSoC5/DONE.o build/obj/disp.cydsn/Generated_Source/PSoC5/LED3.o build/obj/disp.cydsn/Generated_Source/PSoC5/LED4.o build/obj/disp.cydsn/Generated_Source/PSoC5/MOSI.o build/obj/disp.cydsn/Generated_Source/PSoC5/RESET.o build/obj/disp.cydsn/Generated_Source/PSoC5/RS_DC.o build/obj/disp.cydsn/Generated_Source/PSoC5/SCLK.o build/obj/disp.cydsn/Generated_Source/PSoC5/SPI.o build/obj/disp.cydsn/Generated_Source/PSoC5/SPI_INT.o build/obj/disp.cydsn/Generated_Source/PSoC5/SPI_IntClock.o build/obj/disp.cydsn/Generated_Source/PSoC5/SPI_PM.o build/obj/disp.cydsn/Generated_Source/PSoC5/SW1.o build/obj/disp.cydsn/Generated_Source/PSoC5/TX_NOT_FULL.o build/obj/disp.cydsn/Generated_Source/PSoC5/cyPm.o build/obj/disp.cydsn/Generated_Source/PSoC5/cyfitter_cfg.o build/obj/disp.cydsn/Generated_Source/PSoC5/cymetadata.o build/obj/disp.cydsn/Generated_Source/PSoC5/cyutils.o build/obj/disp.cydsn/main.o build/obj/disp.cydsn/Generated_Source/PSoC5/CyBootAsmGnu.o
Converting build/disp.elf to build/disp.hex
SEGGER J-Link Commander V4.84e ('?' for help)
Compiled Apr 28 2014 20:57:37
DLL version V4.84e, compiled Apr 28 2014 20:57:32
Firmware: J-Link ARM V8 compiled Nov 25 2013 19:20:08
Hardware: V8.00
S/N: 268004817
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
VTarget = 3.274V
Info: TotalIRLen = 8, IRPrint = 0x0011
Info: Found Cortex-M3 r2p1, Little endian.
Info: FPUnit: 6 code (BP) slots and 2 literal slots
Info: TPIU fitted.
Info: ETM fitted.
Found 2 JTAG devices, Total IRLen = 8:
#0 Id: 0x4BA00477, IRLen: 04, IRPrint: 0x1, CoreSight JTAG-DP (ARM)
#1 Id: 0x2E123069, IRLen: 04, Unknown device
Cortex-M3 identified.
Target interface speed: 100 kHz
Target interface speed: 1000 kHz
Info: Device "CY8C5868XXXLP" selected (256 KB flash, 64 KB RAM).
Reconnecting to target...
Info: TotalIRLen = 8, IRPrint = 0x0011
Info: Found Cortex-M3 r2p1, Little endian.
Info: FPUnit: 6 code (BP) slots and 2 literal slots
Info: TPIU fitted.
Info: ETM fitted.
PC = 00000FD6, CycleCnt = DE952439
R0 = 00000001, R1 = 00000000, R2 = 1FFF8114, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 20007FC0
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000
SP(R13)= 20007FC0, MSP= 20007FC0, PSP= 00000000, R14(LR) = 00000FCD
XPSR = 61000000: APSR = nZCvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Erasing device (CY8C5868xxxLP)...
Info: J-Link: Flash download: Total time needed: 7.068s (Prepare: 0.170s, Compare: 0.000s, Erase: 6.886s, Program: 0.000s, Verify: 0.000s, Restore: 0.011s)
Erasing done.
Downloading file... [build/disp.hex]
Info: J-Link: Flash download: Flash programming performed for 1 range (9984 bytes)
Info: J-Link: Flash download: Total time needed: 1.130s (Prepare: 0.258s, Compare: 0.413s, Erase: 0.000s, Program: 0.378s, Verify: 0.001s, Restore: 0.078s)
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Compilation finished at Fri Jun 13 16:19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment