ascillato / shelly-dimmer-stm32

Open-source firmware for STM32 co-processor on the Shelly Dimmer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An open-source firmware for the STM32 co-processor on the Shelly Dimmer and Shelly Dimmer 2.

License: GPL v3 Open in Gitpod Open in Visual Studio Code

Disclaimer

⚠️ DANGER OF ELECTROCUTION ⚠️

The Shelly Dimmer 1 and Shelly Dimmer 2 connect to mains electricity (AC power), therefore there is danger of electrocution if not installed properly. If you don't know how to install it, please call an electrician (Beware: certain countries prohibit installation without a licensed electrician present). Remember: SAFETY FIRST. It is not worth the risk to yourself, your family and your home if you don't know exactly what you are doing. Never tinker or try to flash a device using the serial programming interface while it is connected to MAINS ELECTRICITY (AC power).

We don't take any responsibility nor liability for using this software nor for the installation or any tips, advice, videos, etc. given by any member of this site or any related site.

Pre-build binary

See the releases page to download the latest pre-build binary.

Instructions

Use Gitpod to edit and compile the firmware from within your browser.

For building local on your PC do:

  1. git clone --recurse-submodules https://github.com/jamesturton/shelly-dimmer-stm32.git
  2. cd shelly-dimmer-stm32
  3. make -C libopencm3 # (Only needed once)
  4. make -C src

If you have an older git, or got ahead of yourself and skipped the --recurse-submodules you can fix things by running git submodule update --init (This is only needed once)

To flash the firmware directly to the STM32 chip using a programmer such as the Black Magic Probe (ST-Link could also be used):

  1. make -C src flash BMP_PORT=/dev/ttyBmpGdb

Communication protocol

Information on the communication protocol used can be found here.

Pinout

Here is a guess of the pinout of the STM32F031K6 chip.

stm32f031k6

Pin Name Function - Shelly Dimmer 1 Function - Shelly Dimmer 2 Pin type
1 VDD 3V3 3V3
2 OCS_IN - -
3 OCS_OUT - -
4 NRST NRST NRST
5 VDDA 3V3 3V3
6 PA0 CF1 HLW8012 - Input
7 PA1 CF HLW8012 - Input
8 PA2 - - Input
9 PA3 - ?? Input
10 PA4 - - Input
11 PA5 - Live pin sense Analog
12 PA6 TEST POINT - Input
13 PA7 TEST POINT Output pin sense Analog
14 PB0 - ?? Input
15 PB1 - Board HW version? Input
16 PB2 Zero-crossing detection ?? Input ExtInt
17 VDD GND GND
18 PA8 ON MOSFET 1 - Input
19 PA9 USART_TX USART_TX AltFun
20 PA10 USART_RX USART_RX AltFun
21 PA11 ON MOSFET 2 ON MOSFET 1 Output
22 PA12 - ON MOSFET 2 Output
23 PA13 SWDIO SWDIO AltFun
24 PA14 SWCLK SWCLK AltFun
25 PA15 - - Input
26 PB3 - - Input
27 PB4 - - Input
28 PB5 - - Input
29 PB6 - - Input
30 PB7 - Pin7 A42 BAKN Input ExtInt Live - Output
31 BOOT0 BOOT0 BOOT0
32 PB8 SEL HLW8012 - Input

Useful links

About

Open-source firmware for STM32 co-processor on the Shelly Dimmer.

License:GNU General Public License v3.0


Languages

Language:C 83.9%Language:Makefile 15.4%Language:Dockerfile 0.7%