Commit 595541e3 authored by Christian Eichler's avatar Christian Eichler
Browse files

Implement proper targets */ids_${ID} for device identification

parent 14229087
TARGET = xmc
.PHONY: flash/ids_%
#### Setup ####
XMC = $(shell pwd)/XMC
CMSIS = $(XMC)/CMSIS
SRC = $(wildcard src/*.c) $(shell find ./lib -name "*.c") $(shell find ${XMC}/XMCLib/src -name "*.c")
SRC_MAIN = $(wildcard src/*.c)
SRC = $(shell find ./lib -name "*.c") $(shell find ${XMC}/XMCLib/src -name "*.c")
TOOLCHAIN = arm-none-eabi
UC = XMC4500
UC_ID = 4503
......@@ -78,6 +79,7 @@ ODFLAGS = -S
OBJS = $(SRC:.c=.o)
OBJS += src/System_$(UC).o
OBJS_MAIN = $(OBJS) $(SRC_MAIN:.c=.o)
#### Rules ####
all: $(OBJS) xmc xmccomm
......@@ -92,12 +94,33 @@ gene.o:
@echo CC $<
@$(CC) -c $(CFLAGS) $< -o $@
xmc.axf: $(OBJS) gene.o
bin/startup_XMC4500.o: XMC/CMSIS/Infineon/XMC4500_series/Source/GCC/startup_XMC4500.S
mkdir -p bin
@echo AS startup_XMC4500.S
@$(SYSCC) -c XMC/CMSIS/Infineon/XMC4500_series/Source/GCC/startup_XMC4500.S -o bin/startup_XMC4500.o
@$(SYSCC) -c $^ -o $@
bin/ids_%.o: src/main.c
@echo CC $< \(IDS\)
@$(CC) -DID_SYSTEM -DSERIAL=$* -c $(CFLAGS) $< -o $@
bin/ids_%.axf: $(OBJS) bin/startup_XMC4500.o bin/ids_%.o
@echo LD $@
@$(CC) -T $(LINKER_FILE) $(LFLAGS) -o $@ $^ $(LIBS)
%.bin: %.axf
$(CP) $(CPFLAGS) $^ $@
flash/ids_%: bin/ids_%.bin
echo "connect\n\
loadbin $< 0x8000000\n\
r\n\
g\n\
exit\n" | $(JLINK) $(JLFLAGS) -SelectEmuBySN $*
xmc.axf: $(OBJS_MAIN) bin/startup_XMC4500.o gene.o
mkdir -p bin
@echo LD $<
@$(CC) -T $(LINKER_FILE) $(LFLAGS) -o bin/$(TARGET).axf $(OBJS) bin/startup_XMC4500.o gene.o $(LIBS)
@$(CC) -T $(LINKER_FILE) $(LFLAGS) -o bin/xmc.axf $^ $(LIBS)
xmc: xmc.axf
$(CP) $(CPFLAGS) bin/xmc.axf bin/xmc.bin
......
......@@ -7,7 +7,9 @@
#include <xmc4_flash.h>
#include "GPIO.h"
#include "timer.h"
#ifndef ID_SYSTEM
#include "timer.h"
#endif /* ifndef ID_SYSTEM */
#define IHANDLER __attribute__ ((naked))
......@@ -67,17 +69,7 @@ IHANDLER void HardFault_Handler() { P1_1_set(); while(1) {} }
IHANDLER void NMI_Handler() { P1_1_set(); while(1) {} }
IHANDLER void MemManage_Handler() { P1_1_set(); while(1) {} }
IHANDLER void UsageFault_Handler() { P1_1_set(); while(1) {} }
IHANDLER void BusFault_Handler() {
//__asm volatile("ldr sp,=__initial_sp; isb");
timer_stop();
P1_0_reset();
while(true) {
P1_1_toggle();
for(volatile int i = 0; i < 5000000; ++i) {}
}
}
IHANDLER void BusFault_Handler() { P1_1_set(); while(1) {} }
static void uint64_to_string(char *buf, uint64_t value) {
if(0 == value) {
......@@ -93,6 +85,7 @@ static void uint64_to_string(char *buf, uint64_t value) {
}
}
#ifndef ID_SYSTEM
static void command_bch(char *arg) {
errno = 0;
unsigned long long val = strtoull(arg, NULL, 10);
......@@ -146,11 +139,16 @@ static void command_eic(char *arg) {
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
}
static void command_rst(char *arg) {
NVIC_SystemReset();
}
#endif /* ifndef ID_SYSTEM */
static void command_inf(char *arg) {
#ifdef ID_SYSTEM
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:id " SERIALSTR "\r");
#endif /* ifndef ID_SYSTEM */
// send FREQUENCY
char buf[128] = {0};
......@@ -169,11 +167,13 @@ static void command_inf(char *arg) {
default: CDC_Device_SendString(&VirtualSerial_CDC_Interface, "e:v\r"); break;
}
#ifndef ID_SYSTEM
if(timer_has_overflow_detection()) {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:ov e\r");
} else {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:ov d\r");
}
#endif /* ifndef ID_SYSTEM */
if(PREF->PCON & PREF_PCON_IBYP_Msk) {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:ic d\n");
......@@ -185,10 +185,6 @@ static void command_inf(char *arg) {
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
}
static void command_rst(char *arg) {
NVIC_SystemReset();
}
void* __aeabi_memset(void *s, int c, size_t n){
size_t i;
for (i = 0; i < n; i++) {
......@@ -217,6 +213,7 @@ int main(void) {
CoreDebug->DHCSR &= ~CoreDebug_DHCSR_C_DEBUGEN_Msk;
CoreDebug->DEMCR |= CoreDebug_DEMCR_MON_EN_Msk | CoreDebug_DEMCR_TRCENA_Msk;
#ifndef ID_SYSTEM
NVIC_SetPriorityGrouping(0);
NVIC_SetPriority(DebugMonitor_IRQn, 0);
......@@ -227,6 +224,8 @@ int main(void) {
}
timer_init();
#endif /* ifndef ID_SYSTEM */
USB_Init();
while(true) {
int16_t count = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface);
......@@ -242,11 +241,14 @@ int main(void) {
buffer[pos] = '\0';
#define COMMAND(NAME, FUNC) { if(!strncmp(NAME " ", buffer, strlen(NAME) + 1)) { FUNC(&buffer[strlen(NAME)]); } }
COMMAND("rst", command_rst)
COMMAND("inf", command_inf)
#ifndef ID_SYSTEM
COMMAND("rst", command_rst)
COMMAND("bch", command_bch)
COMMAND("dic", command_dic)
COMMAND("eic", command_eic)
#endif /* ifndef ID_SYSTEM */
#undef COMMAND
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment