commit 05bfa953f4eb5c71470fa5aff044c45c59a9001e Author: LEdoian Date: Thu Apr 14 13:06:47 2016 +0200 First commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef6eb48 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +TARGET = main +GCCFLAGS = -L../../libopencm3/libopencm3/include -DSTM32F1 +LIBS = ../../libopencm3/libopencm3/lib/libopencm3_stm32f1.a + +.DEFAULT: compile link + +.PHONY: compile flash all link + +all: compile link flash + +compile: $(TARGET).o + +%.o: %.c + arm-none-eabi-gcc -c $(GCCFLAGS) $*.c -o $*.o + +link: $(TARGET).bin + +%.bin: %.o $(LIBS) + arm-none-eabi-gcc $^ -o $*.bin diff --git a/Makefile_analysis b/Makefile_analysis new file mode 100644 index 0000000..6ab050d --- /dev/null +++ b/Makefile_analysis @@ -0,0 +1,70 @@ +BINARY=fancyblink +LDSCRIPT=../stm32vl-discovery.ld +?? LDSCRIPT=./lib-ex/ex/stm32/f1/stvldisco/stm32vl-discovery.ld +LIBNAME= opencm3-stm32f1 +DEFS = -DSTM32F1 + +FP_FLAGS = -msoft-float +ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd +=> ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float -mfix-cortex-m3-ldrd + +STLINK_PORT = 4242 + +### Makefile.rules +PREFIX = arm-none-eabi +CC = $(PREFIX)-gcc +=> CC = arm-none-eabi-gcc +LD = $(PREFIX)-gcc +=> LD = arm-none-eabi-gcc +AS = $(PREFIX)-as +=> AS = arm-none-eabi-as +OBJCOPY = $(PREFIX)-objcopy +=> OBJCOPY = arm-none-eabi-objcopy + +OBJS = $(BINARY).o +=> OBJS = fancyblink.o + +LIBPATH = ./libopencm3 ?? Prostě cesta k libopencm3 +OPENCM3_DIR = magic!! ?? složka, kde je libopencm3 + +INCLUDE_DIR = $(OPENCM3_DIR)/include +=> INCLUDE_DIR ??= ~/Dev/STM/libocm3/libocm3/include +LIB_DIR = $(OPENCM3_DIR)/lib +=> LIB_DIR ??= ~/Dev/STM/libocm3/libocm3/lib +SCRIPT_DIR = $(OPENCM3_DIR)/scripts +=> SCRIPT_DIR ??= ~/Dev/STM/libocm3/libocm3/scripts + +CFLAGS = -Os -g -Wextra -Wshadow -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -fno-common -ffunction-sections -fdata-sections + ?? Většina zbytečných (-W...) +CPPFLAGS = -MD -Wall -Wundef -I$(INCLUDE_DIR) $(DEFS) +=> CPPFLAGS = -MD -Wall -Wundef -I~/Dev/ST/locm3/locm3/include -DSTM32F1 +LDFLAGS = --static -nostartfiles -L$(LIB_DIR) -T$(LDSCRIPT) -Wl,-Map=$(*).map -Wl,--gc-sections + ?? $(*).map prostě najít .map soubor +=> LDFLAGS = --static -nostartfiles -L.../libocm3/lib -Tněkde/stm32vl-discovery.ld -Wl,-Map=$(*).map -Wl,--gc-sections + +LDLIBS = -l$(LIBNAME) -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group +=> LDLIBS = -lopencm3-stm32f1 -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group + +>>> LET US COMPILE +-------------------------------------------------- + +To make the .o: +=============== +$(CC) $(CFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o něco.o -c něco.c +=> arm-none-eabi-gcc {Flagy na všechno} -c něco.c -o něco.o +>>> Hotovo!! + +To make the elf: +================ +$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o něco.elf + -> vyžaduje $(OBJS), existenci $(LDSCRIPT) a $(LIB_DIR)/lib$(LIBNAME).a +=> arm-none-eabi-gcc {hromada zbytečných LDFLAGS, ARCH_FLAGS} něco.o {LDLIBS} -o něco.elf + -> vyžaduje vytvoření něco.o (zbytek už je v libopencm3, SNAD) +>>> Hotovo!! + +To make the bin: +================ +$(OBJCOPY) -Obinary něco.elf něco.bin +=> arm-none-eabi-objcopy -Obinary něco.elf něco.bin +>>> Hotovo!! + diff --git a/Makefile_libopencm3-examples b/Makefile_libopencm3-examples new file mode 100644 index 0000000..d1ae93e --- /dev/null +++ b/Makefile_libopencm3-examples @@ -0,0 +1 @@ +include ../../libopencm3-examples/libopencm3-examples/examples/stm32/f1/stm32vl-discovery/fancyblink/Makefile diff --git a/main.c b/main.c new file mode 100644 index 0000000..b298553 --- /dev/null +++ b/main.c @@ -0,0 +1,55 @@ +/* + * My first project + * + * It blinks LEDs like counting in binary, when the button is pressed, it reverses the order + * + * Build on top of libopenocm3, blackbox parts of code (setup()) copied from + * libopencm3-examples/examples/stm32/f1/stm32vl-discovery/button project + * + * Open source licence, let's say Artistic Licence, although it doesn't matter, as it is local only + */ + +#include +#include +#include + +#define DELAY 8000000 // Should be a second, or maybe not (second iff 8MHz clk, 1/3second if 24MHz clk) +#define STM32F1 1 // Needed for libopencm3 + +void setup (void) { // All the blackbox code + rcc_clock_setup_in_hse_8mhz_out_24mhz(); + rcc_periph_clock_enable(RCC_GPIOC); + rcc_periph_clock_enable(RCC_GPIOA); + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8 | GPIO9); + gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO0); +} + +void inline wait (int ticks) { // This works in libopenocm3 examples + int i; + for (i=0;i