Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch571 flash issue ( (BTVER(bootloader ver): 02.90 ) #70

Open
nikitos1550 opened this issue Nov 2, 2024 · 3 comments
Open

ch571 flash issue ( (BTVER(bootloader ver): 02.90 ) #70

nikitos1550 opened this issue Nov 2, 2024 · 3 comments

Comments

@nikitos1550
Copy link

Hello I am trying flash ch571f, but no success.

Seems there is some issue resetting config: first byte is a5 and durint config reset cannot be changed to ff

MYSERIAL:~# test-wch.sh ; sleep 1; wchisp --serial -p /dev/ttyS1 info
00:00:26 [INFO] Opening serial port: "/dev/ttyS1" @ 115200 baud
00:00:26 [INFO] Chip: CH571[0x7113] (Code Flash: 192KiB, Data EEPROM: 32KiB)
00:00:26 [INFO] Chip UID: 4B-A6-36-10-53-5C-D4-12
00:00:26 [INFO] BTVER(bootloader ver): 02.90
00:00:26 [INFO] Current config registers: a5ffffffffffffff550fff4f000209004ba63610535cd412
RESERVED: 0xFFFFFFA5
WPROTECT: 0xFFFFFFFF
  [0:0]   NO_KEY_SERIAL_DOWNLOAD 0x1 (0b1)
    `- Enable
  [1:1]   DOWNLOAD_CFG 0x1 (0b1)
    `- PB22(Default set)
USER_CFG: 0x4FFF0F55
  [2:0]   RESERVED 0x5 (0b101)
    `- Default
  [3:3]   CFG_RESET_EN 0x0 (0b0)
    `- Disable
  [4:4]   CFG_DEBUG_EN 0x1 (0b1)
    `- Enable
  [5:5]   RESERVED 0x0 (0b0)
    `- Default
  [6:6]   CFG_BOOT_EN 0x1 (0b1)
    `- Enable
  [7:7]   CFG_ROM_READ 0x0 (0b0)
    `- Disable the programmer to read out, and keep the program secret
  [27:8]  RESERVED 0xFFF0F (0b11111111111100001111)
    `- Default
  [31:28] VALID_SIG 0x4 (0b100)
    `- Valid
MYSERIAL:~# test-wch.sh ; sleep 1; wchisp --serial -p /dev/ttyS1 config reset
00:00:45 [INFO] Opening serial port: "/dev/ttyS1" @ 115200 baud
00:00:45 [INFO] Current config registers: a5ffffffffffffff550fff4f
00:00:45 [INFO] Reset config registers:   ffffffffffffffffd50fff4f
00:00:45 [INFO] Config register restored to default value(non-protected, debug-enabled)
MYSERIAL:~# test-wch.sh ; sleep 1; wchisp --serial -p /dev/ttyS1 info
00:00:50 [INFO] Opening serial port: "/dev/ttyS1" @ 115200 baud
00:00:50 [INFO] Chip: CH571[0x7113] (Code Flash: 192KiB, Data EEPROM: 32KiB)
00:00:50 [INFO] Chip UID: 4B-A6-36-10-53-5C-D4-12
00:00:50 [INFO] BTVER(bootloader ver): 02.90
00:00:50 [INFO] Current config registers: a5ffffffffffffff550fff4f000209004ba63610535cd412
RESERVED: 0xFFFFFFA5
WPROTECT: 0xFFFFFFFF
  [0:0]   NO_KEY_SERIAL_DOWNLOAD 0x1 (0b1)
    `- Enable
  [1:1]   DOWNLOAD_CFG 0x1 (0b1)
    `- PB22(Default set)
USER_CFG: 0x4FFF0F55
  [2:0]   RESERVED 0x5 (0b101)
    `- Default
  [3:3]   CFG_RESET_EN 0x0 (0b0)
    `- Disable
  [4:4]   CFG_DEBUG_EN 0x1 (0b1)
    `- Enable
  [5:5]   RESERVED 0x0 (0b0)
    `- Default
  [6:6]   CFG_BOOT_EN 0x1 (0b1)
    `- Enable
  [7:7]   CFG_ROM_READ 0x0 (0b0)
    `- Disable the programmer to read out, and keep the program secret
  [27:8]  RESERVED 0xFFF0F (0b11111111111100001111)
    `- Default
  [31:28] VALID_SIG 0x4 (0b100)
    `- Valid
MYSERIAL:~# test-wch.sh ; sleep 1; wchisp --serial -p /dev/ttyS1 -b Baud115200 flash /lib/firmware/tests-ch57xf-led.bin 
00:01:15 [INFO] Opening serial port: "/dev/ttyS1" @ 115200 baud
00:01:16 [INFO] Chip: CH571[0x7113] (Code Flash: 192KiB, Data EEPROM: 32KiB)
00:01:16 [INFO] Chip UID: 4B-A6-36-10-53-5C-D4-12
00:01:16 [INFO] BTVER(bootloader ver): 02.90
00:01:16 [INFO] Current config registers: a5ffffffffffffff550fff4f000209004ba63610535cd412
RESERVED: 0xFFFFFFA5
WPROTECT: 0xFFFFFFFF
  [0:0]   NO_KEY_SERIAL_DOWNLOAD 0x1 (0b1)
    `- Enable
  [1:1]   DOWNLOAD_CFG 0x1 (0b1)
    `- PB22(Default set)
USER_CFG: 0x4FFF0F55
  [2:0]   RESERVED 0x5 (0b101)
    `- Default
  [3:3]   CFG_RESET_EN 0x0 (0b0)
    `- Disable
  [4:4]   CFG_DEBUG_EN 0x1 (0b1)
    `- Enable
  [5:5]   RESERVED 0x0 (0b0)
    `- Default
  [6:6]   CFG_BOOT_EN 0x1 (0b1)
    `- Enable
  [7:7]   CFG_ROM_READ 0x0 (0b0)
    `- Disable the programmer to read out, and keep the program secret
  [27:8]  RESERVED 0xFFF0F (0b11111111111100001111)
    `- Default
  [31:28] VALID_SIG 0x4 (0b100)
    `- Valid
00:01:16 [INFO] Read /lib/firmware/tests-ch57xf-led.bin as Binary format
00:01:16 [INFO] Firmware size: 3072
00:01:16 [INFO] Erasing...
00:01:16 [WARN] erase_code: set min number of erased sectors to 8
00:01:16 [INFO] Erased 8 code flash sectors
00:01:17 [INFO] Erase done
00:01:17 [INFO] Writing to code flash...
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 3072/307200:01:23 [INFO] Code flash 3072 bytes written
00:01:23 [INFO] Verifying...
Error: Verify failed, mismatch

I also try config unprotect

MYSERIAL:~# test-wch.sh ; sleep 1; wchisp --serial -p /dev/ttyS1 info
00:04:12 [INFO] Opening serial port: "/dev/ttyS1" @ 115200 baud
00:04:12 [INFO] Chip: CH571[0x7113] (Code Flash: 192KiB, Data EEPROM: 32KiB)
00:04:12 [INFO] Chip UID: 4B-A6-36-10-53-5C-D4-12
00:04:12 [INFO] BTVER(bootloader ver): 02.90
00:04:12 [INFO] Current config registers: a5ffffffffffffff550fff4f000209004ba63610535cd412
RESERVED: 0xFFFFFFA5
WPROTECT: 0xFFFFFFFF
  [0:0]   NO_KEY_SERIAL_DOWNLOAD 0x1 (0b1)
    `- Enable
  [1:1]   DOWNLOAD_CFG 0x1 (0b1)
    `- PB22(Default set)
USER_CFG: 0x4FFF0F55
  [2:0]   RESERVED 0x5 (0b101)
    `- Default
  [3:3]   CFG_RESET_EN 0x0 (0b0)
    `- Disable
  [4:4]   CFG_DEBUG_EN 0x1 (0b1)
    `- Enable
  [5:5]   RESERVED 0x0 (0b0)
    `- Default
  [6:6]   CFG_BOOT_EN 0x1 (0b1)
    `- Enable
  [7:7]   CFG_ROM_READ 0x0 (0b0)
    `- Disable the programmer to read out, and keep the program secret
  [27:8]  RESERVED 0xFFF0F (0b11111111111100001111)
    `- Default
  [31:28] VALID_SIG 0x4 (0b100)
    `- Valid
MYSERIAL:~# test-wch.sh ; sleep 1; wchisp --serial -p /dev/ttyS1 config unprotect
00:04:17 [INFO] Opening serial port: "/dev/ttyS1" @ 115200 baud
00:04:17 [INFO] Code Flash unprotected
00:04:17 [INFO] Device reset
MYSERIAL:~# test-wch.sh ; sleep 1; wchisp --serial -p /dev/ttyS1 flash /lib/firmware/tests-ch57xf-led.bin
00:04:25 [INFO] Opening serial port: "/dev/ttyS1" @ 115200 baud
00:04:25 [INFO] Chip: CH571[0x7113] (Code Flash: 192KiB, Data EEPROM: 32KiB)
00:04:25 [INFO] Chip UID: 4B-A6-36-10-53-5C-D4-12
00:04:25 [INFO] BTVER(bootloader ver): 02.90
00:04:25 [INFO] Current config registers: a5ffffffffffffff550fff4f000209004ba63610535cd412
RESERVED: 0xFFFFFFA5
WPROTECT: 0xFFFFFFFF
  [0:0]   NO_KEY_SERIAL_DOWNLOAD 0x1 (0b1)
    `- Enable
  [1:1]   DOWNLOAD_CFG 0x1 (0b1)
    `- PB22(Default set)
USER_CFG: 0x4FFF0F55
  [2:0]   RESERVED 0x5 (0b101)
    `- Default
  [3:3]   CFG_RESET_EN 0x0 (0b0)
    `- Disable
  [4:4]   CFG_DEBUG_EN 0x1 (0b1)
    `- Enable
  [5:5]   RESERVED 0x0 (0b0)
    `- Default
  [6:6]   CFG_BOOT_EN 0x1 (0b1)
    `- Enable
  [7:7]   CFG_ROM_READ 0x0 (0b0)
    `- Disable the programmer to read out, and keep the program secret
  [27:8]  RESERVED 0xFFF0F (0b11111111111100001111)
    `- Default
  [31:28] VALID_SIG 0x4 (0b100)
    `- Valid
00:04:25 [INFO] Read /lib/firmware/tests-ch57xf-led.bin as Binary format
00:04:25 [INFO] Firmware size: 3072
00:04:25 [INFO] Erasing...
00:04:25 [WARN] erase_code: set min number of erased sectors to 8
00:04:25 [INFO] Erased 8 code flash sectors
00:04:26 [INFO] Erase done
00:04:26 [INFO] Writing to code flash...
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 3072/307200:04:29 [INFO] Code flash 3072 bytes written
00:04:29 [INFO] Verifying...
Error: Verify failed, mismatch

Is it known problem? Are there any way to debug and make it works?

@nikitos1550
Copy link
Author

I found at least one thing that maybe a bug (https://github.com/ch32-rs/wchisp/blob/c7a7434f7adfd0dde9933bdb97a252c8f50c77c5/src/protocol.rs#L209C1-L216C14)

            Command::WriteConfig { bit_mask, data } => {
                let mut buf = vec![0u8; 1 + 2 + 2 + data.len()];
                buf[0] = commands::WRITE_CONFIG;
                buf.pwrite_with(1 + data.len() as u16, 1, scroll::LE)?;  // <---- here len seems should be 2 + data.len()
                buf[3] = bit_mask;
                buf[5..].copy_from_slice(&data);
                Ok(buf)
            }

@nikitos1550
Copy link
Author

Finally found that changing reset to default 0x4FFF0F4D make deal

    # reset: 0x4FFF0F4D
    # CFG_DEBUG_EN=1、CFG_RESET_EN=0、CFG_ROM_READ=1
    # enable 2-wire debug
    reset: 0x4FFF0FD5 

@nikitos1550
Copy link
Author

Good PR will be implementation for config set in order to setup custom value and keep reset same as WCHISPUtil default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant