Electoday 2025

ไมโครคอนโทรลเลอร์ => ARM Processors => Topic started by: tha on September 24, 2020, 07:28:27 AM

Title: STM32F1 DMA
Post by: tha on September 24, 2020, 07:28:27 AM
ท่านใดเรียกร้องให้เอา 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 เหล่านี้.
Title: Re: STM32F1 DMA
Post by: tha on September 24, 2020, 08:47:53 AM
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.

(https://i.imgur.com/oYCS2XQ.png)
Title: Re: STM32F1 DMA
Post by: tha on October 01, 2020, 07:23:00 AM
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.
Title: Re: STM32F1 DMA
Post by: tha on October 01, 2020, 07:43:35 AM
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.
Title: Re: STM32F1 DMA
Post by: tha on October 01, 2020, 03:58:19 PM
โดยสรุป, แต่ละ 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 ก็ได้ ได้หลายอย่างนะ ต้องแปลกันต่อไปก่อนครับ
Title: Re: STM32F1 DMA
Post by: tha on October 01, 2020, 04:23:53 PM
-
Title: Re: STM32F1 DMA
Post by: moneyp1000 on October 02, 2020, 12:40:54 AM
ขอบคุณครับ
Title: Re: STM32F1 DMA
Post by: tha on October 02, 2020, 07:40:07 AM
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.
Title: Re: STM32F1 DMA
Post by: tha on October 02, 2020, 08:09:16 AM
13.3.3 DMA channels
แต่ละ channel สามารถจัดการ DMA transfer ระหว่าง a peripheral register ที่มีตำแหน่งอยู่ที่ address ที่คงที่ และ a memory address. จำนวนของ data ที่ถูก transferred (มากถึง 65535) สามารถโปรแกรมได้. The register ซึ่งบรรจุจำนวนรายการ data ที่จะถูก transferred ถูกลดลงหลังจาก transaction แต่ละครั้ง
Title: Re: STM32F1 DMA
Post by: tha on October 02, 2020, 08:35:07 AM
Programmable data sizes
Transfer data sizes ของ the peripheral และ memory สามารถโปรแกรมได้อย่างเต็มที่ผ่าน the PSIZE และ MSIZE bits ใน the DMA_CCRx register.
Title: Re: STM32F1 DMA
Post by: tha on October 03, 2020, 07:37:36 AM
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.
Title: Re: STM32F1 DMA
Post by: tha on October 03, 2020, 09:01:38 AM
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) ถูกเซ็ต.
Title: Re: STM32F1 DMA
Post by: tha on October 04, 2020, 06:54:01 AM
Circular mode
Circular mode มีให้ใช้งานเพื่อจัดการ circular buffers (บัฟเฟอร์หลายตัวหมุนวน)และการไหลของ data อย่างต่อเนื่อง (ตัวอย่างเช่น ADC scan mode). คุณลักษณะนี้สามารถถูกเปิดการใช้งานโดยใช้ the CIRC bit ใน the DMA_CCRx register. เมื่อ circular mode ถูกทำให้ทำงาน, จำนวนของ data ที่ถูก transferred จะถูกโหลดซ้ำใหม่โดยอัตโนมัติด้วยค่าเริ่มต้นที่โปรแกรมไว้ในระหว่างขั้นตอนการกำหนดค่าชาแนล, และ the DMA requests ถูกบริการต่อไป.
Title: Re: STM32F1 DMA
Post by: tha on October 04, 2020, 07:39:34 AM
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.

ปล. นึกคำเข็ดตึงฟันอยู่เหมือนกัน คงจะได้ไปวันละนิดละหน่อย
Title: Re: STM32F1 DMA
Post by: tha on October 04, 2020, 01:35:48 PM
13.3.4 Programmable data width, data alignment and endians
เมื่อ PSIZE และ MSIZE ไม่เท่ากัน, the DMA จะดำเนินการจัดแนว data ดังอธิบายในตารางที่ 76.

(https://i.imgur.com/px1V9zo.png)

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".
Title: Re: STM32F1 DMA
Post by: tha on October 05, 2020, 07:40:15 AM
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 ถูกเซ็ต
Title: Re: STM32F1 DMA
Post by: tha on October 05, 2020, 08:15:19 AM
13.3.6 Interrupts
An interrupt สามารถถูกผลิตเมื่อ a Half-transfer, Transfer complete หรือ Transfer error สำหรับแต่ละ DMA channel. มี interrupt enable bits ให้ใช้งานแยกกันต่างหากสำหรับความ flexibility.

(https://i.imgur.com/lRtVIFf.png)

Note: ใน high-density และ XL-density devices, DMA2 Channel4 และ DMA2 Channel5 interrupts ถูก mapped ลงบน the same interrupt vector. ใน connectivity line devices, DMA2 Channel4 และ DMA2 Channel5 interrupts มี interrupt vectors แยกกันต่างหาก. ส่วน DMA1 และ DMA2 Channel interrupts อื่นทั้งหมด จะมี interrupt vector เป็นของมันเอง.
Title: Re: STM32F1 DMA
Post by: tha on October 05, 2020, 08:47:27 AM
13.3.7 DMA request mapping
DMA1 controller
The 7 requests(การร้องขอ) จาก the peripherals (TIMx[1,2,3,4], ADC1, SPI1, SPI/I2S2, I2Cx[1,2] และ USARTx[1,2,3]) ถูกออร์(OR)เข้าด้วยกันง่ายๆก่อนเข้าสู่ the DMA1, นี้หมายความว่ามีการร้องขอหนึ่งเดียวเท่านั้นที่ต้องถูกเปิดใช้งานในเวลาหนึ่งๆ.อ้างอิงถึงรูปที่ 50.

The peripheral DMA requests สามารถถูกทำให้ทำงาน/ทำให้ไม่ทำงาน โดยการโปรแกรม the DMA control bit ใน the registers เหล่านั้นของ the corresponding peripheral.

(https://i.imgur.com/xDE1fsl.png)

(https://i.imgur.com/PwDyUkf.png)

ปล. ก็ลองไล่ดูเอาว่าชาแนลไหนรับการร้องขอจาก peripheral ไหนได้บ้าง เช้านี้พอแค่นี้ก่อนครับ
Title: Re: STM32F1 DMA
Post by: tha on October 05, 2020, 12:19:40 PM
DMA2 controller
The five requests จาก the peripherals (TIMx[5,6,7,8], ADC3, SPI/I2S3, UART4, DAC_Channel[1,2] and SDIO) ถูกออร์(OR)เข้าด้วยกันง่ายๆก่อนเข้าสู่ the DMA2, นี้หมายความว่ามีการร้องขอหนึ่งเดียวเท่านั้นที่ต้องถูกเปิดใช้งานในเวลาหนึ่งๆ.อ้างอิงถึงรูปที่ 51.

The peripheral DMA requests สามารถถูกทำให้ทำงาน/ทำให้ไม่ทำงาน โดยการโปรแกรม the DMA control bit ใน the registers เหล่านั้นของ the corresponding peripheral.


Note: The DMA2 controller และการร้องขอที่สัมพันธ์กันของมันมีให้ใช้งานใน high-density, XL-density และ connectivity line devices เท่านั้น.

(https://i.imgur.com/LJfS3uO.png)
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 07:26:29 AM
13.4 DMA registers
อ้างถึง Section 2.2 บนหน้า 45 สำหรับรายการย่อที่ใช้ใน register descriptions.

Note: ใน registers ต่อไปนี้, บิตทั้งหมดที่เกี่ยวข้องกับ channel6 และ channel7 ไม่เกี่ยวข้องกับ DMA2 เนื่องจากมันมีเพียง 5 channels.

The peripheral registers สามารถถูกเข้าถึงโดย bytes (8-bit), half-words (16-bit) or words (32-bit).

(https://i.imgur.com/rglf3DC.png)

      Bits 31:28 สงวนไว้, ต้องถูกเก็บไว้ที่ reset value.
      Bits 27, 23, 19, 15,  TEIFx: Channel x transfer error flag (x = 1 ..7)
                     11, 7, 3   บิตนี้ถูกเซ็ตโดย hardware. เคลียร์โดย software โดยการเขียน 1 ไปยังบิตที่ตรงกันใน the
                                    DMA_IFCR register.
                                    0: ไม่มี transfer error (TE) บน channel x
                                    1 : A transfer error (TE) เกิดขึ้นบน channel x
     Bits 26, 22, 18, 14, HTIFx: Channel x half transfer flag (x = 1 ..7)
                     10, 6, 2  บิตนี้ถูกเซ็ตโดย hardware. เคลียร์โดย software โดยการเขียน 1 ไปยังบิตที่ตรงกันใน the
                                   DMA_IFCR register.
                                   0: ไม่มี half transfer (HT) event บน channel x
                                   1: A half transfer (HT) event เกิดขึ้นบน channel x
     Bits 25, 21, 17, 13, TCIFx: Channel x transfer complete flag (x = 1 ..7)
                      9, 5, 1   บิตนี้ถูกเซ็ตโดย hardware. เคลียร์โดย software โดยการเขียน 1 ไปยังบิตที่ตรงกันใน the
                                   DMA_IFCR register.
                                   0: ไม่มี transfer complete (TC) event บน channel x
                                   1: A transfer complete (TC) event เกิดขึ้นบน channel x
     Bits 24, 20, 16, 12, GIFx: Channel x global interrupt flag (x = 1 ..7)
                      8, 4, 0   บิตนี้ถูกเซ็ตโดย hardware. เคลียร์โดย software โดยการเขียน 1 ไปยังบิตที่ตรงกันใน the
                                   DMA_IFCR register.
                                   0: ไม่มี TE, HT or TC event บน channel x
                                   1: A TE, HT or TC event เกิดขึ้นบน channel x
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 07:48:44 AM
(https://i.imgur.com/90m3Qpv.png)

     Bits 31:28 สงวนไว้, ต้องถูกเก็บไว้ที่ reset value.
     Bits 27, 23, 19, 15, CTEIFx: Channel x transfer error clear (x = 1 ..7)
                    11, 7, 3   บิตนี้ถูกเซ็ตและเคลียร์โดย software.
                                  0: ไม่มีผลอะไร
                                  1: เคลียร์ the corresponding TEIF flag ใน the DMA_ISR register
     Bits 26, 22, 18, 14, CHTIFx: Channel x half transfer clear (x = 1 ..7)
                    10, 6, 2   บิตนี้ถูกเซ็ตและเคลียร์โดย software.
                                  0: ไม่มีผลอะไร
                                  1: เคลียร์ the corresponding HTIF flag ใน the DMA_ISR register
     Bits 25, 21, 17, 13, CTCIFx: Channel x transfer complete clear (x = 1 ..7)
                      9, 5, 1   บิตนี้ถูกเซ็ตและเคลียร์โดย software.
                                   0: ไม่มีผลอะไร
                                   1: เคลียร์ the corresponding TCIF flag ใน the DMA_ISR register
     Bits 24, 20, 16, 12, CGIFx: Channel x global interrupt clear (x = 1 ..7)
                      8, 4, 0   บิตนี้ถูกเซ็ตและเคลียร์โดย software.
                                   0: ไม่มีผลอะไร
                                   1: เคลียร์ the GIF, TEIF, HTIF and TCIF flags ใน the DMA_ISR register

ปล. อันนี้ต้องมีการเคลียร์แฟลค เมื่อแฟลคมันเซ็ตแล้ว แต่อยู่คนละรีจีสเตอร์กัน ไม่ยากใช่มั๊ย
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 08:53:57 AM
(https://i.imgur.com/WPGk8Td.png)

     Bits 31:15 สงวนไว้, ต้องถูกเก็บไว้ที่ reset value.
     Bit 14 MEM2MEM: Memory to memory mode
              บิตนี้ถูกเซ็ตและเคลียร์โดย software.
              0: ปิดการใช้งาน Memory to memory mode
              1: เปิดการใช้งาน Memory to memory mode
     Bits 13:12 PL[1:0]: Channel priority level
              บิตนี้ถูกเซ็ตและเคลียร์โดย software.
              00: Low
              01: Medium
              10: High
              11: Very high
     Bits 11:10 MSIZE[1:0]: Memory size
              บิตนี้ถูกเซ็ตและเคลียร์โดย software.
              00: 8-bits
              01: 16-bits
              10: 32-bits
              11: สงวนไว้
     Bits 9:8 PSIZE[1:0]: Peripheral size
              บิตนี้ถูกเซ็ตและเคลียร์โดย software.
              00: 8-bits
              01: 16-bits
              10: 32-bits
              11: Reserved
     Bit 7 MINC: Memory increment mode
              บิตนี้ถูกเซ็ตและเคลียร์โดย software.
              0: ปิดการใช้งาน Memory increment mode
              1: เปิดการใช้งาน Memory increment mode
     Bit 6 PINC: Peripheral increment mode
               บิตนี้ถูกเซ็ตและเคลียร์โดย software.
              0: ปิดการใช้งาน Peripheral increment mode
              1: เปิดการใช้งาน Peripheral increment mode
     Bit 5 CIRC: Circular mode
              บิตนี้ถูกเซ็ตและเคลียร์โดย software.
              0: ปิดการใช้งาน Circular mode
              1: เปิดการใช้งาน Circular mode
     Bit 4 DIR: Data transfer direction
               บิตนี้ถูกเซ็ตและเคลียร์โดย software.
               0: อ่านจาก peripheral
               1: อ่านจาก memory
     Bit 3 TEIE: Transfer error interrupt enable
                บิตนี้ถูกเซ็ตและเคลียร์โดย software.
                0: ปิดการใช้งาน TE interrupt
                1: เปิดการใช้งาน TE interrupt
     Bit 2 HTIE: Half transfer interrupt enable
                บิตนี้ถูกเซ็ตและเคลียร์โดย software.
                0: ปิดการใช้งาน HT interrupt
                1: เปิดการใช้งาน HT interrupt
     Bit 1 TCIE: Transfer complete interrupt enable
               บิตนี้ถูกเซ็ตและเคลียร์โดย software.
               0: ปิดการใช้งาน TC interrupt
               1: เปิดการใช้งาน TC interrupt
     Bit 0 EN: Channel enable
               บิตนี้ถูกเซ็ตและเคลียร์โดย software.
               0: ปิดการใช้งาน Channel
               1: เปิดการใช้งาน Channel
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 12:09:52 PM
(https://i.imgur.com/ObyaLgl.png)

     Bits 31:16 สงวนไว้, ต้องถูกเก็บไว้ที่ reset value.
     Bits 15:0 NDT[15:0]: Number of data to transfer
                   จำนวนของ data ที่ถูก transferred (0 ไปถึง 65535). register นี้สามารถถูกเขียนเมื่อ the channel นี้ถูกปิดการใช้
                   งาน. เมื่อ the channel นี้เปิดการใช้งานแล้ว, register นี้อ่านได้เพียงอย่างเดียว, แสดงจำนวน bytes ที่ยังเหลืออยู่ที่จะถูก
                   transmitted. register ลดลงหลังจากแต่ละ DMA transfer. เมื่อ the transfer นี้เสร็จสมบูรณ์, register นี้สามารถที่จะ
                   อยู่ที่ศูนย์หรือจะโหลดซ้ำใหม่โดยอัตโนมัติโดยค่าก่อนหน้าที่โปรแกรมเอาไว้ ถ้า the channel นี้ถูกกำหนดค่าใน autoreload
                   mode.
                   ถ้า register นี้เป็นศูนย์, ไม่มี transaction ใดสามารถให้บริการได้ไม่ว่า the channel ถูกเปิดการใช้งานหรือไม่ก็ตาม.
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 12:21:32 PM
(https://i.imgur.com/9cyJj4D.png)

      Bits 31:0 PA[31:0]: Peripheral address
                        แอดเดรสฐานของ the peripheral data register จาก/ถึง ซึ่ง the data จะถูกอ่าน/เขียน.
                        เมื่อ PSIZE เป็น 01 (16-bit), the PA[0] bit จะถูกละเลย. การเข้าถึงถูกวางแนวอย่างอัตโนมัติเป็น a halfword
                        address.
                        เมื่อ PSIZE เป็น 10 (32-bit), PA[1:0] จะถูกละเลย. การเข้าถึงถูกวางแนวอย่างอัตโนมัติเป็น a word address.
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 12:26:26 PM
(https://i.imgur.com/wUB0etK.png)

Bits 31:0 MA[31:0]: Memory address
                        แอดเดรสฐานของ the memory area จาก/ถึง ซึ่ง the data จะถูกอ่าน/เขียน.
                        เมื่อ MSIZE เป็น 01 (16-bit), the MA[0] bit จะถูกละเลย. การเข้าถึงถูกวางแนวอย่างอัตโนมัติเป็น a halfword
                        address.
                        เมื่อ MSIZE เป็น 10 (32-bit), MA[1:0] จะถูกละเลย. การเข้าถึงถูกวางแนวอย่างอัตโนมัติเป็น a word address.
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 12:34:35 PM
(https://i.imgur.com/I5b4ju7.png)

(https://i.imgur.com/hV4u8B2.png)

(https://i.imgur.com/5UKNxix.png)

ปล. เสร็จแล้ว เดี๋ยวจะไปไล่ ADC ต่ออีกหน่อยนะ แล้วจะได้ทำตัวอย่างกัน
Title: Re: STM32F1 DMA
Post by: tha on October 06, 2020, 06:02:50 PM
ตกลงให้ปฏิบัติด้วยนะ เคร ตามนั้น เดี๋ยวถ้าทำโปรแกรมไม่ได้ ก็จะอัผโหลดมาให้ช่วยกันทำนะครับ