mstar 平台GPIO在线调试

16 篇文章 8 订阅

1. GPIO状态

cat  /sys/kernel/debug/gpio

可以看到所有当年GPIO口的状态,输入输出模式,输出高/低

gpiochip0: GPIOs 0-115, gpio:
 gpio-0   (                    |sysfs               ) in  hi    
 gpio-1   (                    |sysfs               ) in  hi    
 gpio-2   (                    |sysfs               ) out hi    
 gpio-3   (                    |sysfs               ) in  hi    
 gpio-4   (                    |sysfs               ) in  hi    
 gpio-5   (                    |sysfs               ) out lo    
 gpio-6   (                    |sysfs               ) in  hi    
 gpio-7   (                    |sysfs               ) out hi    
 gpio-8   (                    |sysfs               ) out hi    
 gpio-9   (                    |sysfs               ) in  hi    
 gpio-10  (                    |sysfs               ) out lo    
 gpio-11  (                    |sysfs               ) in  hi    
 gpio-12  (                    |sysfs               ) in  hi    
 gpio-13  (                    |sysfs               ) out hi    
 gpio-14  (                    |sysfs               ) in  hi    
 gpio-15  (                    |sysfs               ) in  hi    
 gpio-16  (                    |sysfs               ) out lo    
 gpio-17  (                    |sysfs               ) out hi    
 gpio-18  (                    |sysfs               ) out lo    
 gpio-19  (                    |sysfs               ) out lo    
 gpio-20  (                    |sysfs               ) in  hi    
 gpio-21  (                    |sysfs               ) in  lo    
 gpio-22  (                    |sysfs               ) in  lo    
 gpio-23  (                    |sysfs               ) in  hi    
 gpio-24  (                    |sysfs               ) in  hi    
 gpio-25  (                    |sysfs               ) in  hi    
 gpio-26  (                    |sysfs               ) in  hi    
 gpio-27  (                    |sysfs               ) in  lo    
 gpio-28  (                    |sysfs               ) in  lo    
 gpio-29  (                    |sysfs               ) in  hi    
 gpio-30  (                    |sysfs               ) in  hi    
 gpio-31  (                    |sysfs               ) out hi    
 gpio-32  (                    |sysfs               ) in  hi    
 gpio-33  (                    |sysfs               ) in  hi    
 gpio-34  (                    |sysfs               ) in  hi    
 gpio-35  (                    |sysfs               ) out lo    
 gpio-36  (                    |sysfs               ) out lo    
 gpio-37  (                    |sysfs               ) out lo    
 gpio-38  (                    |sysfs               ) out lo    
 gpio-39  (                    |sysfs               ) in  lo    
 gpio-40  (                    |sysfs               ) in  hi    
 gpio-41  (                    |sysfs               ) in  hi    
 gpio-42  (                    |sysfs               ) in  hi    
 gpio-43  (                    |sysfs               ) in  hi    
 gpio-44  (                    |sysfs               ) in  hi    
 gpio-45  (                    |sysfs               ) in  hi    
 gpio-46  (                    |sysfs               ) in  hi    
 gpio-47  (                    |sysfs               ) in  hi    
 gpio-48  (                    |sysfs               ) in  hi    
 gpio-49  (                    |sysfs               ) in  hi    
 gpio-50  (                    |sysfs               ) in  hi    
 gpio-51  (                    |sysfs               ) in  hi    
 gpio-52  (                    |sysfs               ) in  lo    
 gpio-53  (                    |sysfs               ) in  hi    
 gpio-54  (                    |sysfs               ) in  hi    
 gpio-55  (                    |sysfs               ) out hi    
 gpio-56  (                    |sysfs               ) in  hi    
 gpio-57  (                    |sysfs               ) in  hi    
 gpio-58  (                    |sysfs               ) in  hi    
 gpio-59  (                    |sysfs               ) in  hi    
 gpio-60  (                    |sysfs               ) in  hi    
 gpio-61  (                    |sysfs               ) in  hi    
 gpio-64  (                    |sysfs               ) out lo    
 gpio-65  (                    |sysfs               ) out hi    
 gpio-66  (                    |sysfs               ) out hi    
 gpio-67  (                    |sysfs               ) out hi    
 gpio-68  (                    |sysfs               ) in  hi    
 gpio-69  (                    |sysfs               ) in  hi    
 gpio-70  (                    |sysfs               ) in  hi    
 gpio-71  (                    |sysfs               ) in  hi    
 gpio-72  (                    |sysfs               ) in  hi    
 gpio-73  (                    |sysfs               ) in  hi    
 gpio-74  (                    |sysfs               ) out lo    
 gpio-75  (                    |sysfs               ) out hi    
 gpio-76  (                    |sysfs               ) in  hi    
 gpio-77  (                    |sysfs               ) in  hi    
 gpio-78  (                    |sysfs               ) in  hi    
 gpio-79  (                    |sysfs               ) in  lo    
 gpio-80  (                    |sysfs               ) in  lo    
 gpio-81  (                    |sysfs               ) in  lo    
 gpio-82  (                    |sysfs               ) in  lo    
 gpio-83  (                    |sysfs               ) in  hi    
 gpio-84  (                    |sysfs               ) in  lo    
 gpio-85  (                    |sysfs               ) in  lo    
 gpio-86  (                    |sysfs               ) in  hi    
 gpio-87  (                    |sysfs               ) out lo    
 gpio-88  (                    |sysfs               ) in  hi    
 gpio-89  (                    |sysfs               ) in  lo    
 gpio-90  (                    |sysfs               ) in  hi    
 gpio-91  (                    |sysfs               ) in  hi    
 gpio-92  (                    |sysfs               ) in  hi    
 gpio-93  (                    |sysfs               ) in  hi    
 gpio-94  (                    |sysfs               ) in  hi    
 gpio-95  (                    |sysfs               ) in  hi    
 gpio-96  (                    |sysfs               ) in  hi    
 gpio-97  (                    |scl                 ) in  hi    
 gpio-98  (                    |sda                 ) in  hi    
 gpio-99  (                    |sysfs               ) in  hi    
 gpio-100 (                    |sysfs               ) in  hi    
 gpio-101 (                    |sysfs               ) out hi    
 gpio-102 (                    |sysfs               ) out hi    
 gpio-103 (                    |sysfs               ) in  hi    
 gpio-104 (                    |sysfs               ) in  hi    
 gpio-105 (                    |sysfs               ) in  hi    
 gpio-106 (                    |sysfs               ) in  hi    
 gpio-107 (                    |sysfs               ) in  hi    
 gpio-108 (                    |sysfs               ) in  hi    
 gpio-109 (                    |sysfs               ) in  hi    
 gpio-110 (                    |sysfs               ) out lo    
 gpio-111 (                    |sysfs               ) out lo    
 gpio-112 (                    |sysfs               ) in  hi    
 gpio-113 (                    |sysfs               ) in  hi    
 gpio-114 (                    |sysfs               ) in  hi    
 gpio-115 (                    |sysfs               ) in  hi    

例如: GPIO16

gpio-16  (                    |sysfs               ) out lo 

输出低信号

2. GPIO属性

例如gpio16

  1. direction
    IO输入,输出模式
 # cat  /sys/devices/gpiochip0/gpio/gpio16/direction                
   out
  1. active_low
# cat  /sys/devices/gpiochip0/gpio/gpio16/active_low               
  0
  1. value
    当前电平高低
# cat   /sys/devices/gpiochip0/gpio/gpio16/value                   
  0

拉高

echo  1   >  /sys/devices/gpiochip0/gpio/gpio16/value

拉低

echo  0   >  /sys/devices/gpiochip0/gpio/gpio16/value

3. reg 与 IO 映射

reg 和 pin ID映射
mstar2\hal\m7221\gpio\mhal_gpio.c。
其中PAD_IRIN,PAD_CEC0,PAD_PWM_PM是pin id。

#define GPIO999_OEN     0, 0
#define GPIO999_OUT     0, 0
#define GPIO999_IN      0, 0

#define GPIO0_PAD PAD_IRIN
#define GPIO0_OEN 0x0f26, BIT0
#define GPIO0_OUT 0x0f26, BIT1
#define GPIO0_IN  0x0f26, BIT2

#define GPIO1_PAD PAD_CEC0
#define GPIO1_OEN 0x0f2a, BIT0
#define GPIO1_OUT 0x0f2a, BIT1
#define GPIO1_IN  0x0f2a, BIT2

#define GPIO2_PAD PAD_PWM_PM
#define GPIO2_OEN 0x0f28, BIT0
#define GPIO2_OUT 0x0f28, BIT1
#define GPIO2_IN  0x0f28, BIT2

#define GPIO3_PAD PAD_DDCA_CK
#define GPIO3_OEN 0x0494, BIT1
#define GPIO3_OUT 0x0494, BIT2
#define GPIO3_IN  0x0494, BIT0

#define GPIO4_PAD PAD_DDCA_DA
#define GPIO4_OEN 0x0494, BIT5
#define GPIO4_OUT 0x0494, BIT6
#define GPIO4_IN  0x0494, BIT4
.......

#define GPIO_EXT7_MSK  0x10190e, BIT15
#define GPIO_EXT7_POL  0x101916, BIT15
#define GPIO_EXT7_CLR  0x10191e, BIT15
#define GPIO_EXT7_STS  0x10191e, BIT15

......
static const struct gpio_setting
{
    U32 r_oen;
    U8  m_oen;
    U32 r_out;
    U8  m_out;
    U32 r_in;
    U8  m_in;
} gpio_table[] =
{
#define __GPIO__(_x_)   { CONCAT(CONCAT(GPIO, _x_), _OEN),   \
                          CONCAT(CONCAT(GPIO, _x_), _OUT),   \
                          CONCAT(CONCAT(GPIO, _x_), _IN) }
#define __GPIO(_x_)     __GPIO__(_x_)

//
// !! WARNING !! DO NOT MODIFIY !!!!
//
// These defines order must match following
// 1. the PAD name in GPIO excel
// 2. the perl script to generate the package header file
//
    //__GPIO(999), // 0 is not used

    __GPIO(0), __GPIO(1), __GPIO(2), __GPIO(3), __GPIO(4),
    __GPIO(5), __GPIO(6), __GPIO(7), __GPIO(8), __GPIO(9),
    __GPIO(10), __GPIO(11), __GPIO(12), __GPIO(13), __GPIO(14),
    __GPIO(15), __GPIO(16), __GPIO(17), __GPIO(18), __GPIO(19),
    __GPIO(20), __GPIO(21), __GPIO(22), __GPIO(23), __GPIO(24),
    __GPIO(25), __GPIO(26), __GPIO(27), __GPIO(28), __GPIO(29),
    __GPIO(30), __GPIO(31), __GPIO(32), __GPIO(33), __GPIO(34),
    __GPIO(35), __GPIO(36), __GPIO(37), __GPIO(38), __GPIO(39),
    __GPIO(40), __GPIO(41), __GPIO(42), __GPIO(43), __GPIO(44),
    __GPIO(45), __GPIO(46), __GPIO(47), __GPIO(48), __GPIO(49),
    __GPIO(50), __GPIO(51), __GPIO(52), __GPIO(53), __GPIO(54),
    __GPIO(55), __GPIO(56), __GPIO(57), __GPIO(58), __GPIO(59),
    __GPIO(60), __GPIO(61), __GPIO(62), __GPIO(63), __GPIO(64),
    __GPIO(65), __GPIO(66), __GPIO(67), __GPIO(68), __GPIO(69),
    __GPIO(70), __GPIO(71), __GPIO(72), __GPIO(73), __GPIO(74),
    __GPIO(75), __GPIO(76), __GPIO(77), __GPIO(78), __GPIO(79),
    __GPIO(80), __GPIO(81), __GPIO(82), __GPIO(83), __GPIO(84),
    __GPIO(85), __GPIO(86), __GPIO(87), __GPIO(88), __GPIO(89),
    __GPIO(90), __GPIO(91), __GPIO(92), __GPIO(93), __GPIO(94),
    __GPIO(95), __GPIO(96), __GPIO(97), __GPIO(98), __GPIO(99),
    __GPIO(100), __GPIO(101), __GPIO(102), __GPIO(103), __GPIO(104),
    __GPIO(105), __GPIO(106), __GPIO(107), __GPIO(108), __GPIO(109),
    __GPIO(110), __GPIO(111), __GPIO(112), __GPIO(113), __GPIO(114),
    __GPIO(115)
};

gpio pin 的ID 号,在mstar2\hal\m7221\gpio\mhal_gpio_reg.h定义

#define PAD_IRIN                    0
#define PAD_CEC0                    1
#define PAD_PWM_PM                  2
#define PAD_DDCA_CK                 3
#define PAD_DDCA_DA                 4
#define PAD_GPIO0_PM                5
#define PAD_GPIO1_PM                6
#define PAD_GPIO2_PM                7
#define PAD_USB_CTRL                8
#define PAD_GPIO5_PM                9
#define PAD_GPIO6_PM                10
#define PAD_GPIO7_PM                11
#define PAD_GPIO8_PM                12
#define PAD_GPIO9_PM                13
#define PAD_GPIO10_PM               14
#define PAD_GPIO11_PM               15
#define PAD_GPIO12_PM               16
#define PAD_HOTPLUGA                17
#define PAD_HOTPLUGB                18
#define PAD_HOTPLUGC                19
#define PAD_HOTPLUGA_HDMI20_5V      20
#define PAD_HOTPLUGB_HDMI20_5V      21
#define PAD_HOTPLUGC_HDMI20_5V      22
#define PAD_DDCDA_CK                23
#define PAD_DDCDA_DA                24
#define PAD_DDCDB_CK                25
#define PAD_DDCDB_DA                26
#define PAD_DDCDC_CK                27
#define PAD_DDCDC_DA                28
#define PAD_SAR0                    29
#define PAD_SAR1                    30
#define PAD_SAR2                    31
#define PAD_SAR3                    32
#define PAD_SAR4                    33
#define PAD_VPLUGIN                 34
#define PAD_VID0                    35
#define PAD_VID1                    36
#define PAD_VID2                    37
#define PAD_VID3                    38
#define PAD_WOL_INT_OUT             39
#define PAD_I2S_IN_BCK              40
#define PAD_I2S_IN_WS               41
#define PAD_I2S_IN_MCK              42
#define PAD_I2S_IN_SD0              43
#define PAD_I2S_IN_SD1              44
#define PAD_CILINK_DEMOD0_CLK       45
#define PAD_CILINK_DEMOD1_CLK       46
#define PAD_CILINK_INT              47
#define PAD_CILINK_RX0_D0           48
#define PAD_CILINK_RX0_D1           49
#define PAD_CILINK_RX1_D0           50
#define PAD_CILINK_RX1_D1           51
#define PAD_CILINK_RX_CLK           52
#define PAD_CILINK_SPI_CLK          53
#define PAD_CILINK_SPI_CS           54
#define PAD_CILINK_SPI_MISO         55
#define PAD_CILINK_SPI_MOSI         56
#define PAD_CILINK_TX0_D0           57
#define PAD_CILINK_TX0_D1           58
#define PAD_CILINK_TX1_D0           59
#define PAD_CILINK_TX1_D1           60
#define PAD_CILINK_TX_CLK           61
#define PAD_DDCR_CK                 62
#define PAD_DDCR_DA                 63
#define PAD_GPIO2                   64
#define PAD_GPIO3                   65
#define PAD_GPIO4                   66
#define PAD_GPIO5                   67
#define PAD_GPIO9                   68
#define PAD_GPIO10                  69
#define PAD_GPIO11                  70
#define PAD_GPIO12                  71
#define PAD_GPIO19                  72
#define PAD_GPIO20                  73
#define PAD_GPIO25                  74
#define PAD_GPIO26                  75
#define PAD_GPIO30                  76
#define PAD_GPIO31                  77
#define PAD_HDMIRX_ARCTX            78
#define PAD_I2S_OUT_BCK             79
#define PAD_I2S_OUT_MCK             80
#define PAD_I2S_OUT_SD              81
#define PAD_I2S_OUT_SD1             82
#define PAD_I2S_OUT_SD2             83
#define PAD_I2S_OUT_WS              84
#define PAD_PWM0                    85
#define PAD_PWM1                    86
#define PAD_PWM2                    87
#define PAD_PWM3                    88
#define PAD_SD_CLK                  89
#define PAD_SD_CMD                  90
#define PAD_SD_D0                   91
#define PAD_SD_D1                   92
#define PAD_SD_D2                   93
#define PAD_SD_D3                   94
#define PAD_SPDIF_IN                95
#define PAD_SPDIF_OUT               96
#define PAD_TGPIO0                  97
#define PAD_TGPIO1                  98
#define PAD_TGPIO2                  99
#define PAD_TGPIO3                  100
#define PAD_TS1_CLK                 101
#define PAD_TS1_D0                  102
#define PAD_TS1_D1                  103
#define PAD_TS1_D2                  104
#define PAD_TS1_D3                  105
#define PAD_TS1_D4                  106
#define PAD_TS1_D5                  107
#define PAD_TS1_D6                  108
#define PAD_TS1_D7                  109
#define PAD_TS1_SYNC                110
#define PAD_TS1_VLD                 111
#define PAD_TS2_CLK                 112
#define PAD_TS2_D0                  113
#define PAD_TS2_SYNC                114
#define PAD_TS2_VLD                 115

4. pin id 与芯片管脚映射

以GPIO16 为例
#define GPIO16_PAD PAD_GPIO12_PM

supernova\projects\board\m7221\ChipInfo\MSD96BUXM8.h
#define BALL_U3 PAD_GPIO12_PM
#define PAD_GPIO12_PM 17
#define GPIO_PAD_17 GPIO16
#ifndef BALL_U3_IS_GPIO
#define BALL_U3_IS_GPIO 0
#endif 
#ifndef PAD_GPIO12_PM_IS_GPIO
#define PAD_GPIO12_PM_IS_GPIO BALL_U3_IS_GPIO
#endif 

其中BALL_U3即为芯片的管脚
在这里插入图片描述

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值