DMA support for Pi Pico rp2 port

树莓派 PICO 和 RP2040 相关应用讨论
帖子: 2994
注册时间: 2019年 10月 21日 13:48

DMA support for Pi Pico rp2 port


帖子 shaoziyang »

rp2 对 DMA 功能支持已加入 pull request 了。
This PR implements fairly complete support for the DMA controller in the rp2 series of microcontrollers. It provides a class for accessing the DMA channels through a high-level, pythonic interface, a class for setting and manipulating the DMA channel configurations and a utility function that makes it easier to implement complex scatter-gather type chained DMA configurations.

Creating an instance of the rp2.DMA class claims one of the processor's DMA channels. A sensible, per-channel default value for the configuration register can be fetched from the default_config attribute and the components of this configuration can be manipulated through its own attributes.

The read, write, count and config attributes provide read/write access to the respective registers of the DMA controller and while the setup() method allows any or all of these values to be set simultaneously and adds a trigger keyword argument to allow the setup to immediately be triggered. The read and write attributes (or keywords in setuo()) accept either actual addresses or any object that supports the buffer interface. The active attribute provides read/write control of the channel's activity, allowing the user to start and stop the channel and test if it is running.

Standard Micropython interrupt handlers are supported through the irq() method and the channel can be released either by deleting it and allowing it to be garbage-collected or with the explicit close() method.

Direct, unfettered access to the DMA controllers registers is provided through a proxy array() object returned by the registers attribute that maps directly onto the memory-mapped registers. This is necessary for more fine-grained control and is helpful for allowing chaining of DMA channels.

A utility function called buffer_address() is also added to the rp2 module that returns the address of the memory buffer underlying any object that supports the buffer interface. This is necessary for building DMA scatter-gather lists. Passing the registers value to this function returns the address of the registers themselves.

I've tried to strike a balance between simplicity and comprehensiveness but I'm sure that others will have suggestions!


  • 随机主题