Browse Source

chore: ch32v103 verfied

pull/32/head
Andelf 1 year ago
parent
commit
bb98f40823
  1. 51
      src/flash_op.rs
  2. 2
      src/lib.rs
  3. 45
      src/operations.rs

51
src/flash_op.rs

@ -35,39 +35,38 @@ pub const CH32V307: [u8; 446] = [
/// For CH32V103 /// For CH32V103
// 1 // 1
pub const CH32V103: [u8; 0x200] = [ pub const CH32V103: [u8; 494] = [
0x01, 0x11, 0x02, 0xce, 0x93, 0x77, 0x15, 0x00, 0x99, 0xcf, 0xb7, 0x06, 0x67, 0x45, 0xb7, 0x27, 0x01, 0x11, 0x02, 0xce, 0x93, 0x77, 0x15, 0x00, 0x99, 0xcf, 0xb7, 0x06, 0x67, 0x45, 0xb7, 0x27,
0x02, 0x40, 0x93, 0x86, 0x36, 0x12, 0x37, 0x97, 0xef, 0xcd, 0xd4, 0xc3, 0x13, 0x07, 0xb7, 0x9a, 0x02, 0x40, 0x93, 0x86, 0x36, 0x12, 0x37, 0x97, 0xef, 0xcd, 0xd4, 0xc3, 0x13, 0x07, 0xb7, 0x9a,
0xd8, 0xc3, 0xd4, 0xd3, 0xd8, 0xd3, 0x93, 0x77, 0x25, 0x00, 0x9d, 0xc7, 0xb7, 0x27, 0x02, 0x40, 0xd8, 0xc3, 0xd4, 0xd3, 0xd8, 0xd3, 0x93, 0x77, 0x25, 0x00, 0x9d, 0xc7, 0xb7, 0x27, 0x02, 0x40,
0x98, 0x4b, 0xad, 0x66, 0x37, 0x38, 0x00, 0x40, 0x13, 0x67, 0x47, 0x00, 0x98, 0xcb, 0x98, 0x4b, 0x98, 0x4b, 0xad, 0x66, 0x37, 0x38, 0x00, 0x40, 0x13, 0x67, 0x47, 0x00, 0x98, 0xcb, 0x98, 0x4b,
0x93, 0x86, 0xa6, 0xaa, 0x13, 0x67, 0x07, 0x04, 0x98, 0xcb, 0xd8, 0x47, 0x05, 0x8b, 0x63, 0x16, 0x93, 0x86, 0xa6, 0xaa, 0x13, 0x67, 0x07, 0x04, 0x98, 0xcb, 0xd8, 0x47, 0x05, 0x8b, 0x63, 0x1f,
0x07, 0x10, 0x98, 0x4b, 0x6d, 0x9b, 0x98, 0xcb, 0x93, 0x77, 0x45, 0x00, 0xa9, 0xcb, 0x93, 0x07, 0x07, 0x10, 0x98, 0x4b, 0x6d, 0x9b, 0x98, 0xcb, 0x93, 0x77, 0x45, 0x00, 0xa9, 0xcb, 0x93, 0x07,
0xf6, 0x0f, 0xa1, 0x83, 0x2e, 0xc6, 0x2d, 0x68, 0x81, 0x76, 0x3e, 0xca, 0xb7, 0x08, 0x02, 0x00, 0xf6, 0x07, 0x9d, 0x83, 0x2e, 0xc6, 0x2d, 0x68, 0x81, 0x76, 0x3e, 0xca, 0xb7, 0x08, 0x02, 0x00,
0xb7, 0x27, 0x02, 0x40, 0x37, 0x33, 0x00, 0x40, 0x13, 0x08, 0xa8, 0xaa, 0xfd, 0x16, 0x98, 0x4b, 0xb7, 0x27, 0x02, 0x40, 0x37, 0x33, 0x00, 0x40, 0x13, 0x08, 0xa8, 0xaa, 0xfd, 0x16, 0x98, 0x4b,
0x33, 0x67, 0x17, 0x01, 0x98, 0xcb, 0x32, 0x47, 0xd8, 0xcb, 0x98, 0x4b, 0x13, 0x67, 0x07, 0x04, 0x33, 0x67, 0x17, 0x01, 0x98, 0xcb, 0x32, 0x47, 0xd8, 0xcb, 0x98, 0x4b, 0x13, 0x67, 0x07, 0x04,
0x98, 0xcb, 0xd8, 0x47, 0x05, 0x8b, 0x69, 0xe7, 0x98, 0x4b, 0x75, 0x8f, 0x98, 0xcb, 0x32, 0x47, 0x98, 0xcb, 0xd8, 0x47, 0x05, 0x8b, 0x71, 0xef, 0x98, 0x4b, 0x75, 0x8f, 0x98, 0xcb, 0x32, 0x47,
0x13, 0x07, 0x07, 0x10, 0x3a, 0xc6, 0x52, 0x47, 0x7d, 0x17, 0x3a, 0xca, 0x69, 0xfb, 0x93, 0x77, 0x13, 0x07, 0x07, 0x08, 0x3a, 0xc6, 0x52, 0x47, 0x7d, 0x17, 0x3a, 0xca, 0x69, 0xfb, 0x93, 0x77,
0x85, 0x00, 0xf1, 0xcf, 0x93, 0x07, 0xf6, 0x0f, 0x2e, 0xc6, 0xa1, 0x83, 0x3e, 0xca, 0x37, 0x27, 0x85, 0x00, 0xed, 0xc3, 0x93, 0x07, 0xf6, 0x07, 0x2e, 0xc6, 0x9d, 0x83, 0x37, 0x27, 0x02, 0x40,
0x02, 0x40, 0x1c, 0x4b, 0xc1, 0x66, 0x2d, 0x68, 0xd5, 0x8f, 0x1c, 0xcb, 0xb7, 0x16, 0x00, 0x20, 0x3e, 0xca, 0x1c, 0x4b, 0xc1, 0x66, 0x37, 0x08, 0x08, 0x00, 0xd5, 0x8f, 0x1c, 0xcb, 0xa1, 0x48,
0xb7, 0x27, 0x02, 0x40, 0x37, 0x03, 0x08, 0x00, 0x13, 0x0e, 0x00, 0x04, 0xb7, 0x0e, 0x04, 0x00, 0x37, 0x17, 0x00, 0x20, 0xb7, 0x27, 0x02, 0x40, 0x37, 0x03, 0x04, 0x00, 0x94, 0x4b, 0xb3, 0xe6,
0xb7, 0x38, 0x00, 0x40, 0x13, 0x08, 0xa8, 0xaa, 0x98, 0x4b, 0x33, 0x67, 0x67, 0x00, 0x98, 0xcb, 0x06, 0x01, 0x94, 0xcb, 0xd4, 0x47, 0x85, 0x8a, 0xf5, 0xfe, 0xb2, 0x46, 0x3a, 0x8e, 0x36, 0xc8,
0xd8, 0x47, 0x05, 0x8b, 0x75, 0xff, 0x32, 0x47, 0x36, 0x8f, 0x3a, 0xc8, 0x72, 0xcc, 0x42, 0x47, 0x46, 0xcc, 0xc2, 0x46, 0x83, 0x2e, 0x07, 0x00, 0x41, 0x07, 0x23, 0xa0, 0xd6, 0x01, 0xc2, 0x46,
0x03, 0x2f, 0x0f, 0x00, 0x91, 0x06, 0x23, 0x20, 0xe7, 0x01, 0x98, 0x4b, 0x33, 0x67, 0xd7, 0x01, 0x83, 0x2e, 0x47, 0xff, 0x23, 0xa2, 0xd6, 0x01, 0xc2, 0x46, 0x83, 0x2e, 0x87, 0xff, 0x23, 0xa4,
0x98, 0xcb, 0xd8, 0x47, 0x05, 0x8b, 0x21, 0xeb, 0x42, 0x47, 0x36, 0x8f, 0x11, 0x07, 0x3a, 0xc8, 0xd6, 0x01, 0xc2, 0x46, 0x03, 0x2e, 0xce, 0x00, 0x23, 0xa6, 0xc6, 0x01, 0x94, 0x4b, 0xb3, 0xe6,
0x62, 0x47, 0x7d, 0x17, 0x3a, 0xcc, 0x61, 0xff, 0x32, 0x47, 0xd8, 0xcb, 0x98, 0x4b, 0x13, 0x67, 0x66, 0x00, 0x94, 0xcb, 0xd4, 0x47, 0x85, 0x8a, 0xf5, 0xfe, 0xc2, 0x46, 0x3a, 0x8e, 0xc1, 0x06,
0x07, 0x04, 0x98, 0xcb, 0xd8, 0x47, 0x05, 0x8b, 0x15, 0xeb, 0xd8, 0x47, 0x41, 0x8b, 0x15, 0xcb, 0x36, 0xc8, 0xe2, 0x46, 0xfd, 0x16, 0x36, 0xcc, 0xcd, 0xfe, 0xb2, 0x46, 0xd4, 0xcb, 0x94, 0x4b,
0xd8, 0x47, 0xb7, 0x06, 0xf3, 0xff, 0xfd, 0x16, 0x13, 0x67, 0x07, 0x01, 0xd8, 0xc7, 0x98, 0x4b, 0x93, 0xe6, 0x06, 0x04, 0x94, 0xcb, 0xd4, 0x47, 0x85, 0x8a, 0xf5, 0xfe, 0xd4, 0x47, 0xd1, 0x8a,
0x21, 0x45, 0x75, 0x8f, 0x98, 0xcb, 0x05, 0x61, 0x02, 0x90, 0x23, 0x20, 0xd8, 0x00, 0xf5, 0xb5, 0x85, 0xc6, 0xd8, 0x47, 0xb7, 0x06, 0xf3, 0xff, 0xfd, 0x16, 0x13, 0x67, 0x47, 0x01, 0xd8, 0xc7,
0x23, 0x20, 0x03, 0x01, 0x3d, 0xb7, 0x23, 0xa0, 0x08, 0x01, 0x65, 0xb7, 0x23, 0xa0, 0x08, 0x01, 0x98, 0x4b, 0x21, 0x45, 0x75, 0x8f, 0x98, 0xcb, 0x05, 0x61, 0x02, 0x90, 0x23, 0x20, 0xd8, 0x00,
0xd1, 0xb7, 0x32, 0x47, 0x13, 0x07, 0x07, 0x10, 0x3a, 0xc6, 0x52, 0x47, 0x7d, 0x17, 0x3a, 0xca, 0xe9, 0xbd, 0x23, 0x20, 0x03, 0x01, 0x31, 0xbf, 0xb2, 0x46, 0x93, 0x86, 0x06, 0x08, 0x36, 0xc6,
0x25, 0xf7, 0x98, 0x4b, 0xb7, 0x06, 0xf3, 0xff, 0xfd, 0x16, 0x75, 0x8f, 0x98, 0xcb, 0x41, 0x89, 0xd2, 0x46, 0xfd, 0x16, 0x36, 0xca, 0xb9, 0xfa, 0x98, 0x4b, 0xb7, 0x06, 0xf3, 0xff, 0xfd, 0x16,
0x19, 0xe1, 0x01, 0x45, 0xc9, 0xb7, 0x2e, 0xc6, 0x0d, 0x06, 0x02, 0xca, 0x09, 0x82, 0x32, 0xcc, 0x75, 0x8f, 0x98, 0xcb, 0x41, 0x89, 0x19, 0xe1, 0x01, 0x45, 0xf9, 0xb7, 0x2e, 0xc6, 0x0d, 0x06,
0xb7, 0x17, 0x00, 0x20, 0x98, 0x43, 0x13, 0x86, 0x47, 0x00, 0xd2, 0x47, 0xb2, 0x46, 0x8a, 0x07, 0x02, 0xca, 0x09, 0x82, 0x32, 0xcc, 0xb7, 0x17, 0x00, 0x20, 0x98, 0x43, 0x13, 0x86, 0x47, 0x00,
0xb6, 0x97, 0x9c, 0x43, 0x63, 0x18, 0xf7, 0x02, 0xd2, 0x47, 0x32, 0x47, 0x8a, 0x07, 0xba, 0x97, 0xd2, 0x47, 0xb2, 0x46, 0x8a, 0x07, 0xb6, 0x97, 0x9c, 0x43, 0x63, 0x18, 0xf7, 0x02, 0xd2, 0x47,
0x98, 0x43, 0xf2, 0x47, 0xba, 0x97, 0x3e, 0xce, 0xd2, 0x47, 0x85, 0x07, 0x3e, 0xca, 0xd2, 0x46, 0x32, 0x47, 0x8a, 0x07, 0xba, 0x97, 0x98, 0x43, 0xf2, 0x47, 0xba, 0x97, 0x3e, 0xce, 0xd2, 0x47,
0x62, 0x47, 0xb2, 0x87, 0xe3, 0xe8, 0xe6, 0xfc, 0xb7, 0x27, 0x00, 0x20, 0x98, 0x4b, 0xf2, 0x47, 0x85, 0x07, 0x3e, 0xca, 0xd2, 0x46, 0x62, 0x47, 0xb2, 0x87, 0xe3, 0xe8, 0xe6, 0xfc, 0xb7, 0x27,
0xe3, 0x09, 0xf7, 0xfa, 0x41, 0x45, 0x85, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x20, 0x98, 0x4b, 0xf2, 0x47, 0xe3, 0x09, 0xf7, 0xfa, 0x41, 0x45, 0xb5, 0xbf,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
]; ];
/// For CH56X /// For CH56X

2
src/lib.rs

@ -163,7 +163,7 @@ impl RiscvChip {
// 81 0d 01 03 // 81 0d 01 03
// 81 0d 01 10 // 81 0d 01 10
let _ = probe.send_command(RawCommand::<0x0d>(vec![0x03]))?; let _ = probe.send_command(RawCommand::<0x0d>(vec![0x03]))?;
let _ = probe.send_command(RawCommand::<0x0d>(vec![0x10]))?; // let _ = probe.send_command(RawCommand::<0x0d>(vec![0x10]))?;
} }
RiscvChip::CH32V30X | RiscvChip::CH8571 | RiscvChip::CH32V003 => { RiscvChip::CH32V30X | RiscvChip::CH8571 | RiscvChip::CH32V003 => {
// 81 0d 01 03 // 81 0d 01 03

45
src/operations.rs

@ -281,8 +281,16 @@ impl WchLink {
let write_pack_size = self.chip.as_ref().unwrap().chip_family.write_pack_size(); let write_pack_size = self.chip.as_ref().unwrap().chip_family.write_pack_size();
let data_packet_size = self.chip.as_ref().unwrap().chip_family.data_packet_size(); let data_packet_size = self.chip.as_ref().unwrap().chip_family.data_packet_size();
let data = data.to_vec(); let mut data = data.to_vec();
log::trace!("Using write pack size {}", write_pack_size); if data.len() % data_packet_size != 0 {
data.resize((data.len() / data_packet_size + 1) * data_packet_size, 0xff);
log::debug!("Data resized to {}", data.len());
}
log::debug!(
"Using write pack size {} data pack size {}",
write_pack_size,
data_packet_size
);
//if data.len() < write_pack_size as usize { //if data.len() < write_pack_size as usize {
// data.resize(write_pack_size as usize, 0xff); // data.resize(write_pack_size as usize, 0xff);
// } // }
@ -306,6 +314,7 @@ impl WchLink {
log::debug!("Flash OP written"); log::debug!("Flash OP written");
std::thread::sleep(Duration::from_millis(10)); std::thread::sleep(Duration::from_millis(10));
if self.chip.as_ref().unwrap().chip_family == RiscvChip::CH32V103 {}
if let Ok(n) = self.send_command(Program::Unknown07AfterFlashOPWritten) { if let Ok(n) = self.send_command(Program::Unknown07AfterFlashOPWritten) {
if n == 0x07 { if n == 0x07 {
break; break;
@ -324,38 +333,24 @@ impl WchLink {
} }
// wlink_fastprogram // wlink_fastprogram
self.send_command(Program::WriteFlash)?; self.send_command(Program::WriteFlashAndVerify)?;
for chunk in data.chunks(write_pack_size as usize) { for chunk in data.chunks(write_pack_size as usize) {
self.device_handle self.device_handle
.write_data_endpoint(&chunk, data_packet_size)?; .write_data_endpoint(&chunk, data_packet_size)?;
} std::thread::sleep(Duration::from_secs(2));
std::thread::sleep(Duration::from_secs(2));
let rxbuf = self.device_handle.read_data_endpoint(4)?;
// 41 01 01 04
if rxbuf[3] != 0x04 {
return Err(Error::Custom(format!(
// 0x05
// 0x18
// 0xff
"Error while fastprogram: {:02x?}",
rxbuf
)));
}
/* for chunk in data.chunks(write_pack_size as usize) {
self.device_handle
.write_data_endpoint(chunk, data_packet_size)?;
let rxbuf = self.device_handle.read_data_endpoint(4)?; let rxbuf = self.device_handle.read_data_endpoint(4)?;
// 41 01 01 04 // 41 01 01 04
if rxbuf[3] != 0x02 && rxbuf[3] != 0x04 { if rxbuf[3] != 0x04 {
return Err(Error::Custom(format!( return Err(Error::Custom(format!(
"Error while fastprogram: {:02x}", // 0x05
rxbuf[3] // 0x18
// 0xff
"Error while fastprogram: {:02x?}",
rxbuf
))); )));
} }
} }
*/
log::debug!("Fastprogram done"); log::debug!("Fastprogram done");
// wlink_endprogram // wlink_endprogram

Loading…
Cancel
Save