diff --git a/docs/CH643.md b/docs/CH643.md new file mode 100644 index 0000000..f7d8130 --- /dev/null +++ b/docs/CH643.md @@ -0,0 +1,10 @@ +# CH643 + +## Chips + +``` +* CH643W-0x64300601 +* CH643Q-0x64310601 +* CH643L-0x64330601 +* CH643U-0x64340601 +``` diff --git a/src/chips.rs b/src/chips.rs new file mode 100644 index 0000000..9e1fcc4 --- /dev/null +++ b/src/chips.rs @@ -0,0 +1,90 @@ +//! The chip DB. + +pub fn chip_id_to_chip_name(chip_id: u32) -> Option<&'static str> { + match chip_id & 0xFFF00000 { + 0x650_00000 => Some("CH565"), + 0x690_00000 => Some("CH569"), + 0x710_00000 => Some("CH571"), + 0x730_00000 => Some("CH573"), + 0x810_00000 => Some("CH581"), + 0x820_00000 => Some("CH582"), + 0x830_00000 => Some("CH583"), + 0x920_00000 => Some("CH592"), + 0x003_00000 => match chip_id & 0xFFFFFF0F { + 0x003_00500 => Some("CH32V003F4P6"), + 0x003_10500 => Some("CH32V003F4U6"), + 0x003_20500 => Some("CH32V003A4M6"), + 0x003_30500 => Some("CH32V003J4M6"), + _ => None, + }, + 0x035_00000 => match chip_id & 0xFFFFFF0F { + 0x035_00601 => Some("CH32X035R8T6"), + 0x035_10601 => Some("CH32X035C8T6"), + 0x035_E0601 => Some("CH32X035F8U6"), + 0x035_60601 => Some("CH32X035G8U6"), + 0x035_B0601 => Some("CH32X035G8R6"), + 0x035_70601 => Some("CH32X035F7P6"), + 0x035_A0601 => Some("CH32X033F8P6"), + _ => None, + }, + 0x103_00000 => match chip_id & 0xFFFFFF0F { + 0x103_00700 => Some("CH32L103C8U6"), + 0x103_10700 => Some("CH32L103C8T6"), + 0x103_A0700 => Some("CH32L103F8P6"), + 0x103_B0700 => Some("CH32L103G8R6"), + 0x103_20700 => Some("CH32L103K8U6"), + 0x103_D0700 => Some("CH32L103F8U6"), + 0x103_70700 => Some("CH32L103F7P6"), + _ => None, + }, + 0x200_00000 => match chip_id { + 0x200_04102 => Some("CH32F103C8T6"), + 0x200_0410F => Some("CH32F103R8T6"), + _ => None, + }, + 0x203_00000 => match chip_id & 0xFFFFFF0F { + 0x203_00500 => Some("CH32V203C8U6"), + 0x203_10500 => Some("CH32V203C8T6"), + 0x203_20500 => Some("CH32V203K8T6"), + 0x203_30500 => Some("CH32V203C6T6"), + 0x203_50500 => Some("CH32V203K6T6"), + 0x203_60500 => Some("CH32V203G6U6"), + 0x203_B0500 => Some("CH32V203G8R6"), + 0x203_E0500 => Some("CH32V203F8U6"), + 0x203_70500 => Some("CH32V203F6P6"), + 0x203_90500 => Some("CH32V203F6P6"), + 0x203_A0500 => Some("CH32V203F8P6"), + 0x203_4050C => Some("CH32V203RBT6"), + _ => None, + }, + 0x208_00000 => match chip_id & 0xFFFFFF0F { + 0x208_0050C => Some("CH32V208WBU6"), + 0x208_1050C => Some("CH32V208RBT6"), + 0x208_2050C => Some("CH32V208CBU6"), + 0x208_3050C => Some("CH32V208GBU6"), + _ => None, + }, + 0x303_00000 | 0x305_00000 | 0x307_00000 => match chip_id & 0xFFFFFF0F { + 0x303_30504 => Some("CH32V303CBT6"), + 0x303_20504 => Some("CH32V303RBT6"), + 0x303_10504 => Some("CH32V303RCT6"), + 0x303_00504 => Some("CH32V303VCT6"), + 0x305_20508 => Some("CH32V305FBP6"), + 0x305_00508 => Some("CH32V305RBT6"), + 0x305_B0508 => Some("CH32V305GBU6"), + 0x307_30508 => Some("CH32V307WCU6"), + 0x307_20508 => Some("CH32V307FBP6"), + 0x307_10508 => Some("CH32V307RCT6"), + 0x307_00508 => Some("CH32V307VCT6"), + _ => None, + }, + 0x643_00000 => match chip_id { + 0x643_00601 => Some("CH643W"), + 0x643_10601 => Some("CH643Q"), + 0x643_30601 => Some("CH643L"), + 0x643_40601 => Some("CH643U"), + _ => None, + } + _ => None, + } +} diff --git a/src/commands/control.rs b/src/commands/control.rs index b99f2ff..ab10a01 100644 --- a/src/commands/control.rs +++ b/src/commands/control.rs @@ -70,7 +70,7 @@ impl Command for AttachChip { pub struct AttachChipResponse { pub chip_family: RiscvChip, pub riscvchip: u8, - pub chip_type: u32, + pub chip_id: u32, } impl AttachChipResponse {} impl Response for AttachChipResponse { @@ -81,17 +81,23 @@ impl Response for AttachChipResponse { Ok(Self { chip_family: RiscvChip::try_from_u8(bytes[0])?, riscvchip: bytes[0], - chip_type: u32::from_be_bytes(bytes[1..5].try_into().unwrap()), + chip_id: u32::from_be_bytes(bytes[1..5].try_into().unwrap()), }) } } // For logging impl fmt::Display for AttachChipResponse { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if self.chip_type == 0 { + if self.chip_id == 0 { write!(f, "{:?}", self.chip_family) + } else if let Some(chip_name) = crate::chips::chip_id_to_chip_name(self.chip_id) { + write!( + f, + "{:?} [{}] (ChipID: 0x{:08x})", + self.chip_family, chip_name, self.chip_id + ) } else { - write!(f, "{:?}(0x{:08x})", self.chip_family, self.chip_type) + write!(f, "{:?}(ChipID: 0x{:08x})", self.chip_family, self.chip_id) } } } diff --git a/src/lib.rs b/src/lib.rs index 4906740..f15cdd5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ pub mod format; mod operations; pub mod regs; pub mod transport; +pub mod chips; use commands::RawCommand; use device::WchLink; diff --git a/src/operations.rs b/src/operations.rs index e5112c5..856171b 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -87,7 +87,7 @@ impl WchLink { let info = ChipInfo { uid: None, // TODO chip_family: chip_info.chip_family, - chip_id: chip_info.chip_type, + chip_id: chip_info.chip_id, march: None, };