135 lines
4.6 KiB
Markdown
135 lines
4.6 KiB
Markdown
This is the firmware for the sound lever enforcer.
|
|
It will cut the power of speakers when it's too loud.
|
|
|
|
project
|
|
=======
|
|
|
|
summary
|
|
-------
|
|
|
|
The sound level enforcer receives measurements from a sound level meter over Bluetooth.
|
|
The sound level is then show on a display (0 if it is not connected or receives no data).
|
|
If this level is below the threshold configured, the display is dim.
|
|
If the level is above the threshold configured, the brightness is higher.
|
|
If the level is above the threshold configured, for a set amount of time, a relay it activated.
|
|
The relay's purpose is to cut the power of speakers/mixer.
|
|
"too loud" will be shown on the display, and the button will light up.
|
|
Press the button to reset the device.
|
|
The relay will be deactivated, and the cycle starts again.
|
|
|
|
When powered up or reset, the display will show the sound level threshold (followed by the unit "dBa"), and duration (followed by the unit "dBa").
|
|
To change the sound level threshold, enter "threshold xxx" on the serial interface (over USB, or UART).
|
|
To change the sound level duration, enter "duration xxx" on the serial interface (over USB, or UART).
|
|
|
|
technology
|
|
----------
|
|
|
|
The firmware runs on a [black pill](https://wiki.cuvoodoo.info/doku.php?id=stm32f1xx#black_pill) development board.
|
|
It is based on a STM32F103C8T6 micro-controller.
|
|
This will do all the processing and control the peripherals.
|
|
|
|
The Bluetooth module is a HC-05.
|
|
It should be configured to automatically connect to the sound level meter.
|
|
It should receive the sound level over Bluetooth in the format "123.4 dBa\n".
|
|
The measurement will be forwarded to the micro-controller over the UART part configured at 115200 bps 8N1.
|
|
|
|
This does not use a Bluetooth Low Energy (BLE) module because it does not fit the needs.
|
|
There is no need to save energy since the device needs permanent power just for the display.
|
|
There is a constant stream of data (not fitting BLE principles).
|
|
The is a specified Classic Bluetooth profile for serial data: Serial Port Profile (SPP).
|
|
BLE module use non-standard GATT characteristics for serial data transfer.
|
|
|
|
The display is a 4-digit 7-segment LED display.
|
|
This is controlled by a TM1367.
|
|
|
|
The relay is a SRD-05VDC-SL-C module (250V 10A).
|
|
Connect it to the device using a 2.5 mm jack.
|
|
|
|
The momentary button should have a built-in LED.
|
|
|
|
connections
|
|
===========
|
|
|
|
Connect the peripherals as described below.
|
|
|
|
HC-05 Bluetooth SPP module:
|
|
|
|
- STATE: no connect
|
|
- RX: no connect
|
|
- TX: USART3_RX/PB11
|
|
- GND: ground
|
|
- VCC: 5V
|
|
- EN: no connect
|
|
|
|
button (momentary, with LED)
|
|
|
|
- +: 5V
|
|
- -: 470 Ohm resistor to PB12 (sometimes the resistor is already built in the button)
|
|
- S: GND
|
|
- S: NRST
|
|
|
|
7-segment display TM1637:
|
|
|
|
- GND: ground
|
|
- VCC: 5V
|
|
- DIO: PB13
|
|
- CLK: PB14
|
|
|
|
relay, connected to 2.5 mm TRS jack:
|
|
|
|
- tip, VCC: 5V
|
|
- ring, IN: PB15
|
|
- sleeve, GND: ground
|
|
|
|
All pins are configured using `define`s in the corresponding source code.
|
|
|
|
code
|
|
====
|
|
|
|
dependencies
|
|
------------
|
|
|
|
The source code uses the [libopencm3](http://libopencm3.org/) 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`.
|
|
|
|
firmware
|
|
--------
|
|
|
|
To compile the firmware run `rake`.
|
|
|
|
documentation
|
|
-------------
|
|
|
|
To generate doxygen documentation run `rake doc`.
|
|
|
|
flash
|
|
-----
|
|
|
|
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 `bootlaoder` image will be flashed using SWD (Serial Wire Debug).
|
|
For that you need an SWD adapter.
|
|
The `Makefile` uses a ST-Link V2 along OpenOCD software.
|
|
To flash the `booltoader` using SWD run `rake flash_booloader`.
|
|
|
|
Once the `bootloader` is flashed it is possible to flash the `application` over USB using the DFU protocol by running `rake flash`.
|
|
To force the bootloader to start the DFU mode press the user button or short a pin, depending on the board.
|
|
It is also possible to flash the `application` image using SWD by running `rake flash_application`.
|
|
|
|
debug
|
|
-----
|
|
|
|
SWD also allows to debug the code running on the micro-controller using GDB.
|
|
To start the debugging session run `rake debug`.
|
|
|
|
USB
|
|
---
|
|
|
|
The firmware offers serial communication over USART1 and USB (using the CDC ACM device class).
|