我看mini2440的eboot的时候,有这么一段
void OEMInitDebugSerial(void)
{
volatile UART0reg *s2440UART0 = (UART0reg *)UART0_BASE;
volatile IOPreg *s2440IOP = (IOPreg *)IOP_BASE;
// Configure port H for UART.
s2440IOP->rGPHCON |= ((2 << 4) | (2 << 6));
s2440IOP->rGPHUP |= (1 << 4) | (1 << 5); // Disable pull-up on TXD1 and RXD1.
........
}
因为不知道什么意思,我查了一下datasheet:
- Port H(GPH): 9-input/output port
Port H Selectable Pin Functions
GPH10 Input/output CLKOUT1 – –
GPH9 Input/output CLKOUT0 – –
GPH8 Input/output UEXTCLK – –
GPH7 Input/output RXD2 nCTS1 –
GPH6 Input/output TXD2 nRTS1 –
GPH5 Input/output RXD1 – –
GPH4 Input/output TXD1 – –
GPH3 Input/output RXD0 – –
GPH2 Input/output TXD0 – –
GPH1 Input/output nRTS0 – –
GPH0 Input/output nCTS0 – –
GPHCON Bit Description
GPH10 [21:20] 00 = Input 01 = Output 10 = CLKOUT1 11 = Reserved
GPH9 [19:18] 00 = Input 01 = Output 10 = CLKOUT0 11 = Reserved
GPH8 [17:16] 00 = Input 01 = Output 10 = UEXTCLK 11 = Reserved
GPH7 [15:14] 00 = Input 01 = Output 10 = RXD[2] 11 = nCTS1
GPH6 [13:12] 00 = Input 01 = Output 10 = TXD[2] 11 = nRTS1
GPH5 [11:10] 00 = Input 01 = Output 10 = RXD[1] 11 = Reserved
GPH4 [9:8] 00 = Input 01 = Output 10 = TXD[1] 11 = Reserved
GPH3 [7:6] 00 = Input 01 = Output 10 = RXD[0] 11 = reserved
GPH2 [5:4] 00 = Input 01 = Output 10 = TXD[0] 11 = Reserved
GPH1 [3:2] 00 = Input 01 = Output 10 = nRTS0 11 = Reserved
GPH0 [1:0] 00 = Input 01 = Output 10 = nCTS0 11 = Reserved
谁能帮我解释一下,
1.既然是个9pin的口,为啥有11个(pin)控制位,而且GPHCON是个32位寄存器,0-21总共用到22个bit,每两个bit设置一个pin?
2.s2440IOP->rGPHCON |= ((2 << 4) | (2 << 6)); 这结果是bit5和bit7置1,是不是说 GPH2 [5:4] = 10, GPH3 [7:6] = 10,那就是pin2和pin3分别用作TXD[0]和RXD[1]。
3. GPHUP Bit Description
GPH[10:0] [10:0] 0: the pull up function attached to to the corresponding port pin is enabled.
1: the pull up function is disabled.
那第二句话s2440IOP->rGPHUP |= (1 << 4) | (1 << 5); 应该是把bit4和bit5置1,的确有可能是Disable pull-up on TXD1 and RXD1. 不过和前一句的配置不匹配啊。前一句并没有配置pin4和pin5.
多谢
兄弟,一看你那个s2440IOP->rGPHCON |= ((2 < < 4) | (2 < < 6));
s2440IOP->rGPHUP |= (1 < < 4) | (1 < < 5);就是错的了,
倘若是对着s2440IOP->rGPHCON |= ((2 < < 4) | (2 < < 6)); 来说的话,s2440IOP->rGPHUP |= (1 < < 2) | (1 < < 3);才是对的。呵呵
明白了,多谢二位。那头一个问题呢,为啥要用11个控制位来设置9pin的口。是不是rxd/txd我只能在0/1/2中选一个,不管我用哪个,9个pin都不可能全都用到。如果我用uart0的话,对应的应该是GPH0-3,或许GPH8-10也会用到,那pin只有0-8九个,GPH9/10对应到哪去了。
GPH的PIN口当然不是全部用来做UART的啦,也可用做其它工作呀,不明白楼主要执这种死角,分明是11个PIN啦,开发手册打错字当然是有的。
GPH有11个pin。只不过GPH0-3可以用作UART0也可以用做GPIO。GPH4-5可以用过Uart1或者GPIO,GPH6-7用作Uart2或者GPIO。GPH8-10用作Clkout或者GPIO。
都是相对独立的。没有必然联系要以前用的。楼主不用想的太复杂。你完全可以只用Uart0,其他的设置成GPIO即可。