Electoday 2025

ไมโครคอนโทรลเลอร์ => ARM Processors => Topic started by: tha on April 01, 2021, 07:19:59 AM

Title: STM32F1 USB
Post by: tha on April 01, 2021, 07:19:59 AM
23 Universal serial bus full-speed device interface (USB)

Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.


Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.


High-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 256 and 512 Kbytes.


XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 768 Kbytes and 1 Mbyte.


Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.

ส่วนนี้ใช้กับ the STM32F103xx performance line และ STM32F102xx USB access line families เท่านั้น.


23.1 USB introduction

The USB peripheral จัดให้มีใช้ an interface ระหว่าง a full-speed USB 2.0 bus และ the APB1 bus.
USB แขวนไว้/ดำเนินการต่อถูกรองรับซึ่งยอมให้หยุด the device clocks เพื่อ low-power consumption

23.2 USB main features

•    USB specification version 2.0 full-speed compliant
•    จำนวนที่กำหนดค่าได้ของ endpoints จาก 1 ถึง 8
•    Cyclic redundancy check (CRC) การสร้าง / การตรวจสอบ , Non-return-to-zero Inverted (NRZI) การเข้ารหัส / ถอดรหัส
      และการบรรจุบิต
•    รองรับ Isochronous transfers
•    รองรับ Double-buffered bulk/isochronous endpoint
•    USB การทำงานแขวนไว้/ดำเนินการต่อ
•    Frame locked clock pulse generation

ใน low, medium, high และ XL-density devices, the USB และ CAN แชร์ a dedicated 512-byte SRAM memory สำหรับ data transmission and reception, และดังนั้นพวกมันไม่สามารถถูกใช้ได้พร้อมกัน (the shared RAM ถูกเข้าถึงผ่านทาง CAN and USB อย่างกีดกัน). The USB and CAN สามารถถูกใช้ใน the same application แต่ไม่ในเวลาเดียวกัน.

23.3 USB functional description

Figure 220 แสดง the block diagram ของ the USB peripheral.

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

The USB peripheral จัดให้มี an USB compliant connection ระหว่าง the host PC และ the function ที่มีให้ใช้โดย the microcontroller. Data transfer ระหว่าง the host PC และ the system memory เกิดขึ้นผ่านทาง a dedicated packet buffer memory ถูกเข้าถึงโดยตรงโดย the USB peripheral. ขนาดของ this dedicated buffer memory ต้องสอดคล้องกับจำนวนของ endpoints ที่ใช้และ the maximum packet size. dedicated memory นี้มีขนาดถึง 512 bytes และมากถึง 16 mono-directional หรือ 8 bidirectional endpoints สามารถถูกใช้.The USB peripheral เชื่อมต่อกับ the USB host, การตรวจจับ token packets, การรับมือ data transmission/reception, และการประมวลผล handshake packets ตามที่ถูกต้องการโดย the USB standard. Transaction formatting ถูกดำเนินการโดย the hardware, รวมถึง CRC generation และการตรวจสอบ.
Title: Re: STM32F1 USB
Post by: tha on April 01, 2021, 09:19:41 AM
แต่ละ endpoint ที่เกี่ยวข้องกับ a buffer description block แสดงให้เห็นที่ๆ the endpoint related memory area ตั้งอยู่, มันใหญ่เท่าใดหรือ bytes จำนวนเท่าใดที่ต้องถูกส่ง. เมื่อ a token สำหรับ a valid function/endpoint pair ถูกรับรู้จาก the USB peripheral, the related data transfer (ถ้าต้องการและถ้า the endpoint ถูกกำหนดค่า) จะเกิดขึ้น. The data ที่บัฟเฟอร์โดย the USB peripheral จะถูกโหลดใน an internal 16 bit register และ memory เข้าถึงไปยัง the dedicated buffer ถูกดำเนินการ. เมื่อ the data ทั้งหมดถูกส่งถ่ายแล้ว, ถ้าจำเป็น, the proper handshake packet over the USB ถูกสร้างหรือคาดว่าจะสอดคล้องกับ the direction of the transfer
Title: Re: STM32F1 USB
Post by: tha on April 01, 2021, 10:10:58 AM
ที่จุดสิ้นสุดของ the transaction, an endpoint-specific interrupt ถูกสร้างขึ้น, การอ่าน status registers และ/หรือการใช้ different interrupt response routines. The microcontroller สามารถกำหนด :
•    the endpoint ที่จะถูกบริการ
•    ประเภทของ transaction ที่จะเกิดขึ้น, ถ้า errors (อย่างเช่น bit stuffing, format, CRC, protocol, missing ACK,
      over/underrun) เกิดขึ้น.

การรองรับพิเศษถูกเสนอถึง Isochronous transfers และ high throughput bulk transfers, การจัดให้มีใช้ a double buffer usage, ซึ่งยอมให้มี an available buffer เสมอสำหรับ the USB peripheral ในขณะที่ the microcontroller ใช้อีกอันหนึ่ง.

The unit สามารถถูกวางใน low-power mode (SUSPEND mode), โดยการเขียนใน the control register, เมื่อไรก็ตามที่จำเป็น. ที่เวลานี้, static power dissipation ทั้งหมดถูกหลีกเลี่ยง, และ the USB clock สามารถถูกทำให้ช้าลงหรือหยุด. การตรวจจับกิจกรรมที่ the USB inputs, ในขณะใน low-power mode, จะปลุก the device ขึ้นแบบ asynchronously. A special interrupt source สามารถถูกต่อโดยตรงถึง a wakeup line เพื่อยอมให้ the system รีสตาร์ทโดยทันที the normal clock generation และ/หรือรองรับ direct clock start/stop.
Title: Re: STM32F1 USB
Post by: tha on April 02, 2021, 08:03:56 AM
23.3.1 Description of USB blocks

The USB peripheral จัดให้มีใช้คุณลักษณะทั้งหมดที่เกี่ยวกับ USB interfacing, ซึ่งรวมถึง blocks ต่อไปนี้ :
•    Serial Interface Engine (SIE) : หน้าที่ของ block นี้รวมถึง : synchronization pattern recognition, bit-stuffing,
      CRC generation and checking, PID verification/generation, and handshake evaluation. มันต้องอินเตอร์เฟสกับ the
      USB transceivers และใช้ the virtual buffers ที่จัดให้มีโดย the packet buffer interface สำหรับ local data storage,
      unit นี้สร้าง signals ที่สอดคล้องกับ  USB peripheral events อีกด้วย, อย่างเช่น Start of Frame (SOF), USB_Reset, Data
      errors etc. และไปยัง Endpoint related events อย่าง end of transmission หรือ correct reception of a packet;
      signals เหล่านี้ดังนั้นถูกใช้เพื่อสร้าง interrupts
•    Timer : block นี้สร้าง a start-of-frame locked clock pulse และตรวจจับ a global suspend (จาก the host) เมื่อ
      ไม่มี traffic ถูกรับมาเป็นเวลา 3 ms.
•    Packet Buffer Interface : block นี้จัดการ the local memory ที่จัดให้มีใช้ a set of buffers ใน a flexible way, ทั้ง
      สำหรับ transmission และ reception. มันสามารถเลือก the proper buffer สอดคล้องกับการร้องขอที่มาจาก the SIE และให้
      ตำแหน่งพวกมันใน the memory addresses ที่ถูกชี้โดย the Endpoint registers. มันเพิ่ม the address หลังจากแต่ละ
      exchanged word จนกระทั่ง the end of packet, ติดตามจำนวนของ exchanged bytes และป้องกันไม่ให้ the buffer ทำงาน
      เกิน the maximum capacity.
•    Endpoint-Related Registers : แต่ละ endpoint มี an associated register ที่มี the endpoint type และ status
      ปัจจุบันของมัน. สำหรับ mono-directional/single-buffer endpoints, a single register สามารถถูกใช้เพื่อจัดให้มีใช้ two
      distinct endpoints. จำนวนของ registers คือ 8, ยอมให้สูงถึง 16 mono-directional/single-buffer หรือสูงถึง 7 double-
      buffer endpoints(a) ในการผสมใดก็ได้. ตัวอย่างเช่น the USB peripheral สามารถถูกโปรแกรมให้มี 4 double buffer
      endpoints และ 8 single-buffer/mono-directional endpoints
•    Control Registers: เหล่านี้คือ the registers ที่มี information เกี่ยวกับ the status ของ the whole USB peripheral
      และถูกใช้เพื่อบังคับบาง USB events, อย่างเช่น resume และ power-down.
•    Interrupt Registers : เหล่านี้บรรจุ the Interrupt masks และบันทึกของ the events. พวกมันสามารถถูกใช้เพื่อสอบถาม
      an interrupt reason, the interrupt status หรือเพื่อเคลียร์ the status of a pending interrupt.

a. Endpoint 0 ถูกใช้เสมอสำหรับ control transfer ใน single-buffer mode.
Title: Re: STM32F1 USB
Post by: tha on April 02, 2021, 10:07:20 AM
The USB peripheral ถูกต่อถึง the APB1 bus ผ่านทาง an APB1 interface, บรรจุ blocks ต่อไปนี้:
•    Packet Memory: นี้คือ the local memory ที่ในทางกายภาพบรรจุ the Packet Buffers. มันสามารถถูกใช้โดย the
      Packet Buffer interface, ซึ่งสร้าง the data structure และสามารถถูกเข้าถึงโดยตรงโดย the application software. ขนาด
      ของ the Packet Memory คือ 512 bytes, มีโครงสร้างเป็น 256 words คุณ 16 bits.
•    Arbiter: block นี้ยอมรับ memory requests ที่มาจาก the APB1 bus และจาก the USB interface. มันแก้ปัญหาความ
      ขัดแย้งโดยการให้ priority กับการเข้าถึง APB1, ในขณะที่สงวนครึ่งหนึ่งของ the memory bandwidth ไว้เสมอเพื่อเสร็จสมบูรณ์
      USB transfers ทั้งหมด. time-duplex scheme นี้จัดให้มีใช้ a virtual dual-port SRAM ที่ยอมให้เข้าถึง memory , ในขณะที่
      an USB transaction กำลังเกิดขึ้น. Multiword APB1 transfers ที่มีความยาวเท่าใดก็ได้ถูกยอมให้โดยแบบแผนนี้อีกด้วย.
•    Register Mapper: block นี้รวบรวม the various byte-wide และ bit-wide registers ของ the USB peripheral ใน
      a structured 16-bit wide word set ที่ให้ที่อยู่โดย the APB1.
•    APB1 Wrapper: นี้จัดให้มี an interface ไปยัง the APB1 สำหรับ the memory และ register. มันยังแม็ป the whole
      USB peripheral ใน the APB1 address space.
•    Interrupt Mapper: block นี้ถูกใช้เพื่อเลือกอย่างไรที่ the possible USB events สามารถสร้าง interrupts และแม็ปพวก
      มันถึง three different lines ของ the NVIC:
      –    USB low-priority interrupt (Channel 20): ถูกทริกโดย USB events ทั้งหมด (Correct transfer, USB reset, etc.).
            The firmware ต้องตรวจสอบ the interrupt source ก่อนให้บริการ the interrupt.
      –    USB high-priority interrupt (Channel 19): ถูกทริกเฉพาะโดย a correct transfer event สำหรับ isochronous และ
            double-buffer bulk transfer เพื่อให้ถึง the highest possible transfer rate.
      –    USB wakeup interrupt (Channel 42): ถูกทริกโดย the wakeup event จาก the USB Suspend mode.
Title: Re: STM32F1 USB
Post by: tha on April 02, 2021, 03:26:22 PM
23.4.2 System and power-on reset

เมื่อ system and power-on reset, การทำงานอันดับแรก the application software ควรดำเนินการคือจัดให้มี all required clock signals ไปยัง the USB peripheral และจากนั้นจึงยกเลิกการยืนยัน reset signal ของมันเพื่อให้สามารถเข้าถึง registers ของมัน. ลำดับการเริ่มต้นทั้งหมดถูกอธิบายต่อจากนี้.

ตามที่ a first step application software จำเป็นเพื่อทำให้ทำงาน register macrocell clock และยกเลิกการยืนยัน macrocell specific reset signal โดยใช้ related control bits ที่จัดให้มีโดย device clock management logic.

หลังจากนั้น, the analog part ของ the device ที่เกี่ยวข้องกับ the USB transceiver ต้องถูก switched on โดยใช้ the PDWN bit ใน CNTR register, ซึ่งต้องการการจัดการพิเศษ. บิตนี้มีไว้เพื่อเปิด the internal voltage references ที่จ่ายไฟ the port transceiver. วงจรนี้มี a defined startup time (tSTARTUP ที่ระบุใน the datasheet) ในระหว่างที่พฤติกรรมของ the USB transceiver ไม่ได้ถูกกำหนด. ดังนั้นจึงจำเป็นต้องรอเวลานี้, หลังจากการเซ็ต the PDWN bit ใน the CNTR register, ก่อนการเอาออก the reset condition บน the USB part (โดยการเคลียร์ the FRES bit ใน the CNTR register). การเคลียร์ the ISTR register ดังนั้นจะเอาออก any spurious pending interrupt ก่อน macrocell operation อื่นใดๆจะถูกเปิดการใช้งาน.

At system reset, the microcontroller ต้องเริ่มต้นทุก required registers และ the packet buffer description table, เพื่อทำให้ the USB peripheral สามารถ interrupts และ data transfers อย่างเหมาะสม. ทุก registers ที่ไม่เฉพาะเจาะจงกับ endpoint ใดๆต้องถูกเริ่มต้นให้สอดคล้องกับความต้องการของ application software (ทางเลือกของ interrupts ที่ถูกเปิดการใช้งาน, address ที่เลือกของ packet buffers, ฯลฯ). จากนั้น the process ดำเนินการต่อไปเหมือนกับสำหรับ the USB reset case (ดูย่อหน้าต่อไป).
Title: Re: STM32F1 USB
Post by: tha on April 03, 2021, 07:03:24 AM
USB reset (RESET interrupt)

เมื่อ event นี้เกิดขึ้น, the USB peripheral ถูกใส่ใน the same conditions ที่มันถูกทิ้งโดย the system reset หลังจากการเริ่มต้นที่อธิบายในย่อหน้าก่อนหน้า : communication ถูกปิดการใช้งานในทุก endpoint registers (the USB peripheral จะไม่ตอบสนองต่อ packet ใดๆ). ตามที่ตอบสนองต่อ the USB reset event, the USB function ต้องถูกเปิดการใช้งาน, โดยมีเป็น USB address 0, จักให้มีใช้เฉพาะ the default control endpoint (endpoint address เป็น 0 ด้วย). นี้ถูกทำให้สำเร็จลงโดยการเซ็ต the Enable Function (EF) bit ของ the USB_DADDR register และการเตรียม the EP0R register และ related packet buffers ของมันสอดคล้องกัน. ในระหว่าง USB enumeration process, the host กำหนด a unique address ถึง device นี้, ซึ่งต้องถูกเขียนใน the ADD[6:0] bits ของ the USB_DADDR register, และกำหนดค่า endpoint ที่จำเป็นอื่นใดๆ.

เมื่อ a RESET interrupt ถูกรับ, the application software ตอบสนองโดยเปิดการใช้งานอีกครั้ง the default endpoint of USB function 0 ภายใน 10mS จากจุดสิ้นสุดของ reset sequence ซึ่งทริก the interrupt.
Title: Re: STM32F1 USB
Post by: tha on April 03, 2021, 08:32:09 AM
Structure and usage of packet buffers

แต่ละ bidirectional endpoint อาจ receive หรือ transmit data จาก/ถึง the host. The received data ถูกเก็บใน a dedicated memory buffer ที่ถูกสงวนไว้สำหรับ endpoint นั้น, ในขณะที่ memory buffer อื่นบรรจุ the data ที่จะถูกส่งโดย the endpoint. เข้าถึงไปยัง memory นี้ถูกดำเนินการโดย the packet buffer interface block, ซึ่งจะส่ง a memory access request และรอสำหรับ acknowledgement ของมัน. เนื่องจาก the packet buffer memory ต้องถูกเข้าถึงโดย the microcontroller อีกด้วย, an arbitration logic จะดูแล the access conflicts, โดยใช้ครึ่งหนึ่ง  APB1 cycle สำหรับ microcontroller access และครึ่งหนึ่งที่เหลือสำหรับ the USB peripheral access. ด้วยวิธีนี้, ทั้งสอง the agents สามารถทำงานราวกับว่า the packet memory เป็น a dual-port SRAM, โดยไม่ต้องตระหนักถึง conflict ใดๆแม้ในขณะที่ the microcontroller กำลังดำเนินการ back-to-back accesses. The USB peripheral logic ใช้ a dedicated clock. ความถี่ของ dedicated clock นี้ถูกคงที่โดยความต้องการของ the USB standard ที่ 48 MHz, และนี้สามารถแตกต่างจาก the clock ที่ถูกใช้สำหรับ the interface ไปยัง the APB1 bus. Different clock configurations เป็นไปได้ที่ the APB1 clock frequency สามารถสูงกว่าหรือต่ำกว่า the USB peripheral.

Note: เนื่องจาก USB data rate และ packet memory interface requirements, the APB1 clock frequency ต้องใหญ่กว่า 8
           MHz เพื่อหลีกเลี่ยงปัญหา data overrun/underrun.
Title: Re: STM32F1 USB
Post by: tha on April 03, 2021, 09:37:15 AM
แต่ละ endpoint ถูกเกี่ยวข้องกับ two packet buffers (โดยปกติจะหนึ่งสำหรับ transmission และอีกหนึ่งสำหรับ reception). Buffers สามารถถูกวางที่ไหนก็ได้ภายใน the packet memory เพราะตำแหน่งของมันและขนาดถูกระบุใน a buffer description table, ซึ่งถูกวางตำแหน่งใน the packet memory อีกด้วยที่ the address ที่แสดงให้เห็นโดย the USB_BTABLE register. แต่ละ table entry ถูกเกี่ยวข้องถึง an endpoint register และมันประกอบด้วย four 16-bit words ดังนั้น table start address ต้องถูกจัดแนวให้ตรงกับ an 8-byte boundary เสมอ (สามบิตต่ำสุดของ USB_BTABLE register เป็น "000" เสมอ). Buffer descriptor table entries ถูกอธิบายใน the Section 23.5.3. ถ้า an endpoint เป็นแบบทิศทางเดียวและไม่ใช่ทั้งแบบ an Isochronous หรือ a double-buffered bulk, เพียง one packet buffer ถูกต้องการ (หนึ่งเดียวที่เกี่ยวพันกับ the supported transfer direction). table locations อื่นที่เกี่ยวพันกับ unsupported transfer directions หรือ unused endpoints, มีให้ใช้งานกับผู้ใช้. Isochronous และ double-buffered bulk endpoints มีการจัดการพิเศษของ packet buffers (อ้างอิงถึง Section 23.4.4 และ Section 23.4.3 ตามลำดับ). ความเกี่ยวพันกันระหว่าง buffer description table entries และ packet buffer areas ถูกให้รายละเอียดใน Figure 221.

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

แต่ละ packet buffer ถูกใช้อย่างใดอย่างหนึ่งระหว่าง reception หรือ transmission สตาร์ทจาก the bottom. The USB peripheral จะไม่เคยเปลี่ยนสิ่งที่อยู่ภายในของ memory locations ที่อยู่ติดกันกับ the allocated memory buffers; ถ้า a packet ใหญ่กว่า the allocated buffer length ถูกรับ (buffer overrun condition) the data จะถูกคัดลอกไปยัง the memory เฉพาะสูงถึง the last available location.
Title: Re: STM32F1 USB
Post by: tha on April 03, 2021, 11:13:20 AM
Endpoint initialization

ขั้นตอนแรกในการเริ่มต้น an endpoint คือเขียนค่าที่เหมาะสมไปยัง the ADDRn_TX/ADDRn_RX registers เพื่อให้ the USB peripheral ค้นหา the data ที่จะถูกส่งพร้อมมีให้ใช้งานและ the data ที่จะถูกรับสามารถถูกบัฟเฟอร์ได้. The EP_TYPE bits ใน the USB_EPnR register ต้องถูกเซ็ตสอดคล้องกับ the endpoint type, ในที่สุดใช้ the EP_KIND bit เพื่อเปิดการใช้งานคุณลักษณะที่จำเป็นพิเศษใดๆ. บน the transmit side, the endpoint ต้องถูกเปิดการใช้งานโดยใช้ the STAT_TX bits ใน the USB_EPnR register และ COUNTn_TX ต้องถูกเริ่มต้น. สำหรับ reception, STAT_RX bits ต้องถูกเซ็ตเพื่อเปิดการใช้งาน reception และ COUNTn_RX ต้องถูกเขียนด้วย the allocated buffer size โดยใช้ the BL_SIZE และ NUM_BLOCK fields. Unidirectional endpoints, ยกเว้น Isochronous และ double-buffered bulk endpoints, จำเป็นต้องเริ่มต้นเฉพาะ bits and registers ที่เกี่ยวพันกับทิศทางที่รองรับ. เมื่อ the transmission และ/หรือ reception ถูกเปิดการใช้งาน, register USB_EPnR และตำแหน่ง ADDRn_TX/ADDRn_RX, COUNTn_TX/COUNTn_RX (ตามลำดับ), ไม่ควรถูกแก้ไขโดย the application software, เนื่องจาก the hardware สามารถเปลี่ยนค่าของมันได้ทันที. เมื่อ the data transfer operation เสร็จสมบูรณ์, จะถูกแจ้งให้ทราบโดย a CTR interrupt event, พวกมันสามารถถูกเข้าถึงอีกครั้งเพื่อเปิดการใช้งานใหม่ a new operation.
Title: Re: STM32F1 USB
Post by: tha on April 03, 2021, 03:08:37 PM
IN packets (data transmission)

เมื่อได้รับ an IN token packet, ถ้า the received address ตรงกับที่กำหนดค่าไว้และ endpoint ที่ถูกต้องตัวหนึ่ง, the USB peripheral เข้าถึงสิ่งที่อยู่ภายในของ ADDRn_TX และ COUNTn_TX locations ภายใน buffer descriptor table entry ที่เกี่ยวพันกับ the addressed endpoint. สิ่งที่อยู่ภายในของ locations เหล่านี้ถูกเก็บใน internal 16 bit registers ADDR and COUNT ของมัน(ไม่สามารถเข้าถึงได้โดย software). The packet memory ถูกเข้าถึงอีกครั้งเพื่ออ่าน the first word ที่จะถูกส่ง (อ้างอิงถึง Structure and usage of packet buffers) และสตาร์ทการส่ง a DATA0 หรือ DATA1 PID สอดคล้องกับ USB_EPnR bit DTOG_TX. เมื่อ the PID เสร็จสมบูรณ์, the first byte จาก the word, ถูกอ่านจาก buffer memory, ถูกโหลดลงใน the output shift register เพื่อจะถูกส่งไปบน the USB bus. หลังจาก the last data byte ถูกส่, the computed CRC ถูกส่ง. ถ้า the addressed endpoint ไม่ถูกต้อง, a NAK or STALL handshake packet ถูกส่งแทนที่จะเป็น the data packet, สอดคล้องกับ STAT_TX bits ใน the USB_EPnR register.

The ADDR internal register ถูกใช้เป็น a pointer ไปยัง the current buffer memory location ในขณะที่ COUNT ถูกใช้เพื่อนับจำนวน bytes ที่ยังเหลือที่จะถูกส่ง. แต่ละ word ถูกอ่านจาก the packet buffer memory ถูกส่งไปบน the USB bus โดยเริ่มจาก the least significant byte. Transmission buffer memory ถูกอ่านโดยเริ่มจาก the address ที่ถูกชี้โดย ADDRn_TX for COUNTn_TX/2 words. ถ้า a transmitted packet ถูกประกอบด้วยจำนวนคี่ของ bytes, เฉพาะครึ่งล่างของ the last word ที่ถูกเข้าถึงจะถูกใช้.

ในการรับ the ACK ที่รับโดย the host, the USB_EPnR register ถูกอัปเดตในวิธีต่อไปนี้: DTOG_TX bit ถูกสลับ, the endpoint ถูกทำให้ใช้ไม่ได้โดยการเซ็ต STAT_TX=10 (NAK) และ bit CTR_TX ถูกเซ็ต. The application software ต้องวินิจฉัย the endpoint เป็นอันดับแรก, ซึ่งกำลังร้องขอ microcontroller attention โดยการตรวจสอบ the EP_ID และ DIR bits ใน the USB_ISTR register. การให้บริการของ the CTR_TX event จะเริ่มการเคลียร์ the interrupt bit; the application software จากนั้นเตรียม buffer อื่นที่ data เต็มที่จะถูกส่ง, อัปเดต the COUNTn_TX table location ด้วยจำนวนของ byte ที่จะถูกส่งในระหว่าง the next transfer, และสุดท้ายเซ็ต STAT_TX เป็น '11 (VALID) เพื่อเปิดการใช้งานใหม่ transmissions. ในขณะที่ the STAT_TX bits เท่ากันกับ 10 (NAK), IN request ใดๆที่ส่งไปยัง endpoint นั้นจะถูก NAK, แสดงให้เห็น a flow control condition: the USB host จะลองทำ the transaction อีกครั้งจนกว่าจะสำเร็จ. มันจำเป็นต้องดำเนินการตามลำดับของการทำงานดังที่กล่าวมาข้างต้นเพื่อหลีกเลี่ยงการสูญเสียการแจ้งเตือนของ a second IN transaction ที่ส่งไปยัง the same endpoint ตามมาทันทีที่ตัวแรกซึ่งทริก the CTR interrupt.
Title: Re: STM32F1 USB
Post by: tha on April 04, 2021, 11:13:29 AM
OUT and SETUP packets (data reception)

tokens ทั้งสองนี้ถูกจัดการโดย the USB peripheral  ไม่มากก็น้อยในลักษณะเดียวกัน; ความแตกต่างในการจัดการของ SETUP packets ถูกให้รายละเอียดในย่อหน้าต่อไปนี้เกี่ยวกับ control transfers. เมื่อได้รับ an OUT/SETUP PID, ถ้า the address ตรงกับ a valid endpoint, the USB peripheral เข้าถึงสิ่งที่อยู่ภายในของ the ADDRn_RX and COUNTn_RX locations ภายใน the buffer descriptor table entry ที่เกี่ยวพันกับ the addressed endpoint. สิ่งที่อยู่ภายในของ the ADDRn_RX ถูกเก็บโดยตรงใน internal register ADDR ของมัน. ในขณะที่ COUNT ถูกรีเซ็ตเดี๋ยวนี้และค่าของ BL_SIZE และ NUM_BLOCK bit fields, ซึ่งถูกอ่านภายใน COUNTn_RX content ถูกใช้เพื่อเริ่มต้น BUF_COUNT, an internal 16 bit counter, ซึ่งถูกใช้เพื่อตรวจสอบ the buffer overrun condition ( internal registers เหล่านี้ทั้งหมดไม่สามารถเข้าถึงได้โดย software). Data bytes ที่ได้รับตามมาโดย the USB peripheral ถูกแพ็คเป็น words (the first byte ที่ได้รับถูกเก็บเป็น least significant byte) และจากนั้นถูกส่งถ่ายไปยัง the packet buffer เริ่มต้นจาก the address ที่บรรจุใน the internal ADDR register ในขณะที่ BUF_COUNT ถูกลดลงและ COUNT ถูกเพิ่มขึ้นที่แต่ละ byte transfer. เมื่อ the end of DATA packet ถูกตรวจพบ, ความถูกต้องของ the received CRC ถูกตรวจสอบและเฉพาะถ้าไม่มี errors เกิดขึ้นในนระหว่าง the reception, an ACK handshake packet ถูกส่งกลับไปยัง the transmitting host.
Title: Re: STM32F1 USB
Post by: tha on April 04, 2021, 02:20:41 PM
ในกรณีของ wrong CRC หรือ errors ประเภทอื่นๆ (bit-stuff violations, frame errors, etc.), data bytes ยังคงถูกคัดลอกลงใน the packet memory buffer, อย่างน้อยก็จนถึง the error detection point, แต่ ACK packet ไม่ถูกส่งและ the ERR bit ใน USB_ISTR register ถูกเซ็ต. อย่างไรก็ตาม, ปกติแล้วไม่มี software action ที่ต้องการในกรณีนี้ : the USB peripheral จะกู้คืนจาก reception errors และยังคงพร้อมสำหรับ the next transaction ที่จะมา. ถ้า the addressed endpoint ไม่ถูกต้อง, a NAK or STALL handshake packet ถูกส่งแทนที่จะเป็น the ACK, สอดคล้องกับ bits STAT_RX ใน the USB_EPnR register และไม่มี data ถูกเขียนใน the reception memory buffers.
Title: Re: STM32F1 USB
Post by: tha on April 04, 2021, 03:16:15 PM
Reception memory buffer locations ถูกเขียนเริ่มจาก the address ที่บรรจุใน the ADDRn_RX เป็นจำนวนของ bytes ที่ตรงกันกับ the received data packet length, รวมถึง CRC  (เช่น data payload length + 2), หรือสูงถึง the last allocated memory location, ตามที่กำหนดโดย BL_SIZE and NUM_BLOCK, แล้วแต่ว่ากรณีใดจะเกิดขึ้นก่อน. ด้วยวิธีนี้, the USB peripheral ไม่เคยเขียนเกินกว่า the end of the allocated reception memory buffer area. ถ้า the length of the data packet payload (actual number of bytes ที่ถูกใช้โดย the application) ใหญ่กว่า the allocated buffer, the USB peripheral จะตรวจพบ a buffer overrun condition. ในกรณีนี้, a STALL handshake ถูกส่งแทนที่จะเป็น the usual ACK เพื่อแจ้งให้ทราบปัญหาไปยัง the host, ไม่มี interrupt ถูกสร้างและ the transaction ถูกพิจารณาว่าล้มเหลว
Title: Re: STM32F1 USB
Post by: tha on April 05, 2021, 07:33:55 AM
เมื่อ the transaction เสร็จสมบูรณ์อย่างถูกต้อง, โดยการส่ง the ACK handshake packet, the internal COUNT register ถูกคัดลอกกลับใน the COUNTn_RX location ภายใน the buffer description table entry, โดยปล่อยให้ BL_SIZE and NUM_BLOCK fields ไม่ได้รับผลกระทบ, ซึ่งโดยปกติไม่จำเป็นต้องเขียนซ้ำ, และ the USB_EPnR register ถูกอัปเดตในวิธีต่อไปนี้ : DTOG_RX bit ถูกสลับ, the endpoint ถูกทำให้ใช้ไม่ได้โดยการเซ็ต STAT_RX = '10 (NAK) และ bit CTR_RX ถูกเซ็ต. ถ้า the transaction ล้มเหลวเนื่องจาก errors หรือ buffer overrun condition, ไม่มีการดำเนินการใดๆที่ระบุไว้ก่อนหน้านี้เกิดขึ้น. The application software ต้องก่อนอื่นวินิจฉัย the endpoint, ซึ่งกำลังขอ microcontroller attention โดยการตรอจสอบ the EP_ID และ DIR bits ใน the USB_ISTR register. The CTR_RX event ถูกให้บริการโดยการกำหนด the transaction type เป็นอันดับแรก (SETUP bit ใน the USB_EPnR register); the application software ต้องเคลียร์ the interrupt flag bit และได้รับจำนวนของ received bytes โดยอ่าน the COUNTn_RX location ภายใน the buffer description table entry ที่เกี่ยวพันกับ the endpoint ที่กำลังถูกประมวลผล. หลังจาก the received data ถูกประมวลผล, the application software ควรเซ็ต the STAT_RX bits เป็น '11 (Valid) ใน the USB_EPnR, เปิดการใช้งาน transactions ต่อไป. ในขณะที่ the STAT_RX bits เท่ากับ '10 (NAK), OUT request ใดๆที่ส่งไป endpoint นั้นถูก NAK, แสดงให้เห็น a flow control condition: the USB host จะลองทำ the transaction อีกครั้งจนกว่ามันจะประสบผลสำเร็จ. จำเป็นต้องปฏิบัติตามลำดับการทำงานตามที่กล่าวไว้ข้างต้นเพื่อหลีกเลี่ยงการสูญเสียการแจ้งเตือนของ a second OUT transaction ที่ส่งถึง the same endpoint ตามมาทันทีที่ตัวแรกซึ่งทริก the CTR interrupt.
Title: Re: STM32F1 USB
Post by: tha on April 05, 2021, 09:14:06 AM
Control transfers

Control transfers ถูกทำจาก a SETUP transaction, ตามด้วยศูนย์หรือมากกว่า data stages, ทิศทางเดียวกันทั้งหมด, ตามด้วย a status stage (a zero-byte transfer ในทิศทางที่ตรงกันข้าม). SETUP transactions ถูกจัดการโดย control endpoints เท่านั้นและคล้ายกันมากกับ OUT transactions (data reception) ยกเว้นว่าค่าของ DTOG_TX และ DTOG_RX bits ของ the addressed endpoint registers ถูกเซ็ตเป็น 1 และ 0 ตามลำดับ, เพื่อเริ่มต้น the control transfer, และทั้ง STAT_TX และ STAT_RX ถูกเซ็ตเป็น '10 (NAK) เพื่อให้ software ตัดสินใจว่าถ้า transactions ที่ตามมาต้องเป็น IN หรือ OUT ขึ้นอยู่กับ the SETUP contents. A control endpoint ต้องตรวจสอบ SETUP bit ใน the USB_EPnR register ที่แต่ละ CTR_RX event เพื่อแยกความแตกต่าง normal OUT transactions จาก SETUP transactions. A USB device สามารถกำหนดจำนวนและทิศทางของ data stages โดยการตีความ the data ที่ส่งถ่ายใน the SETUP stage, และจำเป็นต้อง STALL the transaction ในกรณีของ errors. ในการทำเช่นนั้น, ที่ทุก data stages ก่อนสุดท้าย, ทิศทางที่ไม่ได้ถูกใช้ควรถูกเซ็ตเป็น STALL, ดังนั้น, ถ้า the host กลับ the transfer direction เร็วเกินไป, มันจะได้รับ a STALL เป็น a status stage.
Title: Re: STM32F1 USB
Post by: tha on April 05, 2021, 10:21:58 AM
ในขณะที่เปิดการใช้งาน 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).
Title: Re: STM32F1 USB
Post by: tha on April 05, 2021, 10:49:58 AM
เนื่องจาก 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.
Title: Re: STM32F1 USB
Post by: tha on April 05, 2021, 11:28:24 AM
เมื่อ 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.
Title: Re: STM32F1 USB
Post by: tha on April 06, 2021, 07:14:06 AM
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).
Title: Re: STM32F1 USB
Post by: tha on April 07, 2021, 07:04:18 AM
เนื่องจาก 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.

(https://i.imgur.com/ESze7BG.png)
Title: Re: STM32F1 USB
Post by: tha on April 07, 2021, 08:32:49 AM
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 เป็นเหมือนกันในทั้งสองกรณี, และถูกแสดงรายการในตารางต่อไปนี้.

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

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.
Title: Re: STM32F1 USB
Post by: tha on April 07, 2021, 10:38:27 AM
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.
Title: Re: STM32F1 USB
Post by: tha on April 07, 2021, 03:34:34 PM
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.

(https://i.imgur.com/WDVVJPM.png)
Title: Re: STM32F1 USB
Post by: tha on April 07, 2021, 04:28:39 PM
ตามที่มันเกิดขึ้นกับ double-buffered bulk endpoints, the USB_EPnR registers ที่ใช้เพื่อจัดให้มีใช้ Isochronous endpoints ถูกบังคับที่จะถูกใช้เป็น unidirectional ones. ถ้ามันถูกต้องการให้มี Isochronous endpoints ที่เปิดการใช้งานทั้งสำหรับ reception and transmission, two USB_EPnR registers ต้องถูกใช้.

The application software รับผิดชอบสำหรับ the DTOG bit initialization สอดคล้องกับ the first buffer ที่จะถูกใช้; สิ่งนี้จะต้องทำโดยพิจารณา the special toggle-only property ที่สองบิตเหล่านี้มี. ที่จุดสิ้นสุดของแต่ละ 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 ถูกสลับทางฮาร์ดแวร์ทำให้ buffer swapping โดย software เป็นอิสรอย่างสมบูรณ์. คู่ STAT bit ไม่ถูกกระทบโดย transaction completion; เนื่องจากไม่มี flow control สามารถเป็นได้สำหรับ Isochronous transfers เนื่องจากไม่มี handshake phase, the endpoint ยังคง '11 (Valid) เสมอ. CRC errors หรือ buffer-overrun conditions เกิดขึ้นในระหว่าง Isochronous OUT transfers ถูกพิจารณาเป็น correct transactions อยู่ดีและพวกมันทริก an CTR_RX event เสมอ. อย่างไรก็ตาม, CRC errors จะเซ็ต the ERR bit ใน the USB_ISTR register อยู่ดีเพื่อแจ้งให้ the software ทราบถึง the possible data corruption.
Title: Re: STM32F1 USB
Post by: tha on April 08, 2021, 07:05:29 AM
23.4.5 Suspend/Resume events

The USB standard กำหนด a special peripheral state, ที่เรียกว่า SUSPEND, ซึ่งกระแสเฉลี่ยที่ดึงมาจาก the USB bus ต้องไม่ใหญ่กว่า 2.5 mA. ข้อกำหนดนี้มีความสำคัญขั้นพื้นฐานสำหรับ bus-powered devices, ในขณะที่ self-powered devices ไม่จำเป็นต้องปฏิบัติตาม strict power consumption constraint นี้. ใน suspend mode, the host PC จะส่งการแจ้งเตือนว่าจะไม่ส่งการรับส่งข้อมูลใด ๆ บน the USB bus เป็นเวลามากกว่า 3mS: เนื่องจาก a SOF packet ต้องถูกส่งทุกๆ mS ในระหว่าง normal operations, the USB peripheral ตรวจพบการขาดไปของ 3 SOF packets ติดต่อกันเป็น a suspend request จาก the host PC และเซ็ต the SUSP bit เป็น '1 ใน USB_ISTR register, ทำให้เกิด an interrupt ถ้าเปิดการใช้งาน. เมื่อ the device ถูกแขวน, normal operation ของมันจะสามารถเรียกคืนได้ด้วยสิ่งที่เรียกว่า RESUME sequence, ซึ่งสามารถถูกสตาร์ทได้จาก the host PC หรือโดยตรงจาก the peripheral มันเอง, แต่มันจะถูกยุติโดย the host PC เสมอ. The suspended USB peripheral ต้องสามารถตรวจจับ a RESET sequence อยู่ดี, ตอบสนองต่อ event นี้เหมือนกับ a normal USB reset event.
Title: Re: STM32F1 USB
Post by: tha on April 08, 2021, 09:12:01 AM
ขั้นตอนจริงที่ใช้แขวน the USB peripheral นั้นขึ้นอยู่กับ device เนื่องจากสอดคล้องกับ the device composition, การปฏิบัติที่แตกต่างอาจถูกต้องการเพื่อลด the total consumption.

คำอธิบายสั้น ๆของ a typical suspend procedure ถูกจัดให้มีข้างล่างนี้, โดยเน้นที่ the USB related aspects ของ the application software routine ที่ตอบสนองต่อ the SUSP notification ของ the USB peripheral:
1.    เซ็ต the FSUSP bit ใน the USB_CNTR register เป็น 1. การปฏิบัตินี้ทำให้ the suspend mode ทำงานภายใน the USB
       peripheral. ทันทีที่ the suspend mode ถูกทำให้ทำงาน, การตรวจสอบบน SOF reception จะถูกปิดการใช้งานเพื่อหลีกเลี่ยง
       SUSP interrupts ต่อไปใดๆที่จะถูกปล่อยออกในขณะ the USB ถูกแขวน.
2.    เอาออกหรือลด static power consumption ใดๆใน blocks ที่แตกต่างจาก the USB peripheral
3.    เซ็ต LP_MODE bit ใน USB_CNTR register เป็น 1 เพื่อเอาออก static power consumption ใน the analog USB
       transceivers แต่ทำให้พวกมันสามารถตรวจจับ resume activity ได้.
4.    ทางเลือกปิด external oscillator และ device PLL เพื่อหยุดกิจกรรมใดๆภายใน the device.
Title: Re: STM32F1 USB
Post by: tha on April 08, 2021, 02:39:16 PM
เมื่อ an USB event เกิดขึ้นในขณะที่ the device อยู่ใน SUSPEND mode, the RESUME procedure ต้องถูกปลุกเพื่อกู้คืน nominal clocks และกลับไปสู่ normal USB behavior. ความระมัดระวังเป็นพิเศษต้องถูกใช้เพื่อให้แน่ใจว่าขั้นตอนนี้ใช้เวลาไม่มากกว่า 10mS เมื่อ the wakening event คือ an USB reset sequence (ดู "Universal Serial Bus Specification" สำหรับรายละเอียดที่มากขึ้น). การสตาร์ทของ a resume หรือ reset sequence, ในขณะที่ the USB peripheral ถูกแขวน, จะเคลียร์ the LP_MODE bit ใน USB_CNTR register แบบ asynchronous. แม้ว่า event นี้สามารถทริก an WKUP interrupt ถ้าเปิดการใช้งาน, การใช้ของ an interrupt response routine ต้องถูกประเมินอย่างรอบคอบเนื่องจากเวลาแฝงที่ยาวเนื่องจาก system clock restart; เพื่อให้มี the shorter latency ก่อนทำให้ the nominal clock ทำงานใหม่ขอแนะนำให้ใส่ the resume procedure แค่หลังจากการสิ้นสุดของ the suspend one, ดังนั้นs code ของมันถูกปฏิบัติทันทีทันทีที่ the system clock restarts. เพื่อป้องกัน ESD discharges หรือชนิดอื่นใดๆของ noise จากการปลุก the system (การออกจาก suspend mode เป็น an asynchronous event), a suitable analog filter บน data line status ถูกทำให้ทำงานในระหว่าง suspend; the filter width ประมาณ 70ns.
Title: Re: STM32F1 USB
Post by: tha on April 09, 2021, 07:01:43 AM
ต่อไปนี้คือรายการของการปฏิบัติ a resume procedure ที่ควรกล่าวถึง:
1.    ทางเลือกเปิด external oscillator และ/หรือ device PLL.
2.    เคลียร์ FSUSP bit ของ USB_CNTR register.
3.    ถ้า the resume triggering event ต้องถูกแยกแยะ, bits RXDP and RXDM ใน the USB_FNR register สามารถถูกใช้
       สอดคล้องกับ Table 172, ซึ่งแสดงรายการ the intended software action ในทุกกรณีอีกด้วย. ถ้าจำเป็น, the end of resume
       หรือ reset sequence สามารถถูกตรวจจับโดยมอนิเตอร์สถานะของบิตที่กล่าวมาข้างต้นโดยการเช็คเมื่อพวกมันถึง the "10"
       configuration, ซึ่งแสดงถึง the Idle bus state; นอกจากนี้ที่ the end of a reset sequence the RESET bit ใน
       USB_ISTR register ถูกเซ็ตเป็น 1, ปล่อยออก an interrupt ถ้าเปิดการใช้งาน, ซึ่งควรถูกจัดการตามปกติ.

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

A device อาจจำเป็นต้องออกจาก suspend mode เพื่อตอบสนองต่อเหตุการณ์บางอย่างที่ไม่ได้เกี่ยวข้องโดยตรงกับ the USB protocol (เช่น a mouse movement ปลุก the whole system). ในกรณีนี้, the resume sequence สามารถถูกสตาร์ทโดยการเซ็ต the RESUME bit ใน the USB_CNTR register เป็น '1 และรีเซ็ตมันเป็น 0 หลังจากช่วงเวลาระหว่าง 1 mS และ 15 mS (ช่วงเวลานี้สามารถถูกกำหนดเวลาโดยใช้ ESOF interrupts, ซึ่งเกิดขึ้นพร้อมกับ a 1mS period เมื่อ the system clock กำลังรันที่ nominal frequency). เมื่อ the RESUME bit ถูกเคลียร์, the resume sequence จะถูกทำให้เสร็จสมบูรณ์โดย the host PC และจุดสิ้นสุดของมันสามารถถูกมอนิเตอร์อีกครั้งโดยใช้ the RXDP and RXDM bits ใน the USB_FNR register.

Note: The RESUME bit ต้องถูกใช้เฉพาะหลังจาก the USB peripheral ถูกใส่ลงใน suspend mode, โดยการเซ็ต the FSUSP bit
           ใน USB_CNTR register เป็น 1.
Title: Re: STM32F1 USB
Post by: tha on April 09, 2021, 09:18:13 AM
23.5 USB registers

The USB peripheral registers สามารถถูกแบ่งออกเป็นกลุ่มต่างๆดังต่อไปนี้:
•    Common Registers: Interrupt and Control registers
•    Endpoint Registers: Endpoint configuration and status
•    Buffer Descriptor Table: ตำแหน่งของ packet memory ถูกใช้เพื่อวางตำแหน่ง data buffers

ทุก register addresses ถูกแสดงเป็น offsets ที่เคารพต่อ the USB peripheral registers base address 0x4000 5C00, ยกเว้น the buffer descriptor table locations, ซึ่งสตาร์ทที่ the address ที่ระบุโดย the USB_BTABLE register. เนื่องจากข้อจำกัดทั่วไปของ APB1 bridges บนความสามารถในการระบุตำแหน่งเป็น word, ทุก register addresses ถูกจัดแนวให้ตรงกับ 32-bit word boundaries แม้ว่าพวกมันเป็น 16-bit wide ก็ตาม. The same address alignment ถูกใช้เพื่อเข้าถึง packet buffer memory locations, ซึ่งถูกวางตำแหน่งสตาร์ทจาก 0x4000 6000

อ้างอิงถึง Section 2.2 on page 45 สำหรับรายการของตัวย่อที่ถูกใช้ใน register descriptions.

The peripheral registers สามารถถูกเข้าถึงโดย half-words (16-bit) หรือ words (32-bit).
Title: Re: STM32F1 USB
Post by: tha on April 09, 2021, 01:58:31 PM
23.5.1 Common registers

registers เหล่านี้มีผลต่อ the general behavior ของ the USB peripheral การกำหนด operating mode, การจัดการ interrupt, device address และการให้เข้าถึงไปยัง the current frame number ที่อัปเดตโดย the host PC.

USB control register (USB_CNTR)

Address offset: 0x40
Reset value: 0x0003

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

Bit 15 CTRM: Correct transfer interrupt mask
     0: Correct Transfer (CTR) Interrupt ถูกปิดการใช้งาน.
     1: CTR Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูกเซ็ต.

Bit 14 PMAOVRM: Packet memory area over / underrun interrupt mask
     0: PMAOVR Interrupt ถูกปิดการใช้งาน.
     1: PMAOVR Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูก
         เซ็ต.

Bit 13 ERRM: Error interrupt mask
     0: ERR Interrupt ถูกปิดการใช้งาน.
     1: ERR Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูกเซ็ต.

Bit 12 WKUPM: Wakeup interrupt mask
     0: WKUP Interrupt ถูกปิดการใช้งาน.
     1: WKUP Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูกเซ็ต.

Bit 11 SUSPM: Suspend mode interrupt mask
     0: Suspend Mode Request (SUSP) Interrupt ถูกปิดการใช้งาน.
     1: SUSP Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูกเซ็ต.

Bit 10 RESETM: USB reset interrupt mask
     0: RESET Interrupt ถูกปิดการใช้งาน.
     1: RESET Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูกเซ็ต.

Bit 9 SOFM: Start of frame interrupt mask
     0: SOF Interrupt ถูกปิดการใช้งาน.
     1: SOF Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูกเซ็ต.

Bit 8 ESOFM: Expected start of frame interrupt mask
     0: Expected Start of Frame (ESOF) Interrupt ถูกปิดการใช้งาน.
     1: ESOF Interrupt ถูกเปิดการใช้งาน, an interrupt request ถูกสร้างขึ้นเมื่อบิตที่ตรงกันใน the USB_ISTR register ถูกเซ็ต.

Bits 7:5 Reserved.
Title: Re: STM32F1 USB
Post by: tha on April 09, 2021, 03:27:57 PM
Bit 4 RESUME: Resume request
The microcontroller สามารถเซ็ตบิตนี้เพื่อส่ง a Resume signal ไปยัง the host. มันต้องถูกทำให้ทำงาน, สอดคล้องกับ USB specifications, เป็นเวลาไม่น้อยกว่า 1 mS และไม่มากกว่า 15 mS หลังจากที่ the Host PC พร้อมที่จะขับ the resume sequence จนถึงจุดสิ้นสุดของมัน.

Bit 3 FSUSP: Force suspend
Software ต้องเซ็ตบิตนี้เมื่อ the SUSP interrupt ถูกรับ, ซึ่งถูกปล่อยออกเมื่อไม่มีการรับส่งข้อมูลถูกรับโดย the USB peripheral เป็นเวลา 3 mS.
     0: ไม่มีผลอะไร.
     1: เข้าสู่ suspend mode. Clocks และ static power dissipation ใน the analog transceiver ถูกปล่อยไว้ไม่ได้รับผลกระทบ.
         ถ้า suspend power consumption คือความต้องการ (bus-powered device), the application software ควรเซ็ต the
         LP_MODE bit หลังจาก FSUSP ตามที่อธิบายข้างล่าง.
Title: Re: STM32F1 USB
Post by: tha on April 09, 2021, 05:37:06 PM
Bit 2 LP_MODE: Low-power mode
mode นี้ถูกใช้เมื่อ the suspend-mode power constraints ต้องการให้ all static power dissipation ถูกหลีกเลี่ยง, ยกเว้นสิ่งเดียวที่จำเป็นต้องจ่ายไฟให้ the external pull-up resistor. เงื่อนไขนี้ควรถูกเข้าสู่เมื่อ the application พร้อมที่จะหยุด all system clocks, หรือลดความถี่ของมันเพื่อให้ตรงตาม the power consumption requirements ของ the USB suspend condition. The USB activity ในระหว่าง the suspend mode (WKUP event) จะรีเซ็ตบิตนี้แบบอะซิงโครนัส (มันสามารถถูกรีเซ็ตโดย software ได้อีกด้วย)
     0: ไม่มี Low-power mode.
     1: เข้าสู่ Low-power mode

Bit 1 PDWN: Power down
บิตนี้ถูกใช้เพื่อปิด all USB-related analog parts อย่างสมบูรณ์ถ้ามันถูกต้องการเพื่อจะปิดการใช้งาน the USB peripheral อย่างสมบูรณ์ไม่ว่าด้วยเหตุผลใดก็ตาม. เมื่อบิตนี้ถูกเซ็ต, the USB peripheral ถูกตัดการเชื่อมต่อจาก the transceivers และมันไม่สามารถถูกใช้.
     0: ออกจาก Power Down.
     1: เข้าสู่ Power down mode.

Bit 0 FRES: Force USB Reset
     0: เคลียร์ USB reset.
     1: บังคับ a reset ของ the USB peripheral, เหมือนจริงๆกับ a RESET signalling บน the USB. The USB peripheral ถูกยึด
         อยู่ใน RESET state จนกระทั่ง software เคลียร์บิตนี้. A "USB-RESET" interrupt ถูกสร้างขึ้น, ถ้าเปิดการใช้งาน.
Title: Re: STM32F1 USB
Post by: tha on April 10, 2021, 07:49:15 AM
USB interrupt status register (USB_ISTR)

Address offset: 0x44
Reset value: 0x0000 0000

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

register นี้บรรจุสถานะของ all the interrupt sources ที่ยอมให้ application software ตัดสินใจ, ซึ่ง events ที่ทำให้เกิด an interrupt request.

ส่วนบนของ register นี้บรรจุ single bits, แต่ละของพวกมันแสดง a specific event. บิตเหล่านี้ถูกเซ็ตโดย the hardware เมื่อ the related event เกิดขึ้น; ถ้าบิตที่ตรงกันใน the USB_CNTR register ถูกเซ็ต, a generic interrupt request ถูกสร้างขึ้น. The interrupt routine, ตรวจสอบแต่ละบิต, จะดำเนินการ all necessary actions, และสุดท้ายมันจะเคลียร์ the serviced bits. ถ้าพวกมันอันไหนไม่ถูกเคลียร์, the interrupt ถูกพิจารณาว่ายังคง pending, และ the interrupt line จะถูกเก็บ high อีกครั้ง. ถ้าหลายบิตถูกเซ็ตพร้อมกัน, มีเพียง a single interrupt ที่จะถูกสร้างขึ้น.
Title: Re: STM32F1 USB
Post by: tha on April 10, 2021, 09:33:23 AM
Endpoint transaction completion สามารถถูกจัดการในวิธีต่างๆเพื่อลด interrupt response latency. The CTR bit ถูกเซ็ตโดย the hardware ทันทีที่ an endpoint สำเร็จเสร็จสมบูรณ์ a transaction, สร้างขึ้น a generic interrupt request ถ้าบิตที่ตรงกันใน USB_CNTR ถูกเซ็ต. An endpoint dedicated interrupt condition ถูกทำให้ทำงานเป็นอิสระจาก the CTRM bit ใน the USB_CNTR register. ทั้งสอง interrupt conditions ยังคงทำงานจนกว่า software จะเคลียร์ the pending bit ใน the corresponding USB_EPnR register (the CTR bit จริงๆแล้วเป็น a read only bit). สำหรับ endpoint-related interrupts, the software สามารถใช้ the Direction of Transaction (DIR) และ EP_ID read-only bits เพื่อวินิจฉัย, ซึ่ง endpoint ได้ทำ the last interrupt request แล้วและได้เรียก the corresponding interrupt service routine แล้ว.
Title: Re: STM32F1 USB
Post by: tha on April 10, 2021, 10:38:05 AM
ผู้ใช้สามารถเลือกลำดับความสำคัญที่เกี่ยวข้องกันของ pending USB_ISTR events ที่พร้อมกันโดยระบุลำดับขั้นที่ software ตรวจสอบ USB_ISTR bits ใน an interrupt service routine. เฉพาะบิตที่เกี่ยวข้องกับ events, ที่ถูกให้บริการ, จะถูกเคลียร์. ที่ the end of the service routine, interrupt อื่นจะถูกร้องขอ, เพื่อให้บริการ the remaining conditions.

เพื่อหลีกเลี่ยงการเคลียร์เทียมของบางบิต, ขอแนะนำให้เคลียร์พวกมันด้วยคำสั่ง load ที่ทุกบิตซึ่งต้องไม่ถูกเปลี่ยนแปลงเมื่อถูกเขียนด้วย 1, และทุกบิตจะถูกเคลียร์เมื่อถูกเขียนด้วย '0 (บิตเหล่านี้สามารถถูกเคลียร์โดย software เท่านั้น). Read-modify-write cycles ควรถูกหลีกเลี่ยงเนื่องจากระหว่าง the read and the write operations บิตอื่นอาจจะถูกเซ็ตโดย the hardware และ the next write จะเคลียร์มันก่อนที่ the microprocessor จะมีเวลาให้บริการ the event.
Title: Re: STM32F1 USB
Post by: tha on April 10, 2021, 02:25:01 PM
Bit 15 CTR: Correct transfer
บิตนี้ถูกเซ็ตโดย the hardware เพื่อแสดงให้เห็นว่า an endpoint สำเร็จเสร็จสมบูรณ์ a transaction; โดยใช้ DIR and EP_ID bits software สามารถกำหนดซึ่ง endpoint ที่ร้องขอ the interrupt. บิตนี้ถูกอ่านได้เพียงอย่างเดียว.

Bit 14 PMAOVR: Packet memory area over / underrun
บิตนี้ถูกเซ็ตถ้า the microcontroller ไม่สามารถตอบสนองให้ทันเวลาต่อ an USB memory request. The USB peripheral จัดการ event นี้ด้วยวิธีต่อไปนี้: ในระหว่าง reception an ACK handshake packet ไม่ถูกส่ง, ในระหว่าง transmission a bit-stuff error ถูกบังคับบน the transmitted stream; ในทั้งสองกรณ๊ the host จะลองทำ the transaction อีกครั้ง. The PMAOVR interrupt ไม่ควรเกิดขึ้นในระหว่าง normal operations. เนื่องจาก the failed transaction ถูกทำอีกครั้งโดย the host, the application software มีโอกาศเร่งความเร็ว device operations ในระหว่างการจัดการ interrupt นี้, เพื่อให้พร้อมสำหรับ the next transaction retry; อย่างไรก็ตามสิ่งนี้จะไม่เกิดขึ้นในระหว่าง Isochronous transfers (ไม่มี isochronous transaction ถูกทำอีกครั้งอีกต่อไป) นำมาซึ่งการสูญเสียของ data ในกรณีนี้. บิตนี้ถูกอ่าน/เขียนได้แต่มีเพียง '0 เท่านั้นที่สามารถถูกเขียนและการเขียน '1 ไม่มีผลอะไร.
Title: Re: STM32F1 USB
Post by: tha on April 10, 2021, 04:05:50 PM
Bit 13 ERR: Error
flag นี้ถูกเซ็ตเมื่อหนึ่งของ the errors ที่แสดงรายการข้างล่างนี้เกิดขึ้น :
NANS: No ANSwer. หมดเวลาสำหรับ a host response ได้หมดลง.
CRC: Cyclic Redundancy Check error. หนึ่งของ the received CRCs, อย่างใดอย่างหนึ่งใน the token หรือใน the data, ผิด.
BST: Bit Stuffing error. A bit stuffing error ถูกตรวจพบแล้วที่ใดที่หนึ่งใน the PID, data, และ/หรือ CRC.
FVIO: Framing format Violation. A non-standard frame ถูกรับแล้ว (EOP ไม่อยู่ในตำแหน่งที่ถูก, wrong token sequence, ฯลฯ).
The USB software สามารถเพิกเฉย errors โดยปกติ, เนื่องจาก the USB peripheral และ the PC host จัดการ retransmission ในกรณีของ errors ในวิธีที่โปร่งใสเต็มที่. interrupt นี้สามารถมีประโยชน์ในระหว่าง the software development phase, หรือเพื่อมอนิเตอร์คุณภาพของ transmission บน the USB bus, เพื่อ flag ปัญหาที่เป็นไปได้ไปยังผู้ใช้ (อย่างเช่น loose connector, too noisy environment, broken conductor ใน the USB cable และอื่นๆ). บิตนี้ถูกอ่าน/เขียนได้แต่มีเพียง '0 เท่านั้นสามารถถูกเขียนและการเขียน '1 ไม่มีผลอะไร.
Title: Re: STM32F1 USB
Post by: tha on April 10, 2021, 05:22:52 PM
Bit 12 WKUP: Wakeup
บิตนี้ถูกเซ็ตเป็น 1 โดย the hardware เมื่อ, ในระหว่าง suspend mode, กิจกรรมถูกตรวจพบว่าปลุก the USB peripheral. event นี้เคลียร๋แบบอซิงโครนัส the LP_MODE bit ใน the CTLR register และทำให้ทำงาน the USB_WAKEUP line, ซึ่งสามารถถูกใช้เพื่อแจ้งให้ทราบส่วนที่เหลือของ the device (อย่างเช่น wakeup unit) เกี่ยวกับการสตาร์ทของ the resume process. บิตนี้ถูกอ่าน/เขียนได้แต่มีเพียง '0 เท่านั้นสามารถถูกเขียนและการเขียน '1 ไม่มีผลอะไร.

Bit 11 SUSP: Suspend mode request
บิตนี้ถูกเซ็ตโดย the hardware เมื่อไม่มีการรับส่งข้อมูลถูกรับเป็นเวลา 3mS, แสดงให้เห็น a suspend mode request จาก the USB bus. The suspend condition check ถูกเปิดการใช้งานทันทีหลังจาก USB reset ใดๆและมันถูกปิดการใช้งานโดย the hardware เมื่อ the suspend mode ทำงาน (FSUSP=1) จนกระทั่ง the end of resume sequence. บิตนี้ถูกอ่าน/เขียนได้แต่มีเพียง '0 เท่านั้นสามารถถูกเขียนและการเขียน '1 ไม่มีผลอะไร.
Title: Re: STM32F1 USB
Post by: tha on April 11, 2021, 08:06:17 AM
Bit 10 RESET: USB reset request
เซ็ตเมื่อ the USB peripheral ตรวจพบ an active USB RESET signal ที่ inputs ของมัน. The USB peripheral, ในการตอบสนองต่อ a RESET, เพียงแค่รีเซ็ต internal protocol state machine ของมัน, สร้างขึ้น an interrupt ถ้า RESETM enable bit ใน the USB_CNTR register ถูกเซ็ต. Reception and transmission ถูกปิดการใช้งานจนกระทั่ง the RESET bit ถูกเคลียร์. All configuration registers ไม่รีเซ็ต: the microcontroller ต้องเคลียร์อย่างชัดแจ้ง registers เหล่านี้ (นี้เพื่อให้แน่ใจว่า the RESET interrupt สามารถถูกจัดส่งอย่างปลอดภัย, และ transaction ใดๆทันทีที่ตามด้วย a RESET สามารถถูกทำให้เสร็จสมบูรณ์). The function address and endpoint registers ถูกรีเซ็ตโดย an USB reset event.
บิตนี้ถูกอ่าน/เขียนได้แต่มีเพียง '0 เท่านั้นสามารถถูกเขียนและการเขียน '1 ไม่มีผลอะไร.
Title: Re: STM32F1 USB
Post by: tha on April 12, 2021, 07:31:10 AM
Bit 9 SOF: Start of frame
บิตนี้ส่งสัญญานจุดเริ่มต้นของ a new USB frame และมันถูกเซ็ตเมื่อ a SOF packet มาถึงผ่านทาง the USB bus. The interrupt service routine อาจมอนิเตอร์ the SOF events เพื่อให้มี a 1 mS synchronization event ไปยัง the USB host และเพื่อให้อ่านอย่างปลอดภัย the USB_FNR register ซึ่งถูกอัปเดตที่ the SOF packet reception (สิ่งนี้อาจมีประโยชน์สำหรับ isochronous applications).
บิตนี้ถูกอ่าน/เขียนได้แต่มีเพียง '0 เท่านั้นสามารถถูกเขียนและการเขียน '1 ไม่มีผลอะไร.
Title: Re: STM32F1 USB
Post by: tha on April 12, 2021, 07:57:25 AM
Bit 8 ESOF: Expected start of frame
บิตนี้ถูกเซ็ตโดย the hardware เมื่อ an SOF packet ถูกคาดหวังแต่ไม่ได้รับ. The host ส่ง an SOF packet แต่ละ mS, แต่ถ้า the hub ไม่ได้รับมันอย่างถูกต้อง, the Suspend Timer จะปล่อยออก interrupt นี้. ถ้า ESOF interrupts สามครั้งติดต่อกันถูกสร้างขึ้น (อย่างเช่น three SOF packets สูญหาย) โดยไม่มีการรับส่งข้อมูลใด ๆ เกิดขึ้นในระหว่างนี้, a SUSP interrupt จะถูกสร้างขึ้น. บิตนี้ถูกเซ็ตแม้เมื่อ the missing SOF packets เกิดขึ้นในขณะ the Suspend Timer ยังไม่ถูกล็อค.
บิตนี้ถูกอ่าน/เขียนได้แต่มีเพียง '0 เท่านั้นสามารถถูกเขียนและการเขียน '1 ไม่มีผลอะไร.

Bits 7:5 Reserved.
Title: Re: STM32F1 USB
Post by: tha on April 12, 2021, 08:52:10 AM
Bit 4 DIR: Direction of transaction
บิตนี้ถูกเขียนโดย the hardware สอดคล้องกับทิศทางของ the successful transaction, ซึ่งสร้าง the interrupt request.
ถ้า DIR bit=0, CTR_TX bit ถูกเซ็ตใน the USB_EPnR register ที่เกี่ยวข้องกับ the interrupting endpoint. The interrupting transaction เป็น IN type (data ถูกส่งโดย the USB peripheral ไปยัง the host PC).
ถ้า DIR bit=1, CTR_RX bit หรือทั้ง CTR_TX/CTR_RX ถูกเซ็ตใน the USB_EPnR register ที่เกี่ยวข้องกับ the interrupting endpoint. The interrupting transaction เป็น OUT type (data ถูกรับโดย the USB peripheral จาก the host PC) หรือ two pending transactions กำลังรอถูกปฏิบัติ.
information นี้สามารถถูกใช้โดย the application software เพื่อเข้าถึง the USB_EPnR bits ที่เกี่ยวข้องกับ the triggering transaction เนื่องจากมันแสดงถึง the direction ที่มี the interrupt pending. บิตนี้ถูกอ่านได้เพียงอย่างเดียว
Title: Re: STM32F1 USB
Post by: tha on April 24, 2021, 09:58:13 AM
Bits 3:0 EP_ID[3:0]: Endpoint Identifier
บิตเหล่านี้ถูกเขียนโดย the hardware สอดคล้องกับ the endpoint number, ซึ่งสร้าง the interrupt request. ถ้าหลาย endpoint transactions กำลังค้างอยู่, the hardware จะเขียน the endpoint identifier ที่เกี่ยวข้องกับ the endpoint ที่มี the highest priority ที่กำหนดในวิธีต่อไปนี้ : Two endpoint sets ถูกกำหนด, ตามลำดับของ priority: Isochronous และ double-buffered bulk endpoints จะถูกพิจารณาก่อนและจากนั้น endpoints อื่นถูกตรวจสอบ. ถ้ามากกว่าหนึ่ง endpoint จากชุดเดียวกันกำลังร้องขอ an interrupt, the EP_ID bits ใน USB_ISTR register ถูกกำหนดสอดคล้องกับ the lowest requesting endpoint register, EP0R จะมี the highest priority ตามด้วย EP1R และต่อไป. The application software สามารถกำหนด a register ไปยังแต่ละ endpoint สอดคล้องกับ priority scheme นี้, เพื่อจัดลำดับ the concurring endpoint requests ในวิธีที่เหมาะสม. บิตนี้ถูกอ่านได้เพียงอย่างเดียว.
Title: Re: STM32F1 USB
Post by: tha on April 24, 2021, 10:04:03 AM
USB frame number register (USB_FNR)

Address offset: 0x48
Reset value: 0x0XXX where X is undefined

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

Bit 15 RXDP: Receive data + line status
บิตนี้สามารถถูกใช้เพื่อสังเกตุ the status of received data บวกกับ upstream port data line. มันสามารถถูกใช้ในระหว่าง end-of-suspend routines เพื่อช่วยในการตัดสินใจ the wakeup event.

Bit 14 RXDM: Receive data - line status
บิตนี้สามารถถูกใช้เพื่อสังเกตุ the status of received data ลบ upstream port data line. มันสามารถถูกใช้ในระหว่าง end-of-suspend routines เพื่อช่วยในการตัดสินใจ the wakeup event.

Bit 13 LCK: Locked
บิตนี้ถูกเซ็ตโดย the hardware เมื่ออย่างน้อยสอง SOF packets ที่ติดต่อกันถูกรับแล้วหลังจาก the end of an USB reset condition หรือหลังจาก the end of an USB resume sequence. เมื่อถูกล็อค, the frame timer ยังคงอยู่ในสถานะนี้จนกระทั่ง an USB reset หรือ USB suspend event เกิดขึ้น.

Bits 12:11 LSOF[1:0]: Lost SOF
บิตเหล่านี้ถูกเขียนโดย the hardware เมื่อ an ESOF interrupt ถูกสร้างขึ้น, นับจำนวนของ SOF packets ที่ติดต่อกันที่หายไป. ที่การรับของ an SOF packet, บิตเหล่านี้จะถูกเคลียร์.

Bits 10:0 FN[10:0]: Frame number
bit field นี้บรรจุ the 11-bits frame number ที่บรรจุใน the last received SOF packet. The frame number ถูกเพิ่มขึ้นสำหรับทุกๆ frame ที่ส่งโดย the host และมันมีประโยชน์สำหรับ Isochronous transfers. bit field นี้ถูกอัปเดตบนการสร้างของ an SOF interrupt.
Title: Re: STM32F1 USB
Post by: tha on April 27, 2021, 09:28:02 AM
USB device address (USB_DADDR)

Address offset: 0x4C
Reset value: 0x0000

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

Bits 15:8 Reserved

Bit 7 EF: Enable function
บิตนี้ถูกเซ็ตโดย the software เพื่อเปิดการใช้งาน the USB device. The address ของ device นี้ถูกบรรจุใน ADD[6:0] bits ที่ตามมานี้. ถ้าบิตนี้เป็น '0 ไม่มี transactions ใดถูกจัดการ, โดยไม่คำนึงถึงการเซ็ตของ USB_EPnR registers.

Bits 6:0 ADD[6:0]: Device address
บิตเหล่านี้บรรจุ the USB function address กำหนดโดย the host PC ในระหว่าง the enumeration process. ทั้ง field นี้และ the Endpoint Address (EA) field ใน USB_EPnR register ที่เกี่ยวข้องต้องตรงกับ the information ที่บรรจุใน a USB token เพื่อจัดการ a transaction ไปยัง endpoint ที่ต้องการ.
Title: Re: STM32F1 USB
Post by: tha on April 27, 2021, 09:57:15 AM
Buffer table address (USB_BTABLE)

Address offset: 0x50
Reset value: 0x0000

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

Bits 15:3 BTABLE[15:3]: Buffer table
บิตเหล่านี้บรรจุ the start address ของ the buffer allocation table ภายใน the dedicated packet memory. table นี้อธิบายแต่ละ endpoint buffer location และขนาดและมันต้องถูกจัดแนวให้ตรงกับ an 8 byte boundary (the 3 least significant bits เป็น '0 เสมอ). ที่จุดเริ่มต้นของทุกๆ transaction ที่ส่งถึง device นี้, the USP peripheral อ่านองค์ประกอบของ table นี้ที่เกี่ยวข้องกับ the addressed endpoint, เพื่อให้ได้ buffer start location ของมันและ the buffer size (อ้างอิงถึง Structure and usage of packet buffers).

Bits 2:0 Reserved, forced by hardware to 0.
Title: Re: STM32F1 USB
Post by: tha on June 06, 2021, 07:50:24 AM
23.5.2 Endpoint-specific registers

จำนวนของ registers เหล่านี้แตกต่างกันไปสอดคล้องกับจำนวนของ endpoints ที่ the USB peripheral ถูกออกแบบเพื่อจัดการ. The USB peripheral รองรับได้สูงถึง 8 bidirectional endpoints. แต่ละ USB device ต้องรองรับ a control endpoint ซึ่ง address (EA bits) ต้องถูกเซ็ตเป็น 0. The USB peripheral จะทำงานในลักษณะที่ไม่ได้กำหนดไว้ถ้าหลาย endpoints ที่ถูกเปิดการใช้งานมี the same endpoint number value. สำหรับแต่ละ endpoint, an USB_EPnR register มีให้ใช้งานเพื่อเก็บ the endpoint specific information.

USB endpoint n register (USB_EPnR), n=[0..7]

Address offset: 0x00 to 0x1C
Reset value: 0x0000

(https://i.imgur.com/QHHFFkN.png)
Title: Re: STM32F1 USB
Post by: tha on June 15, 2021, 09:24:54 AM
มันยังถูกรีเซ็ตอีกด้วยเมื่อ an USB reset ถูกรับจาก the USB bus หรือถูกบังคับผ่านทาง bit FRES ใน the CTLR register, ยกเว้น the CTR_RX and CTR_TX bits, ซึ่งถูกเก็บไม่ให้เปลี่ยนเพื่อหลีกเลี่ยงการพลาด a correct packet notification ทันทีที่ถูกติดตามโดย an USB reset event. แต่ละ endpoint มี USB_EPnR register ของมันโดยที่ n คือ the endpoint identifier.

Read-modify-write cycles บน registers เหล่านี้ควรถูกหลีกเลี่ยงเนื่องจากในระหว่าง the read and the write operations บางบิตสามารถถูกเซ็ตโดย the hardware และ the next write จะแก้ไขมันก่อน the CPU จะมีเวลาที่จะตรวจพบการเปลี่ยนแปลงนี้. ดวยเหตุนี้, ทุกบิตที่ได้รับผลกระทบโดยปัญหานี้มีค่า 'คงที่' ที่ต้องถูกใช้เมื่อไรก็ตามที่การปรับเปลี่ยนของมันไม่ถูกต้องการ. ขอแนะนำให้แก้ไข registers เหล่านี้ด้วย a load instruction ที่บิตทั้งหมด, ซึ่งสามารถถูกแก้ไขเฉพาะโดย the hardware, ถูกเขียนด้วยค่า 'คงที่' ของมัน.
Title: Re: STM32F1 USB
Post by: tha on June 15, 2021, 10:33:39 AM
Bit 15 CTR_RX: Correct Transfer for reception
บิตนี้ถูกเซ็ตโดย the hardware เมื่อ an OUT/SETUP transaction ถูกทำให้สำเร็จเสร็จสมบูรณ์บน endpoint นี้; มีเพียง the software ที่สามารถเคลียร์บิตนี้. ถ้า the CTRM bit ใน USB_CNTR register ถูกเซ็ตอย่างสอดคล้อง, a generic interrupt condition ถูกสร้างขึ้นพร้อมด้วย the endpoint related interrupt condition, ซึ่งถูกเปิดใช้งานเสมอ. ชนิดของ transaction ที่เกิดขึ้น, OUT หรือ SETUP, สามารถถูกกำหนดจาก the SETUP bit ที่อธิบายข้างล่าง.
A transaction ที่สิ้นสุดด้วย a NAK หรือ STALL handshake ไม่เซ็ตบิตนี้t, เนื่องจากไม่มี data ถูกส่งถ่ายจริง, เช่นในกรณีของ protocol errors หรือ data toggle mismatches.
บิตนี้ถูก read/write แต่เฉพาะ '0 เท่านั้นที่สามารถถูกเขียน, การเขียน 1 ไม่มีผลอะไร.
Title: Re: STM32F1 USB
Post by: tha on June 15, 2021, 02:18:38 PM
Bit 14 DTOG_RX: Data Toggle, for reception transfers
ถ้า the endpoint ไม่ใช่ Isochronous, บิตนี้บรรจุค่าที่คาดไว้ของ the data toggle bit (0=DATA0, 1=DATA1) สำหรับ the next data packet ที่จะถูกรับ. Hardware สลับบิตนี้, เมื่อ the ACK handshake ถูกส่งไปยัง the USB host, ที่ตาม a data packet reception ที่มี a matching data PID value; ถ้า the endpoint ถูกกำหนดเป็น a control one, hardware เคลียร์บิตนี้ที่การรับของ a SETUP PID ที่ส่งถึง endpoint นี้
ถ้า the endpoint กำลังใช้ the double-buffering feature บิตนี้ถูกใช้เพื่อรองรับ packet buffer swapping ด้วย (อ้างอิงถึง Section 23.4.3).
ถ้า the endpoint เป็น Isochronous, บิตนี้ถูกใช้เฉพาะเพื่อรองรับ support packet buffer swapping เนื่องจากไม่มี data toggling ถูกใช้สำหรับ endpoints ประเภทนี้และมีเพียง DATA0 packet ที่ถูกส่ง (อ้างอิงถึง Section 23.4.4). Hardware สลับบิตนี้หลังจากการสิ้นสุดของ data packet reception, เนื่องจากไม่มี handshake ถูกใช้สำหรับ isochronous transfers
บิตนี้สามารถถูกสลับโดย the software เพื่อเริ่มต้นค่าของมันได้อีกด้วย (บังคับเมื่อ the endpoint ไม่ใช่ a control one) หรือเพื่อบังคับ specific data toggle/packet buffer usage. เมื่อ the application software เขียน '0, ค่านี้ของ DTOG_RX ยังคงไม่เปลี่ยน, ในขณะที่เขียน '1 ทำให้ค่าบิตนี้สลับ. บิตนี้ถูก read/write แต่มันสามารถสลับได้เฉพาะโดยการเขียน 1
Title: Re: STM32F1 USB
Post by: tha on June 15, 2021, 03:38:00 PM
Bits 13:12 STAT_RX [1:0]: Status bits, for reception transfers
บิตเหล่านี้บรรจุ information เกี่ยวกับ the endpoint status, ซึ่งถูกแสดงรายการไว้ใน Table 173. บิตเหล่านี้สามารถถูกสลับโดย software เพื่อเริ่มต้นค่าของมัน. เมื่อ the application software เขียน '0, ค่ายังคงไม่เปลี่ยน, ในขณะที่เขียน '1 ทำให้ค่าบิตนี้สลับ. Hardware เซ็ต the STAT_RX bits เป็น NAK เมื่อ a correct transfer เกิดขึ้นแล้ว (CTR_RX=1) ตรงกันกับ a OUT หรือ SETUP (control เท่านั้น) transaction ส่งถึง endpoint นี้, ดังนั้น the software มีเวลาอ่านรายละเอียด the received data ก่อนที่มัน acknowledge a new transaction.
Double-buffered bulk endpoints จัดให้มีใช้ a special transaction flow control, ซึ่งควบคุม the status บนฐานของ buffer availability condition (อ้างอิงถึง Section 23.4.3).
ถ้า the endpoint ถูกกำหนดเป็น Isochronous, status ของมันสามารถถูกเฉพาะ "VALID" หรือ "DISABLED", ดังนั้น the hardware ไม่สามารถเปลี่ยน the status ของ the endpoint หลังจาก a successful transaction. ถ้า the software เซ็ต the STAT_RX bits ไปเป็น 'STALL' หรือ 'NAK' สำหรับ an Isochronous endpoint, the USB peripheral behavior ไม่ถูกกำหนดได้. บิตเหล่านี้ถูก read/write แต่พวกมันสามารถสลับได้เฉพาะโดยการเขียน 1.
Title: Re: STM32F1 USB
Post by: tha on June 15, 2021, 04:17:47 PM
Bit 11 SETUP: Setup transaction completed
บิตนี้เป็นแบบอ่านอย่างเดียวและมันถูกเซ็ตโดย the hardware เมื่อ the last completed transaction เป็น a SETUP. บิตนี้เปลี่ยนค่าของมันเฉพาะสำหรับ control endpoints. มันต้องถูกตรวจสอบ, ในกรณีของ a successful receive transaction (CTR_RX event), เพื่อกำหนดชนิดของ transaction ที่เกิดขึ้น. เพื่อป้องกัน the interrupt service routine จากการเปลี่ยนใน SETUP bits เนื่องจาก next incoming tokens, บิตนี้ถูกเก็บแช่แข็งในขณะที่ CTR_RX bit อยู่ที่ 1; สภาพของมันเปลี่ยนเมื่อ CTR_RX อยู่ที่ 0. บิตนี้เป็นแบบอ่านอย่างเดียว.
Title: Re: STM32F1 USB
Post by: tha on June 16, 2021, 09:24:00 AM
Bits 10:9 EP_TYPE[1:0]: Endpoint type
บิตเหล่านี้กำหนดค่า the behavior ของ endpoint นี้ดังอธิบายใน Table 174. Endpoint 0 ต้องเป็น a control endpoint เสมอและแต่ละ USB function ต้องมีอย่างน้อยหนึ่ง control endpoint ซึ่งมี address 0, แต่อาจจะมี control endpoints อื่นๆหากจำเป็น. มีเพียง control endpoints ที่จัดการ SETUP transactions, ซึ่งจะถูกเพิกเฉยโดย endpoints ชนิดอื่นๆ. SETUP transactions ไม่สามารถถูกตอบรับด้วย NAK หรือ STALL. ถ้า a control endpoint ถูกกำหนดเป็น NAK, the USB peripheral จะไม่ตอบรับ, จำลอง a receive error, ใน the receive direction เมื่อ a SETUP transaction ถูกรับ. ถ้า the control endpoint ถูกกำหนดเป็น STALL ใน the receive direction, จากนั้น the SETUP packet จะถูกยอมรับอยู่ดี, ส่งถ่าย data และปล่อยออก the CTR interrupt. การรับของ OUT transactions ถูกจัดการในวิธีปกติ, แม้ว่า the endpoint จะเป็น a control endpoint ตัวหนึ่งก็ตาม.
Bulk และ interrupt endpoints มีพฤติกรรมที่คล้ายกันมากและพวกมันต่างกันเฉพาะใน the special feature มีให้ใช้โดยใช้ the EP_KIND configuration bit.
การใช้ของ Isochronous endpoints ถูกอธิบายใน Section 23.4.4
Title: Re: STM32F1 USB
Post by: tha on June 16, 2021, 11:00:51 AM
Bit 8 EP_KIND: Endpoint kind
ความหมายของบิตนี้ขึ้นอยู่กับ the endpoint type ที่กำหนดค่าโดย the EP_TYPE bits. Table 175 สรุปความหมายต่างๆ.
DBL_BUF: บิตนี้ถูกเซ็ตโดย the software เพื่อเปิดการใช้งาน the double-buffering feature สำหรับ bulk endpoint นี้. การใช้ของ double-buffered bulk endpoints ถูกอธิบายใน Section 23.4.3.
STATUS_OUT: บิตนี้ถูกเซ็ตโดย the software เพื่อแสดงให้เห็นว่า a status out transaction ที่ถูกคาดไว้: ในกรณีนี้ทุก OUT transactions ที่บรรจุมากกว่า zero data bytes ถูกตอบรับด้วย 'STALL' แทน 'ACK'. บิตนี้อาจถูกใช้เพื่อปรับปรุงความทนทานของ the application ต่อ protocol errors ในระหว่าง control transfers และการใช้ของมันถูกมุ่งหมายสำหรับ control endpoints เท่านั้น. เมื่อ STATUS_OUT ถูกรีเซ็ต, OUT transactions สามารถมีจำนวน bytes, ตามต้องการ.
Title: Re: STM32F1 USB
Post by: tha on June 16, 2021, 11:27:25 AM
Bit 7 CTR_TX: Correct Transfer for transmission
บิตนี้ถูกเซ็ตโดย the hardware เมื่อ an IN transaction ถูกทำให้สำเร็จเสร็จสมบูรณ์บน endpoint นี้; มีเพียง the software ที่สามารถเคลียร์บิตนี้. ถ้า the CTRM bit ใน the USB_CNTR register ถูกเซ็ตอย่างสอดคล้อง, a generic interrupt condition ถูกสร้างขึ้นพร้อมกันกับ the endpoint related interrupt condition, ซึ่งถูกเปิดใช้งานเสมอ.
A transaction ที่สิ้นสุดด้วย a NAK หรือ STALL handshake จะไม่เซ็ตบิตนี้, เนื่องจากไม่มี data ถูกส่งถ่ายจริงๆ, ดังในกรณีของ protocol errors หรือ data toggle mismatches.
บิตนี้ถูก read/write แต่มีเพียง '0 สามารถถูกเขียน.
Title: Re: STM32F1 USB
Post by: tha on June 16, 2021, 12:21:00 PM
Bit 6 DTOG_TX: Data Toggle, for transmission transfers
ถ้า the endpoint คือ non-Isochronous, บิตนี้บรรจุค่าที่จำเป็นของ the data toggle bit (0=DATA0, 1=DATA1) สำหรับ the next data packet ที่จะถูกส่ง. Hardware สลับบิตนี้, เมื่อ the ACK handshake ถูกรับจาก the USB host, ที่ตาม a data packet transmission. ถ้า the endpoint ถูกกำหนดเป็น a control one, hardware จะเซ็ตบิตนี้ที่การรับของ a SETUP PID ที่ส่งถึง endpoint นี้
ถ้า the endpoint กำลังใช้ the double-buffering feature บิตนี้ถูกใช้เพื่อรองรับ packet buffer swapping ด้วย (อ้างอิงถึง Section 23.4.3).
ถ้า the endpoint เป็น Isochronous, บิตนี้ถูกใช้เพื่อรองรับ support packet buffer swapping เนื่องจากไม่มี data toggling ถูกใช้สำหรับ endpoints ประเภทนี้และมีเพียง DATA0 packet ที่ถูกส่ง(อ้างอิงถึง Section 23.4.4). Hardware สลับบิตนี้หลังจากการสิ้นสุดของ data packet transmission, เนื่องจากไม่มี handshake ถูกใช้สำหรับ isochronous transfers
บิตนี้สามารถถูกสลับโดย the software เพื่อเริ่มต้นค่าของมันได้อีกด้วย (บังคับเมื่อ the endpoint ไม่ใช่ a control one) หรือเพื่อบังคับ specific data toggle/packet buffer usage. เมื่อ the application software เขียน '0, ค่านี้ของ DTOG_TX ยังคงไม่เปลี่ยน, ในขณะที่เขียน '1 ทำให้ค่าบิตนี้สลับ. บิตนี้ถูก read/write แต่มันสามารถถูกสลับได้เฉพาะโดยการเขียน 1.
Title: Re: STM32F1 USB
Post by: tha on June 16, 2021, 02:29:42 PM
Bits 5:4 STAT_TX [1:0]: Status bits, for transmission transfers
บิตเหล่านี้บรรจุ information เกี่ยวกับ the endpoint status, ถูกแสดงรายการไว้ใน Table 176. บิตเหล่านี้สามารถถูกสลับโดย software เพื่อเริ่มต้นค่าของมัน. เมื่อ the application software เขียน '0, ค่ายังคงไม่เปลี่ยน, ในขณะที่เขียน '1 ทำให้ค่าบิตนี้สลับ. Hardware เซ็ต the STAT_TX bits เป็น NAK เมื่อ a correct transfer เกิดขึ้นแล้ว (CTR_TX=1) ตรงกันกับ a IN หรือ SETUP (control เท่านั้น) transaction ที่ส่งถึง endpoint นี้, จากนั้นจะรอสำหรับ the software เตรียมชุดถัดไปของ data ที่จะถูกส่ง.
Double-buffered bulk endpoints จัดให้มีใช้ a special transaction flow control, ซึ่งควบคุม the status บนฐานของ buffer availability condition (อ้างอิงถึง Section 23.4.3).
ถ้า the endpoint ถูกกำหนดเป็น Isochronous, status ของมันสามารถถูกเป็นเฉพาะ "VALID" หรือ "DISABLED", ดังนั้น the hardware ไม่สามารถเปลี่ยน the status ของ the endpoint หลังจาก a successful transaction. ถ้า the software เซ็ต the STAT_TX bits ไปเป็น 'STALL' หรือ 'NAK' สำหรับ an Isochronous endpoint, the USB peripheral behavior จะไม่ถูกกำหนดได้. บิตเหล่านี้ถูก read/write แต่พวกมันสามารถสลับได้เฉพาะโดยการเขียน 1.
Title: Re: STM32F1 USB
Post by: tha on June 16, 2021, 03:43:10 PM
Bits 3:0 EA[3:0]: Endpoint address
Software ต้องเขียนใน field the 4-bit address นี้ถูกใช้เพื่อระบุ the transactions ที่ส่งไปยัง endpoint นี้. ค่าต้องเขียนก่อนการเปิดการใช้งาน the corresponding endpoint.

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

(https://i.imgur.com/O4Qf21D.png)
Title: Re: STM32F1 USB
Post by: tha on June 17, 2021, 08:22:41 AM
23.5.3 Buffer descriptor table

แม้ว่า the buffer descriptor table ถูกวางตำแหน่งไว้ภายใน the packet buffer memory, รายการของมันสามารถถูกพิจารณาเป็นดัง additional registers ที่ถูกใช้เพื่อกำหนดค่าตำแหน่งและขนาดของ the packet buffers ที่ถูกใช้เพื่อแลกเปลี่ยน data ระหว่าง the USB macro cell และ the STM32F10xxx. เนื่องจาก the common APB bridge limitation บน word addressability, ทุก packet memory locations ถูกเข้าถึงโดย the APB โดยใช้ 32-bit aligned addresses, แทนที่จะเป็น the actual memory location addresses ที่ใช้ประโยชน์โดย the USB peripheral สำหรับ the USB_BTABLE register และ buffer description table locations.

ในหน้าต่อไปนี้สอง location addresses ถูกรายงาน: ตัวที่หนึ่งถูกใช้โดย application software ในขณะที่เข้าถึง the packet memory, และภายในอีกตัวสัมพันธ์กับ USB Peripheral access. เพื่อให้ได้ the correct STM32F10xxx memory address value ที่ถูกใช้ใน the application software ในขณะที่เข้าถึง the packet memory, the actual memory location address ต้องถูกคูณด้วยสอง. The first packet memory location ถูกวางตำแหน่งที่ 0x4000 6000. The buffer descriptor table entry ที่เกี่ยวข้องกับ the USB_EPnR registers ถูกอธิบายข้างล่างนี้.

คำอธิบายโดยละเอียดของ packet buffers และ the buffer descriptor table usage สามารถถูกพบใน Structure and usage of packet buffers.

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

Bits 15:1 ADDRn_TX[15:1]: Transmission buffer address
บิตเหล่านี้ชี้ไปยัง the starting address ของ the packet buffer ที่บรรจุ data ที่จะถูกส่งโดย the endpoint ที่เกี่ยวข้องกับ the USB_EPnR register ที่ the next IN token จ่าหน้าถึงมัน.

Bit 0 ต้องถูกเขียนให้เป็น '0 เสมอเนื่องจาก packet memory เป็น word-wide และทุก packet buffers ต้องเป็น word-aligned.
Title: Re: STM32F1 USB
Post by: tha on June 17, 2021, 09:30:56 AM
(https://i.imgur.com/a33EUYl.png)

Bits 15:10 บิตเหล่านี้ไม่ถูกใช้เนื่องจาก packet size ถูกจำกัดโดย USB specifications เป็น 1023 bytes. ค่าของมันไม่ถูกพิจารณาโดย the USB peripheral.

Bits 9:0 COUNTn_TX[9:0]: Transmission byte count
บิตเหล่านี้บรรจุจำนวนของ bytes ที่จะถูกส่งโดย the endpoint ที่เกี่ยวข้องกับ the USB_EPnR register ที่ the next IN token จ่าหน้าถึงมัน.

Note: Double-buffered และ Isochronous IN Endpoints มีสอง USB_COUNTn_TX registers: ชื่อว่า USB_COUNTn_TX_1 และ USB_COUNTn_TX_0 โดยมีสิ่งที่บรรจุอยู่ภายในดังนี้

(https://i.imgur.com/RUU6tsc.png)
Title: Re: STM32F1 USB
Post by: tha on June 17, 2021, 10:05:01 AM
(https://i.imgur.com/MEbK1si.png)

Bits 15:1 ADDRn_RX[15:1]: Reception buffer address
บิตเหล่านี้ชี้ไปยัง the starting address ของ the packet buffer ซึ่งจะบรรจุ data ที่ถูกรับโดย the endpoint ที่เกี่ยวข้องกับ the USB_EPnR register ที่ the next OUT/SETUP token จ่าหน้าถึงมัน.

Bit 0 ต้องถูกเขียนให้เป็น '0 เสมอเนื่องจาก packet memory เป็น word-wide และทุก packet buffers ต้องเป็น word-aligned.
Title: Re: STM32F1 USB
Post by: tha on June 17, 2021, 10:53:51 AM
(https://i.imgur.com/lVc6iBC.png)

table location นี้ถูกใช้เก็บค่าที่ต่างกันสองค่า, ทั้งสองถูกต้องการในระหว่าง packet reception. The most significant bits บรรจุ the definition ของ allocated buffer size, เพื่อยอมให้ buffer overflow detection, ในขณะที่ the least significant part ของตำแหน่งนี้ถูกเขียนกลับโดย the USB peripheral ที่จุดสิ้นสุดของ reception เพื่อให้จำนวนจริงของ received bytes เนื่องจากข้อจำกัดเกี่ยวกับจำนวนบิตที่มีอยู่, buffer size ถูกแสดงโดยใช้จำนวนของ allocated memory blocks, ที่ block size สามารถถูกเลือกเพื่อเลือกการแลกเปลี่ยนระหว่าง fine-granularity/small-buffer และ coarse-granularity/large-buffer. ขนาดของ allocated buffer เป็นส่วนหนึ่งของ the endpoint descriptor และมันถูกกำหนดเป็นปกติในระหว่าง the enumeration process สอดคล้องกันกับ maxPacketSize parameter value ของมัน (ดู "Universal Serial Bus Specification").
Title: Re: STM32F1 USB
Post by: tha on June 17, 2021, 12:15:01 PM
Bit 15 BL_SIZE: BLock size
บิตนี้เลือกขนาดของ memory block ที่ใช้กำหนด the allocated buffer area.
– ถ้า BL_SIZE=0, the memory block มีขนาดใหญ่ 2 byte, ซึ่งเป็น block ขั้นต่ำที่ยอมให้ใน a word-wide memory. ด้วย block size นี้ the allocated buffer size มีย่านจาก 2 ถึง 62 bytes.
– ถ้า BL_SIZE=1, the memory block มีขนาดใหญ่ 32 byte, ซึ่งยอมให้ถึง the maximum packet length ที่ถูกกำหนดโดย USB specifications. ด้วย block size นี้ the allocated buffer size ย่านจาก 32 ถึง 1024 bytes, ซึ่งเป็นs the longest packet size ที่ถูกอนุญาติให้โดย USB standard specifications.

Bits 14:10 NUM_BLOCK[4:0]: Number of blocks
บิตเหล่านี้กำหนดจำนวนของ memory blocks ถูกจัดสรรเพื่อ packet buffer นี้. จำนวนจริงของ allocated memory ขึ้นอยู่กับ the BL_SIZE value ดังแสดงใน Table 177.

Bits 9:0 COUNTn_RX[9:0]: Reception byte count
บิตเหล่านี้บรรจุจำนวนของ bytes ที่ถูกรับโดย the endpoint ที่เกี่ยวข้องกับ the USB_EPnR register ในระหว่าง the last OUT/SETUP transaction จ่าหน้าถึงมัน.

Note: Double-buffered และ Isochronous IN Endpoints มีสอง USB_COUNTn_TX registers: ชื่อว่า USB_COUNTn_TX_1 และ USB_COUNTn_TX_0 โดยมีสิ่งที่บรรจุอยู่ภายในดังนี้

(https://i.imgur.com/002J0rm.png)

(https://i.imgur.com/WDc0agg.png)
Title: Re: STM32F1 USB
Post by: tha on June 17, 2021, 12:25:08 PM
(https://i.imgur.com/hmERII6.png)

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