-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
zephyr: Construct Pin object with a port instance number. #10859
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
zephyr: Construct Pin object with a port instance number. #10859
Conversation
Adds support for constructing a Pin object with a port instance number, where the available instances are defined by devicetree chosen nodes. Existing support for constructing a Pin object with a device name string remains, but device names will become less user-friendly when upgrading to Zephyr v3.2.0 due to deprecation of the devicetree label property. Signed-off-by: Maureen Helm <maureen.helm@intel.com>
Thanks for the patch. It looks like this will require a overlay (for the device tree) for every board? And then every peripheral within that board will need to be listed (GPIO, SPI, UART, etc), is that correct? Is it possible to provide a generic overlay for a particular MCU series that will work on all boards using that MCU? (Or even better a single, generic overlay for everything?) |
Take a look at the solution proposed in #10830, it should be a bit more generic I think. |
@MaureenHelm @bogdanm -- Thanks both of you for looking at this! It has been on my TODO list, but I am relatively new to Zephyr and device tree and haven't had the time to really try and understand this. I have looked at this PR and #10830 (and of course the original #9335 to move to v3.2.0). From MicroPython's perspective, we'd like to see three things:
We (@dpgeorge and I) are very keen to do more with the Zephyr port, in particular to support the nRF family, to the extent that I'd like to remove our nRF port in favour of making the Zephyr port feature-parity. I don't particularly mind about (once-off) breaking backwards compatibility on the Zephyr port in order to achieve any of the above. So... first up... I'm curious why Zephyr made the change here. Why was the devicetree label property deprecated? It seems useful? What was the downside? I'll address the two PRs together here, mostly because my comments are fairly high-level...
Thanks! |
Hi @jimmo, thank for your reply. The reason for the change is explained in some detail in https://docs.zephyrproject.org/3.2.0/releases/release-notes-3.2.html#devicetree. While I am not a Zephyr expert, I think I understand their reasoning. Their macro-based alternative ( My script can easily be changed to generate |
Thanks for the additional context @bogdanm I guess the guiding principles here should be:
My understanding of https://docs.zephyrproject.org/3.2.0/build/dts/api-usage.html#dt-node-identifiers is that node labels are named for the way the SoC names them. Fortunately this matches what we do in MicroPython for other ports. e.g. on STM32 you refer to pins as "An", "Bn", etc. On rp2, it's "GPIOn", i.e. we match the way the datasheet or vendor SDK refers to them. Zephyr is the only port where we do the tuple thing for machine.Pin, so it's a bit of an odd one out there, so I'd like to fix that too. It's also one of the few remaining ports where machine.Pin.cpu.PinName isn't implemented. Should find out what @dpgeorge thinks, but I think what I'd like to see on Zephyr is: machine.Pin("<nodelabel>_n")
machine.Pin.cpu.<nodelabel>_n
machine.I2C("<nodelabel>")
... etc (In other words, if we're going to break backwards compatibility we might as well go all the way and drop the tuple syntax for pins and make it exactly like the other ports, right down to the way make-pins.py works on other ports. The only difference is that make-pins.py is using something like the code you've written to query the device tree in order to generate the tables, compared to e.g. the stm32 one that parses the stm hal). There's a whole separate discussion to be had around how to implement |
@jimmo I'm new to MicroPython in general and I only used it with Zephyr, so I'll take your word for it :) Just let me know how I can help to make this happen.
Not in general, as far as I can tell. The code to access a GPIO pin would look something like this:
There are some things for which you can specify a port/pin combo. For example, you can define LEDs (https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/arm/stm32h735g_disco/stm32h735g_disco.dts#L22-L32) or keys (https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/arm/stm32h735g_disco/stm32h735g_disco.dts#L34-L40), but these are specific DT features. For generic GPIO access you are stuck with the port/pin pair, but there's probably a way to make this happen in MicroPython too. I'm thinking that the C code can parse |
Yes, that is correct. There isn't a general way to enumerate a list of devices of a given type (i.e., all I2C devices or all UART devices). It's possible for sensors via zephyrproject-rtos/zephyr#51352 but this pattern hasn't been extended to other device types.
Probably, but I'm not sure how much that really helps here.
Right, and unfortunately I think this will make @bogdanm 's script hard to maintain across SoC families.
That's great to hear! |
FWIW, the Arduino GSoC project also had the same desire and looked into automating generating overlay files. We ran out of time last year but it seemed feasible given how simple the overlays need to be (at least for the Arduino Core.) I imagine something similar could apply for MP. |
I don't think the script would require much maintenance. This is (hopefully) a one time change in Zephyr, so the script would have to be written once, verified that it works correctly and then happily do its job ever after :) I'm not even married to the idea of translating the node names ( |
Any news on this? I appreciate that this kind of thing moves slowly, but think about the benefits: as someone mentioned above, this could potentially replace the nRF port completely (I can personally testify that the nRF support in Zephyr is very good). And who knows, maybe other platforms too. |
Fixing this is important but we need to fully understand the best way forward. And the pending v1.20.0 release of MicroPython is a higher priority right now. |
Any news? |
Sadly, this appears to be a low priority item for the dev team, which is unfortunate because it forces me (and likely others) to work on a fork, which is rarely a good thing. But I still hope for some good news 🤞 |
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
@MaureenHelm I think we can close this, because it was superseded by #9335. Or at the very least, this needs reworking on the latest master. |
Adds support for constructing a Pin object with a port instance number, where the available instances are defined by devicetree chosen nodes. Existing support for constructing a Pin object with a device name string remains, but device names will become less user-friendly when upgrading to Zephyr v3.2.0 due to deprecation of the devicetree label property.