Merge branch 'master' of git://github.com/libopencm3/libopencm3 into upstream-merge
This commit is contained in:
commit
db35fbb7ba
12
.gitignore
vendored
12
.gitignore
vendored
@ -16,4 +16,14 @@ lib/*.ld
|
|||||||
html/
|
html/
|
||||||
latex/
|
latex/
|
||||||
*.pdf
|
*.pdf
|
||||||
|
# These are generated
|
||||||
|
include/libopencm3/**/nvic.h
|
||||||
|
include/libopencm3/**/**/nvic.h
|
||||||
|
lib/**/vector_nvic.c
|
||||||
|
lib/**/**/vector_nvic.c
|
||||||
|
include/libopencmsis/efm32/
|
||||||
|
include/libopencmsis/lm3s/
|
||||||
|
include/libopencmsis/lpc13xx/
|
||||||
|
include/libopencmsis/lpc17xx/
|
||||||
|
include/libopencmsis/lpc43xx/
|
||||||
|
include/libopencmsis/stm32/
|
||||||
|
56
Makefile
56
Makefile
@ -19,14 +19,20 @@
|
|||||||
|
|
||||||
PREFIX ?= arm-none-eabi
|
PREFIX ?= arm-none-eabi
|
||||||
#PREFIX ?= arm-elf
|
#PREFIX ?= arm-elf
|
||||||
|
|
||||||
|
ifeq ($(DETECT_TOOLCHAIN),)
|
||||||
DESTDIR ?= /usr/local
|
DESTDIR ?= /usr/local
|
||||||
|
else
|
||||||
|
DESTDIR ?= $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/..
|
||||||
|
endif
|
||||||
|
|
||||||
INCDIR = $(DESTDIR)/$(PREFIX)/include
|
INCDIR = $(DESTDIR)/$(PREFIX)/include
|
||||||
LIBDIR = $(DESTDIR)/$(PREFIX)/lib
|
LIBDIR = $(DESTDIR)/$(PREFIX)/lib
|
||||||
SHAREDIR = $(DESTDIR)/$(PREFIX)/share/libopencm3/scripts
|
SHAREDIR = $(DESTDIR)/$(PREFIX)/share/libopencm3/scripts
|
||||||
INSTALL = install
|
INSTALL = install
|
||||||
|
|
||||||
SRCLIBDIR = $(shell pwd)/lib
|
SRCLIBDIR = $(shell pwd)/lib
|
||||||
TARGETS = stm32/f1 stm32/f2 stm32/f4 lpc13xx lpc17xx lpc43xx lm3s
|
TARGETS = stm32/f1 stm32/f2 stm32/f4 stm32/l1 lpc13xx lpc17xx lpc43xx lm3s efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
|
||||||
|
|
||||||
# Be silent per default, but 'make V=1' will show all compiler calls.
|
# Be silent per default, but 'make V=1' will show all compiler calls.
|
||||||
ifneq ($(V),1)
|
ifneq ($(V),1)
|
||||||
@ -39,41 +45,57 @@ all: build
|
|||||||
|
|
||||||
build: lib examples
|
build: lib examples
|
||||||
|
|
||||||
lib:
|
generatedheaders:
|
||||||
$(Q)for i in $(addprefix $@/,$(TARGETS)); do \
|
@printf " UPDATING HEADERS\n"
|
||||||
if [ -d $$i ]; then \
|
$(Q)for yamlfile in `find . -name 'irq.yaml'`; do \
|
||||||
printf " BUILD $$i\n"; \
|
./scripts/irq2nvic_h $$yamlfile ; \
|
||||||
$(MAKE) -C $$i SRCLIBDIR=$(SRCLIBDIR) || exit $?; \
|
|
||||||
fi; \
|
|
||||||
done
|
done
|
||||||
|
|
||||||
examples: lib
|
cleanheaders:
|
||||||
$(Q)for i in $(addsuffix /*/*,$(addprefix $@/,$(TARGETS))); do \
|
@printf " CLEANING HEADERS\n"
|
||||||
if [ -d $$i ]; then \
|
$(Q)for yamlfile in `find . -name 'irq.yaml'`; do \
|
||||||
printf " BUILD $$i\n"; \
|
./scripts/irq2nvic_h --remove $$yamlfile ; \
|
||||||
$(MAKE) -C $$i || exit $?; \
|
|
||||||
fi; \
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
LIB_DIRS:=$(wildcard $(addprefix lib/,$(TARGETS)))
|
||||||
|
$(LIB_DIRS): generatedheaders
|
||||||
|
@printf " BUILD $@\n";
|
||||||
|
$(Q)$(MAKE) --directory=$@ SRCLIBDIR=$(SRCLIBDIR)
|
||||||
|
|
||||||
|
lib: $(LIB_DIRS)
|
||||||
|
$(Q)true
|
||||||
|
|
||||||
|
EXAMPLE_DIRS:=$(sort $(dir $(wildcard $(addsuffix /*/*/Makefile,$(addprefix examples/,$(TARGETS))))))
|
||||||
|
$(EXAMPLE_DIRS): lib
|
||||||
|
@printf " BUILD $@\n";
|
||||||
|
$(Q)$(MAKE) --directory=$@
|
||||||
|
|
||||||
|
examples: $(EXAMPLE_DIRS)
|
||||||
|
$(Q)true
|
||||||
|
|
||||||
install: lib
|
install: lib
|
||||||
@printf " INSTALL headers\n"
|
@printf " INSTALL headers\n"
|
||||||
$(Q)$(INSTALL) -d $(INCDIR)/libopencm3
|
$(Q)$(INSTALL) -d $(INCDIR)/libopencm3
|
||||||
|
$(Q)$(INSTALL) -d $(INCDIR)/libopencmsis
|
||||||
$(Q)$(INSTALL) -d $(LIBDIR)
|
$(Q)$(INSTALL) -d $(LIBDIR)
|
||||||
$(Q)$(INSTALL) -d $(SHAREDIR)
|
$(Q)$(INSTALL) -d $(SHAREDIR)
|
||||||
$(Q)cp -r include/libopencm3/* $(INCDIR)/libopencm3
|
$(Q)cp -r include/libopencm3/* $(INCDIR)/libopencm3
|
||||||
|
$(Q)cp -r include/libopencmsis/* $(INCDIR)/libopencmsis
|
||||||
@printf " INSTALL libs\n"
|
@printf " INSTALL libs\n"
|
||||||
$(Q)$(INSTALL) -m 0644 lib/*.a $(LIBDIR)
|
$(Q)$(INSTALL) -m 0644 lib/*.a $(LIBDIR)
|
||||||
@printf " INSTALL ldscripts\n"
|
@printf " INSTALL ldscripts\n"
|
||||||
$(Q)$(INSTALL) -m 0644 lib/*.ld $(LIBDIR)
|
$(Q)$(INSTALL) -m 0644 lib/*.ld $(LIBDIR)
|
||||||
|
$(Q)$(INSTALL) -m 0644 lib/efm32/*/*.ld $(LIBDIR)
|
||||||
@printf " INSTALL scripts\n"
|
@printf " INSTALL scripts\n"
|
||||||
$(Q)$(INSTALL) -m 0644 scripts/* $(SHAREDIR)
|
$(Q)$(INSTALL) -m 0644 scripts/* $(SHAREDIR)
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
$(Q)$(MAKE) -C doc doc
|
$(Q)$(MAKE) -C doc doc
|
||||||
|
|
||||||
clean:
|
# Bleh http://www.makelinux.net/make3/make3-CHP-6-SECT-1#make3-CHP-6-SECT-1
|
||||||
$(Q)for i in $(addprefix lib/,$(TARGETS)) \
|
clean: cleanheaders
|
||||||
$(addsuffix /*/*,$(addprefix examples/,$(TARGETS))); do \
|
$(Q)for i in $(LIB_DIRS) \
|
||||||
|
$(EXAMPLE_DIRS); do \
|
||||||
if [ -d $$i ]; then \
|
if [ -d $$i ]; then \
|
||||||
printf " CLEAN $$i\n"; \
|
printf " CLEAN $$i\n"; \
|
||||||
$(MAKE) -C $$i clean SRCLIBDIR=$(SRCLIBDIR) || exit $?; \
|
$(MAKE) -C $$i clean SRCLIBDIR=$(SRCLIBDIR) || exit $?; \
|
||||||
@ -82,5 +104,5 @@ clean:
|
|||||||
@printf " CLEAN doxygen\n"
|
@printf " CLEAN doxygen\n"
|
||||||
$(Q)$(MAKE) -C doc clean
|
$(Q)$(MAKE) -C doc clean
|
||||||
|
|
||||||
.PHONY: build lib examples install doc clean
|
.PHONY: build lib $(LIB_DIRS) examples $(EXAMPLE_DIRS) install doc clean generatedheaders cleanheaders
|
||||||
|
|
||||||
|
24
README
24
README
@ -48,7 +48,8 @@ Example projects
|
|||||||
|
|
||||||
The library ships with a few small example projects which illustrate how
|
The library ships with a few small example projects which illustrate how
|
||||||
individual subsystems of the microcontrollers can be configured and used with
|
individual subsystems of the microcontrollers can be configured and used with
|
||||||
libopencm3.
|
libopencm3. The makefiles are generally useable for your own projects with
|
||||||
|
only minimal changes for the libopencm3 install path (See Installation)
|
||||||
|
|
||||||
For flashing the 'miniblink' example (after you built libopencm3 and the
|
For flashing the 'miniblink' example (after you built libopencm3 and the
|
||||||
examples by typing 'make' at the top-level directory) onto the Olimex
|
examples by typing 'make' at the top-level directory) onto the Olimex
|
||||||
@ -79,16 +80,23 @@ Installation
|
|||||||
|
|
||||||
$ make install
|
$ make install
|
||||||
|
|
||||||
This will install the library in /usr/local. If you want to install it
|
This will install the library into /usr/local. (permissions permitting)
|
||||||
elsewhere, use the following syntax:
|
|
||||||
|
|
||||||
$ DESTDIR=/opt make install
|
If you want to install it elsewhere, use the following syntax:
|
||||||
|
|
||||||
The recommended location is to install into your toolchain directory, e.g.
|
$ make DESTDIR=/opt/libopencm3 install
|
||||||
/home/someuser/sat for a toolchain built using the summon-arm-toolchain
|
|
||||||
script from https://github.com/esden/summon-arm-toolchain.
|
|
||||||
|
|
||||||
$ DESTDIR=~/sat make install
|
If you want to attempt to install into your toolchain, use this:
|
||||||
|
|
||||||
|
$ make DETECT_TOOLCHAIN=1 install
|
||||||
|
|
||||||
|
Note: If you install this into your toolchain, you don't need to pass
|
||||||
|
any extra -L or -I flags into your projects. However, this also means
|
||||||
|
you must NOT pass any -L or -I flags that point into the toolchain. This
|
||||||
|
_will_ confuse the linker. (ie, for summon-arm-toolchain, do NOT pass
|
||||||
|
-L/home/user/sat/lib) Common symptoms of confusing
|
||||||
|
the linker are hard faults caused by branches into arm code.
|
||||||
|
You can use objdump to check for this in your final elf.
|
||||||
|
|
||||||
|
|
||||||
Coding style and development guidelines
|
Coding style and development guidelines
|
||||||
|
@ -1491,13 +1491,13 @@ ENABLE_PREPROCESSING = YES
|
|||||||
# compilation will be performed. Macro expansion can be done in a controlled
|
# compilation will be performed. Macro expansion can be done in a controlled
|
||||||
# way by setting EXPAND_ONLY_PREDEF to YES.
|
# way by setting EXPAND_ONLY_PREDEF to YES.
|
||||||
|
|
||||||
MACRO_EXPANSION = NO
|
MACRO_EXPANSION = YES
|
||||||
|
|
||||||
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
|
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
|
||||||
# then the macro expansion is limited to the macros specified with the
|
# then the macro expansion is limited to the macros specified with the
|
||||||
# PREDEFINED and EXPAND_AS_DEFINED tags.
|
# PREDEFINED and EXPAND_AS_DEFINED tags.
|
||||||
|
|
||||||
EXPAND_ONLY_PREDEF = NO
|
EXPAND_ONLY_PREDEF = YES
|
||||||
|
|
||||||
# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
|
# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
|
||||||
# pointed to by INCLUDE_PATH will be searched when a #include is found.
|
# pointed to by INCLUDE_PATH will be searched when a #include is found.
|
||||||
@ -1525,7 +1525,7 @@ INCLUDE_FILE_PATTERNS =
|
|||||||
# undefined via #undef or recursively expanded use the := operator
|
# undefined via #undef or recursively expanded use the := operator
|
||||||
# instead of the = operator.
|
# instead of the = operator.
|
||||||
|
|
||||||
PREDEFINED =
|
PREDEFINED = __attribute__(x)=
|
||||||
|
|
||||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
||||||
# this tag can be used to specify a list of macro names that should be expanded.
|
# this tag can be used to specify a list of macro names that should be expanded.
|
||||||
|
@ -37,7 +37,7 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS += -O0 -g3 -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
CFLAGS += -O0 -g3 -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
-mcpu=cortex-m3 -mthumb -MD
|
-mcpu=cortex-m3 -mthumb -MD -DLM3S
|
||||||
LDSCRIPT ?= $(BINARY).ld
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
||||||
|
@ -37,7 +37,7 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
-mcpu=cortex-m3 -mthumb -MD
|
-mcpu=cortex-m3 -mthumb -MD -DLPC13XX
|
||||||
LDSCRIPT ?= $(BINARY).ld
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
||||||
|
@ -37,7 +37,7 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS += -O0 -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
CFLAGS += -O0 -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
-mcpu=cortex-m3 -mthumb -MD
|
-mcpu=cortex-m3 -mthumb -MD -DLPC17XX
|
||||||
LDSCRIPT ?= $(BINARY).ld
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
||||||
|
@ -41,7 +41,7 @@ endif
|
|||||||
|
|
||||||
CFLAGS += -O2 -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
CFLAGS += -O2 -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
-mcpu=cortex-m4 -mthumb -MD \
|
-mcpu=cortex-m4 -mthumb -MD \
|
||||||
-mfloat-abi=hard -mfpu=fpv4-sp-d16
|
-mfloat-abi=hard -mfpu=fpv4-sp-d16 -DLPC43XX
|
||||||
LDSCRIPT ?= $(BINARY).ld
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections -Xlinker -Map=$(BINARY).map
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections -Xlinker -Map=$(BINARY).map
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include <libopencm3/lpc43xx/gpio.h>
|
#include <libopencm3/lpc43xx/gpio.h>
|
||||||
#include <libopencm3/lpc43xx/scu.h>
|
#include <libopencm3/lpc43xx/scu.h>
|
||||||
#include <libopencm3/lpc43xx/cgu.h>
|
#include <libopencm3/lpc43xx/cgu.h>
|
||||||
#include <libopencm3/lpc43xx/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/lpc43xx/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/cm3/scs.h>
|
#include <libopencm3/cm3/scs.h>
|
||||||
|
|
||||||
#include "../jellybean_conf.h"
|
#include "../jellybean_conf.h"
|
||||||
|
@ -45,6 +45,15 @@ LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
|
|||||||
-L$(TOOLCHAIN_DIR)/lib \
|
-L$(TOOLCHAIN_DIR)/lib \
|
||||||
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \
|
||||||
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd
|
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd
|
||||||
|
|
||||||
|
ifneq ($(OPENCM3_DIR),)
|
||||||
|
CFLAGS += -I$(OPENCM3_DIR)/include
|
||||||
|
LDFLAGS += -L$(OPENCM3_DIR)/lib -L$(OPENCM3_DIR)/lib/stm32/f1
|
||||||
|
SCRIPT_DIR = $(OPENCM3_DIR)/share
|
||||||
|
else
|
||||||
|
SCRIPT_DIR = $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/../$(PREFIX)/share
|
||||||
|
endif
|
||||||
|
|
||||||
OBJS += $(BINARY).o
|
OBJS += $(BINARY).o
|
||||||
|
|
||||||
OOCD ?= openocd
|
OOCD ?= openocd
|
||||||
@ -53,6 +62,9 @@ OOCD_BOARD ?= olimex_stm32_h103
|
|||||||
# Black magic probe specific variables
|
# Black magic probe specific variables
|
||||||
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
||||||
BMP_PORT ?=
|
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.
|
# Be silent per default, but 'make V=1' will show all compiler calls.
|
||||||
ifneq ($(V),1)
|
ifneq ($(V),1)
|
||||||
@ -107,6 +119,7 @@ clean:
|
|||||||
$(Q)rm -f *.srec
|
$(Q)rm -f *.srec
|
||||||
$(Q)rm -f *.list
|
$(Q)rm -f *.list
|
||||||
|
|
||||||
|
ifeq ($(STLINK_PORT),)
|
||||||
ifeq ($(BMP_PORT),)
|
ifeq ($(BMP_PORT),)
|
||||||
ifeq ($(OOCD_SERIAL),)
|
ifeq ($(OOCD_SERIAL),)
|
||||||
%.flash: %.hex
|
%.flash: %.hex
|
||||||
@ -140,6 +153,14 @@ else
|
|||||||
-x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \
|
-x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \
|
||||||
$(*).elf
|
$(*).elf
|
||||||
endif
|
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
|
.PHONY: images clean
|
||||||
|
|
||||||
|
4
examples/stm32/f1/lisa-m-1/can/README
Normal file
4
examples/stm32/f1/lisa-m-1/can/README
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
||||||
|
100ms. The first byte is being incremented in each cycle. The demo also
|
||||||
|
receives messages and is displaing the first 4 bits of the first byte on the
|
||||||
|
board LEDs.
|
@ -21,8 +21,8 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/stm32/can.h>
|
#include <libopencm3/stm32/can.h>
|
||||||
|
|
||||||
struct can_tx_msg {
|
struct can_tx_msg {
|
||||||
@ -106,15 +106,15 @@ void can_setup(void)
|
|||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN);
|
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN);
|
||||||
|
|
||||||
AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB;
|
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||||
|
|
||||||
/* Configure CAN pin: RX (input pull-up). */
|
/* Configure CAN pin: RX (input pull-up). */
|
||||||
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT,
|
||||||
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
||||||
gpio_set(GPIOB, GPIO_CAN1_PB_RX);
|
gpio_set(GPIOB, GPIO_CAN1_PB_RX);
|
||||||
|
|
||||||
/* Configure CAN pin: TX. */
|
/* Configure CAN pin: TX. */
|
||||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
|
||||||
|
|
||||||
/* NVIC setup. */
|
/* NVIC setup. */
|
||||||
@ -167,8 +167,10 @@ void sys_tick_handler(void)
|
|||||||
static int temp32 = 0;
|
static int temp32 = 0;
|
||||||
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
/* We call this handler every 1ms so 1000ms = 1s on/off. */
|
/* We call this handler every 1ms so 100ms = 1s
|
||||||
if (++temp32 != 1000)
|
* Resulting in 100Hz message frequency.
|
||||||
|
*/
|
||||||
|
if (++temp32 != 100)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
temp32 = 0;
|
temp32 = 0;
|
||||||
|
@ -164,11 +164,12 @@ static const char *usb_strings[] = {
|
|||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
(void)buf;
|
(void)buf;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (req->bRequest) {
|
switch (req->bRequest) {
|
||||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||||
@ -200,15 +201,15 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_data_rx_cb(u8 ep)
|
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, u8 ep)
|
||||||
{
|
{
|
||||||
(void)ep;
|
(void)ep;
|
||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
while (usbd_ep_write_packet(0x82, buf, len) == 0)
|
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0)
|
||||||
;
|
;
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
}
|
}
|
||||||
@ -216,15 +217,16 @@ static void cdcacm_data_rx_cb(u8 ep)
|
|||||||
gpio_toggle(GPIOC, GPIO5);
|
gpio_toggle(GPIOC, GPIO5);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_set_config(u16 wValue)
|
static void cdcacm_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||||
{
|
{
|
||||||
(void)wValue;
|
(void)wValue;
|
||||||
|
|
||||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
cdcacm_control_request);
|
cdcacm_control_request);
|
||||||
@ -234,6 +236,8 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_clock_setup_in_hsi_out_48mhz();
|
rcc_clock_setup_in_hsi_out_48mhz();
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||||
@ -246,13 +250,13 @@ int main(void)
|
|||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||||
|
|
||||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_set_config_callback(cdcacm_set_config);
|
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
|
||||||
|
|
||||||
for (i = 0; i < 0x800000; i++)
|
for (i = 0; i < 0x800000; i++)
|
||||||
__asm__("nop");
|
__asm__("nop");
|
||||||
gpio_clear(GPIOC, GPIO2);
|
gpio_clear(GPIOC, GPIO2);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/dfu.h>
|
#include <libopencm3/usb/dfu.h>
|
||||||
|
|
||||||
@ -130,10 +130,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
(void)req;
|
(void)req;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (usbdfu_state) {
|
switch (usbdfu_state) {
|
||||||
case STATE_DFU_DNBUSY:
|
case STATE_DFU_DNBUSY:
|
||||||
@ -166,9 +167,11 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||||
return 0; /* Only accept class request. */
|
return 0; /* Only accept class request. */
|
||||||
|
|
||||||
@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
if (!gpio_get(GPIOA, GPIO10)) {
|
if (!gpio_get(GPIOA, GPIO10)) {
|
||||||
@ -245,9 +250,10 @@ int main(void)
|
|||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||||
|
|
||||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
usbdfu_control_request);
|
usbdfu_control_request);
|
||||||
@ -255,5 +261,5 @@ int main(void)
|
|||||||
gpio_clear(GPIOC, GPIO2);
|
gpio_clear(GPIOC, GPIO2);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/stm32/spi.h>
|
#include <libopencm3/stm32/spi.h>
|
||||||
#include <libopencm3/stm32/otg_fs.h>
|
#include <libopencm3/stm32/otg_fs.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
@ -32,10 +32,12 @@
|
|||||||
#define INCLUDE_DFU_INTERFACE
|
#define INCLUDE_DFU_INTERFACE
|
||||||
|
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
#include <libopencm3/stm32/f1/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
#include <libopencm3/usb/dfu.h>
|
#include <libopencm3/usb/dfu.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static usbd_device *usbd_dev;
|
||||||
|
|
||||||
const struct usb_device_descriptor dev = {
|
const struct usb_device_descriptor dev = {
|
||||||
.bLength = USB_DT_DEVICE_SIZE,
|
.bLength = USB_DT_DEVICE_SIZE,
|
||||||
.bDescriptorType = USB_DT_DEVICE,
|
.bDescriptorType = USB_DT_DEVICE,
|
||||||
@ -173,10 +175,11 @@ static const char *usb_strings[] = {
|
|||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int hid_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if((req->bmRequestType != 0x81) ||
|
if((req->bmRequestType != 0x81) ||
|
||||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||||
@ -191,9 +194,10 @@ static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
static void dfu_detach_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||||
{
|
{
|
||||||
(void)req;
|
(void)req;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
@ -202,11 +206,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
|||||||
scb_reset_core();
|
scb_reset_core();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)buf;
|
(void)buf;
|
||||||
(void)len;
|
(void)len;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||||
return 0; /* Only accept class request. */
|
return 0; /* Only accept class request. */
|
||||||
@ -217,18 +222,20 @@ static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void hid_set_config(u16 wValue)
|
static void hid_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||||
{
|
{
|
||||||
(void)wValue;
|
(void)wValue;
|
||||||
|
|
||||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
usbd_ep_setup(usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
hid_control_request);
|
hid_control_request);
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
dfu_control_request);
|
dfu_control_request);
|
||||||
@ -329,8 +336,8 @@ int main(void)
|
|||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||||
|
|
||||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_set_config_callback(hid_set_config);
|
usbd_register_set_config_callback(usbd_dev, hid_set_config);
|
||||||
|
|
||||||
/* Delay some seconds to show that pull-up switch works. */
|
/* Delay some seconds to show that pull-up switch works. */
|
||||||
for (i = 0; i < 0x800000; i++)
|
for (i = 0; i < 0x800000; i++)
|
||||||
@ -345,7 +352,7 @@ int main(void)
|
|||||||
// OTG_FS_GCCFG &= ~OTG_FS_GCCFG_VBUSBSEN;
|
// OTG_FS_GCCFG &= ~OTG_FS_GCCFG_VBUSBSEN;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sys_tick_handler(void)
|
void sys_tick_handler(void)
|
||||||
@ -357,5 +364,5 @@ void sys_tick_handler(void)
|
|||||||
buf[1] = x >> 9;
|
buf[1] = x >> 9;
|
||||||
buf[2] = y >> 9;
|
buf[2] = y >> 9;
|
||||||
|
|
||||||
usbd_ep_write_packet(0x81, buf, 4);
|
usbd_ep_write_packet(usbd_dev, 0x81, buf, 4);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = adc_injec
|
BINARY = adc_injec
|
||||||
|
|
||||||
# Comment the following line if you _don't_ have luftboot flashed!
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
CFLAGS += -std=c99
|
CFLAGS += -std=c99
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = adc_injec_timtrig
|
BINARY = adc_injec_timtrig
|
||||||
|
|
||||||
# Comment the following line if you _don't_ have luftboot flashed!
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
CFLAGS += -std=c99
|
CFLAGS += -std=c99
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = adc_injec_timtrig_irq
|
BINARY = adc_injec_timtrig_irq
|
||||||
|
|
||||||
# Comment the following line if you _don't_ have luftboot flashed!
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
CFLAGS += -std=c99
|
CFLAGS += -std=c99
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include <libopencm3/stm32/f1/adc.h>
|
#include <libopencm3/stm32/f1/adc.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/timer.h>
|
#include <libopencm3/stm32/timer.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
volatile u16 temperature = 0;
|
volatile u16 temperature = 0;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = adc_injec_timtrig_irq_4ch
|
BINARY = adc_injec_timtrig_irq_4ch
|
||||||
|
|
||||||
# Comment the following line if you _don't_ have luftboot flashed!
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
CFLAGS += -std=c99
|
CFLAGS += -std=c99
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include <libopencm3/stm32/f1/adc.h>
|
#include <libopencm3/stm32/f1/adc.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/timer.h>
|
#include <libopencm3/stm32/timer.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
volatile u16 temperature = 0;
|
volatile u16 temperature = 0;
|
||||||
volatile u16 v_refint = 0;
|
volatile u16 v_refint = 0;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = adc
|
BINARY = adc
|
||||||
|
|
||||||
# Comment the following line if you _don't_ have luftboot flashed!
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
CFLAGS += -std=c99
|
CFLAGS += -std=c99
|
||||||
|
28
examples/stm32/f1/lisa-m-2/can/Makefile
Normal file
28
examples/stm32/f1/lisa-m-2/can/Makefile
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = can
|
||||||
|
|
||||||
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
|
CFLAGS += -std=c99
|
||||||
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
4
examples/stm32/f1/lisa-m-2/can/README
Normal file
4
examples/stm32/f1/lisa-m-2/can/README
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
||||||
|
100ms. The first byte is being incremented in each cycle. The demo also
|
||||||
|
receives messages and is displaing the first 4 bits of the first byte on the
|
||||||
|
board LEDs.
|
234
examples/stm32/f1/lisa-m-2/can/can.c
Normal file
234
examples/stm32/f1/lisa-m-2/can/can.c
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||||
|
* Copyright (C) 2010-2011 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
*
|
||||||
|
* 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/f1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
#include <libopencm3/cm3/systick.h>
|
||||||
|
#include <libopencm3/stm32/can.h>
|
||||||
|
|
||||||
|
struct can_tx_msg {
|
||||||
|
u32 std_id;
|
||||||
|
u32 ext_id;
|
||||||
|
u8 ide;
|
||||||
|
u8 rtr;
|
||||||
|
u8 dlc;
|
||||||
|
u8 data[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct can_rx_msg {
|
||||||
|
u32 std_id;
|
||||||
|
u32 ext_id;
|
||||||
|
u8 ide;
|
||||||
|
u8 rtr;
|
||||||
|
u8 dlc;
|
||||||
|
u8 data[8];
|
||||||
|
u8 fmi;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct can_tx_msg can_tx_msg;
|
||||||
|
struct can_rx_msg can_rx_msg;
|
||||||
|
|
||||||
|
void gpio_setup(void)
|
||||||
|
{
|
||||||
|
/* Enable Alternate Function clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
|
|
||||||
|
/* Enable GPIOA clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
|
/* Enable GPIOB clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
|
||||||
|
/* Enable GPIOC clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||||
|
|
||||||
|
/* Preconfigure LEDs. */
|
||||||
|
gpio_set(GPIOA, GPIO8); /* LED1 off */
|
||||||
|
gpio_set(GPIOB, GPIO4); /* LED2 off */
|
||||||
|
gpio_set(GPIOC, GPIO2); /* LED3 off */
|
||||||
|
gpio_set(GPIOC, GPIO5); /* LED4 off */
|
||||||
|
gpio_set(GPIOC, GPIO15); /* LED5 off */
|
||||||
|
|
||||||
|
/* Configure LED GPIOOs. */
|
||||||
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
|
||||||
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||||
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||||
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||||
|
|
||||||
|
/* Configure PB4 as GPIO. */
|
||||||
|
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void systick_setup(void)
|
||||||
|
{
|
||||||
|
/* 72MHz / 8 => 9000000 counts per second */
|
||||||
|
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||||
|
|
||||||
|
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
|
||||||
|
systick_set_reload(9000);
|
||||||
|
|
||||||
|
systick_interrupt_enable();
|
||||||
|
|
||||||
|
/* Start counting. */
|
||||||
|
systick_counter_enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void can_setup(void)
|
||||||
|
{
|
||||||
|
/* Enable peripheral clocks. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CAN1EN);
|
||||||
|
|
||||||
|
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||||
|
|
||||||
|
/* Configure CAN pin: RX (input pull-up). */
|
||||||
|
gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT,
|
||||||
|
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
||||||
|
gpio_set(GPIO_BANK_CAN1_PB_RX, GPIO_CAN1_PB_RX);
|
||||||
|
|
||||||
|
/* Configure CAN pin: TX. */
|
||||||
|
gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
|
||||||
|
|
||||||
|
/* NVIC setup. */
|
||||||
|
nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ);
|
||||||
|
nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1);
|
||||||
|
|
||||||
|
/* Reset CAN. */
|
||||||
|
can_reset(CAN1);
|
||||||
|
|
||||||
|
/* CAN cell init. */
|
||||||
|
if (can_init(CAN1,
|
||||||
|
false, /* TTCM: Time triggered comm mode? */
|
||||||
|
true, /* ABOM: Automatic bus-off management? */
|
||||||
|
false, /* AWUM: Automatic wakeup mode? */
|
||||||
|
false, /* NART: No automatic retransmission? */
|
||||||
|
false, /* RFLM: Receive FIFO locked mode? */
|
||||||
|
false, /* TXFP: Transmit FIFO priority? */
|
||||||
|
CAN_BTR_SJW_1TQ,
|
||||||
|
CAN_BTR_TS1_3TQ,
|
||||||
|
CAN_BTR_TS2_4TQ,
|
||||||
|
12)) /* BRP+1: Baud rate prescaler */
|
||||||
|
{
|
||||||
|
gpio_set(GPIOA, GPIO8); /* LED1 off */
|
||||||
|
gpio_set(GPIOB, GPIO4); /* LED2 off */
|
||||||
|
gpio_set(GPIOC, GPIO2); /* LED3 off */
|
||||||
|
gpio_clear(GPIOC, GPIO5); /* LED4 on */
|
||||||
|
gpio_set(GPIOC, GPIO15); /* LED5 off */
|
||||||
|
|
||||||
|
/* Die because we failed to initialize. */
|
||||||
|
while (1)
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CAN filter 0 init. */
|
||||||
|
can_filter_id_mask_32bit_init(CAN1,
|
||||||
|
0, /* Filter ID */
|
||||||
|
0, /* CAN ID */
|
||||||
|
0, /* CAN ID mask */
|
||||||
|
0, /* FIFO assignment (here: FIFO0) */
|
||||||
|
true); /* Enable the filter. */
|
||||||
|
|
||||||
|
/* Enable CAN RX interrupt. */
|
||||||
|
can_enable_irq(CAN1, CAN_IER_FMPIE0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_tick_handler(void)
|
||||||
|
{
|
||||||
|
static int temp32 = 0;
|
||||||
|
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
|
/* We call this handler every 1ms so every 100ms = 0.1s
|
||||||
|
* resulting in 100Hz message rate.
|
||||||
|
*/
|
||||||
|
if (++temp32 != 100)
|
||||||
|
return;
|
||||||
|
|
||||||
|
temp32 = 0;
|
||||||
|
|
||||||
|
/* Transmit CAN frame. */
|
||||||
|
data[0]++;
|
||||||
|
if (can_transmit(CAN1,
|
||||||
|
0, /* (EX/ST)ID: CAN ID */
|
||||||
|
false, /* IDE: CAN ID extended? */
|
||||||
|
false, /* RTR: Request transmit? */
|
||||||
|
8, /* DLC: Data length */
|
||||||
|
data) == -1)
|
||||||
|
{
|
||||||
|
gpio_set(GPIOA, GPIO8); /* LED1 off */
|
||||||
|
gpio_set(GPIOB, GPIO4); /* LED2 off */
|
||||||
|
gpio_set(GPIOC, GPIO2); /* LED3 off */
|
||||||
|
gpio_set(GPIOC, GPIO5); /* LED4 off */
|
||||||
|
gpio_clear(GPIOC, GPIO15); /* LED5 on */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_lp_can_rx0_isr(void)
|
||||||
|
{
|
||||||
|
u32 id, fmi;
|
||||||
|
bool ext, rtr;
|
||||||
|
u8 length, data[8];
|
||||||
|
|
||||||
|
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data);
|
||||||
|
|
||||||
|
if (data[0] & 1)
|
||||||
|
gpio_clear(GPIOA, GPIO8);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOA, GPIO8);
|
||||||
|
|
||||||
|
if (data[0] & 2)
|
||||||
|
gpio_clear(GPIOB, GPIO4);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOB, GPIO4);
|
||||||
|
|
||||||
|
if (data[0] & 4)
|
||||||
|
gpio_clear(GPIOC, GPIO2);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOC, GPIO2);
|
||||||
|
|
||||||
|
if (data[0] & 8)
|
||||||
|
gpio_clear(GPIOC, GPIO5);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOC, GPIO5);
|
||||||
|
|
||||||
|
can_fifo_release(CAN1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||||
|
gpio_setup();
|
||||||
|
can_setup();
|
||||||
|
systick_setup();
|
||||||
|
|
||||||
|
while (1); /* Halt. */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
BINARY = fancyblink
|
BINARY = fancyblink
|
||||||
|
|
||||||
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
|
CFLAGS += -std=c99
|
||||||
LDSCRIPT = ../lisa-m.ld
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
BINARY = usart
|
BINARY = usart
|
||||||
|
|
||||||
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
|
CFLAGS += -std=c99
|
||||||
LDSCRIPT = ../lisa-m.ld
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
BINARY = usart_dma
|
BINARY = usart_dma
|
||||||
|
|
||||||
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
|
CFLAGS += -std=c99
|
||||||
LDSCRIPT = ../lisa-m.ld
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/f1/dma.h>
|
#include <libopencm3/stm32/f1/dma.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
BINARY = usart_irq
|
BINARY = usart_irq
|
||||||
|
|
||||||
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
|
CFLAGS += -std=c99
|
||||||
LDSCRIPT = ../lisa-m.ld
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
BINARY = usart_irq_printf
|
BINARY = usart_irq_printf
|
||||||
|
|
||||||
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
|
CFLAGS += -std=c99
|
||||||
LDSCRIPT = ../lisa-m.ld
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
BINARY = usart_printf
|
BINARY = usart_printf
|
||||||
|
|
||||||
|
# Comment the following line if you _don't_ have luftboot flashed!
|
||||||
|
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||||
|
CFLAGS += -std=c99
|
||||||
LDSCRIPT = ../lisa-m.ld
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
25
examples/stm32/f1/obldc-strip/can/Makefile
Normal file
25
examples/stm32/f1/obldc-strip/can/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = can
|
||||||
|
|
||||||
|
LDSCRIPT = ../obldc-strip.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
4
examples/stm32/f1/obldc-strip/can/README
Normal file
4
examples/stm32/f1/obldc-strip/can/README
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
||||||
|
100ms. The first byte is being incremented in each cycle. The demo also
|
||||||
|
receives messages and is displaing the first 4 bits of the first byte on the
|
||||||
|
board LEDs.
|
202
examples/stm32/f1/obldc-strip/can/can.c
Normal file
202
examples/stm32/f1/obldc-strip/can/can.c
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
*
|
||||||
|
* 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/f1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
#include <libopencm3/cm3/systick.h>
|
||||||
|
#include <libopencm3/stm32/can.h>
|
||||||
|
|
||||||
|
struct can_tx_msg {
|
||||||
|
u32 std_id;
|
||||||
|
u32 ext_id;
|
||||||
|
u8 ide;
|
||||||
|
u8 rtr;
|
||||||
|
u8 dlc;
|
||||||
|
u8 data[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct can_rx_msg {
|
||||||
|
u32 std_id;
|
||||||
|
u32 ext_id;
|
||||||
|
u8 ide;
|
||||||
|
u8 rtr;
|
||||||
|
u8 dlc;
|
||||||
|
u8 data[8];
|
||||||
|
u8 fmi;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct can_tx_msg can_tx_msg;
|
||||||
|
struct can_rx_msg can_rx_msg;
|
||||||
|
|
||||||
|
void gpio_setup(void)
|
||||||
|
{
|
||||||
|
/* Enable Alternate Function clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
|
|
||||||
|
/* Enable GPIOB clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
|
||||||
|
/* Preconfigure LEDs. */
|
||||||
|
gpio_set(GPIOB, GPIO4); /* LED green off */
|
||||||
|
gpio_set(GPIOB, GPIO5); /* LED red off */
|
||||||
|
|
||||||
|
/* Configure LED GPIOs. */
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||||
|
|
||||||
|
/* Configure PB4 as GPIO. */
|
||||||
|
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void systick_setup(void)
|
||||||
|
{
|
||||||
|
/* 64MHz / 8 => 8000000 counts per second */
|
||||||
|
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||||
|
|
||||||
|
/* 8000000/8000 = 1000 overflows per second - every 1ms one interrupt */
|
||||||
|
systick_set_reload(8000);
|
||||||
|
|
||||||
|
systick_interrupt_enable();
|
||||||
|
|
||||||
|
/* Start counting. */
|
||||||
|
systick_counter_enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void can_setup(void)
|
||||||
|
{
|
||||||
|
/* Enable peripheral clocks. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CAN1EN);
|
||||||
|
|
||||||
|
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||||
|
|
||||||
|
/* Configure CAN pin: RX (input pull-up). */
|
||||||
|
gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT,
|
||||||
|
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
||||||
|
gpio_set(GPIO_BANK_CAN1_PB_RX, GPIO_CAN1_PB_RX);
|
||||||
|
|
||||||
|
/* Configure CAN pin: TX. */
|
||||||
|
gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
|
||||||
|
|
||||||
|
/* NVIC setup. */
|
||||||
|
nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ);
|
||||||
|
nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1);
|
||||||
|
|
||||||
|
/* Reset CAN. */
|
||||||
|
can_reset(CAN1);
|
||||||
|
|
||||||
|
/* CAN cell init.
|
||||||
|
* Setting the bitrate to 1MBit. APB1 = 32MHz,
|
||||||
|
* prescaler = 2 -> 16MHz time quanta frequency.
|
||||||
|
* 1tq sync + 9tq bit segment1 (TS1) + 6tq bit segment2 (TS2) =
|
||||||
|
* 16time quanto per bit period, therefor 16MHz/16 = 1MHz
|
||||||
|
*/
|
||||||
|
if (can_init(CAN1,
|
||||||
|
false, /* TTCM: Time triggered comm mode? */
|
||||||
|
true, /* ABOM: Automatic bus-off management? */
|
||||||
|
false, /* AWUM: Automatic wakeup mode? */
|
||||||
|
false, /* NART: No automatic retransmission? */
|
||||||
|
false, /* RFLM: Receive FIFO locked mode? */
|
||||||
|
false, /* TXFP: Transmit FIFO priority? */
|
||||||
|
CAN_BTR_SJW_1TQ,
|
||||||
|
CAN_BTR_TS1_9TQ,
|
||||||
|
CAN_BTR_TS2_6TQ,
|
||||||
|
2)) /* BRP+1: Baud rate prescaler */
|
||||||
|
{
|
||||||
|
gpio_clear(GPIOB, GPIO4); /* LED green on */
|
||||||
|
gpio_set(GPIOB, GPIO5); /* LED red off */
|
||||||
|
|
||||||
|
/* Die because we failed to initialize. */
|
||||||
|
while (1)
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CAN filter 0 init. */
|
||||||
|
can_filter_id_mask_32bit_init(CAN1,
|
||||||
|
0, /* Filter ID */
|
||||||
|
0, /* CAN ID */
|
||||||
|
0, /* CAN ID mask */
|
||||||
|
0, /* FIFO assignment (here: FIFO0) */
|
||||||
|
true); /* Enable the filter. */
|
||||||
|
|
||||||
|
/* Enable CAN RX interrupt. */
|
||||||
|
can_enable_irq(CAN1, CAN_IER_FMPIE0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_tick_handler(void)
|
||||||
|
{
|
||||||
|
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
|
/* We call this handler every 1ms so every 1ms = 0.001s
|
||||||
|
* resulting in 1000Hz message rate.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Transmit CAN frame. */
|
||||||
|
data[0]++;
|
||||||
|
if (can_transmit(CAN1,
|
||||||
|
0, /* (EX/ST)ID: CAN ID */
|
||||||
|
false, /* IDE: CAN ID extended? */
|
||||||
|
false, /* RTR: Request transmit? */
|
||||||
|
8, /* DLC: Data length */
|
||||||
|
data) == -1)
|
||||||
|
{
|
||||||
|
gpio_set(GPIOB, GPIO4); /* LED green off */
|
||||||
|
gpio_clear(GPIOB, GPIO5); /* LED red on */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_lp_can_rx0_isr(void)
|
||||||
|
{
|
||||||
|
u32 id, fmi;
|
||||||
|
bool ext, rtr;
|
||||||
|
u8 length, data[8];
|
||||||
|
|
||||||
|
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data);
|
||||||
|
|
||||||
|
if (data[0] & 0x40)
|
||||||
|
gpio_clear(GPIOB, GPIO4);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOB, GPIO4);
|
||||||
|
|
||||||
|
if (data[0] & 0x80)
|
||||||
|
gpio_clear(GPIOB, GPIO5);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOB, GPIO5);
|
||||||
|
|
||||||
|
can_fifo_release(CAN1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
rcc_clock_setup_in_hsi_out_64mhz();
|
||||||
|
gpio_setup();
|
||||||
|
can_setup();
|
||||||
|
systick_setup();
|
||||||
|
|
||||||
|
while (1); /* Halt. */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
25
examples/stm32/f1/obldc-strip/led/Makefile
Normal file
25
examples/stm32/f1/obldc-strip/led/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = led
|
||||||
|
|
||||||
|
LDSCRIPT = ../obldc-strip.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
65
examples/stm32/f1/obldc-strip/led/led.c
Normal file
65
examples/stm32/f1/obldc-strip/led/led.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
*
|
||||||
|
* 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/f1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
|
|
||||||
|
void clock_setup(void)
|
||||||
|
{
|
||||||
|
/* Set STM32 to 64 MHz. */
|
||||||
|
rcc_clock_setup_in_hsi_out_64mhz();
|
||||||
|
|
||||||
|
/* Enable alternate function peripheral clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
|
|
||||||
|
/* Enable GPIOB clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gpio_setup(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Configure PB4 as GPIO. */
|
||||||
|
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||||
|
|
||||||
|
/* Set GPIO4 and 5 (in GPIO port B) to 'output push-pull'. */
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4 | GPIO5);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
clock_setup();
|
||||||
|
gpio_setup();
|
||||||
|
|
||||||
|
/* Blink the LEDs on the board. */
|
||||||
|
while (1) {
|
||||||
|
gpio_toggle(GPIOB, GPIO4); /* LED on/off */
|
||||||
|
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||||
|
__asm__("nop");
|
||||||
|
gpio_toggle(GPIOB, GPIO5); /* LED on/off */
|
||||||
|
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the libopencm3 project.
|
* This file is part of the libopencm3 project.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
|
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
*
|
*
|
||||||
* This library is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@ -17,19 +17,15 @@
|
|||||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libopencm3/stm32/f2/scb.h>
|
/* Linker script for Open-BLDC (STM32F103CBT6, 128K flash, 20K RAM). */
|
||||||
|
|
||||||
void scb_reset_core(void)
|
/* Define memory regions. */
|
||||||
|
MEMORY
|
||||||
{
|
{
|
||||||
SCB_AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_VECTRESET;
|
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||||
|
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||||
}
|
}
|
||||||
|
|
||||||
void scb_reset_system(void)
|
/* Include the common ld script. */
|
||||||
{
|
INCLUDE libopencm3_stm32f1.ld
|
||||||
SCB_AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_SYSRESETREQ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scb_set_priority_grouping(u32 prigroup)
|
|
||||||
{
|
|
||||||
SCB_AIRCR = SCB_AIRCR_VECTKEY | prigroup;
|
|
||||||
}
|
|
25
examples/stm32/f1/obldc-strip/systick/Makefile
Normal file
25
examples/stm32/f1/obldc-strip/systick/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = systick
|
||||||
|
|
||||||
|
LDSCRIPT = ../obldc-strip.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
81
examples/stm32/f1/obldc-strip/systick/systick.c
Normal file
81
examples/stm32/f1/obldc-strip/systick/systick.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
*
|
||||||
|
* 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/f1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
#include <libopencm3/cm3/systick.h>
|
||||||
|
|
||||||
|
u32 temp32;
|
||||||
|
|
||||||
|
void gpio_setup(void)
|
||||||
|
{
|
||||||
|
/* Enable alternate function peripheral clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
|
|
||||||
|
/* Enable GPIOB clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
|
||||||
|
gpio_clear(GPIOB, GPIO4); /* LED green on */
|
||||||
|
gpio_set(GPIOB, GPIO5); /* LED red off */
|
||||||
|
|
||||||
|
/* Set GPIO4/5 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||||
|
|
||||||
|
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_tick_handler(void)
|
||||||
|
{
|
||||||
|
temp32++;
|
||||||
|
|
||||||
|
/* We call this handler every 1ms so 1000ms = 1s on/off. */
|
||||||
|
if (temp32 == 1000) {
|
||||||
|
gpio_toggle(GPIOB, GPIO4); /* LED green on/off */
|
||||||
|
gpio_toggle(GPIOB, GPIO5); /* LED red on/off */
|
||||||
|
temp32 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
rcc_clock_setup_in_hsi_out_64mhz();
|
||||||
|
gpio_setup();
|
||||||
|
|
||||||
|
temp32 = 0;
|
||||||
|
|
||||||
|
/* 64MHz / 8 => 8000000 counts per second */
|
||||||
|
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||||
|
|
||||||
|
/* 8000000/8000 = 1000 overflows per second - every 1ms one interrupt */
|
||||||
|
systick_set_reload(8000);
|
||||||
|
|
||||||
|
systick_interrupt_enable();
|
||||||
|
|
||||||
|
/* Start counting. */
|
||||||
|
systick_counter_enable();
|
||||||
|
|
||||||
|
while (1); /* Halt. */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -21,8 +21,8 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/stm32/can.h>
|
#include <libopencm3/stm32/can.h>
|
||||||
|
|
||||||
struct can_tx_msg {
|
struct can_tx_msg {
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
|
|
||||||
u32 temp32;
|
u32 temp32;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/timer.h>
|
#include <libopencm3/stm32/timer.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/spi.h>
|
#include <libopencm3/stm32/spi.h>
|
||||||
#include "./dogm128.h"
|
#include "./dogm128.h"
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rtc.h>
|
#include <libopencm3/stm32/f1/rtc.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/pwr.h>
|
#include <libopencm3/stm32/pwr.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
|
|
||||||
u32 temp32;
|
u32 temp32;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/timer.h>
|
#include <libopencm3/stm32/timer.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
void gpio_setup(void)
|
void gpio_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -164,11 +164,12 @@ static const char *usb_strings[] = {
|
|||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
(void)buf;
|
(void)buf;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch(req->bRequest) {
|
switch(req->bRequest) {
|
||||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||||
@ -200,28 +201,29 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_data_rx_cb(u8 ep)
|
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, u8 ep)
|
||||||
{
|
{
|
||||||
(void)ep;
|
(void)ep;
|
||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
usbd_ep_write_packet(0x82, buf, len);
|
usbd_ep_write_packet(usbd_dev, 0x82, buf, len);
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_set_config(u16 wValue)
|
static void cdcacm_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||||
{
|
{
|
||||||
(void)wValue;
|
(void)wValue;
|
||||||
|
|
||||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
cdcacm_control_request);
|
cdcacm_control_request);
|
||||||
@ -229,6 +231,8 @@ static void cdcacm_set_config(u16 wValue)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_clock_setup_in_hsi_out_48mhz();
|
rcc_clock_setup_in_hsi_out_48mhz();
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
@ -238,13 +242,13 @@ int main(void)
|
|||||||
|
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||||
|
|
||||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_set_config_callback(cdcacm_set_config);
|
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
|
||||||
|
|
||||||
gpio_set(GPIOA, GPIO15);
|
gpio_set(GPIOA, GPIO15);
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/dfu.h>
|
#include <libopencm3/usb/dfu.h>
|
||||||
|
|
||||||
@ -130,10 +130,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
(void)req;
|
(void)req;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (usbdfu_state) {
|
switch (usbdfu_state) {
|
||||||
case STATE_DFU_DNBUSY:
|
case STATE_DFU_DNBUSY:
|
||||||
@ -166,9 +167,11 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||||
return 0; /* Only accept class request. */
|
return 0; /* Only accept class request. */
|
||||||
|
|
||||||
@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
if (!gpio_get(GPIOA, GPIO10)) {
|
if (!gpio_get(GPIOA, GPIO10)) {
|
||||||
@ -246,9 +251,10 @@ int main(void)
|
|||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);
|
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);
|
||||||
|
|
||||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
usbdfu_control_request);
|
usbdfu_control_request);
|
||||||
@ -258,5 +264,5 @@ int main(void)
|
|||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/hid.h>
|
#include <libopencm3/usb/hid.h>
|
||||||
|
|
||||||
@ -28,10 +28,12 @@
|
|||||||
#define INCLUDE_DFU_INTERFACE
|
#define INCLUDE_DFU_INTERFACE
|
||||||
|
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
#include <libopencm3/stm32/f1/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
#include <libopencm3/usb/dfu.h>
|
#include <libopencm3/usb/dfu.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static usbd_device *usbd_dev;
|
||||||
|
|
||||||
const struct usb_device_descriptor dev = {
|
const struct usb_device_descriptor dev = {
|
||||||
.bLength = USB_DT_DEVICE_SIZE,
|
.bLength = USB_DT_DEVICE_SIZE,
|
||||||
.bDescriptorType = USB_DT_DEVICE,
|
.bDescriptorType = USB_DT_DEVICE,
|
||||||
@ -169,10 +171,11 @@ static const char *usb_strings[] = {
|
|||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int hid_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if((req->bmRequestType != 0x81) ||
|
if((req->bmRequestType != 0x81) ||
|
||||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||||
@ -187,9 +190,10 @@ static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
static void dfu_detach_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||||
{
|
{
|
||||||
(void)req;
|
(void)req;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
@ -198,11 +202,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
|||||||
scb_reset_core();
|
scb_reset_core();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)buf;
|
(void)buf;
|
||||||
(void)len;
|
(void)len;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||||
return 0; /* Only accept class request. */
|
return 0; /* Only accept class request. */
|
||||||
@ -213,18 +218,21 @@ static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void hid_set_config(u16 wValue)
|
static void hid_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||||
{
|
{
|
||||||
(void)wValue;
|
(void)wValue;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
usbd_ep_setup(usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
hid_control_request);
|
hid_control_request);
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
dfu_control_request);
|
dfu_control_request);
|
||||||
@ -246,15 +254,15 @@ int main(void)
|
|||||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||||
|
|
||||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_set_config_callback(hid_set_config);
|
usbd_register_set_config_callback(usbd_dev, hid_set_config);
|
||||||
|
|
||||||
gpio_set(GPIOA, GPIO15);
|
gpio_set(GPIOA, GPIO15);
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sys_tick_handler(void)
|
void sys_tick_handler(void)
|
||||||
@ -270,5 +278,5 @@ void sys_tick_handler(void)
|
|||||||
if (x < -30)
|
if (x < -30)
|
||||||
dir = -dir;
|
dir = -dir;
|
||||||
|
|
||||||
usbd_ep_write_packet(0x81, buf, 4);
|
usbd_ep_write_packet(usbd_dev, 0x81, buf, 4);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/exti.h>
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
|
||||||
u16 exti_line_state;
|
u16 exti_line_state;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/exti.h>
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
|
||||||
u16 exti_line_state;
|
u16 exti_line_state;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/exti.h>
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
|
||||||
#define FALLING 0
|
#define FALLING 0
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/timer.h>
|
#include <libopencm3/stm32/timer.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/exti.h>
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
|
||||||
#define FALLING 0
|
#define FALLING 0
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/timer.h>
|
#include <libopencm3/stm32/timer.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/exti.h>
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
|
||||||
u16 frequency_sequence[18] = {
|
u16 frequency_sequence[18] = {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -164,11 +164,12 @@ static const char *usb_strings[] = {
|
|||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
(void)buf;
|
(void)buf;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (req->bRequest) {
|
switch (req->bRequest) {
|
||||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||||
@ -199,28 +200,31 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_data_rx_cb(u8 ep)
|
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, u8 ep)
|
||||||
{
|
{
|
||||||
(void)ep;
|
(void)ep;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
usbd_ep_write_packet(0x82, buf, len);
|
usbd_ep_write_packet(usbd_dev, 0x82, buf, len);
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_set_config(u16 wValue)
|
static void cdcacm_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||||
{
|
{
|
||||||
(void)wValue;
|
(void)wValue;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
cdcacm_control_request);
|
cdcacm_control_request);
|
||||||
@ -230,6 +234,8 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_clock_setup_in_hsi_out_48mhz();
|
rcc_clock_setup_in_hsi_out_48mhz();
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||||
@ -238,13 +244,13 @@ int main(void)
|
|||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
||||||
|
|
||||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_set_config_callback(cdcacm_set_config);
|
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
|
||||||
|
|
||||||
for (i = 0; i < 0x800000; i++)
|
for (i = 0; i < 0x800000; i++)
|
||||||
__asm__("nop");
|
__asm__("nop");
|
||||||
gpio_clear(GPIOC, GPIO11);
|
gpio_clear(GPIOC, GPIO11);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/dfu.h>
|
#include <libopencm3/usb/dfu.h>
|
||||||
|
|
||||||
@ -114,8 +114,10 @@ static const char *usb_strings[] = {
|
|||||||
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
|
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
|
||||||
};
|
};
|
||||||
|
|
||||||
static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
static u8 usbdfu_getstatus(usbd_device *usbd_dev, u32 *bwPollTimeout)
|
||||||
{
|
{
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (usbdfu_state) {
|
switch (usbdfu_state) {
|
||||||
case STATE_DFU_DNLOAD_SYNC:
|
case STATE_DFU_DNLOAD_SYNC:
|
||||||
usbdfu_state = STATE_DFU_DNBUSY;
|
usbdfu_state = STATE_DFU_DNBUSY;
|
||||||
@ -130,10 +132,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
(void)req;
|
(void)req;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (usbdfu_state) {
|
switch (usbdfu_state) {
|
||||||
case STATE_DFU_DNBUSY:
|
case STATE_DFU_DNBUSY:
|
||||||
@ -166,8 +169,8 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||||
return 0; /* Only accept class request. */
|
return 0; /* Only accept class request. */
|
||||||
@ -199,7 +202,7 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
return 0;
|
return 0;
|
||||||
case DFU_GETSTATUS: {
|
case DFU_GETSTATUS: {
|
||||||
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
||||||
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
|
(*buf)[0] = usbdfu_getstatus(usbd_dev, &bwPollTimeout);
|
||||||
(*buf)[1] = bwPollTimeout & 0xFF;
|
(*buf)[1] = bwPollTimeout & 0xFF;
|
||||||
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
||||||
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
||||||
@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
if (!gpio_get(GPIOA, GPIO10)) {
|
if (!gpio_get(GPIOA, GPIO10)) {
|
||||||
@ -244,9 +249,10 @@ int main(void)
|
|||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
||||||
gpio_set(GPIOC, GPIO11);
|
gpio_set(GPIOC, GPIO11);
|
||||||
|
|
||||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
usbdfu_control_request);
|
usbdfu_control_request);
|
||||||
@ -254,5 +260,5 @@ int main(void)
|
|||||||
gpio_clear(GPIOC, GPIO11);
|
gpio_clear(GPIOC, GPIO11);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/hid.h>
|
#include <libopencm3/usb/hid.h>
|
||||||
|
|
||||||
@ -28,7 +28,7 @@
|
|||||||
#define INCLUDE_DFU_INTERFACE
|
#define INCLUDE_DFU_INTERFACE
|
||||||
|
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
#include <libopencm3/stm32/f1/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
#include <libopencm3/usb/dfu.h>
|
#include <libopencm3/usb/dfu.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -169,10 +169,11 @@ static const char *usb_strings[] = {
|
|||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int hid_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if ((req->bmRequestType != 0x81) ||
|
if ((req->bmRequestType != 0x81) ||
|
||||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||||
@ -187,9 +188,10 @@ static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
static void dfu_detach_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||||
{
|
{
|
||||||
(void)req;
|
(void)req;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
@ -198,11 +200,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
|||||||
scb_reset_core();
|
scb_reset_core();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)buf;
|
(void)buf;
|
||||||
(void)len;
|
(void)len;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||||
return 0; /* Only accept class request. */
|
return 0; /* Only accept class request. */
|
||||||
@ -213,18 +216,21 @@ static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void hid_set_config(u16 wValue)
|
static void hid_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||||
{
|
{
|
||||||
(void)wValue;
|
(void)wValue;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
usbd_ep_setup(usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
hid_control_request);
|
hid_control_request);
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
dfu_control_request);
|
dfu_control_request);
|
||||||
@ -240,6 +246,8 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_clock_setup_in_hsi_out_48mhz();
|
rcc_clock_setup_in_hsi_out_48mhz();
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||||
@ -248,8 +256,8 @@ int main(void)
|
|||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
||||||
|
|
||||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_set_config_callback(hid_set_config);
|
usbd_register_set_config_callback(usbd_dev, hid_set_config);
|
||||||
|
|
||||||
for (i = 0; i < 0x80000; i++)
|
for (i = 0; i < 0x80000; i++)
|
||||||
__asm__("nop");
|
__asm__("nop");
|
||||||
@ -257,9 +265,10 @@ int main(void)
|
|||||||
gpio_clear(GPIOC, GPIO11);
|
gpio_clear(GPIOC, GPIO11);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0 /* is this used? */
|
||||||
void sys_tick_handler(void)
|
void sys_tick_handler(void)
|
||||||
{
|
{
|
||||||
static int x = 0;
|
static int x = 0;
|
||||||
@ -273,5 +282,6 @@ void sys_tick_handler(void)
|
|||||||
if (x < -30)
|
if (x < -30)
|
||||||
dir = -dir;
|
dir = -dir;
|
||||||
|
|
||||||
usbd_ep_write_packet(0x81, buf, 4);
|
usbd_ep_write_packet(usbd_dev, 0x81, buf, 4);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
#include <libopencm3/stm32/f1/flash.h>
|
#include <libopencm3/stm32/f1/flash.h>
|
||||||
#include <libopencm3/stm32/f1/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/dfu.h>
|
#include <libopencm3/usb/dfu.h>
|
||||||
|
|
||||||
@ -114,8 +114,10 @@ static const char *usb_strings[] = {
|
|||||||
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
|
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
|
||||||
};
|
};
|
||||||
|
|
||||||
static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
static u8 usbdfu_getstatus(usbd_device *usbd_dev, u32 *bwPollTimeout)
|
||||||
{
|
{
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (usbdfu_state) {
|
switch (usbdfu_state) {
|
||||||
case STATE_DFU_DNLOAD_SYNC:
|
case STATE_DFU_DNLOAD_SYNC:
|
||||||
usbdfu_state = STATE_DFU_DNBUSY;
|
usbdfu_state = STATE_DFU_DNBUSY;
|
||||||
@ -130,10 +132,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
(void)req;
|
(void)req;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (usbdfu_state) {
|
switch (usbdfu_state) {
|
||||||
case STATE_DFU_DNBUSY:
|
case STATE_DFU_DNBUSY:
|
||||||
@ -166,8 +169,8 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||||
return 0; /* Only accept class request. */
|
return 0; /* Only accept class request. */
|
||||||
@ -199,7 +202,7 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
return 0;
|
return 0;
|
||||||
case DFU_GETSTATUS: {
|
case DFU_GETSTATUS: {
|
||||||
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
||||||
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
|
(*buf)[0] = usbdfu_getstatus(usbd_dev, &bwPollTimeout);
|
||||||
(*buf)[1] = bwPollTimeout & 0xFF;
|
(*buf)[1] = bwPollTimeout & 0xFF;
|
||||||
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
||||||
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
||||||
@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
if (!gpio_get(GPIOA, GPIO10)) {
|
if (!gpio_get(GPIOA, GPIO10)) {
|
||||||
@ -244,9 +249,10 @@ int main(void)
|
|||||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||||
|
|
||||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
usbdfu_control_request);
|
usbdfu_control_request);
|
||||||
@ -256,5 +262,5 @@ int main(void)
|
|||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
@ -75,12 +75,13 @@ const char *usb_strings[] = {
|
|||||||
"1001",
|
"1001",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
|
static int simple_control_callback(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)buf;
|
(void)buf;
|
||||||
(void)len;
|
(void)len;
|
||||||
(void)complete;
|
(void)complete;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
if (req->bmRequestType != 0x40)
|
if (req->bmRequestType != 0x40)
|
||||||
return 0; /* Only accept vendor request. */
|
return 0; /* Only accept vendor request. */
|
||||||
@ -95,6 +96,8 @@ static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
@ -105,13 +108,14 @@ int main(void)
|
|||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||||
|
|
||||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_VENDOR,
|
USB_REQ_TYPE_VENDOR,
|
||||||
USB_REQ_TYPE_TYPE,
|
USB_REQ_TYPE_TYPE,
|
||||||
simple_control_callback);
|
simple_control_callback);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include <libopencm3/stm32/f1/rtc.h>
|
#include <libopencm3/stm32/f1/rtc.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/pwr.h>
|
#include <libopencm3/stm32/pwr.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libopencm3/stm32/spi.h>
|
#include <libopencm3/stm32/spi.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/f2/gpio.h>
|
#include <libopencm3/stm32/f2/gpio.h>
|
||||||
#include <libopencm3/stm32/f2/rcc.h>
|
#include <libopencm3/stm32/f2/rcc.h>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libopencm3/stm32/f2/gpio.h>
|
#include <libopencm3/stm32/f2/gpio.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/cm3/nvic.h>
|
||||||
#include <libopencm3/stm32/f2/rcc.h>
|
#include <libopencm3/stm32/f2/rcc.h>
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <libopencm3/stm32/f4/gpio.h>
|
#include <libopencm3/stm32/f4/gpio.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/cdc.h>
|
#include <libopencm3/usb/cdc.h>
|
||||||
|
#include <libopencm3/cm3/scb.h>
|
||||||
|
|
||||||
static const struct usb_device_descriptor dev = {
|
static const struct usb_device_descriptor dev = {
|
||||||
.bLength = USB_DT_DEVICE_SIZE,
|
.bLength = USB_DT_DEVICE_SIZE,
|
||||||
@ -164,11 +165,12 @@ static const char *usb_strings[] = {
|
|||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
(void)buf;
|
(void)buf;
|
||||||
|
(void)usbd_dev;
|
||||||
|
|
||||||
switch (req->bRequest) {
|
switch (req->bRequest) {
|
||||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||||
@ -188,30 +190,31 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_data_rx_cb(u8 ep)
|
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, u8 ep)
|
||||||
{
|
{
|
||||||
(void)ep;
|
(void)ep;
|
||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
while (usbd_ep_write_packet(0x82, buf, len) == 0)
|
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_toggle(GPIOC, GPIO5);
|
gpio_toggle(GPIOC, GPIO5);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdcacm_set_config(u16 wValue)
|
static void cdcacm_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||||
{
|
{
|
||||||
(void)wValue;
|
(void)wValue;
|
||||||
|
|
||||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
|
usbd_dev,
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
cdcacm_control_request);
|
cdcacm_control_request);
|
||||||
@ -219,6 +222,8 @@ static void cdcacm_set_config(u16 wValue)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
usbd_device *usbd_dev;
|
||||||
|
|
||||||
rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_120MHZ]);
|
rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_120MHZ]);
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
|
||||||
@ -228,10 +233,9 @@ int main(void)
|
|||||||
GPIO9 | GPIO11 | GPIO12);
|
GPIO9 | GPIO11 | GPIO12);
|
||||||
gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);
|
gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);
|
||||||
|
|
||||||
usbd_init(&otgfs_usb_driver, &dev, &config, usb_strings);
|
usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config, usb_strings);
|
||||||
usbd_register_set_config_callback(cdcacm_set_config);
|
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
164
examples/stm32/l1/Makefile.include
Normal file
164
examples/stm32/l1/Makefile.include
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
## Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
PREFIX ?= arm-none-eabi
|
||||||
|
#PREFIX ?= arm-elf
|
||||||
|
CC = $(PREFIX)-gcc
|
||||||
|
LD = $(PREFIX)-gcc
|
||||||
|
OBJCOPY = $(PREFIX)-objcopy
|
||||||
|
OBJDUMP = $(PREFIX)-objdump
|
||||||
|
GDB = $(PREFIX)-gdb
|
||||||
|
|
||||||
|
TOOLCHAIN_DIR ?= ../../../../..
|
||||||
|
ifeq ($(wildcard ../../../../../lib/libopencm3_stm32l1.a),)
|
||||||
|
ifneq ($(strip $(shell which $(CC))),)
|
||||||
|
TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
ifeq ($(V),1)
|
||||||
|
$(info We seem to be building the example in the source directory. Using local library!)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float
|
||||||
|
CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include \
|
||||||
|
-fno-common $(ARCH_FLAGS) -MD -DSTM32L1
|
||||||
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
|
LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
|
||||||
|
-L$(TOOLCHAIN_DIR)/lib \
|
||||||
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \
|
||||||
|
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd
|
||||||
|
|
||||||
|
CFLAGS += -I$(TOOLCHAIN_DIR)/include
|
||||||
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib -L$(TOOLCHAIN_DIR)/lib/stm32/l1
|
||||||
|
SCRIPT_DIR = $(TOOLCHAIN_DIR)/share
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32l1.a
|
||||||
|
@#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)
|
||||||
|
|
@ -0,0 +1,24 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = main
|
||||||
|
LDSCRIPT = ../../../../../lib/stm32/l1/stm32l15xxb.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
@ -0,0 +1,3 @@
|
|||||||
|
* Prints to the screen when the button is pushed/released (irq driven)
|
||||||
|
115200@8n1 console on PA2 (tx only)
|
||||||
|
|
117
examples/stm32/l1/stm32l-discovery/button-irq-printf/main.c
Normal file
117
examples/stm32/l1/stm32l-discovery/button-irq-printf/main.c
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Karl Palsson, 2012 <karlp@tweak.net.au
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
#include <libopencm3/stm32/l1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/l1/gpio.h>
|
||||||
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
#include <libopencm3/stm32/usart.h>
|
||||||
|
|
||||||
|
#include "syscfg.h"
|
||||||
|
|
||||||
|
static struct state_t state;
|
||||||
|
|
||||||
|
void clock_setup(void) {
|
||||||
|
/* Lots of things on all ports... */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_GPIOAEN);
|
||||||
|
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_GPIOBEN);
|
||||||
|
|
||||||
|
/* Enable clocks for USART2. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gpio_setup(void) {
|
||||||
|
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN);
|
||||||
|
|
||||||
|
/* Setup GPIO pins for USART2 transmit. */
|
||||||
|
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
|
||||||
|
|
||||||
|
/* Setup USART2 TX pin as alternate function. */
|
||||||
|
gpio_set_af(GPIOA, GPIO_AF7, GPIO2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usart_setup(void) {
|
||||||
|
usart_set_baudrate(USART_CONSOLE, 115200);
|
||||||
|
usart_set_databits(USART_CONSOLE, 8);
|
||||||
|
usart_set_stopbits(USART_CONSOLE, USART_STOPBITS_1);
|
||||||
|
usart_set_mode(USART_CONSOLE, USART_MODE_TX);
|
||||||
|
usart_set_parity(USART_CONSOLE, USART_PARITY_NONE);
|
||||||
|
usart_set_flow_control(USART_CONSOLE, USART_FLOWCONTROL_NONE);
|
||||||
|
|
||||||
|
/* Finally enable the USART. */
|
||||||
|
usart_enable(USART_CONSOLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use USART_CONSOLE as a console.
|
||||||
|
* @param file
|
||||||
|
* @param ptr
|
||||||
|
* @param len
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int _write(int file, char *ptr, int len) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (file == STDOUT_FILENO || file == STDERR_FILENO) {
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (ptr[i] == '\n') {
|
||||||
|
usart_send_blocking(USART_CONSOLE, '\r');
|
||||||
|
}
|
||||||
|
usart_send_blocking(USART_CONSOLE, ptr[i]);
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
errno = EIO;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BUTTON_DISCO_USER_isr(void) {
|
||||||
|
exti_reset_request(BUTTON_DISCO_USER_EXTI);
|
||||||
|
if (state.falling) {
|
||||||
|
state.falling = false;
|
||||||
|
exti_set_trigger(BUTTON_DISCO_USER_EXTI, EXTI_TRIGGER_RISING);
|
||||||
|
// ILOG("fell: %d\n", TIM_CNT(TIM7));
|
||||||
|
puts("fell!\n");
|
||||||
|
} else {
|
||||||
|
puts("Rose!\n");
|
||||||
|
// TIM_CNT(TIM7) = 0;
|
||||||
|
state.falling = true;
|
||||||
|
exti_set_trigger(BUTTON_DISCO_USER_EXTI, EXTI_TRIGGER_FALLING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_buttons(void) {
|
||||||
|
/* Enable EXTI0 interrupt. */
|
||||||
|
nvic_enable_irq(BUTTON_DISCO_USER_NVIC);
|
||||||
|
|
||||||
|
gpio_mode_setup(BUTTON_DISCO_USER_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, BUTTON_DISCO_USER_PIN);
|
||||||
|
|
||||||
|
/* Configure the EXTI subsystem. */
|
||||||
|
exti_select_source(BUTTON_DISCO_USER_EXTI, BUTTON_DISCO_USER_PORT);
|
||||||
|
state.falling = false;
|
||||||
|
exti_set_trigger(BUTTON_DISCO_USER_EXTI, EXTI_TRIGGER_RISING);
|
||||||
|
exti_enable_request(BUTTON_DISCO_USER_EXTI);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int i;
|
||||||
|
int j = 0;
|
||||||
|
clock_setup();
|
||||||
|
gpio_setup();
|
||||||
|
usart_setup();
|
||||||
|
puts("hi guys!\n");
|
||||||
|
setup_buttons();
|
||||||
|
while (1) {
|
||||||
|
puts("tick:");
|
||||||
|
putchar('a' + (j++ % 26));
|
||||||
|
gpio_toggle(GPIOB, GPIO7); /* LED on/off */
|
||||||
|
for (i = 0; i < 100000; i++) /* Wait a bit. */
|
||||||
|
__asm__("NOP");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* General configuration of the device
|
||||||
|
*
|
||||||
|
* Karl Palsson <karlp@tweak.net.au> 2012
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SYSCFG_H
|
||||||
|
#define SYSCFG_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <libopencm3/stm32/l1/gpio.h>
|
||||||
|
#include <libopencm3/stm32/l1/nvic.h>
|
||||||
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
#include <libopencm3/stm32/usart.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define USART_CONSOLE USART2
|
||||||
|
#define USE_NASTYLOG 1
|
||||||
|
|
||||||
|
#define LED_DISCO_GREEN_PORT GPIOB
|
||||||
|
#define LED_DISCO_GREEN_PIN GPIO7
|
||||||
|
#define LED_DISCO_BLUE_PORT GPIOB
|
||||||
|
#define LED_DISCO_BLUE_PIN GPIO6
|
||||||
|
|
||||||
|
#define BUTTON_DISCO_USER_PORT GPIOA
|
||||||
|
#define BUTTON_DISCO_USER_PIN GPIO0
|
||||||
|
#define BUTTON_DISCO_USER_EXTI EXTI0
|
||||||
|
#define BUTTON_DISCO_USER_isr exti0_isr
|
||||||
|
#define BUTTON_DISCO_USER_NVIC NVIC_EXTI0_IRQ
|
||||||
|
|
||||||
|
|
||||||
|
struct state_t {
|
||||||
|
bool falling;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* SYSCFG_H */
|
||||||
|
|
25
examples/stm32/l1/stm32l-discovery/miniblink/Makefile
Normal file
25
examples/stm32/l1/stm32l-discovery/miniblink/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = miniblink
|
||||||
|
|
||||||
|
LDSCRIPT = ../../../../../lib/stm32/l1/stm32l15xxb.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
9
examples/stm32/l1/stm32l-discovery/miniblink/README
Normal file
9
examples/stm32/l1/stm32l-discovery/miniblink/README
Normal file
@ -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.
|
||||||
|
|
72
examples/stm32/l1/stm32l-discovery/miniblink/miniblink.c
Normal file
72
examples/stm32/l1/stm32l-discovery/miniblink/miniblink.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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>
|
||||||
|
* Copyright (C) 2012 Karl Palsson <karlp@tweak.net.au>
|
||||||
|
*
|
||||||
|
* 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/l1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/l1/gpio.h>
|
||||||
|
|
||||||
|
#define PORT_LED GPIOB
|
||||||
|
#define PIN_LED GPIO6
|
||||||
|
|
||||||
|
void gpio_setup(void)
|
||||||
|
{
|
||||||
|
/* Enable GPIOB clock. */
|
||||||
|
/* Manually: */
|
||||||
|
//RCC_AHBENR |= RCC_AHBENR_GPIOBEN;
|
||||||
|
/* Using API functions: */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_GPIOBEN);
|
||||||
|
|
||||||
|
/* 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, PIN_LED); /* LED on/off */
|
||||||
|
for (i = 0; i < 1000000; i++) /* Wait a bit. */
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
25
examples/stm32/l1/stm32l-discovery/usart/Makefile
Normal file
25
examples/stm32/l1/stm32l-discovery/usart/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = usart
|
||||||
|
|
||||||
|
LDSCRIPT = ../../../../../lib/stm32/l1/stm32l15xxb.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
12
examples/stm32/l1/stm32l-discovery/usart/README
Normal file
12
examples/stm32/l1/stm32l-discovery/usart/README
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This example program sends some characters on USART2 on the
|
||||||
|
ST STM32L DISCOVERY eval board. (USART2 TX on PA2)
|
||||||
|
|
||||||
|
The terminal settings for the receiving device/PC are 38400 8n1.
|
||||||
|
|
||||||
|
The sending is done in a blocking way in the code, see the usart_irq example
|
||||||
|
for a more elaborate USART example.
|
||||||
|
|
80
examples/stm32/l1/stm32l-discovery/usart/usart.c
Normal file
80
examples/stm32/l1/stm32l-discovery/usart/usart.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
* Copyright (C) 2012 Karl Palsson <karlp@tweak.net.au>
|
||||||
|
*
|
||||||
|
* 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/l1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/l1/gpio.h>
|
||||||
|
#include <libopencm3/stm32/usart.h>
|
||||||
|
|
||||||
|
void clock_setup(void) {
|
||||||
|
/* We are running on MSI after boot. */
|
||||||
|
/* Enable GPIOD clock for LED & USARTs. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_GPIOAEN);
|
||||||
|
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_GPIOBEN);
|
||||||
|
|
||||||
|
/* Enable clocks for USART2. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usart_setup(void) {
|
||||||
|
/* Setup USART2 parameters. */
|
||||||
|
usart_set_baudrate(USART2, 38400);
|
||||||
|
usart_set_databits(USART2, 8);
|
||||||
|
usart_set_stopbits(USART2, USART_STOPBITS_1);
|
||||||
|
usart_set_mode(USART2, USART_MODE_TX);
|
||||||
|
usart_set_parity(USART2, USART_PARITY_NONE);
|
||||||
|
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
|
||||||
|
|
||||||
|
/* Finally enable the USART. */
|
||||||
|
usart_enable(USART2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gpio_setup(void) {
|
||||||
|
/* Setup GPIO pin GPIO7 on GPIO port B for Green LED. */
|
||||||
|
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO7);
|
||||||
|
|
||||||
|
/* Setup GPIO pins for USART2 transmit. */
|
||||||
|
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
|
||||||
|
|
||||||
|
/* Setup USART2 TX pin as alternate function. */
|
||||||
|
gpio_set_af(GPIOA, GPIO_AF7, GPIO2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int i, j = 0, c = 0;
|
||||||
|
|
||||||
|
clock_setup();
|
||||||
|
gpio_setup();
|
||||||
|
usart_setup();
|
||||||
|
|
||||||
|
/* Blink the LED (PD12) on the board with every transmitted byte. */
|
||||||
|
while (1) {
|
||||||
|
gpio_toggle(GPIOB, GPIO7); /* LED on/off */
|
||||||
|
usart_send_blocking(USART2, c + '0'); /* USART2: Send byte. */
|
||||||
|
c = (c == 9) ? 0 : c + 1; /* Increment c. */
|
||||||
|
if ((j++ % 80) == 0) { /* Newline after line full. */
|
||||||
|
usart_send_blocking(USART2, '\r');
|
||||||
|
usart_send_blocking(USART2, '\n');
|
||||||
|
}
|
||||||
|
for (i = 0; i < 100000; i++) /* Wait a bit. */
|
||||||
|
__asm__("NOP");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,21 +1,9 @@
|
|||||||
/** @defgroup STM32F_nvic_defines NVIC Defines
|
|
||||||
|
|
||||||
@brief <b>libopencm3 STM32F Nested Vectored Interrupt Controller</b>
|
|
||||||
|
|
||||||
@ingroup STM32F_defines
|
|
||||||
|
|
||||||
@version 1.0.0
|
|
||||||
|
|
||||||
@author @htmlonly © @endhtmlonly 2010 Piotr Esden-Tempski <piotr@esden.net>
|
|
||||||
|
|
||||||
@date 18 August 2012
|
|
||||||
|
|
||||||
LGPL License Terms @ref lgpl_license
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the libopencm3 project.
|
* This file is part of the libopencm3 project.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
* Copyright (C) 2012 Michael Ossmann <mike@ossmann.com>
|
||||||
|
* Copyright (C) 2012 Benjamin Vernoux <titanmkd@gmail.com>
|
||||||
*
|
*
|
||||||
* This library is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@ -30,13 +18,27 @@ LGPL License Terms @ref lgpl_license
|
|||||||
* You should have received a copy of the GNU Lesser General Public License
|
* 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/>.
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
/** @defgroup CM3_nvic_defines NVIC Defines
|
||||||
|
|
||||||
|
@brief <b>libopencm3 Cortex Nested Vectored Interrupt Controller</b>
|
||||||
|
|
||||||
|
@ingroup CM3_defines
|
||||||
|
|
||||||
|
@version 1.0.0
|
||||||
|
|
||||||
|
@author @htmlonly © @endhtmlonly 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
|
||||||
|
@date 18 August 2012
|
||||||
|
|
||||||
|
LGPL License Terms @ref lgpl_license
|
||||||
|
*/
|
||||||
/**@{*/
|
/**@{*/
|
||||||
|
|
||||||
#ifndef LIBOPENCM3_NVIC_H
|
#ifndef LIBOPENCM3_NVIC_H
|
||||||
#define LIBOPENCM3_NVIC_H
|
#define LIBOPENCM3_NVIC_H
|
||||||
|
|
||||||
#include <libopencm3/stm32/memorymap.h>
|
|
||||||
#include <libopencm3/cm3/common.h>
|
#include <libopencm3/cm3/common.h>
|
||||||
|
#include <libopencm3/cm3/memorymap.h>
|
||||||
|
|
||||||
/* --- NVIC Registers ------------------------------------------------------ */
|
/* --- NVIC Registers ------------------------------------------------------ */
|
||||||
|
|
||||||
@ -79,9 +81,9 @@ LGPL License Terms @ref lgpl_license
|
|||||||
|
|
||||||
/* --- IRQ channel numbers-------------------------------------------------- */
|
/* --- IRQ channel numbers-------------------------------------------------- */
|
||||||
|
|
||||||
/* Cortex M3 System Interrupts */
|
/* Cortex M3 and M4 System Interrupts */
|
||||||
/** @defgroup nvic_sysint Cortex M3 System Interrupts
|
/** @defgroup nvic_sysint Cortex M3/M4 System Interrupts
|
||||||
@ingroup STM32F_nvic_defines
|
@ingroup CM3_nvic_defines
|
||||||
|
|
||||||
IRQ numbers -3 and -6 to -9 are reserved
|
IRQ numbers -3 and -6 to -9 are reserved
|
||||||
@{*/
|
@{*/
|
||||||
@ -98,21 +100,11 @@ IRQ numbers -3 and -6 to -9 are reserved
|
|||||||
#define NVIC_SYSTICK_IRQ -1
|
#define NVIC_SYSTICK_IRQ -1
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
|
|
||||||
/* Note: User interrupts are family specific and are defined in a family
|
/* Note: User interrupts are family specific and are defined in a family
|
||||||
* specific header file in the corresponding subfolder.
|
* specific header file in the corresponding subfolder.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(STM32F1)
|
#include <libopencm3/dispatch/nvic.h>
|
||||||
# include <libopencm3/stm32/f1/nvic_f1.h>
|
|
||||||
#elif defined(STM32F2)
|
|
||||||
# include <libopencm3/stm32/f2/nvic_f2.h>
|
|
||||||
#elif defined(STM32F4)
|
|
||||||
# include <libopencm3/stm32/f4/nvic_f4.h>
|
|
||||||
#else
|
|
||||||
# error "stm32 family not defined."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* --- NVIC functions ------------------------------------------------------ */
|
/* --- NVIC functions ------------------------------------------------------ */
|
||||||
|
|
||||||
@ -131,5 +123,3 @@ void nvic_generate_software_interrupt(u16 irqn);
|
|||||||
END_DECLS
|
END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**@}*/
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
|||||||
#ifndef LIBOPENCM3_SCB_H
|
#ifndef LIBOPENCM3_SCB_H
|
||||||
#define LIBOPENCM3_SCB_H
|
#define LIBOPENCM3_SCB_H
|
||||||
|
|
||||||
#include <libopencm3/stm32/memorymap.h>
|
#include <libopencm3/cm3/memorymap.h>
|
||||||
#include <libopencm3/cm3/common.h>
|
#include <libopencm3/cm3/common.h>
|
||||||
|
|
||||||
/* --- SCB: Registers ------------------------------------------------------ */
|
/* --- SCB: Registers ------------------------------------------------------ */
|
@ -1,22 +1,8 @@
|
|||||||
/** @defgroup STM32F_systick_defines SysTick Defines
|
|
||||||
|
|
||||||
@brief <b>libopencm3 Defined Constants and Types for the STM32F SysTick </b>
|
|
||||||
|
|
||||||
@ingroup STM32F_defines
|
|
||||||
|
|
||||||
@version 1.0.0
|
|
||||||
|
|
||||||
@author @htmlonly © @endhtmlonly 2010 Thomas Otto <tommi@viadmin.org>
|
|
||||||
|
|
||||||
@date 19 August 2012
|
|
||||||
|
|
||||||
LGPL License Terms @ref lgpl_license
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the libopencm3 project.
|
* This file is part of the libopencm3 project.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||||
|
* Copyright (C) 2012 Benjamin Vernoux <titanmkd@gmail.com>
|
||||||
*
|
*
|
||||||
* This library is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@ -31,13 +17,27 @@ LGPL License Terms @ref lgpl_license
|
|||||||
* You should have received a copy of the GNU Lesser General Public License
|
* 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/>.
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
/** @defgroup CM3_systick_defines SysTick Defines
|
||||||
|
|
||||||
|
@brief <b>libopencm3 Defined Constants and Types for the Cortex SysTick </b>
|
||||||
|
|
||||||
|
@ingroup CM3_defines
|
||||||
|
|
||||||
|
@version 1.0.0
|
||||||
|
|
||||||
|
@author @htmlonly © @endhtmlonly 2010 Thomas Otto <tommi@viadmin.org>
|
||||||
|
|
||||||
|
@date 19 August 2012
|
||||||
|
|
||||||
|
LGPL License Terms @ref lgpl_license
|
||||||
|
*/
|
||||||
|
|
||||||
/**@{*/
|
/**@{*/
|
||||||
|
|
||||||
#ifndef LIBOPENCM3_SYSTICK_H
|
#ifndef LIBOPENCM3_SYSTICK_H
|
||||||
#define LIBOPENCM3_SYSTICK_H
|
#define LIBOPENCM3_SYSTICK_H
|
||||||
|
|
||||||
#include <libopencm3/stm32/memorymap.h>
|
#include <libopencm3/cm3/memorymap.h>
|
||||||
#include <libopencm3/cm3/common.h>
|
#include <libopencm3/cm3/common.h>
|
||||||
|
|
||||||
/* --- SYSTICK registers --------------------------------------------------- */
|
/* --- SYSTICK registers --------------------------------------------------- */
|
||||||
@ -63,7 +63,7 @@ LGPL License Terms @ref lgpl_license
|
|||||||
#define STK_CTRL_CLKSOURCE (1 << 2)
|
#define STK_CTRL_CLKSOURCE (1 << 2)
|
||||||
#define STK_CTRL_CLKSOURCE_LSB 2
|
#define STK_CTRL_CLKSOURCE_LSB 2
|
||||||
/** @defgroup systick_clksource Clock source selection
|
/** @defgroup systick_clksource Clock source selection
|
||||||
@ingroup STM32F_systick_defines
|
@ingroup CM3_systick_defines
|
||||||
|
|
||||||
@{*/
|
@{*/
|
||||||
#define STK_CTRL_CLKSOURCE_AHB_DIV8 0
|
#define STK_CTRL_CLKSOURCE_AHB_DIV8 0
|
||||||
@ -104,6 +104,8 @@ void systick_counter_enable(void);
|
|||||||
void systick_counter_disable(void);
|
void systick_counter_disable(void);
|
||||||
u8 systick_get_countflag(void);
|
u8 systick_get_countflag(void);
|
||||||
|
|
||||||
|
u32 systick_get_calib(void);
|
||||||
|
|
||||||
END_DECLS
|
END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
64
include/libopencm3/cm3/vector.h
Normal file
64
include/libopencm3/cm3/vector.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 chrysn <chrysn@fsfe.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Definitions for handling vector tables.
|
||||||
|
*
|
||||||
|
* This implements d0002_efm32_cortex-m3_reference_manual.pdf's figure 2.2
|
||||||
|
* (from the EFM32 documentation at
|
||||||
|
* http://www.energymicro.com/downloads/datasheets), and was seen analogously
|
||||||
|
* in other ARM implementations' libopencm3 files.
|
||||||
|
*
|
||||||
|
* The structure of the vector table is implemented independently of the system
|
||||||
|
* vector table starting at memory position 0x0, as it can be relocated to
|
||||||
|
* other memory locations too.
|
||||||
|
*
|
||||||
|
* The exact size of a vector interrupt table depends on the number of
|
||||||
|
* interrupts IRQ_COUNT, which is defined per family.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBOPENCM3_VECTOR_H
|
||||||
|
#define LIBOPENCM3_VECTOR_H
|
||||||
|
|
||||||
|
#include <libopencm3/cm3/common.h>
|
||||||
|
#include <libopencm3/cm3/nvic.h>
|
||||||
|
|
||||||
|
/** Type of an interrupt function. Only used to avoid hard-to-read function
|
||||||
|
* pointers in the efm32_vector_table_t struct. */
|
||||||
|
typedef void (*vector_table_entry_t)(void);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned int *initial_sp_value; /**< The value the stack pointer is set to initially */
|
||||||
|
vector_table_entry_t reset;
|
||||||
|
vector_table_entry_t nmi;
|
||||||
|
vector_table_entry_t hard_fault;
|
||||||
|
vector_table_entry_t memory_manage_fault;
|
||||||
|
vector_table_entry_t bus_fault;
|
||||||
|
vector_table_entry_t usage_fault;
|
||||||
|
vector_table_entry_t reserved_x001c[4];
|
||||||
|
vector_table_entry_t sv_call;
|
||||||
|
vector_table_entry_t debug_monitor;
|
||||||
|
vector_table_entry_t reserved_x0034;
|
||||||
|
vector_table_entry_t pend_sv;
|
||||||
|
vector_table_entry_t systick;
|
||||||
|
vector_table_entry_t irq[NVIC_IRQ_COUNT];
|
||||||
|
} vector_table_t;
|
||||||
|
|
||||||
|
#endif
|
34
include/libopencm3/dispatch/nvic.h
Normal file
34
include/libopencm3/dispatch/nvic.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#if defined(STM32F1)
|
||||||
|
# include <libopencm3/stm32/f1/nvic.h>
|
||||||
|
#elif defined(STM32F2)
|
||||||
|
# include <libopencm3/stm32/f2/nvic.h>
|
||||||
|
#elif defined(STM32F4)
|
||||||
|
# include <libopencm3/stm32/f4/nvic.h>
|
||||||
|
#elif defined(STM32L1)
|
||||||
|
# include <libopencm3/stm32/l1/nvic.h>
|
||||||
|
|
||||||
|
#elif defined(EFM32TG)
|
||||||
|
# include <libopencm3/efm32/efm32tg/nvic.h>
|
||||||
|
#elif defined(EFM32G)
|
||||||
|
# include <libopencm3/efm32/efm32g/nvic.h>
|
||||||
|
#elif defined(EFM32LG)
|
||||||
|
# include <libopencm3/efm32/efm32lg/nvic.h>
|
||||||
|
#elif defined(EFM32GG)
|
||||||
|
# include <libopencm3/efm32/efm32gg/nvic.h>
|
||||||
|
|
||||||
|
#elif defined(LPC13XX)
|
||||||
|
# include <libopencm3/lpc13xx/nvic.h>
|
||||||
|
#elif defined(LPC17XX)
|
||||||
|
# include <libopencm3/lpc17xx/nvic.h>
|
||||||
|
#elif defined(LPC43XX)
|
||||||
|
# include <libopencm3/lpc43xx/nvic.h>
|
||||||
|
|
||||||
|
#elif defined(LM3S)
|
||||||
|
# include <libopencm3/lm3s/nvic.h>
|
||||||
|
|
||||||
|
#else
|
||||||
|
# warning"no interrupts defined for chipset; NVIC_IRQ_COUNT = 0"
|
||||||
|
|
||||||
|
#define NVIC_IRQ_COUNT 0
|
||||||
|
|
||||||
|
#endif
|
35
include/libopencm3/efm32/efm32g/irq.yaml
Normal file
35
include/libopencm3/efm32/efm32g/irq.yaml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
includeguard: LIBOPENCM3_EFM32G_NVIC_H
|
||||||
|
partname_humanreadable: EFM32 Gecko series
|
||||||
|
partname_doxygen: EFM32G
|
||||||
|
# The names and sequence are taken from d0001_efm32g_reference_manual.pdf table 4.1.
|
||||||
|
irqs:
|
||||||
|
- dma
|
||||||
|
- gpio_even
|
||||||
|
- timer0
|
||||||
|
- usart0_rx
|
||||||
|
- usart0_tx
|
||||||
|
- acmp01
|
||||||
|
- adc0
|
||||||
|
- dac0
|
||||||
|
- i2c0
|
||||||
|
- gpio_odd
|
||||||
|
- timer1
|
||||||
|
- timer2
|
||||||
|
- usart1_rx
|
||||||
|
- usart1_tx
|
||||||
|
- usart2_rx
|
||||||
|
- usart2_tx
|
||||||
|
- uart0_rx
|
||||||
|
- uart0_tx
|
||||||
|
- leuart0
|
||||||
|
- leuart1
|
||||||
|
- letimer0
|
||||||
|
- pcnt0
|
||||||
|
- pcnt1
|
||||||
|
- pcnt2
|
||||||
|
- rtc
|
||||||
|
- cmu
|
||||||
|
- vcmp
|
||||||
|
- lcd
|
||||||
|
- msc
|
||||||
|
- aes
|
43
include/libopencm3/efm32/efm32gg/irq.yaml
Normal file
43
include/libopencm3/efm32/efm32gg/irq.yaml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
includeguard: LIBOPENCM3_EFM32GG_NVIC_H
|
||||||
|
partname_humanreadable: EFM32 Giant Gecko series
|
||||||
|
partname_doxygen: EFM32GG
|
||||||
|
# The names and sequence are taken from d0053_efm32gg_refreence_manual.pdf table 4.1.
|
||||||
|
irqs:
|
||||||
|
- dma
|
||||||
|
- gpio_even
|
||||||
|
- timer0
|
||||||
|
- usart0_rx
|
||||||
|
- usart0_tx
|
||||||
|
- usb
|
||||||
|
- acmp01
|
||||||
|
- adc0
|
||||||
|
- dac0
|
||||||
|
- i2c0
|
||||||
|
- i2c1
|
||||||
|
- gpio_odd
|
||||||
|
- timer1
|
||||||
|
- timer2
|
||||||
|
- timer3
|
||||||
|
- usart1_rx
|
||||||
|
- usart1_tx
|
||||||
|
- lesense
|
||||||
|
- usart2_rx
|
||||||
|
- usart2_tx
|
||||||
|
- uart0_rx
|
||||||
|
- uart0_tx
|
||||||
|
- uart1_rx
|
||||||
|
- uart1_tx
|
||||||
|
- leuart0
|
||||||
|
- leuart1
|
||||||
|
- letimer0
|
||||||
|
- pcnt0
|
||||||
|
- pcnt1
|
||||||
|
- pcnt2
|
||||||
|
- rtc
|
||||||
|
- burtc
|
||||||
|
- cmu
|
||||||
|
- vcmp
|
||||||
|
- lcd
|
||||||
|
- msc
|
||||||
|
- aes
|
||||||
|
- ebi
|
43
include/libopencm3/efm32/efm32lg/irq.yaml
Normal file
43
include/libopencm3/efm32/efm32lg/irq.yaml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
includeguard: LIBOPENCM3_EFM32LG_NVIC_H
|
||||||
|
partname_humanreadable: EFM32 Leopard Gecko series
|
||||||
|
partname_doxygen: EFM32LG
|
||||||
|
# The names and sequence are taken from d0183_efm32lg_reference_manual.pdf table 4.1.
|
||||||
|
irqs:
|
||||||
|
- dma
|
||||||
|
- gpio_even
|
||||||
|
- timer0
|
||||||
|
- usart0_rx
|
||||||
|
- usart0_tx
|
||||||
|
- usb
|
||||||
|
- acmp01
|
||||||
|
- adc0
|
||||||
|
- dac0
|
||||||
|
- i2c0
|
||||||
|
- i2c1
|
||||||
|
- gpio_odd
|
||||||
|
- timer1
|
||||||
|
- timer2
|
||||||
|
- timer3
|
||||||
|
- usart1_rx
|
||||||
|
- usart1_tx
|
||||||
|
- lesense
|
||||||
|
- usart2_rx
|
||||||
|
- usart2_tx
|
||||||
|
- uart0_rx
|
||||||
|
- uart0_tx
|
||||||
|
- uart1_rx
|
||||||
|
- uart1_tx
|
||||||
|
- leuart0
|
||||||
|
- leuart1
|
||||||
|
- letimer0
|
||||||
|
- pcnt0
|
||||||
|
- pcnt1
|
||||||
|
- pcnt2
|
||||||
|
- rtc
|
||||||
|
- burtc
|
||||||
|
- cmu
|
||||||
|
- vcmp
|
||||||
|
- lcd
|
||||||
|
- msc
|
||||||
|
- aes
|
||||||
|
- ebi
|
28
include/libopencm3/efm32/efm32tg/irq.yaml
Normal file
28
include/libopencm3/efm32/efm32tg/irq.yaml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
includeguard: LIBOPENCM3_EFM32TG_NVIC_H
|
||||||
|
partname_humanreadable: EFM32 Tiny Gecko series
|
||||||
|
partname_doxygen: EFM32TG
|
||||||
|
# The names and sequence are taken from d0034_efm32tg_reference_manual.pdf table 4.1.
|
||||||
|
irqs:
|
||||||
|
- dma
|
||||||
|
- gpio_even
|
||||||
|
- timer0
|
||||||
|
- usart0_rx
|
||||||
|
- usart0_tx
|
||||||
|
- acmp01
|
||||||
|
- adc0
|
||||||
|
- dac0
|
||||||
|
- i2c0
|
||||||
|
- gpio_odd
|
||||||
|
- timer1
|
||||||
|
- usart1_rx
|
||||||
|
- usart1_tx
|
||||||
|
- lesense
|
||||||
|
- leuart0
|
||||||
|
- letimer0
|
||||||
|
- pcnt0
|
||||||
|
- rtc
|
||||||
|
- cmu
|
||||||
|
- vcmp
|
||||||
|
- lcd
|
||||||
|
- msc
|
||||||
|
- aes
|
76
include/libopencm3/efm32/efm32tg/memorymap.h
Normal file
76
include/libopencm3/efm32/efm32tg/memorymap.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 chrysn <chrysn@fsfe.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Layout of the system address space of Tiny Gecko devices.
|
||||||
|
*
|
||||||
|
* This reflects d0034_efm32tg_reference_manual.pdf figure 5.2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The common cortex-m3 definitions were verified from
|
||||||
|
* d0034_efm32tg_reference_manual.pdf figure 5.2. The CM3 ROM Table seems to be
|
||||||
|
* missing there. The details (everything based on SCS_BASE) was verified from
|
||||||
|
* d0002_efm32_cortex-m3_reference_manual.pdf table 4.1, and seems to fit, but
|
||||||
|
* there are discrepancies. */
|
||||||
|
#include <libopencm3/cm3/memorymap.h>
|
||||||
|
|
||||||
|
#define CODE_BASE 0x00000000
|
||||||
|
|
||||||
|
#define SRAM_BASE 0x20000000
|
||||||
|
#define SRAM_BASE_BITBAND 0x22000000
|
||||||
|
|
||||||
|
#define PERIPH_BASE 0x40000000
|
||||||
|
#define PERIPH_BASE_BITBAND 0x42000000
|
||||||
|
|
||||||
|
/* Details of the "Code" section */
|
||||||
|
|
||||||
|
#define FLASH_BASE (CODE_BASE + 0x00000000)
|
||||||
|
#define USERDATA_BASE (CODE_BASE + 0x0fe00000)
|
||||||
|
#define LOCKBITS_BASE (CODE_BASE + 0x0fe04000)
|
||||||
|
#define CHIPCONFIG_BASE (CODE_BASE + 0x0fe08000)
|
||||||
|
#define CODESPACESRAM_BASE (CODE_BASE + 0x10000000)
|
||||||
|
|
||||||
|
/* Tiny Gecko peripherial definitions */
|
||||||
|
|
||||||
|
#define VCMP_BASE (PERIPH_BASE + 0x00000000)
|
||||||
|
#define ACMP0_BASE (PERIPH_BASE + 0x00001000)
|
||||||
|
#define ACMP1_BASE (PERIPH_BASE + 0x00001400)
|
||||||
|
#define ADC_BASE (PERIPH_BASE + 0x00002000)
|
||||||
|
#define DAC0_BASE (PERIPH_BASE + 0x00004000)
|
||||||
|
#define GPIO_BASE (PERIPH_BASE + 0x00006000) /**< @see gpio.h */
|
||||||
|
#define I2C0_BASE (PERIPH_BASE + 0x0000a000)
|
||||||
|
#define USART0_BASE (PERIPH_BASE + 0x0000c000)
|
||||||
|
#define USART1_BASE (PERIPH_BASE + 0x0000c400)
|
||||||
|
#define TIMER0_BASE (PERIPH_BASE + 0x00010000)
|
||||||
|
#define TIMER1_BASE (PERIPH_BASE + 0x00010400)
|
||||||
|
#define RTC_BASE (PERIPH_BASE + 0x00080000)
|
||||||
|
#define LETIMER0_BASE (PERIPH_BASE + 0x00082000)
|
||||||
|
#define LEUART0_BASE (PERIPH_BASE + 0x00084000)
|
||||||
|
#define PCNT0_BASE (PERIPH_BASE + 0x00086000)
|
||||||
|
#define WDOG_BASE (PERIPH_BASE + 0x00088000)
|
||||||
|
#define LCD_BASE (PERIPH_BASE + 0x0008a000)
|
||||||
|
#define LESENSE_BASE (PERIPH_BASE + 0x0008c000)
|
||||||
|
#define MSC_BASE (PERIPH_BASE + 0x000c0000)
|
||||||
|
#define DMA_BASE (PERIPH_BASE + 0x000c2000)
|
||||||
|
#define EMU_BASE (PERIPH_BASE + 0x000c6000)
|
||||||
|
#define CMU_BASE (PERIPH_BASE + 0x000c8000) /**< @see cmu.h */
|
||||||
|
#define RMU_BASE (PERIPH_BASE + 0x000ca000)
|
||||||
|
#define PRS_BASE (PERIPH_BASE + 0x000cc000)
|
||||||
|
#define AES_BASE (PERIPH_BASE + 0x000e0000)
|
37
include/libopencm3/efm32/memorymap.h
Normal file
37
include/libopencm3/efm32/memorymap.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 chrysn <chrysn@fsfe.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Dispatcher for the base address definitions, depending on the particular
|
||||||
|
* Gecko family.
|
||||||
|
*
|
||||||
|
* @see tinygecko/memorymap.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBOPENCM3_EFM32_MEMORYMAP_H
|
||||||
|
#define LIBOPENCM3_EFM32_MEMORYMAP_H
|
||||||
|
|
||||||
|
#ifdef TINYGECKO
|
||||||
|
# include <libopencm3/efm32/tinygecko/memorymap.h>
|
||||||
|
#else
|
||||||
|
# error "efm32 family not defined."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
120
include/libopencm3/lm3s/irq.yaml
Normal file
120
include/libopencm3/lm3s/irq.yaml
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
includeguard: LIBOPENCM3_LM3S_NVIC_H
|
||||||
|
partname_humanreadable: LM3S series
|
||||||
|
partname_doxygen: LM3S
|
||||||
|
irqs:
|
||||||
|
0: GPIOA
|
||||||
|
1: GPIOB
|
||||||
|
2: GPIOC
|
||||||
|
3: GPIOD
|
||||||
|
4: GPIOE
|
||||||
|
5: UART0
|
||||||
|
6: UART1
|
||||||
|
7: SSI0
|
||||||
|
8: I2C0
|
||||||
|
9: PWM0_FAULT
|
||||||
|
10: PWM0_0
|
||||||
|
11: PWM0_1
|
||||||
|
12: PWM0_2
|
||||||
|
13: QEI0
|
||||||
|
14: ADC0SS0
|
||||||
|
15: ADC0SS1
|
||||||
|
16: ADC0SS2
|
||||||
|
17: ADC0SS3
|
||||||
|
18: WATCHDOG
|
||||||
|
19: TIMER0A
|
||||||
|
20: TIMER0B
|
||||||
|
21: TIMER1A
|
||||||
|
22: TIMER1B
|
||||||
|
23: TIMER2A
|
||||||
|
24: TIMER2B
|
||||||
|
25: COMP0
|
||||||
|
26: COMP1
|
||||||
|
27: COMP2
|
||||||
|
28: SYSCTL
|
||||||
|
29: FLASH
|
||||||
|
30: GPIOF
|
||||||
|
31: GPIOG
|
||||||
|
32: GPIOH
|
||||||
|
33: UART2
|
||||||
|
34: SSI1
|
||||||
|
35: TIMER3A
|
||||||
|
36: TIMER3B
|
||||||
|
37: I2C1
|
||||||
|
38: QEI1
|
||||||
|
39: CAN0
|
||||||
|
40: CAN1
|
||||||
|
41: CAN2
|
||||||
|
42: ETH
|
||||||
|
43: HIBERNATE
|
||||||
|
44: USB0
|
||||||
|
45: PWM0_3
|
||||||
|
46: UDMA
|
||||||
|
47: UDMAERR
|
||||||
|
48: ADC1SS0
|
||||||
|
49: ADC1SS1
|
||||||
|
50: ADC1SS2
|
||||||
|
51: ADC1SS3
|
||||||
|
52: I2S0
|
||||||
|
53: EPI0
|
||||||
|
54: GPIOJ
|
||||||
|
55: GPIOK
|
||||||
|
56: GPIOL
|
||||||
|
57: SSI2
|
||||||
|
58: SSI3
|
||||||
|
59: UART3
|
||||||
|
60: UART4
|
||||||
|
61: UART5
|
||||||
|
62: UART6
|
||||||
|
63: UART7
|
||||||
|
# undefined: slot 64 - 67
|
||||||
|
68: I2C2
|
||||||
|
69: I2C3
|
||||||
|
70: TIMER4A
|
||||||
|
71: TIMER4B
|
||||||
|
# undefined: slot 72 - 91
|
||||||
|
92: TIMER5A
|
||||||
|
93: TIMER5B
|
||||||
|
94: WTIMER0A
|
||||||
|
95: WTIMER0B
|
||||||
|
96: WTIMER1A
|
||||||
|
97: WTIMER1B
|
||||||
|
98: WTIMER2A
|
||||||
|
99: WTIMER2B
|
||||||
|
100: WTIMER3A
|
||||||
|
101: WTIMER3B
|
||||||
|
102: WTIMER4A
|
||||||
|
103: WTIMER4B
|
||||||
|
104: WTIMER5A
|
||||||
|
105: WTIMER5B
|
||||||
|
106: SYSEXC
|
||||||
|
107: PECI0
|
||||||
|
108: LPC0
|
||||||
|
109: I2C4
|
||||||
|
110: I2C5
|
||||||
|
111: GPIOM
|
||||||
|
112: GPION
|
||||||
|
# undefined: slot 113
|
||||||
|
114: FAN0
|
||||||
|
# undefined: slot 115
|
||||||
|
116: GPIOP0
|
||||||
|
117: GPIOP1
|
||||||
|
118: GPIOP2
|
||||||
|
119: GPIOP3
|
||||||
|
120: GPIOP4
|
||||||
|
121: GPIOP5
|
||||||
|
122: GPIOP6
|
||||||
|
123: GPIOP7
|
||||||
|
124: GPIOQ0
|
||||||
|
125: GPIOQ1
|
||||||
|
126: GPIOQ2
|
||||||
|
127: GPIOQ3
|
||||||
|
128: GPIOQ4
|
||||||
|
129: GPIOQ5
|
||||||
|
130: GPIOQ6
|
||||||
|
131: GPIOQ7
|
||||||
|
# undefined: slot 132 - 133
|
||||||
|
134: PWM1_0
|
||||||
|
135: PWM1_1
|
||||||
|
136: PWM1_2
|
||||||
|
137: PWM1_3
|
||||||
|
138: PWM1_FAULT
|
62
include/libopencm3/lpc13xx/irq.yaml
Normal file
62
include/libopencm3/lpc13xx/irq.yaml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
includeguard: LIBOPENCM3_LPC13xx_NVIC_H
|
||||||
|
partname_humanreadable: LPC 13xx series
|
||||||
|
partname_doxygen: LPC13xx
|
||||||
|
irqs:
|
||||||
|
0: pio0_0
|
||||||
|
1: pio0_1
|
||||||
|
2: pio0_2
|
||||||
|
3: pio0_3
|
||||||
|
4: pio0_4
|
||||||
|
5: pio0_5
|
||||||
|
6: pio0_6
|
||||||
|
7: pio0_7
|
||||||
|
8: pio0_8
|
||||||
|
9: pio0_9
|
||||||
|
10: pio0_10
|
||||||
|
11: pio0_11
|
||||||
|
12: pio1_0
|
||||||
|
13: pio1_1
|
||||||
|
14: pio1_2
|
||||||
|
15: pio1_3
|
||||||
|
16: pio1_4
|
||||||
|
17: pio1_5
|
||||||
|
18: pio1_6
|
||||||
|
19: pio1_7
|
||||||
|
20: pio1_8
|
||||||
|
21: pio1_9
|
||||||
|
22: pio1_10
|
||||||
|
23: pio1_11
|
||||||
|
24: pio2_0
|
||||||
|
25: pio2_1
|
||||||
|
26: pio2_2
|
||||||
|
27: pio2_3
|
||||||
|
28: pio2_4
|
||||||
|
29: pio2_5
|
||||||
|
30: pio2_6
|
||||||
|
31: pio2_7
|
||||||
|
32: pio2_8
|
||||||
|
33: pio2_9
|
||||||
|
34: pio2_10
|
||||||
|
35: pio2_11
|
||||||
|
36: pio3_0
|
||||||
|
37: pio3_1
|
||||||
|
38: pio3_2
|
||||||
|
39: pio3_3
|
||||||
|
40: i2c0
|
||||||
|
41: ct16b0
|
||||||
|
42: ct16b1
|
||||||
|
43: ct32b0
|
||||||
|
44: ct32b1
|
||||||
|
45: ssp0
|
||||||
|
46: uart
|
||||||
|
47: usb
|
||||||
|
48: usb_fiq
|
||||||
|
49: adc
|
||||||
|
50: wdt
|
||||||
|
51: bod
|
||||||
|
# 52: reserved
|
||||||
|
53: pio3
|
||||||
|
54: pio2
|
||||||
|
55: pio1
|
||||||
|
56: pio0
|
||||||
|
56: ssp1
|
39
include/libopencm3/lpc17xx/irq.yaml
Normal file
39
include/libopencm3/lpc17xx/irq.yaml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
includeguard: LIBOPENCM3_LPC17xx_NVIC_H
|
||||||
|
partname_humanreadable: LPC 17xx series
|
||||||
|
partname_doxygen: LPC17xx
|
||||||
|
irqs:
|
||||||
|
0: wdt
|
||||||
|
1: timer0
|
||||||
|
2: timer1
|
||||||
|
3: timer2
|
||||||
|
4: timer3
|
||||||
|
5: uart0
|
||||||
|
6: uart1
|
||||||
|
7: uart2
|
||||||
|
8: uart3
|
||||||
|
9: pwm
|
||||||
|
10: i2c0
|
||||||
|
11: i2c1
|
||||||
|
12: i2c2
|
||||||
|
13: spi
|
||||||
|
14: ssp0
|
||||||
|
15: ssp1
|
||||||
|
16: pll0
|
||||||
|
17: rtc
|
||||||
|
18: eint0
|
||||||
|
19: eint1
|
||||||
|
20: eint2
|
||||||
|
21: eint3
|
||||||
|
22: adc
|
||||||
|
23: bod
|
||||||
|
24: usb
|
||||||
|
25: can
|
||||||
|
26: gpdma
|
||||||
|
27: i2s
|
||||||
|
28: ethernet
|
||||||
|
29: rit
|
||||||
|
30: motor_pwm
|
||||||
|
31: qei
|
||||||
|
32: pll1
|
||||||
|
33: usb_act
|
||||||
|
34: can_act
|
55
include/libopencm3/lpc43xx/irq.yaml
Normal file
55
include/libopencm3/lpc43xx/irq.yaml
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
includeguard: LIBOPENCM3_LPC43xx_NVIC_H
|
||||||
|
partname_humanreadable: LPC 43xx series
|
||||||
|
partname_doxygen: LPC43xx
|
||||||
|
irqs:
|
||||||
|
0: dac
|
||||||
|
1: m0core
|
||||||
|
2: dma
|
||||||
|
# reserved: 3, 4
|
||||||
|
5: ethernet
|
||||||
|
6: sdio
|
||||||
|
7: lcd
|
||||||
|
8: usb0
|
||||||
|
9: usb1
|
||||||
|
10: sct
|
||||||
|
11: ritimer
|
||||||
|
12: timer0
|
||||||
|
13: timer1
|
||||||
|
14: timer2
|
||||||
|
15: timer3
|
||||||
|
16: mcpwm
|
||||||
|
17: adc0
|
||||||
|
18: i2c0
|
||||||
|
19: i2c1
|
||||||
|
20: spi
|
||||||
|
21: adc1
|
||||||
|
22: ssp0
|
||||||
|
23: ssp1
|
||||||
|
24: usart0
|
||||||
|
25: uart1
|
||||||
|
26: usart2
|
||||||
|
27: usart3
|
||||||
|
28: i2s0
|
||||||
|
29: i2s1
|
||||||
|
30: spifi
|
||||||
|
31: sgpio
|
||||||
|
32: pin_int0
|
||||||
|
33: pin_int1
|
||||||
|
34: pin_int2
|
||||||
|
35: pin_int3
|
||||||
|
36: pin_int4
|
||||||
|
37: pin_int5
|
||||||
|
38: pin_int6
|
||||||
|
39: pin_int7
|
||||||
|
40: gint0
|
||||||
|
41: gint1
|
||||||
|
42: eventrouter
|
||||||
|
43: c_can1
|
||||||
|
# reserved: 44, 45
|
||||||
|
46: atimer
|
||||||
|
47: rtc
|
||||||
|
# reserved: 48
|
||||||
|
49: wwdt
|
||||||
|
# reserved: 50
|
||||||
|
51: c_can0
|
||||||
|
52: qei
|
@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the libopencm3 project.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
|
||||||
* Copyright (C) 2012 Michael Ossmann <mike@ossmann.com>
|
|
||||||
* Copyright (C) 2012 Benjamin Vernoux <titanmkd@gmail.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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LPC43XX_NVIC_H
|
|
||||||
#define LPC43XX_NVIC_H
|
|
||||||
|
|
||||||
#include <libopencm3/cm3/common.h>
|
|
||||||
#include <libopencm3/cm3/memorymap.h>
|
|
||||||
#include <libopencm3/lpc43xx/memorymap.h>
|
|
||||||
|
|
||||||
/* --- NVIC Registers ------------------------------------------------------ */
|
|
||||||
|
|
||||||
/* ISER: Interrupt Set Enable Registers */
|
|
||||||
/* Note: 8 32bit Registers */
|
|
||||||
#define NVIC_ISER(iser_id) MMIO32(NVIC_BASE + 0x00 + (iser_id * 4))
|
|
||||||
|
|
||||||
/* NVIC_BASE + 0x020 (0xE000 E120 - 0xE000 E17F): Reserved */
|
|
||||||
|
|
||||||
/* ICER: Interrupt Clear Enable Registers */
|
|
||||||
/* Note: 8 32bit Registers */
|
|
||||||
#define NVIC_ICER(icer_id) MMIO32(NVIC_BASE + 0x80 + (icer_id * 4))
|
|
||||||
|
|
||||||
/* NVIC_BASE + 0x0A0 (0xE000 E1A0 - 0xE000 E1FF): Reserved */
|
|
||||||
|
|
||||||
/* ISPR: Interrupt Set Pending Registers */
|
|
||||||
/* Note: 8 32bit Registers */
|
|
||||||
#define NVIC_ISPR(ispr_id) MMIO32(NVIC_BASE + 0x100 + (ispr_id * 4))
|
|
||||||
|
|
||||||
/* NVIC_BASE + 0x120 (0xE000 E220 - 0xE000 E27F): Reserved */
|
|
||||||
|
|
||||||
/* ICPR: Interrupt Clear Pending Registers */
|
|
||||||
/* Note: 8 32bit Registers */
|
|
||||||
#define NVIC_ICPR(icpr_id) MMIO32(NVIC_BASE + 0x180 + (icpr_id * 4))
|
|
||||||
|
|
||||||
/* NVIC_BASE + 0x1A0 (0xE000 E2A0 - 0xE00 E2FF): Reserved */
|
|
||||||
|
|
||||||
/* IABR: Interrupt Active Bit Register */
|
|
||||||
/* Note: 8 32bit Registers */
|
|
||||||
#define NVIC_IABR(iabr_id) MMIO32(NVIC_BASE + 0x200 + (iabr_id * 4))
|
|
||||||
|
|
||||||
/* NVIC_BASE + 0x220 (0xE000 E320 - 0xE000 E3FF): Reserved */
|
|
||||||
|
|
||||||
/* IPR: Interrupt Priority Registers */
|
|
||||||
/* Note: 240 8bit Registers */
|
|
||||||
#define NVIC_IPR(ipr_id) MMIO8(NVIC_BASE + 0x300 + ipr_id)
|
|
||||||
|
|
||||||
/* STIR: Software Trigger Interrupt Register */
|
|
||||||
#define NVIC_STIR MMIO32(STIR_BASE)
|
|
||||||
|
|
||||||
/* --- IRQ channel numbers-------------------------------------------------- */
|
|
||||||
|
|
||||||
/* Cortex M4 System Interrupts */
|
|
||||||
#define NVIC_NMI_IRQ -14
|
|
||||||
#define NVIC_HARD_FAULT_IRQ -13
|
|
||||||
#define NVIC_MEM_MANAGE_IRQ -12
|
|
||||||
#define NVIC_BUS_FAULT_IRQ -11
|
|
||||||
#define NVIC_USAGE_FAULT_IRQ -10
|
|
||||||
/* irq numbers -6 to -9 are reserved */
|
|
||||||
#define NVIC_SV_CALL_IRQ -5
|
|
||||||
#define DEBUG_MONITOR_IRQ -4
|
|
||||||
/* irq number -3 reserved */
|
|
||||||
#define NVIC_PENDSV_IRQ -2
|
|
||||||
#define NVIC_SYSTICK_IRQ -1
|
|
||||||
|
|
||||||
/* LPC43xx M4 specific user interrupts */
|
|
||||||
#define NVIC_M4_DAC_IRQ 0
|
|
||||||
#define NVIC_M4_M0CORE_IRQ 1
|
|
||||||
#define NVIC_M4_DMA_IRQ 2
|
|
||||||
#define NVIC_M4_ETHERNET_IRQ 5
|
|
||||||
#define NVIC_M4_SDIO_IRQ 6
|
|
||||||
#define NVIC_M4_LCD_IRQ 7
|
|
||||||
#define NVIC_M4_USB0_IRQ 8
|
|
||||||
#define NVIC_M4_USB1_IRQ 9
|
|
||||||
#define NVIC_M4_SCT_IRQ 10
|
|
||||||
#define NVIC_M4_RITIMER_IRQ 11
|
|
||||||
#define NVIC_M4_TIMER0_IRQ 12
|
|
||||||
#define NVIC_M4_TIMER1_IRQ 13
|
|
||||||
#define NVIC_M4_TIMER2_IRQ 14
|
|
||||||
#define NVIC_M4_TIMER3_IRQ 15
|
|
||||||
#define NVIC_M4_MCPWM_IRQ 16
|
|
||||||
#define NVIC_M4_ADC0_IRQ 17
|
|
||||||
#define NVIC_M4_I2C0_IRQ 18
|
|
||||||
#define NVIC_M4_I2C1_IRQ 19
|
|
||||||
#define NVIC_M4_SPI_IRQ 20
|
|
||||||
#define NVIC_M4_ADC1_IRQ 21
|
|
||||||
#define NVIC_M4_SSP0_IRQ 22
|
|
||||||
#define NVIC_M4_SSP1_IRQ 23
|
|
||||||
#define NVIC_M4_USART0_IRQ 24
|
|
||||||
#define NVIC_M4_UART1_IRQ 25
|
|
||||||
#define NVIC_M4_USART2_IRQ 26
|
|
||||||
#define NVIC_M4_USART3_IRQ 27
|
|
||||||
#define NVIC_M4_I2S0_IRQ 28
|
|
||||||
#define NVIC_M4_I2S1_IRQ 29
|
|
||||||
#define NVIC_M4_SPIFI_IRQ 30
|
|
||||||
#define NVIC_M4_SGPIO_IRQ 31
|
|
||||||
#define NVIC_M4_PIN_INT0_IRQ 32
|
|
||||||
#define NVIC_M4_PIN_INT1_IRQ 33
|
|
||||||
#define NVIC_M4_PIN_INT2_IRQ 34
|
|
||||||
#define NVIC_M4_PIN_INT3_IRQ 35
|
|
||||||
#define NVIC_M4_PIN_INT4_IRQ 36
|
|
||||||
#define NVIC_M4_PIN_INT5_IRQ 37
|
|
||||||
#define NVIC_M4_PIN_INT6_IRQ 38
|
|
||||||
#define NVIC_M4_PIN_INT7_IRQ 39
|
|
||||||
#define NVIC_M4_GINT0_IRQ 40
|
|
||||||
#define NVIC_M4_GINT1_IRQ 41
|
|
||||||
#define NVIC_M4_EVENTROUTER_IRQ 42
|
|
||||||
#define NVIC_M4_C_CAN1_IRQ 43
|
|
||||||
#define NVIC_M4_ATIMER_IRQ 46
|
|
||||||
#define NVIC_M4_RTC_IRQ 47
|
|
||||||
#define NVIC_M4_WWDT_IRQ 49
|
|
||||||
#define NVIC_M4_C_CAN0_IRQ 51
|
|
||||||
#define NVIC_M4_QEI_IRQ 52
|
|
||||||
|
|
||||||
/* LPC43xx M0 specific user interrupts */
|
|
||||||
//TODO
|
|
||||||
|
|
||||||
/* --- NVIC functions ------------------------------------------------------ */
|
|
||||||
|
|
||||||
BEGIN_DECLS
|
|
||||||
|
|
||||||
void nvic_enable_irq(u8 irqn);
|
|
||||||
void nvic_disable_irq(u8 irqn);
|
|
||||||
u8 nvic_get_pending_irq(u8 irqn);
|
|
||||||
void nvic_set_pending_irq(u8 irqn);
|
|
||||||
void nvic_clear_pending_irq(u8 irqn);
|
|
||||||
u8 nvic_get_active_irq(u8 irqn);
|
|
||||||
u8 nvic_get_irq_enabled(u8 irqn);
|
|
||||||
void nvic_set_priority(u8 irqn, u8 priority);
|
|
||||||
void nvic_generate_software_interrupt(u8 irqn);
|
|
||||||
|
|
||||||
END_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the libopencm3 project.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
|
||||||
* Copyright (C) 2012 Benjamin Vernoux <titanmkd@gmail.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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBOPENCM3_SYSTICK_H
|
|
||||||
#define LIBOPENCM3_SYSTICK_H
|
|
||||||
|
|
||||||
#include <libopencm3/lpc43xx/memorymap.h>
|
|
||||||
#include <libopencm3/cm3/memorymap.h>
|
|
||||||
#include <libopencm3/cm3/common.h>
|
|
||||||
|
|
||||||
/* --- SYSTICK registers --------------------------------------------------- */
|
|
||||||
/* See also libopencm3\cm3\scs.h for details on SysTicks registers */
|
|
||||||
|
|
||||||
/* Control and status register (STK_CTRL) */
|
|
||||||
#define STK_CTRL MMIO32(SYS_TICK_BASE + 0x00)
|
|
||||||
|
|
||||||
/* reload value register (STK_LOAD) */
|
|
||||||
#define STK_LOAD MMIO32(SYS_TICK_BASE + 0x04)
|
|
||||||
|
|
||||||
/* current value register (STK_VAL) */
|
|
||||||
#define STK_VAL MMIO32(SYS_TICK_BASE + 0x08)
|
|
||||||
|
|
||||||
/* calibration value register (STK_CALIB) */
|
|
||||||
#define STK_CALIB MMIO32(SYS_TICK_BASE + 0x0C)
|
|
||||||
|
|
||||||
/* --- STK_CTRL values ----------------------------------------------------- */
|
|
||||||
/* Bits [31:17] Reserved, must be kept cleared. */
|
|
||||||
/* COUNTFLAG: */
|
|
||||||
#define STK_CTRL_COUNTFLAG (1 << 16)
|
|
||||||
/* Bits [15:3] Reserved, must be kept cleared. */
|
|
||||||
/* CLKSOURCE: Clock source selection */
|
|
||||||
#define STK_CTRL_CLKSOURCE (1 << 2)
|
|
||||||
/* TICKINT: SysTick exception request enable */
|
|
||||||
#define STK_CTRL_TICKINT (1 << 1)
|
|
||||||
/* ENABLE: Counter enable */
|
|
||||||
#define STK_CTRL_ENABLE (1 << 0)
|
|
||||||
|
|
||||||
/* --- STK_LOAD values ----------------------------------------------------- */
|
|
||||||
/* Bits [31:24] Reserved, must be kept cleared. */
|
|
||||||
/* RELOAD[23:0]: RELOAD value */
|
|
||||||
|
|
||||||
/* --- STK_VAL values ------------------------------------------------------ */
|
|
||||||
/* Bits [31:24] Reserved, must be kept cleared. */
|
|
||||||
/* CURRENT[23:0]: Current counter value */
|
|
||||||
|
|
||||||
/* --- STK_CALIB values ---------------------------------------------------- */
|
|
||||||
/* NOREF: NOREF flag */
|
|
||||||
#define STK_CALIB_NOREF (1 << 31)
|
|
||||||
/* SKEW: SKEW flag */
|
|
||||||
#define STK_CALIB_SKEW (1 << 30)
|
|
||||||
/* Bits [29:24] Reserved, must be kept cleared. */
|
|
||||||
/* TENMS[23:0]: Calibration value */
|
|
||||||
|
|
||||||
/* --- Function Prototypes ------------------------------------------------- */
|
|
||||||
|
|
||||||
BEGIN_DECLS
|
|
||||||
|
|
||||||
void systick_set_reload(u32 value);
|
|
||||||
u32 systick_get_value(void);
|
|
||||||
void systick_set_clocksource(u8 clocksource);
|
|
||||||
void systick_interrupt_enable(void);
|
|
||||||
void systick_interrupt_disable(void);
|
|
||||||
void systick_counter_enable(void);
|
|
||||||
void systick_counter_disable(void);
|
|
||||||
u8 systick_get_countflag(void);
|
|
||||||
|
|
||||||
u32 systick_get_calib(void);
|
|
||||||
|
|
||||||
END_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
@ -461,7 +461,7 @@
|
|||||||
/* --- CAN_TIxR values ------------------------------------------------------ */
|
/* --- CAN_TIxR values ------------------------------------------------------ */
|
||||||
|
|
||||||
/* STID[10:0]: Standard identifier */
|
/* STID[10:0]: Standard identifier */
|
||||||
#define CAN_TIxR_STID_MASK (0x3FF << 21)
|
#define CAN_TIxR_STID_MASK (0x7FF << 21)
|
||||||
#define CAN_TIxR_STID_SHIFT 21
|
#define CAN_TIxR_STID_SHIFT 21
|
||||||
|
|
||||||
/* EXID[15:0]: Extended identifier */
|
/* EXID[15:0]: Extended identifier */
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user