Skip to content

Commit

Permalink
feat: add chip id to chip name mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Oct 3, 2023
1 parent a7f3f00 commit a6a14dd
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/CH643.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CH643

## Chips

```
* CH643W-0x64300601
* CH643Q-0x64310601
* CH643L-0x64330601
* CH643U-0x64340601
```
90 changes: 90 additions & 0 deletions src/chips.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
14 changes: 10 additions & 4 deletions src/commands/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod format;
mod operations;
pub mod regs;
pub mod transport;
pub mod chips;

use commands::RawCommand;
use device::WchLink;
Expand Down
2 changes: 1 addition & 1 deletion src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit a6a14dd

Please sign in to comment.