This repository contains my project template (and mandatory LED blinking code example) for the dirt-cheap Geehy APM32F003 microcontroller.
Structure:
- geehy subdirectory contains startup code, linker scripts, CMSIS header files
and drivers - all extracted from Geehy
APM32F00x_SDK_V1.4
.- only
GPIO
andRCM
drivers are included in the build, if you need other drivers, you need to edit the Makefile.
- only
- src contains actual blinker source code.
Note:
- I use make as a build tool. I consider reworking it
to CMake or SCons some day, to make it
cross-platform. Maintaining a cross-platform
Makefile
is a nightmare (been there, done that), I don't want to fight slashes vs backslashes ever again in my life :) But it's not my priority, though, PRs welcome. - I've used
APM32F003F6P6
(32kB Flash / 4kB RAM) variant, if you want to useAPM32F003F4P6
(16kB Flash / 2kB RAM), remember to tweak theMakefile
-LD_SCRIPT
variable should point to geehy/APM32F00x/Source/gcc/gcc_APM32F00xx4.ld in such case.
I've successfully used a Segger J-Link v8
clone + OpenOCD for
flashing and debugging. Support for APM32F00x
is not yet included in the official
OpenOCD
release, however (and Geehy
only released Windows binaries, as far I know).
I have found this patch,
fixed it to apply cleanly on top of the current code and actually compile, it seems to work fine.
You can grab patched OpenOCD
from my forked repo,
from the apm32
branch (you have to compile it yourself, of course).
For J-Link
probe you can use openocd.cfg directly:
$ openocd -f openocd.cfg
For other probes tweak the first commandi in the openocd.cfg
file accordingly.
In order to build the sample project:
- set
ARM_TOOLCHAIN_PATH
environment variable to point to the directory containingarm-none-eabi-gcc
and other binaries, or set yourPATH
accordingly (on Ubuntu you can justapt-get install gcc-arm-none-eabi gdb-multiarch
). - run
make
- if all is OK, you should getout/blinky.elf
file. - flash it to your test board, e.g. with
OpenOCD
andgdb
, issuingload
command ingdb
.
All my test were performed with a bare minimum circuit done on the breadboard.
The only necessary connections are:
- +5V to
VDD
(pin 9), ground toVSS
(pin 7), some decoupling capacitor - 1uF capacitor between
VCAP
(pin 8) and ground - LED (with 1k resistor in series), between
PD4
(pin 1) and ground - your SWD probe of choice attached to
SWCLK
(pin 19),SWDIO
(pin 18) andNRST
(pin 4).
WARNING: the capacitor between VCAP
and ground is very important. I've lost a few hours
debugging random Hard Fault
crashes early in startup code, just to realize that I connected
the capacitor to the wrong pin by mistake. On the other hand, demo board from Geehy
uses 10k
pull-up resistor on SWDIO
and 10k pull-down on SWCLK
, but everything works fine for me
without those resistors.