Skip to content

Commit 721123b

Browse files
committed
Add basic support for GD32VF103
1 parent 8e43392 commit 721123b

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/bus.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
454454

455455
// Configuring Vbus sense and SOF output
456456
match core_id {
457-
0x0000_1200 | 0x0000_1100 => {
457+
0x0000_1000 | 0x0000_1200 | 0x0000_1100 => {
458458
// F429-like chips have the GCCFG.NOVBUSSENS bit
459459

460460
//modify_reg!(otg_global, regs.global, GCCFG, NOVBUSSENS: 1);
@@ -633,20 +633,25 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
633633
0b01 | 0b11 => {
634634
// Full speed
635635

636-
// From RM0431 (F72xx), RM0090 (F429)
637-
trdt = match self.peripheral.ahb_frequency_hz() {
638-
0..=14_199_999 => panic!("AHB frequency is too low"),
639-
14_200_000..=14_999_999 => 0xF,
640-
15_000_000..=15_999_999 => 0xE,
641-
16_000_000..=17_199_999 => 0xD,
642-
17_200_000..=18_499_999 => 0xC,
643-
18_500_000..=19_999_999 => 0xB,
644-
20_000_000..=21_799_999 => 0xA,
645-
21_800_000..=23_999_999 => 0x9,
646-
24_000_000..=27_499_999 => 0x8,
647-
27_500_000..=31_999_999 => 0x7, // 27.7..32 in code from CubeIDE
648-
32_000_000..=u32::MAX => 0x6,
649-
};
636+
if core_id == 0x0000_1000 {
637+
// From GD32VF103_Firmware_Library_V1.0.2.rar.
638+
trdt = 0x05;
639+
} else {
640+
// From RM0431 (F72xx), RM0090 (F429)
641+
trdt = match self.peripheral.ahb_frequency_hz() {
642+
0..=14_199_999 => panic!("AHB frequency is too low"),
643+
14_200_000..=14_999_999 => 0xF,
644+
15_000_000..=15_999_999 => 0xE,
645+
16_000_000..=17_199_999 => 0xD,
646+
17_200_000..=18_499_999 => 0xC,
647+
18_500_000..=19_999_999 => 0xB,
648+
20_000_000..=21_799_999 => 0xA,
649+
21_800_000..=23_999_999 => 0x9,
650+
24_000_000..=27_499_999 => 0x8,
651+
27_500_000..=31_999_999 => 0x7, // 27.7..32 in code from CubeIDE
652+
32_000_000..=u32::MAX => 0x6,
653+
};
654+
}
650655
}
651656
_ => unimplemented!(),
652657
}
@@ -697,7 +702,10 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
697702
read_reg!(otg_global, regs.global(), GRXSTSP); // pop GRXSTSP
698703

699704
// Re-enable the endpoint, F429-like chips only
700-
if core_id == 0x0000_1200 || core_id == 0x0000_1100 {
705+
if core_id == 0x0000_1000
706+
|| core_id == 0x0000_1200
707+
|| core_id == 0x0000_1100
708+
{
701709
let ep = regs.endpoint_out(epnum as usize);
702710
modify_reg!(endpoint_out, ep, DOEPCTL, CNAK: 1, EPENA: 1);
703711
}

0 commit comments

Comments
 (0)