STM32F1 DMA

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

Previous topic - Next topic

tha

13.3.3 DMA channels
แต่ละ channel สามารถจัดการ DMA transfer ระหว่าง a peripheral register ที่มีตำแหน่งอยู่ที่ address ที่คงที่ และ a memory address. จำนวนของ data ที่ถูก transferred (มากถึง 65535) สามารถโปรแกรมได้. The register ซึ่งบรรจุจำนวนรายการ data ที่จะถูก transferred ถูกลดลงหลังจาก transaction แต่ละครั้ง

tha

Programmable data sizes
Transfer data sizes ของ the peripheral และ memory สามารถโปรแกรมได้อย่างเต็มที่ผ่าน the PSIZE และ MSIZE bits ใน the DMA_CCRx register.

tha

Pointer incrementation
Peripheral และ memory pointers สามารถเลือกได้ให้เพิ่มขึ้นภายหลัง(post-incremented)อย่างอัตโนมัติ หลังจากแต่ละ transaction โดยขึ้นอยู่กับ the PINC and MINC bits ใน the DMA_CCRx register. ถ้า incremented mode ถูกเปิดการใช้งาน, the address ของ the next transfer จะเป็น the address ของอันก่อนหน้านี้โดยเพิ่มทีละ 1, 2 หรือ 4 ขึ้นอยู่กับขนาดของข้อมูลที่เลือก( the chosen data size). The first transfer address คืออันที่โปรแกรมใน the DMA_CPARx/DMA_CMARx registers. ในระหว่าง transfer operations, registers เหล่านี้จะเก็บค่าที่โปรแกรมเริ่มต้นนี้ (the initially programmed value). The current(ปัจจุบัน) transfer addresses(ใน the current internal peripheral/memory address register) ไม่สามารถเข้าถึงได้โดย software.

ถ้า the channel ถูกกำหนดใน noncircular mode, จะไม่มี DMA request ถูกบริการหลังจาก the last transfer (นั่นคือเมื่อจำนวนรายการข้อมูลที่จะถ่ายโอนถึง 0). เพื่อที่จะโหลดซ้ำใหม่จำนวนรายการ data ที่จะ transferred ลงใน the DMA_CNDTRx register, the DMA channel ต้องถูกปิดการใช้งาน

Note: ถ้า a DMA channel ถูกปิดการใช้งาน, the DMA registers จะไม่ถูกรีเซ็ต. The DMA channel registers(DMA_CCRx, DMA_CPARx and DMA_CMARx) เก็บรักษาค่าที่โปรแกรมเริ่มแรกนี้ไว้ในระหว่างช่วงการกำหนดค่าของชาแนล( the channel configuration phase)

ใน circular mode, หลังจาก the last transfer, the DMA_CNDTRx register จะโหลดซ้ำใหม่โดยอัตโนมัติด้วยค่าเริ่มต้นที่โปรแกรมไว้. The current internal address registers ถูกโหลดซ้ำใหม่ด้วย the base address values จาก the DMA_CPARx/DMA_CMARx registers.


tha

Channel configuration procedure
ควรปฏิบัติตามลำดับต่อไปนี้เพื่อกำหนดค่า DMA channelx (เมื่อ x คือ the channel number).
1. เซ็ต the peripheral register address ใน the DMA_CPARx register. The data จะถูกเคลื่ยนย้าย จาก/ ถึง address นี้ ถึง/
    จาก the memory หลังจาก the peripheral event.
2. เซ็ต the memory address ใน the DMA_CMARx register. The data จะถูกเขียนไปยังหรืออ่านจาก memory นี้หลังจาก the
    peripheral event.
3. กำหนดค่าจำนวนทั้งหมดของ data ที่จะถูก transferred ใน the DMA_CNDTRx register. หลังจากแต่ละ peripheral event, ค่านี้
   จะถูกลดลง.
4. กำหนดค่า the channel priority โดยใช้ the PL[1:0] bits ใน the DMA_CCRx register
5. กำหนดค่าe data transfer direction, circular mode, peripheral & memory incremented mode, peripheral &
    memory data size, และ interrupt หลังจาก half และ/หรือ full transfer ใน the DMA_CCRx register
6. ทำให้ the channel ทำงานโดยการเซ็ต the ENABLE bit ใน the DMA_CCRx register.

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

เมื่อครึ่งหนึ่งของ the bytes ถูก transferred, the half-transfer flag (HTIF) ถูกเซ็ตและ an interrupt ถูกทำให้เกิดขึ้นถ้า the Half-Transfer Interrupt Enable bit (HTIE) ถูกเซ็ต. ที่การจบของการ transfer, the Transfer Complete Flag (TCIF) ถูกเซ็ต และ an interrupt ถูกทำให้เกิดขึ้นถ้า the Transfer Complete Interrupt Enable bit (TCIE) ถูกเซ็ต.

tha

Circular mode
Circular mode มีให้ใช้งานเพื่อจัดการ circular buffers (บัฟเฟอร์หลายตัวหมุนวน)และการไหลของ data อย่างต่อเนื่อง (ตัวอย่างเช่น ADC scan mode). คุณลักษณะนี้สามารถถูกเปิดการใช้งานโดยใช้ the CIRC bit ใน the DMA_CCRx register. เมื่อ circular mode ถูกทำให้ทำงาน, จำนวนของ data ที่ถูก transferred จะถูกโหลดซ้ำใหม่โดยอัตโนมัติด้วยค่าเริ่มต้นที่โปรแกรมไว้ในระหว่างขั้นตอนการกำหนดค่าชาแนล, และ the DMA requests ถูกบริการต่อไป.

tha

Memory-to-memory mode
The DMA channels สามารถทำงานโดยปราศจากการทริกโดยการร้องขอ(request)จาก peripheral ได้อีกด้วย. mode นี้ถูกเรียกว่า Memory to Memory mode.

ถ้า the MEM2MEM bit ใน the DMA_CCRx register ถูกเซ็ต, เมื่อนั้น the channel จะเริ่ม transfers ในทันทีที่มันถูกเปิดการใช้งานโดยทาง software โดยการเซ็ต the Enable bit (EN) ใน the DMA_CCRx register. การ transfer หยุดทันทีที่ the DMA_CNDTRx register ลดลงถึง '0'. Memory to Memory mode ไม่สามารถถูกใช้พร้อมกันเป็น(หรือ อย่าง) Circular mode.

ปล. นึกคำเข็ดตึงฟันอยู่เหมือนกัน คงจะได้ไปวันละนิดละหน่อย

tha

13.3.4 Programmable data width, data alignment and endians
เมื่อ PSIZE และ MSIZE ไม่เท่ากัน, the DMA จะดำเนินการจัดแนว data ดังอธิบายในตารางที่ 76.



Addressing an AHB peripheral that does not support byte or halfword write operations(การระบุแอดเดรสของ AHB peripheral ไม่รองรับการทำการเขียนแบบ byte หรือ halfword)
เมื่อ the DMA เริ่มการทำการเขียน an AHB แบบ byte หรือ halfword, the data นี้จะซ้ำไปบนเลนที่ไม่ได้ใช้ของ the HWDATA[31:0] bus. ดังนั้นเมื่อ the used AHB slave peripheral ไม่ได้รองรับการทำการเขียนแบบ byte หรือ halfword (เมื่อ HSIZE ไม่ได้ถูกใช้โดย the peripheral นั้น) และไม่ได้เกิด error ใดๆ, the DMA เขียน the 32 HWDATA bits ดังแสดงในสองตัวอย่างข้างล่างนี้ :

•    ในการเขียน the halfword "0xABCD", the DMA เซ็ต the HWDATA bus เป็น "0xABCDABCD" ด้วย HSIZE = HalfWord
•    ในการเขียน the byte "0xAB", the DMA เซ็ต the HWDATA bus เป็น "0xABABABAB" ด้วย HSIZE = Byte

ทึกทักเอาว่า the AHB/APB bridge(สะพาน) เป็น an AHB 32-bit slave peripheral จะไม่คำนึงถึง the HSIZE data, มันจะแปลง AHB byte หรือ halfword operation ใดๆลงใน a 32-bit APB operation ในลักษณะดังต่อไปนี้:

•    an AHB byte write operation ของ the data "0xB0" ไปยังแอดเดรส 0x0 (หรือไปยังแอดเดรส 0x1, 0x2 or 0x3) จะถูกแปลง
     เป็น an APB word write operation ของ the data "0xB0B0B0B0" ไปยังแอดเดรส 0x0
•    an AHB halfword write operation ของ the data "0xB1B0" ไปยังแอดเดรส 0x0 (หรือไปยัง 0x2) จะถูกแปลงเป็น an APB
     word write operation ของ the data "0xB1B0B1B0" ไปยังแอดเดรส 0x0

ตัวอย่างเช่น, ในการเขียน the APB backup registers (16-bit registers วางแนวไปเป็น a 32-bit address boundary), the memory source size (MSIZE) ต้องถูกกำหนดค่าเป็น "16-bit" และ the peripheral destination size (PSIZE) เป็น "32-bit".

tha

13.3.5 Error management
A DMA transfer errorlสามารถถูกทำให้เกิดขึ้นโดยการอ่านจากหรือเขียนถึง a reserved address space. เมื่อ a DMA transfer error เกิดขึ้นในระหว่าง a DMA read หรือ a write access, the faulty channel จะถูกปิดการใช้งานผ่านทาง a hardware เคลียร์ EN bit ของมันใน the corresponding Channel configuration register (DMA_CCRx). The channel's transfer error interrupt flag
(TEIF) ใน the DMA_IFR register ถูกเซ็ตและ an interrupt ถูกทำให้เกิดขึ้นถ้า the transfer error interrupt enable bit (TEIE) ใน the DMA_CCRx register ถูกเซ็ต