BotoX/xiaomi-m365-compatible-bms

Firmware upload

kalski44 opened this issue · 3 comments

Right now I'm just checking this great project, but one point, which is probably obvious for most of you, is not clear for me.

Do I have to use ISP programmer only to program bootloader by "AVRDUDE", and To upload firmware I should use dedicated PC interface which is delivered with BMS. Am I right?

So I should buy BMS + PC interface (there is also option, only with bluetooth interface).

BotoX commented

You can program both with ISP and avrdude.
But a serial UART converter is useful for debugging and updating the firmware (not only for this device but lots of others like your internet router when flashing alternative firmware, etc.)
So I prefer to teach people how to use both.
With platformio it's just one click of a button to upload the firmware to a chip with a bootloader (okay you probably have to reset the chip/power first and then press the button with 2 seconds)
If you have any problems with the BMS you need to have a UART adapter to read out the error code etc.

Thank you for the answer. To conclude, I dont need "PC comunication module" sold with SP15SV0001-LLT.
Folowing this, I have tried to upload firmware by Serial UART adapter. Unfortunately I have some issue and I'm not sure how to solve it. Until now I made inly simple arduino projects using Arduino IDE, as a hobby.

Below step by step my actions, and results:

1. I programmed bootloader using AVERDUE:

C:\Users\laptop\Documents\PlatformIO\Projects\xiaomi-m365-compatible-bms-master>avrdude -patmega328p -cusbasp -P/dev/ttyUSB3 -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0xFD:m -U lock:w:0x3F:m -U flash:w:optiboot_atmega328_8mhz_57600bps.hex

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xDE"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDE:
avrdude: load data hfuse data from input file 0xDE:
avrdude: input file 0xDE contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFD"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFD:
avrdude: load data efuse data from input file 0xFD:
avrdude: input file 0xFD contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3F:
avrdude: load data lock data from input file 0x3F:
avrdude: input file 0x3F contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "optiboot_atmega328_8mhz_57600bps.hex"
avrdude: input file optiboot_atmega328_8mhz_57600bps.hex auto detected as Intel Hex
avrdude: writing flash (32768 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against optiboot_atmega328_8mhz_57600bps.hex:
avrdude: load data flash data from input file optiboot_atmega328_8mhz_57600bps.hex:
avrdude: input file optiboot_atmega328_8mhz_57600bps.hex auto detected as Intel Hex
avrdude: input file optiboot_atmega328_8mhz_57600bps.hex contains 32768 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...
avrdude: 32768 bytes of flash verified

avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)

avrdude done.  Thank you.

2. I build project in PlatformIO: no errors

3. I shorted RESET and GROUND on connected BMS

4. I tried to upload firmware to BMS, but this failed and I see logs, but I don'd understand:

> Executing task: platformio.exe run --target upload <

Warning! `env_default` configuration option in section [platformio] is deprecated and will be removed in the next release! Please use `default_envs
` instead
Processing sp15s001 (platform: atmelavr; board: pro8MHzatmega328; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/pro8MHzatmega328.html
PLATFORM: Atmel AVR 2.0.0 > Arduino Pro or Pro Mini ATmega328 (3.3V, 8 MHz)
HARDWARE: ATMEGA328P 8MHz, 2KB RAM, 30KB Flash
PACKAGES:
 - framework-arduino-avr 5.0.0
 - tool-avrdude 1.60300.190424 (6.3.0)
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 7 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <PinChangeInterrupt> 1.2.6
|-- <SoftI2CMaster> 1.0.0 #a60c4da
|-- <EEPROM> 2.0
Building in release mode
Checking size .pio\build\sp15s001\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=====     ]  54.2% (used 1111 bytes from 2048 bytes)
Flash: [======    ]  62.9% (used 19330 bytes from 30720 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Use manually specified: /dev/ttyUSB3
Uploading .pio\build\sp15s001\firmware.hex
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Users\laptop\.platformio\python37\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\laptop\.platformio\python37\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\laptop\.platformio\penv\lib\site-packages\platformio\proc.py", line 50, in run
    self.do_reading()
  File "c:\users\laptop\.platformio\penv\lib\site-packages\platformio\proc.py", line 73, in do_reading
    for byte in iter(lambda: self._pipe_reader.read(1), ""):
  File "c:\users\laptop\.platformio\penv\lib\site-packages\platformio\proc.py", line 73, in <lambda>
    for byte in iter(lambda: self._pipe_reader.read(1), ""):
  File "C:\Users\laptop\.platformio\python37\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 32: invalid start byte

=========================================================== [FAILED] Took 2.26 seconds ===========================================================

Do you have some idea what can I do wrong?

It was my fault. I made the same mistake as is already solved in issue #25