Compare commits
1 Commits
master
...
coding_sty
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb73d4ba3d |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -7,12 +7,3 @@
|
|||||||
*.srec
|
*.srec
|
||||||
*.list
|
*.list
|
||||||
*.map
|
*.map
|
||||||
*.stylecheck
|
|
||||||
generated.*.ld
|
|
||||||
.gdb_history
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Project files from idea/netbeans/eclipse
|
|
||||||
nbproject/
|
|
||||||
.idea/
|
|
||||||
.project
|
|
||||||
|
|||||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "libopencm3"]
|
[submodule "libopencm3"]
|
||||||
path = libopencm3
|
path = libopencm3
|
||||||
url = https://git.orangetime.top/EMTime/libopencm3
|
url = https://github.com/libopencm3/libopencm3.git
|
||||||
|
|||||||
16
.travis.yml
16
.travis.yml
@@ -1,16 +0,0 @@
|
|||||||
language: c
|
|
||||||
script:
|
|
||||||
- make
|
|
||||||
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- sourceline: 'ppa:team-gcc-arm-embedded/ppa'
|
|
||||||
packages:
|
|
||||||
- gcc-arm-embedded
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
irc:
|
|
||||||
channels:
|
|
||||||
- "chat.freenode.net#libopencm3"
|
|
||||||
use_notice: true
|
|
||||||
77
Makefile
77
Makefile
@@ -17,15 +17,10 @@
|
|||||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
##
|
##
|
||||||
|
|
||||||
PREFIX ?= arm-none-eabi-
|
PREFIX ?= arm-none-eabi
|
||||||
|
#PREFIX ?= arm-elf
|
||||||
|
|
||||||
TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4
|
TARGETS = stm32/f1 stm32/f2 stm32/f4 stm32/l1 lpc13xx lpc17xx lpc43xx lm3s lm4f efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
|
||||||
TARGETS += stm32/l0 stm32/l1 stm32/l4
|
|
||||||
TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx
|
|
||||||
TARGETS += tiva/lm3s tiva/lm4f
|
|
||||||
TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
|
|
||||||
TARGETS += vf6xx
|
|
||||||
TARGETS += sam/d
|
|
||||||
|
|
||||||
# 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)
|
||||||
@@ -34,68 +29,40 @@ Q := @
|
|||||||
MAKEFLAGS += --no-print-directory
|
MAKEFLAGS += --no-print-directory
|
||||||
endif
|
endif
|
||||||
|
|
||||||
OPENCM3_DIR ?= $(realpath libopencm3)
|
|
||||||
EXAMPLE_RULES = elf
|
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
bin: EXAMPLE_RULES += bin
|
|
||||||
hex: EXAMPLE_RULES += hex
|
|
||||||
srec: EXAMPLE_RULES += srec
|
|
||||||
list: EXAMPLE_RULES += list
|
|
||||||
images: EXAMPLE_RULES += images
|
|
||||||
|
|
||||||
bin: build
|
|
||||||
hex: build
|
|
||||||
srec: build
|
|
||||||
list: build
|
|
||||||
images: build
|
|
||||||
|
|
||||||
build: lib examples
|
build: lib examples
|
||||||
|
|
||||||
lib:
|
lib:
|
||||||
$(Q)if [ ! "`ls -A $(OPENCM3_DIR)`" ] ; then \
|
$(Q)if [ ! "`ls -A libopencm3`" ] ; then \
|
||||||
printf "######## ERROR ########\n"; \
|
echo "######## ERROR ########"; \
|
||||||
printf "\tlibopencm3 is not initialized.\n"; \
|
echo "\tlibopencm3 is not initialized."; \
|
||||||
printf "\tPlease run:\n"; \
|
echo "\tPlease run:"; \
|
||||||
printf "\t$$ git submodule init\n"; \
|
echo "\t$$ git submodule init"; \
|
||||||
printf "\t$$ git submodule update\n"; \
|
echo "\t$$ git submodule update"; \
|
||||||
printf "\tbefore running make.\n"; \
|
echo "\tbefore running make."; \
|
||||||
printf "######## ERROR ########\n"; \
|
echo "######## ERROR ########"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
$(Q)$(MAKE) -C $(OPENCM3_DIR)
|
$(Q)$(MAKE) -C libopencm3
|
||||||
|
|
||||||
EXAMPLE_DIRS:=$(sort $(dir $(wildcard $(addsuffix /*/*/Makefile,$(addprefix examples/,$(TARGETS))))))
|
EXAMPLE_DIRS:=$(sort $(dir $(wildcard $(addsuffix /*/*/Makefile,$(addprefix examples/,$(TARGETS))))))
|
||||||
$(EXAMPLE_DIRS): lib
|
$(EXAMPLE_DIRS): lib
|
||||||
@printf " BUILD $@\n";
|
@printf " BUILD $@\n";
|
||||||
$(Q)$(MAKE) --directory=$@ OPENCM3_DIR=$(OPENCM3_DIR) $(EXAMPLE_RULES)
|
$(Q)$(MAKE) --directory=$@
|
||||||
|
|
||||||
examples: $(EXAMPLE_DIRS)
|
examples: $(EXAMPLE_DIRS)
|
||||||
$(Q)true
|
$(Q)true
|
||||||
|
|
||||||
examplesclean: $(EXAMPLE_DIRS:=.clean)
|
# Bleh http://www.makelinux.net/make3/make3-CHP-6-SECT-1#make3-CHP-6-SECT-1
|
||||||
|
clean:
|
||||||
clean: examplesclean styleclean
|
|
||||||
$(Q)$(MAKE) -C libopencm3 clean
|
$(Q)$(MAKE) -C libopencm3 clean
|
||||||
|
$(Q)for i in $(EXAMPLE_DIRS); do \
|
||||||
|
if [ -d $$i ]; then \
|
||||||
|
printf " CLEAN $$i\n"; \
|
||||||
|
$(MAKE) -C $$i clean SRCLIBDIR=$(SRCLIBDIR) || exit $?; \
|
||||||
|
fi; \
|
||||||
|
done
|
||||||
|
|
||||||
stylecheck: $(EXAMPLE_DIRS:=.stylecheck)
|
.PHONY: build lib examples $(EXAMPLE_DIRS) install clean
|
||||||
styleclean: $(EXAMPLE_DIRS:=.styleclean)
|
|
||||||
|
|
||||||
|
|
||||||
%.clean:
|
|
||||||
$(Q)if [ -d $* ]; then \
|
|
||||||
printf " CLEAN $*\n"; \
|
|
||||||
$(MAKE) -C $* clean OPENCM3_DIR=$(OPENCM3_DIR) || exit $?; \
|
|
||||||
fi;
|
|
||||||
|
|
||||||
%.styleclean:
|
|
||||||
$(Q)$(MAKE) -C $* styleclean OPENCM3_DIR=$(OPENCM3_DIR)
|
|
||||||
|
|
||||||
%.stylecheck:
|
|
||||||
$(Q)$(MAKE) -C $* stylecheck OPENCM3_DIR=$(OPENCM3_DIR)
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: build lib examples $(EXAMPLE_DIRS) install clean stylecheck styleclean \
|
|
||||||
bin hex srec list images
|
|
||||||
|
|
||||||
|
|||||||
45
README
Normal file
45
README
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This repository contains assorted example projects for libopencm3.
|
||||||
|
|
||||||
|
The libopencm3 project aims to create an open-source firmware library for
|
||||||
|
various ARM Cortex-M3 microcontrollers.
|
||||||
|
|
||||||
|
For more information visit http://libopencm3.org
|
||||||
|
|
||||||
|
The examples are meant as starting points for different subsystems on multitude
|
||||||
|
of platforms.
|
||||||
|
|
||||||
|
Feel free to add new examples and send them to us either via the mailinglist or
|
||||||
|
preferably via a github pull request.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
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
|
||||||
|
examples by typing 'make' at the top-level directory) onto the Olimex
|
||||||
|
STM32-H103 eval board (ST STM32F1 series microcontroller), you can execute:
|
||||||
|
|
||||||
|
$ cd examples/stm32/f1/stm32-h103/miniblink
|
||||||
|
$ make flash
|
||||||
|
|
||||||
|
The Makefiles of the examples are configured to use a certain OpenOCD
|
||||||
|
flash programmer, you might need to change some of the variables in the
|
||||||
|
Makefile if you use a different one.
|
||||||
|
|
||||||
|
You can also flash manually like this:
|
||||||
|
|
||||||
|
$ openocd -f interface/jtagkey-tiny.cfg -f target/stm32f1x.cfg
|
||||||
|
$ telnet localhost 4444
|
||||||
|
> reset halt
|
||||||
|
> flash write_image erase foobar.hex
|
||||||
|
> reset
|
||||||
|
|
||||||
|
Replace the "jtagkey-tiny.cfg" with whatever JTAG device you are using, and/or
|
||||||
|
replace "stm32f1x.cfg" with your respective config file. Replace "foobar.hex"
|
||||||
|
with the file name of the image you want to flash.
|
||||||
126
README.md
126
README.md
@@ -1,126 +0,0 @@
|
|||||||
# README
|
|
||||||
[](https://travis-ci.org/libopencm3/libopencm3-examples)
|
|
||||||
|
|
||||||
[](https://gitter.im/libopencm3/discuss)
|
|
||||||
|
|
||||||
This repository contains assorted example projects for libopencm3.
|
|
||||||
|
|
||||||
The libopencm3 project aims to create an open-source firmware library for
|
|
||||||
various ARM Cortex-M microcontrollers.
|
|
||||||
|
|
||||||
For more information visit http://libopencm3.org
|
|
||||||
|
|
||||||
The examples are meant as starting points for different subsystems on multitude
|
|
||||||
of platforms. If you're just looking to test your build environment and hardware,
|
|
||||||
the [libopencm3-miniblink](https://github.com/libopencm3/libopencm3-miniblink)
|
|
||||||
may be more useful, as it covers _many_ more boards, but it is much more limited.
|
|
||||||
|
|
||||||
Feel free to add new examples and send them to us either via the mailinglist or
|
|
||||||
preferably via a github pull request.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
You _must_ run "make" in the top level directory first. This builds the
|
|
||||||
library and all examples. If you're simply hacking on a single example after
|
|
||||||
that, you can type "make clean; make" in any of the individual project
|
|
||||||
directories later.
|
|
||||||
|
|
||||||
For more verbose output, to see compiler command lines, use "make V=1"
|
|
||||||
For insanity levels of verboseness, use "make V=99"
|
|
||||||
|
|
||||||
The makefiles are generally useable for your own projects with
|
|
||||||
only minimal changes for the libopencm3 install path (See Reuse)
|
|
||||||
|
|
||||||
## Make Flash Target
|
|
||||||
|
|
||||||
Please note, the "make flash" target is complicated and not always self-consistent. Please see: https://github.com/libopencm3/libopencm3-examples/issues/34
|
|
||||||
|
|
||||||
For flashing the 'miniblink' example (after you built libopencm3 and the
|
|
||||||
examples by typing 'make' at the top-level directory) onto the Olimex
|
|
||||||
STM32-H103 eval board (ST STM32F1 series microcontroller), you can execute:
|
|
||||||
|
|
||||||
cd examples/stm32/f1/stm32-h103/miniblink
|
|
||||||
make flash V=1
|
|
||||||
|
|
||||||
The Makefiles of the examples are configured to use a certain OpenOCD
|
|
||||||
flash programmer, you might need to change some of the variables in the
|
|
||||||
Makefile if you use a different one.
|
|
||||||
|
|
||||||
To program via a Black Magic Probe, simply provide the serial port, eg:
|
|
||||||
|
|
||||||
cd examples/stm32/f1/stm32-h103/miniblink
|
|
||||||
make flash BMP_PORT=/dev/ttyACM0
|
|
||||||
|
|
||||||
To program via texane/stlink (st-flash utility), use the special target:
|
|
||||||
|
|
||||||
cd examples/stm32/f1/stm32vl-discovery/miniblink
|
|
||||||
make miniblink.stlink-flash
|
|
||||||
|
|
||||||
If you rather use GDB to connect to the st-util you can provide the STLINK\_PORT
|
|
||||||
to the flash target.
|
|
||||||
|
|
||||||
cd examples/stm32/f1/stm32vl-discovery/miniblink
|
|
||||||
make flash STLINK_PORT=:4242
|
|
||||||
|
|
||||||
## Flashing Manually
|
|
||||||
You can also flash manually. Using a miriad of different tools depending on
|
|
||||||
your setup. Here are a few examples.
|
|
||||||
|
|
||||||
### OpenOCD
|
|
||||||
|
|
||||||
openocd -f interface/jtagkey-tiny.cfg -f target/stm32f1x.cfg
|
|
||||||
telnet localhost 4444
|
|
||||||
reset halt
|
|
||||||
flash write_image erase foobar.hex
|
|
||||||
reset
|
|
||||||
|
|
||||||
Replace the "jtagkey-tiny.cfg" with whatever JTAG device you are using, and/or
|
|
||||||
replace "stm32f1x.cfg" with your respective config file. Replace "foobar.hex"
|
|
||||||
with the file name of the image you want to flash.
|
|
||||||
|
|
||||||
### Black Magic Probe
|
|
||||||
|
|
||||||
cd examples/stm32/f1/stm32vl-discovery/miniblink
|
|
||||||
arm-none-eabi-gdb miniblink.elf
|
|
||||||
target extended_remote /dev/ttyACM0
|
|
||||||
monitor swdp_scan
|
|
||||||
attach 1
|
|
||||||
load
|
|
||||||
run
|
|
||||||
|
|
||||||
To exit the gdb session type `<Ctrl>-C` and `<Ctrl>-D`. It is useful to add the
|
|
||||||
following to the .gdbinit to make the flashing and debugging easier:
|
|
||||||
|
|
||||||
set target-async on
|
|
||||||
set confirm off
|
|
||||||
set mem inaccessible-by-default off
|
|
||||||
#set debug remote 1
|
|
||||||
tar ext /dev/ttyACM0
|
|
||||||
mon version
|
|
||||||
mon swdp_scan
|
|
||||||
att 1
|
|
||||||
|
|
||||||
Having this in your .gdbinit boils down the flashing/debugging process to:
|
|
||||||
|
|
||||||
cd examples/stm32/f1/stm32vl-discovery/miniblink
|
|
||||||
arm-none-eabi-gdb miniblink.elf
|
|
||||||
load
|
|
||||||
run
|
|
||||||
|
|
||||||
### ST-Link (st-util)
|
|
||||||
|
|
||||||
This example uses the st-util by texane that you can find on [GitHub](https://github.com/texane/stlink).
|
|
||||||
|
|
||||||
cd examples/stm32/f1/stm32vl-discovery/miniblink
|
|
||||||
arm-none-eabi-gdb miniblink.elf
|
|
||||||
target extended-remote :4242
|
|
||||||
load
|
|
||||||
run
|
|
||||||
|
|
||||||
## Reuse
|
|
||||||
|
|
||||||
If you want to use libopencm3 in your own project, the _easiest_ way is
|
|
||||||
to use the template repository we created for this purpose.
|
|
||||||
|
|
||||||
See https://github.com/libopencm3/libopencm3-template
|
|
||||||
|
|
||||||
137
examples/lm3s/Makefile.include
Normal file
137
examples/lm3s/Makefile.include
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
##
|
||||||
|
## 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
|
||||||
|
|
||||||
|
TOOLCHAIN_DIR ?= ../../../../libopencm3
|
||||||
|
ifeq ($(wildcard ../../../../libopencm3/lib/libopencm3_lm3s.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
|
||||||
|
|
||||||
|
CFLAGS += -O0 -g3 \
|
||||||
|
-Wall -Wextra -Wimplicit-function-declaration \
|
||||||
|
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
||||||
|
-Wundef -Wshadow \
|
||||||
|
-I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
|
-mcpu=cortex-m3 -mthumb -MD -DLM3S
|
||||||
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
||||||
|
OBJS += $(BINARY).o
|
||||||
|
|
||||||
|
OOCD ?= openocd
|
||||||
|
OOCD_INTERFACE ?= flossjtag
|
||||||
|
OOCD_BOARD ?= olimex_stm32_h103
|
||||||
|
# FIXME
|
||||||
|
|
||||||
|
# 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_lm3s.a
|
||||||
|
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
|
||||||
|
$(Q)$(LD) $(LDFLAGS) -o $(*).elf $(OBJS) -lopencm3_lm3s
|
||||||
|
|
||||||
|
%.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
|
||||||
|
|
||||||
|
# FIXME: Replace STM32 stuff with proper LPC13XX OpenOCD support later.
|
||||||
|
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 "stm32x 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 "stm32x mass_erase 0" \
|
||||||
|
-c "flash write_image $(*).hex" \
|
||||||
|
-c "reset" \
|
||||||
|
-c "shutdown" $(NULL)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: images clean
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
@@ -27,4 +27,5 @@ MEMORY
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Include the common ld script. */
|
/* Include the common ld script. */
|
||||||
INCLUDE cortex-m-generic.ld
|
INCLUDE libopencm3_lm3s.ld
|
||||||
|
|
||||||
@@ -22,3 +22,4 @@ BINARY = miniblink
|
|||||||
LDSCRIPT = ../lm3s3748-evb.ld
|
LDSCRIPT = ../lm3s3748-evb.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
|
||||||
9
examples/lm3s/lm3s3748-evb/miniblink/README
Normal file
9
examples/lm3s/lm3s3748-evb/miniblink/README
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is the smallest-possible example program using libopencm3.
|
||||||
|
|
||||||
|
It's intended for the LuminaryMicro LM3S3748-EVB.
|
||||||
|
It should blink the STATUS LED on the board.
|
||||||
|
|
||||||
124
examples/lm4f/Makefile.include
Normal file
124
examples/lm4f/Makefile.include
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
##
|
||||||
|
## 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>
|
||||||
|
## Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
|
||||||
|
##
|
||||||
|
## This library is free software: you can redistribute it and/or modify
|
||||||
|
## it undebipr 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
|
||||||
|
CC = $(PREFIX)-gcc
|
||||||
|
LD = $(PREFIX)-gcc
|
||||||
|
OBJCOPY = $(PREFIX)-objcopy
|
||||||
|
OBJDUMP = $(PREFIX)-objdump
|
||||||
|
|
||||||
|
TOOLCHAIN_DIR ?= ../../../../libopencm3
|
||||||
|
ifeq ($(wildcard ../../../../libopencm3/lib/libopencm3_lm4f.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-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||||
|
CFLAGS += -O0 -g3 \
|
||||||
|
-Wall -Wextra -Wimplicit-function-declaration \
|
||||||
|
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
||||||
|
-Wundef -Wshadow \
|
||||||
|
-I$(TOOLCHAIN_DIR)/include \
|
||||||
|
-fno-common $(ARCH_FLAGS) -MD -DLM4F
|
||||||
|
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)
|
||||||
|
|
||||||
|
OBJS += $(BINARY).o
|
||||||
|
|
||||||
|
# Support for ICDI is available starting with openocd 0.7.0
|
||||||
|
OOCD ?= openocd
|
||||||
|
OOCD_BOARD ?= ek-lm4f120xl
|
||||||
|
|
||||||
|
# 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_lm4f.a
|
||||||
|
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
|
||||||
|
$(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_lm4f $(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
|
||||||
|
|
||||||
|
# FIXME: Replace STM32 stuff with proper Stellaris support.
|
||||||
|
%.flash: %.hex
|
||||||
|
@printf " FLASH $<\n"
|
||||||
|
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
|
||||||
|
$(Q)$(OOCD) -f board/$(OOCD_BOARD).cfg \
|
||||||
|
-c "init" -c "reset init" \
|
||||||
|
-c "flash write_image erase $(*).hex 0" \
|
||||||
|
-c "reset" \
|
||||||
|
-c "shutdown" $(NULL)
|
||||||
|
|
||||||
|
.PHONY: images clean
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
@@ -27,4 +27,5 @@ MEMORY
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Include the common ld script. */
|
/* Include the common ld script. */
|
||||||
INCLUDE cortex-m-generic.ld
|
INCLUDE libopencm3_lm4f.ld
|
||||||
|
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = miniblink
|
BINARY = miniblink
|
||||||
OOCD_FILE = board/ek-lm4f120xl.cfg
|
|
||||||
LDSCRIPT = ../ek-lm4f120xl.ld
|
LDSCRIPT = ../ek-lm4f120xl.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
# README
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
This example demonstrates the following:
|
This example demonstrates the following:
|
||||||
* Configuriong GPIO pins
|
* Configuriong GPIO pins
|
||||||
@@ -16,3 +18,5 @@ Pressing SW1 bypasses the PLL completely, and runs off the raw 16MHz clock
|
|||||||
provided by the external crystal oscillator.
|
provided by the external crystal oscillator.
|
||||||
The LEDs will toggle at different speeds, depending on the system clock. The
|
The LEDs will toggle at different speeds, depending on the system clock. The
|
||||||
system clock changes are handled within the interrupt service routine.
|
system clock changes are handled within the interrupt service routine.
|
||||||
|
|
||||||
|
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = uart_echo_interrupt
|
BINARY = uart_echo_interrupt
|
||||||
OOCD_FILE = board/ek-lm4f120xl.cfg
|
|
||||||
LDSCRIPT = ../ek-lm4f120xl.ld
|
LDSCRIPT = ../ek-lm4f120xl.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
# README
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
This example demonstrates the ease of setting up the UART with libopencm3, and
|
This example demonstrates the ease of setting up the UART with libopencm3, and
|
||||||
using UART interrupts. UART echo is achieved by echoing back received characters
|
using UART interrupts. UART echo is achieved by echoing back received characters
|
||||||
@@ -13,4 +15,4 @@ necessary to test this example. Just connect the debug USB cable and use a
|
|||||||
terminal program to open the ACM port with 921600-8N1.
|
terminal program to open the ACM port with 921600-8N1.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
picocom /dev/ttyACM0 -b921600
|
$ picocom /dev/ttyACM0 -b921600
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
BINARY = uart_echo_simple
|
BINARY = uart_echo_simple
|
||||||
OOCD_FILE = board/ek-lm4f120xl.cfg
|
|
||||||
LDSCRIPT = ../ek-lm4f120xl.ld
|
LDSCRIPT = ../ek-lm4f120xl.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
# README
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
This example demonstrates the ease of setting up the UART with libopencm3.
|
This example demonstrates the ease of setting up the UART with libopencm3.
|
||||||
Basic UART echo is achieved by using blocking reads and writes. The UART is set
|
Basic UART echo is achieved by using blocking reads and writes. The UART is set
|
||||||
@@ -9,4 +11,4 @@ necessary to test this example. Just connect the debug USB cable and use a
|
|||||||
terminal program to open the ACM port with 921600-8N1.
|
terminal program to open the ACM port with 921600-8N1.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
picocom /dev/ttyACM0 -b921600
|
$ picocom /dev/ttyACM0 -b921600
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
##
|
|
||||||
## 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/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
LIBNAME = opencm3_lpc13xx
|
|
||||||
DEFS += -DLPC13XX
|
|
||||||
|
|
||||||
FP_FLAGS ?= -msoft-float
|
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# OpenOCD specific variables
|
|
||||||
|
|
||||||
OOCD ?= openocd
|
|
||||||
OOCD_INTERFACE ?= flossjtag
|
|
||||||
OOCD_TARGET ?= lpc13xx
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Black Magic Probe specific variables
|
|
||||||
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
|
||||||
BMP_PORT ?=
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# texane/stlink specific variables
|
|
||||||
#STLINK_PORT ?= :4242
|
|
||||||
|
|
||||||
|
|
||||||
include ../../../../rules.mk
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This is the smallest-possible example program using libopencm3.
|
|
||||||
|
|
||||||
It's intended for the NXP LPC1343-based
|
|
||||||
[Olimex LPC-1343 eval board](http://olimex.com/dev/lpc-p1343.html for details).
|
|
||||||
It should blink a LED on the board.
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
##
|
|
||||||
## 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/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
|
|
||||||
LIBNAME = opencm3_lpc17xx
|
|
||||||
DEFS += -DLPC17XX
|
|
||||||
|
|
||||||
FP_FLAGS ?= -msoft-float
|
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# OpenOCD specific variables
|
|
||||||
|
|
||||||
OOCD ?= openocd
|
|
||||||
OOCD_INTERFACE ?= flossjtag
|
|
||||||
OOCD_TARGET ?= lpc17xx
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Black Magic Probe specific variables
|
|
||||||
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
|
||||||
BMP_PORT ?=
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# texane/stlink specific variables
|
|
||||||
#STLINK_PORT ?= :4242
|
|
||||||
|
|
||||||
|
|
||||||
include ../../../../rules.mk
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This is the smallest-possible example program using libopencm3.
|
|
||||||
|
|
||||||
It's intended for the NXP LPC1768-based
|
|
||||||
[NGX Blueboard-LPC1768-H eval board](http://shop.ngxtechnologies.com/product_info.php?cPath=21&products_id=65).
|
|
||||||
It should blink a LED on the board.
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
##
|
|
||||||
## 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>
|
|
||||||
## 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/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
|
|
||||||
LIBNAME = opencm3_lpc43xx
|
|
||||||
DEFS += -DLPC43XX
|
|
||||||
|
|
||||||
FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 $(FP_FLAGS)
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# OpenOCD specific variables
|
|
||||||
|
|
||||||
OOCD ?= openocd
|
|
||||||
OOCD_INTERFACE ?= flossjtag
|
|
||||||
OOCD_TARGET ?= lpc4357
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Black Magic Probe specific variables
|
|
||||||
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
|
||||||
BMP_PORT ?=
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# texane/stlink specific variables
|
|
||||||
#STLINK_PORT ?= :4242
|
|
||||||
|
|
||||||
|
|
||||||
include ../../../../rules.mk
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
These example programs are written for the
|
|
||||||
[Diolan LPC-4350-DB1](http://www.diolan.com/lpc4350-features.html)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This is the smallest-possible example program using libopencm3.
|
|
||||||
|
|
||||||
It's intended for the [Diolan LPC-4350-DB1](http://www.diolan.com/lpc4350-features.html).
|
|
||||||
|
|
||||||
It should blink D2 on the board.
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This program exercises the I2C peripheral on Jellybean's LPC43xx. You can
|
|
||||||
scope SCL on P6 pin 3 and SDA on P6 pin 5. If Lemondrop is connected, LED1
|
|
||||||
will illuminate if I2C communication to the Si5351C on Lemondrop is successful.
|
|
||||||
|
|
||||||
Required Lemondrop -> Jellybean connections:
|
|
||||||
|
|
||||||
SCL: Lemondrop P7 pin 3 -> Jellybean P6 pin 3
|
|
||||||
SDA: Lemondrop P7 pin 5 -> Jellybean P6 pin 5
|
|
||||||
VCC: Lemondrop P4 pin 2, 4, or 6 -> Jellybean P17 pin 2, 4, or 6
|
|
||||||
1V8: Lemondrop P11 pin 2, 4, or 6 -> Jellybean P16 pin 2, 4, or 6
|
|
||||||
GND: Lemondrop P5 -> Jellybean P13
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This is the smallest-possible example program using libopencm3.
|
|
||||||
|
|
||||||
It's intended for the Jellybean development board from the
|
|
||||||
[HackRF project](https://github.com/mossmann/hackrf)
|
|
||||||
|
|
||||||
It should blink LED1 on the board.
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This is the smallest-possible example program using libopencm3.
|
|
||||||
|
|
||||||
It's intended for the Jellybean development board from the
|
|
||||||
[HackRF project](https://github.com/mossmann/hackrf)
|
|
||||||
|
|
||||||
It should blink LED1 on the board.
|
|
||||||
This example copy the Code from ROM to RAM and execute code from RAM.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This program exercises the SSP1 peripheral on Jellybean's LPC43xx.
|
|
||||||
|
|
||||||
Jellybean (connector)
|
|
||||||
P9 SPI
|
|
||||||
|-----------------|
|
|
||||||
| Pin2 Pin4 Pin6 |
|
|
||||||
||------| |
|
|
||||||
|| Pin1 |Pin3 Pin5 |
|
|
||||||
||------|----------|
|
|
||||||
|-------|
|
|
||||||
|
|
||||||
SSP1_MISO: Jellybean P9 SPI Pin6
|
|
||||||
SSP1_MOSI: Jellybean P9 SPI Pin4
|
|
||||||
SSP1_SCK: Jellybean P9 SPI Pin2
|
|
||||||
SSP1_SSEL: Jellybean P9 SPI Pin3
|
|
||||||
GND: Can be connected to P12 SD Pin1
|
|
||||||
|
|
||||||
PCLK clock source is PLL1 288MHz (from IRC 96MHz boot from SPIFI)
|
|
||||||
Freq = PCLK / (CPSDVSR * [SCR+1]).
|
|
||||||
|
|
||||||
By default (CPSDVSR=0 => Means MAX Divisor)
|
|
||||||
SSP1->CR0->SCR = 0x00 => CLK Freq 1.126MHz
|
|
||||||
SSP1->CR0->SCR = 0x01 => MOSI Freq 566.9KHz
|
|
||||||
...
|
|
||||||
|
|
||||||
_Test Oscilloscpe_:
|
|
||||||
SCR=0, CPSDVSR=32 => CLK 9.025MHz
|
|
||||||
SCR=1, CPSDVSR=2 => CLK 73MHz
|
|
||||||
SCR=2, CPSDVSR=2 => CLK 49MHz
|
|
||||||
SCR=4, CPSDVSR=2 => CLK 29MHz
|
|
||||||
SCR=8, CPSDVSR=2 => CLK 16MHz
|
|
||||||
SCR=16, CPSDVSR=2 => CLK 8.5MHz
|
|
||||||
SCR=32, CPSDVSR=2 => CLK 4.386MHz
|
|
||||||
SCR=64, CPSDVSR=2 => CLK 2.227MHz
|
|
||||||
SCR=1, CPSDVSR=64 => CLK 2.262MHz
|
|
||||||
|
|
||||||
_Theory_:
|
|
||||||
SCR=0, CPSDVSR=32 => 288MHz / (32*(0+1) = 9MHz
|
|
||||||
SCR=1, CPSDVSR=2 => 288MHz / (2*(1+1) = 72MHz
|
|
||||||
SCR=4, CPSDVSR=2 => 288MHz / (2*(4+1) = 28.8MHz
|
|
||||||
SCR=32, CPSDVSR=2 => 288MHz / (2*(32+1) = 4.364MHz
|
|
||||||
SCR=64, CPSDVSR=2 => 288MHz / (2*(64+1)) = 2.2154MHz
|
|
||||||
SCR=128, CPSDVSR=2 => 288MHz / (2*(128+1)) = 1.116MHz
|
|
||||||
SCR=1, CPSDVSR=64 => 288MHz / (64*(1+1)) = 2.25MHz
|
|
||||||
137
examples/lpc13xx/Makefile.include
Normal file
137
examples/lpc13xx/Makefile.include
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
##
|
||||||
|
## 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
|
||||||
|
|
||||||
|
TOOLCHAIN_DIR ?= ../../../../libopencm3
|
||||||
|
ifeq ($(wildcard ../../../../libopencm3/lib/libopencm3_lpc13xx.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
|
||||||
|
|
||||||
|
CFLAGS += -Os -g \
|
||||||
|
-Wall -Wextra -Wimplicit-function-declaration \
|
||||||
|
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
||||||
|
-Wundef -Wshadow \
|
||||||
|
-I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
|
-mcpu=cortex-m3 -mthumb -MD -DLPC13XX
|
||||||
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
||||||
|
OBJS += $(BINARY).o
|
||||||
|
|
||||||
|
OOCD ?= openocd
|
||||||
|
OOCD_INTERFACE ?= flossjtag
|
||||||
|
OOCD_BOARD ?= olimex_stm32_h103
|
||||||
|
# FIXME
|
||||||
|
|
||||||
|
# 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_lpc13xx.a
|
||||||
|
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
|
||||||
|
$(Q)$(LD) $(LDFLAGS) -o $(*).elf $(OBJS) -lopencm3_lpc13xx
|
||||||
|
|
||||||
|
%.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
|
||||||
|
|
||||||
|
# FIXME: Replace STM32 stuff with proper LPC13XX OpenOCD support later.
|
||||||
|
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 "stm32x 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 "stm32x mass_erase 0" \
|
||||||
|
-c "flash write_image $(*).hex" \
|
||||||
|
-c "reset" \
|
||||||
|
-c "shutdown" $(NULL)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: images clean
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
@@ -27,4 +27,5 @@ MEMORY
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Include the common ld script. */
|
/* Include the common ld script. */
|
||||||
INCLUDE cortex-m-generic.ld
|
INCLUDE libopencm3_lpc13xx.ld
|
||||||
|
|
||||||
@@ -22,3 +22,4 @@ BINARY = miniblink
|
|||||||
LDSCRIPT = ../lpc-p1343.ld
|
LDSCRIPT = ../lpc-p1343.ld
|
||||||
|
|
||||||
include ../../Makefile.include
|
include ../../Makefile.include
|
||||||
|
|
||||||
10
examples/lpc13xx/lpc-p1343/miniblink/README
Normal file
10
examples/lpc13xx/lpc-p1343/miniblink/README
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is the smallest-possible example program using libopencm3.
|
||||||
|
|
||||||
|
It's intended for the NXP LPC1343-based Olimex LPC-1343 eval board (see
|
||||||
|
http://olimex.com/dev/lpc-p1343.html for details). It should blink
|
||||||
|
a LED on the board.
|
||||||
|
|
||||||
137
examples/lpc17xx/Makefile.include
Normal file
137
examples/lpc17xx/Makefile.include
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
##
|
||||||
|
## 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
|
||||||
|
|
||||||
|
TOOLCHAIN_DIR ?= ../../../../libopencm3
|
||||||
|
ifeq ($(wildcard ../../../../libopencm3/lib/libopencm3_lpc17xx.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
|
||||||
|
|
||||||
|
CFLAGS += -O0 -g \
|
||||||
|
-Wall -Wextra -Wimplicit-function-declaration \
|
||||||
|
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
||||||
|
-Wundef -Wshadow \
|
||||||
|
-I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
|
-mcpu=cortex-m3 -mthumb -MD -DLPC17XX
|
||||||
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
||||||
|
OBJS += $(BINARY).o
|
||||||
|
|
||||||
|
OOCD ?= openocd
|
||||||
|
OOCD_INTERFACE ?= flossjtag
|
||||||
|
OOCD_BOARD ?= olimex_stm32_h103
|
||||||
|
# FIXME
|
||||||
|
|
||||||
|
# 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_lpc17xx.a
|
||||||
|
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
|
||||||
|
$(Q)$(LD) $(LDFLAGS) -o $(*).elf $(OBJS) -lopencm3_lpc17xx
|
||||||
|
|
||||||
|
%.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
|
||||||
|
|
||||||
|
# FIXME: Replace STM32 stuff with proper LPC13XX OpenOCD support later.
|
||||||
|
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 "stm32x 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 "stm32x mass_erase 0" \
|
||||||
|
-c "flash write_image $(*).hex" \
|
||||||
|
-c "reset" \
|
||||||
|
-c "shutdown" $(NULL)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: images clean
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
@@ -29,4 +29,4 @@ MEMORY
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Include the common ld script. */
|
/* Include the common ld script. */
|
||||||
INCLUDE cortex-m-generic.ld
|
INCLUDE libopencm3_lpc17xx.ld
|
||||||
9
examples/lpc17xx/blueboard-lpc1768-h/miniblink/README
Normal file
9
examples/lpc17xx/blueboard-lpc1768-h/miniblink/README
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is the smallest-possible example program using libopencm3.
|
||||||
|
|
||||||
|
It's intended for the NXP LPC1768-based NGX Blueboard-LPC1768-H eval board (see
|
||||||
|
http://shop.ngxtechnologies.com/product_info.php?cPath=21&products_id=65). It should blink
|
||||||
|
a LED on the board.
|
||||||
140
examples/lpc43xx/Makefile.include
Normal file
140
examples/lpc43xx/Makefile.include
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
##
|
||||||
|
## 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>
|
||||||
|
## 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/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
PREFIX ?= arm-none-eabi
|
||||||
|
#PREFIX ?= arm-elf
|
||||||
|
CC = $(PREFIX)-gcc
|
||||||
|
LD = $(PREFIX)-gcc
|
||||||
|
OBJCOPY = $(PREFIX)-objcopy
|
||||||
|
OBJDUMP = $(PREFIX)-objdump
|
||||||
|
GDB = $(PREFIX)-gdb
|
||||||
|
|
||||||
|
TOOLCHAIN_DIR ?= ../../../../libopencm3
|
||||||
|
ifeq ($(wildcard ../../../../libopencm3/lib/libopencm3_lpc43xx.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
|
||||||
|
|
||||||
|
CFLAGS += -O2 -g \
|
||||||
|
-Wall -Wextra -Wimplicit-function-declaration \
|
||||||
|
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
||||||
|
-Wundef -Wshadow \
|
||||||
|
-I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||||
|
-mcpu=cortex-m4 -mthumb -MD \
|
||||||
|
-mfloat-abi=hard -mfpu=fpv4-sp-d16 -DLPC43XX
|
||||||
|
LDSCRIPT ?= $(BINARY).ld
|
||||||
|
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib \
|
||||||
|
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections -Xlinker -Map=$(BINARY).map
|
||||||
|
OBJS += $(BINARY).o
|
||||||
|
|
||||||
|
OOCD ?= openocd
|
||||||
|
OOCD_INTERFACE ?= flossjtag
|
||||||
|
OOCD_BOARD ?= olimex_stm32_h103
|
||||||
|
|
||||||
|
# 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_lpc43xx.a
|
||||||
|
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
|
||||||
|
$(Q)$(LD) $(LDFLAGS) -o $(*).elf $(OBJS) -lopencm3_lpc43xx
|
||||||
|
|
||||||
|
%.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
|
||||||
|
$(Q)rm -f *.map
|
||||||
|
|
||||||
|
# FIXME: Replace STM32 stuff with proper LPC43XX OpenOCD support later.
|
||||||
|
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 "stm32x 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 "stm32x mass_erase 0" \
|
||||||
|
-c "flash write_image $(*).hex" \
|
||||||
|
-c "reset" \
|
||||||
|
-c "shutdown" $(NULL)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: images clean
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
3
examples/lpc43xx/diolan-lpc-4350-db1/README
Normal file
3
examples/lpc43xx/diolan-lpc-4350-db1/README
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
These example programs are written for the Diolan LPC-4350-DB1:
|
||||||
|
|
||||||
|
http://www.diolan.com/lpc4350-features.html
|
||||||
11
examples/lpc43xx/diolan-lpc-4350-db1/miniblink/README
Normal file
11
examples/lpc43xx/diolan-lpc-4350-db1/miniblink/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is the smallest-possible example program using libopencm3.
|
||||||
|
|
||||||
|
It's intended for the Diolan LPC-4350-DB1:
|
||||||
|
|
||||||
|
http://www.diolan.com/lpc4350-features.html
|
||||||
|
|
||||||
|
It should blink D2 on the board.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
These example programs are written for the Jellybean development board from the
|
These example programs are written for the Jellybean development board from the
|
||||||
[HackRF project](https://github.com/mossmann/hackrf)
|
HackRF project:
|
||||||
|
|
||||||
|
https://github.com/mossmann/hackrf
|
||||||
15
examples/lpc43xx/hackrf-jellybean/i2c/README
Normal file
15
examples/lpc43xx/hackrf-jellybean/i2c/README
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This program exercises the I2C peripheral on Jellybean's LPC43xx. You can
|
||||||
|
scope SCL on P6 pin 3 and SDA on P6 pin 5. If Lemondrop is connected, LED1
|
||||||
|
will illuminate if I2C communication to the Si5351C on Lemondrop is successful.
|
||||||
|
|
||||||
|
Required Lemondrop -> Jellybean connections:
|
||||||
|
|
||||||
|
SCL: Lemondrop P7 pin 3 -> Jellybean P6 pin 3
|
||||||
|
SDA: Lemondrop P7 pin 5 -> Jellybean P6 pin 5
|
||||||
|
VCC: Lemondrop P4 pin 2, 4, or 6 -> Jellybean P17 pin 2, 4, or 6
|
||||||
|
1V8: Lemondrop P11 pin 2, 4, or 6 -> Jellybean P16 pin 2, 4, or 6
|
||||||
|
GND: Lemondrop P5 -> Jellybean P13
|
||||||
11
examples/lpc43xx/hackrf-jellybean/miniblink/README
Normal file
11
examples/lpc43xx/hackrf-jellybean/miniblink/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is the smallest-possible example program using libopencm3.
|
||||||
|
|
||||||
|
It's intended for the Jellybean development board from the HackRF project:
|
||||||
|
|
||||||
|
https://github.com/mossmann/hackrf
|
||||||
|
|
||||||
|
It should blink LED1 on the board.
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is the smallest-possible example program using libopencm3.
|
||||||
|
|
||||||
|
It's intended for the Jellybean development board from the HackRF project:
|
||||||
|
|
||||||
|
https://github.com/mossmann/hackrf
|
||||||
|
|
||||||
|
It should blink LED1 on the board.
|
||||||
|
This example copy the Code from ROM to RAM and execute code from RAM.
|
||||||
48
examples/lpc43xx/hackrf-jellybean/ssp/README
Normal file
48
examples/lpc43xx/hackrf-jellybean/ssp/README
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This program exercises the SSP1 peripheral on Jellybean's LPC43xx.
|
||||||
|
|
||||||
|
Jellybean (connector)
|
||||||
|
P9 SPI
|
||||||
|
|-----------------|
|
||||||
|
| Pin2 Pin4 Pin6 |
|
||||||
|
||------| |
|
||||||
|
|| Pin1 |Pin3 Pin5 |
|
||||||
|
||------|----------|
|
||||||
|
|-------|
|
||||||
|
|
||||||
|
SSP1_MISO: Jellybean P9 SPI Pin6
|
||||||
|
SSP1_MOSI: Jellybean P9 SPI Pin4
|
||||||
|
SSP1_SCK: Jellybean P9 SPI Pin2
|
||||||
|
SSP1_SSEL: Jellybean P9 SPI Pin3
|
||||||
|
GND: Can be connected to P12 SD Pin1
|
||||||
|
|
||||||
|
PCLK clock source is PLL1 288MHz (from IRC 96MHz boot from SPIFI)
|
||||||
|
Freq = PCLK / (CPSDVSR * [SCR+1]).
|
||||||
|
|
||||||
|
By default (CPSDVSR=0 => Means MAX Divisor)
|
||||||
|
SSP1->CR0->SCR = 0x00 => CLK Freq 1.126MHz
|
||||||
|
SSP1->CR0->SCR = 0x01 => MOSI Freq 566.9KHz
|
||||||
|
...
|
||||||
|
|
||||||
|
Test Oscilloscpe:
|
||||||
|
SCR=0, CPSDVSR=32 => CLK 9.025MHz
|
||||||
|
SCR=1, CPSDVSR=2 => CLK 73MHz
|
||||||
|
SCR=2, CPSDVSR=2 => CLK 49MHz
|
||||||
|
SCR=4, CPSDVSR=2 => CLK 29MHz
|
||||||
|
SCR=8, CPSDVSR=2 => CLK 16MHz
|
||||||
|
SCR=16, CPSDVSR=2 => CLK 8.5MHz
|
||||||
|
SCR=32, CPSDVSR=2 => CLK 4.386MHz
|
||||||
|
SCR=64, CPSDVSR=2 => CLK 2.227MHz
|
||||||
|
SCR=1, CPSDVSR=64 => CLK 2.262MHz
|
||||||
|
|
||||||
|
Theory:
|
||||||
|
SCR=0, CPSDVSR=32 => 288MHz / (32*(0+1) = 9MHz
|
||||||
|
SCR=1, CPSDVSR=2 => 288MHz / (2*(1+1) = 72MHz
|
||||||
|
SCR=4, CPSDVSR=2 => 288MHz / (2*(4+1) = 28.8MHz
|
||||||
|
SCR=32, CPSDVSR=2 => 288MHz / (2*(32+1) = 4.364MHz
|
||||||
|
SCR=64, CPSDVSR=2 => 288MHz / (2*(64+1)) = 2.2154MHz
|
||||||
|
SCR=128, CPSDVSR=2 => 288MHz / (2*(128+1)) = 1.116MHz
|
||||||
|
SCR=1, CPSDVSR=64 => 288MHz / (64*(1+1)) = 2.25MHz
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
# README
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
This program exercises the SysTick Interrupt of ARM CortexM4 on Jellybean's LPC43xx.
|
This program exercises the SysTick Interrupt of ARM CortexM4 on Jellybean's LPC43xx.
|
||||||
It also enable Cycle Counter to be used for accurate delay independant from Clock Frequency.
|
It also enable Cycle Counter to be used for accurate delay independant from Clock Frequency.
|
||||||
@@ -1,270 +0,0 @@
|
|||||||
##
|
|
||||||
## 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>
|
|
||||||
## Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz>
|
|
||||||
##
|
|
||||||
## 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/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
# Be silent per default, but 'make V=1' will show all compiler calls.
|
|
||||||
ifneq ($(V),1)
|
|
||||||
Q := @
|
|
||||||
NULL := 2>/dev/null
|
|
||||||
endif
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Executables
|
|
||||||
|
|
||||||
PREFIX ?= arm-none-eabi-
|
|
||||||
|
|
||||||
CC := $(PREFIX)gcc
|
|
||||||
CXX := $(PREFIX)g++
|
|
||||||
LD := $(PREFIX)gcc
|
|
||||||
AR := $(PREFIX)ar
|
|
||||||
AS := $(PREFIX)as
|
|
||||||
OBJCOPY := $(PREFIX)objcopy
|
|
||||||
OBJDUMP := $(PREFIX)objdump
|
|
||||||
GDB := $(PREFIX)gdb
|
|
||||||
STFLASH = $(shell which st-flash)
|
|
||||||
STYLECHECK := /checkpatch.pl
|
|
||||||
STYLECHECKFLAGS := --no-tree -f --terse --mailback
|
|
||||||
STYLECHECKFILES := $(shell find . -name '*.[ch]')
|
|
||||||
OPT := -Os
|
|
||||||
DEBUG := -ggdb3
|
|
||||||
CSTD ?= -std=c99
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Source files
|
|
||||||
|
|
||||||
OBJS += $(BINARY).o
|
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(strip $(OPENCM3_DIR)),)
|
|
||||||
# user has not specified the library path, so we try to detect it
|
|
||||||
|
|
||||||
# where we search for the library
|
|
||||||
LIBPATHS := ./libopencm3 ../../../../libopencm3 ../../../../../libopencm3
|
|
||||||
|
|
||||||
OPENCM3_DIR := $(wildcard $(LIBPATHS:=/locm3.sublime-project))
|
|
||||||
OPENCM3_DIR := $(firstword $(dir $(OPENCM3_DIR)))
|
|
||||||
|
|
||||||
ifeq ($(strip $(OPENCM3_DIR)),)
|
|
||||||
$(warning Cannot find libopencm3 library in the standard search paths.)
|
|
||||||
$(error Please specify it through OPENCM3_DIR variable!)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(V),1)
|
|
||||||
$(info Using $(OPENCM3_DIR) path to library)
|
|
||||||
endif
|
|
||||||
|
|
||||||
define ERR_DEVICE_LDSCRIPT_CONFLICT
|
|
||||||
You can either specify DEVICE=blah, and have the LDSCRIPT generated,
|
|
||||||
or you can provide LDSCRIPT, and ensure CPPFLAGS, LDFLAGS and LDLIBS
|
|
||||||
all contain the correct values for the target you wish to use.
|
|
||||||
You cannot provide both!
|
|
||||||
endef
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEVICE)),)
|
|
||||||
# Old style, assume LDSCRIPT exists
|
|
||||||
DEFS += -I$(OPENCM3_DIR)/include
|
|
||||||
LDFLAGS += -L$(OPENCM3_DIR)/lib
|
|
||||||
LDLIBS += -l$(LIBNAME)
|
|
||||||
LDSCRIPT ?= $(BINARY).ld
|
|
||||||
else
|
|
||||||
# New style, assume device is provided, and we're generating the rest.
|
|
||||||
ifneq ($(strip $(LDSCRIPT)),)
|
|
||||||
$(error $(ERR_DEVICE_LDSCRIPT_CONFLICT))
|
|
||||||
endif
|
|
||||||
include $(OPENCM3_DIR)/mk/genlink-config.mk
|
|
||||||
endif
|
|
||||||
|
|
||||||
OPENCM3_SCRIPT_DIR = $(OPENCM3_DIR)/scripts
|
|
||||||
EXAMPLES_SCRIPT_DIR = $(OPENCM3_DIR)/../scripts
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# C flags
|
|
||||||
|
|
||||||
TGT_CFLAGS += $(OPT) $(CSTD) $(DEBUG)
|
|
||||||
TGT_CFLAGS += $(ARCH_FLAGS)
|
|
||||||
TGT_CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration
|
|
||||||
TGT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
|
|
||||||
TGT_CFLAGS += -fno-common -ffunction-sections -fdata-sections
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# C++ flags
|
|
||||||
|
|
||||||
TGT_CXXFLAGS += $(OPT) $(CXXSTD) $(DEBUG)
|
|
||||||
TGT_CXXFLAGS += $(ARCH_FLAGS)
|
|
||||||
TGT_CXXFLAGS += -Wextra -Wshadow -Wredundant-decls -Weffc++
|
|
||||||
TGT_CXXFLAGS += -fno-common -ffunction-sections -fdata-sections
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# C & C++ preprocessor common flags
|
|
||||||
|
|
||||||
TGT_CPPFLAGS += -MD
|
|
||||||
TGT_CPPFLAGS += -Wall -Wundef
|
|
||||||
TGT_CPPFLAGS += $(DEFS)
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Linker flags
|
|
||||||
|
|
||||||
TGT_LDFLAGS += --static -nostartfiles
|
|
||||||
TGT_LDFLAGS += -T$(LDSCRIPT)
|
|
||||||
TGT_LDFLAGS += $(ARCH_FLAGS) $(DEBUG)
|
|
||||||
TGT_LDFLAGS += -Wl,-Map=$(*).map -Wl,--cref
|
|
||||||
TGT_LDFLAGS += -Wl,--gc-sections
|
|
||||||
ifeq ($(V),99)
|
|
||||||
TGT_LDFLAGS += -Wl,--print-gc-sections
|
|
||||||
endif
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Used libraries
|
|
||||||
|
|
||||||
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
###############################################################################
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
.SUFFIXES: .elf .bin .hex .srec .list .map .images
|
|
||||||
.SECONDEXPANSION:
|
|
||||||
.SECONDARY:
|
|
||||||
|
|
||||||
all: elf
|
|
||||||
|
|
||||||
elf: $(BINARY).elf
|
|
||||||
bin: $(BINARY).bin
|
|
||||||
hex: $(BINARY).hex
|
|
||||||
srec: $(BINARY).srec
|
|
||||||
list: $(BINARY).list
|
|
||||||
GENERATED_BINARIES=$(BINARY).elf $(BINARY).bin $(BINARY).hex $(BINARY).srec $(BINARY).list $(BINARY).map
|
|
||||||
|
|
||||||
images: $(BINARY).images
|
|
||||||
flash: $(BINARY).flash
|
|
||||||
|
|
||||||
# Either verify the user provided LDSCRIPT exists, or generate it.
|
|
||||||
ifeq ($(strip $(DEVICE)),)
|
|
||||||
$(LDSCRIPT):
|
|
||||||
ifeq (,$(wildcard $(LDSCRIPT)))
|
|
||||||
$(error Unable to find specified linker script: $(LDSCRIPT))
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
include $(OPENCM3_DIR)/mk/genlink-rules.mk
|
|
||||||
endif
|
|
||||||
|
|
||||||
$(OPENCM3_DIR)/lib/lib$(LIBNAME).a:
|
|
||||||
ifeq (,$(wildcard $@))
|
|
||||||
$(warning $(LIBNAME).a not found, attempting to rebuild in $(OPENCM3_DIR))
|
|
||||||
$(MAKE) -C $(OPENCM3_DIR)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Define a helper macro for debugging make errors online
|
|
||||||
# you can type "make print-OPENCM3_DIR" and it will show you
|
|
||||||
# how that ended up being resolved by all of the included
|
|
||||||
# makefiles.
|
|
||||||
print-%:
|
|
||||||
@echo $*=$($*)
|
|
||||||
|
|
||||||
%.images: %.bin %.hex %.srec %.list %.map
|
|
||||||
@#printf "*** $* images generated ***\n"
|
|
||||||
|
|
||||||
%.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 %.map: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(LIBNAME).a
|
|
||||||
@#printf " LD $(*).elf\n"
|
|
||||||
$(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $(*).elf
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
@#printf " CC $(*).c\n"
|
|
||||||
$(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).c
|
|
||||||
|
|
||||||
%.o: %.cxx
|
|
||||||
@#printf " CXX $(*).cxx\n"
|
|
||||||
$(Q)$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cxx
|
|
||||||
|
|
||||||
%.o: %.cpp
|
|
||||||
@#printf " CXX $(*).cpp\n"
|
|
||||||
$(Q)$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cpp
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@#printf " CLEAN\n"
|
|
||||||
$(Q)$(RM) $(GENERATED_BINARIES) generated.* $(OBJS) $(OBJS:%.o=%.d)
|
|
||||||
|
|
||||||
stylecheck: $(STYLECHECKFILES:=.stylecheck)
|
|
||||||
styleclean: $(STYLECHECKFILES:=.styleclean)
|
|
||||||
|
|
||||||
# the cat is due to multithreaded nature - we like to have consistent chunks of text on the output
|
|
||||||
%.stylecheck: %
|
|
||||||
$(Q)$(OPENCM3_SCRIPT_DIR)$(STYLECHECK) $(STYLECHECKFLAGS) $* > $*.stylecheck; \
|
|
||||||
if [ -s $*.stylecheck ]; then \
|
|
||||||
cat $*.stylecheck; \
|
|
||||||
else \
|
|
||||||
rm -f $*.stylecheck; \
|
|
||||||
fi;
|
|
||||||
|
|
||||||
%.styleclean:
|
|
||||||
$(Q)rm -f $*.stylecheck;
|
|
||||||
|
|
||||||
|
|
||||||
%.stlink-flash: %.bin
|
|
||||||
@printf " FLASH $<\n"
|
|
||||||
$(STFLASH) write $(*).bin 0x8000000
|
|
||||||
|
|
||||||
ifeq ($(BMP_PORT),)
|
|
||||||
ifeq ($(OOCD_FILE),)
|
|
||||||
%.flash: %.elf
|
|
||||||
@printf " FLASH $<\n"
|
|
||||||
(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
|
|
||||||
$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
|
|
||||||
-f target/$(OOCD_TARGET).cfg \
|
|
||||||
-c "program $(*).elf verify reset exit" \
|
|
||||||
$(NULL)
|
|
||||||
else
|
|
||||||
%.flash: %.elf
|
|
||||||
@printf " FLASH $<\n"
|
|
||||||
(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
|
|
||||||
$(OOCD) -f $(OOCD_FILE) \
|
|
||||||
-c "program $(*).elf verify reset exit" \
|
|
||||||
$(NULL)
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
%.flash: %.elf
|
|
||||||
@printf " GDB $(*).elf (flash)\n"
|
|
||||||
$(GDB) --batch \
|
|
||||||
-ex 'target extended-remote $(BMP_PORT)' \
|
|
||||||
-x $(EXAMPLES_SCRIPT_DIR)/black_magic_probe_flash.scr \
|
|
||||||
$(*).elf
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: images clean stylecheck styleclean elf bin hex srec list
|
|
||||||
|
|
||||||
-include $(OBJS:.o=.d)
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
##
|
|
||||||
## This file is part of the libopencm3 project.
|
|
||||||
##
|
|
||||||
## 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/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
# You should use linker script generation! Specify device!
|
|
||||||
ifeq ($(DEVICE),)
|
|
||||||
LIBNAME = opencm3_samd
|
|
||||||
DEFS += -DSAMD
|
|
||||||
FP_FLAGS ?= -msoft-float
|
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m0plus $(FP_FLAGS)
|
|
||||||
endif
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# OpenOCD specific variables
|
|
||||||
|
|
||||||
OOCD ?= openocd
|
|
||||||
OOCD_INTERFACE ?= cmsis-dap
|
|
||||||
OOCD_TARGET ?= at91samdXX
|
|
||||||
|
|
||||||
include ../../../../rules.mk
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
##
|
|
||||||
## This file is part of the libopencm3 project.
|
|
||||||
##
|
|
||||||
## 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
|
|
||||||
DEVICE = samd10d14
|
|
||||||
|
|
||||||
include ../../Makefile.include
|
|
||||||
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
##
|
|
||||||
## 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/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
LIBNAME = opencm3_stm32f0
|
|
||||||
DEFS += -DSTM32F0
|
|
||||||
|
|
||||||
FP_FLAGS ?= -msoft-float
|
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m0 $(FP_FLAGS)
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# OpenOCD specific variables
|
|
||||||
|
|
||||||
OOCD ?= openocd
|
|
||||||
OOCD_INTERFACE ?= stlink-v2-1
|
|
||||||
OOCD_TARGET ?= stm32f0x
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Black Magic Probe specific variables
|
|
||||||
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
|
||||||
BMP_PORT ?=
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# texane/stlink specific variables
|
|
||||||
#STLINK_PORT ?= :4242
|
|
||||||
|
|
||||||
|
|
||||||
include ../../../../rules.mk
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
##
|
|
||||||
## 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 = adc
|
|
||||||
|
|
||||||
LDSCRIPT = ../stm32f0-discovery.ld
|
|
||||||
|
|
||||||
include ../../Makefile.include
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
It's intended for the ST STM32F0DISCOVERY eval board. Measures voltage on the
|
|
||||||
ADC\_IN1 input, and prints it to the serial port.
|
|
||||||
|
|
||||||
## Board connections
|
|
||||||
|
|
||||||
| Port | Function | Description |
|
|
||||||
| ----- | ----------- | --------------------------------- |
|
|
||||||
| `PA1` | `(ADC_IN1)` | Analog input |
|
|
||||||
| `PA9` | `(USART1)` | TTL serial output `(115200,8,N,1)` |
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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>
|
|
||||||
* Modified by Fernando Cortes <fermando.corcam@gmail.com>
|
|
||||||
* modified by Guillermo Rivera <memogrg@gmail.com>
|
|
||||||
* modified by Frantisek Burian <BuFran@seznam.cz>
|
|
||||||
*
|
|
||||||
* 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/rcc.h>
|
|
||||||
#include <libopencm3/stm32/adc.h>
|
|
||||||
#include <libopencm3/stm32/usart.h>
|
|
||||||
#include <libopencm3/stm32/gpio.h>
|
|
||||||
|
|
||||||
uint8_t channel_array[] = { 1, 1, ADC_CHANNEL_TEMP};
|
|
||||||
|
|
||||||
static void adc_setup(void)
|
|
||||||
{
|
|
||||||
rcc_periph_clock_enable(RCC_ADC);
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
|
||||||
|
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0);
|
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
|
|
||||||
|
|
||||||
adc_power_off(ADC1);
|
|
||||||
adc_set_clk_source(ADC1, ADC_CLKSOURCE_ADC);
|
|
||||||
adc_calibrate(ADC1);
|
|
||||||
adc_set_operation_mode(ADC1, ADC_MODE_SCAN);
|
|
||||||
adc_disable_external_trigger_regular(ADC1);
|
|
||||||
adc_set_right_aligned(ADC1);
|
|
||||||
adc_enable_temperature_sensor();
|
|
||||||
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPTIME_071DOT5);
|
|
||||||
adc_set_regular_sequence(ADC1, 1, channel_array);
|
|
||||||
adc_set_resolution(ADC1, ADC_RESOLUTION_12BIT);
|
|
||||||
adc_disable_analog_watchdog(ADC1);
|
|
||||||
adc_power_on(ADC1);
|
|
||||||
|
|
||||||
/* Wait for ADC starting up. */
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 800000; i++) { /* Wait a bit. */
|
|
||||||
__asm__("nop");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usart_setup(void)
|
|
||||||
{
|
|
||||||
/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART1. */
|
|
||||||
rcc_periph_clock_enable(RCC_USART1);
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
|
||||||
|
|
||||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
|
|
||||||
gpio_set_af(GPIOA, GPIO_AF1, GPIO9);
|
|
||||||
|
|
||||||
/* Setup UART parameters. */
|
|
||||||
usart_set_baudrate(USART1, 115200);
|
|
||||||
usart_set_databits(USART1, 8);
|
|
||||||
usart_set_stopbits(USART1, USART_CR2_STOPBITS_1);
|
|
||||||
usart_set_mode(USART1, USART_MODE_TX);
|
|
||||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
|
||||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
|
||||||
|
|
||||||
/* Finally enable the USART. */
|
|
||||||
usart_enable(USART1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void my_usart_print_int(uint32_t usart, int16_t value)
|
|
||||||
{
|
|
||||||
int8_t i;
|
|
||||||
int8_t nr_digits = 0;
|
|
||||||
char buffer[25];
|
|
||||||
|
|
||||||
if (value < 0) {
|
|
||||||
usart_send_blocking(usart, '-');
|
|
||||||
value = value * -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == 0) {
|
|
||||||
usart_send_blocking(usart, '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
while (value > 0) {
|
|
||||||
buffer[nr_digits++] = "0123456789"[value % 10];
|
|
||||||
value /= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = nr_digits-1; i >= 0; i--) {
|
|
||||||
usart_send_blocking(usart, buffer[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
usart_send_blocking(usart, '\r');
|
|
||||||
usart_send_blocking(usart, '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
uint16_t temp;
|
|
||||||
|
|
||||||
adc_setup();
|
|
||||||
usart_setup();
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
adc_start_conversion_regular(ADC1);
|
|
||||||
while (!(adc_eoc(ADC1)));
|
|
||||||
|
|
||||||
temp = adc_read_regular(ADC1);
|
|
||||||
my_usart_print_int(USART1, temp);
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 800000; i++) { /* Wait a bit. */
|
|
||||||
__asm__("nop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
##
|
|
||||||
## 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 = button
|
|
||||||
|
|
||||||
LDSCRIPT = ../stm32f0-discovery.ld
|
|
||||||
|
|
||||||
include ../../Makefile.include
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This example blinks the green LED on the ST STM32F0DISCOVERY eval board.
|
|
||||||
|
|
||||||
When you press the 'USER' button, the blinking is slower.
|
|
||||||
|
|
||||||
## Board connections:
|
|
||||||
|
|
||||||
*none required*
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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>
|
|
||||||
* Copyright (C) 2011 Stephen Caudle <scaudle@doceme.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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <libopencm3/stm32/rcc.h>
|
|
||||||
#include <libopencm3/stm32/gpio.h>
|
|
||||||
|
|
||||||
/* Set STM32 to 48 MHz. */
|
|
||||||
static void clock_setup(void)
|
|
||||||
{
|
|
||||||
rcc_clock_setup_in_hsi_out_48mhz();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gpio_setup(void)
|
|
||||||
{
|
|
||||||
/* Enable GPIOD clock. */
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOC);
|
|
||||||
|
|
||||||
|
|
||||||
/* Set GPIO12 (in GPIO port D) to 'output push-pull'. */
|
|
||||||
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT,
|
|
||||||
GPIO_PUPD_NONE, GPIO8 | GPIO9);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void button_setup(void)
|
|
||||||
{
|
|
||||||
/* Enable GPIOA clock. */
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
|
||||||
|
|
||||||
|
|
||||||
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
|
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
clock_setup();
|
|
||||||
button_setup();
|
|
||||||
gpio_setup();
|
|
||||||
|
|
||||||
/* Blink the LED (PD12) on the board. */
|
|
||||||
while (1) {
|
|
||||||
gpio_toggle(GPIOC, GPIO8);
|
|
||||||
|
|
||||||
/* Upon button press, blink more slowly. */
|
|
||||||
if (gpio_get(GPIOA, GPIO0)) {
|
|
||||||
for (i = 0; i < 300000; i++) { /* Wait a bit. */
|
|
||||||
__asm__("nop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 300000; i++) { /* Wait a bit. */
|
|
||||||
__asm__("nop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
##
|
|
||||||
## 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 = ../stm32f0-discovery.ld
|
|
||||||
|
|
||||||
include ../../Makefile.include
|
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This is the smallest-possible example program using libopencm3 and ST
|
|
||||||
STM32F0DISCOVERY eval board.
|
|
||||||
|
|
||||||
It should blink the blue LED on the board.
|
|
||||||
|
|
||||||
## Board connections
|
|
||||||
|
|
||||||
*none required*
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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/rcc.h>
|
|
||||||
#include <libopencm3/stm32/gpio.h>
|
|
||||||
|
|
||||||
#define PORT_LED GPIOC
|
|
||||||
#define PIN_LED GPIO8
|
|
||||||
|
|
||||||
static void gpio_setup(void)
|
|
||||||
{
|
|
||||||
/* Enable GPIOC clock. */
|
|
||||||
/* Manually: */
|
|
||||||
//RCC_AHBENR |= RCC_AHBENR_GPIOCEN;
|
|
||||||
/* Using API functions: */
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOC);
|
|
||||||
|
|
||||||
|
|
||||||
/* Set GPIO8 (in GPIO port C) 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: */
|
|
||||||
// GPIOC_BSRR = PIN_LED; /* LED off */
|
|
||||||
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
|
|
||||||
// __asm__("nop");
|
|
||||||
// GPIOC_BRR = PIN_LED; /* LED on */
|
|
||||||
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
|
|
||||||
// __asm__("nop");
|
|
||||||
|
|
||||||
/* Using API functions gpio_set()/gpio_clear(): */
|
|
||||||
// gpio_set(PORT_LED, PIN_LED); /* LED off */
|
|
||||||
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
|
|
||||||
// __asm__("nop");
|
|
||||||
// gpio_clear(PORT_LED, PIN_LED); /* 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;
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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>
|
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Linker script for ST STM32F0DISCOVERY (STM32F051R8T6, 64K flash, 8K RAM). */
|
|
||||||
|
|
||||||
/* Define memory regions. */
|
|
||||||
MEMORY
|
|
||||||
{
|
|
||||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
|
||||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Include the common ld script. */
|
|
||||||
INCLUDE cortex-m-generic.ld
|
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
##
|
|
||||||
## 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_blink
|
|
||||||
|
|
||||||
LDSCRIPT = ../stm32f0-discovery.ld
|
|
||||||
|
|
||||||
include ../../Makefile.include
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This example is the same as fancy\_blink except that it uses the systick timer
|
|
||||||
to generate time accurate delays. The blue LED flashes four times per second.
|
|
||||||
|
|
||||||
There is internal reference clock available on MCO output pin. This can be used
|
|
||||||
to debug the PLL clock setup by scope.
|
|
||||||
|
|
||||||
## Board connections
|
|
||||||
|
|
||||||
| Port | Function | Description |
|
|
||||||
| ----- | -------- | ------------------------ |
|
|
||||||
| `PA8` | `(MCO)` | Internal reference clock |
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the libopencm3 project.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 Chuck McManis <cmcmanis@mcmanis.com>
|
|
||||||
* Copyright (C) 2013 Onno Kortmann <onno@gmx.net>
|
|
||||||
* Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz> (merge)
|
|
||||||
*
|
|
||||||
* 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/rcc.h>
|
|
||||||
#include <libopencm3/stm32/gpio.h>
|
|
||||||
#include <libopencm3/cm3/nvic.h>
|
|
||||||
#include <libopencm3/cm3/systick.h>
|
|
||||||
|
|
||||||
/* Called when systick fires */
|
|
||||||
void sys_tick_handler(void)
|
|
||||||
{
|
|
||||||
gpio_toggle(GPIOC, GPIO8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set up timer to fire every x milliseconds
|
|
||||||
* This is a unusual usage of systick, be very careful with the 24bit range
|
|
||||||
* of the systick counter! You can range from 1 to 2796ms with this.
|
|
||||||
*/
|
|
||||||
static void systick_setup(int xms)
|
|
||||||
{
|
|
||||||
/* div8 per ST, stays compatible with M3/M4 parts, well done ST */
|
|
||||||
systick_set_clocksource(STK_CSR_CLKSOURCE_EXT);
|
|
||||||
/* clear counter so it starts right away */
|
|
||||||
STK_CVR = 0;
|
|
||||||
|
|
||||||
systick_set_reload(rcc_ahb_frequency / 8 / 1000 * xms);
|
|
||||||
systick_counter_enable();
|
|
||||||
systick_interrupt_enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set STM32 to clock by 48MHz from HSI oscillator */
|
|
||||||
static void clock_setup(void)
|
|
||||||
{
|
|
||||||
rcc_clock_setup_in_hsi_out_48mhz();
|
|
||||||
|
|
||||||
/* Enable clocks to the GPIO subsystems */
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOC);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gpio_setup(void)
|
|
||||||
{
|
|
||||||
/* Set blue led (PC8) as output */
|
|
||||||
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO8);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mco_setup(void)
|
|
||||||
{
|
|
||||||
/* PA8 to AF 0 for MCO */
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO8);
|
|
||||||
gpio_set_output_options(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_100MHZ, GPIO8);
|
|
||||||
gpio_set_af(GPIOA, 0, GPIO8);
|
|
||||||
|
|
||||||
/* clock output on pin PA8 (allows checking with scope) */
|
|
||||||
rcc_set_mco(RCC_CFGR_MCO_SYSCLK);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
clock_setup();
|
|
||||||
gpio_setup();
|
|
||||||
mco_setup();
|
|
||||||
|
|
||||||
/* 125ms ticks => 250ms period => 4Hz blinks */
|
|
||||||
systick_setup(125);
|
|
||||||
|
|
||||||
/* Do nothing in main loop */
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
##
|
|
||||||
## 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 = ../stm32f0-discovery.ld
|
|
||||||
|
|
||||||
include ../../Makefile.include
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This example program sends repeating sequence of characters "0123456789" on
|
|
||||||
USART1 serial line of ST STM32F0DISCOVERY eval board.
|
|
||||||
|
|
||||||
The sending is done in a blocking way.
|
|
||||||
|
|
||||||
## Board connections
|
|
||||||
|
|
||||||
| Port | Function | Description |
|
|
||||||
| ----- | ------------- | --------------------------------- |
|
|
||||||
| `PA9` | `(USART1_TX)` | TTL serial output `(115200,8,N,1)` |
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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>
|
|
||||||
*
|
|
||||||
* 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/rcc.h>
|
|
||||||
#include <libopencm3/stm32/gpio.h>
|
|
||||||
#include <libopencm3/stm32/usart.h>
|
|
||||||
|
|
||||||
static void clock_setup(void)
|
|
||||||
{
|
|
||||||
/* Enable GPIOC clock for LED & USARTs. */
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOC);
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
|
||||||
|
|
||||||
/* Enable clocks for USART. */
|
|
||||||
rcc_periph_clock_enable(RCC_USART1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usart_setup(void)
|
|
||||||
{
|
|
||||||
/* Setup USART parameters. */
|
|
||||||
usart_set_baudrate(USART1, 115200);
|
|
||||||
usart_set_databits(USART1, 8);
|
|
||||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
|
||||||
usart_set_stopbits(USART1, USART_CR2_STOPBITS_1);
|
|
||||||
usart_set_mode(USART1, USART_MODE_TX);
|
|
||||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
|
||||||
|
|
||||||
/* Finally enable the USART. */
|
|
||||||
usart_enable(USART1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gpio_setup(void)
|
|
||||||
{
|
|
||||||
/* Setup GPIO pin GPIO8/9 on GPIO port C for LEDs. */
|
|
||||||
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO8 | GPIO9);
|
|
||||||
|
|
||||||
/* Setup GPIO pins for USART transmit. */
|
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
|
|
||||||
|
|
||||||
/* Setup USART TX pin as alternate function. */
|
|
||||||
gpio_set_af(GPIOA, GPIO_AF1, GPIO9);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i, j = 0, c = 0;
|
|
||||||
|
|
||||||
clock_setup();
|
|
||||||
gpio_setup();
|
|
||||||
usart_setup();
|
|
||||||
|
|
||||||
/* Blink the LED on the board with every transmitted byte. */
|
|
||||||
while (1) {
|
|
||||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
|
||||||
usart_send_blocking(USART1, c + '0'); /* USART1: Send byte. */
|
|
||||||
c = (c == 9) ? 0 : c + 1; /* Increment c. */
|
|
||||||
if ((j++ % 80) == 0) { /* Newline after line full. */
|
|
||||||
usart_send_blocking(USART1, '\r');
|
|
||||||
usart_send_blocking(USART1, '\n');
|
|
||||||
}
|
|
||||||
for (i = 0; i < 100000; i++) { /* Wait a bit. */
|
|
||||||
__asm__("NOP");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
##
|
|
||||||
## 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_stdio
|
|
||||||
CSTD = -std=gnu99
|
|
||||||
|
|
||||||
LDSCRIPT = ../stm32f0-discovery.ld
|
|
||||||
|
|
||||||
include ../../Makefile.include
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This example program sends a message "Pass: n" with increasing number n
|
|
||||||
from 0 to 200 on USART1 serial line of ST STM32F0DISCOVERY eval board.
|
|
||||||
|
|
||||||
The sending is done using newlib library in a blocking way.
|
|
||||||
|
|
||||||
## Board connections
|
|
||||||
|
|
||||||
| Port | Function | Description |
|
|
||||||
| ----- | ------------- | --------------------------------- |
|
|
||||||
| `PA9` | `(USART1_TX)` | TTL serial output `(115200,8,N,1)` |
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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>
|
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <libopencm3/stm32/rcc.h>
|
|
||||||
#include <libopencm3/stm32/gpio.h>
|
|
||||||
#include <libopencm3/stm32/usart.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
static ssize_t _iord(void *_cookie, char *_buf, size_t _n);
|
|
||||||
static ssize_t _iowr(void *_cookie, const char *_buf, size_t _n);
|
|
||||||
|
|
||||||
static ssize_t _iord(void *_cookie, char *_buf, size_t _n)
|
|
||||||
{
|
|
||||||
/* dont support reading now */
|
|
||||||
(void)_cookie;
|
|
||||||
(void)_buf;
|
|
||||||
(void)_n;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t _iowr(void *_cookie, const char *_buf, size_t _n)
|
|
||||||
{
|
|
||||||
uint32_t dev = (uint32_t)_cookie;
|
|
||||||
|
|
||||||
int written = 0;
|
|
||||||
while (_n-- > 0) {
|
|
||||||
usart_send_blocking(dev, *_buf++);
|
|
||||||
written++;
|
|
||||||
};
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static FILE *usart_setup(uint32_t dev)
|
|
||||||
{
|
|
||||||
/* Setup USART parameters. */
|
|
||||||
usart_set_baudrate(dev, 115200);
|
|
||||||
usart_set_databits(dev, 8);
|
|
||||||
usart_set_parity(dev, USART_PARITY_NONE);
|
|
||||||
usart_set_stopbits(dev, USART_CR2_STOPBITS_1);
|
|
||||||
usart_set_mode(dev, USART_MODE_TX_RX);
|
|
||||||
usart_set_flow_control(dev, USART_FLOWCONTROL_NONE);
|
|
||||||
|
|
||||||
/* Finally enable the USART. */
|
|
||||||
usart_enable(dev);
|
|
||||||
|
|
||||||
cookie_io_functions_t stub = { _iord, _iowr, NULL, NULL };
|
|
||||||
FILE *fp = fopencookie((void *)dev, "rw+", stub);
|
|
||||||
/* Do not buffer the serial line */
|
|
||||||
setvbuf(fp, NULL, _IONBF, 0);
|
|
||||||
return fp;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void clock_setup(void)
|
|
||||||
{
|
|
||||||
/* Enable GPIOC clock for LED & USARTs. */
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOC);
|
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
|
||||||
|
|
||||||
/* Enable clocks for USART. */
|
|
||||||
rcc_periph_clock_enable(RCC_USART1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gpio_setup(void)
|
|
||||||
{
|
|
||||||
/* Setup GPIO pin GPIO8/9 on GPIO port C for LEDs. */
|
|
||||||
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO8 | GPIO9);
|
|
||||||
|
|
||||||
/* Setup GPIO pins for USART transmit. */
|
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
|
|
||||||
|
|
||||||
/* Setup USART TX pin as alternate function. */
|
|
||||||
gpio_set_af(GPIOA, GPIO_AF1, GPIO9);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i, c = 0;
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
clock_setup();
|
|
||||||
gpio_setup();
|
|
||||||
fp = usart_setup(USART1);
|
|
||||||
|
|
||||||
/* Blink the LED on the board with every transmitted byte. */
|
|
||||||
while (1) {
|
|
||||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
|
||||||
|
|
||||||
fprintf(fp, "Pass: %d\n", c);
|
|
||||||
|
|
||||||
c = (c == 200) ? 0 : c + 1; /* Increment c. */
|
|
||||||
|
|
||||||
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
|
|
||||||
__asm__("NOP");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -18,27 +18,155 @@
|
|||||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
##
|
##
|
||||||
|
|
||||||
LIBNAME = opencm3_stm32f1
|
PREFIX ?= arm-none-eabi
|
||||||
DEFS += -DSTM32F1
|
#PREFIX ?= arm-elf
|
||||||
|
CC = $(PREFIX)-gcc
|
||||||
|
LD = $(PREFIX)-gcc
|
||||||
|
OBJCOPY = $(PREFIX)-objcopy
|
||||||
|
OBJDUMP = $(PREFIX)-objdump
|
||||||
|
GDB = $(PREFIX)-gdb
|
||||||
|
|
||||||
FP_FLAGS ?= -msoft-float
|
TOOLCHAIN_DIR ?= ../../../../../libopencm3
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
|
ifeq ($(wildcard ../../../../../libopencm3/lib/libopencm3_stm32f1.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
|
||||||
# OpenOCD specific variables
|
CFLAGS += -Os -g \
|
||||||
|
-Wall -Wextra -Wimplicit-function-declaration \
|
||||||
|
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
||||||
|
-Wundef -Wshadow \
|
||||||
|
-I$(TOOLCHAIN_DIR)/include \
|
||||||
|
-fno-common $(ARCH_FLAGS) -MD -DSTM32F1
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
OOCD ?= openocd
|
OOCD ?= openocd
|
||||||
OOCD_INTERFACE ?= flossjtag
|
OOCD_INTERFACE ?= flossjtag
|
||||||
OOCD_TARGET ?= stm32f1x
|
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
|
||||||
# texane/stlink specific variables
|
|
||||||
#STLINK_PORT ?= :4242
|
#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_stm32f1.a
|
||||||
|
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
|
||||||
|
$(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32f1 $(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 "stm32f1x 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 "stm32f1x 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)
|
||||||
|
|
||||||
include ../../../../rules.mk
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
Examples in these directories are not _only_ for the board listed, they are
|
|
||||||
simply preconfigured for those boards. If you do not find an example of the
|
|
||||||
peripheral you want to use listed for your board, please look at the other
|
|
||||||
boards. The differences between boards for the examples is normally only
|
|
||||||
LEDs and buttons on different pins, and different memory sizes.
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
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
|
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
|
receives messages and is displaing the first 4 bits of the first byte on the
|
||||||
@@ -18,13 +18,12 @@
|
|||||||
* 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 <stddef.h>
|
#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/nvic.h>
|
||||||
#include <libopencm3/cm3/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/stm32/can.h>
|
#include <libopencm3/stm32/can.h>
|
||||||
#include <libopencm3/stm32/gpio.h>
|
|
||||||
#include <libopencm3/stm32/flash.h>
|
|
||||||
#include <libopencm3/stm32/rcc.h>
|
|
||||||
|
|
||||||
struct can_tx_msg {
|
struct can_tx_msg {
|
||||||
uint32_t std_id;
|
uint32_t std_id;
|
||||||
@@ -51,16 +50,16 @@ struct can_rx_msg can_rx_msg;
|
|||||||
static void gpio_setup(void)
|
static void gpio_setup(void)
|
||||||
{
|
{
|
||||||
/* Enable Alternate Function clock. */
|
/* Enable Alternate Function clock. */
|
||||||
rcc_periph_clock_enable(RCC_AFIO);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
|
|
||||||
/* Enable GPIOA clock. */
|
/* Enable GPIOA clock. */
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
/* Enable GPIOB clock. */
|
/* Enable GPIOB clock. */
|
||||||
rcc_periph_clock_enable(RCC_GPIOB);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
|
||||||
/* Enable GPIOC clock. */
|
/* Enable GPIOC clock. */
|
||||||
rcc_periph_clock_enable(RCC_GPIOC);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||||
|
|
||||||
/* Preconfigure LEDs. */
|
/* Preconfigure LEDs. */
|
||||||
gpio_set(GPIOA, GPIO8); /* LED0 off */
|
gpio_set(GPIOA, GPIO8); /* LED0 off */
|
||||||
@@ -89,7 +88,7 @@ static void gpio_setup(void)
|
|||||||
static void systick_setup(void)
|
static void systick_setup(void)
|
||||||
{
|
{
|
||||||
/* 72MHz / 8 => 9000000 counts per second */
|
/* 72MHz / 8 => 9000000 counts per second */
|
||||||
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
|
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||||
|
|
||||||
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
|
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
|
||||||
/* SysTick interrupt every N clock pulses: set reload to N-1 */
|
/* SysTick interrupt every N clock pulses: set reload to N-1 */
|
||||||
@@ -104,9 +103,9 @@ static void systick_setup(void)
|
|||||||
static void can_setup(void)
|
static void can_setup(void)
|
||||||
{
|
{
|
||||||
/* Enable peripheral clocks. */
|
/* Enable peripheral clocks. */
|
||||||
rcc_periph_clock_enable(RCC_AFIO);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
rcc_periph_clock_enable(RCC_GPIOB);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
rcc_periph_clock_enable(RCC_CAN);
|
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN);
|
||||||
|
|
||||||
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||||
|
|
||||||
@@ -153,7 +152,7 @@ static void can_setup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* CAN filter 0 init. */
|
/* CAN filter 0 init. */
|
||||||
can_filter_id_mask_32bit_init(
|
can_filter_id_mask_32bit_init(CAN1,
|
||||||
0, /* Filter ID */
|
0, /* Filter ID */
|
||||||
0, /* CAN ID */
|
0, /* CAN ID */
|
||||||
0, /* CAN ID mask */
|
0, /* CAN ID mask */
|
||||||
@@ -196,11 +195,11 @@ void sys_tick_handler(void)
|
|||||||
|
|
||||||
void usb_lp_can_rx0_isr(void)
|
void usb_lp_can_rx0_isr(void)
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id, fmi;
|
||||||
bool ext, rtr;
|
bool ext, rtr;
|
||||||
uint8_t fmi, length, data[8];
|
uint8_t length, data[8];
|
||||||
|
|
||||||
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data, NULL);
|
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data);
|
||||||
|
|
||||||
if (data[0] & 1)
|
if (data[0] & 1)
|
||||||
gpio_clear(GPIOA, GPIO8);
|
gpio_clear(GPIOA, GPIO8);
|
||||||
@@ -227,7 +226,7 @@ void usb_lp_can_rx0_isr(void)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE12_72MHZ]);
|
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||||
gpio_setup();
|
gpio_setup();
|
||||||
can_setup();
|
can_setup();
|
||||||
systick_setup();
|
systick_setup();
|
||||||
|
|||||||
218
examples/stm32/f1/lisa-m-1/can/can.c~
Normal file
218
examples/stm32/f1/lisa-m-1/can/can.c~
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||||
|
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. 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/stm32/nvic.h>
|
||||||
|
#include <libopencm3/stm32/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 GPIOA clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
|
/* Enable GPIOB clock. */
|
||||||
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
|
|
||||||
|
gpio_set(GPIOA, GPIO6); /* LED0 off */
|
||||||
|
gpio_set(GPIOA, GPIO7); /* LED1 off */
|
||||||
|
gpio_set(GPIOB, GPIO0); /* LED2 off */
|
||||||
|
gpio_set(GPIOB, GPIO1); /* LED3 off */
|
||||||
|
|
||||||
|
/* Set GPIO6/7 (in GPIO port A) to 'output push-pull' for the LEDs. */
|
||||||
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||||
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||||
|
|
||||||
|
/* Set GPIO0/1 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO0);
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_CANEN);
|
||||||
|
|
||||||
|
AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||||
|
|
||||||
|
/* Configure CAN pin: RX (input pull-up). */
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
||||||
|
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
||||||
|
gpio_set(GPIOB, GPIO_CAN1_PB_RX);
|
||||||
|
|
||||||
|
/* Configure CAN pin: TX. */
|
||||||
|
gpio_set_mode(GPIOB, 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, GPIO6); /* LED0 off */
|
||||||
|
gpio_set(GPIOA, GPIO7); /* LED1 off */
|
||||||
|
gpio_set(GPIOB, GPIO0); /* LED2 off */
|
||||||
|
gpio_clear(GPIOB, GPIO1); /* LED3 on */
|
||||||
|
|
||||||
|
/* 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 1000ms = 1s on/off. */
|
||||||
|
if (++temp32 != 1000)
|
||||||
|
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, GPIO6); /* LED0 off */
|
||||||
|
gpio_set(GPIOA, GPIO7); /* LED1 off */
|
||||||
|
gpio_clear(GPIOB, GPIO0); /* LED2 on */
|
||||||
|
gpio_set(GPIOB, GPIO1); /* LED3 off */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, GPIO6);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOA, GPIO6);
|
||||||
|
|
||||||
|
if (data[0] & 2)
|
||||||
|
gpio_clear(GPIOA, GPIO7);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOA, GPIO7);
|
||||||
|
|
||||||
|
if (data[0] & 4)
|
||||||
|
gpio_clear(GPIOB, GPIO0);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOB, GPIO0);
|
||||||
|
|
||||||
|
if (data[0] & 8)
|
||||||
|
gpio_clear(GPIOB, GPIO1);
|
||||||
|
else
|
||||||
|
gpio_set(GPIOB, GPIO1);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -18,18 +18,18 @@
|
|||||||
* 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/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
|
|
||||||
/* Set STM32 to 72 MHz. */
|
/* Set STM32 to 72 MHz. */
|
||||||
static void clock_setup(void)
|
static void clock_setup(void)
|
||||||
{
|
{
|
||||||
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE12_72MHZ]);
|
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||||
|
|
||||||
/* Enable GPIOB, GPIOC, and AFIO clocks. */
|
/* Enable GPIOB, GPIOC, and AFIO clocks. */
|
||||||
rcc_periph_clock_enable(RCC_GPIOB);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||||
rcc_periph_clock_enable(RCC_GPIOC);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||||
rcc_periph_clock_enable(RCC_AFIO);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gpio_setup(void)
|
static void gpio_setup(void)
|
||||||
|
|||||||
@@ -28,5 +28,5 @@ MEMORY
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Include the common ld script. */
|
/* Include the common ld script. */
|
||||||
INCLUDE cortex-m-generic.ld
|
INCLUDE libopencm3_stm32f1.ld
|
||||||
|
|
||||||
|
|||||||
7
examples/stm32/f1/lisa-m-1/usb_cdcacm/README
Normal file
7
examples/stm32/f1/lisa-m-1/usb_cdcacm/README
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
README
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This example implements a USB CDC-ACM device (aka Virtual Serial Port)
|
||||||
|
to demonstrate the use of the USB device stack.
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
# README
|
|
||||||
|
|
||||||
This example implements a USB CDC-ACM device (aka Virtual Serial Port)
|
|
||||||
to demonstrate the use of the USB device stack.
|
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user