Skip to content

Commit

Permalink
Merge pull request #1 from jamesturton/shelly-dimmer-2
Browse files Browse the repository at this point in the history
Add support for Shelly dimmer 2
  • Loading branch information
jamesturton authored Nov 14, 2020
2 parents f240a11 + 1f7bfa9 commit 1a0a322
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 134 deletions.
14 changes: 12 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug (BlackMagicProbe)",
"name": "Shelly Dimmer 1 (BlackMagicProbe)",
"type": "cortex-debug",
"request": "attach",
"servertype": "bmp",
"cwd": "${workspaceRoot}/src",
"executable": "shelly-dimmer-stm32.elf",
"svdFile": "../tools/STM32F031x.svd",
"svdFile": "../scripts/STM32F031x.svd",
"BMPGDBSerialPort": "/dev/ttyS15",
"powerOverBMP": "enable",
},
{
"name": "Shelly Dimmer 2 (BlackMagicProbe)",
"type": "cortex-debug",
"request": "attach",
"servertype": "bmp",
"cwd": "${workspaceRoot}/src",
"executable": "shelly-dimmer-stm32.elf",
"svdFile": "../scripts/STM32F0xx.svd",
"BMPGDBSerialPort": "/dev/ttyS15",
},
]
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"command": "make",
"args": [
"flash",
"BMP_PORT=/dev/ttyS12"
"BMP_PORT=/dev/ttyS15"
],
"options": {
"cwd": "${workspaceFolder}/src"
Expand Down
68 changes: 34 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,40 @@ Here is a guess of the pinout of the *STM32F031K6* chip.

![stm32f031k6](https://user-images.githubusercontent.com/6130792/86444616-494b8080-bd11-11ea-8eeb-c07b69b8af35.PNG)

| Pin | Name | Function | Comment |
| ----- | --------- | ------------------------- | ----------------------------- |
| 1 | VDD | 3V3 | |
| 2 | OCS_IN | NC | |
| 3 | OCS_OUT | NC | |
| 4 | NRST | NRST | |
| 5 | VDDA | 3V3 | |
| 6 | PA0 | CF1 HLW8012 | |
| 7 | PA1 | CF HLW8012 | |
| 8 | PA2 | NC | |
| 9 | PA3 | NC | |
| 10 | PA4 | NC | |
| 11 | PA5 | NC | |
| 12 | PA6 | TEST POINT | Only to test point? |
| 13 | PA7 | TEST POINT | Only to test point? |
| 14 | PB0 | NC | |
| 15 | PB1 | NC | |
| 16 | PB2 | Zero-crossing detection | |
| 17 | VDD | GND | |
| 18 | PA8 | ON MOSFET 1 | OSG65R200J |
| 19 | PA9 | USART_TX | |
| 20 | PA10 | USART_RX | |
| 21 | PA11 | ON MOSFET 2 | OSG65R200J |
| 22 | PA12 | NC | |
| 23 | PA13 | SWDIO | |
| 24 | PA14 | SWCLK | |
| 25 | PA15 | NC | |
| 26 | PB3 | NC | |
| 27 | PB4 | NC | |
| 28 | PB5 | NC | |
| 29 | PB6 | NC | |
| 30 | PB7 | NC | |
| 31 | BOOT0 | BOOT0 | Also connected to S4789BB? |
| 32 | PB8 | SEL HLW8012 | |
| 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
- [HLW8012 Information](https://tinkerman.cat/post/hlw8012-ic-new-sonoff-pow)
Expand Down
Binary file added docs/rm0091-stm32f0x-reference-manual.pdf
Binary file not shown.
Binary file added docs/stm32f031k6.pdf
Binary file not shown.
Binary file added docs/stm32f051k8.pdf
Binary file not shown.
16 changes: 15 additions & 1 deletion scripts/binary-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ int main(int argc, char **argv)
fprintf(stderr, "Cannot open ouput file: %s\n", argv[2]);
return 1;
}

fprintf(fileptr, "/* \n * This file has been generated by the shelly-dimmer-stm32 project.\n");
fprintf(fileptr, " * https://github.com/jamesturton/shelly-dimmer-stm32\n");
fprintf(fileptr, " * Copyright (c) 2020 James Turton.\n *\n");
fprintf(fileptr, " * This program is free software: you can redistribute it and/or modify \n");
fprintf(fileptr, " * it under the terms of the GNU General Public License as published by \n");
fprintf(fileptr, " * the Free Software Foundation, version 3.\n *\n");
fprintf(fileptr, " * This program is distributed in the hope that it will be useful, but \n");
fprintf(fileptr, " * WITHOUT ANY WARRANTY; without even the implied warranty of \n");
fprintf(fileptr, " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \n");
fprintf(fileptr, " * General Public License for more details.\n *\n");
fprintf(fileptr, " * You should have received a copy of the GNU General Public License \n");
fprintf(fileptr, " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\n\n");


fprintf(fileptr, "static const uint8_t SHD_FIRMWARE_MAJOR_VERSION = %d;\n", atoi(argv[3]));
fprintf(fileptr, "static const uint8_t SHD_FIRMWARE_MINOR_VERSION = %d;\n", atoi(argv[4]));
Expand All @@ -67,7 +81,7 @@ int main(int argc, char **argv)
fprintf(fileptr, "0x%.2x, ", buffer[i++]);
fprintf(fileptr, "\n");
}
fprintf(fileptr, "};\n\n");
fprintf(fileptr, "};\n");

return 0;
}
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BINARY = usart

# TODO - you will need to edit these two lines!
DEVICE=stm32f031k6
# DEVICE=stm32f051k8

# You shouldn't have to edit anything below here.
OPENCM3_DIR=../libopencm3
Expand Down
Loading

0 comments on commit 1a0a322

Please sign in to comment.