Skip to content

nrf5x: USBD implementation and examples#965

Open
kotokrad wants to merge 4 commits into
ZigEmbeddedGroup:mainfrom
kotokrad:nrf5x-usbd
Open

nrf5x: USBD implementation and examples#965
kotokrad wants to merge 4 commits into
ZigEmbeddedGroup:mainfrom
kotokrad:nrf5x-usbd

Conversation

@kotokrad

Copy link
Copy Markdown
Contributor

Working USBD, both CDC and HID examples work on nrf52840 (tested on nice!nano and a clone). For PR I adapted them for nrf52840_mdk for consistency but haven't tested as I don't have this board.
HAL structure and examples are based on usb for rp2xxx port.

  • There's a workaround for regz: stride is not applied in cluster arrays #962
  • HFXO is assumed to be enabled by user before initializing USBD.
  • It reads from POWER peripheral to detect VBUS event, but it will be not accessible with softdevice enabled. Probably need some generic way to access it
  • Suspend/resume are not implemented, also it would need access to CLOCK to stop/start HFXO which might be blocked by softdevice.
  • ISO endpoints are not implemented
  • It compiles for nrf52833, but not tested

@mattnite

Copy link
Copy Markdown
Contributor

@kotokrad This is a great looking patch. Please ignore failing macos related actions, it seems that it's too new for Zig 0.15.2. It looks like you have some unused imports. Once those are fixed this is ready for a merge.

@kotokrad

Copy link
Copy Markdown
Contributor Author

@mattnite fixed 👌

@Grazfather

Copy link
Copy Markdown
Collaborator

I have the MDK. Give me a few days to test it.


pub fn pre_enable() void {
if (errata_187_applies()) {
if (reg(0x4006EC00).* == 0x00000000) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What registers are these? Are they documented anywhere? I guess these are internal only registers and we aren't going to get more info than this + the code in the comments above.

@kotokrad kotokrad Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registers are not documented, only this:
Anomaly 171
Anomaly 187

Comment thread port/nordic/nrf5x/src/hal/usbd.zig Outdated
/// Temporary workaround: sizes of generated structs don't match
const USBD_BASE: usize = @intFromPtr(peripherals.USBD);
inline fn epin_ptr(i: u32) *volatile u32 {
return @ptrFromInt(USBD_BASE + 0x600 + i * 0x14);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to remove this now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, tested on my hardware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants