stm32f1/README.md

128 lines
4.6 KiB
Markdown

This is the firmware for the Dachboden Klo-Assistant.
project
=======
This project's original purpose was to indicate the occupancy state of the toilet.
If the toilet was in use, a red light on a shield would indicate it is occupied.
Else a green light indicates it is free.
Next, a display has been added to show the time spent in the water room.
This would put some pressure on the user to not spend too much time on the loo and hold up the queue.
Finally, it has been connected to speakers.
A welcome message would greed the new comer, followed by a (random) pleasant music.
Then the time passed inside is announced, followed by a (random) comical message.
And the loop continues with another song.
Once you exit the place, a short (random) message is played.
Two secret modes have been added:
- if the door is closed, opened, and closed, each step within 2 seconds, then techno music is continuously played (replacing all toilet messages)
- if the door is further opened and closed, sketches from the Känguru-Chroniken by Marc-Uwe Kling are played
board
=====
The devices is comprised by following components:
- a [blue pill](https://wiki.cuvoodoo.info/doku.php?id=stm32f1xx#blue_pill) development board, based on a STM32F103C8T6 micro-controller
- a GW1584 step down voltage converter module to lower the 12V input to 5V for all peripherals
- a switch to cut the power, allowing other devices to connect to the Bluetooth speakers
- a micro-switch in the door lock detects when a user closed the door to use the toilet in peace
- a SK6812 RGBW LED strip illuminates the shield to indicate if the toilet is free or occupied
- a Titan TM1637 4-digit 7-segment display shows the time is second passed since the door has been locked
- a Catalex YX5300 MP3 player reads the songs and announcements from a micro-SD card and outputs it to a 3.5 mm stereo jack
- a Taotronics TT-BA01 Bluetooth transmitter with input 3.5 mm stereo jack connects to the room speaker to send the audio
connections
===========
GW1584 step down voltage converter module:
- IN-: outer shell of 5.5/2.1 barrel connector
- IN+: inner pin of 5.5/2.1 barrel connector, after power switch (6-12V)
- OUT-: ground
- OUT+: 5V
micro-switch in door lock:
- COM: ground
- NO: PB8, use external pull-up resistor (10k to 5V)
SK6812 RGBW LED strip:
- 5V (green cable): 5V
- DIN (yellow cable): PB15 (SPI2_MOSI), through voltage shifter (to get clean 5V signal)
- GND (orange cable): GND
Titan TM1637 4-digit 7-segment display:
- GND: GND
- VCC: 5V
- DIO: PB7
- CLK: PB6
Catalex YX5300 MP3 player:
- GND: GND
- VCC: 5V
- TX: PA3 (UART2_RX)
- RX: PA2 (UART2_TX)
Taotronics TT-BA01:
- 3.5 mm stereo jack: to MP3 player
- cable soldered to button: PA0 (this allows to switch on/off the transmitter, and put it into pairing mode)
- cable soldered to blue: PA1 (this allow to know in which state the transmitter is)
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 `bootloader` 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).