引脚复用和控制

引脚复用

概述

因为引脚资源有限,为了提升设计的灵活性,本芯片提供了引脚复用(Pinmux)功能。每个引脚均可通过配置连接到不同的内部 IP 电路。

具体引脚与 IP 电路的对应关系,请查阅 功能复用

查阅引脚复用表可获得以下关键信息:

  • 不同料号下的引脚分布

  • 各引脚支持连接的片上外设信号

  • 上电锁存引脚(Trap Pin)的分配

  • J-Link 调试接口(SWD)的默认引脚分配

  • 固件下载、命令交互及日志功能所用串口(LOGUART)的默认引脚分配

  • 各 I/O 引脚的供电信息等

功能复用

RTL8721Dx:

使用方法

开发者可以通过调用编程接口 Pinmux_Config(PinName, PinFuncID) 将引脚连接到指定的片上外设信号。

参数说明:

PinName:

引脚标识符

PinFuncID:

片上外设控制器的指定信号 ID

根据所设置的 function-id ,引脚既可将芯片内部的信号 输出 到外部设备,也可接收外部设备的信号 输入 到芯片内部模块。

具体引脚与 function-id 的对应关系,请参考 引脚复用表

引脚类型

  • 专用引脚

    • 特点:每个引脚仅能连接到特定 IP 的固定信号。这些引脚可配置的功能非常有限,但通过专用设计可以使各个 IP 模块的性能最大化。

    • 功能组:专用引脚通常按“功能组”进行组织,每个功能组包含了一组相关的引脚。

    • 配置原则:建议选择同一功能组内的引脚组合以达到最佳性能。

  • 全矩阵引脚

    特点:每个引脚可连接到特定 IP 的不同信号。这种设计提供了更大的配置自由度,但使用范围和部分 IP 模块的性能(如最大传输速率)将受限。

Function ID

  • Function ID 0~{{IC_PARAM_FUNCID_DEDICATE_END}}

    当 Function ID 为 0~{{IC_PARAM_FUNCID_DEDICATE_END}} 时,需使用专用引脚。

    备注

    例如:Function ID {{IC_PARAM_FUNCID_DEDICATE_END}} 与 Function ID {{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CLK}}~{{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CS}} 均为 SPI 功能。

    • Function ID {{IC_PARAM_FUNCID_DEDICATE_END}} 为专用引脚,因此 SPI 功能的最大速率可达 50MHz(主机模式);

    • Function ID {{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CLK}}~{{IC_PARAM_FUNCID_FULL_MATRIX_SPI1_CS}} 对应的引脚(全矩阵引脚)能达到的最大速率仅为 12.5MHz(主机模式)。

    PB30 为例:如果将其 Function ID 配置为 1 ,该引脚将通过引脚复用直接连接到 UART1 的 UART1_RXD 信号。

    ../../_images/dplus_schematic_diagram_of_pinmux_dedicate_of_PB30.svg

    PB30 引脚复用连接示意图

    各引脚支持的具体功能分配请参考引脚复用表。

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

    当 Function ID 为 {{IC_PARAM_FUNCID_FULL_MATRIX_START}}~{{IC_PARAM_FUNCID_FULL_MATRIX_END}} 时,需使用全矩阵引脚。

    PA27 为例:

    • PA27 的 Function ID 配置为 19 时,可以将 PA27 连接到 UART0 的 UART0_TXD 信号;

    • PA27 的 Function ID 配置为 20 时,则可以将其连接到 UART0 的 UART0_RXD 信号。

    ../../_images/dplus_schematic_diagram_of_pinmux_fullmatrix_of_PA27.svg

    PA27 引脚复用连接示意图

    具体配置请参考引脚复用表。

Trap 引脚

小心

在进行开发前,请务必注意以下引脚复用相关事项,以避免意外行为导致使用问题。

在芯片上电过程中,内部电路会锁存若干引脚的状态,以决定是否进入不同的模式。下表列出了所有的 Trap 引脚及其描述。

RTL8721Dx:

引脚名称

符号

有效电平

描述

PB31

TM_DIS

低电平

  • 禁用测试模式,默认内部上拉

  • 该引脚仅用于内部测试,正常操作应保持逻辑高电平

    • 1:正常操作模式

    • 0:测试模式

PB5

UD_DIS

低电平

  • 禁用UART下载模式,默认内部上拉

  • 禁用下载模式受到OTP相关栏位控制

    当OTP禁用UART下载后,该引脚上电锁存状态无效

    • 1:进入正常启动模式

    • 0:进入UART下载模式

备注

Trap 引脚需要根据 I/O 电源选择外部上拉或下拉电压。

Wakeup 引脚

RTL8721Dx:
  • 普通 GPIO 引脚支持将系统从 CGPG 睡眠模式唤醒

  • 唤醒引脚( PB30PB31 )因直连唤醒电路,除可唤醒 CGPG 睡眠模式,还可唤醒系统自深度休眠模式

警告

  • 若需复用引脚功能,请先禁用唤醒功能。

  • 唤醒引脚可能与 Trap 引脚复用。复用时应确保唤醒后 Trap 引脚电平状态不会使系统进入非预期模式。

SWD 引脚

RTL8721Dx:

{{IC_PARAM_SWD_CLK_PIN}}{{IC_PARAM_SWD_DATA_PIN}} 引脚默认强制锁定为 SWD 功能。如果复用这两个引脚,需要先关闭 SWD 功能,这一点在编程接口 Pinmux_Config() 已为您处理好。

备注

当出现如下日志信息,表示 {{IC_PARAM_SWD_CLK_PIN}}{{IC_PARAM_SWD_DATA_PIN}} 引脚已经被连接至其他模块,此时无法继续通过该引脚与调试器连接。

如仍需连接调试器,请参考 功能复用SWD 信号重新配置引脚。

SWD PAD PortX_PinYY is configured to funcIDZZ

引脚控制

概述

Ameba 系列的 I/O 提供灵活的连接能力,支持与片上的模拟和数字电路接口进行连接。详见 I/O 框图 所示。

有关 PAD 连接片上信号的配置方法,请参阅 引脚复用 章节。本节主要介绍 PAD 支持的功能与编程方法。

../../_images/pad_path.svg

I/O 框图

功能特性

引脚控制模块支持灵活的 I/O 电气特性控制:

  • 内部上拉/下拉电阻

    • 可配置的片上电阻网络,支持上拉/下拉/高阻控制

    • 部分引脚上拉/下拉电阻阻值可调

  • 可编程的 Driving Strength 挡位

    可编程驱动能力,多档位可选

  • 可编程 Slew Rate 控制

    可调节信号边沿陡峭度,支持快速/慢速模式切换

PAD 控制与编程接口

PAD API 参考

API

描述

PAD_PullCtrl

配置 Active 模式下 PAD Pull 类型

PAD_SleepPullCtrl

配置 Sleep 模式下 PAD Pull 类型

PAD_ResistorCtrl

配置 PAD 上拉/下拉阻值类型

PAD_DrvStrength

配置 PAD 驱动能力挡位

PAD_InputCtrl

开启/关闭 PAD 数字路径控制

PAD_SlewRateCtrl

配置 PAD 上升沿/下降沿速率

备注

有关 PAD 特性参数,如:上下拉阻值信息、驱动能力、电压特性及信号边沿速率等性能指标请查询芯片数据手册。

低功耗模式引脚状态管理

PAD 在 Active 与低功耗模式下的 PU/PD 功能分别由不同寄存器进行控制。这种设计允许在低功耗模式下为每个引脚独立配置片内的上拉或下拉电阻。

PAD 输入状态

  • 普通睡眠模式(PG 或 CG)

    所有 PAD 的 PU/PD 功能均生效。

  • 深度睡眠模式

    • 大多数 PAD 的 PU/PD 功能仍然生效;

    • 某些 PAD 的供电会被关闭,导致这些引脚的 PU/PD 失效,因此可能呈现浮空状态。

      • 如果与这些 PAD 相连的电路需要被拉到高或低状态,则需要在 PCB 上使用外部电阻器。

    备注

    深度睡眠模式下, PU/PD 功能无效的 PAD,请查询芯片数据手册。

PAD 输出状态

  • 普通睡眠模式(PG 或 CG)

    PAD 输出的状态将 保持睡眠前的状态

    例如,在睡眠之前,如果 I/O 设置为输出 1,系统进入 PG 或 CG 后,此 I/O 仍将保持输出 1 不变。

  • 深度睡眠模式

    Active 下设置的 1/0 输出状态将失效

    例如,在睡眠之前,如果 I/O 设置为输出 1,系统进入深度睡眠后,则 I/O 将无法保持输出 1 状态。

模拟数字共用引脚使用规范

部分 PAD 设计为既可连接到模拟电路,也可与数字电路通信。为确保模拟信号的完整性,这些 PAD 用作模拟功能时,需断开与数字路径连接 (例如,作为 ADC 的输入)。

ADC PAD

对于该部分 PAD,支持其与 ADC 模拟电路及数字电路连接。默认情况作为数字功能。

备注

支持该功能的 PAD, 请查询 ADC 章节介绍。

  • 当配置其作为 ADC pin 时,需执行以下操作

    • 步骤 1:关闭数字通路连接

      PAD_InputCtrl(PinName, DISABLE);
      
    • 步骤 2:Pull Control 配置为浮空状态

      PAD_PullCtrl(PinName, GPIO_PuPd_NOPULL);
      
    • 步骤 3:与 ADC pin 功能相关的其它配置,详见 ADC 章节介绍。

  • 当配置其为数字功能时,需执行以下操作

    需先调用如下接口使能数字通路连接,再按需进行引脚复用即可。

    PAD_InputCtrl(PinName, ENABLE);
    

Audio PAD

RTL8721Dx:

无。

USB PAD

RTL8721Dx:
  • 当配置其作为 USB PAD 时,需执行以下操作

    配置 PU/PD 为浮空状态,该操作已在底层驱动代码实现,您无需额外操作。更多技术细节请参阅 USB 章节。

  • 当从 USB 功能切换至其它功能时

    仅需执行相应的 USB 去初始化操作,并按需进行引脚复用即可,无需额外操作。

Raw API

PAD Exported Constants

PAD Pull Resistor Definitions

/* PAD large pull resistor. */
#define PAD_Resistor_LARGE 0x00

/* PAD small pull resistor. */
#define PAD_Resistor_SMALL 0x01

PINMUX 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)

PINMUX PAD Slew Rate Definitions

/* PAD output slew rate fast. */
#define PAD_SlewRate_Fast (0)

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

PINMUX Special Pad Definitions

RTL8721Dx:

No content

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)

PAD Exported Functions

void PAD_CMD(u8 PinName, u8 NewStatus)

Set the Internal pad shutdown or enable mode.

参数:
  • PinName -- Value of PINMUX_Pin_Name_definitions.

  • NewStatus -- Enable or disable (shutdown)

void PAD_DrvStrength(u8 PinName, u32 DrvStrength)

Set the driving strength of the specified PAD.

参数:
  • PinName -- Specify the 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 PINMUX PAD Drive Strength Definitions.

void PAD_InputCtrl(u8 PinName, u32 NewState)

Control digital path input.

参数:
  • PinName -- Value of 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.

参数:
  • PinName -- Value of 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.

参数:
  • PinName -- Value of 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.

参数:
  • PinName -- Specify the 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. HW will switch to the sleep pull ctrl automatically when system enters sleep or deepsleep mode. HW will switch to function pull ctrl automatically when system wakes up from sleep mode.

参数:
  • PinName -- Value of 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.

参数:
  • PinName -- Specify the 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:

No content

PINMUX Exported Functions

void Pinmux_Config(u8 PinName, u32 PinFunc)

Set the function type of one pin.

参数:
  • PinName -- Value of 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.

参数:
  • PinName -- Value of PINMUX_Pin_Name_definitions.

返回:

The function type for the pin, value of PINMUX_Function_definitions.

void Pinmux_Swdoff(void)

Turn off pinmux SWD function.

备注

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