STM32F7 6 General-purpose I/Os (GPIO)

Started by tha, October 25, 2022, 02:48:57 PM

Previous topic - Next topic

tha

6.3.5 I/O data bitwise handling

The bit set reset register (GPIOx_BSRR) คือ a 32-bit register ซึ่งยอมให้ the application สามารถ set และ reset แต่ละ individual bit ใน the output data register (GPIOx_ODR). The bit set reset register มีขนาดเป็นสองเท่าของ GPIOx_ODR.

สำหรับแต่ละบิตใน GPIOx_ODR, ตรงกันกับ two control bits ใน GPIOx_BSRR: BS(i) and BR(i). เมื่อ bit BS(i) ถูกเขียนเป็น 1, จะเซ็ต the corresponding ODR(i) bit. เมื่อ bit BR(i) ถูกเขียนเป็น 1, จะรีเซ็ต the ODR(i) corresponding bit.

การเขียนบิตใดๆเป็น 0 ใน GPIOx_BSRR ไม่มีผลใดๆ กับบิตที่ตรงกันใน GPIOx_ODR. ถ้ามีความพยายามทั้งเซ็ตและรีเซ็ต a bit ใน GPIOx_BSRR, the set action จะได้ priority.

การใช้ the GPIOx_BSRR register เพื่อเปลี่ยนค่าของ individual bits ใน GPIOx_ODR เป็น a "one-shot" effect ที่จะไม่ล็อค the GPIOx_ODR bits. The GPIOx_ODR bits สามารถถูกเข้าถึงได้โดยตรงเสมอ. The GPIOx_BSRR register จัดให้มีวิธีของการดำเนินการ atomic bitwise handling.

ไม่มีความจำเป็นสำหรับ the software ที่จะปิดใช้งาน interrupts เมื่อการโปรแกรม the GPIOx_ODR ที่ระดับบิต: เป็นไปได้ที่จะแก้ไขหนึ่งบิตหรือมากกว่าใน a single atomic AHB write access.

tha

6.3.6 GPIO locking mechanism

มันเป็นไปได้ที่จะแช่แข็ง the GPIO control registers โดยการนำมาใช้ a specific write sequence กับ the GPIOx_LCKR register. The frozen registers คือ GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.

เพื่อเขียน the GPIOx_LCKR register, a specific write / read sequence ต้องถูกนำมาใช้. เมื่อ the right LOCK sequence ถูกนำมาใช้กับ bit 16 ใน register นี้, the value of LCKR[15:0] จะถูกใช้เพือล็อค the configuration ของ the I/Os (ในระหว่าง the write sequence the LCKR[15:0] value ต้องเป็นเหมือนกัน). เมื่อ the LOCK sequence ถูกนำมาใช้กับ a port bit แล้ว, ค่าของ the port bit ไม่สามารถถูกแก้ไขได้อีกต่อไปจนกระทั่ง the next MCU reset หรือ peripheral reset. แต่ละ GPIOx_LCKR bit จะแช่แข็งบิตที่ตรงกันใน the control registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.

The LOCK sequence (ดูที่ Section 6.4.8: GPIO port configuration lock register (GPIOx_LCKR) (x = A to K)) สามารถถูกดำเนินการเฉพาะการใช้ a word (32-bit long) เข้าถึงไปยัง the GPIOx_LCKR register เนื่องจากความจริงที่ว่า GPIOx_LCKR bit 16 ต้องถูกเซ็ตในเวลาเดียวกันกับ the [15:0] bits.

สำหรับรายละเอียดเพิ่มเติมดูที่ LCKR register description ใน Section 6.4.8: GPIO port configuration lock register (GPIOx_LCKR) (x = A to K).

tha

6.3.7 I/O alternate function input/output

Two registers ถุกจัดให้มีเพื่อเลือกหนึ่งใน the alternate function inputs/outputs ที่มีให้ใช้งานสำหรับแต่ละ I/O. ด้วย registers เหล่านี้, ผู้ใช้สามารถต่อ an alternate function เข้ากับบาง pin อื่นๆได้ตามที่ต้องการโดย the application.

ซึ่งหมายความว่าจำนวนของ possible peripheral functions ถูกมัลติเพล็กซ์บนแต่ละ GPIO โดยใช้ the GPIOx_AFRL and GPIOx_AFRH alternate function registers. The application ดังนั้นสามารถเลือกตัวหนึ่งใดๆของ the possible functions สำหรับแต่ละ I/O. The AF selection signal คือร่วมกับ the alternate function input และ alternate function output, a single channel ถูกเลือกสำหรับ the alternate function input/output ของ a given I/O

เพื่อทราบซึ่ง functions ที่ถูกมัลติเพล็กซ์บนแต่ละ GPIO pin, ดูที่ the device datasheet


tha

6.3.8 External interrupt/wakeup lines

ทุก ports มี external interrupt capability. เพื่อใช้ external interrupt lines, the port ต้องถูกกำหนดค่าใน input mode. ดูที่ Section 11: Extended interrupts and events controller (EXTI) Section 11.3: Wakeup event management.

tha

6.3.9 Input configuration

เมื่อ the I/O port ถูกโปรแกรมเป็น input:
•   The output buffer ถูกปิดใช้งาน
•   The Schmitt trigger input ถูกทำให้ทำงาน
•   The pull-up and pull-down resistors ถูกทำให้ทำงานขึ้นอยู่กับ the value ใน the GPIOx_PUPDR register
•   The data ที่ปรากฎบน the I/O pin จะถูกสุ่มลงใน the input data register ทุกๆ AHB clock cycle
•   A read เข้าถึงไปยัง the input data register จัดให้มี the I/O state

Figure 19 แสดง the input configuration ของ the I/O port bit.


tha

6.3.10 Output configuration

เมื่อ the I/O port ถูกโปรแกรมเป็น output:
•   The output buffer ถูกเปิดใช้งาน:
     –   Open drain mode: A "0" ใน the Output register ทำให้ the N-MOS ทำงาน ในขณะที่ a "1" ใน the Output register
          จะทิ้ง the port ใน Hi-Z (the P-MOS ไม่เคยถูกทำให้ทำงาน)
     –   Push-pull mode: A "0" ใน the Output register ทำให้ the N-MOS ทำงาน ในขณะที่ a "1" ใน the Output register
          ทำให้ the P-MOS ทำงาน
•   The Schmitt trigger input ถูกทำให้ทำงาน
•   The pull-up and pull-down resistors ถูกทำให้ทำงานขึ้นอยู่กับ the value ใน the GPIOx_PUPDR register
•   The data ที่ปรากฎบน the I/O pin จะถูกสุ่มลงใน the input data register ทุกๆ AHB clock cycle
•   A read เข้าถึงไปยัง the input data register จะได้ the I/O state
•   A read เข้าถึงไปยัง the output data register จะได้ the last written value

Figure 20 แสดง the output configuration ของ the I/O port bit.


tha

6.3.11 Alternate function configuration

เมื่อ the I/O port ถูกโปรแกรมเป็น alternate function:
•   The output buffer สามารถถูกกำหนดค่าใน open-drain หรือ push-pull mode
•   The output buffer ถูกขับโดย the signals ที่มาจาก the peripheral (transmitter enable and data)
•   The Schmitt trigger input ถูกทำให้ทำงาน
•   The weak pull-up and pull-down resistors ถูกทำให้ทำงานหรือไม่ขึ้นอยู่กับ the value ใน the GPIOx_PUPDR register
•   The data ที่ปรากฎบน the I/O pin จะถูกสุ่มลงใน the input data register ทุกๆ AHB clock cycle
•   A read เข้าถึงไปยัง the input data register จะได้ the I/O state

Figure 21 แสดง the Alternate function configuration ของ the I/O port bit.


tha

6.3.12 Analog configuration

เมื่อ the I/O port ถูกโปรแกรมเป็น analog configuration:
•   The output buffer ถูกปิดใช้งาน
•   The Schmitt trigger input ถูกทำให้ไม่ทำงาน, จัดให้มี zero consumption สำหรับทุกๆ analog value ของ the I/O pin. The
     output ของ the Schmitt trigger ถูกบังคับให้เป็น a constant value (0).
•   The weak pull-up and pull-down resistors ถูกปิดใช้งานโดย hardware
•   Read เข้าถึงไปยัง the input data register จะได้ the value "0"

Figure 22 แสดง the high-impedance, analog-input configuration ของ the I/O port bits.