Raspberry Pi Picoã®PIOãDMAã¯1ã¯ããã¯ãã¨ã«å¦çãå¯è½ã§ããï¼125MHzãªãç§é1å2500ä¸åï¼ããã¼ã¿ãDMAã§PIOã«éãç¶ããå ´åã«autopullã»PIOããDMAã¸ã®DREQï¼ãã¼ã¿ãªã¯ã¨ã¹ãï¼ã»DMAãã£ã³ãã«éã®chain triggerçã®ä½¿ç¨æã§ãå¾ ã¡æéãªãã«ãã¼ã¿è»¢éããç¶ããã®ã ããããã¨ããçåã湧ããã®ã§ç¢ºèªãã¦ã¿ã¾ããã
ç°å¢ã¯Windows 11ã¨VS CodeãPlatformIOã§earlephilhowerçArduinoã³ã¢ï¼Raspberry Pi Pico/RP2040ï¼ã使ç¨ãã¦ã¾ããRaspberry Pi Pico C/C++ SDKã§ãã ãããåãã ã¨æãã¾ããearlephilhowerçãC/C++ SDKããã¼ã¹ã«ä½ããã¦ããã®ã§ã
Â
- PIOã®pullãautopullã«ä»»ããå ´åãTX FIFOâautopullã§osrã¸âosrããoutãã§è»¢éå¾ ã¡ã¯çºçããã®ã
- DMAãã£ã³ãã«éã®chain trigger使ç¨æã¯ããããã®DMA転éãåãç®ãªãç¶ãã®ã
- ãã®ä»ã®è»¢ééå§æ¹æ³ã試ãã¦ã¿ã
- ã½ã¼ã¹ã³ã¼ã
Â
Â
PIOã®pullãautopullã«ä»»ããå ´åãTX FIFOâautopullã§osrã¸âosrããoutãã§è»¢éå¾ ã¡ã¯çºçããã®ã
DMAã§TX FIFOã«æ¯ã¯ããã¯ãã¼ã¿ãå
¥ãã¤ã¤ãPIOã®ã¹ãã¼ããã·ã³ã§ã¯pullã¯autopullã«ä»»ãã¦æ¯ã¯ããã¯outãããã¨ããå ´åãautopullå¾
ã¡ã1ã¯ããã¯çºçãããããã®ã ããããã¨ããçåã
DMAã§ã0,1,2,3,0・・・ãã¨0ãã3ã§ã«ã¼ããã32bitãã¼ã¿ãæ¯ã¯ããã¯TX FIFOã«éãç¶ããautopullããout pins, 32ãã¦æ¯ã¯ããã¯32bitãGPIOã¸åºåãã¦çµæã確èªãã¦ã¿ã¾ãã
åºåçµæã¯ããï¼ã¿ã¤ãã³ã°å³ã§è¡¨è¨ãã¦ã¾ããå³æ¹åãæéçµéã1ãã¹ã1ã¯ããã¯ï¼ã
1ã¯ããã¯ã«1ã¤ãã¤ãã¼ã¿ãåºåããã¦ãã¾ããautopullå¾ ã¡ãªã©ãçºçãã¦ããªãããã§ãã
Â
ã§ã¯ãDMA転éã«channel_config_set_dreqã§DREQ_PIOn_TXnãè¨å®ãã¦ãTX FIFOã空ã«ãªã£ãæã«PIOããDREQãæ¥ã¦DMA転éããããã«ããå ´åã«ãTX FIFOã®ç©ºã確èªâDREQâDMA転éãã§ã©ããã§å¾ ã¡æéã¯çºçããªãã ãããã
å ç¨ã®ãã¹ãã«channel_config_set_dreqã追å ãã¦æ¤è¨¼ã
ãã¡ããå¾ ã¡æéã¯çºçãã¦ããªãããã§ãããããªãPIOã®pullãããã¼ã¹ãå¯å¤ã§ãDMAã«è»¢éãä»»ãããããã§ãããå¾ ã¡æéãçºçãã¦ãã¼ã¿è»¢éãã¼ã¹ãè½ã¡ãã¨ããäºæ ã«ãªããªãã
Â
以ä¸ã¯ã32bit outãããautopullããæ¯ã¯ããã¯32bitãout pinsãï¼ãæ¯ã¯ããã¯autopullãããçµæã§ããããããã8bit outãããautopullããæ¯ã¯ããã¯8bitãout pinsãï¼ãæ¯ã¯ããã¯autopullãã¨ããè¨å®ã«å¤æ´ãã¦è©¦ãã¦ã¿ã¾ãï¼æå¾ã«è¼ãã¦ããã½ã¼ã¹ãå½åãã£ã¡ã®è¨å®ã«ãªã£ã¦ããããä»ã¯32bitã«ä¿®æ£ãã¦ããã¾ãï¼ã
DREQå¾
ã¡ç¡ãã®å ´åã¯å
¨é¨1ã¯ããã¯ã§å¾
ã¡ã¯çºçãã¾ããã§ããããDREQã使ã£ãå ´åã¯ããã
3ã®æã ã3ã¯ããã¯ã«ãªã£ã¦ã¾ããã«ã¼ãããæã«é ããã¨ãããã¨ã§ãããï¼ã¨ãããã¨ã§0ï½3ã®ã«ã¼ãã§ã¯ãªã0ï½16ã®ã«ã¼ãã«ãã¦ç¢ºèªã
ã«ã¼ãç®æé¢ä¿ãªã4åã«1å3ã¯ããã¯ã«å¢ãã¦ã¾ããã4åã«1åautopullã§ã¯ãªããæ¯ã¯ããã¯autopullãã¦ãã®ã«ãã®4åã«1åã£ã¦ãªãã§ããããï¼ããã2ã¯ããã¯å¢ãã¦ãã1ã¯ããã¯ã§ã¯ãªãã
16bitã«ããã32bitã¨åãçµæã2bitã«ããã8bitã¨åãçµæã«ãªãã¾ããã32bitã®1/4ã®8bitã ãã4åã«1åã¨ããããã§ããªããããã
Â
DMAãã£ã³ãã«éã®chain trigger使ç¨æã¯ããããã®DMA転éãåãç®ãªãç¶ãã®ã
picoã§ã¯1ã¤ã®DMAãã£ã³ãã«ã®è»¢éçµäºæã«å¥ã®DMAãã£ã³ãã«ã®è»¢éãéå§ãããã¨ãããDMAãã£ã³ãã«ã®é£é(chain trigger)è¨å®ãå¯è½ã§ã(channel_config_set_chain_toé¢æ°)ã
ãã®æã«è»¢éçµäºã¨è»¢ééå§ã®éã«è»¢éãã¦ãªãæéãçºçãã¦ãªãããã確èªãã¦ã¿ã¾ãã
2ã¤ã®DMAãã£ã³ãã«ã«ã0,1,2,3ãã®4ã¤ã®ãã¼ã¿ã転éããã¨ããè¨å®ããã¦ï¼æåã®ãã¹ãã¨åããæ¯ã¯ããã¯32bit autopullããè¨å®ï¼ã転éçµäºæã«ããä¸æ¹ã®ãã£ã³ãã«ã®è»¢éãéå§ããè¨å®ããã¦ããã¾ããããããçæ¹ã®DMAãã£ã³ãã«ã転ééå§ãããã¨ã§DMA転éãçµãããç¶ãããã«ãªãã¾ãã
ããã§åãç®ãªã転éã§ãã¦ããã©ããã
ãããã3ãã1ã¯ããã¯ã§çµããã4ã¯ããã¯ç¶ãã¦ã¾ãããPIOãã3ããout pinsããå¾ãã¼ã¿ãæ¥ãªãã®ã§å¾
æ©ãã¦ãæéã3ã¯ããã¯ããï¼
転éãã£ã±ãªãã§ã¯ãªãDMAãPIOããã®DREQãåãä»ããå ´åã¯ã©ãã§ãããããchannel_config_set_dreqã§DREQ_PIOn_TXnãè¨å®ãã¦ã¿ã¾ãã
æ´ã«ã3ãã®æéã伸ã³ã¾ããã6ã¯ããã¯ç¶ãã¦ãã¾ãã
ã¦ã£ããåãç®ãªã転éãç¶ãã®ãã¨æã£ããã§ããããã§ããªãã£ã½ãã§ããã¹ãã¼ããã·ã³ããæ¯ã¯ããã¯pullããå ´åã¯ãã®ãã¨ãèæ
®ããæ¹ãããå ´åãããããããã¾ããã
Â
ãã®ä»ã®è»¢ééå§æ¹æ³ã試ãã¦ã¿ã
転éçµäºæåã³è»¢ééå§ãããå ´åã«ããããæ¹æ³ã¨ãã¦ã転éçµäºæã«å²ãè¾¼ã¿ãçºçããããIRQãè¨å®ãå²ãè¾¼ã¿ã§å¼ã°ããé¢æ°å ã§è»¢ééå§å¦çããããã¨ããã®ãããã¾ãããã¡ãã試ãã¦ã¿ã¾ãã
転éãããã¼ã¿ã¯ããã¾ã§ã¨åãè¨å®ã§ã転éçµäºæã®å²ãè¾¼ã¿é¢æ°å ã§DMAã®INTSnã¬ã¸ã¹ã¿ï¼å²ãè¾¼ã¿ã¹ãã¼ã¿ã¹ã¬ã¸ã¹ã¿ï¼ã®ããããã¯ãªã¢ããdma_channel_transfer_from_buffer_nowé¢æ°ã§èªã¿è¾¼ã¿ã¢ãã¬ã¹ã¨è»¢éåæ°ãè¨å®ãã¦è»¢éãéå§ãããã¨ããæ¡ä»¶ã§è©¦ãã¦ã¿ã¾ãã
ãã¿ã¾ããããå³ã«ããæ¹ããããããããã£ããã
è¨èã§èª¬æããã¨ãã3ãã®ç¶æ
ã44ï½48ã¯ããã¯ç¶ãã¾ãããç¶ãé·ãã¯åºå®ã§ã¯ãªãå¤åãã£ã±ãªãã§ããããã¯ãã¥ã¢ã«ã³ã¢ã®2ã³ã¢ç®ã®å ´åã®çµæã§ã1ã³ã¢ç®ã ã¨æ´ã«ãã©ã¤ãã¾ãã
dma_channel_transfer_from_buffer_nowã¯èªã¿è¾¼ã¿ã¢ãã¬ã¹ã¨è»¢éåæ°ãã¬ã¸ã¹ã¿ã«ä»£å ¥ããé¢æ°ã§ãããä»£å ¥ã転éåæ°ã ãã«ããã¨4ã¯ããã¯ç¸®ãã§40ï½44ã¯ããã¯ã«ãªãã¾ããã
ä»ã®æ段ã¨æ¯ã¹ãã¨40ã¯ããã¯ä»¥ä¸ã£ã¦ã®ã¯é·ãã§ããâ¦ã¾ãCPUã¯ããããä»äºãããã¾ãããå²ãè¾¼ã¿çµäºå¾ã®åç¶å¾©å¸°ã®ããã®æºåããªããä»ã®å¦çæ¢ãã¦å²ãè¾¼ãã®ã§ä»æ¹ãªãã®ã§ããâ¦ã
Â
RP2040 Datasheetã®"2.5.6. Example Use Cases"å
ã®"2.5.6.2. DMA Control Blocks"ã§ã¯ãã¬ã¸ã¹ã¿ã®æ´æ°ã«CPUã使ããDMAã§ã¬ã¸ã¹ã¿æ´æ°ï¼è»¢ééå§ããã¨ããææ³ãç´¹ä»ããã¦ãã¾ããå½ããã°ã®Picoã«ããNTSCã®ã³ã³ãã¸ããæ åä¿¡å·ã¢ãã¯ãåºåã§ã使ç¨ãã¦ã¦ããã£ã¡ã®è¨äºã§è§£èª¬ãã¦ã¾ãã
ãã®æ¹æ³ã«ã¤ãã¦ãã¿ã¤ãã³ã°ã確èªãã¦ã¿ã¾ãã
ã3ãã®ç¶æ ã8ã¯ããã¯ç¶ãã¦ãã¾ããchain triggerã ãã®æã¯4ã¯ããã¯ã§ããããããã«channel trigger registerã¸ã®æ¸ãè¾¼ã¿ï¼è»¢ééå§ã¾ã§ã®æéãå ããæ´ã«4ã¯ããã¯å¢ãã¦ãã¾ããããã§ãCPUã§ããããã¯æç¶æ©ãã§ãããç¹°ãè¿ãã¦ã8ã¯ããã¯ããã»ã¨ãã©å¤åãã¾ãããã
Â
ã½ã¼ã¹ã³ã¼ã
æå¾ã«ä»åã®ãã¹ãã®ã½ã¼ã¹ã³ã¼ãããtest.pioã¯PIOASMã§test.pio.hãçæããå¿ è¦ãããã¾ãã
Arduinoéçºç°å¢åãã«æ¸ããã½ã¼ã¹ã§ããpicoã®C/C++ SDKã§ã¯åä½ç¢ºèªãã¦ãã¾ãããmain.cppãC/C++ SDKã§åããå ´åã¯#include <arduino.h>ã¨loop()é¢æ°ã®è¨è¿°ãæ¶ãã¦void setup()ãint main()ã«ããå¿ è¦ãããã¾ãã
Arduinoã§ã®PIOASMã®ä½¿ç¨ãC/C++ SDKã¨ã®éãã¯ãã¡ãã®ãã¼ã¸ãåèã«ãã¾ããã
Â
Â
main.cpp
test.pio
Â