Skip to content

Flashing

David Pye edited this page Sep 4, 2023 · 23 revisions

Note: Unlocking the SAMD20 microcontroller for flashing involves removing the security protection, which erases the chip. There is (intentionally) no way to back up or restore the previous firmware, so it's a one-way journey!

Identifying and preparing connection

After dismantling the battery, identify the pinheader on the side of the circuit board.

The pins are as shown below: (Check the square pin for orientation)

v10-pinouts-closeup

They are covered in a thin layer of lacquer, which can be removed with a small abrasive fibreglass pencil, or very carefully with some fine wet-and-dry sandpaper or similar. Once this is done, you can connect wires to the pads - I found it easiest and most reliable to solder wires to them.

You may or may not need the 3v3 pin depending on your programmer - if you're using an Atmel-ICE programmer, you will need it for VSense (sense voltage). If you're using a Raspberry Pi, you do not need to connect to it.

Caution: Remember, these pins are 'live' all the time, as are the battery pack terminals - make sure nothing shorts (especially to the 18650 terminals) or you are likely to kill the microcontroller.

Flashing with a Raspberry Pi as the programmer

Updated version of the image (1.0.1 onwards) should now work with all models of Pi, including the Pi 4.

Download the Raspberry Pi Autoflash image from the project's Releases section, unzip it and write it to an SD card (or MicroSD card, depending on what Pi you are using).

Make connections between the pack and the Pi's GPIO pins as follows:

image

Image from IOsoft.blog

NB You should not connect 3.3v, just the four pins above

Insert the SD/MicroSD card into the Pi.

Wake up the battery pack by pushing the little black 'lever' on the top.

Power up the Pi. If you have a monitor connected, it'll make it easier to see what is going on, especially if there is a problem, but it isn't absolutely necessary.

Boot-up and programming takes several minutes - you'll know it's done because the pack will do a light sequence. You can now disconnect the cables and power down the Pi.

Flash with SWD capable programmer

You need a working installation of Microchip Studio - you can obtain it for free from: Microchip Studio- during installation, you need to select support for SAMD20 architecture, but not the others.

The microcontroller is locked, with the security bit set, so the first job is to unlock it (this will erase the existing firmware completely).

Once you have the programmer connected and Microchip studio loaded, wake the pack from sleep by pressing the black trigger-button on the top. Under Tools->Device Programming, select your programmer in the Tool pulldown, Device as ATSAMD20E15, Interface as SWD and click Apply.

image

If you click Read, you'll see a dialog like this:

image

This is because the Security bit is set.

To clear it (which will ERASE the existing firmware), go into the Memories tab, and click the ERASE NOW button:

image

If you see "Erase device OK", this has been successful.

Then, if you click the Read button next to the Device signature bar at the top, you'll see the following specs retrieved from the IC:

image

This means the chip is now unlocked, and ready for reprogramming!

Once this is done, you can compile and upload the firmware. (I will produce tested and 'ready to go' binaries - probably around Aug 23)

For now, you'll have to build the project yourself. Download the source code from the Git repository, and open the Project file using Microchip studio. Under the Debug menu, select Start without debugging (Ctrl+Alt+F5).

This will compile the code, and then upload it to the battery pack. From now, you should be good to go.