Init example

This commit is contained in:
GHOSCHT 2024-11-02 17:44:56 +01:00
commit ad1ce76549
Signed by: ghoscht
GPG key ID: 2C2C1C62A5388E82
7 changed files with 252 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake git+https://git.ghoscht.com/ghoscht/xmclib

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.direnv/
target
result
build/
lib_build/

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "xmclib"]
path = xmclib
url = https://git.ghoscht.com/ghoscht/xmclib.git

168
Makefile Executable file
View file

@ -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)

48
dimming.c Executable file
View file

@ -0,0 +1,48 @@
#include <xmc_common.h>
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);
}

26
student.mk Executable file
View file

@ -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 +=

1
xmclib Submodule

@ -0,0 +1 @@
Subproject commit 5fd71915274f4f9bfdab552d301f5f3bc99134c1