STM32F7 8 Direct memory access controller (DMA)

Started by tha, September 16, 2022, 09:00:56 AM

Previous topic - Next topic

tha

8.3.14 DMA transfer completion

เหตุการณ์ต่างๆ สามารถสร้าง an end of transfer โดยการเซ็ต the TCIFx bit ใน the DMA_LISR หรือ DMA_HISR status register:
•   ใน DMA flow controller mode:
     –   The DMA_SxNDTR counter ถึงศูนย์ใน the memory-to-peripheral mode.
     –   The stream ถูกปิดใช้งานก่อน the end of transfer (โดยการเคลียร์ the EN bit ใน the DMA_SxCR register) และ (เมื่อ
          transfers คือ peripheral-to-memory หรือ memory-to-memory) ทุก the remaining data จะถูกล้างจาก the FIFO
          ลงใน the memory.
•   ใน Peripheral flow controller mode:
     –   The last external burst หรือ single request ถูกสร้างจาก the peripheral และ (เมื่อ the DMA กำลังทำงานใน
          peripheral-to-memory mode) the remaining data จะถูกส่งถ่ายจาก the FIFO ลงใน the memory
     –   The stream ถูกปิดใช้งานโดย software, และ (เมื่อ the DMA กำลังทำงานใน peripheral-to-memory mode) the
          remaining data จะถูกส่งถ่ายจาก the FIFO ลงใน the memory

Note: The transfer completion ขึ้นอยู่กับ the remaining data ใน FIFO ที่จะถูกส่งถ่ายลงใน memory เฉพาะในกรณีของ
          peripheral-to-memory mode. เงื่อนไขนี้ใช้ไม่ได้ใน memory-to-peripheral mode.


ถ้า the stream ถูกกำหนดค่าใน noncircular mode, หลังจาก the end of the transfer (นั่นคือเมื่อ the number of data ที่จะถูกส่งถ่ายถึงศูนย์), the DMA จะถูกหยุด (EN bit ใน DMA_SxCR register จะถูกเคลียร์โดย Hardware) และไม่มี DMA request ถูกบริการยกเว้น the software จะโปรแกรมใหม่ the stream และเปิดใช้งานมันใหม่ (โดยการเซ็ต the EN bit ใน the DMA_SxCR register).

tha

8.3.15 DMA transfer suspension

เมื่อใดก็ได้, a DMA transfer สามารถถูกระงับค้างไว้เพื่อสตาร์ทใหม่ในภายหลังหรือถูกปิดใช้งานอย่างแน่นอนก่อน the end of the DMA transfer.

มีสองกรณี:
•   The stream ปิดใช้งงาน the transfer โดยไม่มีการรีสตาร์ทในภายหลังจากจุดที่มันเคยหยุด. ไม่มีการดำเนินการเฉพาะที่ต้องทำ, ยกเว้น
     การเคลียร์ the EN bit ใน the DMA_SxCR register เพื่อปิดใช้งาน the stream. The stream อาจใช้เวลาในการถูกปิดใช้งาน
     (transfer ที่กำลังดำเนินอยู่เสร็จสมบูรณ์ก่อน). The transfer complete interrupt flag (TCIF ใน the DMA_LISR or
     DMA_HISR register) จะถูกเซ็ตเพื่อแสดงให้เห็น the end of transfer. ค่าของ the EN bit in DMA_SxCR ขณะนี้เป็น '0' เพื่อ
     ยืนยัน the stream interruption. The DMA_SxNDTR register บรรจุจำนวนของ remaining data items ในตอนที่เมื่อ the
     stream ถูกหยุดดังนั้น the software สามารถวัดว่า data items จำนวนเท่าใดที่ถูกส่งถ่ายแล้วก่อน the stream ถูกอินเตอร์รัพท์.
•   The stream ระงับค้างไว้ the transfer ก่อนจำนวนของ remaining data items ที่จะถูกส่งถ่ายใน the DMA_SxNDTR register
     ถึง 0. จุดมุ่งหมายคือเพื่อรีสตาร์ท the transfer ภายหลังโดยเปิดใช้งานใหม่ the stream. เพื่อรีสตาร์ทจากจุดที่ the transfer ถูกหยุด
     อยู่, the software ต้องอ่าน the DMA_SxNDTR register หลังจากการปิดใช้งาน the stream โดยการเขียน the EN bit ใน
     DMA_SxCR register (และจากนั้นตรวจสอบว่ามันอยู่ที่ '0') เพื่อให้ทราบจำนวนของ data items ที่เก็บรวบรวมแล้ว. จากนั้น
     –   The peripheral and/or memory addresses ต้องถูกอัฟเดตเพื่อที่จะปรับ the address pointers
     –   The SxNDTR register ต้องถูกอัฟเดตด้วยจำนวนที่เหลืออยู่ของ data items ที่จะถูกส่งถ่าย (ค่าที่อ่านเมื่อตอน the stream ถูก
          หยุด)
     –   The stream อาจจากนั้นถูกเปิดใช้งานใหม่เพื่อรีสตาร์ท the transfer จากจุดที่มันถูกหยุด

Note: A transfer complete interrupt flag (TCIF in DMA_LISR or DMA_HISR) ถูกเซ็ตเพื่อแสดงให้เห็น the end of transfer
          เนื่องจาก the stream interruption.

tha

8.3.16 Flow controller

แก่นแท้ที่ควบคุมจำนวนของ data ที่จะถูกส่งถ่ายรู้กันในนาม the flow controller. flow controller นี้ถูกกำหนดค่าอย่างอิสระสำหรับแต่ละ stream โดยใช้ the PFCTRL bit ใน the DMA_SxCR register.

The flow controller สามารรถเป็น:
•   The DMA controller: ในกรณีนี้, จำนวนของ data items ที่จะถูกส่งถ่ายจะถูกโปรแกรมโดย software ลงใน the DMA_SxNDTR
     register ก่อน the DMA stream ถูกเปิดใช้งาน
•   The peripheral source or destination: นี้เป็นกรณีที่จำนวนของ data items ที่จะถูกส่งถ่ายไม่ถูกทราบ. The peripheral แสดง
     ให้เห็นโดย hardware ไปยัง the DMA controller เมื่อ the last data กำลังถูกส่งถ่าย. คุณลักษณะนี้ถูกรองรับเฉพาะสำหรับ
     peripherals ที่สามารถให้สัญญาน the end of the transfer, นั่นคือ: SDMMC1.

เมื่อ the peripheral flow controller ถูกใช้สำหรับ a given stream, ค่าที่เขียนลงใน the DMA_SxNDTR จะไม่มีผลกับ the DMA transfer. ที่จริงแล้ว, ไม่ว่าค่าที่เขียนเป็นอะไร, มันจะถูกบังคับโดย hardware เป็น 0xFFFF ทันทีที่ the stream ถูกเปิดใช้งาน, เพื่อปฏิบัติตามแบบแผนต่อไปนี้:
•   Anticipated stream interruption: EN bit ใน DMA_SxCR register จะถูกรีเซ็ตเป็น 0 โดย the software เพื่อหยุด the
     stream ก่อน the last data hardware signal (single or burst) จะถูกส่งโดย the peripheral. ในกรณีดังกล่าว, the stream
     จะถูก switched off และ the FIFO flush จะถูกทริกในกรณีของ a peripheral-to-memory DMA transfer. The TCIFx flag
     ของ the corresponding stream จะถูกเซ็ตใน the status register เพื่อแสดงให้เห็น the DMA completion. เพื่อทราบจำนวน
     ของ data items ที่ส่งถ่ายในระหว่าง the DMA transfer, อ่าน the DMA_SxNDTR register และใช้สูตรต่อไปนี้:
     –   Number_of_data_transferred = 0xFFFF – DMA_SxNDTR
•   Normal stream interruption เนื่องจากการรับ a last data hardware signal: the stream จะถูกอินเตอร์รัพท์โดยอัตโนมัติเมื่อ
     the peripheral ร้องขอ the last transfer (single or burst) และเมื่อ transfer นี้เสร็ฐสมบูรณ์. the TCIFx flag ของ the
     corresponding stream จะถูกเซ็ตใน the status register เพื่อแสดงให้เห็น the DMA transfer completion. เพื่อทราบจำนวน
     ของ data items ที่ส่งถ่าย, อ่าน the DMA_SxNDTR register และใช้สูตรเดียวกันกับข้างบน:
•   The DMA_SxNDTR register ถึง 0: the TCIFx flag ของ the corresponding stream จะถูกเซ็ตใน the status register เพื่อ
     แสดงให้เห็น the forced DMA transfer completion. The stream ถูก switched off โดยอัตโนมัติแม้ว่า the last data
     hardware signal (single or burst) ยังไม่ได้รับการยืนยัน. The already transferred data จะไม่สูญหาย. นี้หมายความว่า a
     maximum of 65535 data items สามารถถูกจัดการโดย the DMA ใน a single transaction, แม้ใน peripheral flow control
     mode.

Note: เมื่อถูกกำหนดค่าใน memory-to-memory mode, the DMA จะเป็น the flow controller เสมอและ the PFCTRL bit จะถูก
          บังคับเป็น 0 โดย hardware.

          The circular mode ถูกห้ามใน the peripheral flow controller mode.


tha

8.3.18 Stream configuration procedure

ลำดับต่อไปนี้ต้องถูกตามเพื่อกำหนดค่า a DMA stream x (โดยที่ x คือ the stream number):
1.   ถ้า the stream ถูกเปิดใช้งาน, ปิดใช้งานมันโดยการรีเซ็ต the EN bit ใน the DMA_SxCR register, จากนั้นอ่านบิตนี้เพื่อยืนยันว่า
      ไม่มี ongoing stream operation. การเขียนบิตนี้เป็น 0 จะไม่เป็นผลโดยทันทีเนื่องจากมันจริงๆแล้วถูกเขียนเป็น 0 เมื่อทุก the
      current transfers ถูกทำเสร็จ. เมื่อ the EN bit ถูกอ่านเป็น 0, นี้หมายความว่า the stream
      พร้อมที่จะถูกกำหนดค่า. ดังนั้นจำเป็นต้องรอสำหรับ the EN bit ถูกเคลียร์ก่อนการสตาร์ท stream configuration ใดๆ. ทุก the
      stream dedicated bits ที่เซ็ตใน the status register (DMA_LISR and DMA_HISR) จาก the previous data block
      DMA transfer ต้องถูกเคลีย์ก่อน the stream สามารถถูกเปิดใช้งานใหม่.
2.   เซ็ต the peripheral port register address ใน the DMA_SxPAR register. The data ถูกย้าย จาก/ถึง address นี้ ถึง/จาก
      the peripheral port หลังจาก the peripheral event.
3.   เซ็ต the memory address ใน the DMA_SxMA0R register (และใน the DMA_SxMA1R register ในกรณีของ a double-
      buffer mode). The data ถูกเขียนถึงหรือถูกอ่านจาก memory นี้หลังจาก the peripheral event.
4.   กำหนดค่าจำนวนทั้งหมดของ data items ที่จะถูกส่งถ่ายใน the DMA_SxNDTR register. หลังจากแต่ละ peripheral event หรือ
      แต่ละ beat of the burst, ค่านี้จะถูกลดลง.

tha

5.   เลือก the DMA channel (request) โดยใช้ CHSEL[2:0] ใน the DMA_SxCR register.
6.   ถ้า the peripheral ได้รับวัตถุประสงค์ให้เป็น the flow controller และถ้ามันรองรับคุณลักษณะนี้, เซ็ต the PFCTRL bit ใน the
      DMA_SxCR register.
7.   กำหนดค่า the stream priority โดยใช้ the PL[1:0] bits ใน the DMA_SxCR register.
8.   กำหนดค่า the FIFO usage (เปิดใช้งานหรือปิดใช้งาน, ขอบเขตในการส่งและการรับ)
9.   กำหนดค่า the data transfer direction, peripheral and memory incremented/fixed mode, single or burst
      transactions, peripheral and memory data widths, circular mode, double-buffer mode และอินเตอร์รัพท์หลังจาก
      half และ/หรือ full transfer, และ/หรือ errors ใน the DMA_SxCR register
10. ทำให้ the stream ทำงานโดยการเซ็ต the EN bit ใน the DMA_SxCR register.

tha

ทันทีที่ the stream ถูกเปิดใช้งาน, มันสามารถบริการ DMA request ใดๆจาก the peripheral ที่ต่อถึง the stream.

เมื่อครึ่ง the data ถูกส่งถ่ายไปบน the AHB destination port, the half-transfer flag (HTIF) จะถูกเซ็ตและ an interrupt จะถูกสร้างถ้า the half-transfer interrupt enable bit (HTIE) ถูกเซ็ต. ที่ the end of the transfer, the transfer complete flag (TCIF)  จะถูกเซ็ตและ an interrupt จะถูกสร้างถ้า the transfer complete interrupt enable bit (TCIE) ถูกเซ็ต.

คำเตือน: เพื่อปิด a peripheral ที่ต่อถึง a DMA stream request, จำเป็นต้อง, ก่อนอื่น, ปิด the DMA stream ซึ่ง the peripheral   
                ถูกต่อถึง, จากนั้นรอสำหรับ EN bit = 0. เฉพาะจากนั้นจึงสามารถ the peripheral ถูกปิดใช้งานอย่างปลอดภัย.

tha

8.3.19 Error management

The DMA controller สามารถตรวจพบ the following errors:
•   Transfer error: the transfer error interrupt flag (TEIFx) ถูกเซ็ตเมื่อ:
     –   a bus error เกิดขึ้นในระหว่าง a DMA read or a write access
     –   a write access ถูกร้องขอโดย software บน a memory address register ใน double-buffer mode ในขณะที่ the
          stream ถูกเปิดใช้งานและ the current target memory เป็นอันที่ได้รับผลกระทบจากการเขียนลงใน the memory address
          register (ดูที่ Section 8.3.10: Double-buffer mode)
•   FIFO error: the FIFO error interrupt flag (FEIFx) ถูกเซ็ตถ้า:
     –   a FIFO underrun condition ถูกตรวจพบ
     –   a FIFO overrun condition ถูกตรวจพบ (ไม่มีการตรวจพบ detection ใน memory-to-memory mode เนื่องจาก requests
          และ transfers ถูกจัดการภายในโดย the DMA)
     –   the stream ถูกเปิดใช้งานในขณะที่ the FIFO threshold level เข้ากันไม่ได้กับขนาดของ the memory burst (ดูที่ Table
          31: FIFO threshold configurations)
•   Direct mode error: the direct mode error interrupt flag (DMEIFx) สามารถถูกเซ็ตเฉพาะใน the peripheral-to-
     memory mode ในขณะที่ทำงานใน direct mode และเมื่อ the MINC bit ใน the DMA_SxCR register ถูกเคลียร์. flag นี้จะถูก
     เซ็ตเมื่อ a DMA request เกิดขึ้นในขณะที่ the previous data ยังไม่ถูกส่งถ่ายลงใน the memory อย่างสมบูรณ์(เนื่องจาก the
     memory bus ไม่ถูกอนุญาต). ในกรณีนี้, the flag แสดงให้เห็นว่า 2 data items ถูกส่งถ่ายไปยัง the same destination
     address สำเร็จแล้ว, ซึ่งอาจเป็นปัญหาได้ถ้า the destination ไม่สามารถจัดการสถานะการณ์นี้ได้

tha

ใน direct mode, the FIFO error flag สามารถถูกเซ็ตภายใต้เงื่อนไขต่อไปนี้ได้อีกด้วย:
•   ใน the peripheral-to-memory mode, the FIFO สามารถถูกทำให้อิ่มตัวได้ (overrun) ถ้า the memory bus ไม่ถูกอนุญาตให้
     สำหรับ several peripheral requests.
•   ใน the memory-to-peripheral mode, an underrun condition อาจเกิดขึ้นถ้า the memory bus ไม่ถูกอนุญาตให้ก่อน a
     peripheral request เกิดขึ้น.

ถ้า the TEIFx or the FEIFx flag ถูกเซ็ตเนื่องจากความไม่ลงรอยกันระหว่าง burst size และ FIFO threshold level, the faulty stream จะถูกปิดใช้งานโดยอัตโนมัติผ่านทาง a hardware ที่เคลียร์ EN bit ของมันใน the corresponding stream configuration register (DMA_SxCR).

ถ้า the DMEIFx or the FEIFx flag ถูกเซ็ตเนื่องจาก an overrun or underrun condition, the faulty stream จะถูกปิดใช้งานโดยอัตโนมัติและมันขึ้นอยู่กับซอฟต์แวร์ที่จะปิดใช้งานหรือไม่ the stream โดยการรีเซ็ต the EN bit ใน the DMA_SxCR register. นี้เนื่องจากไม่มีการสูญหายของ data เมื่อเกิดข้อผิดพลาดชนิดนี้.

เมื่อ the stream's error interrupt flag (TEIF, FEIF, DMEIF) ใน the DMA_LISR or DMA_HISR register ถูกเซ็ต, an interrupt จะถูกสร้างถ้า the corresponding interrupt enable bit (TEIE, FEIE, DMIE) ใน the DMA_SxCR หรือ DMA_SxFCR register ถูกเซ็ต.

Note: เมื่อ a FIFO overrun or underrun condition เกิดขึ้น, the data จะไม่สูญหายเนื่องจาก the peripheral request ไม่ถูก
          acknowledged โดย the stream จนกว่า the overrun or underrun condition จะถูกเคลียร์. ถ้า acknowledge นี้ใช้เวลา
          มากเกินไป, the peripheral ตัวมันเองอาจตรวจพบ an overrun or underrun condition ของ internal buffer ของมันและ
          data อาจสูญหาย.