From 8318384cf1fec4d0b336e5d4deb1f126526584be Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Thu, 19 Jul 2012 22:41:52 +0000 Subject: More progress towards L1 support. Believe gpio is complete, but untested without finishing at least the RCC defines. RCC defines are a work in progress --- examples/stm32/l1/Makefile.include | 165 +++++++++++++++++++++ .../stm32/l1/stm32l-discovery/miniblink/Makefile | 25 ++++ .../stm32/l1/stm32l-discovery/miniblink/README | 9 ++ .../l1/stm32l-discovery/miniblink/miniblink.c | 72 +++++++++ 4 files changed, 271 insertions(+) create mode 100644 examples/stm32/l1/Makefile.include create mode 100644 examples/stm32/l1/stm32l-discovery/miniblink/Makefile create mode 100644 examples/stm32/l1/stm32l-discovery/miniblink/README create mode 100644 examples/stm32/l1/stm32l-discovery/miniblink/miniblink.c (limited to 'examples') diff --git a/examples/stm32/l1/Makefile.include b/examples/stm32/l1/Makefile.include new file mode 100644 index 0000000..f152b2a --- /dev/null +++ b/examples/stm32/l1/Makefile.include @@ -0,0 +1,165 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2009 Uwe Hermann +## Copyright (C) 2010 Piotr Esden-Tempski +## +## 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 . +## + +PREFIX ?= arm-none-eabi +#PREFIX ?= arm-elf +CC = $(PREFIX)-gcc +LD = $(PREFIX)-gcc +OBJCOPY = $(PREFIX)-objcopy +OBJDUMP = $(PREFIX)-objdump +GDB = $(PREFIX)-gdb +# If you are copying this file to use in your own project, +# You will need to change this... (Leave unset to assume installed +# in the toolchain itself) +#OPENCM3_DIR ?= /opt/libopencm3/$(PREFIX) +OPENCM3_DIR ?= ../../../../.. + +ARCH_FLAGS = -mcpu=cortex-m3 -mthumb -msoft-float +CFLAGS += -g -Os -Wall -Wextra \ + -fno-common $(ARCH_FLAGS) -MD -DSTM32L1 +LDSCRIPT ?= $(BINARY).ld +LDFLAGS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ + -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ + $(ARCH_FLAGS) -mfix-cortex-m3-ldrd + +ifneq ($(OPENCM3_DIR),) +CFLAGS += -I$(OPENCM3_DIR)/include +LDFLAGS += -L$(OPENCM3_DIR)/lib -L$(OPENCM3_DIR)/lib/stm32/l1 +SCRIPT_DIR = $(OPENCM3_DIR)/share +else +SCRIPT_DIR = $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/../$(PREFIX)/share +endif + +OBJS += $(BINARY).o + +OOCD ?= openocd +OOCD_INTERFACE ?= flossjtag +OOCD_BOARD ?= olimex_stm32_h103 +# Black magic probe specific variables +# Set the BMP_PORT to a serial port and then BMP is used for flashing +BMP_PORT ?= +# texane/stlink can be used by uncommenting this... +# or defining it in your own makefiles +#STLINK_PORT ?= :4242 + +# Be silent per default, but 'make V=1' will show all compiler calls. +ifneq ($(V),1) +Q := @ +NULL := 2>/dev/null +else +LDFLAGS += -Wl,--print-gc-sections +endif + +.SUFFIXES: .elf .bin .hex .srec .list .images +.SECONDEXPANSION: +.SECONDARY: + +all: images + +images: $(BINARY).images +flash: $(BINARY).flash + +%.images: %.bin %.hex %.srec %.list + @#echo "*** $* images generated ***" + +%.bin: %.elf + @#printf " OBJCOPY $(*).bin\n" + $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin + +%.hex: %.elf + @#printf " OBJCOPY $(*).hex\n" + $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex + +%.srec: %.elf + @#printf " OBJCOPY $(*).srec\n" + $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec + +%.list: %.elf + @#printf " OBJDUMP $(*).list\n" + $(Q)$(OBJDUMP) -S $(*).elf > $(*).list + +ifeq ($(OPENCM3_DIR),) +%.elf: $(OBJS) $(LDSCRIPT) +else +%.elf: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/stm32/l1/libopencm3_stm32l1.a +endif + @#printf " LD $(subst $(shell pwd)/,,$(@))\n" + $(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32l1 $(LDFLAGS) + +%.o: %.c Makefile + @#printf " CC $(subst $(shell pwd)/,,$(@))\n" + $(Q)$(CC) $(CFLAGS) -o $@ -c $< + +clean: + $(Q)rm -f *.o + $(Q)rm -f *.d + $(Q)rm -f *.elf + $(Q)rm -f *.bin + $(Q)rm -f *.hex + $(Q)rm -f *.srec + $(Q)rm -f *.list + +ifeq ($(STLINK_PORT),) +ifeq ($(BMP_PORT),) +ifeq ($(OOCD_SERIAL),) +%.flash: %.hex + @printf " FLASH $<\n" + @# IMPORTANT: Don't use "resume", only "reset" will work correctly! + $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ + -f board/$(OOCD_BOARD).cfg \ + -c "init" -c "reset init" \ + -c "stm32l1x mass_erase 0" \ + -c "flash write_image $(*).hex" \ + -c "reset" \ + -c "shutdown" $(NULL) +else +%.flash: %.hex + @printf " FLASH $<\n" + @# IMPORTANT: Don't use "resume", only "reset" will work correctly! + $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ + -f board/$(OOCD_BOARD).cfg \ + -c "ft2232_serial $(OOCD_SERIAL)" \ + -c "init" -c "reset init" \ + -c "stm32l1x mass_erase 0" \ + -c "flash write_image $(*).hex" \ + -c "reset" \ + -c "shutdown" $(NULL) +endif +else +%.flash: %.elf + @echo " GDB $(*).elf (flash)" + $(Q)$(GDB) --batch \ + -ex 'target extended-remote $(BMP_PORT)' \ + -x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \ + $(*).elf +endif +else +%.flash: %.elf + @echo " GDB $(*).elf (flash)" + $(Q)$(GDB) --batch \ + -ex 'target extended-remote $(STLINK_PORT)' \ + -x $(SCRIPT_DIR)/libopencm3/scripts/stlink_flash.scr \ + $(*).elf +endif + +.PHONY: images clean + +-include $(OBJS:.o=.d) + diff --git a/examples/stm32/l1/stm32l-discovery/miniblink/Makefile b/examples/stm32/l1/stm32l-discovery/miniblink/Makefile new file mode 100644 index 0000000..8c88be0 --- /dev/null +++ b/examples/stm32/l1/stm32l-discovery/miniblink/Makefile @@ -0,0 +1,25 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2009 Uwe Hermann +## +## 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 . +## + +BINARY = miniblink + +LDSCRIPT = ../stm32l15xxB.ld + +include ../../Makefile.include + diff --git a/examples/stm32/l1/stm32l-discovery/miniblink/README b/examples/stm32/l1/stm32l-discovery/miniblink/README new file mode 100644 index 0000000..8bdd314 --- /dev/null +++ b/examples/stm32/l1/stm32l-discovery/miniblink/README @@ -0,0 +1,9 @@ +------------------------------------------------------------------------------ +README +------------------------------------------------------------------------------ + +This is the smallest-possible example program using libopencm3. + +It's intended for the ST STM32L-DISCOVERY eval board. It should blink +the blue LED on the board. + diff --git a/examples/stm32/l1/stm32l-discovery/miniblink/miniblink.c b/examples/stm32/l1/stm32l-discovery/miniblink/miniblink.c new file mode 100644 index 0000000..a9d7c3d --- /dev/null +++ b/examples/stm32/l1/stm32l-discovery/miniblink/miniblink.c @@ -0,0 +1,72 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2011 Stephen Caudle + * Copyright (C) 2012 Karl Palsson + * + * 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 . + */ + +#include +#include + +#define PORT_LED GPIOB +#define PIN_LED GPIO6 + +void gpio_setup(void) +{ + /* Enable GPIOB clock. */ + /* Manually: */ + RCC_AHBENR |= RCC_AHBENR_IOPBEN; + /* Using API functions: */ + //rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_IOPBEN); + + /* Set GPIO6 (in GPIO port B) to 'output push-pull'. */ + /* Using API functions: */ + gpio_mode_setup(PORT_LED, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED); +} + +int main(void) +{ + int i; + + gpio_setup(); + + /* Blink the LED (PC8) on the board. */ + while (1) { + /* Manually: */ + // GPIOD_BSRR = GPIO12; /* LED off */ + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ + // __asm__("nop"); + // GPIOD_BRR = GPIO12; /* LED on */ + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ + // __asm__("nop"); + + /* Using API functions gpio_set()/gpio_clear(): */ + // gpio_set(GPIOD, GPIO12); /* LED off */ + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ + // __asm__("nop"); + // gpio_clear(GPIOD, GPIO12); /* LED on */ + // for (i = 0; i < 1000000; i++) /* Wait a bit. */ + // __asm__("nop"); + + /* Using API function gpio_toggle(): */ + gpio_toggle(PORT_LED, PORT_LED); /* LED on/off */ + for (i = 0; i < 1000000; i++) /* Wait a bit. */ + __asm__("nop"); + } + + return 0; +} -- cgit v1.2.3