Development host setup:
sudo apt-get install avrdude gcc-avr binutils-avr avr-libc
Makefile:
all: main.hex
main.hex: main.elf
avr-objcopy -j .text -j .data -O ihex $^ $@
avr-size $@
main.elf: main.c
avr-gcc -mmcu=atmega328p -Os -Wall -Wextra -Wpedantic -DF_CPU=16000000 -o $@ $^
clean:
rm -rf *.o *.elf *.hex
flash: main.hex
sudo avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p atmega328p -U flash:w:main.hex:a
đź’ˇ LED is at PB5.
AVR ISP pinout:
+------+---+---+------+
| MISO | 1 | 2 | VCC |
| SCK | 3 | 4 | MOSI |
| /RST | 5 | 6 | GND |
+------+---+---+------+
Programming using a SWD ST-Link: make sure the configuration jumpers are configured as BOOT0=0
and BOOT1=0
.
SWD interface pinout:
+---+-------+
| 1 | GND |
| 2 | SWCLK |
| 3 | SWDIO |
| 4 | 3V3 |
+---+-------+
Get the compiler:
$ sudo apt-get install gcc-arm-none-eabi binutils-arm-none-eabi
Build the stlink programming software:
$ sudo apt-get install libusb-1.0-0-dev
$ git clone https://github.com/texane/stlink
$ cd stlink
$ make
Check that the programmer is detected:
$ sudo ./build/Release/bin/st-info --probe
Found 1 stlink programmers
serial: 483f7506513f52545635023f
openocd: "\x48\x3f\x75\x06\x51\x3f\x52\x54\x56\x35\x02\x3f"
flash: 131072 (pagesize: 1024)
sram: 20480
chipid: 0x0410
descr: F1 Medium-density device
Get the “blinky light” example from github:
$ git clone https://github.com/satoshinm/pill_blink.git
$ cd pill_blink/opencm
$ make libopencm3
$ make pill_blink.bin
Program the example on the board:
$ sudo ../../stlink/build/Release/bin/st-flash write ./pill_blink.bin 0x8000000
st-flash 1.6.0-3-g3af8048
2020-03-12T21:24:44 INFO common.c: Loading device parameters....
2020-03-12T21:24:44 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2020-03-12T21:24:44 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2020-03-12T21:24:44 INFO common.c: Attempting to write 1092 (0x444) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08000400 erased
2020-03-12T21:24:44 INFO common.c: Finished erasing 2 pages of 1024 (0x400) bytes
2020-03-12T21:24:44 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2020-03-12T21:24:44 INFO flash_loader.c: Successfully loaded flash loader in sram
2/2 pages written
2020-03-12T21:24:44 INFO common.c: Starting verification of write complete
2020-03-12T21:24:44 INFO common.c: Flash written and verified! jolly good!
đź’ˇ LED is at PC13.
This board can be used to program other boards via SWD, using the embedded ST-Link programmer. Remove the CN2 jumpers when doing this.
SWD interface pinout (on CN3):
+---+------------------+
| 1 | VDD_TARGET |
| 2 | SWCLK |
| 3 | GND |
| 4 | SWDIO |
| 5 | /RST (optional?) |
| 6 | SWO (reserved) |
+---+------------------+