STM32F1 USB

Started by tha, April 01, 2021, 07:19:59 AM

Previous topic - Next topic

tha

ในขณะที่เปิดการใช้งาน the last data stage, the opposite direction ควรถูกเซ็ตเพื่อ NAK, ดังนั้น, ถ้า the host กลับ the transfer direction (เพื่อกระทำ the status stage) ในทันที, มันจะรอสำหรับ the completion of the control operation. ถ้า the control operation เสร็จสมบูรณ์เรียบร้อยแล้ว, the software จะเปลี่ยน NAK เป็น VALID, หรือเป็น STALL. ในเวลาเดียวกัน, ถ้า the status stage จะเป็น an OUT, the STATUS_OUT (EP_KIND ใน the USB_EPnR register) bit ควรถูกเซ็ต, ดังนั้น an error ถูกสร้างขึ้นถ้า a status transaction ถูกดำเนินการด้วย not-zero data. เมื่อ the status transaction ถูกบริการ, the application เคลียร์ the STATUS_OUT bit และเซ็ต STAT_RX เป็น VALID (เพื่อรับ a new command) และ STAT_TX เป็น NAK (เพื่อหน่วงเวลา a possible status stage ทันทีหลังจาก(ติดตาม) the next setup).

tha

เนื่องจาก the USB specification ระบุว่า a SETUP packet ไม่สามารถถูกตอบด้วย a handshake ที่ต่างจาก ACK, ในที่สุดก็ยกเลิก a previously issued command เพื่อเริ่มคำสั่งใหม่, the USB logic ไม่ยอมให้ a control endpoint ตอบด้วย a NAK หรือ STALL packet ไปยัง a SETUP token ที่รับจาก the host.

tha

เมื่อ the STAT_RX bits ถูกเซ็ตเป็น '01 (STALL) หรือ '10 (NAK) และ a SETUP token ถูกรับ, the USB ยอมรับ the data, ดำเนินการ the required data transfers และส่งกลับ an ACK handshake. ถ้า endpoint นั้นมี a previously issued CTR_RX request ยังไม่ถูก acknowledged โดย the application (เช่น CTR_RX bit ยังคงถูกเซ็ตจาก a previously completed reception), the USB จะละทิ้ง the SETUP transaction และไม่ตอบด้วย handshake packet ใดๆโดยไม่คำนึงถึงสถานะของมัน, จำลอง a reception error และบังคับ the host ให้ส่ง the SETUP token อีกครั้ง. นี้ถูกทำเพื่อหลีกเลี่ยงการสูญเสียการแจ้งเตือนของ a SETUP transaction ที่ส่งถึง the same endpoint ทันทีหลังจาก the transaction, ซึ่งทริก the CTR_RX interrupt.


tha

23.4.3 Double-buffered endpoints

ทุก different endpoint types ถูกกำหนดโดย the USB standard แสดง different traffic models, และอธิบายความต้องการทั่วไปของประเภทต่างๆของ data transfer operations. เมื่อ data ส่วนที่ใหญ่จะถูกส่งถ่ายระหว่าง the host PC และ the USB function, the bulk endpoint type เป็นรูปแบบที่เหมาะสมที่สุด. นี้ก็เนื่องจาก the host จัดตารางเวลา bulk transactions เพื่อให้เป็นการเติมเต็มทุก the available bandwidth ใน the frame, ทำให้สูงสุด the actual transfer rate ตราบเท่าที่ the USB function พร้อมที่จะจัดการ a bulk transaction ที่ส่งถึงมัน. ถ้า the USB function ยังคงยุ่งอยู่กับ the previous transaction เมื่อ the next one มาถึง, มันจะตอบด้วย a NAK handshake และ the host PC จะปล่อยออก the same transaction อีกครั้งจนกว่า the USB function จะพร้อมจัดการมัน, การลด the actual transfer rate เนื่องจาก the bandwidth ถูกครอบครองโดย re-transmissions. ด้วยเหตุนี้, คุณลักษณะเฉพาะที่เรียกว่า 'double-buffering' สามารถถูกใช้กับ bulk endpoints.

เมื่อ 'double-buffering' ถูกทำให้ทำงาน, data toggle sequencing ถูกใช้เพื่อเลือก, ซึ่ง buffer ใดที่จะถูกใช้โดย the USB peripheral เพื่อดำเนินการ the required data transfers, โดยใช้ทั้ง 'transmission' and 'reception' packet memory areas เพื่อจัดการ buffer swapping บนแต่ละ successful transaction เพื่อให้มี a complete buffer ที่จะถูกใช้โดย the application เสมอ, ในขณะที่ the USB peripheral เติมอีกอันหนึ่ง. ตัวอย่างเช่น, ในระหว่าง an OUT transaction ที่มุ่งไปยัง a 'reception' double-buffered bulk endpoint, ในขณะที่ one buffer กำลังถูกเติมด้วย new data ที่มาจาก the USB host, อีกบัฟเฟอร์หนึ่งมีให้ใช้สำหรับ the microcontroller software usage ((เช่นเดียวกันจะเกิดขึ้นกับ a 'transmission' double buffered bulk endpoint และ an IN transaction).

tha

เนื่องจาก the swapped buffer management ต้องการการใช้งานของ all four buffer description table locations ที่เป็นเจ้าของ the address pointer และความยาวของ the allocated memory buffers, the USB_EPnR registers ถูกใช้เพื่อจัดให้มีใช้ double-buffered bulk endpoints ถูกบังคับเพื่อจะถูกใช้เป็น unidirectional ตัวหนึ่ง. ดังนั้น, STAT bit เพียงคู่เดียวต้องถูกเซ็ตที่ค่าที่แตกต่างจาก '00 (Disabled): STAT_RX ถ้า the double-buffered bulk endpoint ถูกเปิดการใช้งานสำหรับ reception, STAT_TX ถ้า the double-buffered bulk endpoint ถูกเปิดการใช้งานสำหรับ transmission. ในกรณีจำเป็นต้องมี double-buffered bulk endpoints ถูกเปิดใช้งานทั้งสำหรับ reception และ transmission, two USB_EPnR registers ต้องถูกใช้.

เพื่อใช้ประโยชน์ the double-buffering feature และให้ถึง the highest possible transfer rate, the endpoint flow control structure, ที่อธิบายในบทก่อนหน้า, ต้องถูกแก้ไข, เพื่อสวิทช์ the endpoint status เป็น NAK เฉพาะเมื่อ a buffer conflict เกิดขึ้นระหว่าง the USB peripheral และ application software, แทนที่จะทำมันที่จุดสิ้นสุดของแต่ละ successful transaction. The memory buffer ซึ่งกำลังถูกใช้ในปัจจุบันโดย the USB peripheral ถูกกำหนดโดย the DTOG bit ที่เกี่ยวพันกับ the endpoint direction: DTOG_RX (bit 14 of USB_EPnR register) สำหรับ 'reception' double-buffered bulk endpoints หรือ DTOG_TX (bit 6 of USB_EPnR register) สำหรับ 'transmission' double-buffered bulk endpoints. เพื่อจัดให้มีใช้ the new flow control scheme, the USB peripheral ควรรู้ซึ่ง packet buffer กำลังถูกใช้ในปัจจุบันโดย the application software, ดังนั้นเพื่อให้ทราบถึงความขัดแย้งใด ๆ. เนื่องจากใน the USB_EPnR register, มีสอง DTOG bits แต่เฉพาะหนึ่งเดียวถูกใช้โดย USB peripheral สำหรับ data and buffer sequencing (เนื่องจาก the unidirectional constraint ที่ต้องการโดย double-buffering feature) อีกบิตหนึ่งสามารถถูกใช้โดย the application software เพื่อแสดงซึ่ง buffer ที่มันกำลังใช้ในปัจจุบัน. buffer flag ใหม่นี้เรียกว่า SW_BUF. ในตารางต่อไปนี้ความสัมพันธ์ระหว่าง USB_EPnR register bits และ DTOG/SW_BUF definition ถูกอธิบาย, สำหรับกรณีของ 'transmission' and 'reception' double-buffered bulk endpoints.


tha

The memory buffer ซึ่งกำลังถูกใช้ในปัจจุบันโดย the USB peripheral ถูกกำหนดโดย DTOG buffer flag, ในขณะที่ the buffer ปัจจุบันอยู่ในการใช้โดย application software ถูกระบุโดย SW_BUF buffer flag. ความสัมพันธ์ระหว่าง the buffer flag value และ the used packet buffer เป็นเหมือนกันในทั้งสองกรณี, และถูกแสดงรายการในตารางต่อไปนี้.



Double-buffering feature สำหรับ a bulk endpoint ถูกทำให้ทำงานโดย:
• เขียน EP_TYPE bit field ที่ '00 ใน USB_EPnR register ของมัน, เพื่อกำหนด the endpoint เป็น a bulk, และ
• เซ็ต EP_KIND bit ที่ '1 (DBL_BUF), ใน the same register.

tha

The application software รับผิดชอบสำหรับ DTOG and SW_BUF bits initialization สอดคล้องกับ the first buffer ที่จะถูกใช้; นี้ต้องกระทำโดยพิจารณา the special toggle-only property ที่สองบิตเหล่านี้มี. The end of the first transaction เกิดขึ้นหลังจากมีการเซ็ต DBL_BUF, ทริก the special flow control of double-buffered bulk endpoints, ซึ่งถูกใช้สำหรับ transactions อื่นทั้งหมดที่ส่งไปยัง endpoint นี้จนกว่า DBL_BUF ยังคงเซ็ต. ที่จุดสิ้นสุดของแต่ละ transaction the CTR_RX or CTR_TX bit ของ the addressed endpoint USB_EPnR register ถูกเซ็ต, ขึ้นอยู่กับ the enabled direction. ในเวลาเดียวกัน, the affected DTOG bit ใน the USB_EPnR register ถูกสลับทางฮาร์ดแวร์ทำให้ the USB peripheral buffer swapping โดย software เป็นอิสรอย่างสมบูรณ์. ไม่เหมือน transactions ปกติธรรมดา, และ transaction แรกหลังจากการเซ็ต DBL_BUF, คู่ STAT bit ไม่ได้รับผลกระทบโดย the transaction termination และค่าของมันยังคง '11 (Valid). อย่างไรก็ตาม, เมื่อ the token packet of a new transaction ถูกรับ, the actual endpoint status จะถูกบังเป็น '10 (NAK) เมื่อ a buffer ขัดแย้งกันระหว่าง the USB peripheral และ the application software ถูกตรวจพบ (เงื่อนไขนี้ถูกระบุโดย DTOG and SW_BUF มีค่าเดียวกัน, ดู Table 170). The application software ตอบสนองต่อ the CTR event notification โดยการเคลียร์ the interrupt flag และเริ่มการจัดการที่จำเป็นใดๆของ the completed transaction. เมื่อ the application packet buffer usage สิ้นสุดลง, the software สลับ the SW_BUF bit, เขียน '1 ไปยังมัน, เพื่อแจ้งให้ทราบ the USB peripheral เกี่ยวกับการพร้อมให้ใช้งานของ buffer นั้น. ด้วยวิธีนี้, จำนวนของ NAK-ed transactions ถูกจำกัดเฉพาะโดย the application elaboration time ของ a transaction data: ถ้า the elaboration time สั้นกว่าเวลาที่ต้องการเสร็จสมบูรณ์ a transaction บน the USB bus, ไม่มี re-transmissions เนื่องจาก flow control จะเกิดขึ้นและ the actual transfer rate จะถูดจำกัดเฉพาะโดย the host PC.

The application software สามารถข้าม the special flow control ที่จัดให้มีใช้สำหรับ double-buffered bulk endpoints เสมอ, โดยเขียน an explicit status แตกต่างจาก '11 (Valid) ลงใน the STAT bit pair ของ the related USB_EPnR register. ในกรณีนี้, the USB peripheral จะใช้ the programmed endpoint status เสมอ, โดยไม่คำนึงถึง the buffer usage condition.

tha

23.4.4 Isochronous transfers

The USB standard รองรับ full speed peripherals ที่ต้องการ a fixed and accurate data production/consume frequency, ซึ่งกำหนดประเภทนี้ของการรับส่งข้อมูลว่า  'Isochronous'. ตามแบบฉบับตัวอย่างของ data นี้ ได้แก่ : audio samples, compressed video streams, และโดยทั่วไปประเภทของข้อมูลตัวอย่างที่มีข้อกำหนดที่เข้มงวดสำหรับความถูกต้องของความถี่ในการจัดส่ง. เมื่อ an endpoint ถูกกำหนดให้เป็น 'isochronous' ในระหว่าง the enumeration phase, the host จัดสรรแบนด์วิดท์ที่ต้องการใน the frame และส่งจริงๆหนึ่ง IN หรือ OUT packet แต่ละ frame, ขึ้นอยู่กับ endpoint direction. เพื่อจำกัด the bandwidth requirements, ไม่มีการส่งซ้ำของ transactions ที่ล้มเหลวสามารถทำได้สำหรับ Isochronous traffic; นี้นำมาซึ่งความจริงที่ว่า an isochronous transaction ไม่มี a handshake phase และไม่มี ACK packet ถูกคาดหวังหรือส่งหลังจาก the data packet. ด้วยเหตุผลเดียวกัน, Isochronous transfers จะไม่รองรับ data toggle sequencing และใช้ DATA0 PID เสมอเพื่อเริ่ม data packet ใดๆ.

The Isochronous behavior สำหรับ an endpoint ถูกเลือกโดยการเซ็ต the EP_TYPE bits ที่ '10 ใน USB_EPnR register ของมัน; เนื่องจากไม่มี handshake phase ค่าที่ชอบด้วยกฎหมายเฉพาะสำหรับ the STAT_RX/STAT_TX bit pairs เป็น '00 (Disabled) และ '11 (Valid), ค่าอื่นใดๆจะจะสร้างผลลัพธ์ที่ไม่เป็นไปตาม USB standard. Isochronous endpoints จัดให้มีใช้ double-buffering เพื่อให้ง่าย application software development, โดยใช้ทั้ง 'transmission' and 'reception' packet memory areas เพื่อจัดการ buffer swapping บนแต่ละ successful transaction เพื่อห้มี a complete buffer เสมอที่จะถูกใช้โดย the application, ในขณะที่ the USB peripheral เติม buffer อื่น.

The memory buffer ซึ่งถูกใช้ในปัจจุบันโดย the USB peripheral ถูกกำหนดโดย the DTOG bit เกี่ยวพันกับ the endpoint direction (DTOG_RX สำหรับ 'reception' isochronous endpoints, DTOG_TX สำหรับ 'transmission' isochronous endpoints, ทั้งสองใน the related USB_EPnR register) สอดคล้องกับ Table 171.