Turns your STM32F4 development board into an analog audio-level signal generator with precise UART control. Uses built-in 12-bit DAC and 192kHz sampling rate to produce waves of various form, frequency and level generated by Welle library.
Install Welle library header.
Install STM32CubeCLT command tools package with arm-none-eabi-gcc, STM32_Programmer_CLI and ST-LINK_gdbserver tools included.
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.18.0/STM32CubeProgrammer/bin/STM32_Programmer_CLI \
-DUSE_USART3=0
make
# Upload to the device
make flash
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, so that you can send UART commands directly by plugging-in the board via USB.
Using USART3 when built with -DUSE_USART3=1
:
TX PC10, RX PC11. Use this feature when external UART control is required.
Built-in DAC produces signals with max voltage = Vdda, so for 3.3V supply it outputs signals with a peak-to-peak level 3.3V and DC offset 1.65V. Connect a capacitor to the DAC output pin to remove the DC offset and generate signals oscillating around 0V with a peak output of 1dBV.
Typical levels:
- Line: -10dBV
- Pro line: 4dBu
- Phono: -45dBV
Below is the conversion table of the supported level units:
Unit | Conversion from mV peak |
---|---|
mV_RMS | mV / sqrt(2) |
dBV | 20 * log(mV_RMS) |
dBu | 20 * log(mV_RMS / 0.775) |
# WaveForm Frequency(Hz) Level(mV)
{sine|square|saw|triangle} frequency{[Hz]|kHz} level{[mV]|mVRMS|dBV|dBu}LF
Note that LF(\n)
at the end is required.
Supported frequency is in the range from 20Hz to 20000Hz.
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,bsdel -b 115200 /dev/tty.usbmodem14203
sine 440Hz -10dBV
# Generating sine, 440Hz, 316mV RMS (-10dBV) signal
square 100Hz 200mVRMS
# Generating square, 100Hz, 200mV RMS (-6dBV) signal
saw 1kHz 100mV
# Generating saw, 1000Hz, 71mV RMS (-23dBV) signal
triangle 10kHz -3dbU
# Generating triangle, 10000Hz, 548mV RMS (-5dBV) signal