-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #247 from stuartpittaway/all-in-one
Merge 16S "all-in-one" to master
- Loading branch information
Showing
22 changed files
with
2,464 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# DIYBMS All-in-one 16S monitoring board | ||
|
||
This is the code for the (up to) 16S monitoring board. | ||
|
||
It uses an [STM32F030K6T6](https://www.st.com/en/microcontrollers-microprocessors/stm32f030k6.html) chip, with 32K flash and 4K RAM. | ||
|
||
**WARNING**: This code is considered experimental & prototype, use at your own risk - it may not work as intended or at all. | ||
|
||
## How to compile the code | ||
|
||
### Pre-compiled | ||
The easiest way to use the code is with the pre-compiled version generated by [GITHUB Actions](https://github.com/stuartpittaway/diyBMSv4ESP32/actions). | ||
|
||
For this prototype version, look for successful compiles (green ticks) for the "all-in-one" branch. | ||
|
||
Inside the action, you will see "Artifacts" - download the ZIP files for the pre-compiled version of the code, look inside the ZIP file for a "BIN" folder and the files named "module_fw_V490_10K_genericSTM32F030K6T6.bin" or similar. | ||
|
||
### Manual compile | ||
The code is written in C/C++ and you can use VSCode and Platform.IO to compile to code. | ||
|
||
This can also be used to upload the code into the microcontroller. | ||
|
||
Platform.IO should automatically configure the build environment and compile the code for you. | ||
|
||
Recommend installing GITHUB Desktop for a pain free experience. | ||
|
||
The compiled code will be named "module_fw_V490_10K_genericSTM32F030K6T6.bin" inside the ".pio\build\V490_10K" folder - this uses the 10,000 baud communication speed. A 5,000 baud (5K) version is also available. | ||
|
||
## Programming the STM32 chip | ||
|
||
Interfaces for both serial and ST-LINK are provided. If you don't have an ST-LINK programmer, use the serial method below. | ||
|
||
You will require [STM32 Cube Programmer](https://www.st.com/en/development-tools/stm32cubeprog.html) software. | ||
|
||
|
||
### Serial Programming | ||
|
||
Use an off the shelf [USB Serial adapter](https://amzn.to/44umP3v) (Silicon Labs CP210x or similar). | ||
|
||
1. Disconnect the battery cells completely from the monitor PCB (2 pin and 17 pin terminal blocks on left of board). | ||
2. Remove the "PWR" jump pin (if fitted) | ||
3. Move the jump pin "PRG/RUN" to "PRG" (left 2 pins) | ||
4. Connect the serial adapter to the connector marked "UART PROG". Pins are marked on the silkscreen. | ||
``` | ||
Serial Adapter --> Monitoring PCB | ||
GND --> GND | ||
TX --> RX | ||
RX --> TX | ||
+3.3V --> 3.3V | ||
``` | ||
**Under no circumstances connect a 5V supply. Ensure battery connector is unplugged.** | ||
|
||
5. Using STM Cube Programmer, select "UART" (top right of screen) and click "CONNECT" | ||
6. Using the "Erasing & Programming" option (2nd icon down, on left of screen) | ||
7. Select the firmware file in "file path" | ||
8. Check "Verify programming" and then "Start Programming" | ||
9. Wait for "File Download Complete" message, click OK. | ||
10. Wait for "Download verified successfully" message, click OK. | ||
11. Move "PRG/RUN" jumper to "RUN" | ||
12. Disconnect USB programming cable BEFORE connecting battery connector! | ||
13. Once disconnected, re-connect "PWR" jumper if required. | ||
|
||
|
||
### ST-LINK | ||
|
||
Repeat above, but using ST-LINK connector on the PCB. There is no need to change the "PRG/RUN" jumper setting. | ||
|
||
Observe warnings about disconnecting the battery connector before programming, or connecting to your computer. | ||
|
||
Use the STM32 Cube software to program the firmware using ST-LINK protocol. | ||
|
||
## Error LED flash sequences | ||
|
||
On power up (after successful programming of the STM32 chip with code) the LED may flash a light sequence in the event of an error. | ||
|
||
* 0 = Successful power on | ||
* 1 = Not used | ||
* 2 = MAX14921 thermal shutdown | ||
* 3 = Less than 4 cells detected (check wiring and soldering to MAX chip) | ||
* 4 = MAX14921 VA pin (Analog Supply Voltage) below UV_VAVTH (4.7V) | ||
* 5 = MAX14921 VP is below UV_VPVTH (6V) | ||
* 6 = MAX14921 device reports not ready (after 5 seconds waiting) | ||
* 7 = Unable to communicate with MAX14921 over SPI pins/interface | ||
|
||
Most of these reasons are caused by poor soldering to the MAX14921 chip. Check for solder bridges and loose pins (not soldered). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"build": { | ||
"cpu": "cortex-m0", | ||
"extra_flags": "-DSTM32F030x6", | ||
"f_cpu": "48000000L", | ||
"mcu": "stm32f030k6t6", | ||
"product_line": "STM32F030x6", | ||
"variant": "STM32F0xx/F030K6T" | ||
}, | ||
"debug": { | ||
"jlink_device": "STM32F030K6", | ||
"openocd_target": "stm32f0x", | ||
"svd_path": "STM32F0x0.svd" | ||
}, | ||
"frameworks": [ | ||
"arduino", | ||
"cmsis", | ||
"stm32cube", | ||
"libopencm3" | ||
], | ||
"name": "GENERIC STM32F030K6T6", | ||
"upload": { | ||
"maximum_ram_size": 4096, | ||
"maximum_size": 31744, | ||
"protocol": "stlink", | ||
"protocols": [ | ||
"dfu", | ||
"jlink", | ||
"stlink", | ||
"blackmagic", | ||
"serial" | ||
] | ||
}, | ||
"url": "", | ||
"vendor": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Import("env") | ||
|
||
platform = env.PioPlatform() | ||
|
||
#my_flags = env.ParseFlags(env['BUILD_FLAGS']) | ||
#defines = {k: v for (k, v) in my_flags.get("CPPDEFINES")} | ||
#print(my_flags) | ||
#print(defines.get("DIYBMSMODULEVERSION")) | ||
#print(str(env["BOARD_MCU"]).lower()) | ||
|
||
|
||
if str(env["BOARD_MCU"]).lower()=="stm32f030k6t6": | ||
env.Replace(PROGNAME="module_fw_%s_%s" % (env["PIOENV"],env.get("BOARD"))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" Script for DIYBMS """ | ||
import datetime | ||
import subprocess | ||
import os | ||
from os import path | ||
|
||
Import("env") | ||
|
||
git_sha=None | ||
|
||
AreWeInGitHubAction = True if "GITHUB_SHA" in env else False | ||
|
||
if (AreWeInGitHubAction): | ||
git_sha=env["GITHUB_SHA"] | ||
else: | ||
if (path.exists('..'+os.path.sep+'.git')): | ||
# Get the latest GIT version header/name | ||
try: | ||
git_sha = subprocess.check_output(['git','log','-1','--pretty=format:%H']).decode('utf-8') | ||
except: | ||
# Ignore any error, user may not have GIT installed | ||
git_sha = None | ||
|
||
# print(env.Dump()) | ||
|
||
# These are used by GenerateBinaryFile.py | ||
# If a user doesn't have GIT installed, use fake fffff numbers... | ||
if (git_sha!=None): | ||
env.Append(git_sha=git_sha) | ||
env.Append(git_sha_short=git_sha[32:]) | ||
else: | ||
env.Append(git_sha="ffffffffffffffffffffffffffffffffffffffff") | ||
env.Append(git_sha_short="ffffffff") | ||
|
||
include_dir = os.path.join(env.get('PROJECT_DIR'), 'include') | ||
|
||
if (os.path.exists(include_dir) == False): | ||
raise Exception("Missing include folder") | ||
|
||
|
||
with open(os.path.join(include_dir, 'EmbeddedFiles_Defines.h'), 'w') as f: | ||
f.write("// This is an automatically generated file, any changes will be overwritten on compiliation!\n") | ||
f.write("// DO NOT CHECK THIS INTO SOURCE CONTROL\n") | ||
f.write("\n\n#ifndef EmbeddedFiles_Defines_H\n#define EmbeddedFiles_Defines_H\n\n") | ||
|
||
f.write("static const char GIT_VERSION[] = \"") | ||
if (git_sha!=None): | ||
f.write(git_sha) | ||
else: | ||
f.write("LocalCompile") | ||
f.write("\";\n\n") | ||
|
||
f.write("static const uint16_t GIT_VERSION_B1 = 0x") | ||
if (git_sha!=None): | ||
f.write(git_sha[32:36]) | ||
else: | ||
#Default for local compile | ||
f.write("FFFF") | ||
f.write(";\n\n") | ||
|
||
f.write("static const uint16_t GIT_VERSION_B2 = 0x") | ||
if (git_sha!=None): | ||
f.write(git_sha[36:]) | ||
else: | ||
#Default for local compile | ||
f.write("FFFF") | ||
f.write(";\n\n") | ||
|
||
|
||
f.write("static const char COMPILE_DATE_TIME[] = \"") | ||
f.write(datetime.datetime.utcnow().isoformat()[:-3]+'Z') | ||
f.write("\";\n\n") | ||
|
||
f.write("#endif") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This is an automatically generated file, any changes will be overwritten on compiliation! | ||
// DO NOT CHECK THIS INTO SOURCE CONTROL | ||
|
||
|
||
#ifndef EmbeddedFiles_Defines_H | ||
#define EmbeddedFiles_Defines_H | ||
|
||
static const char GIT_VERSION[] = "a4f3024afd95548a3a8628db190a98564f7cd2d5"; | ||
|
||
static const uint16_t GIT_VERSION_B1 = 0x4f7c; | ||
|
||
static const uint16_t GIT_VERSION_B2 = 0xd2d5; | ||
|
||
static const char COMPILE_DATE_TIME[] = "2023-07-04T15:47:51.443Z"; | ||
|
||
#endif |
Oops, something went wrong.