Pin Mux and Control

Pin Mux

Overview

Due to the limited number of pins, to enhance design flexibility, this chip provides pin multiplexing (Pinmux) functionality. The signals of internal IP modules can be flexibly mapped to designated pins through configuration.

For the specific mapping between pins and IP circuits, refer to the Pin Mux Table.

The pin multiplexing table provides the following key information:

  • Pin distribution for different part numbers

  • On-chip peripheral signals that each pin can be connected to

  • Trap Pin assignment latched at power-on

  • Default pin assignment of the J-Link debug interface (SWD)

  • Default pin assignment of the serial port (LOGUART) used for firmware download, command interaction, and logging

  • Power supply information for each I/O port, etc.

Function Mux

RTL8721Dx:

Usage

Developers can call the programming interface Pinmux_Config(PinName, PinFuncID) to connect on-chip peripheral signals to specified pins.

Parameter description:

PinName:

Pin identifier

PinFuncID:

Specified signal ID of the on-chip peripheral controller

Based on the configured Function ID, a pin can either output internal chip signals to external devices or receive external device signals into internal chip modules.

For the mapping between Function IDs and pins, refer to the Pinmux Table.

Function Group Types

  • Dedicated Pin Function Group:

    • Feature: Specific peripheral signals can only be mapped to the corresponding dedicated pins. Although the number of configurable functions is relatively limited, this dedicated design fully utilizes the performance of each IP module, meeting peripheral signal quality and rate performance requirements.

    • Function Group: Dedicated pins are typically organized by “function groups”, where each function group contains a set of related pins.

    • Configuration Principle: Pins within the same function group must be selected to achieve optimal performance.

  • Full-Matrix Pin Function Group:

    Feature: Peripheral signals can be flexibly mapped to multiple pins, providing greater configuration freedom, but the performance of some IP modules (such as maximum transfer rate) is relatively limited.

Function ID

  • Function ID 0~{{IC_PARAM_FUNCID_DEDICATE_END}}

    When the Function ID is 0~{{IC_PARAM_FUNCID_DEDICATE_END}}, dedicated pins must be used.

    Note

    For example: Function ID {{IC_PARAM_FUNCID_DEDICATE_SPI0}} and Function ID {{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CLK}}~{{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CS}} are both SPI functions.

    • Function ID {{IC_PARAM_FUNCID_DEDICATE_SPI0}} uses dedicated pins, so the maximum rate for SPI can reach 50 MHz (master mode);

    • Function ID {{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CLK}}~{{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CS}} uses full-matrix pins, and the maximum achievable rate is only 25 MHz (master mode).

    Taking PB30 as an example: if its Function ID is configured as 1, the UART1_RXD signal of UART1 will be directly connected to this pin through pin multiplexing.

    ../../_images/dplus_schematic_diagram_of_pinmux_dedicate_of_PB30.svg

    Schematic diagram of pinmux connection for PB30

  • Function ID {{IC_PARAM_FUNCID_FULL_MATRIX_START}}~{{IC_PARAM_FUNCID_FULL_MATRIX_END}}

    When the Function ID is {{IC_PARAM_FUNCID_FULL_MATRIX_START}}~{{IC_PARAM_FUNCID_FULL_MATRIX_END}}, full-matrix pins must be used.

    Taking PA27 as an example:

    • When PA27’s Function ID is configured as 19, the UART0_TXD signal of UART0 can be connected to PA27;

    • When PA27’s Function ID is configured as 20, the UART0_RXD signal of UART0 can be connected to this pin.

    ../../_images/dplus_schematic_diagram_of_pinmux_fullmatrix_of_PA27.svg

    Schematic diagram of pinmux connection for PA27

Trap Pins

Note

Before development, please pay attention to the following pin multiplexing considerations to avoid unexpected behavior.

During the power-on process, the chip’s internal circuitry latches the voltage levels of certain pins to determine the operating mode of the chip. Therefore, when designing hardware or using development boards, configure them correctly according to the hardware design guide for the corresponding chip to avoid abnormal operation. After startup is complete, Trap Pins behave the same as other pins and can be configured for other functions normally.

RTL8721Dx:

Pin Name

Symbol

Active Level

Description

PB31

TM_DIS

Low

  • Disable test mode, internal pull-up by default

  • This pin is for internal testing only; it should remain at logic high during normal operation

    • 1: Normal operation mode

    • 0: Test mode

PB5

UD_DIS

Low

  • Disable UART download mode, internal pull-up by default

    • 1: Enter normal boot mode

    • 0: Enter UART download mode

Note

Disabling the download mode is controlled by OTP-related fields. When UART download is disabled via OTP, the power-on latch state of this pin is invalid.

Note

Please configure the external pull-up/pull-down resistors for each Trap Pin correctly to ensure the pin logic levels during power-on meet expectations. Refer to the datasheet for details.

Wakeup Pins

RTL8721Dx:
  • Regular GPIO pins support waking the system from CG and PG sleep modes.

  • Wake pins ( PB30 and PB31 ) are directly connected to the wake-up circuit; in addition to waking from CG and PG sleep modes, they can also wake the system from deep sleep mode.

Warning

  • If these pins need to be configured for other peripheral functions, disable the wake-up function first to avoid accidental wake-up triggered by pin signal changes.

  • Wake pins may be multiplexed with Trap pins. When multiplexed, ensure that the logic level of the Trap pin after wake-up does not cause the system to enter an unintended operating mode.

Note

For specific configuration methods of the wakeup function (such as enabling/disabling wakeup sources, configuring wakeup trigger conditions, etc.), refer to the Power Saving section.

SWD Pins

RTL8721Dx:

{{IC_PARAM_SWD_CLK_PIN}} and {{IC_PARAM_SWD_DATA_PIN}} are the default pins for the SWD debug interface.

Note

When the following log message appears, it indicates that the {{IC_PARAM_SWD_CLK_PIN}} or {{IC_PARAM_SWD_DATA_PIN}} pin has already been configured to another module, and it is no longer possible to connect to the debugger through that pin.

SWD PAD PortX_PinYY is configured to funcIDZZ

If you still need to connect a debugger, refer to Function Mux to reconfigure the pin for the SWD signal.

Raw API

PINMUX Exported Constants

PINMUX Peripheral Location Definitions
/* Peripheral pinmux location selection 0. */
#define PINMUX_S0 (0)

/* Peripheral pinmux location selection 1. */
#define PINMUX_S1 (1)

/* Peripheral pinmux location selection 2. */
#define PINMUX_S2 (2)

/* Peripheral pinmux location selection 3. */
#define PINMUX_S3 (3)

/* Peripheral pinmux location selection 4. */
#define PINMUX_S4 (4)

/* Peripheral pinmux location selection 5. */
#define PINMUX_S5 (5)
PINMUX Port and Pin Definitions
/* Extract port number from pin name. */
#define PORT_NUM ((pin>>5) & 0x03)

/* Extract pin number from pin name. */
#define PIN_NUM (pin & 0x1f)

PINMUX Exported Functions

void Pinmux_Config(u8 PinName, u32 PinFunc)

Set the function type of one pin.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • PinFunc – The function type for the pin, value of PINMUX_Function_definitions.

u32 Pinmux_ConfigGet(u8 PinName)

Get the function type of one pin.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

Returns:

The function type for the pin, value of PINMUX_Function_definitions.

void Pinmux_Swdoff(void)

Turn off pinmux SWD function.

Note

When multiplexing shared SWD pins to other functions, this function must be called.

Pin Control

Overview

Depending on user requirements, the chip’s I/O ports can be flexibly configured. For details, see I/O Block Diagram.

This section mainly introduces the features supported by I/O ports and programming methods. For the configuration methods of connecting I/O ports to on-chip peripheral signals, refer to the Pin Mux section.

../../_images/pad_path.svg

I/O Block Diagram

Features

Each pin supports the following electrical characteristic configurations:

  • Internal pull-up/pull-down resistors

    • Supports independent pull-up/pull-down/high-impedance control

    • Pull resistance values are adjustable for certain pins

  • Multiple drive strength levels

    Multiple drive strength levels are available. The maximum level is used by default unless otherwise specified.

  • Adjustable slew rate control

    Supports signal edge output at different slew rates. This feature is supported only on certain pins.

Note

For I/O port characteristic parameters such as pull resistance values, drive strength, voltage characteristics, and signal slew rate, please refer to the Chip Datasheet. Drive strength values and the number of levels may vary between pins.

Pin State Management in Low-Power Mode

The pull-up/pull-down (PU/PD) states of I/O ports in Active mode and low-power modes are controlled by separate independent registers. The default PU/PD states of each pin during initialization are defined uniformly in ameba_pinmapcfg and loaded by pinmap_init() at system startup.

Pin Input State

  • Normal Sleep Mode (PG or CG)

    The PU/PD function of all I/O ports takes effect.

  • Deep Sleep Mode (DSLP)

    • The PU/PD function of most I/O ports remains effective;

    • The power supply of some I/O ports will be cut off, causing the PU/PD of these pins to become invalid and leaving the pins in a floating state.

      • If the circuit connected to these I/O ports needs to be pulled high or low, a dedicated pull-up/pull-down circuit must be designed in the external circuitry of the chip.

    Note

    For I/O ports whose PU/PD function becomes invalid in Deep Sleep Mode, refer to the chip datasheet.

Pin Output State

  • Normal Sleep Mode (PG or CG)

    The I/O port output will retain the logic level before entering sleep.

    For example, if an I/O is configured to output 1 before sleep, after the system enters PG or CG, the I/O will still maintain output 1 unchanged.

  • Deep Sleep Mode (DSLP)

    The high/low logic level output state set during the Active phase will be lost.

    For example, if an I/O is configured to output 1 before sleep, after the system enters Deep Sleep Mode, the I/O will no longer maintain the output 1 state.

I/O Ports Special Power Group

I/O ports are managed in groups by power domain. The supported operating voltages vary across groups (e.g., some groups support both 1.8V and 3.3V, while others support only 3.3V). For complete pin power group information, refer to the chip datasheet.

This section lists only the pin groups with special power supply constraints.

RTL8721Dx:

None.

Analog-Digital Shared Pin Usage Guidelines

Some I/O ports are designed to connect to both analog circuits and digital circuits. To ensure analog signal integrity, when these I/O ports are used for analog functions, the connection to the digital path must be disconnected (for example, when used as ADC input).

ADC Pins

These I/O ports support connection to either ADC analog circuits or digital circuits, and are used as digital functions by default.

Note

For I/O ports that support this function, refer to the ADC section.

  • When configuring as an ADC pin, perform the following steps:

    • Step 1: Disable the digital path connection

      PAD_InputCtrl(PinName, DISABLE);
      
    • Step 2: Configure pull-up/pull-down to floating state

      PAD_PullCtrl(PinName, GPIO_PuPd_NOPULL);
      

    Note

    For other configurations related to ADC pin functionality, refer to the ADC section.

  • When configuring as a digital function, perform the following:

    First call the following interface to enable the digital path connection, then configure pin multiplexing as needed.

    PAD_InputCtrl(PinName, ENABLE);
    

Raw API

PAD Exported Constants

PAD Drive Strength Definitions
/* PAD drive strength lowest level. */
#define PAD_DRV_ABILITITY_LOW (0)

/* PAD drive strength mid-low level. */
#define PAD_DRV_ABILITITY_MID_LOW (1)

/* PAD drive strength mid-high level. */
#define PAD_DRV_ABILITITY_MID_HIGH (2)

/* PAD drive strength highest level. */
#define PAD_DRV_ABILITITY_HIGH (3)
PAD Pull Resistor Definitions
/* PAD large pull resistor. */
#define PAD_Resistor_LARGE 0x00

/* PAD small pull resistor. */
#define PAD_Resistor_SMALL 0x01
PAD Slew Rate Definitions
/* PAD output slew rate fast. */
#define PAD_SlewRate_Fast (0)

/* PAD output slew rate slow. */
#define PAD_SlewRate_Slow (1)

PAD Exported Functions

void PAD_CMD(u8 PinName, u8 NewStatus)

Set the Internal pad shutdown or enable mode.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • NewStatus – Enable or disable (shutdown)

void PAD_DrvStrength(u8 PinName, u32 DrvStrength)

Set the driving strength of the specified PAD.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • DrvStrength – PAD driving strength. This parameter can be a value of PAD Drive Strength Definitions.

void PAD_InputCtrl(u8 PinName, u32 NewState)

Control digital path input.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • NewState

    Digital path input status.

    • ENABLE: Enable digital path input.

    • DISABLE: Disable digital path input.

void PAD_PullCtrl(u8 PinName, u8 PullType)

Set the internal PAD pull type.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • PullType

    Pull type for the pin. This parameter can be one of the following values:

    • GPIO_PuPd_NOPULL

    • GPIO_PuPd_DOWN

    • GPIO_PuPd_UP

void PAD_ResistorCtrl(u8 PinName, u8 RType)

Set the internal PAD resistor type.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • RType

    Resistor type for the pin. This parameter can be one of the following values:

    • PAD_Resistor_LARGE

    • PAD_Resistor_SMALL

void PAD_SchmitCtrl(u8 PinName, u32 NewState)

Set the PAD Schmitt trigger control status.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • NewState – Specify the control status. Refer to the datasheet for detail informations. This parameter can be: ENABLE or DISABLE.

void PAD_SleepPullCtrl(u8 PinName, u8 PullType)

Set the internal PAD pull type in sleep and deepsleep mode. The hardware will automatically switch to the sleep pull control when the system enters sleep or deepsleep mode. The hardware will automatically switch to the function pull control when the system wakes up from sleep mode.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • PullType

    Pull type for the pin. This parameter can be one of the following values:

    • GPIO_PuPd_NOPULL

    • GPIO_PuPd_DOWN

    • GPIO_PuPd_UP

void PAD_SlewRateCtrl(u8 PinName, u32 NewState)

Set the PAD slew rate control status.

Parameters:
  • PinName – Target pin. This parameter must be one of the values defined in PINMUX_Pin_Name_definitions.

  • NewState

    Specify the slew rate control status. Refer to the datasheet for detail informations. This parameter can be one of the following values:

    • PAD_SlewRate_Slow

    • PAD_SlewRate_Fast

RTL8721Dx:

Not supported.