277 Commits

Author SHA1 Message Date
60c46ba807 Update submodule to use Gitea 2025-09-27 22:44:23 +08:00
Karl Palsson
15637e291b Update library to latest
This includes fixes for peripheral resets, introduced by library
changes:
* b3bdf025d7 stm32: i2c: drop i2c_reset()
* df654d7f28 stm32: spi: drop spi_reset()

Fixes: https://github.com/libopencm3/libopencm3-examples/issues/240
2023-01-16 20:39:31 +00:00
Karl Palsson
9577cd71eb stm32f0: eliminate outdated comments
Fixes: https://github.com/libopencm3/libopencm3-examples/pull/229
2021-11-17 12:48:23 +00:00
Piotr Esden-Tempski
3a8911627d Corrected the clock lookup table.
Due to copypasta we were using the hse table for hsi clocks.
2021-06-20 00:54:16 -07:00
Piotr Esden-Tempski
991bb45710 stm32f429i-discovery/spi: Fixed an OBO index bug. 2021-06-19 02:19:47 -07:00
Piotr Esden-Tempski
4cfc75f715 i2c_stts75_sensor: Replaced the depricated define with number. 2021-06-19 02:19:47 -07:00
Piotr Esden-Tempski
66d622aa7e Fixed an unintended fall through bug. 2021-06-19 02:19:47 -07:00
Piotr Esden-Tempski
e599e34073 Updated all rcc_clock_setups to use the new lookup tables.
The old "one function per config" system is depricated for quite a while
now...
2021-06-19 02:19:47 -07:00
Piotr Esden-Tempski
02f48ef616 Corrected the linker script selection for l0 & l1 examples. 2021-06-19 02:19:47 -07:00
Piotr Esden-Tempski
520e7523ec Updated to the new DAC api. 2021-06-19 02:19:47 -07:00
Piotr Esden-Tempski
0bbafd690a stm32vl-discovery: Corrected linker script. 2021-06-19 02:19:30 -07:00
Piotr Esden-Tempski
4c5ff56168 Updated libopencm3 to the most recent sha. 2021-06-19 00:59:47 -07:00
Santiago Piccinini
882f5b7d1b stm32: cdcacm: fix array out of bounds write
Remove debug leftovers that were causing memory corruption.
Writes of 64 or more bytes from the USB host side caused memory
corruption before this commit.
I've tested it in a STM32L4 board and it is working as expected.
2021-01-24 11:02:40 -03:00
Jeff Kent
4b4115fd72 stm32f429: lcd-dma: Fix LCD clock shift
RCC_DCKCFGR was missing a shift for register write
2020-12-19 00:29:47 +00:00
Karl Palsson
9b7c2c3dbf Update submodule
Primarily to pull in make 4.3 fixes.
2020-02-22 16:20:37 +00:00
Karl Palsson
9830486509 stm32: standard bauds to 115200
See also be1d296 stm32: serial use 115200
In that commit we mostly replaced 38400, now we've cleaned up all of
them to be consistent.
2019-10-24 21:46:56 +00:00
Karl Palsson
6e12785c84 f1:h103: drop incomplete spi example 2019-10-24 21:30:22 +00:00
Karl Palsson
5a828ffb82 Update library
Use the now standard $(PREFIX)gcc form instead of with the -.
more consistent with other projects.
2019-06-07 21:31:44 +00:00
Karl Palsson
be1d296e2f stm32: serial use 115200 baud rate
115200 is a much more sane "default" than 38400.
Instead of a mix of 38400 and 115200, just use 115200 in all places.
There's no reason for modern 32bit cpus to be using such old slow
baudrates.

Tested on f1, f4, l1.  Replaced some old f1 code that predated some
library support code for this.
2019-06-02 20:51:42 +00:00
Karl Palsson
e0f377fec0 stm32f4: use new rcc_clock_setup_pll()
Batch replaced to use new api.  User code doesn't need this, but
examples should be up to date, and this avoids deprecation warnings.
2019-06-02 20:39:56 +00:00
Karl Palsson
2cd847eab1 Update library to pick up new f4 rcc apis 2019-06-02 20:39:56 +00:00
Karl Palsson
4f4e6f9ef2 stm32f4: use 168MHz instead of intermediate 120MHz
120MHz is being removed in the library.
2019-06-02 16:02:43 +00:00
Karl Palsson
fed62e7ef4 stm32l1: button-irq-printf: add syscfg clock.
Not strictly required as we're using port A out of the box, but makes
for bad example code, when the syscfg clock is required for selectin
exti sources other than port A.
2019-06-01 16:20:13 +00:00
Karl Palsson
c9fe1da748 stm32l4: include missing makefile
Fixes: b8b97209 stm32l4: basic uart/exti/led/clock demo

which introduced the l4 example, but left out the makefile.include file
and didn't add it to the root build.

Reported at: 2a7e4fac14
2019-05-27 11:23:46 +00:00
Karl Palsson
591d715d52 update library submodule 2019-05-25 21:33:10 +00:00
Karl Palsson
90262eb880 stm32-h103: use proper HSE for USB
HSI is out of spec for reliable USB operation, even though it sometimes
works.  stm32-h103 board has an 8Mhz external crystal which should
therefore be used for any USB work.

Originally reported as https://github.com/libopencm3/libopencm3-examples/pull/192
2019-04-21 21:50:42 +00:00
Karl Palsson
f9713ff865 Update library ref 2019-01-20 13:08:33 +00:00
Karl Palsson
b7aac4bc76 stm32f4/usart: use 115200 baud rate
38400 is uncommon and slow.  Just live in the modern world of at least
115200.
2018-10-07 13:43:21 +00:00
Karl Palsson
d434a00323 reference miniblink repos 2018-08-29 14:31:16 +00:00
Karl Palsson
236428e74b readme: refer to template instead of lengthy reuse steps 2018-08-29 14:20:57 +00:00
Karl Palsson
dc2142b729 rules: attempt rebuild of library of not found
Based on https://github.com/libopencm3/libopencm3-examples/pull/90
2018-08-29 11:54:43 +00:00
Karl Palsson
f09dd550fd tiva/lm4f: drop unnecessary externs
These were added to the library as for other usb drivers.
2018-08-29 10:32:56 +00:00
Karl Palsson
3527ce407e stm32f3: usb: use proper clocks
Don't use the HSI clock, that's not specced for USB use.
Also, drop the unnecessary delays that were working around old bugs.
2018-08-29 10:32:56 +00:00
Karl Palsson
8faca31dc5 stm32f3: update examples for new library code 2018-08-29 10:32:56 +00:00
Karl Palsson
87680cd122 doc: linker generator is now in plain old python
No more mawk/gawk problems.
2018-08-29 10:32:56 +00:00
Karl Palsson
7c121eda94 update to latest library 2018-08-29 10:32:56 +00:00
Nicolas Schodet
5b30e3d98d Fix usage of USB_VBUS
USB_VBUS is not an alternate function, it is an additionnal function which is
always enabled.

If configured as an alternate function, it will draw current from VBUS.
2018-07-03 22:42:44 +00:00
Markus Barenhoff
ce364386d6 stm32f429: allow using all of ram 2018-07-03 22:38:04 +00:00
Karl Palsson
fe6a2b5f13 make clean: avoid bashisms in favour of posixy forms.
Got a little too clever.
2018-06-08 09:53:09 +00:00
Karl Palsson
21ce202a07 properly clean .d files
And also, _only_ clean our own files, not both a hard list of all files,
just the ones we built ourselves
2018-06-07 11:42:44 +00:00
Karl Palsson
37126c5f02 last try markdown
Apparently, we were't a "proper" numeric list.
2018-05-04 10:22:14 +00:00
Karl Palsson
cef41e465d markdown is wonderful
Autonumbering and indenting broken by mixing "compatible" styles of code
formatting.
2018-05-04 10:20:05 +00:00
Karl Palsson
6bca6aaf02 Update readme for reuse and multi source 2018-05-04 09:55:32 +00:00
Karl Palsson
bc9ad8df08 travis: get notifcations on build status for examples too 2018-05-02 11:09:55 +00:00
Karl Palsson
4ddb9db8b9 update linker scripts to use common generic files 2018-05-02 11:01:28 +00:00
Karl Palsson
daff5b130a update library to latest 2018-05-01 22:26:36 +00:00
Karl Palsson
8c6c8720bf stm32f3: cdcacm: fix grossly misleading comments 2018-05-01 22:14:26 +00:00
Karl Palsson
301b4f9194 update usb enum return codes
Should have been fixed in commit 85be1e5e7b when we updated the library, but was... missed.
travis caught it after the fact at least.
2018-03-04 13:57:29 +00:00
Karl Palsson
a4eec6026b travis: add basic build check
And a badge to the readme.
2018-03-04 13:30:44 +00:00
Karl Palsson
b8b9720926 stm32l4: basic uart/exti/led/clock demo
No miniblink, let people interpret a more useful example.
2018-03-04 00:24:39 +00:00
Karl Palsson
7d6a2e36ee update library to get exti for l4 2018-03-04 00:24:39 +00:00
Karl Palsson
85be1e5e7b update to current library
Minor api changes required.
2018-03-03 21:42:52 +00:00
saogalde
bcf608fa54 readme: use full gdb commands
gdb will actually accept as little "tar ext :4242" but use the full
commands to help clarify the intent for people who might not be as
familiar with the syntax.
2018-01-08 10:04:26 +00:00
Peter Mortensen
6e71b9dea8 stm32f0: miniblink: update comments to match code
Brought the comments up to date wrt. the actual code (inconsistency removed).
2018-01-08 10:02:47 +00:00
Paul Fertser
f4e129cd4a rules.mk: Add cross-reference to the map file
This adds a section to the bottom of the .map file containing the
symbol->object file mapping.  (the logical inverse of the existing
section at the start of the .map file that lists objects, and the
symbols that pulled them in)

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2017-12-18 12:28:52 +00:00
Paul Fertser
6dbc067b3e Add maximum debugging info to ELF; doesn't affect binary size 2017-12-18 12:17:50 +00:00
Karl Palsson
f368819e81 Update to current master library
can fixes are compile tested only.  I don't have those boards.
f3 i2c is tested on i2c and gives the same results
l1 low power demo seems to have been broken for some time already.
 => should be fixed, but not something I'm going to work on right now.
2017-09-01 23:19:46 +00:00
Karl Palsson
d6876b1f77 f3:i2c: use printf and update docs
Preparations for updating the tree was making sure the existing example
worked :)
2017-09-01 23:01:56 +00:00
Jelmer Tiete
2107faf5ee rules: drop broken stlink util support
There was an attempt at providing support for the texane/stlink utility.
It has been broken for a long time, referring to missing scripts.
Remove it as clearly unused.
2017-08-25 14:58:41 +00:00
Jelmer Tiete
1f322c1cef rules: flash target helpers had broken script paths 2017-08-25 14:58:20 +00:00
Sergey Alirzaev
fc60651b6a stm32f4-discovery: add new board revision 2017-08-25 14:55:45 +00:00
Chuck McManis
766f89c724 Better Debugging in make
This commit does two things, it removes the "Quiet" flag
from the flash target so you can see what it is trying to
do when it trys to flash your code, and it adds a make
target print-% which can be used to print the resolved
value of make variables (also helpful in figuring out
what it is trying to do).
2016-12-29 15:38:50 +00:00
Karl Palsson
d23bee4f1a docs: mention targets might need GNU awk 2016-12-27 21:43:04 +00:00
Karl Palsson
1b92d46b97 docs: try and clear up how "make flash" works
Likely to be insufficient, but perhaps a start.

See https://github.com/libopencm3/libopencm3-examples/issues/34
2016-12-27 21:41:08 +00:00
Karl Palsson
c03b580722 stm32: morse timer: remove WFI where not critical
__WFI is not standardized, though often provided.  As it's not a core
part of this example, drop it.
2016-12-17 00:24:36 +00:00
Karl Palsson
9af2b8c7fb stm32: morse timer: standardize example
Simplify, clarify and synchronize the two morse LED blinker examples.
Prepare for one day extracting the core as common morse example code.
2016-12-17 00:23:10 +00:00
Karl Palsson
d2abd471a5 stm32: timer: further clarify example commentary
The "timer" example is actually "the same" for both f1 and f4.  Do a
sanity sweep over the commentary, remove all vestiges that this was
cloned from a motor control example, and synchronize both examples.

Future work should extract the common portions "somewhere" but at least
make them consistent for now.
2016-12-16 22:41:15 +00:00
Valentin Ochs
da04ccdf71 stm32: timer: Clarify some misleading comments.
Start clearing up misleading/redundant commentary.
2016-12-16 22:35:22 +00:00
Karl Palsson
1260b16772 timer_reset -> rcc_periph_reset_pulse() replace
timer_reset wasn't fully implemented for all timers on all series, and
was simply a wrapper of the RST bits in the RCC registers anyway.

First part of https://github.com/libopencm3/libopencm3/issues/709
2016-12-16 21:32:36 +00:00
Karl Palsson
833da68c18 f1: h103: drop duplicate usb_hid example.
This example was functionally similar to the "other" example, but had
the actual functional mouse movement disabled.  To reduce maintennance
cost with slightly divergent examples, simply drop the less useful
example.
2016-12-16 21:27:25 +00:00
Karl Palsson
8fae7811a8 stm32f1: ubshid: add re-enumeration forcing.
This makes the demo reliably work on "generic" "other" style f1 boards
out of the box.
2016-12-16 21:27:25 +00:00
Karl Palsson
23001dfbcb stm32f1: hid: drop irrelevant gpio A15 config
Relates to jtag vs swd on some specific board, but not relevant to the
demo.
2016-12-16 21:27:25 +00:00
Karl Palsson
c22200ceb5 stm32f4: clarify input mode comment
Based on irc discussion, make the comment more accurately reflect what
the code is doing.
2016-11-23 17:36:01 +00:00
Karl Palsson
ed6973584c f3: adc: drop the _worst_ of the bad code
The example is pointlessly complicated and includes lots of dead code,
but at least remove the wasteful and confusing references to the
temperature channel as pointed out on github.
2016-10-28 17:39:38 +00:00
Roland Hieber
bb8f4699da stm32 button: use more idiomatic GPIO read
Using GPIOA_IDR directly looks a bit arcane, and the example can benefit
from introducing gpio_get() and how to use it.  The stm32f0-discovery
example already does it like this.
2016-10-11 19:51:51 +02:00
Karl Palsson
4dfa31f9f8 rules.mk: flash: send full path for existing openocd
When using netcat to send commands to an already existing openocd
session, you must path full paths to the file to flash.  There's no
guarantee that it is running from the same directory as the present
example
2016-10-04 20:25:49 +00:00
Karl Palsson
eb54fbf285 adc: update to standardized calibrate api
Drop leftover code from before they were blocking, unify all to standard
api.
2016-10-01 16:13:45 +00:00
Karl Palsson
fc690fd6c4 upgrade library to latest.
Requires changes to all temperature sensor enabling on f1.
2016-10-01 16:02:26 +00:00
Karl Palsson
9fbac7daaf .gitignore more project files
add intellij (clion/pycharm) and eclipse project files to the ignore
list.
2016-09-02 21:12:28 +00:00
Chuck McManis
da679c1775 [Makefile]: add objects to clean target
Some demos will use object files from a different directory and
those files would not be cleaned by the simple CLEAN rule. This
small change insures that those objects and their dependency files
are also cleaned.
2016-08-18 22:51:55 +00:00
Karl Palsson
bcd7d57c11 make flash: overhaul openocd configuration
Instead of OOCD_SERIAL triggering an attempt to use a specific ftdi based
adapter, introduce common target/interface pairs, OOCD_INTERFACE and
OOCD_TARGET, and an override via OOCD_FILE allowing full control.

Further, attempt to connect to a running openocd instance to flash if possible.
This _will not_ work well if you have multiple openocd instances open at once,
but that's a rare use case.

Examples:
OOCD_INTERFACE=stlink-v2
OOCD_TARGET=stm32f0x
 --> openocd ... -f interface/stlink-v2.cfg -f target/stm32f0x.cfg)

OOCD_FILE=board/ek-lm4f120xl.cfg
 --> openocd ... -f $(OOCD_FILE)  (ie, the variable is passed untouched)

As part of implementing this, correct variables that were always wrong, and
update the openocd flashing commands to use current commands.
2016-08-18 22:41:23 +00:00
Karl Palsson
b227e1609c rules: provide default C and C++ standards
Default CSTD to c99, no default for CXXSTD, but if provided it will be used.

Add required gnu99 flags to projects using gnu styles.
2016-08-18 22:41:23 +00:00
Karl Palsson
408b83f47a make: provide "examplesclean" to avoid cleaning library as well
We already have "make examples" and "make lib" but make clean cleans
everything.  Not super useful for end users, but rather handy for people
working on the examples.
2016-08-18 22:41:23 +00:00
Karl Palsson
30667fe62c rules: rename file only.
Trivial rename, allow vim to properly detect the file as a makefile.
2016-08-18 22:41:23 +00:00
Karl Palsson
133a45b734 atmel samd: initial blinky demo
Uses the DEVICE linker and config generation style.
2016-08-18 22:41:23 +00:00
Karl Palsson
b5fcf55005 stm32f4: switch two examples to linker generation
Proves that the tree can have projects specifying the linker script explicitly,
and also "modern" projects specifying simply the DEVICE= variable.
2016-08-18 22:41:23 +00:00
Karl Palsson
0f04829415 gitignore generated linker script files 2016-08-18 22:41:23 +00:00
Karl Palsson
de0d4af890 make: enable DEVICE _or_ LDSCRIPT to be specified
First step towards migrating towards generated devices.
2016-08-18 22:41:16 +00:00
Karl Palsson
52b12d5259 update library: pickup devices.data and friends 2016-08-18 22:39:25 +00:00
Karl Palsson
140d0864b8 rules: use TGT_xxx to avoid trampling user vars
As in the main library, instead of constructing and making our own CFLAGS
CXXFLAGS and LDFLAGS variables, use TGT_ for ones we construct, and include any
user provided variables afterwards.
2016-08-18 22:39:25 +00:00
Karl Palsson
4b772a4437 rules: pull up optimization level 2016-08-18 22:39:25 +00:00
Trevor Woerner
a5641ab63e cookie_io fixes for gcc-5.3
Using the latest (as of today) gcc-arm-embedded toolchain caused two build
failures similar to:

	error: unknown type name 'cookie_io_functions_t'

These custom IO functions are now protected by a define, so define _GNU_SOURCE
which enables all such areas. This is a libc issue.

Signed-off-by: Trevor Woerner <twoerner@gmail.com>
2016-06-17 10:31:56 -04:00
Karl Palsson
8924042d2a stm32f4: timer: correct misleading comments.
Code was correct, comment was badly imported.
2016-05-03 21:14:09 +00:00
Karl Palsson
5b35c7d7a1 rules: provide better feedback on missing libraries.
If the library files are missing (haven't been built) it's better to get a
failure message saying that, rather than a failed dependency with no rules to
generated it.

Before: (I'd manually removed the f4 library)
```
$ make clean all V=1
Using ../../../../../libopencm3/ path to library
rm -f *.o *.d *.elf *.bin *.hex *.srec *.list *.map
make: *** No rule to make target `adc-dac-printf.elf', needed by `elf'.  Stop.
```

After:
```
$ make clean all V=1
Using ../../../../../libopencm3/ path to library
rm -f *.o *.d *.elf *.bin *.hex *.srec *.list *.map
arm-none-eabi-gcc -Os -g -Wextra -Wshadow -Wimplicit-function-declaration
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -fno-common
-ffunction-sections -fdata-sections -MD -Wall -Wundef
-I../../../../../libopencm3//include -DSTM32F4 -mthumb -mcpu=cortex-m4
-mfloat-abi=hard -mfpu=fpv4-sp-d16 -o adc-dac-printf.o -c adc-dac-printf.c
arm-none-eabi-gcc --static -nostartfiles -L../../../../../libopencm3//lib
-T../stm32f4-discovery.ld -Wl,-Map=adc-dac-printf.map -Wl,--gc-sections -mthumb
-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 adc-dac-printf.o
-lopencm3_stm32f4 -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group -o
adc-dac-printf.elf
/home/karlp/tools/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
cannot find -lopencm3_stm32f4
collect2: error: ld returned 1 exit status
make: *** [adc-dac-printf.elf] Error 1
```

I strongly feel that the latter is far more informative.
2016-04-17 00:21:24 +00:00
Alexandru Gagniuc
07c2326f7e examples/tiva/lm4f: Use correct openocd interface
I'd love to meet the person who managed to use flossjtag interface
with a Stellaris board, but until we can meet, use the correct
interface, which is ti-icdi. Note that this setting is redundant,
since the board config file already specifies the correct interface;
however, OOCD_INTERFACE variable cannot be empty, by virtue of how
higher-level makefiles are written.
2016-04-11 23:27:23 +00:00
Karl Palsson
9f8d37d8c8 stm32f4: usb midi: use unique serial numbers
The unique serial number from the device unique signature block was never used
in any examples.  Add it to the these two usb midi examples, to have a user for
this api available for reference.
2016-04-11 23:24:23 +00:00
Karl Palsson
2092a6759d update libopencm3
This brings in the new ADC api for STM32 parts.

Update to new standardized ADC apis.
Drops pointless channel definitions, uses common names for common functions.
No functional changes.

Based on work in: https://github.com/libopencm3/libopencm3-examples/pull/130
2016-04-10 13:49:07 +00:00
Karl Palsson
b50cdb56de stm32f0: systick_blink: Robustness and correctness fixes
Update documentation and comments in code to reflect reality.
Ensure that GPIO pin output speed is actually set, to ensure that 48Mhz sysclk
output is functional.
Actually set AF, instead of relying on reset values.
Replace the systick code, the core of this example, with some code that has
less traps and surprises.  Instead of trying to get a direct interrupt x times
per second, and reguarly running into problems with the 24 bit counter limit,
use a method that triggers an interrupt every x ms instead.  Tested MCO and
blink rates with a logic analyser, properly verified working now :)
2016-04-07 22:04:03 +00:00
Karl Palsson
dfc4763ab3 scripts: import BMP helper scripts from library.
These should have been moved over when the library was initial split.
Even if we eventually drop any attempt at flash support, at least have all the
files here.
2016-02-29 21:33:22 +00:00
Karl Palsson
7bbc57df75 Drop explict M3 reference from readme.
While the library and project remain libopencm3, there's no reason to
explicitly limit things to M3 in the introductory text.
2016-02-08 14:07:54 +00:00
Fabian Bartschke
ec1d59e344 stm32f4-discovery: correct part number for alternatives
STM32F401 Discovery is labelled MB1115B:
http://www.st.com/stm32f401discovery
2016-01-21 00:08:11 +00:00
Karl Palsson
b22ea8b616 stm32f1: maple LED is on A5.
Fix incorrect RCC port.  Only applies to "maple" not to maple mini.

Fixes github issue #117
2016-01-11 10:01:22 +00:00
Zhiyuan Wan
7322fdcdb9 stm32f103: fix all usb driver
Correctly migrate stm32f103_usb_driver to st_usbfs_v1_driver instead of the
f107 driver.

Fixes: 976720c355
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2016-01-03 14:51:12 +00:00
Piotr Esden-Tempski
8ce9536b2e Added gitter chat badge. 2015-12-15 17:41:07 +01:00
Piotr Esden-Tempski
976720c355 Updated libopencm3 to current master. Made all examples compile again.
Be specifically careful with the usb examples. There is likely some
breakage to be expected, not sure I updated all the drivers to the
correct types for the respective chips.
2015-12-15 00:56:25 +01:00
Piotr Esden-Tempski
f0009c64dc Added some more files to gitignore. 2015-12-15 00:06:06 +01:00
Andrew Chen
2314635cf0 Makefile.include: don't override DEFS
Allow examples (such as usart-semihosting) to set DEFS for their own use,
and _then_ add the target definitions.
2015-12-10 15:51:57 +00:00
Karl Palsson
070e5bbb94 make: allow specifying OPENCM3_DIR on command line
Allow specifying the path to the library on the command line, without
editing the makefile
2015-10-21 15:19:53 +00:00
Karl Palsson
3a275fb601 make: respect OPENCM3_DIR variable
When checking for the existing of the library, respect the variable
that's defined instead of checking a hardcoded path.
2015-10-21 15:19:49 +00:00
Karl Palsson
393fe8e449 stm32: usb: register control handlers in config callback
As found in 6f2b39c1be6a8b9531264d92138dc2629d51cfa0, you can't just register a
control callback by itself, you can only register them in the set config
callback, (or, at least, _after_ set config has been done.

This has been compile tested only for the extra examples that were found to
have this failing pattern.
2015-08-23 15:02:34 +00:00
Jan
dd0e48369d stm32f1: fix h103 usbdfu example
This has been broken since f87170e when set config started clearing control
handlers to be re-registered by different configurations.

Fix this example to use a set config callback to setup control transfer
callbacks, just like CDC-ACM demos.  With this fix, this demo works with
dfu-tool 0.8

Signed-off-by: Karl Palsson <karlp@tweak.net.au>
2015-08-23 15:02:20 +00:00
Karl Palsson
a6c183d470 vf6xx: merge gpio/uart examples
The plain "uart" example was just a slightly less featured version.
Compile tested only!
2015-07-16 17:17:12 +00:00
Stefan Agner
1123768e78 vf6xx: add GPIO example
This example muxes two pins as GPIO and enables one GPIO (logical
high). The other GPIO is then read in the main loop. One can use
a jumper to bridge the two GPIOs to see that also reading succeeds.
2015-07-16 17:10:11 +00:00
Stefan Agner
0b9e7d0d5d vf6xx: add UART example
The UART's baud rate is calculated using the current clock
configuration from the clock module. This example makes use
of the standard C library and writes the characters to the
UART in blocking mode.
2015-07-16 17:10:11 +00:00
Karl Palsson
849bdc8001 build ti/nxp examples again
Note, lpc43xx still fails to build, so still disabled!
2015-07-16 16:56:32 +00:00
Karl Palsson
b7c04b4eee docs: try and clarify that you should look in other directories 2015-07-16 16:30:17 +00:00
Karl Palsson
a023b0a7ca stm32f1: rtc: drop redundant ld script
Now that this is known targetting h103 board, drop the duped ld script.
2015-07-16 16:28:07 +00:00
Karl Palsson
3a06a8d24c stm32f1: other: rtc example is actually for h-103 board
Move it into the directory already available for this board.
No code changes, just clarifies it a little bit
2015-07-16 16:25:46 +00:00
Ken Sarkies
697d4f307a STM32F1xx RTC example: Change usart_send to blocking form to allow time to send characters
Tested with ET-STAMP-STM32
2015-07-16 16:23:43 +00:00
Karl Palsson
b779843799 update library 2015-07-15 12:28:37 +00:00
Priit Laes
48b2f10e66 [BUILD] Report proper error when linker script cannot be found. 2015-06-28 22:53:55 +03:00
Karl Palsson
be988d74ca makefiles: clean should cleanup stylecheck as well. 2015-05-17 18:20:23 +00:00
Piotr Esden-Tempski
c6af45ba8f [nucleo-f411re] Stylefix. 2015-02-24 19:47:28 -08:00
Chuck McManis
d90d72291a USART with Standard I/O
This example takes advantage of the big Flash memory space and
uses the standard library functions printf, and fgets to
implement a simple interactive application.
2015-02-24 19:44:14 -08:00
Chuck McManis
4837775449 Nucleo F411RE - Simple USART example
Same as the one for other boards
2015-02-24 19:44:14 -08:00
Chuck McManis
8019726f51 Nucleo Examples F411RE 2015-02-24 19:44:14 -08:00
kbob
9cee61f089 [stm32f429i-discovery] Added LTDC DMA example.
This example is just using buffers and built in alpha overlay
functionality to animate a dmond floating on a checker board. After
initializing of the frame buffers only 7 registers are being modified to
implement the animation.
2015-02-24 17:14:57 -08:00
Piotr Esden-Tempski
408ba8c885 Updated libopencm3 to the newest version. 2015-02-20 20:51:59 -08:00
Chuck McManis
22f59c4583 LCD version of the Mandelbrot example
This version is the ASCII one but uses the LCD display
that is attached to the board for a more colorful result.

This example also zooms into a more "interesting" place in the set so
the display stays interesting during the full 100 generations.
2015-02-16 18:13:28 -08:00
Piotr Esden-Tempski
4de8d15303 [stm32f4-discovery] Using WFI instead of nop in the main loop.
WFI (Wait for Interrupt) tells the processor to suspend untill the next
interrupt is called. Better than burning away the cycles with nop.
2015-02-13 16:41:18 -08:00
Piotr Esden-Tempski
ec7c0f318b [stm32f4-discovery] Added timer example for the stm32f4 discovery board. 2015-02-13 16:41:18 -08:00
Piotr Esden-Tempski
5b26d350ff Updated locm3. 2015-02-13 16:36:15 -08:00
Piotr Esden-Tempski
51dda90570 [stm32f429i-discovery] Replaced the ctrl-c handler in console for a shorter version.
Thanks to ChuckM for that.
2015-02-05 16:34:36 -08:00
Piotr Esden-Tempski
8c6eb9ca57 [stm32f429-discovery] General sweep to fix style according to make stylecheck. 2015-02-04 20:39:32 -08:00
Piotr Esden-Tempski
c06aba1603 Removed the use of ITM_Sendchar. 2015-02-04 17:07:57 -08:00
Chuck McManis
0a863789b0 Additional cleanup on lcd-serial
Remove the ISR function and remains of the hack in lcd-spi.c and
convert console.c to use the LOC3 system reset code rather than
the hack which only works on the F4 as it turns out.
2015-02-04 16:48:36 -08:00
Chuck McManis
5379525a87 Updated the LCD SPI
Now that I know a bit more about how SPI is working on the STM32F4
I removed the egregious hack and replaced it with some cleaner code
for driving the LCD. On the positive side it gets a faster update
rate on the screen.
2015-02-04 16:48:18 -08:00
Chuck McManis
b76c30cdb0 Fixups 2015-02-04 16:34:03 -08:00
Piotr Esden-Tempski
d29e4d2b7c [stm32f429i-discovery] Moved Chucks remaining examples to the correct directory.
Additionally added Chucks readme to the stm32f429i-discovery board
readme.
2015-01-22 18:38:16 -08:00
Piotr Esden-Tempski
86c42bc2dd [stm32f429i-discovery] Switched over to UART1.
UART1 is connected through two jumpers to the programmer chip on the
board. Making the use of it very streight forward.
2015-01-22 18:27:28 -08:00
Piotr Esden-Tempski
d6cb05d792 [stm32f429i-discovery] Moved Chucks usart irq example to usart irq console.
Chucks irq example is more elaborate than the ported one so we keep
both.
2015-01-22 16:08:28 -08:00
Piotr Esden-Tempski
fbcb1ca66e [stm32f429i-discovery] Moved Chucks example to usart_console
Chucks example is more elaborate than the simple ported example so we
keep both.
2015-01-22 16:05:48 -08:00
Piotr Esden-Tempski
ed4bec540c [stm32f429i-discovery] Removed Chucks blink example. 2015-01-22 15:57:20 -08:00
Piotr Esden-Tempski
c18a16d979 [stm32f429i-discovery] Merge and delete systick blink example.
Added Chucks improvements to the systick example into the ported one.
2015-01-22 15:51:20 -08:00
kbob
7629bb01e6 Switched from USART 2 to USART 1. 2015-01-21 02:00:08 -08:00
Piotr Esden-Tempski
71b2c1991f [style] Trailing white space fixes. 2015-01-20 16:27:50 -08:00
Piotr Esden-Tempski
ea5af55b92 [stm32f4-discovery] Reverted addition of console. 2015-01-20 16:18:43 -08:00
Chuck McManis
a3ff2c9250 Intermediate step in the examples tree, looking to get USB working correctly on the
429 still
2015-01-20 16:12:57 -08:00
cmcmanis
e4d106dce6 Updated to use the new rcc_periph_clock_enable code 2015-01-20 16:12:57 -08:00
cmcmanis
ae9c116e30 Pulling in some of the makefile changes that are in master into this
branch to make merging easier later on.
2015-01-20 16:12:56 -08:00
cmcmanis
4defd3e1d2 The SPI-MEMS example, its not great but it does use the SPI
port and can tell you the temperature of the room you are in.
2015-01-20 16:12:56 -08:00
cmcmanis
e5585dd07d Some examples for the STM32F4-Disco board 2015-01-20 16:12:56 -08:00
Piotr Esden-Tempski
2583cc54cc [rcc_periph_clock_enable] Using the new rcc enable format.
We are missing handling of stm32l1 AHBLP clock rail.
2015-01-20 15:33:00 -08:00
Piotr Esden-Tempski
1c4ae95729 [README] Coarse sweep to use markup in READMEs.
This should improve online readability of the readme files.
2015-01-19 19:20:12 -08:00
Piotr Esden-Tempski
ab7efee88e [README] Renamed all readme files to indicate markup format. 2015-01-19 19:19:42 -08:00
Piotr Esden-Tempski
64761d405b [README] Converted to markdown for better readability online. 2015-01-19 18:04:33 -08:00
Piotr Esden-Tempski
aae10c6dcb [README] Added some more information about the flash target. 2015-01-19 17:38:37 -08:00
Piotr Esden-Tempski
397780799a [copyright] Added credit copyright for Laurent. Thanks! 2015-01-19 15:54:08 -08:00
Barattero Laurent
f6a1a3ee14 adding spi exemple to stm32vl-discovery 2015-01-19 15:47:39 -08:00
Piotr Esden-Tempski
ddd5d5a918 [copyright] Updated copyright credits on some newly added files.
We need to go through all the examples and make sure we credit them
accordingly.
2015-01-15 17:09:30 -08:00
Piotr Esden-Tempski
1120b3f1b5 [stm32f429i-discovery] Added toplevel README. 2015-01-15 16:59:39 -08:00
Piotr Esden-Tempski
4f1db00763 [stm32f429i-discovery] Added adc-dac-printf example. 2015-01-15 01:58:25 -08:00
Piotr Esden-Tempski
016923e654 [stm32f429i-discovery] Added dac dma example. 2015-01-15 01:06:48 -08:00
Piotr Esden-Tempski
dfac3be665 [stm32f429i-discovery] Added mandelbrot set example. 2015-01-14 18:51:45 -08:00
Piotr Esden-Tempski
ddd0312b10 [stm32f429i-discovery] Added random blinking example. 2015-01-14 18:44:04 -08:00
Piotr Esden-Tempski
1346cd0156 [stm32f429i-discovery] Added usb mass storage example. 2015-01-14 18:43:39 -08:00
Piotr Esden-Tempski
92c228bc63 [stm32f429i-discovery] Added usb cdcacm example. 2015-01-14 18:35:07 -08:00
Piotr Esden-Tempski
50b3522e7a [stm32f429i-discovery] Added tick blink example. 2015-01-14 18:28:00 -08:00
Piotr Esden-Tempski
25d924f699 [stm32f429i-discovery] Added button example. 2015-01-14 18:23:01 -08:00
Piotr Esden-Tempski
7bf64424ab [stm32f429i-discovery] Added USART IRQ example. 2015-01-14 18:16:03 -08:00
Piotr Esden-Tempski
23c29f1784 [stm32f429i-discovery] Added usart example. 2015-01-14 18:16:03 -08:00
Piotr Esden-Tempski
ae17f5a77b [stm32f429i-discovery] Added miniblink example. 2015-01-14 18:15:53 -08:00
Piotr Esden-Tempski
a0d379f460 [stm32f429i-discovery] Added usbmidi example.
This board connects the USB HS interface to the micro usb connector as
opposed to the USB FS interface on the stm32f4-discovery board. This is
why we are using different pins, different periph and different driver.
At the end it should(TM) behave the same as the HS interface implements
FS too.
2015-01-14 16:50:44 -08:00
Piotr Esden-Tempski
e8694d561f [stm32f429i-discovery] Added fancyblink example.
For some reason when setting the ram size to 256 in the linker file we
are getting a memory access error. Needs more investigation.
2015-01-14 16:21:56 -08:00
Daniel Thompson
75389c665d stm32f4: usb_midi: Introduce example MIDI firmware
Tested on STM32F4Discovery with Linux host using both amidi (raw
messages to/from device) and a synthesizer (note on/off) and on
Windows 7 using MIDI-OX.
2014-12-18 22:51:06 +00:00
Karl Palsson
766be687dc update lib to latest, and fix for changes
rcc_core_frequency -> rcc_ahb_frequency
2014-12-18 22:10:54 +00:00
Karl Palsson
1215603031 update lib to latest, and fix for changes
rcc_core_frequency -> rcc_ahb_frequency
2014-12-18 22:08:34 +00:00
Karl Palsson
1b2f9db18f stm32:l0: miniblink example
Very basic, as all miniblinks.
2014-12-04 13:10:15 +00:00
Karl Palsson
312540a0e5 lib: Update to fetch latest l0/f0 updates. 2014-12-03 11:21:46 +00:00
Karl Palsson
058298fd78 Update library to get spi fix 2014-10-11 17:42:34 +00:00
Nikolay Merinov
2372d8b59f stm32/l1: lcd: example using the LCD 2014-10-07 22:30:20 +00:00
Karl Palsson
2ba1619889 Update library for new gpio_toggle 2014-10-07 12:02:04 +00:00
Karl Palsson
3f4515438a Update upstream library 2014-10-07 11:51:01 +00:00
Karl Palsson
a15300d9e4 Update upstream library. 2014-09-30 22:38:34 +00:00
Karl Palsson
9852282bcf stm32f4: drop dead code from usb example.
Presumably code that attempted to toggle a led, but it wasn't setup, and it's
not in any other examples.  Kill it for now.

Reported-by: stefanct on irc.
2014-08-21 23:56:34 +00:00
Frantisek Burian
7f215cb6fa Use libopencm3 coding style 2014-07-14 13:44:44 +02:00
Frantisek Burian
bc5d0816e5 MSC: Use another PID to load correct drivers 2014-07-14 13:44:43 +02:00
Pavol Rusnak
7c07ed97a6 example for MSC (Mass Storage Class) support 2014-07-14 13:44:43 +02:00
Frantisek Burian
54c5c77823 Update the library to the newest version 2014-07-14 13:44:43 +02:00
Karl Palsson
4aaae0086a stm32f4: Document which discovery board the examples are for
Try and reduce a little confusion if we can.
2014-07-11 13:13:17 +00:00
Karl Palsson
05d46ab6cd make V=1 no longer spews linker garbage collection
make V=99 will, if you realllly want it.
2014-04-05 13:14:56 +00:00
Karl Palsson
6960d2adef stm32l1: correct misleading comments
Even though we eventually want to replace some of these magic defines with
board info files, let's still have correct comments.
2014-04-05 13:12:36 +00:00
Frantisek Burian
bd76fb8661 Update the library submodule to the newest version. 2014-03-23 21:24:55 +01:00
Frantisek Burian
dd320a6e99 [STYLE] Revert the 'const' warning in cdcacm examples.
Examples are now compilable without warnings.
2014-03-23 21:20:41 +01:00
Karl Palsson
49760aa021 README: Include notes on reuse
This is just one way of doing it, but it shows the basic steps
2014-03-23 12:44:09 +00:00
Karl Palsson
abf774c0f4 Bump libopencm3 submodule
No new examples require this, but it's a better base for stm32f0 and any lcd
work.
2014-03-11 22:05:31 +00:00
Karl Palsson
f94a821712 gitignore netbeans project files
Just in case ;)
2014-03-08 15:20:58 +00:00
Karl Palsson
64ecb61543 f0: remove toolchain specific options
While nano specs are certainly handy, it should be documented how to use them,
not turned on by default.  People with otherwise valid toolchains, who might
simply not care about nano specs are unable to build the examples with these
options.
2014-03-08 15:03:36 +00:00
Frantisek Burian
8ffaf0579d Fix the bug in compilation in the style fix run. 2014-02-13 20:24:22 +01:00
Uwe Bonnes
06208be477 Whitespace changes in the tiva(stellaris/lpc directory structure commit 2014-02-13 20:04:34 +01:00
Uwe Bonnes
1740fee230 tiva(stellaris)/lpc: Use directory structure as stm32
EDIT: Whitespace changes to the files stripped out.
2014-02-13 20:00:25 +01:00
Frantisek Burian
3af1f8d43d [BUILD] Make the binaries only needed for the user
User can specify which binaries he needs on the commandline.

'make hex' will build examples with generating hex file
'make hex bin' will build hex and bin output
'make images' will build all images as in previous versions of buildsystem
'make all' or 'make' will build only elf (+ map) files

This will have huge impact on build speed.
2014-02-13 19:35:18 +01:00
Frantisek Burian
3f47411e24 [Stylecheck] F0, F1, F4
There are remaining C99 comments.
2014-02-13 19:15:24 +01:00
Frantisek Burian
022cc475bf [DOC] Updated README's for F0 and F4 examples to describe the needed board connections. 2014-02-13 19:15:00 +01:00
Frantisek Burian
a265fd4d64 Correct include path in all examples 2014-02-13 19:15:00 +01:00
Frantisek Burian
5bb4d47aae Examples updated to use new rcc_periph_clock_enable function 2014-02-13 19:14:59 +01:00
Karl Palsson
3f68a5ceef stm32l: Correct openocd flash target name 2014-02-13 12:00:03 +00:00
Karl Palsson
c54ab042ef Bump examples library code to get new adc core 2014-02-05 19:13:10 +00:00
Karl Palsson
d1cf776ebc [lm4f] Remove usb cdc definitions moved to library
Requires a library bump to match
2014-01-22 20:28:32 +00:00
Frantisek Burian
5f592615d6 [BUILD] Correct inplace build for examples 2014-01-22 12:50:38 +01:00
Karl Palsson
379889e732 git ignore *.stylecheck files
Generated build droppings
2014-01-22 00:13:41 +00:00
Ken Sarkies
523401097a [STM32F4] DAC triggered by timer and DMA transfers. 2014-01-17 11:36:37 +00:00
Frantisek Burian
1b98ef8bfc Add stylecheck to the examples directory 2014-01-11 13:42:15 +01:00
Frantisek Burian
ffe9376c55 [BUILD] Allow to override FP_FLAGS in make as specified in libopencm3 README 2014-01-09 07:33:11 +01:00
Frantisek Burian
94ddb178eb [BUILD] Use the automatic variable RM=rm -f 2014-01-06 22:30:32 +01:00
Frantisek Burian
52fc38b03e [FIX] Library paths and preprocessor defines should be in CPPFLAGS, Reorganization of *FLAGS
Using:
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options
http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options
http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#ARM-Options

To CFLAGS are added only -ffunction-sections -fdata-sections, so this should not break the build.
2014-01-06 22:30:31 +01:00
Frantisek Burian
04d4bac5af [BUILD] Move out ARCH_FLAGS from the LDFLAGS and CFLAGS, CXXFLAGS 2014-01-06 22:30:19 +01:00
Frantisek Burian
39f6c9eb5f [FIX] Correct the compilation of C++ files (prepared for the future) 2014-01-06 22:27:29 +01:00
Frantisek Burian
f756c99a42 [BUILD] Removed TOOLCHAIN_DIR, add autodetection of current libopencm3 library placement 2014-01-06 22:25:57 +01:00
Frantisek Burian
747e8d260b [BUILD] Splitted long lines in targets definition 2014-01-06 22:25:57 +01:00
Frantisek Burian
07df176a8a [BUILD] Add source library path to the examples makefile to override default paths 2014-01-06 22:25:56 +01:00
Frantisek Burian
5385b463fe [FLASH:OPENOCD] Fixed the flashing function 2014-01-06 22:25:56 +01:00
Frantisek Burian
95fe484c42 Modify all of the examples to use the Makefile.rules 2014-01-06 22:25:56 +01:00
Onno Kortmann
58e84a9438 [BUILD] Generate *.MAP files
Reworked by: Frantisek Burian <BuFran@seznam.cz>
2014-01-06 22:25:55 +01:00
Frantisek Burian
02c35eee70 Make the STM32 Makefile.includes usable from outside the examples tree (Issue #28) 2014-01-06 22:25:55 +01:00
Frantisek Burian
9934e40fe9 [BUILD] Add generic Makefile.rules 2014-01-06 22:25:40 +01:00
Karl Palsson
04c92b6677 stm32f4: adc-dac-printf example
This is the same behaviour as the f1 and l1 examples of this code, making it
easier to test changes to unification of the adc code.
2014-01-04 00:13:34 +00:00
Karl Palsson
cc800be89a linker script paths: don't hardcode the path
While some of the examples include a "board.ld" style file, some of them were
pointing to the libopencm3 provided chip specific ld scripts.  When
TOOLCHAIN_DIR has been overridden, those paths were no longer valid/correct.
2014-01-03 21:54:34 +00:00
Piotr Esden-Tempski
5bafa042c5 [locm3] Updated to the newest version of locm3. 2014-01-03 01:08:13 +01:00
Frantisek Burian
72c1a29779 Correct the F3 examples hardfaults in rare cases, correct style 2014-01-03 00:18:41 +01:00
Onno Kortmann
3efd9f8675 Make the STM32 Makefile.includes usable from outside the examples tree
The Makefile.includes contain a hardcoded ../../../../../libopencm3
path for the TOOLCHAIN_DIR variable. They also contained another copy
of this hardcoded path, that is now generated from $TOOLCHAIN_DIR.

This allows to have a symbolic link to a Makefile.include in an
out-of-tree project and reuse the Makefile infrastructure.
2014-01-03 00:08:01 +01:00
Leigh Brown
c0791cd4a7 lm3s: add LM3S811 eval board miniblink example
The LM3S811-EVB miniblink example is a copy of the LM3S3748-EVB miniblink
example.  Modifications:

 - rename lm3s3748-evb.ld to lm3s811-evb.ld and change RAM and ROM sizes
 - amend Makefile to reference the lm3s811-evb.ld linker script
 - amend miniblink.c to use PC5 instead of PF0 for the LED GPIO
 - amend README to reference LM3S811-EVB instead of LM3S3748-EVB
2014-01-02 23:55:08 +01:00
Joshua Harlan Lifton
4505fa1926 Add USB<->serial loopback example to WaveShare Open103R 2014-01-02 23:38:53 +01:00
Joshua Harlan Lifton
eeb900d800 Fix typo 2014-01-02 23:38:53 +01:00
Joshua Harlan Lifton
b59c0a9e05 Add joystick example to WaveShare Open103R 2014-01-02 23:38:53 +01:00
Joshua Harlan Lifton
d944c0cba6 Port fancyblink example to WaveShare Open103R 2014-01-02 23:38:53 +01:00
Joshua Harlan Lifton
c672f1b329 Port button example to WaveShare Open103R 2014-01-02 23:38:52 +01:00
Joshua Harlan Lifton
f1bb59e19c First working example for the WaveShare Open103R eval board 2014-01-02 23:38:52 +01:00
Karl Palsson
ca926f00e0 [stm32l1] Add semihosting example
This is not specifically an L1 example, but it lives beside the L1 "usart"
example to show how easy it is to add semihosting support to existing code.

Tested with the by now relatively old g-a-e 2012q4 release and
OpenOcd 0.8.0-dev-00011-g70a2ffa (2013-05-14-19:41)
2014-01-02 23:33:22 +01:00
Piotr Esden-Tempski
26d27497f2 [tick_blink] Fixed to work with the current locm3. 2014-01-02 23:30:27 +01:00
Chuck McManis
3673e4059b This is a demo that uses the System Tick counter in the STM32F4
as a way of creating accurately timed delays. A simple 'msleep'
is implemented by watching the system clock to wait a certain
number of milleseconds before it returns. Its a bit more accurate
than a for loop, although it really shines when your running multiple
threads.
2014-01-02 23:29:13 +01:00
Frantisek Burian
314ad2d877 [F24:CRYPTO] Add example using cryptographic module on F41x or F2x 2014-01-02 23:26:32 +01:00
Frantisek Burian
d8757ab1fc [EXAMPLE:F0] Add example of using systick and MCO output on pin PA9.
This example is a merge of Chuck McManis's example for F4 and onnokort's system clock setting test blink example for demonstration issue, corrected in #224.

The LED in any available clock setting flashes four times per second.
2014-01-02 23:22:55 +01:00
Frantisek Burian
c5d6480201 [EXAMPLE:F0] Add simple ADC example 2014-01-02 23:22:55 +01:00
BuFran
4ae45b913d [EXAMPLE:F0] Add usart printf example using newlib-nano 2014-01-02 23:22:55 +01:00
BuFran
60e08c0591 [EXAMPLE:F0] Add simple usart example 2014-01-02 23:22:55 +01:00
Frantisek Burian
f176fe59d9 [EXAMPLE:F0] Add simple button example 2014-01-02 23:22:55 +01:00
Frantisek Burian
a8b3daeb57 [EXAMPLE:F0] Add simple miniblink example 2014-01-02 23:22:55 +01:00
Frantisek Burian
71bd938eeb [EXAMPLE:F0] Add basic example include 2014-01-02 23:22:55 +01:00
Frantisek Burian
80ba923da1 [FIX] Populate the STK_CTRL to STK_CSR change 2014-01-02 23:14:09 +01:00
Piotr Esden-Tempski
9338034eea Updated libopencm3 submodule to the newest version. 2014-01-02 23:06:43 +01:00
Mattias Eriksson
5efea57487 Updated USB HID examples with HID descriptor comments 2014-01-01 18:54:34 +01:00
Karl Palsson
100434b12d Update to latest libopencm3
And fix traceswo to match api change upstream.
2013-12-16 20:24:41 +00:00
Karl Palsson
d9536caeaa Fix broken adc.h includes
My bad, I'd been testing my header includes against a branch with some
draft unification of the adc code.  ADC is one of the remaining major
peripherals that isn't unified neatly.
2013-12-16 16:22:16 +00:00
BuFran
2b8b526df0 [BUILD] Paralelize cleaning of examples
make clean     1:50 -> 1:55 (no change)
make clean -j8 1:30 -> 0:28 (strongly faster)

Measured on Core i7 (4 cores, each HT) @ 3GHz
2013-12-13 14:18:10 +00:00
Karl Palsson
92624b7d01 [stm32x] Use modern header include paths.
Replace includes of stm32/YY/xxxx.h with stm32/xxxx.h
Replace stm32/YY/nvic.h with cm3/nvic.h.
In some cases, the include list was resorted alphabetically when it was
complicated and I was reviewing them manually, but most of this was
automatically done.
2013-12-13 14:13:47 +00:00
Dirk Braun
210761e1df [lm4f] Added a note for Windows users to the README 2013-12-13 14:10:57 +00:00
Alexandru Gagniuc
408fa52ec3 Global: Remove temporary backup files
file.c~ (note the tilde at the end) are temporary backup files used by some
editors. They are not needed.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
2013-07-08 09:59:16 -05:00
Piotr Esden-Tempski
b82cb85cc4 [STM32F3] Updated locm3 so that the newly added f3 examples compile. 2013-07-07 21:58:55 -07:00
Federico Ruiz Ugalde
fa8355225e stm32f3: cleaning some unused variables. 2013-07-07 21:44:50 -07:00
Federico Ruiz Ugalde
04a40d5cf6 stm32f3: Examples Makefile now includes f3 dir. 2013-07-07 21:44:41 -07:00
Federico Ruiz Ugalde
87db268c8e stm32f3: cdcacm example added and tested. 2013-07-07 21:42:18 -07:00
Federico Ruiz Ugalde
d0d2730db8 stm32f3discovery: spi l3gd20 example added. 2013-07-07 21:42:14 -07:00
Federico Ruiz Ugalde
98b4d42846 stm32f3discovery: Moving read and write convinience functions to libopencm3. 2013-07-07 21:41:46 -07:00
Federico Ruiz Ugalde
e1d5325736 stm32f3discovery: Adding i2c accelerometer example. 2013-07-07 21:41:26 -07:00
Federico Ruiz Ugalde
63f3bd7713 Adc example fixed (printing garbage before) and cleaned.
- Integer printing function fixed.
  	  - because of comparison against smaller than 0 numbers we must use signed numbers!
	  - Value zero was not printed at all.
	  - It was printing one more character than it should.
- Erasing unnecesary commentaries.
- Erasing debugging help.
2013-07-07 21:41:11 -07:00
Federico Ruiz Ugalde
6474ed3cf0 Flashing now using openocd. GDB Debugging possible and tested :). 2013-07-07 21:41:11 -07:00
Federico Ruiz Ugalde
4832449dd2 stm32f3discovery ld script corrected as recommended in #82. 2013-07-07 21:40:52 -07:00
Federico Ruiz Ugalde
757d044c23 stm32f3discovery examples added.
- miniblink
- button
- fancyblink
- adc
- Non tested yet! But they compile.
2013-07-07 21:40:06 -07:00
Piotr Esden-Tempski
fb4cecd05e Updated libopencm3. Disabled lpc43xx examples.
We merged a huge patchset for lpc43xx that breaks the examples. As we
are waiting for those to be updated it is better to disable the
automatic build of them.
2013-07-07 19:05:59 -07:00
Piotr Esden-Tempski
7ee888a857 Changed echo usage for printf as it is more portable. 2013-06-30 19:49:21 -07:00
hk
614d921a3b OLIMEX STM32-H107 has a 25MHz crystal 2013-06-16 19:19:32 -07:00
Piotr Esden-Tempski
d74a44e589 Added missing _write prototype. 2013-06-16 19:17:37 -07:00
Piotr Esden-Tempski
3186a4f2e7 Switched sewly added files to stdint types, as the pull request was done before the switch. 2013-06-16 19:14:55 -07:00
Alexandru Gagniuc
7639a88928 lm4f: Add USB bulk device example
I wrote this example to benchmark the USB driver. See the README.md for
full details.

Why README.md instead of just README. README.md shows up better on github,
and makes it easier to browse the tree on github to search for an example.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
2013-06-16 19:11:43 -07:00
Alexandru Gagniuc
28f92cce2b lm4f: Add USB to serial (CDCACM) example
Implements a USB-to-serial adapter, compliant to the CDCACM subclass.
UART1 is used for the TX/RX lines. Although UART1 also has lines for flow
control, they are not used. Instead, the control lines are implemented in
software via GPIOA.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
2013-06-16 19:11:28 -07:00
Piotr Esden-Tempski
f5b0aa5638 Updated to the new locm3 changed to stdint types. 2013-06-16 19:07:22 -07:00
560 changed files with 19676 additions and 4318 deletions

9
.gitignore vendored
View File

@@ -7,3 +7,12 @@
*.srec *.srec
*.list *.list
*.map *.map
*.stylecheck
generated.*.ld
.gdb_history
.DS_Store
# Project files from idea/netbeans/eclipse
nbproject/
.idea/
.project

2
.gitmodules vendored
View File

@@ -1,3 +1,3 @@
[submodule "libopencm3"] [submodule "libopencm3"]
path = libopencm3 path = libopencm3
url = https://github.com/libopencm3/libopencm3.git url = https://git.orangetime.top/EMTime/libopencm3

16
.travis.yml Normal file
View 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

View File

@@ -17,10 +17,15 @@
## along with this library. If not, see <http://www.gnu.org/licenses/>. ## along with this library. If not, see <http://www.gnu.org/licenses/>.
## ##
PREFIX ?= arm-none-eabi PREFIX ?= arm-none-eabi-
#PREFIX ?= arm-elf
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. # Be silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1) ifneq ($(V),1)
@@ -29,40 +34,68 @@ Q := @
MAKEFLAGS += --no-print-directory MAKEFLAGS += --no-print-directory
endif endif
OPENCM3_DIR ?= $(realpath libopencm3)
EXAMPLE_RULES = elf
all: build all: build
bin: EXAMPLE_RULES += bin
hex: EXAMPLE_RULES += hex
srec: EXAMPLE_RULES += srec
list: EXAMPLE_RULES += list
images: EXAMPLE_RULES += images
bin: build
hex: build
srec: build
list: build
images: build
build: lib examples build: lib examples
lib: lib:
$(Q)if [ ! "`ls -A libopencm3`" ] ; then \ $(Q)if [ ! "`ls -A $(OPENCM3_DIR)`" ] ; then \
echo "######## ERROR ########"; \ printf "######## ERROR ########\n"; \
echo "\tlibopencm3 is not initialized."; \ printf "\tlibopencm3 is not initialized.\n"; \
echo "\tPlease run:"; \ printf "\tPlease run:\n"; \
echo "\t$$ git submodule init"; \ printf "\t$$ git submodule init\n"; \
echo "\t$$ git submodule update"; \ printf "\t$$ git submodule update\n"; \
echo "\tbefore running make."; \ printf "\tbefore running make.\n"; \
echo "######## ERROR ########"; \ printf "######## ERROR ########\n"; \
exit 1; \ exit 1; \
fi fi
$(Q)$(MAKE) -C libopencm3 $(Q)$(MAKE) -C $(OPENCM3_DIR)
EXAMPLE_DIRS:=$(sort $(dir $(wildcard $(addsuffix /*/*/Makefile,$(addprefix examples/,$(TARGETS)))))) EXAMPLE_DIRS:=$(sort $(dir $(wildcard $(addsuffix /*/*/Makefile,$(addprefix examples/,$(TARGETS))))))
$(EXAMPLE_DIRS): lib $(EXAMPLE_DIRS): lib
@printf " BUILD $@\n"; @printf " BUILD $@\n";
$(Q)$(MAKE) --directory=$@ $(Q)$(MAKE) --directory=$@ OPENCM3_DIR=$(OPENCM3_DIR) $(EXAMPLE_RULES)
examples: $(EXAMPLE_DIRS) examples: $(EXAMPLE_DIRS)
$(Q)true $(Q)true
# Bleh http://www.makelinux.net/make3/make3-CHP-6-SECT-1#make3-CHP-6-SECT-1 examplesclean: $(EXAMPLE_DIRS:=.clean)
clean:
clean: examplesclean styleclean
$(Q)$(MAKE) -C libopencm3 clean $(Q)$(MAKE) -C libopencm3 clean
$(Q)for i in $(EXAMPLE_DIRS); do \
if [ -d $$i ]; then \
printf " CLEAN $$i\n"; \
$(MAKE) -C $$i clean SRCLIBDIR=$(SRCLIBDIR) || exit $?; \
fi; \
done
.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
View File

@@ -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
View File

@@ -0,0 +1,126 @@
# README
[![Build Status](https://travis-ci.org/libopencm3/libopencm3-examples.svg?branch=master)](https://travis-ci.org/libopencm3/libopencm3-examples)
[![Gitter channel](https://badges.gitter.im/libopencm3/discuss.svg)](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

View File

@@ -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)

View File

@@ -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.

View File

@@ -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)

View 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

View File

@@ -27,5 +27,4 @@ MEMORY
} }
/* Include the common ld script. */ /* Include the common ld script. */
INCLUDE libopencm3_lpc13xx.ld INCLUDE cortex-m-generic.ld

View File

@@ -22,4 +22,3 @@ BINARY = miniblink
LDSCRIPT = ../lpc-p1343.ld LDSCRIPT = ../lpc-p1343.ld
include ../../Makefile.include include ../../Makefile.include

View 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.

View 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

View File

@@ -29,4 +29,4 @@ MEMORY
} }
/* Include the common ld script. */ /* Include the common ld script. */
INCLUDE libopencm3_lpc17xx.ld INCLUDE cortex-m-generic.ld

View File

@@ -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.

View File

@@ -39,7 +39,7 @@ int main(void)
//GPIO1_CLR = (1 << 29); /* LED off */ //GPIO1_CLR = (1 << 29); /* LED off */
//for (i = 0; i < 800000; i++) /* Wait a bit. */ //for (i = 0; i < 800000; i++) /* Wait a bit. */
// __asm__("nop"); // __asm__("nop");
gpio_set(GPIO1, GPIOPIN29); /* LED on */ gpio_set(GPIO1, GPIOPIN29); /* LED on */
for (i = 0; i < 800000; i++) /* Wait a bit. */ for (i = 0; i < 800000; i++) /* Wait a bit. */
__asm__("nop"); __asm__("nop");

View 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

View File

@@ -0,0 +1,4 @@
# README
These example programs are written for the
[Diolan LPC-4350-DB1](http://www.diolan.com/lpc4350-features.html)

View File

@@ -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.

View File

@@ -33,7 +33,7 @@ int main(void)
/* Blink D2 on the board. */ /* Blink D2 on the board. */
while (1) { while (1) {
gpio_set(GPIO0, GPIOPIN5); /* LED on */ gpio_set(GPIO0, GPIOPIN5); /* LED on */
for (i = 0; i < 800000; i++) /* Wait a bit. */ for (i = 0; i < 800000; i++) /* Wait a bit. */
__asm__("nop"); __asm__("nop");

View File

@@ -1,4 +1,4 @@
These example programs are written for the Jellybean development board from the # README
HackRF project:
https://github.com/mossmann/hackrf These example programs are written for the Jellybean development board from the
[HackRF project](https://github.com/mossmann/hackrf)

View 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

View File

@@ -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.

View File

@@ -63,7 +63,7 @@ int main(void)
gpio_set(PORT_EN1V8, PIN_EN1V8); gpio_set(PORT_EN1V8, PIN_EN1V8);
/* Blink LED1/2/3 on the board and Read BOOT0/1/2/3 pins. */ /* Blink LED1/2/3 on the board and Read BOOT0/1/2/3 pins. */
while (1) while (1)
{ {
boot0 = BOOT0_STATE; boot0 = BOOT0_STATE;
boot1 = BOOT1_STATE; boot1 = BOOT1_STATE;

View File

@@ -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.

View File

@@ -63,7 +63,7 @@ int main(void)
gpio_set(PORT_EN1V8, PIN_EN1V8); gpio_set(PORT_EN1V8, PIN_EN1V8);
/* Blink LED1/2/3 on the board and Read BOOT0/1/2/3 pins. */ /* Blink LED1/2/3 on the board and Read BOOT0/1/2/3 pins. */
while (1) while (1)
{ {
boot0 = BOOT0_STATE; boot0 = BOOT0_STATE;
boot1 = BOOT1_STATE; boot1 = BOOT1_STATE;

View 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

View File

@@ -40,9 +40,9 @@ static void gpio_setup(void)
scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_BOOT0, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_BOOT0, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_BOOT1, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_BOOT1, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_BOOT2, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_BOOT2, SCU_GPIO_FAST);

View File

@@ -1,6 +1,4 @@
------------------------------------------------------------------------------ # README
README
------------------------------------------------------------------------------
This program exercises the SysTick Interrupt of ARM CortexM4 on Jellybean's LPC43xx. This program exercises the SysTick Interrupt of ARM CortexM4 on Jellybean's LPC43xx.
It also enable Cycle Counter to be used for accurate delay independant from Clock Frequency. It also enable Cycle Counter to be used for accurate delay independant from Clock Frequency.

View File

@@ -46,9 +46,9 @@ static void gpio_setup(void)
scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_BOOT0, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_BOOT0, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_BOOT1, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_BOOT1, SCU_GPIO_FAST);
scu_pinmux(SCU_PINMUX_BOOT2, SCU_GPIO_FAST); scu_pinmux(SCU_PINMUX_BOOT2, SCU_GPIO_FAST);
@@ -123,7 +123,7 @@ static uint32_t sys_tick_delta_time_ms(uint32_t start, uint32_t end)
{ {
diff=MAX_T_U32-(start-end)+1; diff=MAX_T_U32-(start-end)+1;
} }
return diff; return diff;
} }
@@ -169,7 +169,7 @@ int main(void)
/* SCS & Cycle Counter enabled (used to count number of cycles executed per second see g_NbCyclePerSecond */ /* SCS & Cycle Counter enabled (used to count number of cycles executed per second see g_NbCyclePerSecond */
scs_dwt_cycle_counter_enabled(); scs_dwt_cycle_counter_enabled();
while (1) while (1)
{ {
gpio_set(PORT_LED1_3, (PIN_LED1|PIN_LED2|PIN_LED3)); /* LEDs on */ gpio_set(PORT_LED1_3, (PIN_LED1|PIN_LED2|PIN_LED3)); /* LEDs on */

View File

@@ -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)

View File

@@ -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.

View File

@@ -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)

View File

@@ -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.

View File

@@ -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)

View File

@@ -1,3 +0,0 @@
These example programs are written for the Diolan LPC-4350-DB1:
http://www.diolan.com/lpc4350-features.html

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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
View 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)

View 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

View 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

View File

@@ -1,7 +1,7 @@
/* /*
* This file is part of the libopencm3 project. * 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 * This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
@@ -17,33 +17,30 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <libopencm3/stm32/f1/rcc.h> #include <libopencm3/sam/memorymap.h>
#include <libopencm3/stm32/spi.h> #include <libopencm3/sam/d/port.h>
static void clock_setup(void) // led is on PA09
{
rcc_clock_setup_in_hse_8mhz_out_72mhz();
}
static void spi_setup(void)
{
/* TODO */
}
static void gpio_setup(void) static void gpio_setup(void)
{ {
/* TODO */ PORT_DIR(PORTA) = (1<<9);
PORT_PINCFG(PORTA, 9) = 0;
} }
int main(void) int main(void)
{ {
clock_setup(); int i, j;
gpio_setup(); gpio_setup();
spi_setup();
while (1) { while (1) {
spi_write(SPI1, 0xaa); for (j = 0; j < 10; j++) {
spi_write(SPI1, 0x55); PORT_OUTTGL(PORTA) = 1<<9;
for (i = 0; i < (5000 + (j) * 10000); i++) { /* Wait a bit. */
__asm__("nop");
}
}
} }
return 0; return 0;

View 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

View 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

View 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)` |

View 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;
}

View 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

View 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*

View 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;
}

View 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

View 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*

View 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;
}

View 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

View 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

View 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 |

View File

@@ -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);
}

View 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

View 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)` |

View 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;
}

View 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

View 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)` |

View 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;
}

View File

@@ -18,155 +18,27 @@
## along with this library. If not, see <http://www.gnu.org/licenses/>. ## along with this library. If not, see <http://www.gnu.org/licenses/>.
## ##
PREFIX ?= arm-none-eabi LIBNAME = opencm3_stm32f1
#PREFIX ?= arm-elf DEFS += -DSTM32F1
CC = $(PREFIX)-gcc
LD = $(PREFIX)-gcc
OBJCOPY = $(PREFIX)-objcopy
OBJDUMP = $(PREFIX)-objdump
GDB = $(PREFIX)-gdb
TOOLCHAIN_DIR ?= ../../../../../libopencm3 FP_FLAGS ?= -msoft-float
ifeq ($(wildcard ../../../../../libopencm3/lib/libopencm3_stm32f1.a),) ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
ifneq ($(strip $(shell which $(CC))),)
TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX)
endif
else
ifeq ($(V),1)
$(info We seem to be building the example in the source directory. Using local library!)
endif
endif
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float ################################################################################
CFLAGS += -Os -g \ # OpenOCD specific variables
-Wall -Wextra -Wimplicit-function-declaration \
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
-Wundef -Wshadow \
-I$(TOOLCHAIN_DIR)/include \
-fno-common $(ARCH_FLAGS) -MD -DSTM32F1
LDSCRIPT ?= $(BINARY).ld
LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
-L$(TOOLCHAIN_DIR)/lib \
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd
ifneq ($(OPENCM3_DIR),)
CFLAGS += -I$(OPENCM3_DIR)/include
LDFLAGS += -L$(OPENCM3_DIR)/lib -L$(OPENCM3_DIR)/lib/stm32/f1
SCRIPT_DIR = $(OPENCM3_DIR)/share
else
SCRIPT_DIR = $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/../$(PREFIX)/share
endif
OBJS += $(BINARY).o
OOCD ?= openocd OOCD ?= openocd
OOCD_INTERFACE ?= flossjtag OOCD_INTERFACE ?= flossjtag
OOCD_BOARD ?= olimex_stm32_h103 OOCD_TARGET ?= stm32f1x
# Black magic probe specific variables
################################################################################
# Black Magic Probe specific variables
# Set the BMP_PORT to a serial port and then BMP is used for flashing # Set the BMP_PORT to a serial port and then BMP is used for flashing
BMP_PORT ?= BMP_PORT ?=
# texane/stlink can be used by uncommenting this...
# or defining it in your own makefiles
#STLINK_PORT ?= :4242
# Be silent per default, but 'make V=1' will show all compiler calls. ################################################################################
ifneq ($(V),1) # texane/stlink specific variables
Q := @ #STLINK_PORT ?= :4242
NULL := 2>/dev/null
else
LDFLAGS += -Wl,--print-gc-sections
endif
.SUFFIXES: .elf .bin .hex .srec .list .images
.SECONDEXPANSION:
.SECONDARY:
all: images
images: $(BINARY).images
flash: $(BINARY).flash
%.images: %.bin %.hex %.srec %.list
@#echo "*** $* images generated ***"
%.bin: %.elf
@#printf " OBJCOPY $(*).bin\n"
$(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin
%.hex: %.elf
@#printf " OBJCOPY $(*).hex\n"
$(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex
%.srec: %.elf
@#printf " OBJCOPY $(*).srec\n"
$(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec
%.list: %.elf
@#printf " OBJDUMP $(*).list\n"
$(Q)$(OBJDUMP) -S $(*).elf > $(*).list
%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f1.a
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
$(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32f1 $(LDFLAGS)
%.o: %.c Makefile
@#printf " CC $(subst $(shell pwd)/,,$(@))\n"
$(Q)$(CC) $(CFLAGS) -o $@ -c $<
clean:
$(Q)rm -f *.o
$(Q)rm -f *.d
$(Q)rm -f *.elf
$(Q)rm -f *.bin
$(Q)rm -f *.hex
$(Q)rm -f *.srec
$(Q)rm -f *.list
ifeq ($(STLINK_PORT),)
ifeq ($(BMP_PORT),)
ifeq ($(OOCD_SERIAL),)
%.flash: %.hex
@printf " FLASH $<\n"
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
-f board/$(OOCD_BOARD).cfg \
-c "init" -c "reset init" \
-c "stm32f1x mass_erase 0" \
-c "flash write_image $(*).hex" \
-c "reset" \
-c "shutdown" $(NULL)
else
%.flash: %.hex
@printf " FLASH $<\n"
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
-f board/$(OOCD_BOARD).cfg \
-c "ft2232_serial $(OOCD_SERIAL)" \
-c "init" -c "reset init" \
-c "stm32f1x mass_erase 0" \
-c "flash write_image $(*).hex" \
-c "reset" \
-c "shutdown" $(NULL)
endif
else
%.flash: %.elf
@echo " GDB $(*).elf (flash)"
$(Q)$(GDB) --batch \
-ex 'target extended-remote $(BMP_PORT)' \
-x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \
$(*).elf
endif
else
%.flash: %.elf
@echo " GDB $(*).elf (flash)"
$(Q)$(GDB) --batch \
-ex 'target extended-remote $(STLINK_PORT)' \
-x $(SCRIPT_DIR)/libopencm3/scripts/stlink_flash.scr \
$(*).elf
endif
.PHONY: images clean
-include $(OBJS:.o=.d)
include ../../../../rules.mk

View 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.

View File

@@ -1,3 +1,5 @@
# README
This test sets up the CAN interface on Lisa/M and transmits 8 bites every This test sets up the CAN interface on Lisa/M and transmits 8 bites every
100ms. The first byte is being incremented in each cycle. The demo also 100ms. The first byte is being incremented in each cycle. The demo also
receives messages and is displaing the first 4 bits of the first byte on the receives messages and is displaing the first 4 bits of the first byte on the

View File

@@ -18,12 +18,13 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <libopencm3/stm32/f1/rcc.h> #include <stddef.h>
#include <libopencm3/stm32/f1/flash.h>
#include <libopencm3/stm32/f1/gpio.h>
#include <libopencm3/cm3/nvic.h> #include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h> #include <libopencm3/cm3/systick.h>
#include <libopencm3/stm32/can.h> #include <libopencm3/stm32/can.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/flash.h>
#include <libopencm3/stm32/rcc.h>
struct can_tx_msg { struct can_tx_msg {
uint32_t std_id; uint32_t std_id;
@@ -50,16 +51,16 @@ struct can_rx_msg can_rx_msg;
static void gpio_setup(void) static void gpio_setup(void)
{ {
/* Enable Alternate Function clock. */ /* Enable Alternate Function clock. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); rcc_periph_clock_enable(RCC_AFIO);
/* Enable GPIOA clock. */ /* Enable GPIOA clock. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); rcc_periph_clock_enable(RCC_GPIOA);
/* Enable GPIOB clock. */ /* Enable GPIOB clock. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); rcc_periph_clock_enable(RCC_GPIOB);
/* Enable GPIOC clock. */ /* Enable GPIOC clock. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); rcc_periph_clock_enable(RCC_GPIOC);
/* Preconfigure LEDs. */ /* Preconfigure LEDs. */
gpio_set(GPIOA, GPIO8); /* LED0 off */ gpio_set(GPIOA, GPIO8); /* LED0 off */
@@ -88,7 +89,7 @@ static void gpio_setup(void)
static void systick_setup(void) static void systick_setup(void)
{ {
/* 72MHz / 8 => 9000000 counts per second */ /* 72MHz / 8 => 9000000 counts per second */
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
/* SysTick interrupt every N clock pulses: set reload to N-1 */ /* SysTick interrupt every N clock pulses: set reload to N-1 */
@@ -103,9 +104,9 @@ static void systick_setup(void)
static void can_setup(void) static void can_setup(void)
{ {
/* Enable peripheral clocks. */ /* Enable peripheral clocks. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); rcc_periph_clock_enable(RCC_AFIO);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); rcc_periph_clock_enable(RCC_GPIOB);
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN); rcc_periph_clock_enable(RCC_CAN);
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB; AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
@@ -152,7 +153,7 @@ static void can_setup(void)
} }
/* CAN filter 0 init. */ /* CAN filter 0 init. */
can_filter_id_mask_32bit_init(CAN1, can_filter_id_mask_32bit_init(
0, /* Filter ID */ 0, /* Filter ID */
0, /* CAN ID */ 0, /* CAN ID */
0, /* CAN ID mask */ 0, /* CAN ID mask */
@@ -195,11 +196,11 @@ void sys_tick_handler(void)
void usb_lp_can_rx0_isr(void) void usb_lp_can_rx0_isr(void)
{ {
uint32_t id, fmi; uint32_t id;
bool ext, rtr; 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) if (data[0] & 1)
gpio_clear(GPIOA, GPIO8); gpio_clear(GPIOA, GPIO8);
@@ -226,7 +227,7 @@ void usb_lp_can_rx0_isr(void)
int main(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(); gpio_setup();
can_setup(); can_setup();
systick_setup(); systick_setup();

View File

@@ -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;
}

View File

@@ -18,18 +18,18 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <libopencm3/stm32/f1/rcc.h> #include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/f1/gpio.h> #include <libopencm3/stm32/gpio.h>
/* Set STM32 to 72 MHz. */ /* Set STM32 to 72 MHz. */
static void clock_setup(void) static void clock_setup(void)
{ {
rcc_clock_setup_in_hse_12mhz_out_72mhz(); rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE12_72MHZ]);
/* Enable GPIOB, GPIOC, and AFIO clocks. */ /* Enable GPIOB, GPIOC, and AFIO clocks. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); rcc_periph_clock_enable(RCC_GPIOB);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); rcc_periph_clock_enable(RCC_GPIOC);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); rcc_periph_clock_enable(RCC_AFIO);
} }
static void gpio_setup(void) static void gpio_setup(void)

View File

@@ -28,5 +28,5 @@ MEMORY
} }
/* Include the common ld script. */ /* Include the common ld script. */
INCLUDE libopencm3_stm32f1.ld INCLUDE cortex-m-generic.ld

View File

@@ -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.

View 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.

View File

@@ -18,8 +18,8 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <libopencm3/stm32/f1/rcc.h> #include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/f1/gpio.h> #include <libopencm3/stm32/gpio.h>
#include <libopencm3/usb/usbd.h> #include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/cdc.h> #include <libopencm3/usb/cdc.h>
@@ -166,7 +166,7 @@ static const char *usb_strings[] = {
/* Buffer to be used for control requests. */ /* Buffer to be used for control requests. */
uint8_t usbd_control_buffer[128]; 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)) uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
{ {
(void)complete; (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[8] = req->wValue & 3;
local_buf[9] = 0; local_buf[9] = 0;
// usbd_ep_write_packet(0x83, buf, 10); // usbd_ep_write_packet(0x83, buf, 10);
return 1; return USBD_REQ_HANDLED;
} }
case USB_CDC_REQ_SET_LINE_CODING: case USB_CDC_REQ_SET_LINE_CODING:
if (*len < sizeof(struct usb_cdc_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) 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) { if (len) {
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0) while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0)
; ;
buf[len] = 0;
} }
gpio_toggle(GPIOC, GPIO5); gpio_toggle(GPIOC, GPIO5);
@@ -240,10 +239,10 @@ int main(void)
usbd_device *usbd_dev; 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_periph_clock_enable(RCC_GPIOC);
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN); rcc_periph_clock_enable(RCC_OTGFS);
gpio_set(GPIOC, GPIO2); gpio_set(GPIOC, GPIO2);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,

View File

@@ -18,6 +18,7 @@
## ##
BINARY = usbdfu BINARY = usbdfu
CSTD = -std=gnu99
LDSCRIPT = ../lisa-m.ld LDSCRIPT = ../lisa-m.ld

View File

@@ -1,7 +0,0 @@
------------------------------------------------------------------------------
README
------------------------------------------------------------------------------
This example implements a USB Device Firmware Upgrade (DFU) bootloader
to demonstrate the use of the USB device stack.

View 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.

View File

@@ -18,9 +18,9 @@
*/ */
#include <string.h> #include <string.h>
#include <libopencm3/stm32/f1/rcc.h> #include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/f1/gpio.h> #include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/f1/flash.h> #include <libopencm3/stm32/flash.h>
#include <libopencm3/cm3/scb.h> #include <libopencm3/cm3/scb.h>
#include <libopencm3/usb/usbd.h> #include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/dfu.h> #include <libopencm3/usb/dfu.h>
@@ -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); uint32_t *dat = (uint32_t *)(prog.buf + 1);
flash_erase_page(*dat); flash_erase_page(*dat);
} }
break;
case CMD_SETADDR: case CMD_SETADDR:
{ {
uint32_t *dat = (uint32_t *)(prog.buf + 1); uint32_t *dat = (uint32_t *)(prog.buf + 1);
prog.addr = *dat; prog.addr = *dat;
} }
break;
} }
} else { } else {
uint32_t baseaddr = prog.addr + ((prog.blocknum - 2) * 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)) uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
{ {
(void)usbd_dev; (void)usbd_dev;
if ((req->bmRequestType & 0x7F) != 0x21) if ((req->bmRequestType & 0x7F) != 0x21)
return 0; /* Only accept class request. */ return USBD_REQ_NOTSUPP; /* Only accept class request. */
switch (req->bRequest) { switch (req->bRequest) {
case DFU_DNLOAD: case DFU_DNLOAD:
if ((len == NULL) || (*len == 0)) { if ((len == NULL) || (*len == 0)) {
usbdfu_state = STATE_DFU_MANIFEST_SYNC; usbdfu_state = STATE_DFU_MANIFEST_SYNC;
return 1;
} else { } else {
/* Copy download data for use on GET_STATUS. */ /* Copy download data for use on GET_STATUS. */
prog.blocknum = req->wValue; prog.blocknum = req->wValue;
prog.len = *len; prog.len = *len;
memcpy(prog.buf, *buf, *len); memcpy(prog.buf, *buf, *len);
usbdfu_state = STATE_DFU_DNLOAD_SYNC; usbdfu_state = STATE_DFU_DNLOAD_SYNC;
return 1;
} }
return USBD_REQ_HANDLED;
case DFU_CLRSTATUS: case DFU_CLRSTATUS:
/* Clear error and return to dfuIDLE. */ /* Clear error and return to dfuIDLE. */
if (usbdfu_state == STATE_DFU_ERROR) if (usbdfu_state == STATE_DFU_ERROR)
usbdfu_state = STATE_DFU_IDLE; usbdfu_state = STATE_DFU_IDLE;
return 1; return USBD_REQ_HANDLED;
case DFU_ABORT: case DFU_ABORT:
/* Abort returns to dfuIDLE state. */ /* Abort returns to dfuIDLE state. */
usbdfu_state = STATE_DFU_IDLE; usbdfu_state = STATE_DFU_IDLE;
return 1; return USBD_REQ_HANDLED;
case DFU_UPLOAD: case DFU_UPLOAD:
/* Upload not supported for now. */ /* Upload not supported for now. */
return 0; return USBD_REQ_NOTSUPP;
case DFU_GETSTATUS: { case DFU_GETSTATUS: {
uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */ uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout); (*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 */ (*buf)[5] = 0; /* iString not used here */
*len = 6; *len = 6;
*complete = usbdfu_getstatus_complete; *complete = usbdfu_getstatus_complete;
return 1; return USBD_REQ_HANDLED;
} }
case DFU_GETSTATE: case DFU_GETSTATE:
/* Return state with no state transision. */ /* Return state with no state transision. */
*buf[0] = usbdfu_state; *buf[0] = usbdfu_state;
*len = 1; *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) int main(void)
{ {
usbd_device *usbd_dev; usbd_device *usbd_dev;
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); rcc_periph_clock_enable(RCC_GPIOA);
if (!gpio_get(GPIOA, GPIO10)) { if (!gpio_get(GPIOA, GPIO10)) {
/* Boot the application if it's valid. */ /* 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_periph_clock_enable(RCC_GPIOC);
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN); rcc_periph_clock_enable(RCC_OTGFS);
gpio_set(GPIOC, GPIO2); gpio_set(GPIOC, GPIO2);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2); GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings, 4, usbd_control_buffer, sizeof(usbd_control_buffer)); usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings, 4, usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_register_control_callback( usbd_register_set_config_callback(usbd_dev, usbdfu_set_config);
usbd_dev,
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
usbdfu_control_request);
gpio_clear(GPIOC, GPIO2); gpio_clear(GPIOC, GPIO2);

View File

@@ -1,7 +0,0 @@
------------------------------------------------------------------------------
README
------------------------------------------------------------------------------
This example implements a USB Human Interface Device (HID)
to demonstrate the use of the USB device stack.

View File

@@ -0,0 +1,5 @@
# README
This example implements a USB Human Interface Device (HID)
to demonstrate the use of the USB device stack.

View File

@@ -19,12 +19,12 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <libopencm3/stm32/f1/rcc.h> #include <libopencm3/cm3/nvic.h>
#include <libopencm3/stm32/f1/gpio.h>
#include <libopencm3/cm3/systick.h> #include <libopencm3/cm3/systick.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/spi.h> #include <libopencm3/stm32/spi.h>
#include <libopencm3/stm32/otg_fs.h> #include <libopencm3/usb/dwc/otg_fs.h>
#include <libopencm3/stm32/f1/nvic.h>
#include <libopencm3/usb/usbd.h> #include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/hid.h> #include <libopencm3/usb/hid.h>
#include "adxl345.h" #include "adxl345.h"
@@ -56,18 +56,45 @@ const struct usb_device_descriptor dev_descr = {
.bNumConfigurations = 1, .bNumConfigurations = 1,
}; };
/* I have no idea what this means. I haven't read the HID spec. */
static const uint8_t hid_report_descriptor[] = { static const uint8_t hid_report_descriptor[] = {
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x09, 0x02, /* USAGE (Mouse) */
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0xa1, 0x01, /* COLLECTION (Application) */
0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x09, 0x01, /* USAGE (Pointer) */
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 0xa1, 0x00, /* COLLECTION (Physical) */
0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x03, 0x05, 0x09, /* USAGE_PAGE (Button) */
0x81, 0x06, 0xC0, 0x09, 0x3c, 0x05, 0xff, 0x09, 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */
0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */
0x02, 0xb1, 0x22, 0x75, 0x06, 0x95, 0x01, 0xb1, 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x01, 0xc0, 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 { static const struct {
@@ -178,7 +205,7 @@ static const char *usb_strings[] = {
/* Buffer used for control requests. */ /* Buffer used for control requests. */
uint8_t usbd_control_buffer[128]; 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)(usbd_device *dev, struct usb_setup_data *req))
{ {
(void)complete; (void)complete;
@@ -187,13 +214,13 @@ static int hid_control_request(usbd_device *dev, struct usb_setup_data *req, uin
if((req->bmRequestType != 0x81) || if((req->bmRequestType != 0x81) ||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) || (req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
(req->wValue != 0x2200)) (req->wValue != 0x2200))
return 0; return USBD_REQ_NOTSUPP;
/* Handle the HID report descriptor. */ /* Handle the HID report descriptor. */
*buf = (uint8_t *)hid_report_descriptor; *buf = (uint8_t *)hid_report_descriptor;
*len = sizeof(hid_report_descriptor); *len = sizeof(hid_report_descriptor);
return 1; return USBD_REQ_HANDLED;
} }
#ifdef INCLUDE_DFU_INTERFACE #ifdef INCLUDE_DFU_INTERFACE
@@ -209,7 +236,7 @@ static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req)
scb_reset_core(); 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 (**complete)(usbd_device *dev, struct usb_setup_data *req))
{ {
(void)buf; (void)buf;
@@ -217,11 +244,11 @@ static int dfu_control_request(usbd_device *dev, struct usb_setup_data *req, uin
(void)dev; (void)dev;
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH)) 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; *complete = dfu_detach_complete;
return 1; return USBD_REQ_HANDLED;
} }
#endif #endif
@@ -244,7 +271,7 @@ static void hid_set_config(usbd_device *dev, uint16_t wValue)
dfu_control_request); dfu_control_request);
#endif #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 interrupt every N clock pulses: set reload to N-1 */
systick_set_reload(99999); systick_set_reload(99999);
systick_interrupt_enable(); systick_interrupt_enable();
@@ -296,13 +323,13 @@ int main(void)
{ {
int i; 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_periph_clock_enable(RCC_GPIOA);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); rcc_periph_clock_enable(RCC_GPIOB);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); rcc_periph_clock_enable(RCC_GPIOC);
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_SPI2EN); rcc_periph_clock_enable(RCC_SPI2);
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN); rcc_periph_clock_enable(RCC_OTGFS);
/* Configure SPI2: PB13(SCK), PB14(MISO), PB15(MOSI). */ /* Configure SPI2: PB13(SCK), PB14(MISO), PB15(MOSI). */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_10_MHZ, gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_10_MHZ,

View File

@@ -21,7 +21,6 @@ BINARY = adc_injec
# Comment the following line if you _don't_ have luftboot flashed! # Comment the following line if you _don't_ have luftboot flashed!
LDFLAGS += -Wl,-Ttext=0x8002000 LDFLAGS += -Wl,-Ttext=0x8002000
CFLAGS += -std=c99
LDSCRIPT = ../lisa-m.ld LDSCRIPT = ../lisa-m.ld
include ../../Makefile.include include ../../Makefile.include

View File

@@ -1,6 +1,4 @@
------------------------------------------------------------------------------ # README
README
------------------------------------------------------------------------------
This is a simple polling example that sends the value read out from the This is a simple polling example that sends the value read out from the
temperature sensor ADC channel of the STM32 to the USART2. temperature sensor ADC channel of the STM32 to the USART2.

View File

@@ -19,17 +19,17 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>. * along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <libopencm3/stm32/f1/rcc.h> #include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/f1/flash.h> #include <libopencm3/stm32/flash.h>
#include <libopencm3/stm32/f1/gpio.h> #include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/f1/adc.h> #include <libopencm3/stm32/adc.h>
#include <libopencm3/stm32/usart.h> #include <libopencm3/stm32/usart.h>
static void usart_setup(void) static void usart_setup(void)
{ {
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */ /* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); rcc_periph_clock_enable(RCC_GPIOA);
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN); rcc_periph_clock_enable(RCC_USART2);
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */ /* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
@@ -50,8 +50,8 @@ static void usart_setup(void)
static void gpio_setup(void) static void gpio_setup(void)
{ {
/* Enable GPIO clocks. */ /* Enable GPIO clocks. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); rcc_periph_clock_enable(RCC_GPIOA);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); rcc_periph_clock_enable(RCC_GPIOC);
/* Setup the LEDs. */ /* Setup the LEDs. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
@@ -64,10 +64,10 @@ static void adc_setup(void)
{ {
int i; 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. */ /* Make sure the ADC doesn't run during config. */
adc_off(ADC1); adc_power_off(ADC1);
/* We configure everything for one single injected conversion. */ /* We configure everything for one single injected conversion. */
adc_disable_scan_mode(ADC1); 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_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_JSWSTART);
adc_set_right_aligned(ADC1); adc_set_right_aligned(ADC1);
/* We want to read the temperature sensor, so we have to enable it. */ /* 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_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
adc_power_on(ADC1); adc_power_on(ADC1);
@@ -89,9 +89,7 @@ static void adc_setup(void)
__asm__("nop"); __asm__("nop");
adc_reset_calibration(ADC1); adc_reset_calibration(ADC1);
while ((ADC_CR2(ADC1) & ADC_CR2_RSTCAL) != 0); //added this check adc_calibrate(ADC1);
adc_calibration(ADC1);
while ((ADC_CR2(ADC1) & ADC_CR2_CAL) != 0); //added this check
} }
static void my_usart_print_int(uint32_t usart, int value) static void my_usart_print_int(uint32_t usart, int value)
@@ -122,7 +120,7 @@ int main(void)
uint8_t channel_array[16]; uint8_t channel_array[16];
uint16_t temperature = 0; 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(); gpio_setup();
usart_setup(); usart_setup();
adc_setup(); adc_setup();

View File

@@ -21,7 +21,6 @@ BINARY = adc_injec_timtrig
# Comment the following line if you _don't_ have luftboot flashed! # Comment the following line if you _don't_ have luftboot flashed!
LDFLAGS += -Wl,-Ttext=0x8002000 LDFLAGS += -Wl,-Ttext=0x8002000
CFLAGS += -std=c99
LDSCRIPT = ../lisa-m.ld LDSCRIPT = ../lisa-m.ld
include ../../Makefile.include include ../../Makefile.include

Some files were not shown because too many files have changed in this diff Show More