Skip to content

docs: Add documentation for rp2 DMA support. #7670

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 1 commit into from
Mar 19, 2024

Conversation

nickovs
Copy link
Contributor

@nickovs nickovs commented Aug 15, 2021

This PR provides documentation for the rp2.DMA support in PR #7641 and the associated additions to rp2.PIO in #7650.

@nickovs
Copy link
Contributor Author

nickovs commented Jan 5, 2022

@Maffels Thanks for approving this. Does this mean that #7641 and #7650 might get approved soon? Updating the documentation is of little use without incorporating the code changes being documented! 😀

@Maffels
Copy link

Maffels commented Jan 5, 2022

My apologies, @nickovs , I tagged "approve" by accident and am unaware of any way of rectifying this mistake.
As far as contributing to this project: I'm afraid I'm enthusiastic about this (together with #7641 and #7650) being added to the next micropython release but not related to any of this in any other way. The "approved" status I accidentally gave it is thus worthless.
Feel free to remove this comment and perhaps if possible the "approved" status.

@nickovs nickovs force-pushed the rp2_dma_docs branch 2 times, most recently from 77dca35 to 6291f90 Compare October 16, 2023 02:05
@nickovs
Copy link
Contributor Author

nickovs commented Oct 16, 2023

I have pushed an update to reflect the changes to the configuration model that @dpgeorge requested for #7641.

@NewWheelTech
Copy link

NewWheelTech commented Nov 16, 2023

The documentation says "# The count is in transfers, which default to four-byte words, so divide length by 4".

After testing the Pico and double checking the documentation it appears to default to 0, which would be bytes.

image

@mendenm
Copy link

mendenm commented Dec 29, 2023

@nickovs A picky note: you might do a global search/substitute of 'crtl' to 'ctrl'. In quite a few places, the letters are swapped.

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@nickovs nickovs force-pushed the rp2_dma_docs branch 2 times, most recently from aadbbb9 to b95f0cb Compare December 31, 2023 22:01
@nickovs
Copy link
Contributor Author

nickovs commented Dec 31, 2023

@NewWheelTech The code as merged defaults to word transfers, so the docs are correct for what we've got. I guess there might be an argument for changing the code to match the C SDK.

Copy link

codecov bot commented Dec 31, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.40%. Comparing base (1c6012b) to head (aadbbb9).

❗ Current head aadbbb9 differs from pull request most recent head 77f08b7. Consider uploading reports for the commit 77f08b7 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7670      +/-   ##
==========================================
+ Coverage   98.39%   98.40%   +0.01%     
==========================================
  Files         161      159       -2     
  Lines       21156    21088      -68     
==========================================
- Hits        20816    20752      -64     
+ Misses        340      336       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dpgeorge
Copy link
Member

dpgeorge commented Jan 2, 2024

I guess there might be an argument for changing the code to match the C SDK.

It's not the SDK that defaults to byte transfers, but rather the register is reset to 0 and that means byte transfer size.

I think it's sensible for the default CTRL value (DEFAULT_DMA_CONFIG) to default to word-sized transfers, because that's the most common use (I guess, eg for peripheral access). Then maybe the count parameter to .config() could always be measured in bytes to make it easier for the user... although that would be harder to implement because if the user sets the CTRL register after specifying count then the count value needs to change based on the new data size set by CTRL.

@mendenm
Copy link

mendenm commented Jan 2, 2024

I would recommend not making the count parameter be bytes. That would make the hardware documentation invalid, and I suspect most of us learn about the DMA functionality from that. Also, other DMA devices I have worked with (e.g. on dsPIC33 processors) count transfers, not bytes.

@nickovs
Copy link
Contributor Author

nickovs commented Jan 2, 2024

The problem with making count be in bytes is that it's neoither what the hardware uses nor what the C SDK uses. While we can fix this for the .config method and for reading and writing the count attribute, we can't fix this for direct access to the register bank, so if people are doing any sort of scatter/gather operation then it will be inconsistent. Also, if people are reading examples in the the RP2040 datasheet then they will have to make semantic modifications rather than just transliterate. As a result I really think that it should stay as transfers rather than bytes.

@dpgeorge
Copy link
Member

dpgeorge commented Jan 3, 2024

As a result I really think that it should stay as transfers rather than bytes.

Yes, agreed.

@dpgeorge
Copy link
Member

dpgeorge commented Jan 7, 2024

@nickovs let me know if/when this is ready for final review and merge.

@nickovs
Copy link
Contributor Author

nickovs commented Jan 7, 2024

With #7650 merged I think that this now accurately reflects the code, so please go ahead with a review and merge.

@pi-mst
Copy link

pi-mst commented Jan 7, 2024

Thanks for your efforts @nickovs, much appreciated!

However, is it possible to come up with a more tangible example? It'd be great to be able to point folks at, say, a Wokwi-hosted example that provided a concise, clear and compelling use case - the examples in the docs either execute practically immediately or are quite low-level and difficult to appreciate. Maybe something like a PIO/DMA solution to control a WS2812B...

@mendenm
Copy link

mendenm commented Jan 7, 2024

@pi-mst If there is interest, I have exactly the the sample code requested: WS2812B run from DMA and PIO, which is running my Christmas light display. @nickovs If you want a block of the code to paste into your docs as an example, I can attach a simplified skeleton. It will take a little while to provide (few weeks before I get around to it), since right now my display is running off an older DMA interface

@nickovs
Copy link
Contributor Author

nickovs commented Jan 8, 2024

I guess the question is how much code do we want to include in the docs themselves? Most of the reference pages do not include a great deal of example code.

I've tried to keep the three examples here short enough that you can see what they are doing, without having a ton of code that is doing something other than the DMA functionality. As it stands there are more examples in here than in the page for rp2.PIO, which is rather more complex.

Most more complex examples will end up more being an example of, say, programming the PIO, rather than using DMA. I'd argue now that DMA is merged, it might be better to start using DMA in the examples elsewhere, rather than having examples for use of PIO, SPI and other devices in the DMA docs.

@mendenm
Copy link

mendenm commented Jan 8, 2024

@nickovs The question about how much code is entirely valid. The other possibility, given the unusual nature of the PIO and DMA devices on the RP2, is to create a special examples section for the rp2 port. Maybe each port should have an examples section that show off specific features of that port. That way, the examples are maintained as good code, and the documentation would link to the appropriate examples section.

Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

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

This is really useful documentation, thanks for contributing it @nickovs!

The keys for the keyword arguments can be any key returned by the :meth:`DMA.unpack_ctrl()`
method. The writable values are:

:param enable: ``BOOL`` Set to enable the channel (default: ``True``).
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Suggest bool or boolean for these, to be inline with other docs and/or the Python type.

Copy link
Member

Choose a reason for hiding this comment

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

I have made this change during the rebase/merge.

@projectgus
Copy link
Contributor

projectgus commented Feb 5, 2024

The other possibility, given the unusual nature of the PIO and DMA devices on the RP2, is to create a special examples section for the rp2 port

There is already an examples examples/rp2 directory with some examples for the rp2 port (using PIO), so I agree putting something there and referencing it from the docs would be the best outcome.

I think it would be OK to merge this now and add a more detailed DMA example later, though (maybe at the same time can remove the longer example from the .rst) - depending on Nick's schedule.

EDIT: Especially as I just noted this PR is approaching its third birthday later this year! 🙀

Signed-off-by: Nicko van Someren <nicko@nicko.org>
@dpgeorge dpgeorge merged commit 77f08b7 into micropython:master Mar 19, 2024
@dpgeorge
Copy link
Member

Now merged. Thanks @nickovs for writing this up, it's always hard doing the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants