STM32F1 USB

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

Previous topic - Next topic

tha

ตามที่มันเกิดขึ้นกับ 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.

tha

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.

tha

ขั้นตอนจริงที่ใช้แขวน 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.


tha

เมื่อ 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.

tha

ต่อไปนี้คือรายการของการปฏิบัติ 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 ถ้าเปิดการใช้งาน, ซึ่งควรถูกจัดการตามปกติ.



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.

tha

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).

tha

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



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.

tha

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 ตามที่อธิบายข้างล่าง.