> For the complete documentation index, see [llms.txt](https://docs.cubepilot.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cubepilot.org/here-4/recovering-the-firmware.md).

# Recovering the Firmware

This section explains how to resolve firmware-related issues.

Recovering the firmware may be necessary if a firmware update fails or incompatible firmware is loaded. Attempt flashing the bootloader via the SWD port if the Here4 LEDs are solid white.

## Prerequisites

The following information is for J-Link devices, but it can also be applied to similar devices when using an ST-Link.<br>

* J-Link device:
  * [EDU Mini](https://www.segger.com/products/debug-probes/j-link/models/j-link-edu-mini/) V2, for personal/educational use (and an adapter board)
  * [BASE Compact](https://shop.segger.com/debug-trace-probes/debug-probes/j-link/j-link-base-compact), for commercial use
    * Pinout: <https://www.segger.com/products/debug-probes/j-link/technology/interface-description/>&#x20;
* **6-pin JST SUR** plug for SWD port
  * Refer here for SWD port pinout: [FMU Debug pinout](https://docs.cubepilot.org/user-guides/autopilot/the-cube/introduction/interface-specifications#fmu-debug)
* Download and install “J-Link Software and Documentation Pack” from [segger.com/downloads/jlink/](https://www.segger.com/downloads/jlink/)&#x20;
* Download the bootloader file for your flashing tool:
  * JLink: [Here4\_bl.hex](https://github.com/CubePilot/GNSSPeriph-release/raw/refs/heads/release/bootloaders/Here4_bl.hex)
  * STLink: [Here4\_bl.bin](https://github.com/CubePilot/GNSSPeriph-release/raw/refs/heads/release/bootloaders/Here4_bl.bin)
* De-cased Here4
  * Remove M3 bolt (2 mm hex head)
  * Gently separate the two housing parts, using a plastic tool to pry the clips apart
  * Images for reference:

{% columns %}
{% column %}

<figure><img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2FWycg3QREDqPk9PJwcY8T%2Funknown.jpeg?alt=media&amp;token=6db72fb9-dcd1-4eb5-8ab3-692cb1d8b071" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2F9iVALRZC6HZM9rNArhyT%2Funknown.jpeg?alt=media&amp;token=3eb70bd4-50a2-4ee1-8b13-d72194d2143d" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column valign="bottom" %}

<figure><img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2Fkcd2R3T5gMYmA3Es357k%2Funknown.jpeg?alt=media&amp;token=2fd17a1a-d51d-4ee1-95a7-7005ef989dc8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2FF3W2dBciL5oPFJhkHp9q%2Funknown.jpeg?alt=media&amp;token=3b3451d9-918b-4b39-96e0-637803d6323b" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

## Procedures

### J-Link with J-Flash Lite

1. Plug Here4 into CAN port of a Cube (for power).
2. Plug J-Link into the SWD port on the Here4.

<img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2Fkj8uUfOhNMKfYm8bm9CO%2Funknown.png?alt=media&amp;token=ab228d71-76dc-469c-a341-d5693cdaeb2b" alt="" height="279" width="279">

3. Connect J-Link to PC over USB.
4. Open **J-Flash Lite** (JFlashLite.exe).
5. Use the following parameters:

<img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2FDG3KNrQnNeQgDudAuFrZ%2Funknown.png?alt=media&amp;token=3085588f-04ec-4fb2-9b5c-156962ff026e" alt="" height="252" width="292">

6. Click **OK**.
7. Plug the Cube into power, power up the Here4, and click **Erase Chip**.

<img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2FhFhRnZgV0J7dS31h1gXF%2Funknown.png?alt=media&amp;token=ff0b956a-794d-44c3-aa8a-8b1a22b4f594" alt="" height="275" width="356">

8. Click the button under Data File and open the **Here4\_bl.hex** file.
9. Click **Program Device**.
10. Check the log for the following output:

<img src="https://3175993181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LUhw7cdLeWVORgnTA3i%2Fuploads%2FxVdhyEWhnbrpT7k6DBov%2Funknown.png?alt=media&amp;token=b336eb2b-00ce-4c76-8d0e-34b4634dae51" alt="" height="134" width="354">

11. Unplug the power and SWD connections.
12. Plug in Cube, connect to Mission Planner and verify Here4 shows up in DroneCAN (in **MAINTENANCE** mode).
13. Update the Here4 (**Menu** -> **Update** -> **Yes, search the internet for updates**).
14. Verify Here4 shows up in **OPERATIONAL** mode.

## Connect Programming Devices

This section contains the pinout on either side to assist in connecting the J-Link or ST-Link device to the SWD port. The **same pinout is used for J-Link and ST-Link devices** with 20-pin connectors.

Solder or crimp the 6-pin JST SUR wires onto 2.54 mm female header plugs (if using programming devices with header pins).

<table><thead><tr><th width="154.2000732421875">Pin Number
(SWD port)</th><th width="210.4000244140625">Name
(SWD port)</th><th width="153.7999267578125">Pin Number
(JTAG Interface)</th><th width="210.39990234375">Name
(JTAG Interface)</th></tr></thead><tbody><tr><td><strong>1</strong></td><td>VDD 5V PEIPH</td><td><strong>1</strong></td><td>VTref</td></tr><tr><td><strong>2</strong></td><td>FMU_TX (SERIAL 5)</td><td>Not Connected</td><td>Not Connected</td></tr><tr><td><strong>3</strong></td><td>FMU_RX (SERIAL 5)</td><td>Not Connected</td><td>Not Connected</td></tr><tr><td><strong>4</strong></td><td>FMU-SWDIO</td><td><strong>7</strong></td><td>SWDIO</td></tr><tr><td><strong>5</strong></td><td>FMU-SWCLK</td><td><strong>9</strong></td><td>SWCLK</td></tr><tr><td><strong>6</strong></td><td>GND</td><td><strong>4</strong></td><td>GND</td></tr></tbody></table>

* [SWD port pinout](https://docs.cubepilot.org/autopilot/the-cube/introduction/interface-specifications#fmu-debug)
* [J-Link pinout](https://www.segger.com/products/debug-probes/j-link/technology/interface-description/) ('SWD Connector Pinout' section)
* [ST-Link pinout](https://www.utmel.com/components/stlinkv2-in-circuit-debugger-pinout-datasheet-and-programming?id=237#cat2)
