Git Product home page Git Product logo

stm32f411-black-pill-usb-wav-player's Introduction

STM32F411 "Black Pill" USB WAV Player

Project description

This is just a training project that reads, parses and plays WAV files using PWM from a USB drive (in FAT32 filesystem).
Uses a STM32F411CE "Black Pill" board running at 96MHz.

Supported WAV formats:

  • 8, 16 bit depths (16bit is converted to 8bit).
  • Stereo / mono (In mono mode, right channel is copied to the left channel).
  • 8, 16, 22.05, 32, 44.1, 48, 96KHz sample rates.

22.05 and 44.1KHz have 0.04% error (22059Hz, 44117Hz), it plays only 1.5 seconds faster every hour.
Other WAV formats will be skipped.

In 8/16/32/48/96KHz PWM frequency is 384KHz, max PWM value 249, audio values over that will cause minor clipping.
I used Audacity and normalized the level to -0.1dB, that limited the output within the limits.

In 22.05/44.1KHz PWM frequency is 352.941KHz, max PWM value 271, so there's no clipping problem.

The PWM uses DMA burst mode, a very efficient and clean method to update multiple PWM channels at once.

PWM outputs are as follows:

  • Right channel: PA8
  • Left channel: PA9

For filtering the PWM, I used this calculator: http://sim.okawa-denshi.jp/en/Sallen3tool.php
The parameters were Chebyshev filtering, fc=22KHz.
The result was really good for coming from 8-bit PWM.

The SWO output is enabled on PB3, you can see the debug messages using SWO console.
You can see them without debugging, just connect the ST-Link utility, open "Prinf via SWO viewer", setting clock to 96000000Hz.

Example log:

  Device connected
  Device ready
  Drive mounted
  Opening file: 1-STER~1.WAV
  WAV Info: Stereo, 48KHz, 8bit
  Playback started
  Playback stopped

  Opening file: 7.WAV
  WAV Info: Stereo, 44.1KHz, 16bit
  Playback started
  Playback stopped

  Opening file: 1.WAV
  WAV Info: Stereo, 48KHz, 16bit
  Playback started
  Playback stopped

  Opening file: 6.WAV
  WAV Info: Stereo, 96KHz, 16bit
  Playback started
  Playback stopped

For more details, check:

  /Inc/files.h
  /Inc/pwmAudio.h
  /Src/files.c
  /Src/pwmAudio.c

How to use

Connect a USB drive with wav files in the root folder (/), it will automatically start playing all files found in a loop .

Firmware

You can download already compiled binaries in the Release folder (411.bin file)
If you want to compile your own:

  • Download STM32 Cube IDE
  • Clone or download the code
  • Open STM32 Cube IDE, import existing project and select the folder where the code is.
  • It should recognize it and be ready for compiling or modifying for your own needs.

The code is stripped from all the CubeMX libraries, it needs to regenerate them.
Open the CubeMX (.IOC) file and make any small change (Ex. set an unused GPIO as input), then and revert it and close saving changes.
CubeMx will make new code, and now it will compile correctly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.