First commit
commit
05bfa953f4
@ -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
|
@ -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!!
|
||||
|
@ -0,0 +1 @@
|
||||
include ../../libopencm3-examples/libopencm3-examples/examples/stm32/f1/stm32vl-discovery/fancyblink/Makefile
|
@ -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 <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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<ticks;i++) __asm__("nop");
|
||||
return;
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
setup();
|
||||
|
||||
// Array of what leds should be on
|
||||
uint16_t states[4] = {0, GPIO9, GPIO8, GPIO9 | GPIO8};
|
||||
enum {FORWARD, BACKWARD} direction = FORWARD;
|
||||
bool pressed = false;
|
||||
char state;
|
||||
|
||||
while (true) {
|
||||
if (/*Button pressed, but was not*/ gpio_get(GPIOA, GPIO0) && (pressed == false) ) {
|
||||
pressed = true;
|
||||
direction = (direction == FORWARD ? BACKWARD : FORWARD); // Switch direction
|
||||
} else /*Button not pressed, possibly released*/ {
|
||||
pressed = false;
|
||||
}
|
||||
state = (direction == FORWARD ? (state + 1)%4 : (/*state+4-1*/ state+3)%4 );
|
||||
|
||||
gpio_set(GPIOC, states[state]);
|
||||
wait(DELAY);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue