STM32F7 8 Direct memory access controller (DMA)

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

Previous topic - Next topic

tha

8.3.10 Double-buffer mode

โหมดนี้มีให้ใช้งานสำหรับทุก the DMA1 and DMA2 streams.

The double-buffer mode ถูกเปิดใช้งานโดยการเซ็ต the DBM bit ใน the DMA_SxCR register.

A double-buffer stream ทำงานเหมือนกับ a regular (single buffer) stream ที่มีความแตกต่างกันที่มันมี two memory pointers. เมื่อ the double-buffer mode ถูกเปิดใช้งาน, the circular mode จะถูกเปิดใช้งานโดยอัตโนมัติ (CIRC bit ใน DMA_SxCR ไม่เกี่ยวข้อง) และที่แต่ละ end of transaction, the memory pointers จะถูกสลับ.

ในโหมดนี้, the DMA controller สลับจาก one memory เป้าหมายไปยังอีกตัวหนึ่งที่แต่ละ end of transaction. นี้ช่วยให้ the software ประมวลผล one memory area ในขณะที่ the second memory area กำลังถูกเติม/ถูกใช้โดย the DMA transfer. The double-buffer stream สามารถทำงานในทั้งสอง directions (the memory สามารถเป็น the source หรือ the destination อย่างใดอย่างหนึ่ง) ดังที่อธิบายใน Table 28: Source and destination address registers in double-buffer mode (DBM = 1).

tha

Note:  ใน double-buffer mode, เป็นไปได้ที่จะอัปเดต the base address สำหรับ the AHB memory port กลางอากาศ
          (DMA_SxM0AR or DMA_SxM1AR) เมื่อ the stream ถูกเปิดใช้งาน, โดยเคารพเงื่อนไขดังต่อไปนี้:
          •   เมื่อ the CT bit เป็น '0' ใน the DMA_SxCR register, the DMA_SxM1AR register สามารถถูกเขียน. การพยายามที่จะ
               เขียนไปยัง register นี้ในขณะที่ CT = '1' จะเซ็ต an error flag (TEIF) และ the stream จะถูกปิดใช้งานโดยอัตโนมัติ.
          •   เมื่อ the CT bit เป็น '1' ใน the DMA_SxCR register, the DMA_SxM0AR register สามารถถูกเขียน. การพยายามที่จะ
               เขียนไปยัง register นี้ในขณะที่ CT = '0' จะเซ็ต an error flag (TEIF) และ the stream จะถูกปิดใช้งานโดยอัตโนมัติ.

          เพื่อหลีกเลี่ยง error condition ใดๆ, ขอแนะนำให้เปลี่ยน the base address ทันทีที่ the TCIF flag ถูกยืนยันเนื่องจาก, ที่จุดนี้,
          the targeted memory ต้องเปลี่ยนจาก memory 0 ไปเป็น 1 (หรือจาก 1 ไปเป็น 0) ขึ้นอยู่กับค่าของ CT ใน the
          DMA_SxCR register สอดคล้องกันกับข้อใดข้อหนึ่งในสองเงื่อนไขข้างบน.

          สำหรับโหมดอื่นๆ ทั้งหมด (ยกเว้น the double-buffer mode), the memory address registers ถูกป้องกันการเขียนทันทีที่
          the stream ถูกเปิดใช้งาน.



tha

8.3.11 Programmable data width, packing/unpacking, endianness

จำนวนของ data items ที่จะถูกส่งถ่ายต้องถูกโปรแกรมลงใน DMA_SxNDTR (number of data items to transfer bit, NDT) ก่อนการเปิดใช้งาน the stream (ยกเว้นเมื่อ the flow controller เป็น the peripheral, PFCTRL bit ใน DMA_SxCR ถูกเซ็ต).

เมื่อใช้ the internal FIFO, the data widths ของ the source and destination data สามารถโปรแกรมได้ผ่านทาง the PSIZE and MSIZE bits ใน the DMA_SxCR register (สามารถเป็น 8-, 16- or 32-bit).

เมื่อ PSIZE and MSIZE ไม่เท่ากัน:
•   The data width ของจำนวนของ data items ที่จะส่งถ่าย, ที่กำหนดค่าใน the DMA_SxNDTR register จะเท่ากับความกว้างของ
     the peripheral bus (ที่กำหนดค่าโดย the PSIZE bits ใน the DMA_SxCR register). ตัวอย่างเช่น, ในกรณีของ peripheral-
     to-memory, memory-to-peripheral หรือ memory-to-memory transfers และถ้า the PSIZE[1:0] bits ถูกกำหนดค่า
     สำหรับ half-word, จำนวนของ bytes ที่จะถูกส่งถ่ายจะเท่ากับ 2 × NDT.
•   The DMA controller จะจัดการเฉพาะกับ little-endian addressing เท่านั้นสำหรับทั้งต้นทางและปลายทาง. สิ่งนี้ถูกอธิบายใน Table
     29: Packing/unpacking and endian behavior (bit PINC = MINC = 1).

packing/unpacking procedure นี้อาจมีความเสี่ยงของ data corruption เมื่อ the operation ถูกอินเตอ์รัพท์ก่อนที่ the data จะถูก packed/unpacked เสร็จสมบูรณ์. ดังนั้น, เพื่อให้แน่ใจว่า data ติดต่อกัน, the stream อาจถูกกำหนดค่าเพื่อสร้าง burst transfers: ในกรณีนี้, แต่ละ group of transfers เป้นของ a burst ที่จะแบ่งแยกไม่ได้ (ดูที่ Section 8.3.12: Single and burst transfers).

ใน direct mode (DMDIS = 0 ใน the DMA_SxFCR register), the packing/unpacking ของ data ไม่สามารถทำได้. ในกรณีนี้, ไม่อนุญาตให้มีความแตกต่าง source and destination transfer data widths: ทั้งคู่เท่ากันและถูกกำหนดโดย the PSIZE bits ใน the DMA_SxCR register. MSIZE bits ไม่เกี่ยวข้อง.



Note: Peripheral port อาจเป็น the source หรือ the destination (มันยังสามารถเป็น the memory source ในกรณีของ
           memory-to-memory transfer ได้อีกด้วย).


PSIZE, MSIZE and NDT[15:0] ต้องถูกกำหนดค่า ดังนั้นเพื่อให้แน่ใจว่า the last transfer จะไม่ไม่เสร็จสมบูรณ์. สิ่งนี้สามารถเกิดขึ้นเมื่อ the data width ของ the peripheral port (PSIZE bits) ต่ำกว่า the data width ของ the memory port (MSIZE bits). ข้อจำกัดนี้ถูกสรุปรวมใน Table 30.



tha

8.3.12 Single and burst transfers

The DMA controller สามารถสร้าง single transfers หรือ incremental burst transfers ของ 4, 8 or 16 beats.

ขนาดของการส่งเป็นชุดอย่างรวดเร็วถูกกำหนดค่าโดย software อย่างอิสระสำหรับ the two AHB ports โดยการใช้ the MBURST[1:0] and PBURST[1:0] bits ใน the DMA_SxCR register.

The burst size แสดงให้เห็นจำนวนของ beats ใน the burst, ไม่ใช่จำนวนของ bytes ที่ถูกส่งถ่าย.

เพื่อให้แน่ใจว่า data ติดต่อกัน, แต่ละ group of transfers ที่ฟอร์มเป็น a burst จะแบ่งแยกไม่ได้: AHB transfers ถูกล็อคและ the arbiter of the AHB bus matrix ไม่ได้ทำให้ the DMA master เสื่อมเสียในระหว่าง the sequence of the burst transfer.

ขึ้นอยู่กับ the single หรือ burst configuration, แต่ละ DMA request เริ่มต้นจำนวนที่แตกต่างกันของ transfers บน the AHB peripheral port:
•   เมื่อ the AHB peripheral port ถูกกำหนดค่าสำหรับ single transfers, แต่ละh DMA request จะสร้าง a data transfer ของ a
     byte, half-word or word ขึ้นอยู่กับ the PSIZE[1:0] bits ใน the DMA_SxCR register
•   เมื่อ the AHB peripheral port ถูกกำหนดค่าสำหรับ burst transfers, แต่ละ DMA request จะสร้าง 4,8 or 16 beats ของ
     byte, half word or word transfers ขึ้นอยู่กับ the PBURST[1:0] and PSIZE[1:0] bits ใน the DMA_SxCR register.

ต้องพิจารณาเช่นเดียวกับข้างต้นสำหรับ the AHB memory port โดยพิจารณาจาก the MBURST and MSIZE bits.

ใน direct mode, the stream สามารถสร้างเฉพาะ single transfers และ the MBURST[1:0] and PBURST[1:0] bits จะถูกบังคับโดย hardware.

The address pointers (DMA_SxPAR or DMA_SxM0AR registers) ต้องถูกเลือกดังนั้นเพื่อให้แน่ใจว่าทุก transfers ภายใน a burst block ถูกวางแนวบน the address boundary เท่ากันกับ the size of the transfer.

The burst configuration ต้องถูกเลือกเพื่อปฏิบัติตาม the AHB protocol, โดยที่ bursts ต้องไม่ข้าม the 1 Kbyte address boundary เพราะว่า the minimum address space ที่สามารถถูกจัดสรรให้กับ a single slave คือ 1 Kbyte. นี้หมายความว่า the 1 Kbyte address boundary ต้องไม่ถูกข้ามโดย a burst block transfer, มิฉะนั้น an AHB error จะถูกสร้าง, ที่ไม่ถูกรายงานโดย the DMA registers.

tha

8.3.13 FIFO

FIFO structure

The FIFO ถูกใช้เพื่อเก็บ data ที่มาจากต้นทางไว้ชั่วคราวก่อนที่จะส่งพวกมันไปยังปลายทาง.

แต่ละ stream มี an independent 4-word FIFO และ the threshold level ที่สามารถกำหนดค่าได้ทางซอฟท์แวร์ระหว่าง 1/4, 1/2, 3/4 or full.

เพื่อเปิดใช้งานการใช้ของ the FIFO threshold level, the direct mode ต้องถูกปิดใช้งานโดยการเซ็ต the DMDIS bit ใน the DMA_SxFCR register.

โครงสร้างของ the FIFO แตกต่างกันขึ้นอยู่กับ the source and destination data widths, และถูกอธิบายใน Figure 28: FIFO structure.


tha

FIFO threshold and burst configuration

ความระมัดระวังถูกต้องการเมื่อเลือก the FIFO threshold (bits FTH[1:0] ของ the DMA_SxFCR register) และขนาดของ the memory burst (MBURST[1:0] of the DMA_SxCR register): The content ที่ชี้โดย the FIFO threshold ต้องเท่ากันกับจำนวนเต็มของ memory burst transfers จริงๆ.  หากไม่เป็นเช่นนั้น, a FIFO error (flag FEIFx of the DMA_HISR or DMA_LISR register) จะถูกสร้างเมื่อ the stream ถูกเปิดใช้งาน, จากนั้น the stream จะถูกปิดใช้งานโดยอัตโนมัติ. The allowed and forbidden configurations ถูกอธิบายใน Table 31. The forbidden configurations ถูกเน้นเป็นสีเทาในตาราง.




ในทุกกรณี, the burst size ถูกคุณโดย the data size ต้องไม่เกิน the FIFO size (data size สามารถเป็น: 1 (byte), 2 (half-word) or 4 (word)).

Incomplete burst transfer ที่ the end of a DMA transfer อาจเกิดขึ้นถ้าหนึ่งของเงื่อนไขต่อไปนี้เกิดขึ้น
•   สำหรับ the AHB peripheral port configuration: จำนวนทั้งหมดของ data items (ที่เซ็ตใน the DMA_SxNDTR register) ไม่
     เป็นผลคูณของ the burst size ที่คูณด้วย the data size.
•   สำหรับ the AHB memory port configuration: จำนวนของ remaining data items ใน the FIFO ที่จะถูกส่งถ่ายไปยัง the
     memory ไม่เป็นผลคูณของ the burst size ที่คูณด้วย the data size.

ในกรณีเช่นนี้, the remaining data ที่จะถูกส่งถ่ายจะถูกจัดการใน single mode โดย the DMA, ถึงแม้ว่า a burst transaction ถูกร้องขอในระหว่าง the DMA stream configuration.

Note: เมื่อ burst transfers ถูกร้องขอบน the peripheral AHB port และ the FIFO ถูกใช้ (DMDIS = 1 ใน the DMA_SxCR
         register), จำเป็นต้องปฏิบัติตามกฎต่อไปนี้เพื่อหลีกเลี่ยง permanent underrun or overrun conditions, ขึ้นอยุ่กับ the DMA
         stream direction:
         ถ้า (PBURST × PSIZE) = FIFO_SIZE (4 words), FIFO_Threshold = 3/4 ถูกห้ามด้วย PSIZE = 1, 2 or 4 and
         PBURST = 4, 8 or 16.
         กฎนี้ทำให้แน่ใจว่า enough FIFO space ในแต่ละครั้งถูกปล่อยฟรีเพื่อให้บริการ the request จาก the peripheral.

tha

FIFO flush

The FIFO สามารถถูกล้างเมื่อ the stream ถูกปิดใช้งานโดยการรีเซ็ต the EN bit ใน the DMA_SxCR register และเมื่อ the stream ถูกกำหนดค่าเพื่อจัดการ peripheral-to-memory หรือ memory-to-memory transfers. ถ้าบาง data ยังคงปรากฎอยู่ใน the FIFO เมื่อ the stream ถูกปิดใช้งาน, the DMA controller จะส่งถ่าย the remaining data อย่างต่อเนื่องไปยัง the destination (แม้ว่า stream จะถูกปิดใช้งานเป็นผลแล้วก็ตาม). เมื่อการล้างนี้เสร็จสมบูรณ์, the transfer complete status bit (TCIFx) ใน the DMA_LISR or DMA_HISR register จะถูกเซ็ต.

The remaining data counter DMA_SxNDTR จะเก็บค่าในกรณีนี้เพื่อแสดงให้เห็นว่า data items จำนวนเท่าใดในขณะนี้มีให้ใช้งานใน the destination memory.

โปรดทราบว่าในระหว่าง the FIFO flush operation, ถ้าจำนวนของ remaining data items ใน the FIFO ที่จะถูกส่งถ่ายไปยัง memory (in bytes) น้อยกว่า the memory data width (ตัวอย่างเช่น 2 bytes ใน FIFO ในขณะที่ MSIZE ถูกกำหนดค่าเป็น word), data จะถูกส่งด้วย the data width ที่เซ็ตใน the MSIZE bit ใน the DMA_SxCR register. นี้หมายความว่า memory จะถูกเขียนด้วยค่าที่ไม่ต้องการ. The software อาจอ่าน the DMA_SxNDTR register เพื่อตัดสิน the memory area ที่บรรจุ the good data (start address and last address).

ถ้าจำนวนของ remaining data items ใน the FIFO ต่ำกว่า a burst size (ถ้า the MBURST bits ใน DMA_SxCR register ถูกเซ็ตเพื่อกำหนดค่า the stream เพื่อจัดการ burst บน the AHB memory port), single transactions จะถูกสร้างเพื่อเสร็จสมบูรณ์ the FIFO flush.

tha

Direct mode

โดยค่าเริ่มต้น, the FIFO จะทำงานใน direct mode (DMDIS bit ใน the DMA_SxFCR ถูกรีเว็ต) และ the FIFO threshold level ไม่ถูกใช้. โหมดนี้ประโยชนืเมื่อ the system ต้องการ an immediate and single transfer ไปยังหรือจาก the memory หลังจากแต่ละ DMA request.

เมื่อ the DMA ถูกกำหนดค่าใน direct mode (FIFO ถูกปิดใช้งาน), เพื่อส่งถ่าย data ใน memory-to-peripheral mode, the DMA จะโหลดก่อน one data จาก the memory ไปยัง the internal FIFO เพื่อให้แน่ใจว่า an immediate data transfer ทันทีที่ a DMA request ถูกทริกโดย a peripheral.

เพื่อหลีกเลี่ยงการอิ่มตัว the FIFO, ขอแนะนำให้กำหนดค่า the corresponding stream ด้วย a high priority.

โหมดนี้ถูกจำกัดการส่งถ่ายโดยที่:
•   the source and destination transfer widths เท่ากันและทั้งคู่ถูกกำหนดโดย the PSIZE[1:0] bits ใน DMA_SxCR
     (MSIZE[1:0] bits ไม่เกี่ยวข้อง)
•   burst transfers ไม่สามารถทำได้ (PBURST[1:0] and MBURST[1:0] bits ใน DMA_SxCR ไม่ต้องสนใจ)

Direct mode ต้องไม่ถูกใช้เมื่อจัดให้มีใช้ memory-to-memory transfers.