STM32F1xx micro-controller C firmware template
Go to file
King Kévin 88349d3918 app: working clock generator firmware 2022-05-10 10:50:22 +02:00
lib app: working clock generator firmware 2022-05-10 10:50:22 +02:00
libopencm3@2b603ff2af libopencm3: use branch with OTG fix 2020-12-11 00:00:25 +01:00
.gitignore cherry-pick from busvoodoo branch, part 2 2018-02-18 15:20:01 +01:00
.gitmodules libopencm3: use branch with OTG fix 2020-12-11 00:00:25 +01:00
Doxyfile doc: fix documentation 2020-01-03 00:16:59 +01:00
LICENSE.txt add GPLv3 license file 2018-02-13 15:14:10 +01:00 app: working clock generator firmware 2022-05-10 10:50:22 +02:00
Rakefile flash_internal: add support for STM32F401CE 2021-05-14 14:30:15 +02:00
application.c app: working clock generator firmware 2022-05-10 10:50:22 +02:00
application.ld .ld: minor, fix typo 2021-05-14 14:28:48 +02:00
bootloader.c bootloader: fix compiler warning 2022-05-10 10:48:05 +02:00
bootloader.ld .ld: minor, fix typo 2021-05-14 14:28:48 +02:00
global.c global: improve sleep_us for STM32F4 2020-12-17 12:48:37 +01:00
global.h global: add ADC macros 2020-12-17 12:51:23 +01:00

clock generator (up to 125 MHz) using AD9850.


  • up to 125 MHz@5V, 100MHz@3.3V
  • display shows desired frequency in mHz
  • actual output uses AD9850's 0.0291 Hz resolution
  • square and sine wave output (and it's inverse)
  • 3.3V and 5V output


the clock generator uses following parts:

  • WeAct MiniF4, based on a STM32F401CCU6
  • Analog Devices AD9850, to generator the clock
  • HD44780 LCD display (1x16), to display the set frequency
  • rotary encoder, to set the frequency
  • switch, to set the output voltage
  • coin cell, to save set frequency


All pins are configured using defines in the corresponding source code.



The source code uses the libopencm3 library. The projects is already a git submodules. It will be initialized when compiling the firmware. Alternatively you can run once: git submodule init and git submodule update.


To compile the firmware run rake.


To generate doxygen documentation run rake doc.


There are two firmware images: bootloader and application. The bootloader image allows to flash the application over USB using the DFU protocol. The bootloader is started first and immediately jumps to the application if it is valid and the DFU mode is not forced (i.e. by pressing the user button on the board or requesting a DFU detach in the application). The application image is the main application and is implemented in application.c. It is up to the application to advertise USB DFU support (i.e. as does the provided USB CDC ACM example).

The simplest way do flash the bootloader image is using the embedded bootloader. By pressing the BOOT0 button (setting the pin low) while powering or resetting the device, the micro-controller boot its embedded UART/USB DFU bootloader. Connect a USB cable and run rake dfu_bootloader.

Once the bootloader is flashed, it is possible to flash the application over USB using the DFU protocol by running rake flash (equivalent to rake dfu_application. To force the bootloader to start the DFU mode press the user button or short a pin, depending on the board. Note: I use my own DFU bootloader instead of the embedded bootloader because I was not able to start the embedded USB DFU bootloader from the application.

The images can also be flash using SWD (Serial Wire Debug) in case the firmware gets stuck and does not provide USB functionalities. For that you need an SWD adapter. The Makefile uses a ST-Link V2 programmer along OpenOCD software (default), or Black Magic Probe. To flash the bootloader using SWD run rake swd_bootloader (this will also erase the application). To flash the application using SWD run rake swd_application (or rake swd). To erase all memory and unlock read/write protection, run rake remove_protection.


SWD also allows to debug the code running on the micro-controller using GDB. To start the debugging session run rake debug.


The firmware offers serial communication over USART1 and USB (using the CDC ACM device class).