Ruffian Heng embedded: talk about the difference and usage between ordinary GPIO and high-speed GPIO on i.mxrt1xxx

Time:2022-4-29

Hello, I’m ruffian Heng, a serious technical ruffian. What ruffian Heng introduced to you today isi. Difference between normal GPIO and high-speed GPIO on mxrt

GPIO can be said to be the simplest and most commonly used peripheral module on MCU. When some native function peripheral interface modules can not meet the project design requirements, we often consider using GPIO to realize the corresponding functions through software simulation. At this time, the performance of GPIO itself is very important.

In the early i.mxrt1015/1020/1024/1050 models, GPIO is of ordinary performance (note that the ordinary ones here have superior performance compared with ordinary low-end MCU). Considering that i.mxrt is a monster of performance and needs to be configured with stronger GPIO, hsgpio appears in the subsequent i.mxrt1010/1060/1064/1160/1170 models. Today, ruffian Heng will talk about the difference between GPIO and hsgpio:

1、 What is hsgpio?

Hsgpio is the abbreviation of high speed GPIO, which is sometimes called tightly coupled GPIO or single clock cycle GPIO. In short, the speed of its module (IP) clock source is higher than that of ordinary GPIO clock source, so we can access its module register at a higher frequency. The following table lists the distribution of hsgpio on each model of i.mxrt:

model General GPIO High speed GPIO
i.MXRT1010 GPIO1、GPIO5 GPIO2
i.MXRT1060/1064 GPIO1 – GPIO5 GPIO6 – GPIO9
i.MXRT1160/1170 GPIO1 – GPIO13 CM7_GPIO2、CM7_GPIO3

Taking i.mxrt1060 as an example, we can see from the CCM clock module chapter of its reference manual that the clock source of ordinary gpio1-5 is IPG_ CLK_ Root, and the clock source of high-speed gpio6-9 is AHB_ CLK_ ROOT:

IPG on i.mxrt1060_ CLK_ The highest frequency of root is 150MHz, while AHB_ CLK_ Root refers to the core frequency, which can reach 600MHz. Therefore, from the perspective of clock source alone, the access performance of hsgpio should be “four times” that of GPIO (a quotation mark is used here. In the actual chip design, the access of hsgpio bus is delayed and cannot be the same frequency as AHB bus):

The following figure is the structure block diagram of i.mxrt1060 kernel. It can be seen that hsgpio and ahbp bus are processed by split and AIPS Lite, so the final access frequency of hsgpio is not equal to the frequency of ahbp bus, but the clock source comes from ahbp bus.

  • Note1: hsgpio in the core structure of i.mxrt1170 is the same. It will be processed through split and AIPS Lite.
  • Note2: hsgpio in i.mxrt1010 kernel structure has been optimized, and only split level processing.

2、 Shared pad design

From the inside of the chip, GPIO and hsgpio modules are independent, but because the external pin (PAD) resources of the chip are limited, some hsgpio share pads with GPIO modules. Finally, the actual performance of I / O is actually limited by the same physical pad characteristics.

Let’s take the i.mxrt1010 with the simplest package as an example. The left side of the figure below lists all pads, including GPIO_ SD [13:0] is a dedicated pin for hsgpio, while GPIO [13:0] and GPIO_ Ad [14:0] refers to GPIO and hsgpio multiplexing pins. When these GPIO / hsgpio multiplexing pins are configured as GPIO function, they can be mapped to gpio1 (normal GPIO) or gpio2 (hsgpio):

  • Note: if GPIO has been_ If SD [13:0] is configured as gpio2, do not configure GPIO [13:0] as hsgpio, and a conflict will occur.

The specific GPIO mapping function is provided by iomuxc_ Controlled by GPR26 register (note that this is a soft reset register without setting). For example, when GPIO_ 11 is configured as gpiomux_ Io11 function, then iomuxc_ GPR26 [11] determines its mapping relationship:

IOMUXC_ GPR26 [11] = 0, then GPIO_ 11 corresponds to gpio1 [11], which is ordinary GPIO

The following table lists the GPIO / hsgpio switching control relationship on i.mxrt models:

model Pad switching control register ALT function name Corresponding switching GPIO
i.MXRT1010 IOMUXC_GPR->GPR26 GPIO_MUX Gpio1 and gpio2
i.MXRT1060/1064 IOMUXC_GPR->GPR26


IOMUXC_GPR->GPR27


IOMUXC_GPR->GPR28


IOMUXC_GPR->GPR29
GPIO_MUX1


GPIO_MUX2


GPIO_MUX3


GPIO_MUX4
Gpio1 and gpio6

Gpio2 and gpio7

Gpio3 and gpio8

Gpio4 and gpio9
i.MXRT1160/1170 IOMUXC_GPR->GPR40、41


IOMUXC_GPR->GPR42、43
GPIO_MUX2


GPIO_MUX3
Gpio2 and CM7_ GPIO2

Gpio3 and CM7_ GPIO3

3、 Pad running speed

As mentioned earlier, whether ordinary GPIO or hsgpio is enabled, the signal is ultimately output by the same physical pad, so the actual I / O performance is ultimately limited by the maximum running speed of this pad.

Continue to take i.mxrt1010 as an example. Each pad has a register iomuxc specially configured with electrical properties in the iomuxc module_ SW_ PAD_ CTL_ PAD_ Xxio, select GPIO_ 11 as an example, the SRE, DSE and speed bits can be combined to obtain different operating speeds (the specific combination value can be searched in the GPIO chapter of the reference manual)Operating FrequencyBut we can see that the maximum running speed of pad is 200MHz:

In the i.mxrt1010 data manual, we can also see more specific I / O turnover time test:

4、 Hsgpio sample code

Based on the above knowledge of mx1010.driver_ examples\gpio\led_ Output routine, adding the following hsgpio related codes, can also achieve the function of flashing LED lights.

If we use GPIO to control the GPIO in advance, it seems that we can’t use GPIO to control the difference between GPIO and GPIO. If we use GPIO to control the GPIO in advance, we can’t see the difference_ Toggle and GPIO – > Dr registers have different I / O flip efficiency.

bool is_normal_gpio = false;

int main(void)
{
    BOARD_ConfigMPU();
    BOARD_InitBootClocks();

    /* Define the init structure for the output LED pin*/
    gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};

    CLOCK_EnableClock(kCLOCK_Iomuxc);      
    IOMUXC_SetPinMux(IOMUXC_GPIO_11_GPIOMUX_IO11, 0U); 
    if (is_normal_gpio)
    {
        // GPIO1
        IOMUXC_GPR->GPR26 &= ~(1u << 11);
        // Slow Slew Rate, 100MHz
        IOMUXC_SetPinConfig(IOMUXC_GPIO_11_GPIOMUX_IO11, 0x70A0U);
        GPIO_PinInit(GPIO1, 11, &led_config);
    }
    else
    {
        // GPIO2
        IOMUXC_GPR->GPR26 |= (1u << 11);
        // Fast Slew Rate, 200MHz
        IOMUXC_SetPinConfig(IOMUXC_GPIO_11_GPIOMUX_IO11, 0x70F9U);
        GPIO_PinInit(GPIO2, 11, &led_config);
    }

    while (1)
    {
        SDK_DelayAtLeastUs(100000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);

        if (is_normal_gpio)
        {
            //GPIO1->DR_TOGGLE = (1u << 11);
            GPIO1->DR ^= (1u << 11);
            __DSB();
        }
        else
        {
            //GPIO2->DR_TOGGLE = (1u << 11);
            GPIO2->DR ^= (1u << 11);
            __DSB();
        }
    }
}

So far, the difference between ordinary GPIO and high-speed GPIO on i.mxrt has been introduced. Where is the applause~~~

Welcome to subscribe

The article will be published to me at the same timeBlog Park HomepageCSDN home pageZhihu HomepageWechat official accountOn the platform.

Wechat search“Ruffian scale“Or scan the QR code below, and you can see it for the first time on your mobile phone.