aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules6
m---------stm32f091/lib/STM32-base0
m---------stm32f091/lib/STM32CubeF00
-rw-r--r--stm32f091/main.cpp21
-rw-r--r--stm32f091/makefile80
6 files changed, 108 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index deb8e63..6069cfc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
copyright
+**/*.o
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..7217253
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,6 @@
+[submodule "stm32f091/lib/STM32-base"]
+ path = stm32f091/lib/STM32-base
+ url = https://github.com/STM32-base/STM32-base
+[submodule "stm32f091/lib/STM32CubeF0"]
+ path = stm32f091/lib/STM32CubeF0
+ url = https://github.com/STMicroelectronics/STM32CubeF0
diff --git a/stm32f091/lib/STM32-base b/stm32f091/lib/STM32-base
new file mode 160000
+Subproject d260b616689692bac0411812b37be065b34f335
diff --git a/stm32f091/lib/STM32CubeF0 b/stm32f091/lib/STM32CubeF0
new file mode 160000
+Subproject 830a0e950d421c17abff57a2ea1e97787035551
diff --git a/stm32f091/main.cpp b/stm32f091/main.cpp
new file mode 100644
index 0000000..180240e
--- /dev/null
+++ b/stm32f091/main.cpp
@@ -0,0 +1,21 @@
+#include <stm32f0xx.h>
+#include <stdint.h>
+
+#define PORT GPIOA
+#define PIN 5
+
+int main() {
+ RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN;
+
+ PORT->MODER &= ~(0b11 << (PIN * 2));
+ PORT->MODER |= (0b01 << (PIN * 2));
+
+ uint8_t led = 1;
+
+ while (1) {
+ PORT->ODR &= ~(1 << PIN);
+ PORT->ODR |= (led << PIN);
+ led ^= 1;
+ for (unsigned long i = 0; i < 50000; i++) asm("nop");
+ }
+}
diff --git a/stm32f091/makefile b/stm32f091/makefile
new file mode 100644
index 0000000..63139cb
--- /dev/null
+++ b/stm32f091/makefile
@@ -0,0 +1,80 @@
+CC = arm-none-eabi-g++
+LD = arm-none-eabi-g++
+OC = arm-none-eabi-objcopy
+RM = rm -f
+
+TARGET = main
+MCU_SPEC = cortex-m0
+
+CFLAGS += -g
+CFLAGS += -Wall
+CFLAGS += -Os
+CFLAGS += -mcpu=$(MCU_SPEC)
+CFLAGS += -mthumb
+CFLAGS += --specs=nosys.specs
+CFLAGS += -I./lib/STM32CubeF0/Drivers/CMSIS/DSP/Include
+CFLAGS += -I./lib/STM32CubeF0/Drivers/CMSIS/Core/Include
+CFLAGS += -I./lib/STM32CubeF0/Drivers/CMSIS/Device/ST/STM32F0xx/Include
+CFLAGS += -I./lib/STM32CubeF0/Drivers/CMSIS/RTOS2/Include
+CFLAGS += -I./lib/STM32CubeF0/Drivers/CMSIS/Core_A/Include
+CFLAGS += -I./lib/STM32CubeF0/Drivers/CMSIS/Include
+CFLAGS += -I./lib/STM32CubeF0/Drivers/CMSIS/NN/Include
+CFLAGS += -I./lib/STM32-base/startup
+CFLAGS += -D STM32F091xC
+
+LFLAGS += -Wl,-u,vfprintf
+LFLAGS += -lm
+LFLAGS += -Wl,-relax
+LFLAGS += -Wl,-gc-sections
+LFLAGS += -mcpu=$(MCU_SPEC)
+LFLAGS += -mthumb
+LFLAGS += -Wall
+LFLAGS += --specs=nosys.specs
+LFLAGS += -nostartfiles
+LFLAGS += -nostdlib
+LFLAGS += -lgcc
+LFLAGS += -Wl,-L./lib/STM32-base/linker,-T./lib/STM32-base/linker/STM32F0xx/STM32F091xC.ld
+
+LFLAGS += -Wa,--defsym,CALL_ARM_SYSTEM_INIT=1
+LFLAGS += -march=armv6-m
+LFLAGS += -mlittle-endian
+LFLAGS += -mthumb
+LFLAGS += -masm-syntax-unified
+LFLAGS += -fno-threadsafe-statics
+LFLAGS += -fno-rtti
+LFLAGS += -fno-exceptions
+LFLAGS += -fno-unwind-tables
+
+# AFLAGS += -ffunction-sections -fdata-sections
+
+SRCS += $(wildcard *.cpp)
+OBJS += $(patsubst %.cpp,%.o, $(SRCS))
+
+# SRCS += ./lib/STM32-base/startup/STM32F0xx/STM32F091xC.s
+SRCS += ./lib/STM32CubeF0/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/system_stm32f0xx.o
+OBJS += ./lib/STM32-base/startup/STM32F0xx/STM32F091xC.o
+
+%.o: %.s
+ $(CC) -x assembler-with-cpp -c $(CFLAGS) $(AFLAGS) $< -o $@
+
+%.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+%.o: %.cpp
+ $(CC) -c $(CFLAGS) $< -o $@
+
+$(TARGET).elf: $(OBJS)
+ $(LD) $^ $(LFLAGS) -o $@
+
+$(TARGET).bin: $(TARGET).elf
+ $(OC) -O binary $< $@
+
+flash: $(TARGET).bin
+ st-flash write $(TARGET).bin 0x08000000
+
+compile_commands: clean
+ compiledb make
+
+clean:
+ $(RM) $(TARGET).bin $(TARGET).elf $(OBJS)
+