STM32F1xx micro-controller C firmware template
Go to file
King Kévin 9b8632c893 app: ensure track is not repeated 2021-06-24 21:49:57 +02:00
lib remove unused libraries 2020-10-11 12:48:31 +02:00
libopencm3@cb0661f81d update libopencm3 2020-02-17 11:43:47 +01:00
.gitignore cherry-pick from busvoodoo branch, part 2 2018-02-18 15:20:01 +01:00
.gitmodules remove STM32duino-bootloader 2016-08-14 19:03:17 +02:00
Doxyfile doc: fix documentation 2020-01-03 00:16:59 +01:00
LICENSE.txt add GPLv3 license file 2018-02-13 15:14:10 +01:00
README.md README: document two new secret modes 2021-04-23 15:29:16 +02:00
Rakefile Rakefile: allow to specify CPUTADIP to use SWD with CKS32 2020-06-24 11:57:45 +02:00
application.c app: ensure track is not repeated 2021-06-24 21:49:57 +02:00
application.ld ld: update ld script to updated libopencm3 2020-01-12 15:52:27 +01:00
bootloader.c bootloader: disable clocks after domains used 2020-06-24 11:57:22 +02:00
bootloader.ld ld: update ld script to updated libopencm3 2020-01-12 15:52:27 +01:00
global.c replace header license with SPDX statement 2020-06-10 19:04:41 +02:00
global.h global: add RST macros for GPIO 2020-06-24 11:57:18 +02:00

README.md

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 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 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).