STM32F1 DMA

Started by tha, September 24, 2020, 07:28:27 AM

Previous topic - Next topic

tha

ท่านใดเรียกร้องให้เอา DMA ก่อน เอาไว้ย้ายดาต้า ADC หลายชาแนลใช่มั๊ย เดี๋ยวมาลองดูกัน

13 Direct memory access controller (DMA)

13.1 DMA introduction
Direct memory access (DMA) ถูกใช้เพื่อจัดให้มี high-speed data transfer ระหว่าง peripherals และ memory ตลอดจน memory กับ memory ด้วยกัน. Data สามารถถูกเคลื่อนย้ายอย่างรวดเร็วโดย DMA โดยไม่มีการทำงานของ CPU ใดๆเลย. นี้ทำให้ CPU resources ว่างเพื่อทำงานอย่างอื่น.

DMA controllers 2 ตัวมีทั้งหมด 12 channels (7 for DMA1 and 5 for DMA2), แต่ละตัวถูกมอบหมายให้จัดการกับ memory access requests(การร้องขอเพื่อเข้าถึง memory) จาก peripherals หนึ่งหรือหลายตัว. มันมีตัวตัดสินเพื่อที่จะจัดการ priority (ระดับความสำคัญ) ระหว่าง DMA requests เหล่านี้.

tha

13.2 DMA main features(คุณลักษณะหลักของ DMA)
   • มี 12 ชาแนลที่กำหนดค่าได้อย่างอิสระ (การร้องขอ): 7 สำหรับ DMA1 และ 5 สำหรับ DMA2
   • แต่ละชาแนลของ the 12 channels ถูกต่อถึง hardware DMA requests เฉพาะตัวไป, software trigger ยัง support ในแต่ละ
     channel อีกด้วย. การกำหนดนี้ทำได้โดยทาง software.
   • Priorities(ระดับความสำคัญ) ระหว่าง requests(การร้องขอ) เหล่านี้ จาก channels เหล่านี้ของ DMA ตัวหนึ่งสามารถโปรแกรมได้ทาง
     software (มี 4 ระดับประกอบด้วย of very high, high, medium, low) หรือทาง hardware ในกรณีที่ระดับความสำคัญมันเท่ากัน
     (request 1 มีระดับความสำคัญที่สูงกว่า request 2, etc.)
   • กำหนดขนาดของต้นทางและปลายทางของการเคลื่อนย้ายได้อย่างอิสระ (byte, half word, word), เลียนแบบ packing และ
     unpacking. Source/destination addresses ต้องถูกวางแนวตาม the data size.
   • รองรับสำหรับ circular buffer management
   • มี 3 event flags (DMA Half Transfer, DMA Transfer complete และ DMA Transfer Error)
     logically ORed ออร์เข้าด้วยกันใน interrupt request เดียวสำหรับแต่ละ channel
   • Memory-to-memory transfer
   • Peripheral-to-memory และ memory-to-peripheral, และ peripheral-to-peripheral
     transfers
   • เข้าถึง Flash, SRAM, APB1, APB2 and AHB peripherals ได้เป็นทั้งต้นทางและปลายทาง( source and destination)
   • จำนวณที่โปรแกรมได้ของ data ที่ถูกเคลื่อนย้าย: มีมากถึง 65536
The block diagram ถูกแสดงใน Figure 48.


tha

13.3 DMA functional description
The DMA controller ทำการ direct memory transfer โดยใช้ the system bus ร่วมกันกับ the Cortex®-M3 core. The DMA request(การร้องขอ DMA) อาจหยุด the CPU เข้าถึง the system bus เป็นจำนวนบาง bus cycles, เมื่อ the CPU และ DMA กำลังมีเป้าหมายปลายทางเดียวกัน (memory or peripheral). The bus matrix ดำเนินการ round-robin scheduling, ดังนั้นเพื่อให้แน่ใจว่าอย่างน้อยครึ่งหนึ่งของ the system bus bandwidth (รวมทั้งถึง memory and peripheral) สำหรับ the CPU.


tha

13.3.1 DMA transactions
หลังจากจบเหตุการณ์หนึ่ง(event), the peripheral ส่ง request signal ไปยัง the DMA Controller. The DMA controller บริการการร้องขอนั้นโดยขึ้นอยู่กับ the channel priorities ของมัน. ทันทีที่ the DMA Controller เข้าถึง the peripheral, an Acknowledge ถูกส่งถึง the peripheral โดย the DMA Controller. The peripheral จะปล่อยการร้องขอของมันทันทีที่มันได้รับ the Acknowledge จาก the DMA Controller. เมื่อการร้องขอนั้นถอนการถือสิทธิ์โดย the peripheral, the DMA Controller ก็จะปล่อย the Acknowledge. หากมีการร้องขอมากกว่าหนึ่ง, the peripheral สามารถเริ่ม the next  transaction.

tha

โดยสรุป, แต่ละ DMA transfer ประกอบด้วยการทำงาน ๓ ประการดังนี้ :
   • การโหลด data จาก the peripheral data register หรือตำแหน่งใน memory addressed ผ่านทาง an internal current
     peripheral/memory address register. The start address ที่ใช้สำหรับ the first transfer คือ the base
     peripheral/memory address ที่ถูกโปรแกรมใน the DMA_CPARx or DMA_CMARx register
   • data ที่จัดเก็บถูกโหลดไปยัง the peripheral data register หรือตำแหน่งใน memory addressed ผ่านทาง an internal
     current peripheral/memory address register. The start address ที่ใช้สำหรับ the first transfer คือ the base
     peripheral/memory address ที่ถูกโปรแกรมใน the DMA_CPARx or DMA_CMARx register
   • The post-decrementing(การลดลงภายหลัง)ของ the DMA_CNDTRx register, ซึ่งบรรจุจำนวนของ transactions ที่ยังคงต้อง
     ถูกกระทำการ transfer ต่อ.

ปล. งงมั๊ย DMA ส่วนมากก็ใช้โหลด data จาก peripheral data register ไปยัง RAM โดยตรง โดยที่ไม่ใช้ CPU มาทำ ให้ CPU ทำงานอื่นไป หรือ data จาก RAM ไปยัง peripheral ก็ได้ ได้หลายอย่างนะ ต้องแปลกันต่อไปก่อนครับ

tha


moneyp1000

ขอบคุณครับ

tha

13.3.2 Arbiter(ตัวตัดสิน)
The arbiter จัดการ the channel requests ขึ้นอยู่กับ priority ของมันและเริ่ม the peripheral/memory access sequences.
The priorities ถูกจัดการในสองขั้นตอน :
   • Software: แต่ละ channel priority สามารถถูกกำหนดค่าใน the DMA_CCRx register. มี 4 ระดับด้วยกัน:
     – Very high priority
     – High priority
     – Medium priority
     – Low priority
   • Hardware: ถ้า 2 requests มี the same software priority level, the channel ที่มี the lowest number จะมี priority สูง
      กว่าเมื่อเทียบกับ the channel ที่มี the highest number. ตัวอย่างเช่นe, channel 2 จะมี priority สูงกว่า channel 4.

Note: ใน high-density, XL-density and connectivity line devices, the DMA1 controller มี priority สูงกว่า the DMA2 controller.