Compare commits
277 Commits
coding_sty
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 60c46ba807 | |||
|
|
15637e291b | ||
|
|
9577cd71eb | ||
|
|
3a8911627d | ||
|
|
991bb45710 | ||
|
|
4cfc75f715 | ||
|
|
66d622aa7e | ||
|
|
e599e34073 | ||
|
|
02f48ef616 | ||
|
|
520e7523ec | ||
|
|
0bbafd690a | ||
|
|
4c5ff56168 | ||
|
|
882f5b7d1b | ||
|
|
4b4115fd72 | ||
|
|
9b7c2c3dbf | ||
|
|
9830486509 | ||
|
|
6e12785c84 | ||
|
|
5a828ffb82 | ||
|
|
be1d296e2f | ||
|
|
e0f377fec0 | ||
|
|
2cd847eab1 | ||
|
|
4f4e6f9ef2 | ||
|
|
fed62e7ef4 | ||
|
|
c9fe1da748 | ||
|
|
591d715d52 | ||
|
|
90262eb880 | ||
|
|
f9713ff865 | ||
|
|
b7aac4bc76 | ||
|
|
d434a00323 | ||
|
|
236428e74b | ||
|
|
dc2142b729 | ||
|
|
f09dd550fd | ||
|
|
3527ce407e | ||
|
|
8faca31dc5 | ||
|
|
87680cd122 | ||
|
|
7c121eda94 | ||
|
|
5b30e3d98d | ||
|
|
ce364386d6 | ||
|
|
fe6a2b5f13 | ||
|
|
21ce202a07 | ||
|
|
37126c5f02 | ||
|
|
cef41e465d | ||
|
|
6bca6aaf02 | ||
|
|
bc9ad8df08 | ||
|
|
4ddb9db8b9 | ||
|
|
daff5b130a | ||
|
|
8c6c8720bf | ||
|
|
301b4f9194 | ||
|
|
a4eec6026b | ||
|
|
b8b9720926 | ||
|
|
7d6a2e36ee | ||
|
|
85be1e5e7b | ||
|
|
bcf608fa54 | ||
|
|
6e71b9dea8 | ||
|
|
f4e129cd4a | ||
|
|
6dbc067b3e | ||
|
|
f368819e81 | ||
|
|
d6876b1f77 | ||
|
|
2107faf5ee | ||
|
|
1f322c1cef | ||
|
|
fc60651b6a | ||
|
|
766f89c724 | ||
|
|
d23bee4f1a | ||
|
|
1b92d46b97 | ||
|
|
c03b580722 | ||
|
|
9af2b8c7fb | ||
|
|
d2abd471a5 | ||
|
|
da04ccdf71 | ||
|
|
1260b16772 | ||
|
|
833da68c18 | ||
|
|
8fae7811a8 | ||
|
|
23001dfbcb | ||
|
|
c22200ceb5 | ||
|
|
ed6973584c | ||
|
|
bb8f4699da | ||
|
|
4dfa31f9f8 | ||
|
|
eb54fbf285 | ||
|
|
fc690fd6c4 | ||
|
|
9fbac7daaf | ||
|
|
da679c1775 | ||
|
|
bcd7d57c11 | ||
|
|
b227e1609c | ||
|
|
408b83f47a | ||
|
|
30667fe62c | ||
|
|
133a45b734 | ||
|
|
b5fcf55005 | ||
|
|
0f04829415 | ||
|
|
de0d4af890 | ||
|
|
52b12d5259 | ||
|
|
140d0864b8 | ||
|
|
4b772a4437 | ||
|
|
a5641ab63e | ||
|
|
8924042d2a | ||
|
|
5b35c7d7a1 | ||
|
|
07c2326f7e | ||
|
|
9f8d37d8c8 | ||
|
|
2092a6759d | ||
|
|
b50cdb56de | ||
|
|
dfc4763ab3 | ||
|
|
7bbc57df75 | ||
|
|
ec1d59e344 | ||
|
|
b22ea8b616 | ||
|
|
7322fdcdb9 | ||
|
|
8ce9536b2e | ||
|
|
976720c355 | ||
|
|
f0009c64dc | ||
|
|
2314635cf0 | ||
|
|
070e5bbb94 | ||
|
|
3a275fb601 | ||
|
|
393fe8e449 | ||
|
|
dd0e48369d | ||
|
|
a6c183d470 | ||
|
|
1123768e78 | ||
|
|
0b9e7d0d5d | ||
|
|
849bdc8001 | ||
|
|
b7c04b4eee | ||
|
|
a023b0a7ca | ||
|
|
3a06a8d24c | ||
|
|
697d4f307a | ||
|
|
b779843799 | ||
|
|
48b2f10e66 | ||
|
|
be988d74ca | ||
|
|
c6af45ba8f | ||
|
|
d90d72291a | ||
|
|
4837775449 | ||
|
|
8019726f51 | ||
|
|
9cee61f089 | ||
|
|
408ba8c885 | ||
|
|
22f59c4583 | ||
|
|
4de8d15303 | ||
|
|
ec7c0f318b | ||
|
|
5b26d350ff | ||
|
|
51dda90570 | ||
|
|
8c6eb9ca57 | ||
|
|
c06aba1603 | ||
|
|
0a863789b0 | ||
|
|
5379525a87 | ||
|
|
b76c30cdb0 | ||
|
|
d29e4d2b7c | ||
|
|
86c42bc2dd | ||
|
|
d6cb05d792 | ||
|
|
fbcb1ca66e | ||
|
|
ed4bec540c | ||
|
|
c18a16d979 | ||
|
|
7629bb01e6 | ||
|
|
71b2c1991f | ||
|
|
ea5af55b92 | ||
|
|
a3ff2c9250 | ||
|
|
e4d106dce6 | ||
|
|
ae9c116e30 | ||
|
|
4defd3e1d2 | ||
|
|
e5585dd07d | ||
|
|
2583cc54cc | ||
|
|
1c4ae95729 | ||
|
|
ab7efee88e | ||
|
|
64761d405b | ||
|
|
aae10c6dcb | ||
|
|
397780799a | ||
|
|
f6a1a3ee14 | ||
|
|
ddd5d5a918 | ||
|
|
1120b3f1b5 | ||
|
|
4f1db00763 | ||
|
|
016923e654 | ||
|
|
dfac3be665 | ||
|
|
ddd0312b10 | ||
|
|
1346cd0156 | ||
|
|
92c228bc63 | ||
|
|
50b3522e7a | ||
|
|
25d924f699 | ||
|
|
7bf64424ab | ||
|
|
23c29f1784 | ||
|
|
ae17f5a77b | ||
|
|
a0d379f460 | ||
|
|
e8694d561f | ||
|
|
75389c665d | ||
|
|
766be687dc | ||
|
|
1215603031 | ||
|
|
1b2f9db18f | ||
|
|
312540a0e5 | ||
|
|
058298fd78 | ||
|
|
2372d8b59f | ||
|
|
2ba1619889 | ||
|
|
3f4515438a | ||
|
|
a15300d9e4 | ||
|
|
9852282bcf | ||
|
|
7f215cb6fa | ||
|
|
bc5d0816e5 | ||
|
|
7c07ed97a6 | ||
|
|
54c5c77823 | ||
|
|
4aaae0086a | ||
|
|
05d46ab6cd | ||
|
|
6960d2adef | ||
|
|
bd76fb8661 | ||
|
|
dd320a6e99 | ||
|
|
49760aa021 | ||
|
|
abf774c0f4 | ||
|
|
f94a821712 | ||
|
|
64ecb61543 | ||
|
|
8ffaf0579d | ||
|
|
06208be477 | ||
|
|
1740fee230 | ||
|
|
3af1f8d43d | ||
|
|
3f47411e24 | ||
|
|
022cc475bf | ||
|
|
a265fd4d64 | ||
|
|
5bb4d47aae | ||
|
|
3f68a5ceef | ||
|
|
c54ab042ef | ||
|
|
d1cf776ebc | ||
|
|
5f592615d6 | ||
|
|
379889e732 | ||
|
|
523401097a | ||
|
|
1b98ef8bfc | ||
|
|
ffe9376c55 | ||
|
|
94ddb178eb | ||
|
|
52fc38b03e | ||
|
|
04d4bac5af | ||
|
|
39f6c9eb5f | ||
|
|
f756c99a42 | ||
|
|
747e8d260b | ||
|
|
07df176a8a | ||
|
|
5385b463fe | ||
|
|
95fe484c42 | ||
|
|
58e84a9438 | ||
|
|
02c35eee70 | ||
|
|
9934e40fe9 | ||
|
|
04c92b6677 | ||
|
|
cc800be89a | ||
|
|
5bafa042c5 | ||
|
|
72c1a29779 | ||
|
|
3efd9f8675 | ||
|
|
c0791cd4a7 | ||
|
|
4505fa1926 | ||
|
|
eeb900d800 | ||
|
|
b59c0a9e05 | ||
|
|
d944c0cba6 | ||
|
|
c672f1b329 | ||
|
|
f1bb59e19c | ||
|
|
ca926f00e0 | ||
|
|
26d27497f2 | ||
|
|
3673e4059b | ||
|
|
314ad2d877 | ||
|
|
d8757ab1fc | ||
|
|
c5d6480201 | ||
|
|
4ae45b913d | ||
|
|
60e08c0591 | ||
|
|
f176fe59d9 | ||
|
|
a8b3daeb57 | ||
|
|
71bd938eeb | ||
|
|
80ba923da1 | ||
|
|
9338034eea | ||
|
|
5efea57487 | ||
|
|
100434b12d | ||
|
|
d9536caeaa | ||
|
|
2b8b526df0 | ||
|
|
92624b7d01 | ||
|
|
210761e1df | ||
|
|
408fa52ec3 | ||
|
|
b82cb85cc4 | ||
|
|
fa8355225e | ||
|
|
04a40d5cf6 | ||
|
|
87db268c8e | ||
|
|
d0d2730db8 | ||
|
|
98b4d42846 | ||
|
|
e1d5325736 | ||
|
|
63f3bd7713 | ||
|
|
6474ed3cf0 | ||
|
|
4832449dd2 | ||
|
|
757d044c23 | ||
|
|
fb4cecd05e | ||
|
|
7ee888a857 | ||
|
|
614d921a3b | ||
|
|
d74a44e589 | ||
|
|
3186a4f2e7 | ||
|
|
7639a88928 | ||
|
|
28f92cce2b | ||
|
|
f5b0aa5638 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -7,3 +7,12 @@
|
||||
*.srec
|
||||
*.list
|
||||
*.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"]
|
||||
path = libopencm3
|
||||
url = https://github.com/libopencm3/libopencm3.git
|
||||
url = https://git.orangetime.top/EMTime/libopencm3
|
||||
|
||||
16
.travis.yml
Normal file
16
.travis.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
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,10 +17,15 @@
|
||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
PREFIX ?= arm-none-eabi
|
||||
#PREFIX ?= arm-elf
|
||||
PREFIX ?= arm-none-eabi-
|
||||
|
||||
TARGETS = stm32/f1 stm32/f2 stm32/f4 stm32/l1 lpc13xx lpc17xx lpc43xx lm3s lm4f efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
|
||||
TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4
|
||||
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.
|
||||
ifneq ($(V),1)
|
||||
@@ -29,40 +34,68 @@ Q := @
|
||||
MAKEFLAGS += --no-print-directory
|
||||
endif
|
||||
|
||||
OPENCM3_DIR ?= $(realpath libopencm3)
|
||||
EXAMPLE_RULES = elf
|
||||
|
||||
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
|
||||
|
||||
lib:
|
||||
$(Q)if [ ! "`ls -A libopencm3`" ] ; then \
|
||||
echo "######## ERROR ########"; \
|
||||
echo "\tlibopencm3 is not initialized."; \
|
||||
echo "\tPlease run:"; \
|
||||
echo "\t$$ git submodule init"; \
|
||||
echo "\t$$ git submodule update"; \
|
||||
echo "\tbefore running make."; \
|
||||
echo "######## ERROR ########"; \
|
||||
$(Q)if [ ! "`ls -A $(OPENCM3_DIR)`" ] ; then \
|
||||
printf "######## ERROR ########\n"; \
|
||||
printf "\tlibopencm3 is not initialized.\n"; \
|
||||
printf "\tPlease run:\n"; \
|
||||
printf "\t$$ git submodule init\n"; \
|
||||
printf "\t$$ git submodule update\n"; \
|
||||
printf "\tbefore running make.\n"; \
|
||||
printf "######## ERROR ########\n"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(Q)$(MAKE) -C libopencm3
|
||||
$(Q)$(MAKE) -C $(OPENCM3_DIR)
|
||||
|
||||
EXAMPLE_DIRS:=$(sort $(dir $(wildcard $(addsuffix /*/*/Makefile,$(addprefix examples/,$(TARGETS))))))
|
||||
$(EXAMPLE_DIRS): lib
|
||||
@printf " BUILD $@\n";
|
||||
$(Q)$(MAKE) --directory=$@
|
||||
$(Q)$(MAKE) --directory=$@ OPENCM3_DIR=$(OPENCM3_DIR) $(EXAMPLE_RULES)
|
||||
|
||||
examples: $(EXAMPLE_DIRS)
|
||||
$(Q)true
|
||||
|
||||
# Bleh http://www.makelinux.net/make3/make3-CHP-6-SECT-1#make3-CHP-6-SECT-1
|
||||
clean:
|
||||
examplesclean: $(EXAMPLE_DIRS:=.clean)
|
||||
|
||||
clean: examplesclean styleclean
|
||||
$(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
|
||||
|
||||
.PHONY: build lib examples $(EXAMPLE_DIRS) install clean
|
||||
stylecheck: $(EXAMPLE_DIRS:=.stylecheck)
|
||||
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
45
README
@@ -1,45 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
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
Normal file
126
README.md
Normal file
@@ -0,0 +1,126 @@
|
||||
# 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
|
||||
|
||||
@@ -1,137 +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/>.
|
||||
##
|
||||
|
||||
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)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
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.
|
||||
|
||||
@@ -1,124 +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 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)
|
||||
|
||||
44
examples/lpc/lpc13xx/Makefile.include
Normal file
44
examples/lpc/lpc13xx/Makefile.include
Normal file
@@ -0,0 +1,44 @@
|
||||
##
|
||||
## 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
|
||||
@@ -27,5 +27,4 @@ MEMORY
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_lpc13xx.ld
|
||||
|
||||
INCLUDE cortex-m-generic.ld
|
||||
@@ -22,4 +22,3 @@ BINARY = miniblink
|
||||
LDSCRIPT = ../lpc-p1343.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
7
examples/lpc/lpc13xx/lpc-p1343/miniblink/README.md
Normal file
7
examples/lpc/lpc13xx/lpc-p1343/miniblink/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# 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.
|
||||
45
examples/lpc/lpc17xx/Makefile.include
Normal file
45
examples/lpc/lpc17xx/Makefile.include
Normal file
@@ -0,0 +1,45 @@
|
||||
##
|
||||
## 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
|
||||
@@ -29,4 +29,4 @@ MEMORY
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_lpc17xx.ld
|
||||
INCLUDE cortex-m-generic.ld
|
||||
@@ -0,0 +1,7 @@
|
||||
# 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.
|
||||
47
examples/lpc/lpc43xx/Makefile.include
Normal file
47
examples/lpc/lpc43xx/Makefile.include
Normal file
@@ -0,0 +1,47 @@
|
||||
##
|
||||
## 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
|
||||
4
examples/lpc/lpc43xx/diolan-lpc-4350-db1/README.md
Normal file
4
examples/lpc/lpc43xx/diolan-lpc-4350-db1/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# README
|
||||
|
||||
These example programs are written for the
|
||||
[Diolan LPC-4350-DB1](http://www.diolan.com/lpc4350-features.html)
|
||||
@@ -0,0 +1,7 @@
|
||||
# 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 @@
|
||||
These example programs are written for the Jellybean development board from the
|
||||
HackRF project:
|
||||
# README
|
||||
|
||||
https://github.com/mossmann/hackrf
|
||||
These example programs are written for the Jellybean development board from the
|
||||
[HackRF project](https://github.com/mossmann/hackrf)
|
||||
13
examples/lpc/lpc43xx/hackrf-jellybean/i2c/README.md
Normal file
13
examples/lpc/lpc43xx/hackrf-jellybean/i2c/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# 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
|
||||
@@ -0,0 +1,8 @@
|
||||
# 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,9 @@
|
||||
# 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.
|
||||
46
examples/lpc/lpc43xx/hackrf-jellybean/ssp/README.md
Normal file
46
examples/lpc/lpc43xx/hackrf-jellybean/ssp/README.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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,6 +1,4 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
# README
|
||||
|
||||
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.
|
||||
@@ -1,137 +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/>.
|
||||
##
|
||||
|
||||
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)
|
||||
|
||||
@@ -1,10 +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 (see
|
||||
http://olimex.com/dev/lpc-p1343.html for details). It should blink
|
||||
a LED on the board.
|
||||
|
||||
@@ -1,137 +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/>.
|
||||
##
|
||||
|
||||
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)
|
||||
|
||||
@@ -1,9 +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 (see
|
||||
http://shop.ngxtechnologies.com/product_info.php?cPath=21&products_id=65). It should blink
|
||||
a LED on the board.
|
||||
@@ -1,140 +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/>.
|
||||
##
|
||||
|
||||
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)
|
||||
@@ -1,3 +0,0 @@
|
||||
These example programs are written for the Diolan LPC-4350-DB1:
|
||||
|
||||
http://www.diolan.com/lpc4350-features.html
|
||||
@@ -1,11 +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,15 +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,11 +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,12 +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,48 +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
|
||||
270
examples/rules.mk
Normal file
270
examples/rules.mk
Normal file
@@ -0,0 +1,270 @@
|
||||
##
|
||||
## 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)
|
||||
33
examples/sam/d/Makefile.include
Normal file
33
examples/sam/d/Makefile.include
Normal file
@@ -0,0 +1,33 @@
|
||||
##
|
||||
## 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
|
||||
22
examples/sam/d/d10-xplained-mini/miniblink/Makefile
Normal file
22
examples/sam/d/d10-xplained-mini/miniblink/Makefile
Normal file
@@ -0,0 +1,22 @@
|
||||
##
|
||||
## 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,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
* Copyright (C) 2016 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
|
||||
@@ -17,33 +17,30 @@
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/spi.h>
|
||||
#include <libopencm3/sam/memorymap.h>
|
||||
#include <libopencm3/sam/d/port.h>
|
||||
|
||||
static void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
}
|
||||
|
||||
static void spi_setup(void)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
// led is on PA09
|
||||
|
||||
static void gpio_setup(void)
|
||||
{
|
||||
/* TODO */
|
||||
PORT_DIR(PORTA) = (1<<9);
|
||||
PORT_PINCFG(PORTA, 9) = 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
clock_setup();
|
||||
int i, j;
|
||||
|
||||
gpio_setup();
|
||||
spi_setup();
|
||||
|
||||
while (1) {
|
||||
spi_write(SPI1, 0xaa);
|
||||
spi_write(SPI1, 0x55);
|
||||
for (j = 0; j < 10; j++) {
|
||||
PORT_OUTTGL(PORTA) = 1<<9;
|
||||
for (i = 0; i < (5000 + (j) * 10000); i++) { /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
44
examples/stm32/f0/Makefile.include
Normal file
44
examples/stm32/f0/Makefile.include
Normal file
@@ -0,0 +1,44 @@
|
||||
##
|
||||
## 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
|
||||
24
examples/stm32/f0/stm32f0-discovery/adc/Makefile
Normal file
24
examples/stm32/f0/stm32f0-discovery/adc/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This library is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU Lesser General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public License
|
||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
BINARY = adc
|
||||
|
||||
LDSCRIPT = ../stm32f0-discovery.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
11
examples/stm32/f0/stm32f0-discovery/adc/README.md
Normal file
11
examples/stm32/f0/stm32f0-discovery/adc/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# 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)` |
|
||||
132
examples/stm32/f0/stm32f0-discovery/adc/adc.c
Normal file
132
examples/stm32/f0/stm32f0-discovery/adc/adc.c
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
25
examples/stm32/f0/stm32f0-discovery/button/Makefile
Normal file
25
examples/stm32/f0/stm32f0-discovery/button/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This library is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU Lesser General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public License
|
||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
BINARY = button
|
||||
|
||||
LDSCRIPT = ../stm32f0-discovery.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
9
examples/stm32/f0/stm32f0-discovery/button/README.md
Normal file
9
examples/stm32/f0/stm32f0-discovery/button/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# 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*
|
||||
77
examples/stm32/f0/stm32f0-discovery/button/button.c
Normal file
77
examples/stm32/f0/stm32f0-discovery/button/button.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
25
examples/stm32/f0/stm32f0-discovery/miniblink/Makefile
Normal file
25
examples/stm32/f0/stm32f0-discovery/miniblink/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This library is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU Lesser General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public License
|
||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
BINARY = miniblink
|
||||
|
||||
LDSCRIPT = ../stm32f0-discovery.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
10
examples/stm32/f0/stm32f0-discovery/miniblink/README.md
Normal file
10
examples/stm32/f0/stm32f0-discovery/miniblink/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# 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*
|
||||
74
examples/stm32/f0/stm32f0-discovery/miniblink/miniblink.c
Normal file
74
examples/stm32/f0/stm32f0-discovery/miniblink/miniblink.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
32
examples/stm32/f0/stm32f0-discovery/stm32f0-discovery.ld
Normal file
32
examples/stm32/f0/stm32f0-discovery/stm32f0-discovery.ld
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
24
examples/stm32/f0/stm32f0-discovery/systick_blink/Makefile
Normal file
24
examples/stm32/f0/stm32f0-discovery/systick_blink/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This library is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU Lesser General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public License
|
||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
BINARY = systick_blink
|
||||
|
||||
LDSCRIPT = ../stm32f0-discovery.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
13
examples/stm32/f0/stm32f0-discovery/systick_blink/README.md
Normal file
13
examples/stm32/f0/stm32f0-discovery/systick_blink/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# 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 |
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
25
examples/stm32/f0/stm32f0-discovery/usart/Makefile
Normal file
25
examples/stm32/f0/stm32f0-discovery/usart/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This library is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU Lesser General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public License
|
||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
BINARY = usart
|
||||
|
||||
LDSCRIPT = ../stm32f0-discovery.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
12
examples/stm32/f0/stm32f0-discovery/usart/README.md
Normal file
12
examples/stm32/f0/stm32f0-discovery/usart/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# 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)` |
|
||||
84
examples/stm32/f0/stm32f0-discovery/usart/usart.c
Normal file
84
examples/stm32/f0/stm32f0-discovery/usart/usart.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
26
examples/stm32/f0/stm32f0-discovery/usart_stdio/Makefile
Normal file
26
examples/stm32/f0/stm32f0-discovery/usart_stdio/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
##
|
||||
## 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
|
||||
|
||||
12
examples/stm32/f0/stm32f0-discovery/usart_stdio/README.md
Normal file
12
examples/stm32/f0/stm32f0-discovery/usart_stdio/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# 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)` |
|
||||
121
examples/stm32/f0/stm32f0-discovery/usart_stdio/usart_stdio.c
Normal file
121
examples/stm32/f0/stm32f0-discovery/usart_stdio/usart_stdio.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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,155 +18,27 @@
|
||||
## 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
|
||||
LIBNAME = opencm3_stm32f1
|
||||
DEFS += -DSTM32F1
|
||||
|
||||
TOOLCHAIN_DIR ?= ../../../../../libopencm3
|
||||
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
|
||||
FP_FLAGS ?= -msoft-float
|
||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
|
||||
|
||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float
|
||||
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
|
||||
################################################################################
|
||||
# OpenOCD specific variables
|
||||
|
||||
OOCD ?= openocd
|
||||
OOCD_INTERFACE ?= flossjtag
|
||||
OOCD_BOARD ?= olimex_stm32_h103
|
||||
# Black magic probe specific variables
|
||||
OOCD_TARGET ?= stm32f1x
|
||||
|
||||
################################################################################
|
||||
# Black Magic Probe specific variables
|
||||
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
||||
BMP_PORT ?=
|
||||
# texane/stlink can be used by uncommenting this...
|
||||
# or defining it in your own makefiles
|
||||
#STLINK_PORT ?= :4242
|
||||
BMP_PORT ?=
|
||||
|
||||
# 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
|
||||
################################################################################
|
||||
# texane/stlink specific variables
|
||||
#STLINK_PORT ?= :4242
|
||||
|
||||
.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
|
||||
|
||||
5
examples/stm32/f1/README.md
Normal file
5
examples/stm32/f1/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
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,3 +1,5 @@
|
||||
# README
|
||||
|
||||
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
||||
100ms. The first byte is being incremented in each cycle. The demo also
|
||||
receives messages and is displaing the first 4 bits of the first byte on the
|
||||
@@ -18,12 +18,13 @@
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <stddef.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.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 {
|
||||
uint32_t std_id;
|
||||
@@ -50,16 +51,16 @@ struct can_rx_msg can_rx_msg;
|
||||
static void gpio_setup(void)
|
||||
{
|
||||
/* Enable Alternate Function clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
rcc_periph_clock_enable(RCC_AFIO);
|
||||
|
||||
/* Enable GPIOA clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOB);
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOC);
|
||||
|
||||
/* Preconfigure LEDs. */
|
||||
gpio_set(GPIOA, GPIO8); /* LED0 off */
|
||||
@@ -88,7 +89,7 @@ static void gpio_setup(void)
|
||||
static void systick_setup(void)
|
||||
{
|
||||
/* 72MHz / 8 => 9000000 counts per second */
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
|
||||
|
||||
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
|
||||
/* SysTick interrupt every N clock pulses: set reload to N-1 */
|
||||
@@ -103,9 +104,9 @@ static void systick_setup(void)
|
||||
static 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);
|
||||
rcc_periph_clock_enable(RCC_AFIO);
|
||||
rcc_periph_clock_enable(RCC_GPIOB);
|
||||
rcc_periph_clock_enable(RCC_CAN);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||
|
||||
@@ -152,7 +153,7 @@ static void can_setup(void)
|
||||
}
|
||||
|
||||
/* CAN filter 0 init. */
|
||||
can_filter_id_mask_32bit_init(CAN1,
|
||||
can_filter_id_mask_32bit_init(
|
||||
0, /* Filter ID */
|
||||
0, /* CAN ID */
|
||||
0, /* CAN ID mask */
|
||||
@@ -195,11 +196,11 @@ void sys_tick_handler(void)
|
||||
|
||||
void usb_lp_can_rx0_isr(void)
|
||||
{
|
||||
uint32_t id, fmi;
|
||||
uint32_t id;
|
||||
bool ext, rtr;
|
||||
uint8_t length, data[8];
|
||||
uint8_t fmi, length, data[8];
|
||||
|
||||
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data);
|
||||
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data, NULL);
|
||||
|
||||
if (data[0] & 1)
|
||||
gpio_clear(GPIOA, GPIO8);
|
||||
@@ -226,7 +227,7 @@ void usb_lp_can_rx0_isr(void)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE12_72MHZ]);
|
||||
gpio_setup();
|
||||
can_setup();
|
||||
systick_setup();
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
/* Set STM32 to 72 MHz. */
|
||||
static void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE12_72MHZ]);
|
||||
|
||||
/* Enable GPIOB, GPIOC, and AFIO clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOB);
|
||||
rcc_periph_clock_enable(RCC_GPIOC);
|
||||
rcc_periph_clock_enable(RCC_AFIO);
|
||||
}
|
||||
|
||||
static void gpio_setup(void)
|
||||
|
||||
@@ -28,5 +28,5 @@ MEMORY
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32f1.ld
|
||||
INCLUDE cortex-m-generic.ld
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB CDC-ACM device (aka Virtual Serial Port)
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
5
examples/stm32/f1/lisa-m-1/usb_cdcacm/README.md
Normal file
5
examples/stm32/f1/lisa-m-1/usb_cdcacm/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# README
|
||||
|
||||
This example implements a USB CDC-ACM device (aka Virtual Serial Port)
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/cdc.h>
|
||||
|
||||
@@ -166,7 +166,7 @@ static const char *usb_strings[] = {
|
||||
/* Buffer to be used for control requests. */
|
||||
uint8_t usbd_control_buffer[128];
|
||||
|
||||
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
|
||||
static enum usbd_request_return_codes cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
|
||||
uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
@@ -192,15 +192,15 @@ static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *
|
||||
local_buf[8] = req->wValue & 3;
|
||||
local_buf[9] = 0;
|
||||
// usbd_ep_write_packet(0x83, buf, 10);
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
}
|
||||
case USB_CDC_REQ_SET_LINE_CODING:
|
||||
if (*len < sizeof(struct usb_cdc_line_coding))
|
||||
return 0;
|
||||
return USBD_REQ_NOTSUPP;
|
||||
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
}
|
||||
return 0;
|
||||
return USBD_REQ_NOTSUPP;
|
||||
}
|
||||
|
||||
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep)
|
||||
@@ -213,7 +213,6 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep)
|
||||
if (len) {
|
||||
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0)
|
||||
;
|
||||
buf[len] = 0;
|
||||
}
|
||||
|
||||
gpio_toggle(GPIOC, GPIO5);
|
||||
@@ -240,10 +239,10 @@ int main(void)
|
||||
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_48MHZ]);
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOC);
|
||||
rcc_periph_clock_enable(RCC_OTGFS);
|
||||
|
||||
gpio_set(GPIOC, GPIO2);
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
##
|
||||
|
||||
BINARY = usbdfu
|
||||
CSTD = -std=gnu99
|
||||
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB Device Firmware Upgrade (DFU) bootloader
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
5
examples/stm32/f1/lisa-m-1/usb_dfu/README.md
Normal file
5
examples/stm32/f1/lisa-m-1/usb_dfu/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# README
|
||||
|
||||
This example implements a USB Device Firmware Upgrade (DFU) bootloader
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
@@ -145,11 +145,13 @@ static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_da
|
||||
uint32_t *dat = (uint32_t *)(prog.buf + 1);
|
||||
flash_erase_page(*dat);
|
||||
}
|
||||
break;
|
||||
case CMD_SETADDR:
|
||||
{
|
||||
uint32_t *dat = (uint32_t *)(prog.buf + 1);
|
||||
prog.addr = *dat;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
uint32_t baseaddr = prog.addr + ((prog.blocknum - 2) *
|
||||
@@ -174,39 +176,38 @@ static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_da
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
|
||||
static enum usbd_request_return_codes usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
|
||||
uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)usbd_dev;
|
||||
|
||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request. */
|
||||
return USBD_REQ_NOTSUPP; /* Only accept class request. */
|
||||
|
||||
switch (req->bRequest) {
|
||||
case DFU_DNLOAD:
|
||||
if ((len == NULL) || (*len == 0)) {
|
||||
usbdfu_state = STATE_DFU_MANIFEST_SYNC;
|
||||
return 1;
|
||||
} else {
|
||||
/* Copy download data for use on GET_STATUS. */
|
||||
prog.blocknum = req->wValue;
|
||||
prog.len = *len;
|
||||
memcpy(prog.buf, *buf, *len);
|
||||
usbdfu_state = STATE_DFU_DNLOAD_SYNC;
|
||||
return 1;
|
||||
}
|
||||
return USBD_REQ_HANDLED;
|
||||
case DFU_CLRSTATUS:
|
||||
/* Clear error and return to dfuIDLE. */
|
||||
if (usbdfu_state == STATE_DFU_ERROR)
|
||||
usbdfu_state = STATE_DFU_IDLE;
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
case DFU_ABORT:
|
||||
/* Abort returns to dfuIDLE state. */
|
||||
usbdfu_state = STATE_DFU_IDLE;
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
case DFU_UPLOAD:
|
||||
/* Upload not supported for now. */
|
||||
return 0;
|
||||
return USBD_REQ_NOTSUPP;
|
||||
case DFU_GETSTATUS: {
|
||||
uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
||||
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
|
||||
@@ -217,23 +218,34 @@ static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *
|
||||
(*buf)[5] = 0; /* iString not used here */
|
||||
*len = 6;
|
||||
*complete = usbdfu_getstatus_complete;
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
}
|
||||
case DFU_GETSTATE:
|
||||
/* Return state with no state transision. */
|
||||
*buf[0] = usbdfu_state;
|
||||
*len = 1;
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return USBD_REQ_NOTSUPP;
|
||||
}
|
||||
|
||||
static void usbdfu_set_config(usbd_device *usbd_dev, uint16_t wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
|
||||
if (!gpio_get(GPIOA, GPIO10)) {
|
||||
/* Boot the application if it's valid. */
|
||||
@@ -248,21 +260,17 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_48MHZ]);
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOC);
|
||||
rcc_periph_clock_enable(RCC_OTGFS);
|
||||
|
||||
gpio_set(GPIOC, GPIO2);
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||
|
||||
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings, 4, usbd_control_buffer, sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
usbd_register_set_config_callback(usbd_dev, usbdfu_set_config);
|
||||
|
||||
gpio_clear(GPIOC, GPIO2);
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB Human Interface Device (HID)
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
5
examples/stm32/f1/lisa-m-1/usb_hid/README.md
Normal file
5
examples/stm32/f1/lisa-m-1/usb_hid/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# README
|
||||
|
||||
This example implements a USB Human Interface Device (HID)
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/spi.h>
|
||||
#include <libopencm3/stm32/otg_fs.h>
|
||||
#include <libopencm3/stm32/f1/nvic.h>
|
||||
#include <libopencm3/usb/dwc/otg_fs.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/hid.h>
|
||||
#include "adxl345.h"
|
||||
@@ -56,18 +56,45 @@ const struct usb_device_descriptor dev_descr = {
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
/* I have no idea what this means. I haven't read the HID spec. */
|
||||
static const uint8_t hid_report_descriptor[] = {
|
||||
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,
|
||||
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,
|
||||
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,
|
||||
0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01,
|
||||
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38,
|
||||
0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x03,
|
||||
0x81, 0x06, 0xC0, 0x09, 0x3c, 0x05, 0xff, 0x09,
|
||||
0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95,
|
||||
0x02, 0xb1, 0x22, 0x75, 0x06, 0x95, 0x01, 0xb1,
|
||||
0x01, 0xc0,
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
|
||||
0x09, 0x02, /* USAGE (Mouse) */
|
||||
0xa1, 0x01, /* COLLECTION (Application) */
|
||||
0x09, 0x01, /* USAGE (Pointer) */
|
||||
0xa1, 0x00, /* COLLECTION (Physical) */
|
||||
0x05, 0x09, /* USAGE_PAGE (Button) */
|
||||
0x19, 0x01, /* USAGE_MINIMUM (Button 1) */
|
||||
0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x95, 0x03, /* REPORT_COUNT (3) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */
|
||||
0x75, 0x05, /* REPORT_SIZE (5) */
|
||||
0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
|
||||
0x09, 0x30, /* USAGE (X) */
|
||||
0x09, 0x31, /* USAGE (Y) */
|
||||
0x09, 0x38, /* USAGE (Wheel) */
|
||||
0x15, 0x81, /* LOGICAL_MINIMUM (-127) */
|
||||
0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x03, /* REPORT_COUNT (3) */
|
||||
0x81, 0x06, /* INPUT (Data,Var,Rel) */
|
||||
0xc0, /* END_COLLECTION */
|
||||
0x09, 0x3c, /* USAGE (Motion Wakeup) */
|
||||
0x05, 0xff, /* USAGE_PAGE (Vendor Defined Page 1) */
|
||||
0x09, 0x01, /* USAGE (Vendor Usage 1) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0x95, 0x02, /* REPORT_COUNT (2) */
|
||||
0xb1, 0x22, /* FEATURE (Data,Var,Abs,NPrf) */
|
||||
0x75, 0x06, /* REPORT_SIZE (6) */
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */
|
||||
0xb1, 0x01, /* FEATURE (Cnst,Ary,Abs) */
|
||||
0xc0 /* END_COLLECTION */
|
||||
};
|
||||
|
||||
static const struct {
|
||||
@@ -178,7 +205,7 @@ static const char *usb_strings[] = {
|
||||
/* Buffer used for control requests. */
|
||||
uint8_t usbd_control_buffer[128];
|
||||
|
||||
static int hid_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
|
||||
static enum usbd_request_return_codes hid_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
|
||||
void (**complete)(usbd_device *dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
@@ -187,13 +214,13 @@ static int hid_control_request(usbd_device *dev, struct usb_setup_data *req, uin
|
||||
if((req->bmRequestType != 0x81) ||
|
||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||
(req->wValue != 0x2200))
|
||||
return 0;
|
||||
return USBD_REQ_NOTSUPP;
|
||||
|
||||
/* Handle the HID report descriptor. */
|
||||
*buf = (uint8_t *)hid_report_descriptor;
|
||||
*len = sizeof(hid_report_descriptor);
|
||||
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
@@ -209,7 +236,7 @@ static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req)
|
||||
scb_reset_core();
|
||||
}
|
||||
|
||||
static int dfu_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
|
||||
static enum usbd_request_return_codes dfu_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
|
||||
void (**complete)(usbd_device *dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)buf;
|
||||
@@ -217,11 +244,11 @@ static int dfu_control_request(usbd_device *dev, struct usb_setup_data *req, uin
|
||||
(void)dev;
|
||||
|
||||
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||
return 0; /* Only accept class request. */
|
||||
return USBD_REQ_NOTSUPP; /* Only accept class request. */
|
||||
|
||||
*complete = dfu_detach_complete;
|
||||
|
||||
return 1;
|
||||
return USBD_REQ_HANDLED;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -244,7 +271,7 @@ static void hid_set_config(usbd_device *dev, uint16_t wValue)
|
||||
dfu_control_request);
|
||||
#endif
|
||||
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
|
||||
/* SysTick interrupt every N clock pulses: set reload to N-1 */
|
||||
systick_set_reload(99999);
|
||||
systick_interrupt_enable();
|
||||
@@ -296,13 +323,13 @@ int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE12_72MHZ]);
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_SPI2EN);
|
||||
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
rcc_periph_clock_enable(RCC_GPIOB);
|
||||
rcc_periph_clock_enable(RCC_GPIOC);
|
||||
rcc_periph_clock_enable(RCC_SPI2);
|
||||
rcc_periph_clock_enable(RCC_OTGFS);
|
||||
|
||||
/* Configure SPI2: PB13(SCK), PB14(MISO), PB15(MOSI). */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_10_MHZ,
|
||||
|
||||
@@ -21,7 +21,6 @@ BINARY = adc_injec
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
# README
|
||||
|
||||
This is a simple polling example that sends the value read out from the
|
||||
temperature sensor ADC channel of the STM32 to the USART2.
|
||||
@@ -19,17 +19,17 @@
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/f1/adc.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/adc.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
|
||||
static void usart_setup(void)
|
||||
{
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN);
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
rcc_periph_clock_enable(RCC_USART2);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
@@ -50,8 +50,8 @@ static void usart_setup(void)
|
||||
static void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIO clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
rcc_periph_clock_enable(RCC_GPIOC);
|
||||
|
||||
/* Setup the LEDs. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
@@ -64,10 +64,10 @@ static void adc_setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
|
||||
rcc_periph_clock_enable(RCC_ADC1);
|
||||
|
||||
/* Make sure the ADC doesn't run during config. */
|
||||
adc_off(ADC1);
|
||||
adc_power_off(ADC1);
|
||||
|
||||
/* We configure everything for one single injected conversion. */
|
||||
adc_disable_scan_mode(ADC1);
|
||||
@@ -79,7 +79,7 @@ static void adc_setup(void)
|
||||
adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_JSWSTART);
|
||||
adc_set_right_aligned(ADC1);
|
||||
/* We want to read the temperature sensor, so we have to enable it. */
|
||||
adc_enable_temperature_sensor(ADC1);
|
||||
adc_enable_temperature_sensor();
|
||||
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
|
||||
|
||||
adc_power_on(ADC1);
|
||||
@@ -89,9 +89,7 @@ static void adc_setup(void)
|
||||
__asm__("nop");
|
||||
|
||||
adc_reset_calibration(ADC1);
|
||||
while ((ADC_CR2(ADC1) & ADC_CR2_RSTCAL) != 0); //added this check
|
||||
adc_calibration(ADC1);
|
||||
while ((ADC_CR2(ADC1) & ADC_CR2_CAL) != 0); //added this check
|
||||
adc_calibrate(ADC1);
|
||||
}
|
||||
|
||||
static void my_usart_print_int(uint32_t usart, int value)
|
||||
@@ -122,7 +120,7 @@ int main(void)
|
||||
uint8_t channel_array[16];
|
||||
uint16_t temperature = 0;
|
||||
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE12_72MHZ]);
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
adc_setup();
|
||||
|
||||
@@ -21,7 +21,6 @@ BINARY = adc_injec_timtrig
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user