Skip to content

STM32F4 analog wave generator with precise UART control

License

Notifications You must be signed in to change notification settings

frolovilya/stm32-wave-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stm32-wave-generator

STM32F4 analog wave generator with precise UART control. Uses built-in DAC to produce waves of various form and frequency generated by Welle library.

Build

Install ARM GNU Toolchain. arm-none-eabi compiler is required.

On Mac could be done with brew as well:

brew install --cask gcc-arm-embedded

Install STM32CubeProgrammer to flash STM32 via ST-Link.

There's also an all-in-one STM32CubeCLT command tools package available.

Build the project using CMake:

mkdir build; cd build

# Using USART2 by default if -DUSE_USART3=1 flag isn't provided
cmake ../ -DPROGRAMMER_CLI=/opt/ST/STM32CubeCLT_1.15.1/STM32CubeProgrammer/bin \
    -DUSE_USART3=0

make

# Upload to the device
make flash

Connectivity

DAC output pin is PA4.

Using USART2 by default: TX PA2, RX PA3. Note that on Nucleo boards USART2 is routed to ST-Link USB instead.

Using USART3 when built with -DUSE_USART3=1: TX PC10, RX PC11.

Usage

Command Syntax

sine|square|saw|triangle 20..20000LF

Note that LF(\n) at the end is required.

Sending Commands via Serial Port

When using Nucleo board or any UART to USB adapter it's possible to send commands via a serial port.

# Install picocom serial port terminal
brew install picocom

# Find your connected device
ls /dev/tty.*

# Start session (press Ctrl+a Ctrl+x to exit)
picocom --echo --omap crlf --imap lfcrlf -b 115200 /dev/tty.usbmodem14203

Examples

sine 440
Generating 440Hz sine wave

sine-440

square 200
Generating 200Hz square wave

square-200

saw 300
Generating 300Hz saw wave

saw-300

triangle 600
Generating 600Hz triangle wave

triangle-600

Integration Tests

Tests are using Digilent WaveForms SDK and require a compatible Analog Discovery device to be plugged-in and connected to the corresponding SMT32F4 pins.

cd ./integration-tests
mkdir build; cd build

# The following pins configuration is default
cmake ../ -DSCOPE_CHANNEL=1 \
    -DDIGITAL_TX_PIN=0 \
    -DDIGITAL_RX_PIN=1

make

# Run tests
./integration-tests