stm32f1/README.md

105 lines
4.1 KiB
Markdown
Raw Normal View History

2022-10-28 13:28:34 +02:00
Firmware for the crown counter.
project
=======
summary
-------
2022-10-28 13:28:34 +02:00
The crow counter just counts how many (per day and in total) caps (e.g. crown cork) have entered the basket.
technology
----------
2022-10-28 13:28:34 +02:00
An infra-red LED and photo-detector create a light barrier, broken when crossed by caps.
An RTC keeps track of the days.
2 TM1637 7-segment displays show how many caps passed in total and today.
2016-01-29 12:12:04 +01:00
board
=====
The underlying template also supports following board:
2016-01-29 12:12:04 +01:00
2020-11-30 15:03:32 +01:00
- [WeAct MiniF4](https://github.com/WeActTC/MiniF4-STM32F4x1), based on a STM32F401CCU6
2016-01-29 12:12:04 +01:00
**Which board is used is defined in the Makefile**.
2017-04-15 13:58:39 +02:00
This is required to map the user LED and button provided on the board
2016-01-29 12:12:04 +01:00
connections
===========
2016-01-29 12:12:04 +01:00
2022-10-28 13:28:34 +02:00
Connect the peripherals the following way:
2016-01-29 12:12:04 +01:00
2022-10-28 13:28:34 +02:00
- IR LED: connected across 3.3V with potentiometer to adjust brightness
- IR photo-detector: PB5
- first TM1637 7-segment 4-digit display: CLK to PB6, DIO to PB7
- second TM1637 7-segment 4-digit display: CLK to PB8, DIO to PB9
- CR1220 to VBAT for the RTC
2022-10-28 13:28:34 +02:00
note
----
at first I use a KY-032 infrared sensor detects when a cap passes through the basket.
this modules the infra-red LED (set to 38 kHz), and has an IR demodulator (at 38 kHz).
I though this would be less noise prone, particularly from external IR sources.
turns out it is a lot more.
I tested will the cap reflecting the IR, but this is sometimes to short, and the demodulator might not detect it.
I tested with the cap breaking the barrier, but the IR demodulator doesn't allow continuous IR burst detection and has a hard time detecting when it is broken and restarted.
in the end, a simple LED on and photo-detector to create a barrier is super simple and efficient.
2016-01-29 12:12:04 +01:00
code
====
2016-01-29 12:12:04 +01:00
dependencies
------------
2016-01-29 12:12:04 +01:00
The source code uses the [libopencm3](http://libopencm3.org/) library.
The projects is already a git submodules.
2017-08-07 23:13:30 +02:00
It will be initialized when compiling the firmware.
Alternatively you can run once: `git submodule init` and `git submodule update`.
2016-01-29 12:12:04 +01:00
firmware
--------
2016-01-29 12:12:04 +01:00
2017-08-07 23:13:30 +02:00
To compile the firmware run `rake`.
2016-01-29 12:12:04 +01:00
documentation
-------------
2017-08-07 23:13:30 +02:00
To generate doxygen documentation run `rake doc`.
2016-01-29 12:12:04 +01:00
flash
-----
2017-04-15 13:58:39 +02:00
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`).
2017-08-07 23:13:30 +02:00
The `application` image is the main application and is implemented in `application.c`.
2017-04-15 13:58:39 +02:00
It is up to the application to advertise USB DFU support (i.e. as does the provided USB CDC ACM example).
2020-11-30 15:03:32 +01:00
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`.
2017-04-15 13:58:39 +02:00
2020-11-30 15:03:32 +01:00
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`.
2017-04-15 13:58:39 +02:00
To force the bootloader to start the DFU mode press the user button or short a pin, depending on the board.
2020-11-30 15:03:32 +01:00
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.
2021-05-03 13:38:58 +02:00
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`).
2020-11-30 15:03:32 +01:00
To erase all memory and unlock read/write protection, run `rake remove_protection`.
2016-01-29 12:12:04 +01:00
debug
2016-01-29 12:12:04 +01:00
-----
SWD also allows to debug the code running on the micro-controller using GDB.
2017-08-07 23:13:30 +02:00
To start the debugging session run `rake debug`.
2016-01-29 12:12:04 +01:00
USB
---
The firmware offers serial communication over USART1 and USB (using the CDC ACM device class).