Skip to content

Commit

Permalink
Merge pull request #247 from stuartpittaway/all-in-one
Browse files Browse the repository at this point in the history
Merge 16S "all-in-one" to master
  • Loading branch information
stuartpittaway authored Oct 14, 2023
2 parents 169a4ea + 391a195 commit f84cc2a
Show file tree
Hide file tree
Showing 22 changed files with 2,464 additions and 5 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ jobs:
pwd
ls
- name: Build code for modules
- name: Build code for ATTINY modules
run: pio run --project-dir=/home/runner/work/diyBMSv4ESP32/diyBMSv4ESP32/ATTINYCellModule --project-conf=/home/runner/work/diyBMSv4ESP32/diyBMSv4ESP32/ATTINYCellModule/platformio.ini

- name: Copy output
run: |
cp ./ATTINYCellModule/.pio/build/V*/*.hex ~/OUTPUT/Modules/HEX/
cp ./ATTINYCellModule/.pio/build/V*/*.bin ~/OUTPUT/Modules/BIN/
- name: Build code for STM32 modules
run: pio run --project-dir=/home/runner/work/diyBMSv4ESP32/diyBMSv4ESP32/STM32All-In-One --project-conf=/home/runner/work/diyBMSv4ESP32/diyBMSv4ESP32/STM32All-In-One/platformio.ini

- name: Copy STM32 binary firmware output files
run: |
cp ./STM32All-In-One/.pio/build/V*/*.bin ~/OUTPUT/Modules/BIN/
- name: Get latest esptool
run: |
git clone https://github.com/espressif/esptool.git
Expand Down Expand Up @@ -109,11 +115,11 @@ jobs:
needs: [job_build_modulecode]
steps:
- name: Download artifact DIYBMS-Compiled
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: DIYBMS-Compiled

- name: Display structure of downloaded files
- name: Rename over-the-air firmware
run: mv ./Controller/diybms_controller_firmware_espressif32_esp32-devkitc.bin ./Controller/esp32-controller-firmware-over-the-air.bin

- name: Display structure of downloaded files
Expand All @@ -126,12 +132,13 @@ jobs:
zip release.zip ./ControllerBoardTest/diybms_boardtest_espressif32_esp32-devkitc.bin
zip release.zip ./Modules/manifest.json
zip release.zip ./Modules/HEX/*.*
zip release.zip ./Modules/BIN/module_fw_V490*.*
- name: Get current date
id: date
run: echo "dt=$(date +'%Y-%m-%d-%H-%M')" >> $GITHUB_ENV

- name: Display structure of downloaded files
- name: Rename ZIP
run: mv release.zip release_${{ env.dt }}.zip

- name: Publish Artifact
Expand All @@ -142,6 +149,7 @@ jobs:
./Controller/*.*
./Modules/manifest.json
./Modules/HEX/*.*
./Modules/BIN/module_fw_V490*.bin
if-no-files-found: error

- name: Create Release Files on MASTER branch only
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ dkms.conf
*.log
ESPController/compile_commands.json
ATTINYCellModule/compile_commands.json
STM32All-In-One/compile_commands.json
5 changes: 5 additions & 0 deletions STM32All-In-One/.gitignore
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
86 changes: 86 additions & 0 deletions STM32All-In-One/README.md
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).

36 changes: 36 additions & 0 deletions STM32All-In-One/boards/genericSTM32F030K6T6.json
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": ""
}
15 changes: 15 additions & 0 deletions STM32All-In-One/buildscript.py
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")))


74 changes: 74 additions & 0 deletions STM32All-In-One/buildscript_versioning.py
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")
16 changes: 16 additions & 0 deletions STM32All-In-One/include/EmbeddedFiles_Defines.h
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
Loading

0 comments on commit f84cc2a

Please sign in to comment.