当前位置: 首页>>代码示例>>C++>>正文


C++ GPIO_PinAFConfig函数代码示例

本文整理汇总了C++中GPIO_PinAFConfig函数的典型用法代码示例。如果您正苦于以下问题:C++ GPIO_PinAFConfig函数的具体用法?C++ GPIO_PinAFConfig怎么用?C++ GPIO_PinAFConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GPIO_PinAFConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: usart3_init

void usart3_init(void)
{
	/* RCC initialization */
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);

	/* GPIO initialization */
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);

	GPIO_InitTypeDef GPIO_InitStruct = {
		.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11,
		.GPIO_Mode = GPIO_Mode_AF,
		.GPIO_Speed = GPIO_Speed_50MHz,
		.GPIO_OType = GPIO_OType_PP,
		.GPIO_PuPd = GPIO_PuPd_UP
	};
	GPIO_Init(GPIOC, &GPIO_InitStruct);

	/* USART initialization */
	USART_InitTypeDef USART_InitStruct = {
		.USART_BaudRate = 9600,
		.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
		.USART_WordLength = USART_WordLength_8b,
		.USART_StopBits = USART_StopBits_1,
		.USART_Parity = USART_Parity_No
	};
	USART_Init(USART3, &USART_InitStruct);

	USART_Cmd(USART3, ENABLE);

	USART_ClearFlag(USART3, USART_FLAG_TC);

	/* DMA initialization */
	DMA_ClearFlag(DMA1_Stream4, DMA_FLAG_TCIF4);
}

char usart_getc(void)
{
	while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != SET);
	return USART_ReceiveData(USART3);
}

void usart_puts(uint8_t *datas, int size)
{
	DMA_ClearFlag(DMA1_Stream4, DMA_FLAG_TCIF4);

	/* Setup the DMA */
	DMA_InitTypeDef DMA_InitStructure = {
		.DMA_BufferSize = (uint32_t)size,
		.DMA_FIFOMode = DMA_FIFOMode_Disable,
		.DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
		.DMA_MemoryBurst = DMA_MemoryBurst_Single,
		.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
		.DMA_MemoryInc = DMA_MemoryInc_Enable,
		.DMA_Mode = DMA_Mode_Normal,
		.DMA_PeripheralBaseAddr = (uint32_t)(&USART3->DR),
		.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
		.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
		.DMA_Priority = DMA_Priority_Medium,
		.DMA_Channel = DMA_Channel_7,
		.DMA_DIR = DMA_DIR_MemoryToPeripheral,
		.DMA_Memory0BaseAddr = (uint32_t)datas
        };
	DMA_Init(DMA1_Stream4, &DMA_InitStructure);

	/* Enable DMA to sent the data */
	DMA_Cmd(DMA1_Stream4, ENABLE);
	USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);

	while(DMA_GetFlagStatus(DMA1_Stream4, DMA_FLAG_TCIF4) == RESET);
}

int main()
{
	usart3_init();

	char *string = "STM32: Hello World!\n\r";


	while(1) {
		usart_puts(string, strlen(string) + 1);
	}

	return 0;
}
开发者ID:chunting746,项目名称:stm32f4-examples,代码行数:87,代码来源:main.c

示例2: i2c_lowLevel_init

/**
 * @brief  Initializes peripherals used by the I2C EEPROM driver.
 * @param  None
 * @retval None
 */
static void i2c_lowLevel_init(i2c_dev *dev)
    {
    GPIO_InitTypeDef GPIO_I2C1_InitStructure;
    GPIO_InitTypeDef GPIO_I2C2_InitStructure;

    /* Enable the i2c */
    RCC_APB1PeriphClockCmd(dev->clk, ENABLE);

    /* Reset the Peripheral */
    RCC_APB1PeriphResetCmd(dev->clk, ENABLE);
    RCC_APB1PeriphResetCmd(dev->clk, DISABLE);

    /* Enable the GPIOs for the SCL/SDA Pins */
    RCC_AHB1PeriphClockCmd(dev->gpio_port->clk, ENABLE);



    if(dev->I2Cx == I2C1) {
	/* GPIO configuration */
	/* Configure SCL */
	GPIO_I2C1_InitStructure.GPIO_Pin = BIT(dev->scl_pin);
	GPIO_I2C1_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_I2C1_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_I2C1_InitStructure.GPIO_OType = GPIO_OType_OD;
	GPIO_I2C1_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_Init(dev->gpio_port->GPIOx, &GPIO_I2C1_InitStructure);

	/* Configure SDA */
	GPIO_I2C1_InitStructure.GPIO_Pin = BIT(dev->sda_pin);
	GPIO_Init(dev->gpio_port->GPIOx, &GPIO_I2C1_InitStructure);

	/* Connect GPIO pins to peripheral */
	GPIO_PinAFConfig(dev->gpio_port->GPIOx, dev->scl_pin, dev->gpio_af);
	GPIO_PinAFConfig(dev->gpio_port->GPIOx, dev->sda_pin, dev->gpio_af);

	NVIC_InitTypeDef NVIC_InitStructure;
	/* Configure and enable I2C DMA TX Channel interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C1_DMA_TX_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	/* Configure and enable I2C DMA RX Channel interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C1_DMA_RX_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_Init(&NVIC_InitStructure);

	/*!< I2C DMA TX and RX channels configuration */
	/* Enable the DMA clock */
	RCC_AHB1PeriphClockCmd(sEE_I2C1_DMA_CLK, ENABLE);

	/* Clear any pending flag on Rx Stream  */
	DMA_ClearFlag(sEE_I2C1_DMA_STREAM_TX,
		sEE1_TX_DMA_FLAG_FEIF | sEE1_TX_DMA_FLAG_DMEIF | sEE1_TX_DMA_FLAG_TEIF
			| sEE1_TX_DMA_FLAG_HTIF | sEE1_TX_DMA_FLAG_TCIF );
	/* Disable the EE I2C Tx DMA stream */
	DMA_Cmd(sEE_I2C1_DMA_STREAM_TX, DISABLE);
	/* Configure the DMA stream for the EE I2C peripheral TX direction */
	DMA_DeInit(sEE_I2C1_DMA_STREAM_TX );
	I2C1DMA_InitStructure.DMA_Channel = sEE_I2C1_DMA_CHANNEL;
	I2C1DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&I2C1->DR;
	I2C1DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t) 0; /* This parameter will be configured durig communication */
	I2C1DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; /* This parameter will be configured durig communication */
	I2C1DMA_InitStructure.DMA_BufferSize = 0xFFFF; /* This parameter will be configured durig communication */
	I2C1DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	I2C1DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	I2C1DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	I2C1DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	I2C1DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
	I2C1DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
	I2C1DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
	I2C1DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
	I2C1DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	I2C1DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(sEE_I2C1_DMA_STREAM_TX, &I2C1DMA_InitStructure);

	/* Clear any pending flag on Rx Stream */
	DMA_ClearFlag(sEE_I2C1_DMA_STREAM_RX,
		sEE1_RX_DMA_FLAG_FEIF | sEE1_RX_DMA_FLAG_DMEIF | sEE1_RX_DMA_FLAG_TEIF
			| sEE1_RX_DMA_FLAG_HTIF | sEE1_RX_DMA_FLAG_TCIF );
	/* Disable the EE I2C DMA Rx stream */
	DMA_Cmd(sEE_I2C1_DMA_STREAM_RX, DISABLE);
	/* Configure the DMA stream for the EE I2C peripheral RX direction */
	DMA_DeInit(sEE_I2C1_DMA_STREAM_RX );
	DMA_Init(sEE_I2C1_DMA_STREAM_RX, &I2C1DMA_InitStructure);

	/* Enable the DMA Channels Interrupts */
	DMA_ITConfig(sEE_I2C1_DMA_STREAM_TX, DMA_IT_TC, ENABLE);
	DMA_ITConfig(sEE_I2C1_DMA_STREAM_RX, DMA_IT_TC, ENABLE);

    } else if (dev->I2Cx == I2C2) {
	/* GPIO configuration */
	/* Configure SCL */
//.........这里部分代码省略.........
开发者ID:136048599,项目名称:vrbrain,代码行数:101,代码来源:i2c.c

示例3: Hardware_PWM_init

/***********************************
	Hardware Init PWM for Servos
 ***********************************/
void Hardware_PWM_init(void) {

	GPIO_InitTypeDef  GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	TIM_OCInitTypeDef  TIM_OCInitStructure;
	uint16_t original_x_pulse = 765;
	uint16_t original_y_pulse = 645;
	uint16_t PrescalerValue = 0;

	/* Enable the GPIO D2/D3 Clock */
	RCC_AHB1PeriphClockCmd(NP2_D1_GPIO_CLK, ENABLE);
	RCC_AHB1PeriphClockCmd(NP2_D2_GPIO_CLK, ENABLE);
	RCC_AHB1PeriphClockCmd(NP2_D3_GPIO_CLK, ENABLE);

	/* TIM2 clock enable */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

	/* Configure the D2/D3 pin for PWM output */
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Pin = NP2_D2_PIN;
	GPIO_Init(NP2_D2_GPIO_PORT, &GPIO_InitStructure);	//Struct for D2
	GPIO_InitStructure.GPIO_Pin = NP2_D3_PIN;
	GPIO_Init(NP2_D3_GPIO_PORT, &GPIO_InitStructure);	//Struct for D3

	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_Pin = NP2_D1_PIN;
	GPIO_Init(NP2_D1_GPIO_PORT, &GPIO_InitStructure);

	/* Connect TIM2 output to D2/D3 pin */
	GPIO_PinAFConfig(NP2_D2_GPIO_PORT, NP2_D2_PINSOURCE, GPIO_AF_TIM2);
	GPIO_PinAFConfig(NP2_D3_GPIO_PORT, NP2_D3_PINSOURCE, GPIO_AF_TIM2);

	/* Compute the prescaler value. SystemCoreClock = 168000000 - set for 500Khz clock */
	PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 500000) - 1;

	/* Time 2 mode and prescaler configuration */
	TIM_TimeBaseStructure.TIM_Period = 10000;
	TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

	/* Configure Timer 2 mode and prescaler */
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

	/* PWM Mode configuration for Channel3/4 - set pulse width*/
	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;				//Set PWM MODE (1 or 2 - NOT CHANNEL)
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
	TIM_OCInitStructure.TIM_Pulse = original_y_pulse;
	TIM_OC3Init(TIM2, &TIM_OCInitStructure);						//Channel 3 - D3
	TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
	TIM_OCInitStructure.TIM_Pulse = original_x_pulse;
	TIM_OC4Init(TIM2, &TIM_OCInitStructure);						//Channel 4 - D2
	TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable);

	/* TIM2 enable counter */
	TIM_Cmd(TIM2, ENABLE);
}
开发者ID:reyrey1989,项目名称:CSSE3010-2014,代码行数:64,代码来源:main.c

示例4: bt_usart_conf

void bt_usart_conf(u32 br){
	
//  GPIO_InitTypeDef  GPIO_InitStructure;
//  USART_InitTypeDef USART_InitStructure;  
//	if(br==0)br = 115200;
//	/*DMA1 open*/
//	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);  

//  /* Enable UART GPIO clocks */
//  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
//  /* Enable UART clock */
//  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
//  //UART
//  USART_InitStructure.USART_BaudRate = br;
//  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
//  USART_InitStructure.USART_StopBits = USART_StopBits_1; 
//  USART_InitStructure.USART_Parity = USART_Parity_No; 
//  USART_InitStructure.USART_HardwareFlowControl = 
//    USART_HardwareFlowControl_None; 
//  USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
//  USART_Init(BT_USART, &USART_InitStructure);
//  USART_Cmd(BT_USART,ENABLE);
//  ///TX
//  RCC_APB2PeriphClockCmd(UART_IO_PERIPH,ENABLE);
//  GPIO_SetBits(UART_IO_PORT,UART_IO_TX);
//  GPIO_InitStructure.GPIO_Pin = UART_IO_TX;
//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
//  GPIO_Init(UART_IO_PORT, &GPIO_InitStructure);
//  ///RX
//  RCC_APB2PeriphClockCmd(UART_IO_PERIPH,ENABLE);
//  GPIO_InitStructure.GPIO_Pin=UART_IO_RX;
//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//  GPIO_Init(UART_IO_PORT, &GPIO_InitStructure);
	
	USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
	if(br==0)br = 115200;
  /* Peripheral Clock Enable -------------------------------------------------*/
  /* Enable GPIO clock */
  RCC_AHB1PeriphClockCmd(USARTx_TX_GPIO_CLK | USARTx_RX_GPIO_CLK, ENABLE);
  
  /* Enable USART clock */
  USARTx_CLK_INIT(USARTx_CLK, ENABLE);
  
  /* Enable the DMA clock */
  RCC_AHB1PeriphClockCmd(USARTx_DMAx_CLK, ENABLE);
  
  /* USARTx GPIO configuration -----------------------------------------------*/ 
  /* Connect USART pins to AF7 */
  GPIO_PinAFConfig(USARTx_TX_GPIO_PORT, USARTx_TX_SOURCE, USARTx_TX_AF);
  GPIO_PinAFConfig(USARTx_RX_GPIO_PORT, USARTx_RX_SOURCE, USARTx_RX_AF);
  
  /* Configure USART Tx and Rx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  
  GPIO_InitStructure.GPIO_Pin = USARTx_TX_PIN;
  GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = USARTx_RX_PIN;
  GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStructure);
 
  /* USARTx configuration ----------------------------------------------------*/
  /* Enable the USART OverSampling by 8 */
 // USART_OverSampling8Cmd(USARTx, ENABLE); 
  
  /* USARTx configured as follows:
        - BaudRate = 5250000 baud
		   - Maximum BaudRate that can be achieved when using the Oversampling by 8
		     is: (USART APB Clock / 8) 
			 Example: 
			    - (USART3 APB1 Clock / 8) = (42 MHz / 8) = 5250000 baud
			    - (USART1 APB2 Clock / 8) = (84 MHz / 8) = 10500000 baud
		   - Maximum BaudRate that can be achieved when using the Oversampling by 16
		     is: (USART APB Clock / 16) 
			 Example: (USART3 APB1 Clock / 16) = (42 MHz / 16) = 2625000 baud
			 Example: (USART1 APB2 Clock / 16) = (84 MHz / 16) = 5250000 baud
        - Word Length = 8 Bits
        - one Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */ 
  USART_InitStructure.USART_BaudRate = br;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  /* When using Parity the word length must be configured to 9 bits */
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  USART_Init(USARTx, &USART_InitStructure);
	USART_Cmd(BT_USART,ENABLE);
}
开发者ID:XHelaoshi,项目名称:USER,代码行数:96,代码来源:hal_uart_dma.c

示例5: EepromSpiInitialization

/**
* @brief  Initializes the SPI for the EEPROM.
*         SPI, MISO, MOSI and SCLK are the same used for the SPIRIT1.
*         This function can be replaced by EepromCsPinInitialization if
*         SpiritSpiInit is called.
* @param  None
* @retval None
*/
void EepromSpiInitialization(void)
{ 
  SPI_InitTypeDef SPI_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;

  s_EepromSpiPort = s_EepromSpiPortVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiCsPin = (uint16_t *)&s_vectpxEepromSpiCsPinVersion[SdkEvalGetVersion()];
  s_vectpxEepromSpiCsPort = &s_vectpxEepromSpiCsPortVersion[SdkEvalGetVersion()];
    
  if(SdkEvalGetVersion() == SDK_EVAL_VERSION_2_1) {
    /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
    RCC_APB2PeriphClockCmd(EEPROM_V2_SPI_PERIPH_RCC, ENABLE);
    RCC_AHBPeriphClockCmd(EEPROM_V2_SPI_PERIPH_MOSI_RCC | EEPROM_V2_SPI_PERIPH_MISO_RCC | EEPROM_V2_SPI_PERIPH_SCLK_RCC | EEPROM_V2_SPI_PERIPH_CS_RCC, ENABLE);
    
    /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/
    GPIO_PinAFConfig(EEPROM_V2_SPI_PERIPH_MOSI_PORT, EEPROM_V2_SPI_PERIPH_MOSI_RCC_SOURCE, EEPROM_V2_SPI_PERIPH_MOSI_AF);
    GPIO_PinAFConfig(EEPROM_V2_SPI_PERIPH_MISO_PORT, EEPROM_V2_SPI_PERIPH_MISO_RCC_SOURCE, EEPROM_V2_SPI_PERIPH_MISO_AF);
    GPIO_PinAFConfig(EEPROM_V2_SPI_PERIPH_SCLK_PORT, EEPROM_V2_SPI_PERIPH_SCLK_RCC_SOURCE, EEPROM_V2_SPI_PERIPH_SCLK_AF);
    
    /* Configure SPI pins:SCLK, MISO and MOSI */
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
    
    GPIO_InitStructure.GPIO_Pin = EEPROM_V2_SPI_PERIPH_SCLK_PIN;
    GPIO_Init(EEPROM_V2_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = EEPROM_V2_SPI_PERIPH_MISO_PIN;
    GPIO_Init(EEPROM_V2_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = EEPROM_V2_SPI_PERIPH_MOSI_PIN;
    GPIO_Init(EEPROM_V2_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure);

  }
  else if(SdkEvalGetVersion() == SDK_EVAL_VERSION_3 || SdkEvalGetVersion() == SDK_EVAL_VERSION_D1) {      
    /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
    RCC_APB1PeriphClockCmd(EEPROM_V3_SPI_PERIPH_RCC, ENABLE);  
    RCC_AHBPeriphClockCmd(EEPROM_V3_SPI_PERIPH_MOSI_RCC | EEPROM_V3_SPI_PERIPH_MISO_RCC | EEPROM_V3_SPI_PERIPH_SCLK_RCC | EEPROM_V3_SPI_PERIPH_CS_RCC, ENABLE);
    
    /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/
    GPIO_PinAFConfig(EEPROM_V3_SPI_PERIPH_MOSI_PORT, EEPROM_V3_SPI_PERIPH_MOSI_RCC_SOURCE, EEPROM_V3_SPI_PERIPH_MOSI_AF);
    GPIO_PinAFConfig(EEPROM_V3_SPI_PERIPH_MISO_PORT, EEPROM_V3_SPI_PERIPH_MISO_RCC_SOURCE, EEPROM_V3_SPI_PERIPH_MISO_AF);
    GPIO_PinAFConfig(EEPROM_V3_SPI_PERIPH_SCLK_PORT, EEPROM_V3_SPI_PERIPH_SCLK_RCC_SOURCE, EEPROM_V3_SPI_PERIPH_SCLK_AF);
    
    /* Configure SPI pins:SCLK, MISO and MOSI */
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
    
    GPIO_InitStructure.GPIO_Pin = EEPROM_V3_SPI_PERIPH_SCLK_PIN;
    GPIO_Init(EEPROM_V3_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = EEPROM_V3_SPI_PERIPH_MISO_PIN;
    GPIO_Init(EEPROM_V3_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = EEPROM_V3_SPI_PERIPH_MOSI_PIN;
    GPIO_Init(EEPROM_V3_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure);
    
  }
  
  /* Configure SPI pin: CS */
  GPIO_InitStructure.GPIO_Pin = *s_vectnEepromSpiCsPin;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_Init(*s_vectpxEepromSpiCsPort, &GPIO_InitStructure);
  
  /* Configure SPI peripheral */
  SPI_DeInit(s_EepromSpiPort);
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(s_EepromSpiPort, &SPI_InitStructure);
  
  SPI_Cmd(s_EepromSpiPort, ENABLE);
  
  EepromSPICSHigh();
  
}
开发者ID:bzdegluk,项目名称:ACQ,代码行数:96,代码来源:SPIRIT_SDK_EEPROM.c

示例6: I2Cx_Init

// Initialize specified I2C peripheral
// input:
//   I2Cx - I2C port
//   Clock - I2C speed (Hz)
// return:
//   I2C_ERROR if there was a timeout during I2C initialization, I2C_SUCCESS otherwise
// note: minimum APB1 frequency for I2C work is 2MHz
I2C_Status I2Cx_Init(I2C_TypeDef* I2Cx, uint32_t Clock) {
	GPIO_InitTypeDef PORT;
	RCC_ClocksTypeDef RCC_Clocks; // To compute I2C speed depending on current MCU clocking
	uint16_t reg, spd, freq;

	PORT.GPIO_Speed = GPIO_Speed_40MHz;
	PORT.GPIO_OType = GPIO_OType_OD;
	PORT.GPIO_Mode  = GPIO_Mode_AF;
	PORT.GPIO_PuPd  = GPIO_PuPd_UP;

	if (I2Cx == I2C1) {
		// Enable the I2C1 peripheral clock
		RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;
		// Reset the I2C1 peripheral to initial state
		RCC->APB1RSTR |=  RCC_APB1RSTR_I2C1RST;
		RCC->APB1RSTR &= ~RCC_APB1RSTR_I2C1RST;
		// Enable the I2Cx GPIO peripheral clock
		RCC->AHBENR |= I2C1_GPIO_AHB;
		// Initialize the I2C1 GPIO peripheral
		PORT.GPIO_Pin = I2C1_GPIO_SCL | I2C1_GPIO_SDA;
		GPIO_Init(I2C1_GPIO_PORT,&PORT);
		GPIO_PinAFConfig(I2C1_GPIO_PORT,I2C1_GPIO_SCL_SRC,GPIO_AF_I2C1);
		GPIO_PinAFConfig(I2C1_GPIO_PORT,I2C1_GPIO_SDA_SRC,GPIO_AF_I2C1);
	} else {
		// Enable the I2C2 peripheral clock
		RCC->APB1ENR |= RCC_APB1ENR_I2C2EN;
		// Reset the I2C2 peripheral to initial state
		RCC->APB1RSTR |=  RCC_APB1RSTR_I2C2RST;
		RCC->APB1RSTR &= ~RCC_APB1RSTR_I2C2RST;
		// Enable the I2Cx GPIO peripheral clock
		RCC->AHBENR |= I2C2_GPIO_AHB;
		// Initialize the I2C2 GPIO peripheral
		PORT.GPIO_Pin = I2C2_GPIO_SCL | I2C2_GPIO_SDA;
		GPIO_Init(I2C2_GPIO_PORT,&PORT);
		GPIO_PinAFConfig(I2C2_GPIO_PORT,I2C2_GPIO_SCL_SRC,GPIO_AF_I2C2);
		GPIO_PinAFConfig(I2C2_GPIO_PORT,I2C2_GPIO_SDA_SRC,GPIO_AF_I2C2);
	}

	// Configure the I2C peripheral

	// Get CR2 register value and clear FREQ[5:0] bits
	reg = I2Cx->CR2 & ~I2C_CR2_FREQ;
	// Get current RCC clocks
	RCC_GetClocksFreq(&RCC_Clocks);
	// Set FREQ bits depending on PCLK1 value
	freq = (uint16_t)(RCC_Clocks.PCLK1_Frequency / 1000000);
	I2Cx->CR2 |= freq;

	// TRISE can be configured only when I2C peripheral disabled
	I2Cx->CR1 &= ~I2C_CR1_PE;

	// Configure I2C speed
	if (Clock <= 100000) {
		// I2C standard speed (Clock <= 100kHz)
		spd = (uint16_t)(RCC_Clocks.PCLK1_Frequency / (Clock << 1)); // Duty cycle 50%/50%
		// I2C CCR value: Standard mode
		reg = (spd < 0x04) ? 0x04 : spd;
		// Maximum rise time for standard mode
		I2Cx->TRISE = freq + 1;
	} else {
		// I2C fast speed (100kHz > Clock <= 400kHz)
		// PCLK1 frequency must be a multiple of 10MHz
		spd = (uint16_t)(RCC_Clocks.PCLK1_Frequency / (Clock * 3)); // Duty cycle 66%/33% (Tlow/Thigh = 2)
//		spd = (uint16_t)(RCC_Clocks.PCLK1_Frequency / (Clock * 25)); // Duty cycle 64%/33% (Tlow/Thigh = 16/9)
//		reg |= I2C_CCR_DUTY; // I2C fast mode mode duty cycle = 16/9
		// I2C CCR value: Fast mode
		reg = (spd == 0) ? 1 : spd;
		reg |= I2C_CCR_FS;
		// Maximum rise time for fast mode
	    I2Cx->TRISE = (uint16_t)(((freq * 300) / 1000) + 1);
	}
	// Write to I2C CCR register
	I2Cx->CCR = reg;

	// Enable acknowledge, I2C mode, peripheral enabled
	I2Cx->CR1 = I2C_CR1_ACK | I2C_CR1_PE;

	// Set I2C own address: 0x00, 7-bit
	I2Cx->OAR1 = (1 << 14); // Bit 14 should be kept as 1

	// Wait until I2C bus is free
	if (I2Cx_WaitFlagReset(I2Cx,I2C_F_BUSY) == I2C_ERROR) return I2C_ERROR;

	return I2C_SUCCESS;
}
开发者ID:9zigen,项目名称:stm32,代码行数:92,代码来源:i2c.c

示例7: USB_OTG_BSP_Init

/**
 * @brief  USB_OTG_BSP_Init
 *         Initilizes BSP configurations
 * @param  None
 * @retval None
 */
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{
	/* Note: On STM32F4-Discovery board only USB OTG FS core is supported. */

	GPIO_InitTypeDef GPIO_InitStructure;
#ifdef USE_USB_OTG_FS

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

	/* Configure SOF VBUS ID DM DP Pins */
	GPIO_InitStructure.GPIO_Pin = 	GPIO_Pin_11 | 	// Data -
									GPIO_Pin_12;	// Data +

	#ifndef USB_MSC_HOST_DISABLE_VBUS
	GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_9;		// VBUS
	#endif
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	#ifndef USB_MSC_HOST_DISABLE_VBUS
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource9, GPIO_AF_OTG1_FS);
	#endif
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource11, GPIO_AF_OTG1_FS);
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource12, GPIO_AF_OTG1_FS);

	/* this for ID line debug */
	#ifndef USB_MSC_HOST_DISABLE_ID
	GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource10, GPIO_AF_OTG1_FS) ;
	#endif

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
	RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
	
#else //USE_USB_OTG_HS

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);

	/* Configure SOF VBUS ID DM DP Pins */  
	GPIO_InitStructure.GPIO_Pin = 	GPIO_Pin_14 |	// Data -
									GPIO_Pin_15;	// Data +

	#ifndef USB_MSC_HOST_DISABLE_ID
	GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
	#endif

	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 
	GPIO_Init(GPIOB, &GPIO_InitStructure);  

	#ifndef USB_MSC_HOST_DISABLE_ID
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource12, GPIO_AF_OTG2_FS);
	#endif
	
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource14, GPIO_AF_OTG2_FS); 
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource15, GPIO_AF_OTG2_FS);   
	
	/* VBUS */
	#ifndef USB_MSC_HOST_DISABLE_VBUS
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	#endif

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS, ENABLE);  

#endif //USB_OTG_HS
}
开发者ID:Captnlink,项目名称:SkyRunner_ELE400,代码行数:84,代码来源:usb_bsp.c

示例8: sflash_platform_init

int sflash_platform_init( int peripheral_id, void** platform_peripheral_out )
{
    GPIO_InitTypeDef GPIO_InitStructure;
    SPI_InitTypeDef  SPI_InitStructure;

    (void) peripheral_id; /* Unused due to single SPI Flash */

    /* Enable clocks */
    SFLASH_SPI_CLK_INIT( SFLASH_SPI_CLK, ENABLE );

    RCC_AHB1PeriphClockCmd( SFLASH_SPI_SCK_GPIO_CLK  | SFLASH_SPI_MISO_GPIO_CLK |
                            SFLASH_SPI_MOSI_GPIO_CLK | SFLASH_CS_CLK, ENABLE      );


    /* Use Alternate Functions for SPI pins */
    GPIO_PinAFConfig( SFLASH_SPI_SCK_GPIO_PORT,  SFLASH_SPI_SCK_SOURCE,  SFLASH_SPI_SCK_AF  );
    GPIO_PinAFConfig( SFLASH_SPI_MISO_GPIO_PORT, SFLASH_SPI_MISO_SOURCE, SFLASH_SPI_MISO_AF );
    GPIO_PinAFConfig( SFLASH_SPI_MOSI_GPIO_PORT, SFLASH_SPI_MOSI_SOURCE, SFLASH_SPI_MOSI_AF );

    /* Setup pin types */
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;

    GPIO_InitStructure.GPIO_Pin   = SFLASH_SPI_SCK_PIN;
    GPIO_Init( SFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure );

    GPIO_InitStructure.GPIO_Pin   =  SFLASH_SPI_MOSI_PIN;
    GPIO_Init( SFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure );

    GPIO_InitStructure.GPIO_Pin   =  SFLASH_SPI_MISO_PIN;
    GPIO_Init( SFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure );

    /* Chip select is used as a GPIO */
    GPIO_InitStructure.GPIO_Pin   = SFLASH_CS_PIN;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_Init( SFLASH_CS_PORT, &GPIO_InitStructure );

    /* Deselect flash initially */
    GPIO_SetBits( SFLASH_CS_PORT, SFLASH_CS_PIN );

    /*!< SPI configuration */
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;

    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStructure.SPI_CRCPolynomial = 7;
    SPI_Init(SFLASH_SPI, &SPI_InitStructure);

    /* Enable the SPI peripheral */
    SPI_Cmd(SFLASH_SPI, ENABLE);

    *platform_peripheral_out = (void*)SFLASH_SPI;

    return 0;
}
开发者ID:bangkr,项目名称:MiCO_ELink407,代码行数:65,代码来源:EMW3165.c

示例9: init_Timer

void init_Timer()
{

	  GPIO_InitTypeDef GPIO_InitStructure;
	  NVIC_InitTypeDef NVIC_InitStructure;
	  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	  uint16_t PrescalerValue = 0;

	  /* TIM3 clock enable */
	  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
	
	  /* Enable the TIM3 gloabal Interrupt */
	  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
	  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	  NVIC_Init(&NVIC_InitStructure);
	
	  /* ---------------------------------------------------------------
	    TIM3 Configuration: Output Compare Timing Mode:
	    TIM3 counter clock at 6 MHz
	    CC1 Update Rate : 128 Hz
	  --------------------------------------------------------------- */
	
	  /* Compute the prescaler value */
	  PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 6000000) - 1;
	
	  /* Time base configuration */
	  TIM_TimeBaseStructure.TIM_Period = 6000000 -1; //46875;
	  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
	  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	
	  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
	
	  /* Prescaler configuration */
	  TIM_PrescalerConfig(TIM2, PrescalerValue, TIM_PSCReloadMode_Immediate);
	   
	  /* TIM Interrupts enable */
	  TIM_ITConfig(TIM2, TIM_IT_CC1 , ENABLE);
	
	  /* TIM3 enable counter */
	  TIM_Cmd(TIM2, ENABLE);
		
	return;
  /* TIM3 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

  /* GPIOC clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  
  /* GPIOC Configuration: TIM3 CH1 (PC6), TIM3 CH2 (PC7), TIM3 CH3 (PC8) and TIM3 CH4 (PC9) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
  GPIO_Init(GPIOE, &GPIO_InitStructure); 

  /* Connect TIM3 pins to AF2 */  
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource13, GPIO_AF_TIM1);
	
	PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 20000000) - 1;

  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period =1000000;
  TIM_TimeBaseStructure.TIM_Prescaler = 1000;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  /* PWM1 Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  /* PWM1 Mode configuration: Channel3 */
  TIM_OCInitStructure.TIM_Pulse = 45;
  TIM_OC3Init(TIM1, &TIM_OCInitStructure);
  TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);

  TIM_ARRPreloadConfig(TIM1, ENABLE);

  CCR3_Val = 100;
  /* TIM3 enable counter */
  TIM_Cmd(TIM1, ENABLE);
	
}
开发者ID:lordhippo,项目名称:ImmortalsSender,代码行数:89,代码来源:main.c

示例10: PIOS_USART_Init

/**
* Initialise a single USART device
*/
int32_t PIOS_USART_Init(uintptr_t * usart_id, const struct pios_usart_cfg * cfg)
{
	PIOS_DEBUG_Assert(usart_id);
	PIOS_DEBUG_Assert(cfg);

	struct pios_usart_dev * usart_dev;

	usart_dev = (struct pios_usart_dev *) PIOS_USART_alloc();
	if (!usart_dev) goto out_fail;

	/* Bind the configuration to the device instance */
	usart_dev->cfg = cfg;

	/* Map pins to USART function */
	if (usart_dev->cfg->remap) {
		if (usart_dev->cfg->rx.gpio != 0)
			GPIO_PinAFConfig(usart_dev->cfg->rx.gpio,
				usart_dev->cfg->rx.pin_source,
				usart_dev->cfg->remap);
		if (usart_dev->cfg->tx.gpio != 0)
			GPIO_PinAFConfig(usart_dev->cfg->tx.gpio,
				usart_dev->cfg->tx.pin_source,
				usart_dev->cfg->remap);
	}

	/* Initialize the USART Rx and Tx pins */
	if (usart_dev->cfg->rx.gpio != 0)
		GPIO_Init(usart_dev->cfg->rx.gpio, (GPIO_InitTypeDef *)&usart_dev->cfg->rx.init);
	if (usart_dev->cfg->tx.gpio != 0)
		GPIO_Init(usart_dev->cfg->tx.gpio, (GPIO_InitTypeDef *)&usart_dev->cfg->tx.init);

	/* Apply inversion and swap settings */
	if (usart_dev->cfg->rx_invert == true)
		USART_InvPinCmd(usart_dev->cfg->regs, USART_InvPin_Rx, ENABLE);
	else
		USART_InvPinCmd(usart_dev->cfg->regs, USART_InvPin_Rx, DISABLE);

	if (usart_dev->cfg->tx_invert == true)
		USART_InvPinCmd(usart_dev->cfg->regs, USART_InvPin_Tx, ENABLE);
	else
		USART_InvPinCmd(usart_dev->cfg->regs, USART_InvPin_Tx, DISABLE);

	if (usart_dev->cfg->rxtx_swap == true)
		USART_SWAPPinCmd(usart_dev->cfg->regs, ENABLE);
	else
		USART_SWAPPinCmd(usart_dev->cfg->regs, DISABLE);

	/* Configure the USART */
	USART_Init(usart_dev->cfg->regs, (USART_InitTypeDef *)&usart_dev->cfg->init);

	*usart_id = (uintptr_t)usart_dev;

	/* Configure USART Interrupts */
	switch ((uint32_t)usart_dev->cfg->regs) {
	case (uint32_t)USART1:
		PIOS_USART_1_id = (uintptr_t)usart_dev;
		break;
	case (uint32_t)USART2:
		PIOS_USART_2_id = (uintptr_t)usart_dev;
		break;
	case (uint32_t)USART3:
		PIOS_USART_3_id = (uintptr_t)usart_dev;
		break;
	case (uint32_t)UART4:
		PIOS_UART_4_id = (uintptr_t)usart_dev;
		break;
	case (uint32_t)UART5:
		PIOS_UART_5_id = (uintptr_t)usart_dev;
		break;
	}
	NVIC_Init((NVIC_InitTypeDef *)&(usart_dev->cfg->irq.init));
	USART_ITConfig(usart_dev->cfg->regs, USART_IT_RXNE, ENABLE);
	USART_ITConfig(usart_dev->cfg->regs, USART_IT_TXE,  ENABLE);

	// FIXME XXX Clear / reset uart here - sends NUL char else

	/* Enable USART */
	USART_Cmd(usart_dev->cfg->regs, ENABLE);

	return(0);

out_fail:
	return(-1);
}
开发者ID:1heinz,项目名称:TauLabs,代码行数:87,代码来源:pios_usart.c

示例11: f4_sram_pins_init

static int f4_sram_pins_init( const wiced_sram_device_t* sram, const stm32f4xx_platform_nor_sram_t* settings )
{
    /* Enable clocks for associated gpios */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);

    GPIO_PinAFConfig(GPIOD, 7, GPIO_AF_FSMC);   /* one of chip select control signals NE1-NE4 to FSMC  */

    /* Configure gpios for FSMC alternate function */
    /* Connect all gpio lined to the FSMC */

    GPIO_PinAFConfig(GPIOF, 0, GPIO_AF_FSMC);   /* A0 connected to PF0 */
    GPIO_PinAFConfig(GPIOF, 1, GPIO_AF_FSMC);   /* A1 connected to PF1 */
    GPIO_PinAFConfig(GPIOF, 2, GPIO_AF_FSMC);   /* A2 connected to PF2 */
    GPIO_PinAFConfig(GPIOF, 3, GPIO_AF_FSMC);   /* A3 connented to PF3 */
    GPIO_PinAFConfig(GPIOF, 4, GPIO_AF_FSMC);   /* A4 connected to PF4 */
    GPIO_PinAFConfig(GPIOF, 5, GPIO_AF_FSMC);   /* A5 connected to PF5 */
    GPIO_PinAFConfig(GPIOF, 12, GPIO_AF_FSMC);  /* A6 connected to PF12 */
    GPIO_PinAFConfig(GPIOF, 13, GPIO_AF_FSMC);  /* A7 connected to PF13 */
    GPIO_PinAFConfig(GPIOF, 14, GPIO_AF_FSMC);  /* A8 connected to PF14 */
    GPIO_PinAFConfig(GPIOF, 15, GPIO_AF_FSMC);  /* A9 connected to PF15 */
    GPIO_PinAFConfig(GPIOG, 0, GPIO_AF_FSMC);   /* A10 connected to PG0 */
    GPIO_PinAFConfig(GPIOG, 1, GPIO_AF_FSMC);   /* A11 connected to PG1 */
    GPIO_PinAFConfig(GPIOG, 2, GPIO_AF_FSMC);   /* A12 connected to PG2 */
    GPIO_PinAFConfig(GPIOG, 3, GPIO_AF_FSMC);   /* A13 connected to PG3 */
    GPIO_PinAFConfig(GPIOG, 4, GPIO_AF_FSMC);   /* A14 connected to PG4 */
    GPIO_PinAFConfig(GPIOG, 5, GPIO_AF_FSMC);   /* A15 connected to PG5 */

    GPIO_PinAFConfig(GPIOD, 11, GPIO_AF_FSMC);      /* A16 connected to PD11 */
    GPIO_PinAFConfig(GPIOD, 12, GPIO_AF_FSMC);      /* A17 connected to PD12 */
    GPIO_PinAFConfig(GPIOD, 13, GPIO_AF_FSMC);      /* A18 connected to PD13 */
    GPIO_PinAFConfig(GPIOE, 3, GPIO_AF_FSMC);       /* A19 connected to PE3  */
    GPIO_PinAFConfig(GPIOE, 4, GPIO_AF_FSMC);       /* A20 connected to PE4 */
    GPIO_PinAFConfig(GPIOE, 5, GPIO_AF_FSMC);       /* A21 connected to PE5 */

    GPIO_PinAFConfig(GPIOE, 6, GPIO_AF_FSMC);       /* A22 connected to PE6 */

    GPIO_PinAFConfig(GPIOE, 2, GPIO_AF_FSMC);       /* A23 connected to PE2 */
    GPIO_PinAFConfig(GPIOG, 13, GPIO_AF_FSMC);      /* A24 connected to PG13 */
    GPIO_PinAFConfig(GPIOG, 14, GPIO_AF_FSMC);      /* A25 connected to PG14 */

    /* Data lines */
    GPIO_PinAFConfig(GPIOD, 14, GPIO_AF_FSMC);      /* D0 connected to PD14 */
    GPIO_PinAFConfig(GPIOD, 15, GPIO_AF_FSMC);      /* D1 connected to PD15 */
    GPIO_PinAFConfig(GPIOD, 0, GPIO_AF_FSMC);       /* D2 connected to PD0 */
    GPIO_PinAFConfig(GPIOD, 1, GPIO_AF_FSMC);       /* D3 connected to PD1 */
    GPIO_PinAFConfig(GPIOE, 7, GPIO_AF_FSMC);       /* D4 connected to PE7 */
    GPIO_PinAFConfig(GPIOE, 8, GPIO_AF_FSMC);       /* D5 connected to PE8 */
    GPIO_PinAFConfig(GPIOE, 9, GPIO_AF_FSMC);       /* D6 connected to PE9 */
    GPIO_PinAFConfig(GPIOE, 10, GPIO_AF_FSMC);      /* D7 connected to PE10 */

    /* Connect D7-D15 to FSMC is the data bus is 16 bit */
    GPIO_PinAFConfig(GPIOE, 11, GPIO_AF_FSMC);  /* D8 is connected to PE11 */
    GPIO_PinAFConfig(GPIOE, 12, GPIO_AF_FSMC);  /* D9 is connected to PE12 */
    GPIO_PinAFConfig(GPIOE, 13, GPIO_AF_FSMC);  /* D10 is connected to PE13 */
    GPIO_PinAFConfig(GPIOE, 14, GPIO_AF_FSMC);  /* D11 is connected to PE14 */
    GPIO_PinAFConfig(GPIOE, 15, GPIO_AF_FSMC);  /* D12 is connected to PE15 */
    GPIO_PinAFConfig(GPIOD, 8, GPIO_AF_FSMC);   /* D13 is connected to PD8 */
    GPIO_PinAFConfig(GPIOD, 9, GPIO_AF_FSMC);   /* D14 is connected to PD9 */
    GPIO_PinAFConfig(GPIOD, 10, GPIO_AF_FSMC);  /* D15 is connected to PD10 */

    /* control lines */
    /* NOE */
    GPIO_PinAFConfig(GPIOD, 4, GPIO_AF_FSMC); /* NOE is connected to PD4 */

    /* NWE */
    GPIO_PinAFConfig(GPIOD, 5, GPIO_AF_FSMC); /* NWE is connected to PD5 */

    /* NL(NADV) */
    /* NADV stays unconnected in SRAM memories */

    /* On BCM9WCD1AUDIO first spin board NWAIT is connected to the ZZ pin of the PSRAM memory */
    GPIO_InitTypeDef gpio_init_structure;
    gpio_init_structure.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init_structure.GPIO_Mode  = GPIO_Mode_OUT;
    gpio_init_structure.GPIO_OType = GPIO_OType_PP;
    gpio_init_structure.GPIO_PuPd  =  GPIO_PuPd_UP;
    gpio_init_structure.GPIO_Pin =  ( 1 << 6 );
    GPIO_Init( GPIOD, &gpio_init_structure );
    /* Set to high level, so memory never goes to power-save mode */
    GPIO_SetBits( GPIOD, ( 1 << 6 ) );

     /* NWAIT */

    /* NBL[1] and NBL[0] */
    GPIO_PinAFConfig(GPIOE, 1, GPIO_AF_FSMC); /* NBL[1] is connected to PE1 */
    GPIO_PinAFConfig(GPIOE, 0, GPIO_AF_FSMC); /* NBL[0] is connected to PE0 */

    /* CLK */
    GPIO_PinAFConfig(GPIOD, 3, GPIO_AF_FSMC); /* CLK is connected to PD3 */

    /* Initialise GPIO to operate in high speed Alternate function mode */
    int a;
    for (a = 0; a < 4; ++a)
//.........这里部分代码省略.........
开发者ID:fishbaoz,项目名称:wiced-emw3165,代码行数:101,代码来源:platform_ext_memory.c

示例12: MicoPwmInitialize

OSStatus MicoPwmInitialize( mico_pwm_t pwm_peripheral, uint32_t frequency, float duty_cycle )
{
  TIM_TimeBaseInitTypeDef tim_time_base_structure;
  TIM_OCInitTypeDef       tim_oc_init_structure;
  GPIO_InitTypeDef        gpio_init_structure;
  RCC_ClocksTypeDef       rcc_clock_frequencies;
  const platform_pwm_mapping_t* pwm                 = &pwm_mappings[pwm_peripheral];
  uint16_t                      period              = 0;
  float                         adjusted_duty_cycle = ( ( duty_cycle > 100.0f ) ? 100.0f : duty_cycle );
  
  MicoMcuPowerSaveConfig(false);
  
  RCC_GetClocksFreq( &rcc_clock_frequencies );
  
  if ( pwm->tim == TIM1 || pwm->tim == TIM8 || pwm->tim == TIM9 || pwm->tim == TIM10 || pwm->tim == TIM11 )
  {
    RCC_APB2PeriphClockCmd( pwm->tim_peripheral_clock, ENABLE );
    period = (uint16_t)( rcc_clock_frequencies.PCLK2_Frequency / frequency - 1 ); /* Auto-reload value counts from 0; hence the minus 1 */
  }
  else
  {
    RCC_APB1PeriphClockCmd( pwm->tim_peripheral_clock, ENABLE );
    period = (uint16_t)( 2*rcc_clock_frequencies.PCLK1_Frequency / frequency - 1 ); /* Auto-reload value counts from 0; hence the minus 1 */
  }
  
  RCC_AHB1PeriphClockCmd( pwm->pin->peripheral_clock, ENABLE );
  
  GPIO_PinAFConfig( pwm->pin->bank, pwm->pin->number, pwm->gpio_af );
  gpio_init_structure.GPIO_Pin   = (uint32_t) ( 1 << pwm->pin->number );
  gpio_init_structure.GPIO_Mode  = GPIO_Mode_AF;
  gpio_init_structure.GPIO_Speed = GPIO_Speed_100MHz;
  gpio_init_structure.GPIO_OType = GPIO_OType_PP;
  gpio_init_structure.GPIO_PuPd  = GPIO_PuPd_UP;
  GPIO_Init( pwm->pin->bank, &gpio_init_structure );
  
  
  /* Time base configuration */
  tim_time_base_structure.TIM_Period            = (uint32_t) period;
  tim_time_base_structure.TIM_Prescaler         = (uint16_t) 0;  
  tim_time_base_structure.TIM_ClockDivision     = 0;
  tim_time_base_structure.TIM_CounterMode       = TIM_CounterMode_Up;
  tim_time_base_structure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit( pwm->tim, &tim_time_base_structure );
  
  /* PWM1 Mode configuration */
  tim_oc_init_structure.TIM_OCMode       = TIM_OCMode_PWM1;
  tim_oc_init_structure.TIM_OutputState  = TIM_OutputState_Enable;
  tim_oc_init_structure.TIM_OutputNState = TIM_OutputNState_Enable;
  tim_oc_init_structure.TIM_Pulse        = (uint16_t) ( adjusted_duty_cycle * (float) period / 100.0f );
  tim_oc_init_structure.TIM_OCPolarity   = TIM_OCPolarity_High;
  tim_oc_init_structure.TIM_OCNPolarity  = TIM_OCNPolarity_High;
  tim_oc_init_structure.TIM_OCIdleState  = TIM_OCIdleState_Reset;
  tim_oc_init_structure.TIM_OCNIdleState = TIM_OCIdleState_Set;
  
  switch ( pwm->channel )
  {
  case 1:
    {
      TIM_OC1Init( pwm->tim, &tim_oc_init_structure );
      TIM_OC1PreloadConfig( pwm->tim, TIM_OCPreload_Enable );
      break;
    }
  case 2:
    {
      TIM_OC2Init( pwm->tim, &tim_oc_init_structure );
      TIM_OC2PreloadConfig( pwm->tim, TIM_OCPreload_Enable );
      break;
    }
  case 3:
    {
      TIM_OC3Init( pwm->tim, &tim_oc_init_structure );
      TIM_OC3PreloadConfig( pwm->tim, TIM_OCPreload_Enable );
      break;
    }
  case 4:
    {
      TIM_OC4Init( pwm->tim, &tim_oc_init_structure );
      TIM_OC4PreloadConfig( pwm->tim, TIM_OCPreload_Enable );
      break;
    }
  default:
    {
      break;
    }
  }
  
  MicoMcuPowerSaveConfig(true);
  
  return kNoErr;
}
开发者ID:ChinaAmada,项目名称:MICO,代码行数:90,代码来源:MicoDriverPwm.c

示例13: USB_OTG_BSP_Init

/**
  * @brief  USB_OTG_BSP_Init
  *         Initilizes BSP configurations
  * @param  None
  * @retval None
  */
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{
 /* Note: On STM32F4-Discovery board only USB OTG FS core is supported. */

  GPIO_InitTypeDef GPIO_InitStructure;
 #ifdef USE_USB_OTG_FS 

  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);  
  
  /* Configure SOF VBUS ID DM DP Pins */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9  | 
      GPIO_Pin_11 | 
        GPIO_Pin_12;
  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_OTG1_FS) ; 
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ; 
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
  
  /* this for ID line debug */
  
  
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;   


  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ; 
 #else // USE_USB_OTG_HS 

  #ifdef USE_ULPI_PHY // ULPI
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | 
                         RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOH | 
                           RCC_AHB1Periph_GPIOI, ENABLE);    
  
  
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource3, GPIO_AF_OTG2_HS) ; // D0
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // CLK
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // D1
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource1, GPIO_AF_OTG2_HS) ; // D2
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // D7
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_OTG2_HS) ; // D3
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // D4
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource12,GPIO_AF_OTG2_HS) ; // D5
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_OTG2_HS) ; // D6
  GPIO_PinAFConfig(GPIOH,GPIO_PinSource4, GPIO_AF_OTG2_HS) ; // NXT
  GPIO_PinAFConfig(GPIOI,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // DIR
  GPIO_PinAFConfig(GPIOC,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // STP
  
  // CLK
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  
  // D0
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3  ; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  
  
  
  // D1 D2 D3 D4 D5 D6 D7
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1  |
    GPIO_Pin_5 | GPIO_Pin_10 | 
      GPIO_Pin_11| GPIO_Pin_12 | 
        GPIO_Pin_13 ;
  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOB, &GPIO_InitStructure);  
  
  
  // STP
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  ;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOC, &GPIO_InitStructure);  
  
  //NXT  
//.........这里部分代码省略.........
开发者ID:0x00f,项目名称:stm32,代码行数:101,代码来源:usb_bsp.c

示例14: NOR_GPIOConfig

/**
  * @brief  Configures all SDRAM memory I/Os pins. 
  * @param  None. 
  * @retval None.
  */
void NOR_GPIOConfig(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  /* Enable GPIO Clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOE |
                         RCC_AHB1Periph_GPIOF, ENABLE);

/* GPIOs Configuration -------------------------------------------------------*/
/*
 +-------------------+--------------------+--------------------+--------------------+
 +                       NOR flash pins assignment             +                    +
 +-------------------+--------------------+--------------------+--------------------+
 | PD0  <-> FMC_D2   | PE2  <-> FMC_A23   | PF0  <-> FMC_A0    | PG0 <-> FMC_A10    | 
 | PD1  <-> FMC_D3   | PE3  <-> FMC_A19   | PF1  <-> FMC_A1    | PG1 <-> FMC_A11    | 
 | PD3  <-> FMC_CLK  | PE4  <-> FMC_A20   | PF2  <-> FMC_A2    | PG2 <-> FMC_A12    | 
 | PD4  <-> FMC_NOE  | PE5  <-> FMC_A21   | PF3  <-> FMC_A3    | PG3 <-> FMC_A13    | 
 | PD5  <-> FMC_NWE  | PE6  <-> FMC_A22   | PF4  <-> FMC_A4    | PG4 <-> FMC_A14    | 
 | PD6  <-> FMC_NWAIT| PE7  <-> FMC_D4    | PF5  <-> FMC_A5    | PG5 <-> FMC_A15    |
 | PD7  <-> FMC_NE1  | PE8  <-> FMC_D5    | PF12 <-> FMC_A6    |--------------------+   
 | PD8  <-> FMC_D13  | PE9  <-> FMC_D6    | PF13 <-> FMC_A7    | 
 | PD9  <-> FMC_D14  | PE10 <-> FMC_D7    | PF14 <-> FMC_A8    | 
 | PD10 <-> FMC_D15  | PE11 <-> FMC_D8    | PF15 <-> FMC_A9    |                    
 | PD11 <-> FMC_A16  | PE12 <-> FMC_D9    | -------------------+                  
 | PD12 <-> FMC_A17  | PE13 <-> FMC_D10   |                     
 | PD13 <-> FMC_A18  | PE14 <-> FMC_D11   | 
 | PD14 <-> FMC_D0   | PE15 <-> FMC_D12   |
 | PD15 <-> FMC_D1   |--------------------+  
 +-------------------+
 
*/   
  
/* GPIOs Configuration --------------------------------------------------------*/
  /* Common GPIO configuration */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL; 
  
  /* GPIOD configuration */
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource3, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FMC);
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  | GPIO_Pin_1  |GPIO_Pin_3  | GPIO_Pin_4 | 
                                GPIO_Pin_5  | GPIO_Pin_6  |GPIO_Pin_7  | GPIO_Pin_8 |
                                GPIO_Pin_9  | GPIO_Pin_10 |GPIO_Pin_11 |GPIO_Pin_12 |
                                GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* GPIOE configuration */
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource2, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource3, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource6, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource7, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource8, GPIO_AF_FMC); 
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource12, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource13, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource14, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource15, GPIO_AF_FMC);
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2  |GPIO_Pin_3  | GPIO_Pin_4 |GPIO_Pin_5  | 
                                GPIO_Pin_6  |GPIO_Pin_7  | GPIO_Pin_8 |GPIO_Pin_9  | 
                                GPIO_Pin_10 |GPIO_Pin_11 |GPIO_Pin_12 |GPIO_Pin_13 |
                                GPIO_Pin_14 | GPIO_Pin_15;
                                
  GPIO_Init(GPIOE, &GPIO_InitStructure);

  /* GPIOF configuration */ 
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource0, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource1, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource2, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource3, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource4, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource5, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource12, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF,GPIO_PinSource13, GPIO_AF_FMC);
//.........这里部分代码省略.........
开发者ID:ShowerXu,项目名称:Elink407Board,代码行数:101,代码来源:stm324x9i_eval_fmc_nor.c

示例15: SDRAM_GPIOConfig

/**
  * @brief  Configures all SDRAM memory I/Os pins.
  * @param  None.
  * @retval None.
  */
void SDRAM_GPIOConfig(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable GPIOs clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE |
                         RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH |
                         RCC_AHB1Periph_GPIOI, ENABLE);

/*-- GPIOs Configuration -----------------------------------------------------*/
/*
 +-------------------+--------------------+--------------------+--------------------+
 +                       SDRAM pins assignment                                      +
 +-------------------+--------------------+--------------------+--------------------+
 | PD0  <-> FMC_D2   | PE0  <-> FMC_NBL0  | PF0  <-> FMC_A0    | PG0 <-> FMC_A10    |
 | PD1  <-> FMC_D3   | PE1  <-> FMC_NBL1  | PF1  <-> FMC_A1    | PG1 <-> FMC_A11    |
 | PD8  <-> FMC_D13  | PE7  <-> FMC_D4    | PF2  <-> FMC_A2    | PG4 <-> FMC_A14    |
 | PD9  <-> FMC_D14  | PE8  <-> FMC_D5    | PF3  <-> FMC_A3    | PG5 <-> FMC_A15    |
 | PD10 <-> FMC_D15  | PE9  <-> FMC_D6    | PF4  <-> FMC_A4    | PG8 <-> FC_SDCLK   |
 | PD14 <-> FMC_D0   | PE10 <-> FMC_D7    | PF5  <-> FMC_A5    | PG15 <-> FMC_NCAS  |
 | PD15 <-> FMC_D1   | PE11 <-> FMC_D8    | PF11 <-> FC_NRAS   |--------------------+
 +-------------------| PE12 <-> FMC_D9    | PF12 <-> FMC_A6    |
                     | PE13 <-> FMC_D10   | PF13 <-> FMC_A7    |
                     | PE14 <-> FMC_D11   | PF14 <-> FMC_A8    |
                     | PE15 <-> FMC_D12   | PF15 <-> FMC_A9    |
 +-------------------+--------------------+--------------------+
 | PH2 <-> FMC_SDCKE0| PI4 <-> FMC_NBL2   |
 | PH3 <-> FMC_SDNE0 | PI5 <-> FMC_NBL3   |
 | PH5 <-> FMC_SDNW  |--------------------+
 +-------------------+
 +-------------------+------------------+
 +   32-bits Mode: D31-D16              +
 +-------------------+------------------+
 | PH8 <-> FMC_D16   | PI0 <-> FMC_D24  |
 | PH9 <-> FMC_D17   | PI1 <-> FMC_D25  |
 | PH10 <-> FMC_D18  | PI2 <-> FMC_D26  |
 | PH11 <-> FMC_D19  | PI3 <-> FMC_D27  |
 | PH12 <-> FMC_D20  | PI6 <-> FMC_D28  |
 | PH13 <-> FMC_D21  | PI7 <-> FMC_D29  |
 | PH14 <-> FMC_D22  | PI9 <-> FMC_D30  |
 | PH15 <-> FMC_D23  | PI10 <-> FMC_D31 |
 +------------------+-------------------+

 +-------------------+
 +  Pins remapping   +
 +-------------------+
 | PC0 <-> FMC_SDNWE |
 | PC2 <-> FMC_SDNE0 |
 | PC3 <-> FMC_SDCKE0|
 +-------------------+

*/

  /* Common GPIO configuration */
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

  /* GPIOD configuration */
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FMC);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  |GPIO_Pin_1  |GPIO_Pin_8 |GPIO_Pin_9 |
                                GPIO_Pin_10 |GPIO_Pin_14 |GPIO_Pin_15;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* GPIOE configuration */
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource0 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource1 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FMC);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  | GPIO_Pin_1  | GPIO_Pin_7 | GPIO_Pin_8  |
                                GPIO_Pin_9  | GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12 |
                                GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;

  GPIO_Init(GPIOE, &GPIO_InitStructure);

  /* GPIOF configuration */
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource0 , GPIO_AF_FMC);
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource1 , GPIO_AF_FMC);
//.........这里部分代码省略.........
开发者ID:szymon2103,项目名称:Stm32,代码行数:101,代码来源:stm324x9i_eval_fmc_sdram.c


注:本文中的GPIO_PinAFConfig函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。