STM32F1 GPIO

Started by tha, November 15, 2020, 09:29:02 AM

Previous topic - Next topic

tha

9 General-purpose and alternate-function I/Os (GPIOs and AFIOs)
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.
ส่วนนี้ใช้กับตระกูล STM32F10xxx ทั้งหมดเว้นแต่จะระบุไว้เป็นอย่างอื่น

9.1 GPIO functional description
แต่ละของ the general-purpose I/O ports มี two 32-bit configuration registers (GPIOx_CRL, GPIOx_CRH), two 32-bit data registers (GPIOx_IDR, GPIOx_ODR), a 32-bit set/reset register (GPIOx_BSRR), a 16-bit reset register (GPIOx_BRR) และ a 32-bit locking register (GPIOx_LCKR).

ขึ้นอยู่กับ the specific hardware characteristics ของแต่ละ I/O port แสดงรายการใน the datasheet, แต่ละ port bit ของ the General Purpose IO (GPIO) Ports, สามารถถูกกำหนดค่าเฉพาะรายได้โดย software

ในหลายโหมด :
• Input floating
• Input pull-up
• Input-pull-down
• Analog
• Output open-drain
• Output push-pull
• Alternate function push-pull (หน้าที่ทางเลือกอื่น push-pull )
• Alternate function open-drain

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

Figure 13 แสดงโครงสร้างพื้นฐานของ an I/O Port bit.


1. VDD_FT เป็นศักยภาพเฉพาะสำหรับ I/Os ที่ทนต่อ 5 โวลต์และแตกต่างจาก VDD

tha


tha

9.1.1 General-purpose I/O (GPIO)
ระหว่างและเพิ่งหลังจากรีเซ็ต, the alternate functions จะไม่ทำงานและ the I/O ports ถูกกำหนดค่าใน Input Floating mode (CNFx[1:0]=01b, MODEx[1:0]=00b).

The JTAG pins อยู่ใน input PU/PD หลังจาก reset:
PA15: JTDI ใน PU
PA14: JTCK ใน PD
PA13: JTMS ใน PU
PB4: NJTRST ใน PU

เมื่อถูกกำหนดค่าเป็น output, ค่าที่เขียนไปยัง the Output Data register (GPIOx_ODR) ถูก output ไปบน the I/O pin. มันเป็นไปได้ที่จะใช้ the output driver ใน Push-Pull mode หรือ Open-Drain mode (มีเพียง the N-MOS ถูกทำให้ทำงานเมื่อ outputting 0).

The Input Data register (GPIOx_IDR) จับข้อมูลที่มีอยู่บน the I/O pin ทุกๆ APB2 clock cycle.

ทุก GPIO pins มี an internal weak pull-up และ weak pull-down ที่สามารถถูกทำให้ทำงานหรือไม่เมื่อกำหนดค่าเป็น input

9.1.2 Atomic bit set or reset
ไม่มีความจำเป็นต้องให้ the software ปิดการใช้งาน interrupts เมื่อโปรแกรม the GPIOx_ODR ที่ระดับบิต: มันเป็นไปได้ที่จะแก้ไขเพียงหนึ่งหรือหลายบิตใน a single atomic APB2 write access. นี้สำเร็จลงโดยการโปรแกรม '1' the Bit Set/Reset Register (GPIOx_BSRR, หรือสำหรับ reset เพียงอย่างเดียว GPIOx_BRR) เพื่อเลือกบิตที่จะแก้ไข. บิตที่ไม่ได้เลือกจะไม่ถูกแก้ไข

9.1.3 External interrupt/wakeup lines
ทุก ports มี external interrupt capability. เพื่อใช้ external interrupt lines, the port ต้องถูกกำหนดค่าใน input mode. สำหรับข้อมูลที่มากขึ้นบน external interrupts, อ้างอิงถึง Section 10.2: External interrupt/event controller (EXTI) และ Section 10.2.3: Wakeup event management.

9.1.4 Alternate functions (AF)
มันมีความจำเป็นต้องโปรแกรม the Port Bit Configuration Register ก่อนการใช้ a default alternate function.
•    สำหรับ alternate function inputs, the port ต้องถูกกำหนดค่าใน Input mode (floating, pullup หรือ pull-down) และ the
      input pin ต้องถูกขับจากภายนอก

Note: นอกจากนี้ยังสามารถที่จะเลียนแบบ the AFI input pin โดย software โดยการโปรแกรม the GPIO controller. ในกรณีนี้, the port ควรถูกกำหนดค่าใน Alternate Function Output mode. และเห็นได้ชัดวา, the corresponding port ไม่ควรถูกขับจากภายนอกเนื่องจากมันจะถูกขับโดย the software โดยใช้ the GPIO controller.

•    สำหรับ alternate function outputs, the port ต้องถูกกำหนดค่าใน Alternate Function Output mode (Push-Pull หรือ
      Open-Drain)
.
•    สำหรับ bidirectional Alternate Functions, the port bit ต้องถูกกำหนดค่าใน Alternate Function Output mode (Push-
     Pull หรือ Open-Drain). ในกรณีนี้ the input driver ถูกกำหนดค่าใน input floating mode

ถ้า a port bit ถูกกำหนดค่าเป็น Alternate Function Output, จะเป็นการยกเลิกการเชื่อมต่อ the output register และไปต่อ the pin นั้นไปยัง the output signal ของ an on-chip peripheral.

ถ้า software กำหนดค่า a GPIO pin เป็น Alternate Function Output, แต่ peripheral ไม่ถูกทำให้ทำงาน, output ของมันจะไม่ถูกระบุ.



tha

9.1.5 Software remapping(เปลี่ยนขา) of I/O alternate functions
เพื่อทำจำนวนของ peripheral I/O functions ให้เหมาะสำหรับ device packages ที่แตกต่างกัน, มันสามารถที่จะเปลี่ยนขา(remap) บาง alternate functions ไปยังบางพินอื่นๆ. นี้ถูกทำให้สำเร็จลงโดย software, โดยการโปรแกรม the corresponding registers (อ้างอิงถึง AFIO registers. ในกรณีนี้, the alternate functions จะไม่ถูก mapped เข้ากับการกำหนดเดิม(original assignations)อีกต่อไป

9.1.6 GPIO locking mechanism
The locking mechanism ยอมให้ the IO configuration ถูกตรึง. เมื่อ the LOCK sequence ถูกนำไปใช้กับ a port bit, มันจะไม่สามารถแก้ไขค่าของ the port bit ได้อีกต่อไปจนกว่า the next reset.

tha

9.1.7 Input configuration
เมื่อ the I/O Port ถูกโปรแกรมเป็น Input:
•    The Output Buffer ถูกปิดการใช้งาน
•    The Schmitt Trigger Input ถูกทำให้ทำงาน
•    The weak pull-up และ pull-down resistors ถูกทำให้ทำงานหรือไม่ขึ้นอยู่กับ input configuration (pull-up, pull-down or
      floating):
•    The data ที่มีบน the I/O pin ถูกสุ่มเข้าไปยัง the Input Data Register ทุกๆ APB2 clock cycle
•    A read เข้าถึงไปยัง the Input Data Register จะได้รับ the I/O State.

Figure 15 แสดง the Input Configuration ของ the I/O Port bit.


1. VDD_FT เป็นศักยภาพเฉพาะสำหรับ I/Os ที่ทนต่อ 5 โวลต์และแตกต่างจาก VDD

tha

9.1.8 Output configuration
เมื่อ the I/O Port ถูกโปรแกรมเป็น Output:
•    The Output Buffer ถูกเปิดการใช้งาน:
      – Open Drain Mode: A "0" ใน the Output register ทำให้ the N-MOS ทำงาน ขณะที่ "1" ใน the Output register ทำให้
      the port อยู่ในสถานะอิมพิแด๊นต์สูง (Hi-Z )(the P-MOS จะไม่ถูกทำให้ทำงานเลย)
      ( Open Drain นี้จะต้องมี power supply ภายนอกมาต่อกัย load แล้วอีกขาหนึ่งของ load ก็มาต่อที่ output pin อีกที คือจะลงกราว
      น์ภายในตัว mcu )
      – Push-Pull Mode: A "0" in the Output register ทำให้ the N-MOS ทำงาน ขณะที่ "1" ใน the Output register ทำให้ P-
      MOS ทำงาน
      ( mcu จะเป็นตัวจ่ายไฟให้ load ภายนอก)
•    The Schmitt Trigger Input ถูกทำให้ทำงาน
•    The weak pull-up and pull-down resistors ถูกปิดการใช้งาน.
•    The data ที่แสดงบน  I/O pin จะถูกสุ่มเข้าไปใน Input Data Register ทุกๆ APB2 clock cycle
•    A read เข้าถึงไปยัง the Input Data Register จะได้รับ the I/O state ใน open drain mode
•    A read เข้าถึงไปยัง the Output Data register จะได้รับค่าที่เขียนเป็นครั้งสุดท้ายใน Push-Pull mode

Figure 16 แสดง the Output configuration of the I/O Port bit.


1. VDD_FT เป็นศักยภาพเฉพาะสำหรับ I/Os ที่ทนต่อ 5 โวลต์และแตกต่างจาก VDD

tha

9.1.9 Alternate function configuration
เมื่อ the I/O Port ถูกโปรแกรมเป็น Alternate Function:
•    The Output Buffer ถูก turned on ใน Open Drain หรือ Push-Pull configuration
•    The Output Buffer ถูกขับโดย the signal ที่มาจาก the peripheral (alternate function out)
•    The Schmitt Trigger Input ถูกทำให้ทำงาน
•    The weak pull-up and pull-down resistors ถูกปิดการใช้งาน.
•    The data ที่แสดงบน  I/O pin จะถูกสุ่มเข้าไปใน Input Data Register ทุกๆ APB2 clock cycle
•    A read เข้าถึงไปยัง the Input Data Register จะได้รับ the I/O state ใน open drain mode
•    A read เข้าถึงไปยัง the Output Data register จะได้รับค่าที่เขียนเป็นครั้งสุดท้ายใน Push-Pull mode

Figure 17 แสดง the Alternate Function Configuration of the I/O Port bit. นอกจากนี้, อ้างอิงถึง Section 9.4: AFIO registers สำหรับข้อมูลเพิ่มเติม

ชุดของ Alternate Function I/O registers ยอมให้ผู้ใช้เปลี่ยนขา(remap) บาง alternate functions ไปยัง different pins. อ้างอิงถึง Section 9.3: Alternate function I/O and debug configuration (AFIO).


1. VDD_FT เป็นศักยภาพเฉพาะสำหรับ I/Os ที่ทนต่อ 5 โวลต์และแตกต่างจาก VDD

tha

9.1.10 Analog configuration
เมื่อ the I/O Port ถูกโปรแกรมเป็น Analog configuration:
•    The Output Buffer ถูกปิดการใช้งาน.
•    The Schmitt Trigger Input ถูกทำให้ไม่ทำงานจัดให้มีการกินพลังงานเป็นศูนย์สำหรับทุกๆ analog value ของ the I/O pin. The
      output ของ the Schmitt Trigger ถูกบังคับให้เป็นค่าคงที่ (0).
•    The weak pull-up and pull-down resistors ถูกปิดการใช้งาน.
•    Read เข้าถึงไปยัง the Input Data Register จะได้รับ the value "0".

Figure 18 แสดง the high impedance-analog configuration of the I/O Port bit.