diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-02-24 19:14:10 +0100 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-02-24 19:14:10 +0100 |
commit | 23a1333abe125ff2dd4a1493dd6553ddccf84514 (patch) | |
tree | 90a954270b90facff3709f12c97a9ce3f6efe508 /controller/fw | |
parent | b5196749352cdba56b99221e648feb371cf017ac (diff) | |
download | master-thesis-23a1333abe125ff2dd4a1493dd6553ddccf84514.tar.gz master-thesis-23a1333abe125ff2dd4a1493dd6553ddccf84514.tar.bz2 master-thesis-23a1333abe125ff2dd4a1493dd6553ddccf84514.zip |
Initial reset controller firmware
Diffstat (limited to 'controller/fw')
-rw-r--r-- | controller/fw/Makefile | 93 | ||||
-rw-r--r-- | controller/fw/main.c | 53 | ||||
-rw-r--r-- | controller/fw/mspdebug_wrapper.c | 112 | ||||
-rw-r--r-- | controller/fw/stm32f407.ld | 34 |
4 files changed, 292 insertions, 0 deletions
diff --git a/controller/fw/Makefile b/controller/fw/Makefile new file mode 100644 index 0000000..8a6d0da --- /dev/null +++ b/controller/fw/Makefile @@ -0,0 +1,93 @@ + +SOURCES := main.c mspdebug_wrapper.c +SOURCES += mspdebug/drivers/jtaglib.c + +BUILDDIR ?= build +BINARY := safetyreset +LDSCRIPT := stm32f407.ld +LIBNAME := opencm3_stm32f4 + +OPENCM3_DIR ?= libopencm3 + +PREFIX ?= arm-none-eabi- + + +CC := $(PREFIX)gcc +CXX := $(PREFIX)g++ +LD := $(PREFIX)gcc +AR := $(PREFIX)ar +AS := $(PREFIX)as +OBJCOPY := $(PREFIX)objcopy +OBJDUMP := $(PREFIX)objdump +GDB := $(PREFIX)gdb + + +CFLAGS += -I$(OPENCM3_DIR)/include -Imspdebug/util -Imspdebug/drivers + +CFLAGS += -Os -std=c11 -g -DSTM32F4 +# Note: libopencm3 requires some standard libc definitions from stdint.h and stdbool.h, so we don't pass -nostdinc here. +CFLAGS += -nostdlib -ffreestanding +CFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -g +CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration -Wundef +CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes +CFLAGS += -fno-common -ffunction-sections -fdata-sections + +LDFLAGS += --static -nostartfiles +LDFLAGS += -T$(LDSCRIPT) +LDFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -g +LDFLAGS += -Wl,--cre +#LDFLAGS += -Wl,--gc-sections +LDFLAGS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group +LDFLAGS += -L$(OPENCM3_DIR)/lib +LDFLAGS += -l$(LIBNAME) $(shell $(CC) -print-libgcc-file-name) + +all: elf + +elf: $(BUILDDIR)/$(BINARY).elf +bin: $(BUILDDIR)/$(BINARY).bin +hex: $(BUILDDIR)/$(BINARY).hex +srec: $(BUILDDIR)/$(BINARY).srec +list: $(BUILDDIR)/$(BINARY).list + +images: $(BUILDDIR)/$(BINARY).images + +$(OPENCM3_DIR)/lib/lib$(LIBNAME).a: + echo "Warning, $@ not found, attempting to rebuild in $(OPENCM3_DIR)" + $(MAKE) -C $(OPENCM3_DIR) + +OBJS := $(addprefix $(BUILDDIR)/,$(SOURCES:%.c=%.o)) + +# Define a helper macro for debugging make errors online +# you can type "make print-OPENCM3_DIR" and it will show you +# how that ended up being resolved by all of the included +# makefiles. +print-%: + @echo $*=$($*) + +$(BUILDDIR)/%.images: $(BUILDDIR)/%.bin $(BUILDDIR)/%.hex $(BUILDDIR)/%.srec $(BUILDDIR)/%.list $(BUILDDIR)/%.map + +$(BUILDDIR)/%.bin: $(BUILDDIR)/%.elf + $(OBJCOPY) -Obinary $< $@ + +$(BUILDDIR)/%.hex: $(BUILDDIR)/%.elf + $(OBJCOPY) -Oihex $< $@ + +$(BUILDDIR)/%.srec: $(BUILDDIR)/%.elf + $(OBJCOPY) -Osrec $< $@ + +$(BUILDDIR)/%.list: $(BUILDDIR)/%.elf + $(OBJDUMP) -S $< > $@ + +$(BUILDDIR)/%.elf: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(LIBNAME).a + $(LD) $(OBJS) $(LDFLAGS) -o $@ -Wl,-Map=$*.map + +$(BUILDDIR)/%.o: %.c + mkdir -p $(dir $@) + $(CC) $(CFLAGS) -o $@ -c $< + +clean: + -rm -r $(BUILDDIR) + +.PHONY: images clean elf bin hex srec list + +-include $(OBJS:.o=.d) diff --git a/controller/fw/main.c b/controller/fw/main.c new file mode 100644 index 0000000..7359c59 --- /dev/null +++ b/controller/fw/main.c @@ -0,0 +1,53 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de> + * Copyright (C) 2011 Damjan Marion <damjan.marion@gmail.com> + * Copyright (C) 2011 Mark Panajotovic <marko@electrontube.org> + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <libopencm3/stm32/rcc.h> +#include <libopencm3/stm32/gpio.h> + +/* Set STM32 to 168 MHz. */ +static void clock_setup(void) +{ + rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); + rcc_periph_clock_enable(RCC_GPIOA); +} + +static void gpio_setup(void) +{ + gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO6 | GPIO7); +} + +int main(void) +{ + int i; + + clock_setup(); + gpio_setup(); + + gpio_set(GPIOA, GPIO6); + + while (1) { + gpio_toggle(GPIOA, GPIO6 | GPIO7); + for (i = 0; i < 6000000; i++) + __asm__("nop"); + } + + return 0; +} diff --git a/controller/fw/mspdebug_wrapper.c b/controller/fw/mspdebug_wrapper.c new file mode 100644 index 0000000..3d8daf5 --- /dev/null +++ b/controller/fw/mspdebug_wrapper.c @@ -0,0 +1,112 @@ + +#include "sr_global.h" + +#include "output.h" +#include "jtaglib.h" + +int printc_err(const char *fmt, ...) { + UNUSED(fmt); + /* ignore */ +} + + +static void sr_jtdev_power_on(struct jtdev *p) { + /* ignore */ +} + +static void sr_jtdev_connect(struct jtdev *p) { + /* ignore */ +} + +static enum sr_gpio_types { + SR_GPIO_TCK, + SR_GPIO_TMS, + SR_GPIO_TDI, + SR_GPIO_RST, + SR_GPIO_TST, + SR_GPIO_TDO, + SR_NUM_GPIOS +}; + +struct { + uint32_t port, uint16_t num, +} gpios[SR_NUM_GPIOS] = { + [SR_GPIO_TCK] = {}, + [SR_GPIO_TMS] = {}, + [SR_GPIO_TDI] = {}, + [SR_GPIO_RST] = {}, + [SR_GPIO_TST] = {}, + [SR_GPIO_TDO] = {}, +}; + +static void sr_jtdev_tck(struct jtdev *p, int out) { +} + +static void sr_jtdev_tms(struct jtdev *p, int out) { +} + +static void sr_jtdev_tdi(struct jtdev *p, int out) { +} + +static void sr_jtdev_rst(struct jtdev *p, int out) { +} + +static void sr_jtdev_tst(struct jtdev *p, int out) { +} + +static int sr_jtdev_tdo_get(struct jtdev *p) { +} + +static void sr_jtdev_tclk(struct jtdev *p, int out) { +} + +static int sr_jtdev_tclk_get(struct jtdev *p) { +} + +static void sr_jtdev_tclk_strobe(struct jtdev *p, unsigned int count) { +} + +static void sr_jtdev_led_green(struct jtdev *p, int out) { + UNUSED(p); + UNUSED(out); + /* ignore */ +} + +static void sr_jtdev_led_red(struct jtdev *p, int out) { + UNUSED(p); + UNUSED(out); + /* ignore */ +} + + +static struct jtdev_func sr_jtdev_vtable = { + .jtdev_open = 0, + .jtdev_close = 0, + + .jtdev_power_off = 0, + .jtdev_release = 0, + + .jtdev_power_on = sr_jtdev_power_on, + .jtdev_connect = sr_jtdev_connect, + + .jtdev_tck = sr_jtdev_tck, + .jtdev_tms = sr_jtdev_tms, + .jtdev_tdi = sr_jtdev_tdi, + .jtdev_rst = sr_jtdev_rst, + .jtdev_tst = sr_jtdev_tst, + .jtdev_tdo_get = sr_jtdev_tdo_get, + + .jtdev_tclk = sr_jtdev_tclk, + .jtdev_tclk_get = sr_jtdev_tclk_get, + .jtdev_tclk_strobe = sr_jtdev_tclk_strobe, + + .jtdev_led_green = sr_jtdev_led_green, + .jtdev_led_red = sr_jtdev_led_red, + +}; + +static struct jtdev sr_jtdev = { + 0, + .f = &sr_jtdev_vtable +}; + diff --git a/controller/fw/stm32f407.ld b/controller/fw/stm32f407.ld new file mode 100644 index 0000000..764ed6b --- /dev/null +++ b/controller/fw/stm32f407.ld @@ -0,0 +1,34 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de> + * Copyright (C) 2011 Stephen Caudle <scaudle@doceme.com> + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + +/* Linker script for ST STM32F4DISCOVERY (STM32F407VG, 1024K flash, 128K RAM). */ + +/* Define memory regions. */ +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 1024K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K + ccm (rwx) : ORIGIN = 0x10000000, LENGTH = 64K + bkp (rwx) : ORIGIN = 0x40024000, LENGTH = 4K +} + +/* Include the common ld script. */ +INCLUDE cortex-m-generic.ld + |