# Factory Authentication Recovery This guide addresses factory firmware failures caused by accidentally erasing factory authentication information with `Full chip erase`, `Mass erase`, or an equivalent full-chip erase operation. Custom firmware does not depend on this authentication information and is unaffected. The board contains two STM32F407 MCUs, identified in this guide by the PCB labels `STM32(1)` and `STM32(2)`. A single USB Type-C connection links both MCUs through the onboard USB HUB, so COM port numbers, names, and Device Manager order do not identify the MCU number. This procedure first programs UID Reader only onto the MCU labeled `STM32(1)`. The only MCU returning UID Reader information is therefore `STM32(1)`. UID Reader is then programmed onto `STM32(2)`, and the new UID that differs from the first one identifies `STM32(2)`. These two labeled UIDs must be used throughout recovery and verification. > **Important:** Do not use `Full chip erase`, `Mass erase`, any equivalent full-chip erase operation, or modify Option Bytes at any point in this procedure. ## Downloads | Software or file | Purpose | Download | | --- | --- | --- | | UID Reader V3 HEX | Read the hardware UID and inspect Sector 7 status | [Download sanpo_v4_uid_reader.hex](https://gitcode.com/sanpo/robot/blob/main/products/spine/v4/f407/firmware/recovery/sanpo_v4_uid_reader.hex) | | UID Reader checksums | Verify the UID Reader BIN/HEX files | [Download SHA256SUMS.txt](https://gitcode.com/sanpo/robot/blob/main/products/spine/v4/f407/firmware/recovery/SHA256SUMS.txt) | | UartAssist | Windows serial terminal | [Download UartAssist.zip](https://gitcode.com/sanpo/robot/blob/main/products/spine/v4/f407/tools/UartAssist.zip) | | STM32CubeProgrammer | Program and verify firmware through ST-LINK | [Download STM32CubeProgrammer_win64.zip](https://gitcode.com/sanpo/robot/blob/main/products/spine/v4/f407/tools/STM32CubeProgrammer_win64.zip) | | Spine V4 V47 factory firmware | Program after authentication is restored and verified | [Download spine_v4_v47_release.bin](https://gitcode.com/sanpo/robot/blob/main/products/spine/v4/f407/firmware/spine_v4_v47_release.bin) | The `STM32_1__sector7.hex` and `STM32_2__sector7.hex` files returned by customer service contain device-specific authentication information. They cannot be downloaded from the public repository and must not be replaced with files for another board. ## 1. Prepare the Tools 1. Download and extract `UartAssist.zip`, then run `UartAssist 5.0.2.exe`. Installation is not required. 2. Download, extract, and open STM32CubeProgrammer. 3. Download `sanpo_v4_uid_reader.hex`. 4. Prepare an ST-LINK and a USB data cable, and locate the `STM32(1)` and `STM32(2)` labels on the PCB. 5. Connect ST-LINK only to the MCU currently being operated on. Keep USB Type-C connected. ## 2. Read and Label the Hardware Information of Both MCUs ### 2.1 Read STM32(1) First 1. Following the PCB label, connect ST-LINK to the SWD connector for `STM32(1)` and power the board. 2. In the upper-right corner of STM32CubeProgrammer, select `ST-LINK` and use: - Port: `SWD` - Frequency: keep the default; reduce it if the connection is unstable - Reset mode: start with the default; use `Under Reset` if connection fails 3. Click `Connect` and confirm that the log identifies an STM32F407. 4. Open `Erasing & Programming` and select `sanpo_v4_uid_reader.hex`. The HEX file already contains address `0x08000000`; do not enter an address manually. 5. Select `Verify programming` and click `Start Programming`. After success, click `Disconnect`, then power-cycle or reset the board. 6. Wait for USB HUB enumeration. One COM port may appear, or two may appear if the other MCU's existing firmware still runs. In UartAssist, check every currently available COM port using: - Baud rate: `115200` - Data bits: `8` - Stop bits: `1` - Parity: `None` - Flow control: `None` - Send and receive mode: text/ASCII, not HEX - Line ending: `CRLF` ![UartAssist serial settings](../zh/assist.png) 7. Send `AT+HWINFO` to each port. Do not type the literal characters `\r\n`. At this point, only `STM32(1)`, which is running UID Reader, returns a line in this format: ```text SANPO_V4_HWINFO,V=3,UID=XXXXXXXX-XXXXXXXX-XXXXXXXX,SECUID=FFFFFFFF-FFFFFFFF-FFFFFFFF,DEVID=413,REVID=XXXX,FLASHKB=512,SECTOR7=BLANK ``` 8. Copy the complete line and label it clearly as `STM32(1)`. Do not save or rely on the current COM number, because its number and order may change after reconnecting or resetting the board. If no port returns `SANPO_V4_HWINFO,V=3`, or two different V3 responses appear, stop the procedure. Check the programming target and log, then contact customer service. ### 2.2 Read STM32(2) 1. Move ST-LINK to the SWD connector identified by the `STM32(2)` PCB label. 2. Program and verify `sanpo_v4_uid_reader.hex` in the same way as for STM32(1), then power-cycle or reset the board. 3. Use UartAssist to open every COM port enumerated by the USB HUB and send `AT+HWINFO`. 4. You should now obtain two different `SANPO_V4_HWINFO,V=3` lines: - The line whose `UID` matches the first saved value is `STM32(1)`. - The new `UID`, which differs from the first value, is `STM32(2)`. 5. Copy the complete new line and label it clearly as `STM32(2)`. If you do not obtain two different UIDs, do not guess the relationship between an MCU and a COM port. Recheck the second programming operation and all COM ports. ### 2.3 Send the Information to Customer Service Send both complete original lines and retain the following labels: ```text STM32(1): SANPO_V4_HWINFO,V=3,UID=........-........-........,SECUID=........-........-........,DEVID=413,REVID=....,FLASHKB=512,SECTOR7=.... STM32(2): SANPO_V4_HWINFO,V=3,UID=........-........-........,SECUID=........-........-........,DEVID=413,REVID=....,FLASHKB=512,SECTOR7=.... ``` ## 3. Check the Recovery Package from Customer Service The recovery directory should contain: - `STM32_1__sector7.hex`: only for the MCU identified by the `STM32(1)` PCB label - `STM32_2__sector7.hex`: only for the MCU identified by the `STM32(2)` PCB label - `spine_v4_official.bin` - `manifest.json` - `SHA256SUMS.txt` - Customer recovery instructions Both Sector 7 filenames contain the MCU position label and that MCU's hardware UID. Before programming, confirm that the UID in each filename exactly matches the corresponding UID saved in Section 2. Never exchange the two files. UID Reader status fields mean: - `UID`: the current MCU's actual hardware UID. - `SECUID`: the UID stored in Sector 7; an empty area normally contains all `F` characters. - `BLANK`: the Sector 7 authentication block is empty. - `INVALID`: the Sector 7 format, length, end marker, or CRC is invalid. - `UID_MISMATCH`: `SECUID` differs from the current MCU's actual `UID`, which means the device-specific HEX file was programmed onto the wrong MCU. - `UID_MATCH`: `SECUID` matches the actual `UID`, and the format and CRC are valid. ## 4. Restore and Verify STM32(1) 1. Following the PCB label, connect ST-LINK to the SWD connector for `STM32(1)`. 2. Connect in STM32CubeProgrammer, open `Erasing & Programming`, and select `STM32_1__sector7.hex`. The HEX file already contains address `0x08070000`; do not change the address. 3. Select `Verify programming` and click `Start Programming`. After success, disconnect and power-cycle or reset the board. UID Reader is still running at this point. 4. Use UartAssist to query every currently enumerated COM port. Identify the `STM32(1)` response by the hardware UID saved in Section 2, not by the COM number. 5. All three conditions must be met: - `UID` exactly matches the previously labeled `STM32(1)` UID. - `SECUID` exactly matches `UID`. - `SECTOR7=UID_MATCH`. 6. Only after verification, reconnect STM32CubeProgrammer, select `spine_v4_official.bin` from the recovery package, manually enter download address `0x08000000`, keep `Verify programming` selected, and start programming. If `UID_MISMATCH`, `INVALID`, or an incorrect UID appears, do not continue with factory firmware. Save the UID Reader response and STM32CubeProgrammer log and contact customer service. Do not perform a full-chip erase. ## 5. Restore and Verify STM32(2) 1. Following the PCB label, move ST-LINK to the SWD connector for `STM32(2)`. 2. Select `STM32_2__sector7.hex`, then program and verify it in the same way as for STM32(1). 3. Before factory firmware overwrites UID Reader, query every currently enumerated COM port again. Identify the `STM32(2)` response by the saved hardware UID and confirm `UID=SECUID` and `SECTOR7=UID_MATCH`. 4. Only after confirmation, program `spine_v4_official.bin` from the recovery package at `0x08000000`. ## 6. Final Verification 1. After both MCUs are complete, disconnect board power for 10 seconds and then power it again. 2. In UartAssist, open both COM ports enumerated by the USB HUB and send `AT+VER` in text mode with a `CRLF` line ending. Confirm that both ports return the factory firmware version. 3. Test CAN, RS485, SPI, and motor communication as required by the application. `AT+VER` only confirms that the factory firmware is running. By itself, it does not prove that a Sector 7 file was programmed onto the correct MCU. Before programming the factory firmware, the UID Reader response must confirm `UID=SECUID` and `SECTOR7=UID_MATCH`. If programming fails, a status is abnormal, or the factory firmware does not respond, stop the procedure. Save both labeled, complete `SANPO_V4_HWINFO` lines and the STM32CubeProgrammer log, then contact customer service.