Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature: additional peripheral registers #145

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

Merged
merged 7 commits into from
Apr 15, 2025

Conversation

rivimey
Copy link
Contributor

@rivimey rivimey commented Apr 9, 2025

I tried running an instance of Apache nuttx compiled for rp2040 and got quite a number of failures, mostly due to incomplete peripheral register emulation. This PR includes some work that starts to fill in those gaps. I split the changes up by file but mostly also by function:

  • Add register addrEndp with masking value; not yet used.
    AddrEndP is used to set the USB endpoint addresses for both host and device mode. nuttx was trying to configure it and failing the write, though I'm not sure it actually matters yet (other than a message) because so much usb functionality is missing anyway.

  • Include register info for most registers, no additional functionality
    Adds the register names/address offsets for many of the SSI registers and for about half (those that nuttx references) adds a variable that can be read/written. I don't see any actual functionality for SSI so there doesn't seem to be anything else to do.

  • Report unimplemented registers using hex values; NB sometimes see "0x-1" -- signedness issue
    This is the generic "unimplemented" code, and the change causes register offset number and register value to be written in hex - more useful IMO than decimal, and also clearer when the 0x prefix indicates it.

  • Logic for spikelen register, enable_status register and sda_hold
    The I2C peripheral has a few registers that caused problems because nuttx code was busy-waiting for non-zero read results. The change makes the register model a lot more complete and can now boot nuttx[i2c].

  • Add registers for all clocks in clock block with reset default values, selects, reserved bit masking
    Nuttx tries to configure the clock unit and needs to see things selected properly to boot. The change adds almost all (not the freq counter) of the registers with appropriate links, though it doesn't as yet attempt to use the clock configuration in any way. It would be nice to link the 125MHz clock constant seen elsewhere into this but I'm not sure what that would entail. Reads of control register values are anded with a bitmask corresponding to the reserved bits in the registers. Not sure if it's needed but decided it wouldn't hurt.

  • Report correct state when GPIO has both pullup & pulldown
    This is a little random: saw a comment in the gpio code about both pullup&pulldown at once and decided to include a fix, based on the datasheet. I looked for possible places the new state might be used but didn't see any...

Not changed:
The nuttx boot also tries to change PLL and XOSC unit registers but these blocks are not implemented at all and I chose not to start doing so. Perhaps in the longer term this might be done.

I do get an apparently valid boot with these changes included (using rp2040js via npm on Mac) though it is hard to know how correct the result is, given how much of the hardware is not emulated at all.

I had hoped to be able to use nuttx driving the USB unit in USB CDC-EN (Ethernet) mode, but I guess this would be a lot of work from here.

Hope this is useful. I'm up for some refinement if you need it.

@urish urish self-assigned this Apr 9, 2025
@urish urish requested a review from Copilot April 9, 2025 17:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

src/peripherals/ssi.ts:58

  • If the reserved bits are intended to be cleared, apply the mask as indicated (e.g., 'return this.crtlr0 & 0x017FFFFF;'), otherwise update the comment for clarity.
return this.crtlr0; /*  & 0x017FFFFF = b23,b25..31 reserved */

src/peripherals/i2c.ts:502

  • Consider revisiting the logic for IC_SDA_HOLD writes to ensure it correctly validates input according to the datasheet, as the current check may not cover all valid scenarios.
if (value != 0x1) {

src/peripherals/clocks.ts:65

  • [nitpick] Consider defining the mask value as a named constant instead of using an inline bit literal to improve readability and maintainability.
return this.gpout0Ctrl & 0b100110001110111100000;

@urish
Copy link
Contributor

urish commented Apr 9, 2025

Thanks for your contribution and for the detailed explanation!

Can you please fix the few code styles issues? https://github.com/wokwi/rp2040js/actions/runs/14362416160/job/40271713997?pr=145

Also, would love if we had a github workflow to test with Nuttx, similar to what we currently do with the Pico SDK and MicroPython: https://github.com/wokwi/rp2040js/blob/main/.github/workflows/ci-micropython.yml

But this could be as a future PR

@urish urish merged commit 37019e4 into wokwi:main Apr 15, 2025
13 checks passed
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.

2 participants