注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
shangdawei的个人空间 https://home.eeworld.com.cn/space-uid-180876.html [收藏] [复制] [分享] [RSS]
日志

STR912如何设置使管脚功能?

已有 1619 次阅读2010-12-30 10:12


GPIO_DIR     GPIO Data Direction Register      
These bits are set and cleared by software to configure the corresponding
GPIO pin to be an input or an output.
All bits are cleared by a reset.
Therefore, the GPIO pins are input by default.

0: Input
1: Output


GPIO_SEL GPIO Mode Control Register      

These bits are set an cleared by software.
All bits are cleared by a reset.
Therefore, the GPIO pins are GPIO mode by default.

0: GPIO mode (for general purpose I/O)
1: Reserved

Note: This bit must be ‘0’ when GPIO is used.

GPIO_DATA GPIO Data Register

Values written in the GPIO_DATA register are transferred onto the
GPIO pins if the respective
pins have been configured as outputs through the GPIO_DIR register
and Alternate Function 1 is configured in the SCU_GPIOOUT register.


看起来如果要把数据发送到端口引脚:
1. GPIO_DIR    : 1 : GPIO as Output
2. SCU_GPIOOUT : 01 : Alternate Function 1


In order to write to GPIO_DATA, the corresponding bits in the mask,
resulting from the from bits [9:2] of the address offset, must be
HIGH. Otherwise the bit values remain unchanged by the write.

Similarly, the values read from this register are determined for each
bit, by the mask bit derived from bits [9:2] of the address offset used to access the data register.

Bits that are 1 in the address mask cause the corresponding bits in
GPIO_DATA to be read, and bits that are 0 in the address mask
cause the corresponding bits in GPIO_DATA to be read as 0,
regardless of their value.

A read from GPIO_DATA returns the last bit value written if the
respective pins are configured as output, or it returns the value on
the corresponding input pin when these are configured as inputs. All
bits are cleared by a reset.

看起来, 读取GPIO_DATA时:
1. 读取到输出锁存器的值 : GPIO 作为输出
2. 读取GPIO的引脚状态   : GPIO 作为输人


System control unit GPIO registers

GPIO Pins on P0 thru P7 have multiple input and output alternate functions.
You select these using the System Control Unit (SCU)registers.

GPIO output register (SCU_GPIOOUTn)

Reset value: 0000 0000 0000 0000

Pn.[7:0]OUT[1:0]: GPIO Port Output Control bits

00: Input mode <-- Default Mode
01: Alternate Output 1 (general purpose output)
10: Alternate Output 2
11: Alternate Output 3


SCU registers are also used to select open collector or Push-Pull operation

GPIO type register (SCU_GPIOTYPEm)

TYPE[7:0]: GPIO output type register
These bits are set and cleared by software to configure the
corresponding GPIO pin output type.
All bits are cleared by a reset, so the GPIO pins are push-pull by default.

0: Push-pull
1: Open collector


and to configure Port 4 pins for use as analog inputs.

GPIO analog mode register (SCU_GPIOANA)
P4[7:0]A: GPIO Port 4 Analog Control bits
These bits are set and cleared by software to configure the corresponding
GPIO port 4 pin in analog mode. When you use analog mode, clear the
corresponding bits in the SCU_GPIOINn and SCU_GPIOUTn registers.
0: Analog mode off
1: Analog mode on



GPIO Pins on P8 thru P9 are only multiplexed with EMI and have no SCU output or input control registers.
GPIO external memory interface register (SCU_EMI)

GPIOEMI: GPIO EMI selection

This bit is set and cleared by software to configure Port 8 and 9 to the EMI
block. It is cleared by a reset. Therefore, the external memory bus is
disabled by default.
0: Port 8 and 9 used for general purpose I/O
1: Port 8 and 9 connected to EMI block


All ports have SCU_GPIOTYPE registers for selecting
Open Collector or Push/Pull configuration.

GPIO type register (SCU_GPIOTYPEm)

TYPE[7:0]: GPIO output type register
These bits are set and cleared by software to configure the
corresponding GPIO pin output type.
All bits are cleared by a reset, so the GPIO pins are push-pull by default.

0: Push-pull
1: Open collector

GPIO input register (SCU_GPIOINn)
Pn.[7:0]IN: GPIO Port Input Control bits
0: On-chip peripheral not connected to the input
1: On-chip peripheral connected to the input (Alternate input 1)

Note: If a peripheral has the same input on multiple pins, do not enable
more than one pin.

看起来不用任何设置, default Input Function 一直是允许的.
备注: 需要配置为
 // GPIO0 All pins Default Input function
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //止输出功能
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_Init(GPIO0, &GPIO_InitStructure);


另外图片中没有 GPIO mode control register (GPIO_SEL) 这个寄存器的说明.

文档中提到:

GPIO mode control register (GPIO_SEL)

GPIOSEL[7:0]: GPIO mode control register
These bits are set an cleared by software. All bits are cleared by a reset.
0: GPIO mode (for general purpose I/O)
1: Reserved
Note: This bit must be ‘0’ when GPIO is used.

似乎说明, 用作GPIO时, 必须设置为 0
其他模式, 无需设置这个寄存器. (可以保持为0) ?


STR91x ENET 端口配置 

00 - P07 & P10 P15 P16 : Input : Default Input Function
P11 P12 P13 P14 P17 P52 P53 :  Output : Alternate Output 2

  // Assign pins to the MII interface
  // Enable GPIO clocks
  SCU_APBPeriphClockConfig(__GPIO0 | __GPIO1 | __GPIO5, ENABLE);
  // Release GPIO reset
  SCU_APBPeriphReset(__GPIO0 | __GPIO1 | __GPIO5, DISABLE);

  // GPIO0 All pins Default Input function
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_Init(GPIO0, &GPIO_InitStructure);

  // GPIO1 0,5,6 inputs
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_5 | GPIO_Pin_6;
  GPIO_Init(GPIO1, &GPIO_InitStructure);

  // GPIO1 1,2,3,4,7 Push-Pull outputs  Alt func 2
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |\
                                GPIO_Pin_4 | GPIO_Pin_7;
  GPIO_Init(GPIO1, &GPIO_InitStructure);

  // GPIO5 2,3 Push-Pull outputs  Alt func 2
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
  GPIO_Init(GPIO5, &GPIO_InitStructure);


STR91x ETM 端口配置

P20 - P27 P66 : Output : Alternate Output 3
P67 : Input : Alternate Input 1
 
 
execUserPreload(){

  __message "ETM_Init\n";
 
  __writeMemory32(0x011dc000, 0x5C002018, "Memory"); //port clock enable(SCU_PCGR1)
 
  __writeMemory32(0x011dc000, 0x5C002020, "Memory");// port reset clear( SCU_PRR1)

//OUT 2.7 -- 2.0] are all alt 3 (etm trace sync, pck0, 1, 2, 3, pipe status 0,1,2)(SCU_GPIOOUT2)
  __writeMemory32(0x0000ffff, 0x5C00204C, "Memory");                                       
               
//OUT 6.6 alt 3 function (trace clk out)(SCU_GPIOOUT6)
 __writeMemory32(0x00003000, 0x5C00205C, "Memory");                                                      
 
//IN 6.7  alt 1 function (trigger in)(SCU_GPIOIN6)
 __writeMemory32(0x00000080, 0x5C00207C, "Memory");
}

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章