STM32F7 6 General-purpose I/Os (GPIO)

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

Previous topic - Next topic

tha

6 General-purpose I/Os (GPIO)

6.1 Introduction

แต่ละ general-purpose I/O port มี four 32-bit configuration registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR and GPIOx_PUPDR), two 32-bit data registers (GPIOx_IDR and GPIOx_ODR) และ a 32-bit set/reset register (GPIOx_BSRR). นอกจากนี้ทุก GPIOs มี a 32-bit locking register (GPIOx_LCKR) และ two 32-bit alternate function selection registers (GPIOx_AFRH and GPIOx_AFRL).

tha

6.2 GPIO main features

•   Output states: push-pull หรือ open drain + pull-up/down
•   Output data จาก output data register (GPIOx_ODR) หรือ peripheral (alternate function output)
•   Speed selection สำหรับแต่ละ I/O
•   Input states: floating, pull-up/down, analog
•   Input data ไปยัง input data register (GPIOx_IDR) หรือ peripheral (alternate function input)
•   Bit set and reset register (GPIOx_ BSRR) สำหรับ bitwise write access ไปยัง GPIOx_ODR
•   Locking mechanism (GPIOx_LCKR) ถูกจัดให้มีเพื่อแช่แข็ง the I/O port configurations
•   Analog function
•   Alternate function selection registers
•   Fast toggle capable ของการเปลี่ยนทุกๆ two clock cycles
•   Highly flexible pin multiplexing ช่วยให้การใช้ของ I/O pins เป็น GPIOs หรือเป็นหนึ่งใน several peripheral functions

tha

6.3 GPIO functional description

ขึ้นอยู่กับ the specific hardware characteristics ของแต่ละ I/O port ที่แสดงรายการใน the datasheet, แต่ละ port bit ของ the general-purpose I/O (GPIO) ports สามารถถูกกำหนดค่าเป็นรายๆไปโดย software ในหลายโหมด:
•   Input floating
•   Input pull-up
•   Input-pull-down
•   Analog
•   Output open-drain ที่มี pull-up or pull-down capability
•   Output push-pull ที่มี pull-up or pull-down capability
•   Alternate function push-pull ที่มี pull-up or pull-down capability
•   Alternate function open-drain ที่มี pull-up or pull-down capability

แต่ละ I/O port bit สามารถตั้งโปรแกรมได้อย่างอิสระ, อย่างไรก็ตาม the I/O port registers ต้องถูกเข้าถึงเป็น 32-bit words, half-words or bytes. วัตถุประสงค์ของ the GPIOx_BSRR and GPIOx_BRR registers คือยอมให้ atomic read/modify เข้าถึงไปยังบิตใดๆของ the GPIOx_ODR registers. ด้วยวิธีนี้, ไม่มีความเสี่ยงของ an IRQ เกิดขึ้นระหว่าง the read และ the modify access.

Figure 17 and Figure 18 แสดงโครงสร้างพื้นฐานของ a standard และ a 5-Volt tolerant I/O port bit, ตามลำดับ. Table 22 ให้ the possible port bit configurations.






tha

6.3.1 General-purpose I/O (GPIO)

ในระหว่างและหลังจาก reset, the alternate functions จะไม่ทำงานและส่วนมากของ the I/O ports ถูกกำหนดค่าใน input floating mode.

The debug pins อยู่ใน AF pull-up/pull-down หลังจาก reset:
•   PA15: JTDI in pull-up
•   PA14: JTCK/SWCLK in pull-down
•   PA13: JTMS/SWDAT in pull-up
•   PB4: NJTRST in pull-up
•   PB3: JTDO in floating state

เมื่อ the pin ถูกกำหนดค่าเป็น output, the value ที่เขียนไปยัง the output data register (GPIOx_ODR) จะถูกส่งออกไปบน the I/O pin. มันสามารถเป็นได้ที่จะใช้ the output driver ใน push-pull mode หรือ open-drain mode (เฉพาะ the low level เท่านั้นที่ถูกขับ, high level เป็น HI-Z).

The input data register (GPIOx_IDR) จับ the data ที่ปรากฎบน the I/O pin ที่ทุกๆ AHB clock cycle.

ทุก GPIO pins มี weak internal pull-up and pull-down resistors, ซึ่งสามารถถูกทำให้ทำงานหรือไม่ขึ้นอยู่กับ the value ใน the GPIOx_PUPDR register.

tha

6.3.2 I/O pin alternate function multiplexer and mapping

The device I/O pins ถูกต่อเข้ากับ on-board peripherals/modules ผ่านทาง a multiplexer ที่ยอมให้เฉพาะ one peripheral alternate function (AF) ต่อกับ an I/O pin ในแต่ละครั้ง. ด้วยวิธีนี้, จะไม่มีข้อขัดแย้งระหว่าง peripherals ที่มีให้ใช้งานบน the same I/O pin.

แต่ละ I/O pin มี a multiplexer ที่มีมากถึง sixteen alternate function inputs (AF0 to AF15) ที่สามรถถูกกำหนดค่าผ่านทาง the GPIOx_AFRL (สำหรับ pin 0 ถึง 7) และ GPIOx_AFRH (สำหรับ pin 8 ถึง 15) registers:
•   หลังจากรีเซ็ต the multiplexer selection คือ alternate function 0 (AF0). The I/Os ถูกกำหนดค่าใน alternate function
     mode ผ่านทาง GPIOx_MODER register.
•   The specific alternate function assignments สำหรับแต่ละ pin ถูกให้รายละเอียดใน the device datasheet.
•   Cortex-M7 ที่มี FPU EVENTOUT ถูกแม็ปบน AF15

นอกเหนือจาก flexible I/O multiplexing architecture นี้, แต่ละ peripheral มี alternate functions ที่แม็ปเข้ากับ different I/O pins เพื่อปรับให้ดีขึ้น the number of peripherals ที่มีให้ใช้งานใน smaller packages

tha

เพื่อใช้ an I/O ในการกำหนดค่าที่ให้, ผู้ใช้ต้องดำเนินการดังต่อไปนี้:
•   Debug function: หลังจากแต่ละ device reset พินเหล่านี้จะถูกกำหนดเป็น alternate function pins สามารถใช้ได้โดยทันทีโดย
     the debugger host
•   System function: MCOx pins ต้องถูกกำหนดค่าใน alternate function mode.
•   GPIO: กำหนดค่า the desired I/O เป็น output, input or analog ใน the GPIOx_MODER register.
•   Peripheral alternate function:
     –   ต่อ the I/O เข้ากับ the desired AFx ในหนึ่งของ the GPIOx_AFRL or GPIOx_AFRH register.
     –   เลือกประเภท, pull-up/pull-down and output speed โดยทาง the GPIOx_OTYPER, GPIOx_PUPDR and
          GPIOx_OSPEEDER registers, ตามลำดับ.
     –   กำหนดค่า the desired I/O เป็น an alternate function ใน the GPIOx_MODER register
•   Additional functions:
     –   สำหรับ the ADC and DAC, กำหนดค่า the desired I/O ใน analog mode ใน the GPIOx_MODER register และกำหนด
          ค่า the required function ใน the ADC and DAC registers. สำหรับ the additional functions อย่าง RTC_OUT,
          RTC_TS, RTC_TAMPx, WKUPx and oscillators, กำนหดค่า the required function ใน the related RTC, PWR and
          RCC registers. ฟังชั่นเหล่านี้มี priority เหนือ the configuration ใน the standard GPIO registers. สำหรับรายละเอียด
          เกี่ยวกับ I/O ที่ควบคุมโดย the RTC, ดูที่ Section 29.3: RTC functional description บนหน้า 915.
•   EVENTOUT
     –   กำหนดค่า the I/O pin ที่ใช้เพื่อเอ๊าพุท the core EVENTOUT signal โดยการต่อมันเข้ากับ AF15

ดูที่ the "Alternate function mapping" table ใน the device datasheet สำหรับรายละเอียดการแม็ปของ the alternate function I/O pins.

tha

6.3.3 I/O port control registers

แต่ละ the GPIO ports มี four 32-bit memory-mapped control registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR) เพื่อกำหนดค่ามากถึง 16 I/Os. The GPIOx_MODER register ถูกใช้เพื่อเลือก the I/O mode (input, output, AF, analog). The GPIOx_OTYPER and GPIOx_OSPEEDR registers ถูกใช้เพื่อเลือก the output type (pushpull หรือ open-drain) and speed. The GPIOx_PUPDR register ถูกใช้เพื่อเลือก the pullup/pull-down ตาม the I/O direction.

tha

6.3.4 I/O port data registers

แต่ละ GPIO มี two 16-bit memory-mapped data registers: input and output data registers (GPIOx_IDR and GPIOx_ODR). GPIOx_ODR จะเก็บ the data ที่จะถูกส่งออก, มันเป็น read/write accessible. The data input ผ่านทาง the I/O จะถูกเก็บลงใน the input data register (GPIOx_IDR), a read-only register.

ดู Section 6.4.5: GPIO port input data register (GPIOx_IDR) (x = A to K) และ
Section 6.4.6: GPIO port output data register (GPIOx_ODR) (x = A to K) สำหรับ the register descriptions.