# Update or Re-Flash via ST-Link

pdating via the ST-Link provides a reliable and easy way to flash any STM based MCU's especially if you have issues entering DFU mode, the only time where it becomes problematic is when older/fake ST-Links are used, please see the notes and ways of identifying below.&#x20;

### Requirements&#x20;

* ST-Link v2 (Below is a table of the most common ST-Link v2s. There are obviously more available on the market.&#x20;

| STLink                 | ST-Link V2 Mini (Fake MCU)                                                                                                                                                                                                                                 | ST-Link V2 Mini                                                                                                                                                                                                                                            | ST-Link V2                                                                                                                                                                                                                                                 |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Image                  | <img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FqkWBqc87WJnauwePVekP%2Fimage.png?alt=media&#x26;token=48f90021-8d05-45d6-8865-38439e7f0220" alt="" data-size="original"> | <img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FACaOV8SHXviIOxwfoadb%2Fimage.png?alt=media&#x26;token=96748e80-55e5-4b7c-81ff-36b65de3a4e9" alt="" data-size="original"> | <img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FqnYCPHSwms3f3quXDv8K%2Fimage.png?alt=media&#x26;token=8081da59-f2a8-49bf-8564-f36d6cbdd1d6" alt="" data-size="original"> |
| Note                   | Uses fake STM Chip, Pin order is different and isnt always recognised via STM Cube Programmer.                                                                                                                                                             | Occasional Issues, depending on age / firmware.                                                                                                                                                                                                            | Most Reliable                                                                                                                                                                                                                                              |
| STMCubeProg Compatible | <p>❌ </p><p>May not work</p>                                                                                                                                                                                                                               | ✅                                                                                                                                                                                                                                                          | ✅[^1]                                                                                                                                                                                                                                                      |

* STM Cube Programmer - (recommended version v2.15.0) **- if using Windows or MacOS**
* 4x DuPont M-M or M-F Cables
* Cartographer V3 Probe

{% embed url="<https://www.st.com/en/development-tools/stm32cubeprog.html#st-get-software>" %}

### Step 1 - Wire up your probe

Connect the following pins based upon the different ST-Links.&#x20;

| Hardware                        | Pinout                                                                                                                                                                                                                                                     | Connections (STLink - Probe)                                                                                                                 |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **ST-Link V2**                  | <img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FpaoPni3DdQljgLJ3QQfd%2Fimage.png?alt=media&#x26;token=afdbd640-e20c-4ad7-8fbd-f4ec858fc752" alt="" data-size="original"> | <p>SWDIO - SWD<br>SWCLK - SCL<br>GND - GND<br>VCC - 5V</p>                                                                                   |
| **ST-Link V2 Mini (Fake Chip)** | <img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FHy8jfXAA7hltclxN9Frr%2Fimage.png?alt=media&#x26;token=a1093c58-7d0d-485f-a3f7-56efb4808152" alt="" data-size="original"> | <p>SWDIO - SWD<br>SWCLK - SCL<br>GND - GND<br>3.3V\*- 5V<br><br>\* 5v may also work , but on some mini's it can cause stability issues. </p> |
| **ST-Link V2 Mini**             | <img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FChRywnnbryENLt7KvQtf%2Fimage.png?alt=media&#x26;token=c4d5e975-485e-4e6e-a83f-4b0370cac4b5" alt="" data-size="original"> | <p>SWDIO - SWD<br>SWCLK - SCL<br>GND - GND<br>3.3V\*- 5V<br><br>\* 5v may also work , but on some mini's it can cause stability issues. </p> |

Connect your probe to the STLink connectors to the left and the right of the JST connector.&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FviqBMj8ib03i78c4zotU%2Fimage.png?alt=media&#x26;token=3657f26d-7a83-4c5f-9907-243cd0f793e1" alt=""><figcaption><p>Pinout on Cartgorapher V2 and V3</p></figcaption></figure>

{% hint style="warning" %}
You do NOT need to solder in the connector, pressure fit is fine.&#x20;
{% endhint %}

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2Ffyx29lTNgVBgBm9YdXl8%2Fimage.png?alt=media&#x26;token=a131b47c-7eb5-441f-a797-8b34c89ae6a6" alt=""><figcaption><p>Connected on ST-Link V2</p></figcaption></figure>

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FhcRHfJ9eRre0H34aijw3%2Fimage.png?alt=media&#x26;token=b473435e-bace-40c2-a1ae-4c3bce81c44f" alt=""><figcaption><p>Connected to a ST-Link v2 Mini (with a Genuine STM Chip)</p></figcaption></figure>

### If using Windows follow the next steps, if you are using Linux (Pi) [click here](#flashing-via-linux-pi)

Open STM32CubeProg

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FUtSDt0pw83MvopGd906i%2Fimage.png?alt=media&#x26;token=4f645b2a-612e-49b4-883b-fcbf098b8104" alt=""><figcaption></figcaption></figure>

Select **Open File** and select the file you want to open. For this, I recommend flashing the FULL complete firmware files, which include both **bootloader** and **Cartographer firmware.**&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2F5S5sAOr7akF7esXBOEll%2Fimage.png?alt=media&#x26;token=65266304-cee4-4e20-a7c3-dbe9c54efdf6" alt=""><figcaption><p>Select the file you need</p></figcaption></figure>

### Step 3 - Check the Settings

Ensure that you are writing to the correct memory location&#x20;

If your firmware is from the **`combined-firmware`** folder or starts with the words `Katapult`**,**  ensure that the address is set to `0x08000000`

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FS2QaoePeLZPIvUSFWBia%2Fimage.png?alt=media&#x26;token=6c9f9d7c-0eae-4e1f-8992-346a948b38b4" alt=""><figcaption></figcaption></figure>

Ensure that you have ST-LINK slelected on the right (this can default to DFU mode if you havnt used this before)&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2Fn90zsZGcJOnzlgvLzUSK%2Fimage.png?alt=media&#x26;token=c12240ae-5742-4ec1-97ed-1460b1dafa95" alt=""><figcaption></figcaption></figure>

Now press Connect and the screen should indicate that the probe is Connected&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FHuspqEghB7l97Gscd5Zm%2Fimage.png?alt=media&#x26;token=2311a6b8-a5cf-4986-9896-d32ff1334ab9" alt=""><figcaption></figcaption></figure>

### Flash and Confirm Firmware&#x20;

Press download to Download the firmware to your Cartographer&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2F3EZa9L4sZKDXlwEV5Lje%2Fimage.png?alt=media&#x26;token=5181d9fc-e98f-4584-b989-95f7476ddb9c" alt=""><figcaption></figcaption></figure>

The output should look something like this&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FmRqzgwrbnT827q2h2kd2%2Fimage.png?alt=media&#x26;token=07d6329a-8bbb-41f4-8f67-95fa6757eedd" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FYiUlVaYmZpcdZLUPpvrR%2Fimage.png?alt=media&#x26;token=7efe982b-30b2-4a1e-bdd8-3e597fed18f2" alt=""><figcaption></figcaption></figure>

Press Disconnect and unplug the probe.&#x20;

### Flashing via Linux (Pi)

1. SSH into your 3D Printer using your client of choice&#x20;
2. Run the following command (this may take a little while)

```bash
sudo apt-get update
sudo apt-get upgrade
sudo apt-get -y install stlink-tools
```

3. Navigate to the folder where your firmware is stored, usually&#x20;

```bash
cd ~/cartographer-klipper/firmware/v2-v3/combined-firmware
```

4. Check if the ST-Link has been detected using `lsusb` if it is not visable, unplug and re-plug it back in.&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FB1ESLzPXm0oCLvBZxaLi%2Fimage.png?alt=media&#x26;token=5bf65399-9f28-4cb7-8427-ba57fc29955f" alt=""><figcaption><p>Original lsusb not being able to see the ST-Link, second one able to see it. </p></figcaption></figure>

4. run the following command replacing firmware.bin and the memory address with the correct address for the firmware that you are using.&#x20;

```
st-flash write firmware.bin 0x08000000
```

For example to flash the Survey CAN firmware&#x20;

```
st-flash write Full_Survey_Cartographer_CAN_1M_5_0_0.bin 0x08000000
```

Upon completion, you should see something like this&#x20;

<figure><img src="https://3044346320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpCp1KnR8izt0cnWQfZF%2Fuploads%2FhDPgdhj5u3Hq7DHlDM6P%2Fimage.png?alt=media&#x26;token=4f5c729a-8c18-4c9d-b4e0-d32633303239" alt=""><figcaption><p>Successful Flash</p></figcaption></figure>

### Reconnect your probe to your printer

Reconnect your probe to your 3D Printer, and it should work perfectly :)

[^1]:
