Archive-name: j5hnq9wr5auezrscx1yeepscyn
Submitted-by:
onei...@gmail.com
Last-modified: 2013-05-14 +00:00
Copyright-Notice: Both the README and the code are under the
CC0 Public Domain Dedication.
[Followup-To: set to news:alt.sources.d, as per the
news:alt.sources' charter, and also news:comp.sys.arm, and
news:comp.arch.embedded.]
Synopsis
$ make -f
b4p5ysa9szoedmknero8jhsp7f.mk
$ python stm32loader.py -e -w -p /dev/ttyXXX \
j5hnq9wr5auezrscx1yeepscyn.bin
or:
$ mkdir +build-1
$ cd +build-1
$ make srcdir=.. -f ../
b4p5ysa9szoedmknero8jhsp7f.mk
$ python stm32loader.py -e -w -p /dev/ttyXXX \
j5hnq9wr5auezrscx1yeepscyn.bin
Summary
This simplistic example executes an almost empty infinite loop.
Every 1048576 (0x100000) iterations of the loop, the PB0 pin is
toggled, which results in a roughly 1 Hz signal generated on
that pin.
The code also shows the relevant port initializations, using the
libopencm3 library's functions.
A simplistic LD script (referencing libopencm3_stm32f1.ld) and a
Makefile with the necessary C and LD options are also provided.
Bugs
This example wastes most of the CPU time doing an empty loop.
Obviously, it should instead set up a timer and enter a sleep
mode whenever possible.
It shouldn't be all that hard to extend the code to handle at
least all the other MCUs of the STM32F103 series.
An option (a preprocessor macro and a corresponding Makefile
variable) should be provided to build the code so that it sets
up the MCU to use an external crystal oscillator, and, possibly,
a pin other than PB0.
Frankly, I don't know whether all the CFLAGS and LDFLAGS are
really necessary or not.
See also
The stm32loader.py code to upload the code into an STM32F103C8T6
MCU is available separately [1]. Please note that one may want
to apply one of the patches fixing its "read" (-r) function
(e. g., [2].)
The code was influenced by (but hardly based on) a few examples
I was able to find on the Web, including [3, 4] (the port
initialization, and the compiler and linker options) and [5, 6].
[1]
http://elua-development.2368040.n2.nabble.com/STM32-Bootloader-Flashing-in-Python-td2499766.html
[2]
news:874ne7m...@violet.siamics.net
http://ftp.funet.fi/index/archive/alt.sources/2779.gz
[3]
http://blog.vinu.co.in/2012/07/getting-started-with-arm-cortex-m3-on.html
[4]
https://github.com/vinodstanur/STM32VLDISCOVERY
[5]
http://www.triplespark.net/elec/pdev/arm/stm32.html
[6]
http://fun-tech.se/stm32/OlimexBlinky/mini.php
README.j5hnq9wr5auezrscx1yeepscyn ends here
###
b4p5ysa9szoedmknero8jhsp7f.mk -*- Makefile-gmake -*-
## A GNUmakefile to build a simple example for STM32F103C8T6.
### Ivan Shmakov, 2013
## To the extent possible under law, the author(s) have dedicated all
## copyright and related and neighboring rights to this software to the
## public domain worldwide. This software is distributed without any
## warranty.
## You should have received a copy of the CC0 Public Domain Dedication
## along with this software. If not, see
## <
http://creativecommons.org/publicdomain/zero/1.0/>.
### Code:
srcdir = .
VPATH = $(srcdir)
CC = arm-none-eabi-gcc
LD = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
MCPU = cortex-m3
CFLAGS = -g -Wall -mcpu=$(MCPU) -mthumb
CPPFLAGS = -DSTM32F1
LDFLAGS = \
-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
-nostartfiles -Wl,--gc-sections \
-mcpu=$(MCPU) -mfix-cortex-m3-ldrd \
-T$(srcdir)/3bbbmucd18onzb68p13fpk8rcy.ld
LIBS = -lopencm3_stm32f1
PROGRAMS = j5hnq9wr5auezrscx1yeepscyn
all: $(PROGRAMS) $(PROGRAMS:%=%.bin)
%.bin: %
$(OBJCOPY) -Obinary -- $< $@
j5hnq9wr5auezrscx1yeepscyn: j5hnq9wr5auezrscx1yeepscyn.c
$(CC) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) -o $@ $^ $(LIBS)
###
b4p5ysa9szoedmknero8jhsp7f.mk ends here
/*** j5hnq9wr5auezrscx1yeepscyn.c -*- C -*- */
/** A simple example for STM32F103C8T6. */
/*** Ivan Shmakov, 2013 */
/** To the extent possible under law, the author(s) have dedicated all
** copyright and related and neighboring rights to this software to the
** public domain worldwide. This software is distributed without any
** warranty.
**
** You should have received a copy of the CC0 Public Domain Dedication
** along with this software. If not, see
** <
http://creativecommons.org/publicdomain/zero/1.0/>.
*/
/*** Code: */
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
int
main (void)
{
/* set up PORTB peripheral clock */
rcc_peripheral_enable_clock (&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
/* set up PB0 for output */
gpio_set_mode (GPIOB,
GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL,
GPIO0);
int i;
for (i = 0; ; i++) {
#if 1
/* FIXME: such loops are evil */
/* toggle PB0 every 1048576 iterations */
/* (roughly at 1 Hz, as it seems) */
if (i % 0x100000 == 0) {
gpio_toggle (GPIOB, GPIO0);
}
#else
/* do nothing */
#endif
}
}
/*** j5hnq9wr5auezrscx1yeepscyn.c ends here */
/*** 3bbbmucd18onzb68p13fpk8rcy.ld */
/** Generic LD script for STM32F103C8T6 */
/*** Code: */
MEMORY {
rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
}
INCLUDE libopencm3_stm32f1.ld
/*** 3bbbmucd18onzb68p13fpk8rcy.ld */
--
FSF associate member #7257