Download Print this page

Holtek HT32 MCU User Manual

Gpio
Hide thumbs Also See for HT32 MCU:

Advertisement

Quick Links

HT32 MCU GPIO User's Guide
D/N: AN0681EN
Introduction
The HT32 MCU's General Purpose Input/Output pins (GPIO) along with the Alternate Function
Input/Output Control Unit (AFIO) provide a range of different pin control interfaces. These MCU
pins can be configured through these interfaces to communicate with external devices via digital or
analog methods. The HT32 MCUs provide a wide array of I/O alternative options to expand the
GPIO's flexibility to provide a range of alternative functions. Additionally, the External
Interrupt/Event Controller (EXTI) can detect signal states via configurations and quickly execute
external interrupt/event handling tasks according to the required conditions.
This application note will introduce the HT32 MCU GPIOs, AFIO and EXTI. It will provide a
detailed explanation of registers and API usage for each function, as well as characteristics for the
related configuration limitations. The application note is aimed at helping users quickly understand
these features, and will also discuss considerations for I/O design, assisting users to complete their
relevant circuit design efficiently.
Terms and Abbreviations:
 AFIO: Alternate Function Input / Output Control Unit
 CKCU: Clock Control Unit
 ESD: Electrostatic Discharge
 EFT: Electrical Fast Transient
 EXTI: External Interrupt / Event Controller
 GPIO: General Purpose Input / Output
 NVIC: Nested Vectored Interrupt Controller
 POC: Power On Control
AN0681EN V1.00
HT32 MCU GPIO User's Guide
1 / 54
September 6, 2024

Advertisement

loading
Need help?

Need help?

Do you have a question about the HT32 MCU and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for Holtek HT32 MCU

  • Page 1 This application note will introduce the HT32 MCU GPIOs, AFIO and EXTI. It will provide a detailed explanation of registers and API usage for each function, as well as characteristics for the related configuration limitations.
  • Page 2 A, B, C, etc.) and "n" stands for the pin number (such as 0, 1, 2, etc.). The number of GPIO pins in each HT32 MCU for different package types can be found in the corresponding datasheet. Taking the HT32F52352 64-pin LQFP package as an example, there are up to 51 General Purpose I/O ports, GPIOs named PA0 ~ PA15, PB0 ~ PB8, PB10 ~ PB15, PC0 ~ PC15 and PD0 ~ PD3.
  • Page 3 Each pin in the HT32 MCUs has its own type, such as power supply [P], digital I/O pin [I/O], digital & analog I/O pin [AI/O], etc. The HT32 MCU GPIO architecture list is summarized in Table 1. Refer to the "Pin Assignment" in the corresponding datasheet for pin type confirmation and planning.
  • Page 4 For example: PB10 (X32KIN), PB11 (X32KOUT) and so on. Because the HT32 MCU design and package types are different, the pin classification may not be entirely the same across different MCUs and package types. To view the pin description of the MCU being used, refer to the pin description table in the pin assignment section of the corresponding device datasheet.
  • Page 5 HT32 MCU GPIO User’s Guide Figure 3. HT32F52352 Pin Description - Refer to the Datasheet The electrical characteristics of the HT32 MCU I/Os can be obtained from the device datasheet. Taking the HT32F52352 as an example, the Electrical Characteristics chapter describes multiple characteristics, such as Absolute Maximum Ratings, Recommended DC Operating Conditions, etc., as shown in Figure...
  • Page 6 HT32 MCU GPIO User’s Guide AFIO Basic Introduction In order to expand the flexibility of the GPIOs or the usage of the peripheral functions, each I/O pin can be configured to have different alternative functions such as GPIO, UART and ADC functions by programming the GPxCFGLR or GPxCFGHR registers, where x represents the different port name: A, B, C, etc.
  • Page 7 HT32 MCU GPIO User’s Guide  PxCFGn[3:0] = 0010: Alternative Function 2 (AF2) …  PxCFGn[3:0] = 1110: Alternative Function 14 (AF14)  PxCFGn[3:0] = 1111: Alternative Function 15 (AF15) The HT32F52352 's Alternative Function Mapping Example Table is shown in Figure 6. From the table, it can be seen that if AF2 is selected, the alternative function is ADC, while if AF5 is selected, the alternative function is SPI, etc.
  • Page 8 I/O pins.  Input When the HT32 MCU I/O pins are configured as inputs, one of the following three options must be selected. The Input area follows the HT32 MCU simplified GPIO Architecture Diagram and the Input area can be seen from the red box section in Figure 8: ...
  • Page 9 Figure 8. HT32 MCU Simple GPIO Architecture Diagram - Input Area  Output When the HT32 MCU I/O pins are configured as outputs, the Output Buffer must be set to either Push-Pull or Open-Drain output. Refer to the "Push-Pull" / "Open-Drain" chapter for details.
  • Page 10 Pull" and "Open-Drain" options.  Push-Pull When a HT32 MCU I/O is configured as a Push-Pull type, the Output Buffer is shown within the red dotted line in Figure 10. Here the Output Buffer uses two transistors, one PMOS and one NMOS.
  • Page 11 Figure 10. HT32 MCU Simplified GPIO Architecture Diagram - Output Area - Push-Pull  Open-Drain When a HT32 MCU I/O is configured as an Open-Drain, the Output Buffer is shown within the red dotted line in Figure 11. Here the Output Buffer uses an NMOS transistor and is composed of Output Control and an NMOS transistor.
  • Page 12  Pull-Up When the HT32 MCU I/O is configured as a Pull-Up, as shown in the red dashed part of Figure 12, then when the is turned on, this indicates that the I/O default level is high (V...
  • Page 13 Figure 12. HT32 MCU Simplified GPIO Architecture Diagram - Pull-up  Pull-Down When the HT32 MCU I/O is configured as aPull-down, as shown within the red dashed line in Figure 13, this indicates that the I/O default level is low (GND) once the Pull-down is enabled.
  • Page 14 HT32 MCU GPIO User’s Guide GPIO Register Introduction This chapter will introduce the HT32 MCU GPIO registers. These registers are introduced according to their six different GPIO modes described above. Note: The specification of different MCUs may be different and the available register resources may also be different.
  • Page 15 HT32 MCU GPIO User’s Guide Register PxDINR Register (Port x Data Input Register, where x = A, B, C, etc.) Descriptions This register specifies the GPIO Port x input data Bitmap Bits [15:0] Field PxDINn GPIO Port x Pin n Data Input Bits (n=0~15)
  • Page 16 HT32 MCU GPIO User’s Guide Register PxRR Register (Port x Output Reset Register, where x = A, B, C, etc.) Descriptions This register is used to reset the corresponding bit of the GPIO Port x output data Bitmap Bits [15:0]...
  • Page 17 HT32 MCU GPIO User’s Guide  Pull-Up/Pull-Down Related Register Register PxPUR Register (Port x Pull-Up Selection Register, where x = A, B, C, etc.) Descriptions This register is used to enable or disable the GPIO Port x pull-up function Bitmap...
  • Page 18 HT32 MCU GPIO User’s Guide Classification Descriptions GPIO Registers void GPIO_SetOutBits() Set the specified GPIO pin output data bit to 1 PxSRR\PxRR void GPIO_ClearOutBits() Clear the specified GPIO pin output data bit void GPIO_WriteOutBits() Set the specified GPIO pin output data bit to 1 or clear it...
  • Page 19 HT32 MCU GPIO User’s Guide u16 GPIO_ReadInData (HT_GPIO_TypeDef* HT_GPIOx) Function Obtain the specified GPIO pin output data Where HT_GPIOx is the GPIO selected from the GPIO peripherals. Input HT_GPIOx Note: This parameter can have one of the following values: HT_GPIOA, HT_GPIOB...
  • Page 20 HT32 MCU GPIO User’s Guide void GPIO_ClearOutBits (HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP) Function Clear the specified GPIO pin output data bit Where HT_GPIOx is the GPIO selected from the GPIO peripherals. HT_GPIOx Note: This parameter can have one of the following values: HT_GPIOA, HT_GPIOB...
  • Page 21 HT32 MCU GPIO User’s Guide  Pull-Up/Pull-Down Related API  PxPUR\PxPDR register void GPIO_PullResistorConfig (HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, GPIO_PR_Enum GPIO_PR_x) Function Configure the specified GPIO pin pull-up/down resistor Where HT_GPIOx is the GPIO selected from the GPIO peripherals. HT_GPIOx Note: This parameter can have one of the following values: HT_GPIOA, HT_GPIOB…...
  • Page 22 HT32 MCU GPIO User’s Guide FlagStatus PA0_Status = RESET; FlagStatus PA1_Status = RESET; /* Configure PA0, PA1 AFIO mode of GPIO */ AFIO_GPxConfig(GPIO_PA, AFIO_PIN_0, AFIO_FUN_GPIO); AFIO_GPxConfig(GPIO_PA, AFIO_PIN_1, AFIO_FUN_GPIO); /* Configure GPIO direction of input pins */ GPIO_DirectionConfig(HT_GPIOA, GPIO_PIN_0, GPIO_DIR_IN); GPIO_DirectionConfig(HT_GPIOA, GPIO_PIN_1, GPIO_DIR_IN);...
  • Page 23 HT32 MCU GPIO User’s Guide  Pull-Up & Pull-Down Priority Rules  Priority: Pull-Up > Pull-Down  If the Pull-up and Pull-down functions are both enabled on the same pin at the same time, the pull-up function has the higher priority while the pull-down function will have no effect.
  • Page 24 HT32 MCU GPIO User’s Guide Register PxLOCKR Register (Port x Lock Register, x = A, B, C, etc.) Descriptions This register specifies the GPIO Port x lock configuration Bitmap Bits [31:16] [15:0] Field PxLKEY PxLOCKn GPIO Port x Lock Key...
  • Page 25 GPIO pin lock function is disabled Table 34. API - GPIO_IsPinLocked() The following is an example to describe how to set the HT32 MCU GPIO Pin Lock function and its result. Refer to the HT32 MCU Firmware Library GPIO Pin Lock example.
  • Page 26 HT32 MCU GPIO User’s Guide  Refer to Table 37 for GPIO_Configuration() instruction. Function void GPIO_Configuration (void) Function Configure GPIO (PA1 and PA2) Description AFIO mode: GPIO Mode Default value: RESET Implement Pull resistance: Pull-Disable Setting Output drive current: 8mA...
  • Page 27 HT32 MCU GPIO User’s Guide Function void GPIO_LockStatus (void) Function Determine the specified GPIO Port and Pin lock state (PA1 and PA2) Description void GPIO_LockStatus(void) /* Port A Lock Status */ if (GPIO_IsPortLocked(HT_GPIOA) == TRUE) printf("GPIO Port A is Locked. \r\n");...
  • Page 28 HT32 MCU GPIO User’s Guide Function void GPIO_LockPinTest (void) void GPIO_LockPinTest(void) vu32 i, j; /* Change PA1 GPIO Configuration is invalid, because PA1 is locked */ /* PA1: (Output  Output) Mode, (Pull-Disable  Pull-Disable) */ GPIO_PullResistorConfig(HT_GPIOA, GPIO_PIN_1, GPIO_PR_UP); GPIO_DirectionConfig(HT_GPIOA, GPIO_PIN_1, GPIO_DIR_IN);...
  • Page 29  SWDIO: Input enable with internal pull-up  nRST Pin Internally Integrated Pull-up The HT32 MCU's nRST pin typically integrates an internal weak pull-up resistor (33V_PU) by default. Refer to the device datasheet for the internal weak pull-up resistance actual value. Taking the HT32F52352 as an example, the nRST pin internal weak pull-up resistance is about 46kΩ.
  • Page 30 HT32 MCU AFIO functions. AFIO Function Description For the HT32 MCU GPIOs, users can configure each pin to have an alternative function input/output for various peripherals such as a communication interface (SPI, USART/UART, I etc.), timer (GPTM, SCTM, MCTM, etc.), ADC, DAC, CMP, etc.
  • Page 31: Afio Register Description

    HT32 MCU GPIO User’s Guide AFIO Register Description This chapter will introducethe HT32 MCU AFIO registers. Since different MCUs may have different specifications and the available register resources might also differ, the following explanation of the AFIO registers is based on the HT32F52352 specification as an example.
  • Page 32 HT32 MCU GPIO User’s Guide AFIO API Description This chapter will introduce the AFIO API. In this chapter, users can quickly understand the AFIO API function and usage. Table 44 shows the AFIO API summary table. The detailed description of each API will be described later.
  • Page 33 HT32 MCU GPIO User’s Guide  ESSRx Register (x=0, 1) Function void AFIO_EXTISourceConfig (u32 GPIO_PIN_NUM_n, u32 GPIO_Px) Function Select the GPIO pin to be used as an EXTI channel Specify the GPIO pins to be configured GPIO_PIN_NUM_n Note: This parameter can have one of the following values: GPIO_PIN_NUM_n(n=0, 1, 2…)
  • Page 34 HT32 MCU GPIO User’s Guide  AFIO_EXTISourceConfig(): This API is used to select the specified GPIO pin as the EXTI trigger source. For example, using GPIO PA1 as the EXTI1 trigger source, the settings are shown in Table 50 below. Then refer to the “EXTI/NVIC API Usage Examples” section for detailed EXTI setting examples.
  • Page 35 HT32 MCU GPIO User’s Guide In the interrupt mode there are five trigger types. These are low level, high level, negative edge, positive edge and both edges. These are selected using the SRCnTYPE field in the EXTICFGRn (n=0~15) register. In the wake-up event mode, the wake-up event polarity can be configured by setting the EXTIWAKUPPOLR register.
  • Page 36 As shown in the red box in the figure below, the EXTI function is to be added to the "Figure 1- HT32 MCU Simplified GPIO Architecture Diagram" position. The EXTI function requires that the I/O status is obtained by reading the Data Input Register. Therefore, to use the EXTI, the Input Enable function needs to be enabled.
  • Page 37 MCUs, refer to the corresponding Datasheet for details. DDIO Figure 19. HT32 MCU Simplified GPIO Architecture Diagram - READ (EXTI) in Red Box (2) Interrupt trigger condition flag. An edge trigger requires writing a “1” to the corresponding flag...
  • Page 38 HT32 MCU GPIO User’s Guide Register EXTICFGRn Register - EXTI Interrupt Configuration Register n, n = 0~15 Descriptions This register is used to specify the debounce function and select the trigger type Bitmap Bits [31] [30:28] [15:0] Field DBnEN SRCnTYPE[2:0]...
  • Page 39 HT32 MCU GPIO User’s Guide Register EXTIEDGESR Register (EXTI Interrupt Edge Status Register) Descriptions This register indicates the polarity of a detected EXTI edge Bitmap Bits [15:0] Field EXTInEDS EXTIn Both Edge Detection Status (n=0~15) 0: Negative edge is detected...
  • Page 40: Exti_Channel

    HT32 MCU GPIO User’s Guide Register EXTIWAKUPPOLR Register (EXTI Interrupt Wakeup Polarity Register) Descriptions This register is used to select the EXTI line interrupt wakeup polarity Bitmap Bits [15:0] Field EXTInWPOL EXTIn Wakeup Polarity (n=0~15) Descriptions 0: EXTIn wakeup is high level active 1: EXTIn wakeup is low level active Table 58.
  • Page 41 HT32 MCU GPIO User’s Guide EXTI API Basic Configuration Before using the API function, the main program needs to perform an EXTI basic configuration. Table 61 illustrates the EXTI basic configuration. In this example, the EXTI channel 1 is enabled, the debounce function is enabled and the debounce count is configured to 0xFFFF.
  • Page 42: Output Set Reset

    HT32 MCU GPIO User’s Guide  Init / DeInit Function void EXTI_Init (EXTI_InitTypeDef* EXTI_InitStruct) Function Initialise the EXTI peripheral Input EXTI_InitStruct A pointer to the EXTI_InitTypeDef structure Table 63. EXTI API - EXTI_Init() Function void EXTI_DeInit (u32 EXTI_Channel) Function De-initialise the EXTI peripheral...
  • Page 43: Table Of Contents

    HT32 MCU GPIO User’s Guide  EXTIEDGEFLGR & EXTIEDGESR Register Function FlagStatus EXTI_GetEdgeStatus (u32 EXTI_Channel, u32 EXTI_Edge) Function Obtain the specified EXTI channel x edge state EXTI channel (0~15) Note: This parameter can have one of the following values: EXTI_CHANNEL_0...
  • Page 44 HT32 MCU GPIO User’s Guide  EXTIWAKUPCR Function void EXTI_WakeupEventIntConfig (ControlStatus NewState) Function Enable or disable EXTI channel x event wakeup interrupt Enable or disable Input NewState Note: This parameter can have one of the following values: ENABLE, DISABLE Table 71. EXTI API - EXTI_WakeupEventIntConfig() ...
  • Page 45 HT32 MCU GPIO User’s Guide Classification Description void NVIC_EnableIRQ() Enable the device specific interrupt in the NVIC interrupt controller Enable/disable void NVIC_DisableIRQ() Disable the device specific interrupt in the NVIC interrupt controller External Interrupt Return the device specific interrupt enable status from the NVIC interrupt...
  • Page 46 Table 83. NVIC API - NVIC_ClearPendingIRQ() EXTI/NVIC API Usage Examples In this chapter, the EXTI/NVIC API is illustrated through a simple modifications of the HT32 MCU Firmware Library example. This allows users to gain a better understanding of the EXTI/NVIC API usage through the example programs.
  • Page 47: Exti_Channel_14

    HT32 MCU GPIO User’s Guide /* Global functions -------------------------------------------------------------------------------------------------*/ int main(void) HT32F_DVB_LEDInit(HT_LED1); /* HT_LED1 Init */ CKCU_Configuration(); /* System Related configuration */ /* Configure PA1 pin as the input function and enable exti relate function */ EXTI_Configuration(); while (1) EXTI_MainRoutine();...
  • Page 48 HT32 MCU GPIO User’s Guide Function void EXTI_Configuration (void) void EXTI_Configuration(void) /* Configure AFIO mode of input pins */ AFIO_GPxConfig(GPIO_PA, AFIO_PIN_1, AFIO_FUN_GPIO); /* Enable GPIO Input Function */ GPIO_InputConfig(HT_GPIOA, GPIO_PIN_1, ENABLE); /* Configure GPIO pull resistor of input pins */ GPIO_PullResistorConfig(HT_GPIOA, GPIO_PIN_1, GPIO_PR_DISABLE);...
  • Page 49 HT32 MCU GPIO User’s Guide  EXTI0_1_IRQHandler(): EXTI 0~1 interrupt processing function, program examples and results are described in Table 88. Function void EXTI0_1_IRQHandler (void) Function EXTI 0~1 interrupt processing function Description extern vu32 guEXTIState[1]; void EXTI0_1_IRQHandler(void) if (EXTI_GetEdgeFlag(EXTI_CHANNEL_1)) Program Examples EXTI_ClearEdgeFlag(EXTI_CHANNEL_1);...
  • Page 50  Set unused I/O pins to the Push-Pull mode and output low using firmware. ESD Diode Description and Consideration The HT32 MCU GPIO architecture uses ESD protection diodes as shown in the red box in Figure 20. Therefore, when designing the circuit, special attention should be paid to avoid a situation where a high voltage (e.g., 3.3V) device is connected to the circuit when V...
  • Page 51 IOPOC starts operating and the HT32 MCU core voltage has been established. If the unknown signal on the PMOS Gate terminal of the output stage happens to be at a logic level“0”, and at this time, as long as the PMOS Source terminal voltage is higher than the PMOS Gate terminal voltage by 0.8V (PMOS conduction...
  • Page 52 HT32 MCU GPIO User’s Guide GPIO Recommended Configuration in the Low-Power Mode In order to avoid additional power consumption caused by unknown states or DC Paths, it is recommended that all I/O pins must have a fixed level (V or GND) when entering the Low-Power mode.
  • Page 53: Reference Files

    Figure 22. HT32F52352 EXTI Input Channel Selection - Refer to the User Manual Conclusion This application note has introduced the HT32 MCU GPIOs, AFIO, EXTI/NVIC in detail, and has given information on I/O design considerations. Users can quickly become familiar with the related use of HT32 MCU GPIOs using the information provided in this application note.
  • Page 54: Limitation Of Liability

    Information displayed at such sites. Hyperlinks to other websites are at your own risk. Limitation of Liability In no event shall Holtek Limited be liable to any other party for any loss or damage whatsoever or howsoever caused directly or indirectly in connection with your access to or use of this website, the content thereon or any goods, materials or services.