コード例 #1
0
ファイル: stm32f2xx_adc.c プロジェクト: ADTL/ARMWork
/**
  * @brief  Deinitializes all ADCs peripherals registers to their default reset values.
  * @param  None
  * @retval None
  */
void ADC_DeInit(void)
{
  /* Enable all ADCs reset state */
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC, ENABLE);
  /* Release all ADCs from reset state */
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC, DISABLE);
}
コード例 #2
0
ファイル: main.c プロジェクト: dibalavs/OpenPilotPort
void jump_to_app()
{
    const struct pios_board_info *bdinfo = &pios_board_info_blob;

    PIOS_LED_On(PIOS_LED_HEARTBEAT);
    // Look at cm3_vectors struct in startup. In a fw image the first uint32_t contains the address of the top of irqstack
    uint32_t fwIrqStackBase = (*(__IO uint32_t *)bdinfo->fw_base) & 0xFFFE0000;
    // Check for the two possible irqstack locations (sram or core coupled sram)
    if (fwIrqStackBase == 0x20000000 || fwIrqStackBase == 0x10000000) {
        /* Jump to user application */
        FLASH_Lock();
        RCC_APB2PeriphResetCmd(0xffffffff, ENABLE);
        RCC_APB1PeriphResetCmd(0xffffffff, ENABLE);
        RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
        RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
		
#ifdef PIOS_INCLUDE_USB
        PIOS_USBHOOK_Deactivate();
#endif

        JumpAddress = *(__IO uint32_t *)(bdinfo->fw_base + 4);
        Jump_To_Application = (pFunction)JumpAddress;
        /* Initialize user application's Stack Pointer */
        __set_MSP(*(__IO uint32_t *)bdinfo->fw_base);
        Jump_To_Application();
    } else {
        DeviceState = failed_jump;
        return;
    }
}
コード例 #3
0
ファイル: stm32f10x_spi.c プロジェクト: WrongChao/lammbo-fly
/*******************************************************************************
* 函数名称: SPI_I2S_DeInit
* 功能描述: 将SPIx外设寄存器重置为他们的缺省值(Affects also the I2Ss).
* 输入参数: SPIx x为1,2或3用于选定SPI外设。
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void SPI_I2S_DeInit(SPI_TypeDef* SPIx)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_SPI_ALL_PERIPH(SPIx));
  
  switch (*(u32*)&SPIx)
  {
    case SPI1_BASE:
      /* Enable SPI1 reset state [使能SPI1复位状态]*/
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
      /* Release SPI1 from reset state [解除SPI1复位状态]*/
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
      break;

    case SPI2_BASE:
      /* Enable SPI2 reset state [使能SPI2复位状态]*/
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
      /* Release SPI2 from reset state [解除SPI2复位状态]*/
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
      break;

    case SPI3_BASE:
      /* Enable SPI3 reset state [使能SPI3复位状态]*/
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
      /* Release SPI3 from reset state [解除SPI3复位状态]*/
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
      break;

    default:
      break;
  }
}
コード例 #4
0
ファイル: stm32f10x_spi.c プロジェクト: DFRobot/BlunoM3
/**
  * @brief  Deinitializes the SPIx peripheral registers to their default
  *         reset values (Affects also the I2Ss).
  * @param  SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  * @retval None
  */
void SPI_I2S_DeInit(SPI_TypeDef* SPIx)
{
  /* Check the parameters */
  assert_param(IS_SPI_ALL_PERIPH(SPIx));

  if (SPIx == STM32_SPI1)
  {
    /* Enable SPI1 reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
    /* Release SPI1 from reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
  }
  else if (SPIx == SPI2)
  {
    /* Enable SPI2 reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
    /* Release SPI2 from reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
  }
  else
  {
    if (SPIx == SPI3)
    {
      /* Enable SPI3 reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
      /* Release SPI3 from reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
    }
  }
}
コード例 #5
0
ファイル: spi_api.c プロジェクト: 52osworld/Stm32f103_mbed
void spi_free(spi_t *obj) {
    // Reset SPI and disable clock
    if (obj->spi == SPI_1) {
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, DISABLE);
    }

    if (obj->spi == SPI_2) {
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, DISABLE);
    }
	 if (obj->spi == SPI_3) {
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, DISABLE);
    }

    // Configure GPIOs
    pin_function(obj->pin_miso, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
    pin_function(obj->pin_mosi, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
    pin_function(obj->pin_sclk, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
    pin_function(obj->pin_ssel, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
}
コード例 #6
0
ファイル: stm32f4xx_sai.c プロジェクト: DKhanh/DK_BallBot
/**
  * @brief  Deinitialize the SAIx peripheral registers to their default reset values.
  * @param  SAIx: To select the SAIx peripheral, where x can be the different instances 
  *                     
  * @retval None
  */
void SAI_DeInit(SAI_TypeDef* SAIx)
{
  /* Check the parameters */
  assert_param(IS_SAI_PERIPH(SAIx));
  
  if(SAIx == SAI1)
  {
    /* Enable SAI1 reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SAI1, ENABLE);
    /* Release SAI1 from reset state */
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SAI1, DISABLE); 
  }
  else
  {
#if defined(STM32F446xx)
  if(SAIx == SAI2)
    {
      /* Enable SAI2 reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SAI2, ENABLE);
      /* Release SAI2 from reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SAI2, DISABLE);   
    }
#endif /* STM32F446xx */
  }
}
コード例 #7
0
ファイル: SPI.c プロジェクト: zeroWin/work-stm32
/*
 * 函数名:SPI_Config_Init()
 * 输入:void
 * 输出:void
 * 功能:对SPI进行初始化设置
 */
void SPI1_Config_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
  	SPI_InitTypeDef  SPI_InitStructure;
	
	//开启外设时钟
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE); //PORTB时钟使能 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);//SPI1时钟使能 
	
	//配置CLK端口的GPIO
	GPIO_InitStructure.GPIO_Pin = SPI_CLK_GPIO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;		//复用功能
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;		//推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;	//10MHz
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;		//上拉
	GPIO_Init(SPI_CLK_GPIO_PORT,&GPIO_InitStructure);
	
	//配置MISO端口的GPIO
	GPIO_InitStructure.GPIO_Pin = SPI_MISO_GPIO_PIN ;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;		//复用功能
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;		//推挽输出 因为复用的时候端口方向由内部控制,所以这里设置成输出相当于浮空输入
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;	//10MHz
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;		//上拉
	GPIO_Init(SPI_MISO_GPIO_PORT,&GPIO_InitStructure);
	
	//配置MOSI端口的GPIO
	GPIO_InitStructure.GPIO_Pin = SPI_MOSI_GPIO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;		//复用功能
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;		//推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;	//10MHz
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;		//上拉
	GPIO_Init(SPI_MOSI_GPIO_PORT,&GPIO_InitStructure);

	//设置端口复用
	GPIO_PinAFConfig(SPI_CLK_GPIO_PORT ,SPI_CLK_AF_PINSOURCE ,GPIO_AF_SPI1);	//PB3复用为SPI1
	GPIO_PinAFConfig(SPI_MISO_GPIO_PORT,SPI_MISO_AF_PINSOURCE,GPIO_AF_SPI1);	//PB4复用为SPI1
	GPIO_PinAFConfig(SPI_MOSI_GPIO_PORT,SPI_MOSI_AF_PINSOURCE,GPIO_AF_SPI1);	//PB5复用为SPI1
	
	//这里只针对SPI口初始化
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,ENABLE);	//复位SPI1
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,DISABLE);//停止复位SPI1
	
	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;	//SPI设置为双线双向全双工
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		//设置SPI工作模式:设置为主SPI
	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;	//设置SPI的数据大小:SPI发送接收8位帧结构
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;			//串行同步时钟的空闲状态为高电平
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;		//串行同步时钟的第二个跳变沿(上升或下降)数据被采样
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;			//NSS信号由软件(使用SSI位)管理
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; ////定义波特率预分频的值:波特率预分频值为256 为主时钟分频
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	//指定数据传输从MSB位开始
	SPI_InitStructure.SPI_CRCPolynomial = 7;			//CRC值计算的多项式,含义是CRC的简记式,使用CRC-8
	SPI_Init(SPIx_USE, &SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
	
	SPI_Cmd(SPIx_USE,ENABLE);		//使能SPI外设
	
	SPI1_ReadWriteByte(0xff);		//启动传输
}
コード例 #8
0
ファイル: stm32f4xx_sai.c プロジェクト: LONELY-WOLF/spider
/**
 * @brief  Deinitialize the SAIx peripheral registers to their default reset values.
 * @param  SAIx: To select the SAIx peripheral, where x can be the different instances 
 *                     
 * @retval None
 */
void SAI_DeInit(SAI_TypeDef* SAIx)
{
	/* Check the parameters */
	assert_param(IS_SAI_PERIPH(SAIx));
	
	/* Enable SAI1 reset state */
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SAI1, ENABLE);
	/* Release SAI1 from reset state */
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SAI1, DISABLE);
}
コード例 #9
0
ファイル: stm32f0xx_adc.c プロジェクト: ccccjason/IMU
/**
  * @brief  Deinitializes ADC1 peripheral registers to their default reset values.
  * @param  ADCx: where x can be 1 to select the ADC peripheral.
  * @retval None
  */
void ADC_DeInit(ADC_TypeDef* ADCx)
{
    /* Check the parameters */
    assert_param(IS_ADC_ALL_PERIPH(ADCx));

    if (ADCx == ADC1) {
        /* Enable ADC1 reset state */
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);

        /* Release ADC1 from reset state */
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
    }
}
コード例 #10
0
static void s_hal_spi_hw_init(hal_spi_t id)
{
#if     defined(HAL_USE_CPU_FAM_STM32F1) || defined(HAL_USE_CPU_FAM_STM32F4)

    //uint32_t RCC_APB1Periph_SPIx = (hal_spi1 == id) ? (RCC_APB1Periph_SPI1) : (RCC_APB1Periph_SPI2); RCC_APB1Periph_SPI3


    if(hal_spi1 == id)
    {
        // spi periph clock enable
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

        // the reset and exit from reset is also done by SPI_I2S_DeInit() ..... thus it can be removed from here
        // reset spi periph
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);

        // release reset
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
    }
    else
    {
        uint32_t RCC_APB1Periph_SPIx = s_hal_spi_hw_rcc[HAL_spi_id2index(id)];

        // spi periph clock enable
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPIx, ENABLE);

        // the reset and exit from reset is also done by SPI_I2S_DeInit() ..... thus it can be removed from here
        // reset spi periph
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPIx, ENABLE);

        // release reset
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPIx, DISABLE);
    }

// //    // system configuration controller clock
//     #warning --> in stm32f4 removed "RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);" from spi_hw_init() and it still works....
// //    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
//
//     // spi periph clock enable
//     RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPIx, ENABLE);
//
//     // reset spi periph
//     RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPIx, ENABLE);
//
//     // release reset
//     RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPIx, DISABLE);

#else //defined(HAL_USE_CPU_FAM_*)
#error ERR --> choose a HAL_USE_CPU_FAM_*
#endif
}
コード例 #11
0
ファイル: standby.c プロジェクト: orkash/Library_Jacob
/************************************************ 
* 函  数: Standby_SysEnter(void)
* 功  能: 系统进入待机模式
*
* 参  数: 无
*
* 返回值: 无
*************************************************/
void Standby_SysEnter(void)
{
  RCC_APB2PeriphResetCmd(0x01FC, DISABLE);  // 复位所有IO口
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // 使能PWR外设时钟
  PWR_WakeUpPinCmd(ENABLE); // 使能唤醒引脚唤醒功能
  PWR_EnterSTANDBYMode(); // 进入待机模式
} // Standby_SysEnter()
コード例 #12
0
ファイル: bsp_ltc2402.c プロジェクト: big-big/RD15002WV
void SPI1_Init(void)
{	 
	GPIO_InitTypeDef  GPIO_InitStructure;
	SPI_InitTypeDef  SPI_InitStructure;

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOA时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//使能SPI1时钟

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;//PA5~7复用功能输出	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
	GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//cs
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_SPI1); //PA5复用为 SPI1
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_SPI1); //PA6复用为 SPI1
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_SPI1); //PA7复用为 SPI1

	//这里只针对SPI口初始化
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,ENABLE);//复位SPI1
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,DISABLE);//停止复位SPI1

	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		//设置SPI工作模式:设置为主SPI
	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;		//设置SPI的数据大小:SPI发送接收8位帧结构
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;		//串行同步时钟的空闲状态为高电平
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;	//串行同步时钟的第二个跳变沿(上升或下降)数据被采样
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;		//NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号有SSI位控制
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;		//定义波特率预分频的值:波特率预分频值为256
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	//指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
	SPI_InitStructure.SPI_CRCPolynomial = 7;	//CRC值计算的多项式
	SPI_Init(SPI1, &SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器

	SPI_Cmd(SPI1, ENABLE); //使能SPI外设
		 
}   
コード例 #13
0
ファイル: serial_api.c プロジェクト: 23chrischen/mbed
void serial_free(serial_t *obj) {
    // Reset UART and disable clock
    if (obj->uart == UART_1) {
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
    }
    if (obj->uart == UART_2) {
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
    }

    // Configure GPIOs
    pin_function(obj->pin_tx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
    pin_function(obj->pin_rx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));

    serial_irq_ids[obj->index] = 0;
}
コード例 #14
0
ファイル: main.c プロジェクト: gotosteven/my_OpenPilot_mods
void jump_to_app() {
	if (((*(__IO uint32_t*) START_OF_USER_CODE) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */
		FLASH_Lock();
		RCC_APB2PeriphResetCmd(0xffffffff, ENABLE);
		RCC_APB1PeriphResetCmd(0xffffffff, ENABLE);
		RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
		RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
		_SetCNTR(0); // clear interrupt mask
		_SetISTR(0); // clear all requests

		JumpAddress = *(__IO uint32_t*) (START_OF_USER_CODE + 4);
		Jump_To_Application = (pFunction) JumpAddress;
		/* Initialize user application's Stack Pointer */
		__set_MSP(*(__IO uint32_t*) START_OF_USER_CODE);
		Jump_To_Application();
	} else {
		DeviceState = failed_jump;
		return;
	}
}
コード例 #15
0
ファイル: spi1.c プロジェクト: PaulingZhou/Homework_Sensor
/******************************************************************************* 
* Function Name  : SPI_Config 
* Description    : Config the SPI1	
* Pin Map				 : PB3-->SPI1_SCK;	
*									 PB4-->SPI1_MISO; 	
* 								 PB5-->SPI1_MOSI; 
* Input          : None 
* Output         : None 
* Return         : None 
*******************************************************************************/
 void SPI1_Config(void)
{	
	GPIO_InitTypeDef GPIO_InitStructure;
	SPI_InitTypeDef SPI_InitStructure;
	
	SPI_I2S_DeInit(SPI1);

	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);	//使能GPIOB时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);		//使能SPI1时钟
	
	//GPIOPB3,4,5初始化设置:复用功能输出
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;					//复用功能
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;				//推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;		//100MHz
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;					//上拉
	GPIO_Init(GPIOB,&GPIO_InitStructure);
	
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource3,GPIO_AF_SPI1);	//PB3复用为SPI1_SCK
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource4,GPIO_AF_SPI1);	//PB4复用为SPI1_MISO
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource5,GPIO_AF_SPI1);	//PB5复用为SPI1_MOSI
	
	//Init SPI1 & Set Working Mode
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,ENABLE);
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,DISABLE);
	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;	//双线双向全双工
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;												//主SPI
	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;										//SPI发送接收8位帧结构
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;													//串行同步时钟的空闲状态为低电平
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;												//第二个跳变沿数据采样(下降沿)
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;														//NSS信号由软件控制
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;//预分频4,传输速度84M/32=2.625Mhz
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;									//数据传输从MSB位开始
	SPI_InitStructure.SPI_CRCPolynomial = 7;														//CRC值计算的多项式
	SPI_Init(SPI1,&SPI_InitStructure);
	
	SPI_Cmd(SPI1,ENABLE);
	
	SPI1_ReadWriteByte(0xFF);
}
コード例 #16
0
ファイル: main.c プロジェクト: abdulparis1/OpenPilot
void jump_to_app() {
	const struct pios_board_info * bdinfo = &pios_board_info_blob;

	if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */
		FLASH_Lock();
		RCC_APB2PeriphResetCmd(0xffffffff, ENABLE);
		RCC_APB1PeriphResetCmd(0xffffffff, ENABLE);
		RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
		RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
		_SetCNTR(0); // clear interrupt mask
		_SetISTR(0); // clear all requests
		JumpAddress = *(__IO uint32_t*) (bdinfo->fw_base + 4);
		Jump_To_Application = (pFunction) JumpAddress;
		/* Initialize user application's Stack Pointer */
		__set_MSP(*(__IO uint32_t*) bdinfo->fw_base);
		Jump_To_Application();
	} else {
		DeviceState = failed_jump;
		return;
	}
}
コード例 #17
0
/**
  * @brief  Deinitializes the ADCx peripheral registers to their default
  *   reset values.
  * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  * @retval : None
  */
void ADC_DeInit(ADC_TypeDef* ADCx)
{
  /* Check the parameters */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));
  switch (*(uint32_t*)&ADCx)
  {
    case ADC1_BASE:
      /* Enable ADC1 reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
      /* Release ADC1 from reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
      break;
    
    case ADC2_BASE:
      /* Enable ADC2 reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, ENABLE);
      /* Release ADC2 from reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, DISABLE);
      break;
      
    case ADC3_BASE:
      /* Enable ADC3 reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3, ENABLE);
      /* Release ADC3 from reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3, DISABLE);
      break; 
    default:
      break;
  }
}
/*******************************************************************************
* Function Name  : SPI_DeInit
* Description    : Deinitializes the SPIx peripheral registers to their default
*                  reset values.
* Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_DeInit(SPI_TypeDef* SPIx)
{
  switch (*(u32*)&SPIx)
  {
    case SPI1_BASE:
      /* Enable SPI1 reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
      /* Release SPI1 from reset state */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
      break;

    case SPI2_BASE:
      /* Enable SPI2 reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
      /* Release SPI2 from reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
      break;

    default:
      break;
  }
}
コード例 #19
0
ファイル: BSP_CARTE.c プロジェクト: jdaheron/BLDR
/**-----------------------------------------------------------------------------
 * @brief	Desinitialisation de la carte.
 */
void BSP_DeInit() {

	// Desactivation des interruptions
	__disable_irq();

	// Arret Systick
	SysTick->CTRL = 0;
	SysTick->LOAD = 0;
	SysTick->VAL = 0;

	// DeInitialisation des horloges

	//RCC_AHB1PeriphClockCmd(0xFFFFFFFF, DISABLE);
	RCC_AHB1PeriphResetCmd(0xFFFFFFFF, ENABLE);
	RCC_AHB1PeriphResetCmd(0xFFFFFFFF, DISABLE);

	//RCC_AHB2PeriphClockCmd(0xFFFFFFFF, DISABLE);
	RCC_AHB2PeriphResetCmd(0xFFFFFFFF, ENABLE);
	RCC_AHB2PeriphResetCmd(0xFFFFFFFF, DISABLE);

	//RCC_AHB3PeriphClockCmd(0xFFFFFFFF, DISABLE);
	RCC_AHB3PeriphResetCmd(0xFFFFFFFF, ENABLE);
	RCC_AHB3PeriphResetCmd(0xFFFFFFFF, DISABLE);

	//RCC_APB1PeriphClockCmd(0xFFFFFFFF, DISABLE);
	RCC_APB1PeriphResetCmd(0xFFFFFFFF, ENABLE);
	RCC_APB1PeriphResetCmd(0xFFFFFFFF, DISABLE);

	//RCC_APB2PeriphClockCmd(0xFFFFFFFF, DISABLE);
	RCC_APB2PeriphResetCmd(0xFFFFFFFF, ENABLE);
	RCC_APB2PeriphResetCmd(0xFFFFFFFF, DISABLE);
	RCC_DeInit();

	// ReInit Flash
	FLASH_PrefetchBufferCmd(DISABLE);
	FLASH_InstructionCacheCmd(DISABLE);
	FLASH_DataCacheCmd(DISABLE);
}
コード例 #20
0
ファイル: main.c プロジェクト: mirasanti/vbrain
void jump_to_app() {
	const struct pios_board_info * bdinfo = &pios_board_info_blob;

	PIOS_LED_On(PIOS_LED_HEARTBEAT);
	if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */
		FLASH_Lock();
		RCC_APB2PeriphResetCmd(0xffffffff, ENABLE);
		RCC_APB1PeriphResetCmd(0xffffffff, ENABLE);
		RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
		RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);

		PIOS_USBHOOK_Deactivate();

		JumpAddress = *(__IO uint32_t*) (bdinfo->fw_base + 4);
		Jump_To_Application = (pFunction) JumpAddress;
		/* Initialize user application's Stack Pointer */
		__set_MSP(*(__IO uint32_t*) bdinfo->fw_base);
		Jump_To_Application();
	} else {
		DeviceState = failed_jump;
		return;
	}
}
コード例 #21
0
void configurePin(GPIO_TypeDef* port, uint16_t pinNum, GPIOMode_TypeDef mode)
{
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  
  if (port == GPIOA)
  {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //| RCC_APB2Periph_AFIO
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);
  }
  else if (port == GPIOB)
  {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); 
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);
  }
  else if (port == GPIOC)
  {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); 
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);
  }
  else if (port == GPIOD)
  {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); 
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE);
  }
  else if (port == GPIOE)
  {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); 
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);
  }
  else if (port == GPIOF)
  {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); 
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, DISABLE);
  }
  else
  {
    if (port == GPIOG)
    {
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE); 
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, DISABLE);
    }
  }

  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = pinNum;
  GPIO_InitStructure.GPIO_Mode = mode;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(port, &GPIO_InitStructure);
}
コード例 #22
0
ファイル: printf.c プロジェクト: InnoMerk/remote
 //------------------------------------------------------------------------------------------ 
void USART1_Config(void)
	{
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  GPIO_InitTypeDef initGPIO;
   // Enable USART1 clock and release reset.
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1,DISABLE);
  
  /* Configure the GPIO ports( USART1 Transmit and Receive Lines) */
  /* Configure the USART1_Tx as Alternate function Push-Pull */
  GPIO_StructInit(&initGPIO);
	initGPIO.GPIO_Mode  = GPIO_Mode_AF_PP;
  initGPIO.GPIO_Pin   = GPIO_Pin_9;
  initGPIO.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &initGPIO);
  
  /* Configure the USART1_Rx as input floating */
  initGPIO.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  initGPIO.GPIO_Pin = GPIO_Pin_10 ;
  GPIO_Init(GPIOA, &initGPIO);
  
/* USART1 configuration ------------------------------------------------------*/
/* USART1 configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
*/
  USART_InitTypeDef initUSART;
	
  initUSART.USART_BaudRate = 115200;
	initUSART.USART_WordLength = USART_WordLength_8b;
  initUSART.USART_StopBits = USART_StopBits_1;
  initUSART.USART_Parity = USART_Parity_No;
  initUSART.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  initUSART.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  /* Configure the USART1 */
  USART_Init(USART1, &initUSART);

  /* Enable the USART1 */
  USART_Cmd(USART1, ENABLE);
						 
  
						
	}	 
コード例 #23
0
ファイル: enc_btn.c プロジェクト: bisle/34_GW_G100
void  encb_init( void )
{
  TIM_ICInitTypeDef     TIM_ICInitStructure;
  
	//*********************************************************
	//******  Main Encoder Setting
	//*********************************************************
	
  DBG( ENC, L, "Main encoder button init" );
  
  RCC_APB2PeriphResetCmd( RCC_APB2Periph_TIM8, ENABLE );
  
  TIM_ICInitStructure.TIM_Channel     = TIM_Channel_1;
  TIM_ICInitStructure.TIM_ICPolarity  = TIM_ICPolarity_Falling;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter    = ENCB_FILTER_CNT;
  TIM_ICInit( TIM8, &TIM_ICInitStructure );
  
  TIM_ICInitStructure.TIM_Channel     = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity  = TIM_ICPolarity_Falling;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter    = ENCB_FILTER_CNT;
  TIM_ICInit( TIM8, &TIM_ICInitStructure );
  
	TIM_EncoderInterfaceConfig( TIM8, TIM_EncoderMode_TI12,
	                            TIM_ICPolarity_Falling, ENCB_MAIN_DIR_POL );
  TIM_Cmd( TIM8, ENABLE );
  
  bio_i_chk[ENCB_MAIN_A_PORT_IX].mask &= ~ENCB_MAIN_A_PIN;
  bio_i_chk[ENCB_MAIN_B_PORT_IX].mask &= ~ENCB_MAIN_B_PIN;
  
	//*********************************************************
	//******  Initial Values Setting
	//*********************************************************
	
  encb_info[ENCB_IX_MAIN].pls_rev = 24;
  encb_info[ENCB_IX_MAIN].val_min = 0;
  encb_info[ENCB_IX_MAIN].val_max = 999 * 10;
  encb_info[ENCB_IX_MAIN].val_cur = 123;
//  encb_info[ENCB_IX_MAIN].val_cur = eep_data.c_ht_tgt;
  encb_info[ENCB_IX_MAIN].sns_min = ENCB_BASE_SENS * 10;
  encb_info[ENCB_IX_MAIN].sns_max = 25000;
  
} // end of encb_init()
コード例 #24
0
int main(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC,DISABLE);
    GPIO_InitTypeDef gpio;         //The GPIO_InitTypeDef structure can be referred by stm32f10x_gpio.h.
    gpio.GPIO_Pin = GPIO_Pin_13;
    gpio.GPIO_Speed = GPIO_Speed_50MHz;
    gpio.GPIO_Mode = GPIO_Mode_Out_OD;
    GPIO_Init(GPIOC,&gpio);

    while (1)
   {
    	GPIO_SetBits(GPIOC, GPIO_Pin_13); // LED ON
        delay(10);
        GPIO_ResetBits(GPIOC, GPIO_Pin_13); // LED OFF
        delay(10);
    }
}
コード例 #25
0
/*************************************************************************
 * Function Name: SPI1_Init
 * Parameters: none
 * Return: none
 *
 * Description: Init SPI1
 *
 *************************************************************************/
void SPI1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
  // Enable GPIO clock and release reset
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC,
                         ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC,
                         DISABLE);

  // Configure LCD_CS GPIO Pin as push-pull output in high level
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = LCD_CS_MASK;
  GPIO_Init(LCD_CS_PORT, &GPIO_InitStructure);
  GPIO_SetBits(LCD_CS_PORT,LCD_CS_MASK);

  // Configure SPC1000_CS GPIO Pin as push-pull output in high level
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = SCP1000_CS_MASK;
  GPIO_Init(SCP1000_CS_PORT, &GPIO_InitStructure);
  GPIO_SetBits(SCP1000_CS_PORT,SCP1000_CS_MASK);

  // Configure SPI1_SCLK and SPI1_MOSI GPIOs Pins as push-pull outputs
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = SPI1_SCLK_MASK | SPI1_MOSI_MASK;
  GPIO_Init(SPI1_PORT, &GPIO_InitStructure);

  // Configure SPI1_MISO GPIO Pin as input floating
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Pin = SPI1_MISO_MASK;
  GPIO_Init(SPI1_PORT, &GPIO_InitStructure);

  for(Int32U i = 0; i < SPI1_LAST_DEV; i++)
  {
    _SPI_Dev[i].DataWidth = 8;
    _SPI_Dev[i].Delay = 0;
    _SPI_Dev[i].CPOL = 0;
    _SPI_Dev[i].CPHA = 0;
  }
}
コード例 #26
0
ファイル: main1.c プロジェクト: a-c-t-i-n-i-u-m/HY-STM32F103
/*************************************************************************
 * Function Name: Serial_Init
 * Description: Init USARTs
 *************************************************************************/
void Serial_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);

  /* Configure USART1 Tx (PA.09) as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure USART1 Rx (PA.10) as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

/* USART1 configuration ------------------------------------------------------*/
  // USART1 configured as follow:
  USART_InitStructure.USART_BaudRate = 115200;
  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_Rx | USART_Mode_Tx;

  /* Configure the USART1 */
  USART_Init(USART1, &USART_InitStructure);

  /* Enable the USART Transmoit interrupt: this interrupt is generated when the 
     USART1 transmit data register is empty */  
  USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

  /* Enable the USART Receive interrupt: this interrupt is generated when the 
     USART1 receive data register is not empty */
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

  /* Enable USART1 */
  USART_Cmd(USART1, ENABLE);
  
}
コード例 #27
0
ファイル: usb_hw.c プロジェクト: JigsawRenaissance/GGHC
/*************************************************************************
 * Function Name: USB_HwInit
 * Parameters: none
 *
 * Return: none
 *
 * Description: Init USB
 *
 *************************************************************************/
void USB_HwInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

  // Reset USB Engine
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_USB,ENABLE);
  // Init USB Clock
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB,ENABLE);
  // Release reset USB Engine
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_USB,DISABLE);
  // Enable 48MHz clock
  RCC_USBCLKConfig(USB_DIVIDER);

  // Force USB Reset &  Disable USB interrupts
  USB_CNTR = 1;

  // GPIO assign to the USB engine
  RCC_APB2PeriphResetCmd(  RCC_APB2Periph_GPIOA
                         | RCC_APB2Periph_GPIOC
                         | RCC_APB2Periph_AFIO, DISABLE);
  RCC_APB2PeriphClockCmd(  RCC_APB2Periph_GPIOA
                         | RCC_APB2Periph_GPIOC
                         | RCC_APB2Periph_AFIO, ENABLE);

  GPIO_PinRemapConfig(GPIO_Remap1_CAN1,ENABLE);  // xxx
  // Configure PA11, PA12 as USB lines
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11 | GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  // Configure PC11 USB connect.
  GPIO_WriteBit(GPIOC,GPIO_Pin_11,Bit_SET);
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  // Disconnect device
  USB_ConnectRes(FALSE);

  // Init controls endpoints
  USB_HwReset();

  // Clear spurious pending interrupt
  USB_ISTR = 0;

  // USB interrupt connect to NVIC
#if USB_HIGH_PRIORITY_EVENT > 0
  NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USB_INTR_HIGH_PRIORITY;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
#endif // USB_HIGH_PRIORITY_EVENT > 0

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USB_INTR_LOW_PRIORITY;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

}
コード例 #28
0
ファイル: stm32f4xx_sdio.c プロジェクト: AStennikov/Camera-1
/**
  * @brief  Deinitializes the SDIO peripheral registers to their default reset values.
  * @param  None
  * @retval None
  */
void SDIO_DeInit(void)
{
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_SDIO, ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_SDIO, DISABLE);
}
コード例 #29
0
ファイル: mmc_ll_SPI2.c プロジェクト: Forvater/STM32-P103
/*************************************************************************
 * Function Name: MmcInit
 * Parameters: none
 * Return: none
 *
 * Description: Init SPI, Cart Present, Write Protect and Chip select pins
 *
 *************************************************************************/
void MmcInit (void)
{
SPI_InitTypeDef   SPI_InitStructure;
GPIO_InitTypeDef  GPIO_InitStructure;

  // Enable GPIO clocks
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
  // Enable SPI2 Periphery clock
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

  // Deinitializes the SPI2
  SPI_DeInit(SPI2);
  // Release reset of GPIOB, GPIOC
  RCC_APB2PeriphResetCmd(  RCC_APB2Periph_GPIOB
                         | RCC_APB2Periph_GPIOC, DISABLE);

  // Configure SPI2_CLK, SPI2_MOSI, SPI2_nCS1, Card Present and Write Protect pins
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = SD_CS;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin = SD_SCLK | SD_MOSI | SD_MISO;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Pin = SD_CP | SD_WP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  // Chip select
  MmcChipSelect(0);

  // Spi init
  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_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI2, &SPI_InitStructure);

  // Enable SPI2 */
  SPI_Cmd(SPI2, ENABLE);

  // Clock Freq. Identification Mode < 400kHz
  MmcSetClockFreq(IdentificationModeClock);

#if SPI_DMA_ENA > 0

  // Enable DMA clock
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA, ENABLE);
  // Clear pending interrupt
  DMA_ClearITPendingBit( DMA_IT_GL4
                       | DMA_IT_GL5);

  // Interrupts DMA enable
  SPI_DMACmd(SPI2,SPI_DMAReq_Rx,DISABLE);
  SPI_DMACmd(SPI2,SPI_DMAReq_Tx,DISABLE);
#ifndef DMA_ERRATA
NVIC_InitTypeDef NVIC_InitStructure;
  // VIC configuration
  NVIC_InitStructure.NVIC_IRQChannel = DMAChannel4_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = SPI_DMA_INTR_PRIO;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = DMAChannel5_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = SPI_DMA_INTR_PRIO;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
#endif
#endif // SPI_DMA_ENA > 0
}
コード例 #30
0
ファイル: uart.c プロジェクト: Forvater/STM32-P103
/*************************************************************************
 * Function Name: UartInit
 * Parameters: Int32U IrqSlot
 *
 * Return: Boolean
 *
 * Description: Init UART
 *
 *************************************************************************/
Boolean UartInit(UartNum_t Uart,Int32U IrqSlot)
{
volatile Int8U Tmp;
USART_InitTypeDef  UART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;


  USART_StructInit(&UART_InitStructure);
  UART_InitStructure.USART_Parity = USART_Parity_No;

  switch(Uart)
  {
  case UART_1:
    pUart1RxFifo = (pUartFifo_t)malloc(sizeof(UartFifo_t));
    if(pUart1RxFifo == NULL)
    {
      return(FALSE);
    }
    pUart1TxFifo = (pUartFifo_t)malloc(sizeof(UartFifo_t));
    if(pUart1TxFifo == NULL)
    {
      free(pUart1RxFifo);
      return(FALSE);
    }
    // Init receive and transmit FIFOs
    pUart1RxFifo->PopIndx = pUart1RxFifo->PushIndx = \
    pUart1TxFifo->PopIndx = pUart1TxFifo->PushIndx = 0;

    // Release reset and enable clock
    USART_DeInit(USART1);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

    // GPIO Init
    // Enable GPIO clock and release reset
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,
                           ENABLE);
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA,
                           DISABLE);
    GPIO_PinRemapConfig(GPIO_Remap_USART1,DISABLE);

    // Assign PA9 to UART1 (Tx)
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // Assign PA10 to UART1 (Rx)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // Init UART1
    USART_Init(USART1,&UART_InitStructure);

    // Enable and configure the priority of the UART1 Update IRQ Channel
    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = UART1_INTR_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    USART_ClearFlag(USART1, USART_FLAG_CTS | USART_FLAG_LBD  | USART_FLAG_TXE  |
                            USART_FLAG_TC  | USART_FLAG_RXNE | USART_FLAG_IDLE |
                            USART_FLAG_ORE | USART_FLAG_NE   | USART_FLAG_FE |
                            USART_FLAG_PE);

    // Enable UART1 interrupts
    USART_ITConfig(USART1,USART_IT_PE  ,ENABLE);
    USART_ITConfig(USART1,USART_IT_TC  ,DISABLE);
    USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
    USART_ITConfig(USART1,USART_IT_IDLE,DISABLE);
    USART_ITConfig(USART1,USART_IT_LBD ,DISABLE);
    USART_ITConfig(USART1,USART_IT_CTS ,DISABLE);
    USART_ITConfig(USART1,USART_IT_ERR ,DISABLE);

    // Enable the UART1
    USART_Cmd(USART1, ENABLE);
    break;
  case UART_2:
    pUart2RxFifo = (pUartFifo_t)malloc(sizeof(UartFifo_t));
    if(pUart2RxFifo == NULL)
    {
      return(FALSE);
    }
    pUart2TxFifo = (pUartFifo_t)malloc(sizeof(UartFifo_t));
    if(pUart2TxFifo == NULL)
    {
      free(pUart2RxFifo);
      return(FALSE);
    }
    // Init receive and transmit FIFOs
    pUart2RxFifo->PopIndx = pUart2RxFifo->PushIndx = \
    pUart2TxFifo->PopIndx = pUart2TxFifo->PushIndx = 0;

    // Release reset and enable clock
    USART_DeInit(USART2);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

    // GPIO Init
    // Enable GPIO clock and release reset
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,
                           ENABLE);
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA,
                           DISABLE);
    GPIO_PinRemapConfig(GPIO_Remap_USART2,DISABLE);

    // Assign PA2 to UART2 (Tx)
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // Assign PA3 to UART2 (Rx)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // Init UART2
    USART_Init(USART2,&UART_InitStructure);

    // Enable and configure the priority of the UART2 Update IRQ Channel
    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = UART2_INTR_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    USART_ClearFlag(USART2, USART_FLAG_CTS | USART_FLAG_LBD  | USART_FLAG_TXE  |
                            USART_FLAG_TC  | USART_FLAG_RXNE | USART_FLAG_IDLE |
                            USART_FLAG_ORE | USART_FLAG_NE   | USART_FLAG_FE |
                            USART_FLAG_PE);

    // Enable UART2 interrupts
    USART_ITConfig(USART2,USART_IT_PE  ,ENABLE);
    USART_ITConfig(USART2,USART_IT_TXE ,ENABLE);
    USART_ITConfig(USART2,USART_IT_TC  ,DISABLE);
    USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
    USART_ITConfig(USART2,USART_IT_IDLE,DISABLE);
    USART_ITConfig(USART2,USART_IT_LBD ,DISABLE);
    USART_ITConfig(USART2,USART_IT_CTS ,DISABLE);
    USART_ITConfig(USART2,USART_IT_ERR ,DISABLE);

    // Enable the UART2
    USART_Cmd(USART2, ENABLE);
    break;
  case UART_3:
    pUart3RxFifo = (pUartFifo_t)malloc(sizeof(UartFifo_t));
    if(pUart3RxFifo == NULL)
    {
      return(FALSE);
    }
    pUart3TxFifo = (pUartFifo_t)malloc(sizeof(UartFifo_t));
    if(pUart3TxFifo == NULL)
    {
      free(pUart3RxFifo);
      return(FALSE);
    }
    // Init receive and transmit FIFOs
    pUart3RxFifo->PopIndx = pUart3RxFifo->PushIndx = \
    pUart3TxFifo->PopIndx = pUart3TxFifo->PushIndx = 0;

    // Release reset and enable clock
    USART_DeInit(USART3);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

    // GPIO Init
    // Enable GPIO clock and release reset
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO,
                           ENABLE);
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO,
                           DISABLE);
    GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);

    // Assign PC10 to UART3 (Tx)
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Assign PC11 to UART3 (Rx)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Init UART3
    USART_Init(USART3,&UART_InitStructure);

    // Enable and configure the priority of the UART3 Update IRQ Channel
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = UART3_INTR_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    USART_ClearFlag(USART3, USART_FLAG_CTS | USART_FLAG_LBD  | USART_FLAG_TXE  |
                            USART_FLAG_TC  | USART_FLAG_RXNE | USART_FLAG_IDLE |
                            USART_FLAG_ORE | USART_FLAG_NE   | USART_FLAG_FE |
                            USART_FLAG_PE);

    // Enable UART3 interrupts
    USART_ITConfig(USART3,USART_IT_PE  ,ENABLE);
    USART_ITConfig(USART3,USART_IT_TXE ,DISABLE);
    USART_ITConfig(USART3,USART_IT_TC  ,DISABLE);
    USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
    USART_ITConfig(USART3,USART_IT_IDLE,DISABLE);
    USART_ITConfig(USART3,USART_IT_LBD ,DISABLE);
    USART_ITConfig(USART3,USART_IT_CTS ,DISABLE);
    USART_ITConfig(USART3,USART_IT_ERR ,DISABLE);

    // Enable the UART3
    USART_Cmd(USART3, ENABLE);
    break;
  default:
    return(FALSE);
  }
  return(TRUE);
}