261 lines
7.7 KiB
Markdown
261 lines
7.7 KiB
Markdown
firmware for the Bahn Uhr controller.
|
|
|
|
project
|
|
=======
|
|
|
|
summary
|
|
-------
|
|
|
|
This is the controller for a salvaged and modded Bahnsteig Uhr:
|
|
|
|
- the track is made of white translucent ceramic, and RGBW LED strips illuminate it
|
|
- a motor uses the dial drive to turn the dials (in theory with settable time)
|
|
- LED panels allow to show text on both sides
|
|
- controllable over the network using Art-Net
|
|
|
|
technology
|
|
----------
|
|
|
|
controller comprises:
|
|
|
|
- a [STM32 F4 series micro-controller](https://www.st.com/en/microcontrollers-microprocessors/stm32f4-series.html)-based black pill
|
|
- a DRV8825 stepper motor allows turning the dials (hour is linked to minute)
|
|
- reed switch, to home dial
|
|
- P1 RGB LED panel (128x64), to display text on front side
|
|
- WS2812b panel (2x 32x8), to display text
|
|
- nMOS transistors to control 12V LED strips, to illuminate the track
|
|
- ESP8266-based ESP-01 to connect to network
|
|
- power connectors (0,5,12V-4pin and 12V-barrel input, 5V outputs for LED panels, 12V for motor and LED strips)
|
|
|
|
Art-Net
|
|
-------
|
|
|
|
The Bahn Uhr controller gets data over the network using Art-Net.
|
|
The mapping is as follows (universe without offset, channel, target).
|
|
|
|
clock illumination color (RGBW LED strip):
|
|
|
|
- 0, 0, red high byte
|
|
- 0, 1, red low byte
|
|
- 0, 2, green high byte
|
|
- 0, 3, green low byte
|
|
- 0, 4, blue high byte
|
|
- 0, 5, blue low byte
|
|
- 0, 4, white high byte
|
|
- 0, 5, white low byte
|
|
|
|
dials position:
|
|
|
|
- 1, 0, hours (0-11)
|
|
- 1, 1, minutes (0-59)
|
|
- 1, 2, seconds (0-59)
|
|
- 1, 3, direction
|
|
- 1, 4, speed
|
|
|
|
text display:
|
|
|
|
font display, line 1:
|
|
|
|
- 2, 0, red intensity (0 to use clock illumination color)
|
|
- 2, 1, green intensity (0 to use clock illumination color)
|
|
- 2, 2, blue intensity (0 to use clock illumination color)
|
|
- 2, 3, horizontal position (0 is left), high signed byte
|
|
- 2, 3, horizontal position (0 is left), low byte
|
|
- 2, 4+, text (NULL ended)
|
|
|
|
font display, line 2:
|
|
|
|
- 3, 0, red intensity (0 to use clock illumination color)
|
|
- 3, 1, green intensity (0 to use clock illumination color)
|
|
- 3, 2, blue intensity (0 to use clock illumination color)
|
|
- 3, 3, horizontal position (0 is left), high signed byte
|
|
- 3, 3, horizontal position (0 is left), low byte
|
|
- 3, 4+, text (NULL ended)
|
|
|
|
font display, line 3:
|
|
|
|
- 4, 0, red intensity (0 to use clock illumination color)
|
|
- 4, 1, green intensity (0 to use clock illumination color)
|
|
- 4, 2, blue intensity (0 to use clock illumination color)
|
|
- 4, 3, horizontal position (0 is left), high signed byte
|
|
- 4, 3, horizontal position (0 is left), low byte
|
|
- 4, 4+, text (NULL ended)
|
|
|
|
back display, line 1:
|
|
|
|
- 5, 0, red intensity (0 to use clock illumination color)
|
|
- 5, 1, green intensity (0 to use clock illumination color)
|
|
- 5, 2, blue intensity (0 to use clock illumination color)
|
|
- 5, 3, horizontal position (0 is left), high signed byte
|
|
- 5, 3, horizontal position (0 is left), low byte
|
|
- 5, 4+, text (NULL ended)
|
|
|
|
back display, line 2:
|
|
|
|
- 6, 0, red intensity (0 to use clock illumination color)
|
|
- 6, 1, green intensity (0 to use clock illumination color)
|
|
- 6, 2, blue intensity (0 to use clock illumination color)
|
|
- 6, 3, horizontal position (0 is left), high signed byte
|
|
- 6, 3, horizontal position (0 is left), low byte
|
|
- 6, 4+, text (NULL ended)
|
|
|
|
board
|
|
=====
|
|
|
|
The underlying template also supports following board:
|
|
|
|
- [WeAct MiniF4](https://github.com/WeActTC/MiniF4-STM32F4x1), based on a STM32F401CCU6
|
|
|
|
connections
|
|
===========
|
|
|
|
Connect the peripherals the following way (STM32F4xx signal; STM32F4xx pin; peripheral pin; peripheral signal; comment):
|
|
|
|
- *list board to peripheral pin connections*
|
|
|
|
DRV8825 stepper motor driver (using one timer for PWM output):
|
|
|
|
- STEP: PA15/TIM2_CH1
|
|
- DIRECTION: PB15
|
|
- nSLEEP: PB14, shorted to nRESET
|
|
- nRESET: PB14, with external 10kOhm pull-down resistor
|
|
- nENABLE: PB13, with external 10kOhm pull-up resistor
|
|
- FAULT: PB12, with external 10kOhm pull-up resistor
|
|
|
|
reed switch, to home dial position:
|
|
|
|
- 1: GND
|
|
- 2: PB4
|
|
|
|
LED driver (using one timer for PWM outputs):
|
|
|
|
- gate 0: PB6/TIM4_CH1
|
|
- gate 1: PB7/TIM4_CH2
|
|
- gate 2: PB8/TIM4_CH3
|
|
- gate 3: PB9/TIM4_CH4
|
|
|
|
WS2812b LED matrix:
|
|
|
|
- DOUT: PB5 (SPI1_MOSI)
|
|
|
|
RGB matrix (using one DMA)
|
|
|
|
- DR1: PA2
|
|
- DG1: PA3
|
|
- DB1: PA4
|
|
- DR2: PA5
|
|
- DG2: PA6
|
|
- DB2: PA7
|
|
- CLK: PA0
|
|
- LAT: PA1
|
|
- A: PB0
|
|
- B: PB1
|
|
- C: PB2
|
|
- D: PB3
|
|
- OE: PB10
|
|
|
|
ESP8266-based ESP-01 (using one UART):
|
|
|
|
- RX: PA9/USART1_TX
|
|
- TX: PA10/USART1_RX
|
|
|
|
EN is pulled to VCC using 10 kOhm for the ESP to start.
|
|
I replaced the 1 MB flash with a 4MB flash to be sure I won't be annoyed by the space limit.
|
|
I flashed the AT firmware from ESP8266_NONOS_SDK-3.0.5:
|
|
|
|
~~~
|
|
esptool.py --chip auto --port /dev/ttyUSB0 --baud 115200 erase_flash
|
|
esptool.py -p /dev/ttyUSB0 --chip esp8266 write_flash -fm dio -ff 26m --flash_size 2MB-c1 0x00000 ./bin/boot_v1.7.bin 0x01000 ./bin/at/1024+1024/user1.2048.new.5.bin 0x1fc000 ./bin/esp_init_data_default_v08.bin 0xfe000 ./bin/blank.bin 0x1fe000 ./bin/blank.bin 0x1fb000 ./bin/blank.bin
|
|
~~~
|
|
|
|
to test the firmware, issue AT commands:
|
|
|
|
~~~
|
|
picocom -b 115200 /dev/ttyUSB0 --omap crcrlf
|
|
AT
|
|
|
|
OK
|
|
|
|
AT+GMR
|
|
version information
|
|
~~~
|
|
|
|
configure the access point in flash:
|
|
|
|
~~~
|
|
# set station mode
|
|
AT+CWMODE_DEF=1
|
|
# set AP credentials
|
|
AT+CWJAP_DEF="essid","password"
|
|
~~~
|
|
|
|
free:
|
|
|
|
- PB4, PB5
|
|
- PA8/TIM1_CH1
|
|
|
|
used:
|
|
|
|
- PA12: USB DP
|
|
- PA11: USB DM
|
|
- PC13: LED
|
|
- PC14/PC15: 32kHz XTAL
|
|
|
|
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 simplest way do flash the `bootloader` image is using the embedded bootloader.
|
|
By pressing the BOOT0 button (setting the pin low) while powering or resetting the device, the micro-controller boot its embedded UART/USB DFU bootloader.
|
|
Connect a USB cable and run `rake dfu_bootloader`.
|
|
|
|
Once the `bootloader` is flashed, it is possible to flash the `application` over USB using the DFU protocol by running `rake flash` (equivalent to `rake dfu_application`.
|
|
To force the bootloader to start the DFU mode press the user button or short a pin, depending on the board.
|
|
Note: I use my own DFU bootloader instead of the embedded bootloader because I was not able to start the embedded USB DFU bootloader from the application.
|
|
|
|
The images can also be flash using SWD (Serial Wire Debug) in case the firmware gets stuck and does not provide USB functionalities.
|
|
For that you need an SWD adapter.
|
|
The `Makefile` uses a ST-Link V2 programmer along OpenOCD software (default), or Black Magic Probe.
|
|
To flash the `bootloader` using SWD run `rake swd_bootloader` (this will also erase the application).
|
|
To flash the `application` using SWD run `rake swd_application` (or `rake swd`).
|
|
To erase all memory and unlock read/write protection, run `rake remove_protection`.
|
|
|
|
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).
|