-
Notifications
You must be signed in to change notification settings - Fork 165
ch32 USBHD/USBHS driver implementation #893
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
base: main
Are you sure you want to change the base?
Conversation
…into origin/umain
…oards. ch32 USBHS still sends packets twice.
…ual mode. CDC Works without extra packets!
…ed code in usb_cdc.zig
Lint ResultsFound 12 issues on changed lines in 4 files:
|
…ng to board definitions, add max packet size to usb device hal.
| _reserved1: u2 = 0, | ||
| }); | ||
|
|
||
| fn baseAddr() usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to base_addr, in MicroZig we use snake case for function names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one actually makes sense
Grazfather
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed everything except for the HALs themselves (since this is a draft). Will get to those when you think they're ready.
| .bcd_usb = config.bcd_usb, | ||
| .device_triple = config.device_triple, | ||
| .max_packet_size0 = @max(config.max_supported_packet_size, 64), | ||
| .max_packet_size0 = @min(config.max_supported_packet_size, 64), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woof
| .{ .target = mb.ports.ch32v.boards.ch32v203.nano_ch32v203, .name = "nano_ch32v203_blinky", .file = "src/board_blinky.zig" }, | ||
| .{ .target = mb.ports.ch32v.boards.ch32v203.nano_ch32v203, .name = "nano_ch32v203_usb_cdc", .file = "src/usb_cdc.zig" }, | ||
| .{ .target = mb.ports.ch32v.boards.ch32v203.suzuduino_uno_v1b, .name = "suzuduino_blinky", .file = "src/board_blinky.zig" }, | ||
| .{ .target = mb.ports.ch32v.boards.ch32v203.suzuduino_uno_v1b, .name = "suzuduino_usb_cdc", .file = "src/usb_cdc.zig" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this one tested?
| .{ .target = mb.ports.ch32v.boards.ch32v203.lana_tny, .name = "lana_tny_spi_loopback", .file = "src/spi_loopback.zig" }, | ||
| .{ .target = mb.ports.ch32v.boards.ch32v203.lana_tny, .name = "lana_tny_spi_flash_w25q", .file = "src/spi_flash_w25q.zig" }, | ||
| .{ .target = mb.ports.ch32v.boards.ch32v203.lana_tny, .name = "lana_tny_sharp_niceview", .file = "src/sharp_niceview.zig" }, | ||
| .{ .target = mb.ports.ch32v.boards.ch32v203.lana_tny, .name = "lana_tny_usb_cdc", .file = "src/usb_cdc.zig" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this one? I have this so I can test it for you.
| pub const usart = @import("usart.zig"); | ||
| pub const spi = @import("spi.zig"); | ||
| pub const dma = @import("dma.zig"); | ||
| pub const usb = @import("usbfs.zig"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this in the test block as well
| /// HSI (High Speed Internal) oscillator frequency | ||
| /// This is the fixed internal RC oscillator frequency for CH32V30x | ||
| pub const hsi_frequency: u32 = 8_000_000; // 8 MHz | ||
| pub const hse_frequency: u32 = 8_000_000; // 8 MHz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be board level, since it's external to the chip and may not be present.
| /// selects whether the USBHS 48MHz clock comes from the system PLL clock or the USB PHY, | ||
| /// and enables the AHB clock gate for USBHS. | ||
| /// | ||
| /// Note: The SVD names bit31 as `USBFSSRC`, but the reference manual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we patch this? Which SVD? All of them?
| const tog_pin = gpio.Pin.init(0, 14); | ||
| const mco_pin = gpio.Pin.init(0, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well keep with the comments e.g. PA14 and PA8
| .configurations = &.{.{ | ||
| .attributes = .{ .self_powered = false }, | ||
| .max_current_ma = 50, | ||
| .Drivers = struct { serial: USB_Serial }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe copy some of the extra comments I added to the cdc example for rpi?
| pub var usb_dev: hal.usb.Polled( | ||
| .{}, | ||
| ) = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pub var usb_dev: hal.usb.Polled( | |
| .{}, | |
| ) = undefined; | |
| pub var usb_dev: hal.usb.Polled(.{}) = undefined; |
| // pins.tog.put(0); | ||
| usb_dev.poll(false, &usb_controller); | ||
| // pins.tog.put(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gets rid of toggle pins completely or uncomment these please
This adds a new driver for the ch32 USBHD/USBHS peripheral, USB_OTG_FS peripheral, and examples for the ch32v307, and ch32v203 boards.