Operating Instructions for Hisilicon GPIO

Recently, when I was researching the HiSilicon chip and got the GPIO, I was confused at first. After searching and looking at the documentation, it seemed to understand how to use it. Feature this article to help yourself understand.
According to the 3520dv400 manual (the others are the same), using gpio only requires 3 steps


1 Set gpio port multiplexing


The so-called multiplexing refers to that a port can do many things at the same time, but you need to set up what you are asked to do. This is the role of the pin multiplexing register.
For example, if we want to set GPIO6_7, we need to first find the corresponding pin multiplex register address. Check the manual, the corresponding instructions are shown in the figure. This means that if you want to use this pin as an IO port, you need to write 00 to the muxctrl_reg55 register. So where is the register muxctrl_reg55? The offset address 0x0DC has been given earlier. According to the manual, the base address is 0x200F_0000. So the address of this register is 0x200F_00DC.
So how to write the value into it, HiSilicon SDK has given the tool himm. Just
enter the following command:
himm 0x200F00DC 0
so that the function of the corresponding pin of GPIO6_7 is set to the IO port

 

2 Set the direction of the GPIO port


The so-called direction is whether you use io as input or output. For example, if your board is connected to a battery module, you want the battery module to give a signal to your board when there is no power, telling you that there is no power, then you need to use the io port as an input. Conversely, if you need to tell the external device what is going on, then you have to output the io port.

Setting the direction of the GPIO port is actually writing the GPIO_DIR register. Similarly, you first need to find the address.
Look at the following two tables:


Looking up the table, the GPIO_DIR register address of GPIO6_7 is 0x201A_0400. Then there are 8 bits in the GPIO_DIR register, each bit corresponds to a GPIO direction, namely:

If you want to set the direction of GPIO6_7 as output, enter the command: himm 0x201A0400 0b10000000.
But in actual operation, doing this directly may affect other GPIO directions, so it is best to read the value in the register first, only change the bit The value of 7 remains unchanged.

 

3 Read or write GPIO value


This block is actually the GPIO_DATA register, as you can tell from the name, this register is the value installed, right, it is very easy to understand. But what is difficult to understand is a paragraph in the manual:

My understanding here is that GPIO_DATA [7: 0] actually corresponds to 8 IO ports from GPIO6_7 to GPIO6_0. Each bit is 1 or 0, which corresponds to the value of each IO port.

So what do the addresses 0x3FC and 0x200 mean in that paragraph? I understand that they actually allow you to perform batch operations on the GPIO values.
For example, if you only want to operate GPIO6_7, then your offset address should be 0b10_0000_0000 (ie 0x200), but if you want to operate GPIO6_7 and GPIO6_6 at the same time, then the offset address you give should be 0b11_0000_0000 (ie 0x300 ).
So to continue the above example, we only set output 1 for GPIO6_7, then we should enter: himm 0x201A0200 0xFF

Although the value we give is 0xFF, but for the reasons above, in fact, we just assigned a value to GPIO_DATA [7], and nothing else works.

Finally, I added that the difference between gpio and haisi gpio numbers under linux: When
I study the data, I first look at the schematic diagram. As soon as I see it, I see that the gpio numbers are all gpiox_x (gpio6_6 and the like). . Because I have only done simple GPIO input and output in Linux before, I only have gpiox in my mind, such as gpio1 and gpio2. After reading the CPU manual, I learned that the original gpio of Haisi is grouped. For example, the 3516cv200 has 9 groups, and each group has 8 io ports, so gpio6_6 means the seventh io port of the sixth group.
 

Published 115 original articles · Like 29 · Visitors 50,000+

Guess you like

Origin blog.csdn.net/huabiaochen/article/details/102383381