From ad1ce7654911f8945e5f1a929892f3be08f56ada Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Sat, 2 Nov 2024 17:44:56 +0100 Subject: [PATCH] Init example --- .envrc | 1 + .gitignore | 5 ++ .gitmodules | 3 + Makefile | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++ dimming.c | 48 +++++++++++++++ student.mk | 26 ++++++++ xmclib | 1 + 7 files changed, 252 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100755 Makefile create mode 100755 dimming.c create mode 100755 student.mk create mode 160000 xmclib diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..6eae614 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake git+https://git.ghoscht.com/ghoscht/xmclib diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44f2c75 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.direnv/ +target +result +build/ +lib_build/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..957fe40 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "xmclib"] + path = xmclib + url = https://git.ghoscht.com/ghoscht/xmclib.git diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..bc009e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,168 @@ +##### Makefile for the ESS deliverables ##### +# DO NOT CHANGE THIS FILE, IT WILL BE REPLACED BY THE ORIGINAL VERSION BEFORE GRADING # + +include student.mk + +# Compiler +CROSS_COMPILE=arm-none-eabi + +CC = $(CROSS_COMPILE)-gcc +LD = $(CROSS_COMPILE)-gcc --specs=nosys.specs +AR = $(CROSS_COMPILE)-ar +AS = $(CROSS_COMPILE)-as +OC = $(CROSS_COMPILE)-objcopy +OD = $(CROSS_COMPILE)-objdump +SZ = $(CROSS_COMPILE)-size +DB = $(CROSS_COMPILE)-gdb + +# Paths to build directories for out-of-tree build and path to LUFA USB library +BUILDDIR = build +LIB_BUILDDIR = lib_build +USB_LIBDIR = $(XMC_LIBDIR)/ThirdPartyLibraries/USBlib/USB + +# Specify device +XMC_SERIES=4500 +XMC_PACKAGE=F100 +XMC_SIZE=1024 + +VPATH += $(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/BasicMathFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/CommonTables:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/ComplexMathFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/ControllerFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/FastMathFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/FilteringFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/MatrixFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/StatisticsFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/SupportFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/TransformFunctions:$(XMC_LIBDIR)/CMSIS/Infineon/XMC$(XMC_SERIES)_series/Source:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/SRC:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/SRC/ARM:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/Templates:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/UserCodeTemplates:$(XMC_LIBDIR)/ThirdPartyLibraries/Newlib:$(XMC_LIBDIR)/XMCLib/src:$(USB_LIBDIR)/Class/Common:$(USB_LIBDIR)/Class/Device:$(USB_LIBDIR)/Common:$(USB_LIBDIR)/Core:$(USB_LIBDIR)/Core/XMC4000 + +# Where to find CMSIS, device and XMClib header files +CFLAGS = -I$(XMC_LIBDIR)/CMSIS/Include/ +# Where to find device specific header files +CFLAGS += -I$(XMC_LIBDIR)/CMSIS/Infineon/XMC$(XMC_SERIES)_series/Include/ +# Where to find XMClib headers +CFLAGS += -I$(XMC_LIBDIR)/XMCLib/inc/ +# USB LIB Include paths +CFLAGS += -I$(USB_LIBDIR) +CFLAGS += -I$(USB_LIBDIR)/Class +CFLAGS += -I$(USB_LIBDIR)/Class/Common +CFLAGS += -I$(USB_LIBDIR)/Class/Device +CFLAGS += -I$(USB_LIBDIR)/Common +CFLAGS += -I$(USB_LIBDIR)/Core +CFLAGS += -I$(USB_LIBDIR)/Core/XMC4000 +# Which device +CFLAGS += -DXMC$(XMC_SERIES)_$(XMC_PACKAGE)x$(XMC_SIZE) +# Which core architecture +CFLAGS += -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mthumb +# Debug level and format +CFLAGS += -g3 -gdwarf-2 +# Compile without linking +CFLAGS += -c +# Write separate *.lst file for each source +CFLAGS += -Wa,-adhlns="$@.lst" +# Until here all options are also necessary for compiling startup_XMC4500.S +SFLAGS = $(CFLAGS) +# Add student options, so -Wall comes after and overrides any possible -Wnone or so +CFLAGS +=$(SCFLAGS) +# Enable standard warnings for both +SFLAGS += -Wall +CFLAGS += -Wall +# Put functions into separate sections, so they can be omitted by linker if unused +CFLAGS += -ffunction-sections +# Option for assembly compilation +SFLAGS += -x assembler-with-cpp +# Tell the linker to use our own linker script and startup files +LFLAGS = -T$(BUILDDIR)/$(LD_NAME).ld -nostartfiles +# Where to find the precompiled math libraries +LFLAGS += -L$(XMC_LIBDIR)/CMSIS/Lib/GCC/ +# Create a map file +LFLAGS += -Wl,-Map,"$@.map" +# Also tell the linker core architecture +LFLAGS += -mcpu=cortex-m4 -mthumb +# Inform about debug info +LFLAGS += -g3 -gdwarf-2 + +# startup files +LIBSRCS += startup_XMC$(XMC_SERIES).c system_XMC$(XMC_SERIES).c +# minimal syscalls definition for gcc +LIBSRCS += syscalls.c + + +# convert srcs to respective build targets +OBJS = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS)) +LIBOBJS = $(patsubst %.c,$(LIB_BUILDDIR)/%.o,$(LIBSRCS)) + +.PHONY: default program debug clean + +PARENT_DIR := $(notdir $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../)) +NOT_PACKED := $(shell cd ..; ls | grep -xv "Part[A-Z]") +_PACKED := $(shell cd ..; ls */*/*.elf | tr "/" "\n" | grep "Part") +PACKED := $(patsubst %,../%,$(_PACKED)) + +ifneq ($(NOT_PACKED),) + NOT_PACKING_STRING_1 := "NOTE: NOT PACKING THE FOLLOWING FILES: " + NOT_PACKING_STRING_2 := "(if you want to submit them, rename to 'Part[A-Z]' and make sure your *.elf is present): " +endif + +default: $(BUILDDIR)/main.elf $(BUILDDIR)/main.lst + +program: $(BUILDDIR)/main.hex $(BUILDDIR)/JLinkCommands + JLinkExe -Device XMC$(XMC_SERIES) -If SWD -Speed 1000 -CommanderScript $(BUILDDIR)/JLinkCommands + +debug: $(BUILDDIR)/main.elf $(BUILDDIR)/GDBCommands + echo "##### Debug session started at $(date) #####" >JLinkLog + JLinkGDBServer -device XMC$(XMC_SERIES) -endian little -if SWD -speed 1000 -halt -logtofile -log JLinkLog -silent -vd & + sleep 1 + sh -ci "$(DB) -command=$(BUILDDIR)/GDBCommands -tui" + killall JLinkGDBServer + +$(BUILDDIR)/%.bin: $(BUILDDIR)/%.elf + $(OC) -O binary $< $@ + +$(BUILDDIR)/%.hex: $(BUILDDIR)/%.elf + $(OC) -O ihex $< $@ + +$(BUILDDIR)/%.lst: $(BUILDDIR)/%.elf + $(OD) -h -S $< > $@ + +$(BUILDDIR)/%.elf: $(OBJS) $(LIBOBJS) $(BUILDDIR)/$(LD_NAME).ld + $(LD) $(LFLAGS) -o $@ $(OBJS) $(LIBOBJS) $(LIBLNK) + $(SZ) $@ + +$(BUILDDIR)/%.o: %.c $(HDRS) | $(BUILDDIR) + echo "building $@" + $(CC) $(CFLAGS) -o $@ $< + +$(LIB_BUILDDIR)/%.o: %.c | $(LIB_BUILDDIR) + echo "building $@" + $(CC) $(CFLAGS) -o $@ $< + +# startup +$(LIB_BUILDDIR)/startup_XMC$(XMC_SERIES).o: $(XMC_LIBDIR)/CMSIS/Infineon/XMC$(XMC_SERIES)_series/Source/GCC/startup_XMC$(XMC_SERIES).S | $(LIB_BUILDDIR) + $(CC) $(SFLAGS) -o $@ $< + +# When copying the linker description file, first try to copy one created by the student (and don't +# complain if it does not exist), otherwise use the one from the library +$(BUILDDIR)/$(LD_NAME).ld: $(XMC_LIBDIR)/CMSIS/Infineon/XMC$(XMC_SERIES)_series/Source/GCC/XMC$(XMC_SERIES)x$(XMC_SIZE).ld | $(BUILDDIR) + cp -pu $(LD_NAME).ld $@ | true + cp -n --preserve=timestamps $< $@ + +$(BUILDDIR): + mkdir -p $@ + +$(LIB_BUILDDIR): + mkdir -p $@ + +# Write a script file for JLinkExe +$(BUILDDIR)/JLinkCommands: | $(BUILDDIR) + echo "h;loadfile ${BUILDDIR}/main.hex;r;g;q;" | sed 's/;/\n/g' > $(BUILDDIR)/JLinkCommands + +# Write a script file for GDB +$(BUILDDIR)/GDBCommands: | $(BUILDDIR) + echo "file ${BUILDDIR}/main.elf;target remote localhost:2331;monitor reset;load;break main;" | sed 's/;/\n/g' > $(BUILDDIR)/GDBCommands + +deliverable: + @echo "packing deliverable" + @echo $(NOT_PACKING_STRING_1) + @echo $(NOT_PACKED) + @echo $(NOT_PACKING_STRING_2) + @echo "" + @zip ../$(PARENT_DIR).zip -r $(PACKED) + +clean: + rm -rf $(BUILDDIR) + +clean_all: + rm -rf $(BUILDDIR) $(LIB_BUILDDIR) + diff --git a/dimming.c b/dimming.c new file mode 100755 index 0000000..bf27883 --- /dev/null +++ b/dimming.c @@ -0,0 +1,48 @@ +#include + +void initCCU4(void); +void connectLED(void); + +int main(void) { + + initCCU4(); + + while (1) { + }; + return 0; +} + +void initCCU4() { + // step2: release reset of CCU40, all following lines are equal + //*(0x500414) = 0b100; + // SCU_RESET->PRCLR0 = 0b100; + SCU_RESET->PRCLR0 = SCU_RESET_PRCLR0_CCU40RS_Msk; + + // step 3 + SCU_CLK->CLKSET = SCU_CLK_CLKSET_CCUCEN_Msk; + + // step 4 + CCU40->GIDLC = CCU4_GIDLC_SPRB_Msk; + + // step 6: period value & compare value for PWM + // choose 0xffff to be most flexible & granular + CCU40_CC42->PRS = 0xffff; + // CCU40_CC42->PSC = 0b1010; + CCU40_CC42->CRS = 0xffff * (1 - 0.1); + CCU40->GCSS = CCU4_GCSS_S2SE_Msk; + + // connect led before CCU is started + connectLED(); + + // step 8 + CCU40->GIDLC = CCU4_GIDLC_CS2I_Msk; + + // step 9 + CCU40_CC42->TCSET = CCU4_CC4_TCSET_TRBS_Msk; +} + +void connectLED() { + const static uint8_t ALT3 = 0b10011; + PORT1->IOCR0 = + (PORT1->IOCR0 & ~PORT0_IOCR0_PC1_Msk) | (ALT3 << PORT0_IOCR0_PC1_Pos); +} diff --git a/student.mk b/student.mk new file mode 100755 index 0000000..cc45363 --- /dev/null +++ b/student.mk @@ -0,0 +1,26 @@ +##### Student Makefile for the ESS deliverables ##### +# Change this file to match your requirements + +# Name of your project +LD_NAME = dimming + +# Add lists of space separated source files +# Own sources, e.g. main.c +SRCS = dimming.c +# Library sources, e.g. xmc_gpio.c +LIBSRCS = +# Precompiled libraries, e.g. -lm for math functions +LIBLNK = + +# Change this line if the path to your XMC-Library differs, it will be overwritten before grading to +# match the system the grading is performed on. +XMC_LIBDIR = /home/ghoscht/Coding/embedded/ccu/xmclib/ + +# Language dialect +SCFLAGS = -std=gnu99 +# Optimization level, remember that enabling optimization will stirr up the assembly code and thus +# debugging is more difficult +SCFLAGS += -O0 +# If you like, you can enable even more warnings, e.g. -Wextra, but for grading -Wall will be used +SCFLAGS += + diff --git a/xmclib b/xmclib new file mode 160000 index 0000000..5fd7191 --- /dev/null +++ b/xmclib @@ -0,0 +1 @@ +Subproject commit 5fd71915274f4f9bfdab552d301f5f3bc99134c1