示例#1
0
/**
  * @brief  Deinitialize the SPDIFRXx peripheral registers to their default reset values.
  * @param  void
  * @retval None
  */
void SPDIFRX_DeInit(void)
{
  /* Enable SPDIFRX reset state */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPDIFRX, ENABLE);
  /* Release SPDIFRX from reset state */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPDIFRX, DISABLE); 
}
/*******************************************************************************
* Function Name  : I2C_DeInit
* Description    : Deinitializes the I2Cx peripheral registers to their default
*                  reset values.
* Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void I2C_DeInit(I2C_TypeDef* I2Cx)
{
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));

  switch (*(u32*)&I2Cx)
  {
    case I2C1_BASE:
      /* Enable I2C1 reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
      /* Release I2C1 from reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
      break;

    case I2C2_BASE:
      /* Enable I2C2 reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
      /* Release I2C2 from reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
      break;

    default:
      break;
  }
}
示例#3
0
/**
  * @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));
  
  switch (*(uint32_t*)&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;
    case SPI3_BASE:
      /* Enable SPI3 reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
      /* Release SPI3 from reset state */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
      break;
    default:
      break;
  }
}
示例#4
0
/**
  * @brief  Initializes the GPIO pins used by the IO expander.
  * @param  None
  * @retval None
  */
static void IOE_GPIO_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  /* Enable IOE_I2C and IOE_I2C_GPIO_PORT & Alternate Function clocks */
  RCC_APB1PeriphClockCmd(IOE_I2C_CLK, ENABLE);
  RCC_AHB1PeriphClockCmd(IOE_I2C_SCL_GPIO_CLK | IOE_I2C_SDA_GPIO_CLK |
                         IOE_IT_GPIO_CLK, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  
  /* Reset IOE_I2C IP */
  RCC_APB1PeriphResetCmd(IOE_I2C_CLK, ENABLE);
  /* Release reset signal of IOE_I2C IP */
  RCC_APB1PeriphResetCmd(IOE_I2C_CLK, DISABLE);

  /* Connect PXx to I2C_SCL*/
  GPIO_PinAFConfig(IOE_I2C_SCL_GPIO_PORT, IOE_I2C_SCL_SOURCE, IOE_I2C_SCL_AF);
  /* Connect PXx to I2C_SDA*/
  GPIO_PinAFConfig(IOE_I2C_SDA_GPIO_PORT, IOE_I2C_SDA_SOURCE, IOE_I2C_SDA_AF); 
    
  /* IOE_I2C SCL and SDA pins configuration */
  GPIO_InitStructure.GPIO_Pin = IOE_I2C_SCL_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(IOE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = IOE_I2C_SDA_PIN;
  GPIO_Init(IOE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
  
}
示例#5
0
/**
  * @brief  Deinitializes the CEC peripheral registers to their default reset 
  *         values.
  * @param  None
  * @retval None
  */
void CEC_DeInit(void)
{
  /* Enable CEC reset state */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, ENABLE);  
  /* Release CEC from reset state */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, DISABLE); 
}
示例#6
0
/**
@brief Init I2C
@param[in]	devnum		I2C peripheral number (1 or 2)
@param[in]	clkspd		Baudrate (i.e. 100000 for 100kHz), F_CPU independent
*/
void i2c_init(uint8_t devnum, const uint32_t clkspd)
{
	struct I2C_DevDef* pdef = i2c_get_pdef(devnum);

    // Enable GPIO clocks
    RCC_APB2PeriphClockCmd(pdef->gpio_clk, ENABLE);

	// I2C1 clock enable
	RCC_APB1PeriphClockCmd(pdef->i2c_clk, ENABLE);

	// I2C1 SDA and SCL configuration
	GPIO_InitTypeDef iotd;
	iotd.GPIO_Pin = pdef->pin_sda | pdef->pin_scl;
	iotd.GPIO_Speed = GPIO_Speed_50MHz;
	iotd.GPIO_Mode = GPIO_Mode_AF_OD;
	GPIO_Init(pdef->gpio, &iotd);

	// I2C1 Reset
	RCC_APB1PeriphResetCmd(pdef->i2c_clk, ENABLE);
	RCC_APB1PeriphResetCmd(pdef->i2c_clk, DISABLE);

	// Configure I2Cx
	I2C_InitTypeDef i2td;
	i2td.I2C_ClockSpeed = clkspd;
	i2td.I2C_Mode = I2C_Mode_I2C;
	i2td.I2C_DutyCycle = I2C_DutyCycle_2;
	i2td.I2C_OwnAddress1 = 0;
	i2td.I2C_Ack = I2C_Ack_Enable;
	i2td.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
	I2C_Init(pdef->i2c, &i2td);

	I2C_Cmd(pdef->i2c, ENABLE);
}
示例#7
0
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;
    }
}
示例#8
0
/**
 * @brief  Initializes the I2C peripheral used to drive the MPU6050
 * @param  None
 * @return None
 */
void MPU6050_I2C_Init()
{
    I2C_InitTypeDef I2C_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;

    /* Enable I2C and GPIO clocks */
    RCC_APB1PeriphClockCmd(MPU6050_I2C_RCC_Periph, ENABLE);
    RCC_AHB1PeriphClockCmd(MPU6050_I2C_RCC_Port, ENABLE);

    RCC_APB1PeriphResetCmd ( RCC_APB1Periph_I2C1, ENABLE );

    RCC_APB1PeriphResetCmd ( RCC_APB1Periph_I2C1, DISABLE );

    /* Configure I2C pins: SCL and SDA */
    GPIO_InitStructure.GPIO_Pin = MPU6050_I2C_SCL_Pin | MPU6050_I2C_SDA_Pin;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;// this activates the pullup resistors on the IO pins
    GPIO_Init(MPU6050_I2C_Port, &GPIO_InitStructure);



    /*
00099 #define I2Cx                          I2C1
00100 #define I2Cx_CLK                      RCC_APB1Periph_I2C1
00101 #define I2Cx_SDA_GPIO_CLK             RCC_AHB1Periph_GPIOB
00102 #define I2Cx_SDA_PIN                  GPIO_Pin_9                
00103 #define I2Cx_SDA_GPIO_PORT            GPIOB                       
00104 #define I2Cx_SDA_SOURCE               GPIO_PinSource9
00105 #define I2Cx_SDA_AF                   GPIO_AF_I2C1
00106   
00107 #define I2Cx_SCL_GPIO_CLK             RCC_AHB1Periph_GPIOB
00108 #define I2Cx_SCL_PIN                  GPIO_Pin_6                
00109 #define I2Cx_SCL_GPIO_PORT            GPIOB                    
00110 #define I2Cx_SCL_SOURCE               GPIO_PinSource6
00111 #define I2Cx_SCL_AF                   GPIO_AF_I2C1
    */

    /* Connect PXx to I2C_SCL */
    GPIO_PinAFConfig ( GPIOB, GPIO_PinSource6 /*MPU6050_I2C_SCL_Pin*/, GPIO_AF_I2C1/*I2C1_SCL_AF*/);
   
    /* Connect PXx to I2C_SDA */
    GPIO_PinAFConfig ( GPIOB, GPIO_PinSource7 /*MPU6050_I2C_SDA_Pin*/, GPIO_AF_I2C1/*I2C1_SDA_AF*/);



    /* I2C configuration */
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStructure.I2C_OwnAddress1 = MPU6050_DEFAULT_ADDRESS; // MPU6050 7-bit adress = 0x68, 8-bit adress = 0xD0;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStructure.I2C_ClockSpeed = MPU6050_I2C_Speed;

    /* Apply I2C configuration after enabling it */
    I2C_Init(MPU6050_I2C, &I2C_InitStructure);
    /* I2C Peripheral Enable */
    I2C_Cmd(MPU6050_I2C, ENABLE);
}
示例#9
0
/**
  * @brief  Initializes the GPIO pins used by the IO expander.
  * @param  None
  * @retval None
  */
static void IOE_GPIO_Config(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    /* Enable IOE_I2C and IOE_I2C_PORT & Alternate Function clocks */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOE_I2C, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB_IOE_I2C_PORT | RCC_APB_GPIO_IOE_ITPORT | RCC_APB2Periph_AFIO, ENABLE);

    /* Reset IOE_I2C IP */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_IOE_I2C, ENABLE);

    /* Release reset signal of IOE_I2C IP */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_IOE_I2C, DISABLE);

    /* IOE_I2C SCL and SDA pins configuration */
    GPIO_InitStructure.GPIO_Pin = IOE_SCL_PIN | IOE_SDA_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
    GPIO_Init(IOE_I2C_PORT, &GPIO_InitStructure);

    /* Set EXTI pin as Input PullUp - IO_Expander_INT */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_IOE_ITPIN;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(GPIO_IOE_ITPORT, &GPIO_InitStructure);

    /* Connect IO Expander IT line to EXTI line */
    GPIO_EXTILineConfig(GPIO_PortSource_IOE_ITPORT, GPIO_PinSource_IOE_ITPIN);
}
示例#10
0
void init_I2C1_lowlevel(void)
{
    GPIO_InitTypeDef GPIO_InitStruct;
    I2C_InitTypeDef I2C_InitStruct;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); // SCL pini 
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1); // SDA pini

	/* detail????????????? */
    I2C_InitStruct.I2C_ClockSpeed = 100000;    	//?????????????????????????              
    I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;		//??????????????????
    I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;	//???????????????
    I2C_InitStruct.I2C_OwnAddress1 = 0x00;	//???????????????????????
    I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;	//?????????????????????????????????????
    I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;	//??????????????????????
    I2C_Init(I2C1, &I2C_InitStruct);

    I2C_Cmd(I2C1, ENABLE);
}
示例#11
0
/**
  * @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 == 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);
    }
  }
}
示例#12
0
/*******************************************************************************
* 函数名称: CAN_DeInit
* 功能描述: D将CAN外设寄存器复位为它们的默认值
* 输入参数: 无.
* 输出参数: 无.
* 返回参数: 无.
*******************************************************************************/
void CAN_DeInit(void)
{
  /* Enable CAN reset state */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN, ENABLE);
  /* Release CAN from reset state */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN, DISABLE);
}
示例#13
0
文件: lcd.c 项目: agent-0007/H4ck33D
/* deinitialize lcd */
void LCD_Deinit(void)
{
  /* Enable LCD reset state */
  RCC_APB1PeriphResetCmd(APB1_LCD, ENABLE);
  /* Release LCD from reset state */
  RCC_APB1PeriphResetCmd(APB1_LCD, DISABLE);
}
示例#14
0
void i2c_config()
{
	// RCC
	/* Enable GPIOB clock */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

	// GPIO
	GPIO_InitTypeDef GPIO_InitStructure;

	/* Configure I2C1 pins: SCL and SDA */
	GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

	GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* Enable I2C1 reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
    /* Release I2C1 from reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);

    I2C_DeInit(I2C1);

	// I2C
	/* Enable I2C1 */
	I2C_Cmd(I2C1, ENABLE);

	I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
	I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
	I2C_InitStructure.I2C_OwnAddress1 = ID;
	I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
	I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
	I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;
	I2C_Init(I2C1, &I2C_InitStructure);

	I2C_GeneralCallCmd(I2C1, ENABLE);

	/* Enable Event IT needed for ADDR and STOPF events ITs */
	I2C_ITConfig(I2C1, I2C_IT_EVT, ENABLE);

	/* Enable Error IT */
	I2C_ITConfig(I2C1, I2C_IT_ERR, ENABLE);

	/* Enable Buffer IT (TXE and RXNE ITs) */
	I2C_ITConfig(I2C1, I2C_IT_BUF, ENABLE);

	// NVIC
	/* 1 bit for pre-emption priority, 3 bits for subpriority */
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

	NVIC_SetPriority(I2C1_EV_IRQn, 0x00);
	NVIC_EnableIRQ(I2C1_EV_IRQn);

	NVIC_SetPriority(I2C1_ER_IRQn, 0x01);
	NVIC_EnableIRQ(I2C1_ER_IRQn);
}
示例#15
0
void i2c_reset(i2c_t *obj) {
    if (obj->i2c == I2C_1) {
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
    }
    if (obj->i2c == I2C_2) {
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
    }
}
示例#16
0
文件: main.c 项目: szymon2103/Stm32
/**
  * @brief  Enables the I2C Clock and configures the different GPIO ports.
  * @param  None
  * @retval None
  */
static void I2C_Config(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* RCC Configuration */
  /*I2C Peripheral clock enable */
  RCC_APB1PeriphClockCmd(I2Cx_CLK, ENABLE);

  /*SDA GPIO clock enable */
  RCC_AHB1PeriphClockCmd(I2Cx_SDA_GPIO_CLK, ENABLE);

  /*SCL GPIO clock enable */
  RCC_AHB1PeriphClockCmd(I2Cx_SCL_GPIO_CLK, ENABLE);

  /* Reset I2Cx IP */
  RCC_APB1PeriphResetCmd(I2Cx_CLK, ENABLE);

  /* Release reset signal of I2Cx IP */
  RCC_APB1PeriphResetCmd(I2Cx_CLK, DISABLE);

  /* GPIO Configuration */
  /*Configure I2C SCL pin */
  GPIO_InitStructure.GPIO_Pin = I2Cx_SCL_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(I2Cx_SCL_GPIO_PORT, &GPIO_InitStructure);

  /*Configure I2C SDA pin */
  GPIO_InitStructure.GPIO_Pin = I2Cx_SDA_PIN;
  GPIO_Init(I2Cx_SDA_GPIO_PORT, &GPIO_InitStructure);

  /* Connect PXx to I2C_SCL */
  GPIO_PinAFConfig(I2Cx_SCL_GPIO_PORT, I2Cx_SCL_SOURCE, I2Cx_SCL_AF);

  /* Connect PXx to I2C_SDA */
  GPIO_PinAFConfig(I2Cx_SDA_GPIO_PORT, I2Cx_SDA_SOURCE, I2Cx_SDA_AF);

  /* NVIC configuration */
  /* Configure the Priority Group to 1 bit */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

  /* Configure the I2C event priority */
  NVIC_InitStructure.NVIC_IRQChannel = I2Cx_EV_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Configure I2C error interrupt to have the higher priority */
  NVIC_InitStructure.NVIC_IRQChannel = I2Cx_ER_IRQn;
  NVIC_Init(&NVIC_InitStructure);
}
示例#17
0
/*
	函数功能:定时器6延时函数初始化
*/
void Delay_Init(void)
{
	/*开始定时器6时钟*/
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
	
	/*复位定时器6状态*/
	RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, ENABLE);
	RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, DISABLE);
	
	/*关闭定时器6*/
	TIM_Cmd(TIM6, DISABLE);
}
示例#18
0
/**
  * @brief  Deinitializes the LPTIMx peripheral registers to their default reset values.
  * @param  LPTIMx: where x can be 1.
  * @retval None
  *
  */
void LPTIM_DeInit(LPTIM_TypeDef* LPTIMx)
{
  /* Check the parameters */
  assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
  
  /* Deinitializes the LPTIM1 peripheral */
  if(LPTIMx == LPTIM1)
  {
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_LPTIM1, ENABLE);
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_LPTIM1, DISABLE);
  }
}
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
}
示例#20
0
文件: SPI.c 项目: EAH-Jena/asuromote
void init_SPI(int spi_number){
		SPI_InitTypeDef SPI_InitTypeDefStruct;
		//SPI1 initialisieren
		//Program the Polarity, Phase, First Data, Baud Rate Prescaler, Slave 
		//Management, Peripheral Mode and CRC Polynomial values
		SPI_InitTypeDefStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
		SPI_InitTypeDefStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//bidirectional for read and write
		SPI_InitTypeDefStruct.SPI_Mode = SPI_Mode_Master;//als master
		SPI_InitTypeDefStruct.SPI_DataSize = SPI_DataSize_8b;
		SPI_InitTypeDefStruct.SPI_NSS = SPI_NSS_Soft;//Chip select to Software
		SPI_InitTypeDefStruct.SPI_FirstBit = SPI_FirstBit_MSB;
		SPI_InitTypeDefStruct.SPI_CPOL = SPI_CPOL_High;//clock auf steigende Flanke?
		SPI_InitTypeDefStruct.SPI_CPHA = SPI_CPHA_2Edge;
		
	//Enable peripheral clock
		switch(spi_number){
				case SPI_1:
						RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);// for SPI1
						//SPI1 mit struct initialisieren 
						SPI_Init(SPI1, &SPI_InitTypeDefStruct);
						SPI_Cmd(SPI1, ENABLE);
						break;
				case SPI_2:
						RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);// for SPI2
						SPI_Init(SPI2, &SPI_InitTypeDefStruct);
						SPI_Cmd(SPI2, ENABLE);
						break;
				case SPI_3:
						RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);// for SPI3
						SPI_Init(SPI3, &SPI_InitTypeDefStruct);
						SPI_Cmd(SPI3, ENABLE);
						break;
				case SPI_4:
						RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);// for SPI4
						SPI_Init(SPI4, &SPI_InitTypeDefStruct);
						SPI_Cmd(SPI4, ENABLE);
						break;
				case SPI_5:
						RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);// for SPI5
						SPI_Init(SPI5, &SPI_InitTypeDefStruct);
						SPI_Cmd(SPI5, ENABLE);
						break;
				case SPI_6:
						RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);// for SPI6
						SPI_Init(SPI6, &SPI_InitTypeDefStruct);
						SPI_Cmd(SPI6, ENABLE);
						break;
		}
}
示例#21
0
文件: usb_bsp.c 项目: gmoccapy/stmbl
//--------------------------------------------------------------
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{

  GPIO_InitTypeDef GPIO_InitStructure;   

  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);  
  
  /* Configure  SOF VBUS ID DM DP Pins */
  GPIO_InitStructure.GPIO_Pin = 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_PinSource11,GPIO_AF_OTG1_FS) ;
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
  
 
  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;


  /* enable the PWR clock */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);

}
示例#22
0
void SPI3_Configure(void)
{
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

    GPIO_InitTypeDef init_port;
    init_port.GPIO_Pin = SPI3_MISO_Pin;
    init_port.GPIO_Mode = GPIO_Mode_AF;
    init_port.GPIO_Speed = GPIO_Speed_50MHz;
    init_port.GPIO_OType = GPIO_OType_PP;
    init_port.GPIO_PuPd = GPIO_PuPd_DOWN;
    GPIO_Init(SPI3_MISO_Port, &init_port);

    init_port.GPIO_Pin = SPI3_MOSI_Pin;
    GPIO_Init(SPI3_MOSI_Port, &init_port);

    init_port.GPIO_Pin = SPI3_SCLK_Pin;
    GPIO_Init(SPI3_SCLK_Port, &init_port);

    init_port.GPIO_Pin = SPI3_SS_Pin;
    GPIO_Init(SPI3_SS_Port, &init_port);

    GPIO_PinAFConfig(SPI3_MISO_Port, SPI3_MISO_Pin, GPIO_AF_SPI3);
    GPIO_PinAFConfig(SPI3_MOSI_Port, SPI3_MOSI_Pin, GPIO_AF_SPI3);
    GPIO_PinAFConfig(SPI3_SCLK_Port, SPI3_SCLK_Pin, GPIO_AF_SPI3);
    GPIO_PinAFConfig(SPI3_SS_Port, SPI3_SS_Pin, GPIO_AF_SPI3);

}
示例#23
0
static void init_dbg_watchdog( void )
{
    TIM_TimeBaseInitTypeDef tim_time_base_init_struct;

    RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM7, ENABLE  );
    RCC_APB1PeriphResetCmd( RCC_APB1Periph_TIM7, DISABLE );

    /* Set dbg_watchdog timeout to 90% of the actual watchdog timeout to ensure it break before the actual watchdog bites
     * Timeout calculation
     * - Period per TIM clock cycle : 120MHz (CPU clock) / 2 (APB1 pre-scaler) / DBG_WATCHDOG_PRESCALER = 2.5ms
     *                                DBG_WATCHDOG_PRESCALER = 24000
     * - Timeout                    : ( 0.9 * 2.5ms * 1000 ) * timeout_in_seconds
     *                                DBG_WATCHDOG_TIMEOUT_MULTIPLIER =  ( 0.9 * 2.5ms * 1000 ) = 2250
     */

    tim_time_base_init_struct.TIM_Prescaler         = DBG_WATCHDOG_PRESCALER;
    tim_time_base_init_struct.TIM_CounterMode       = TIM_CounterMode_Up;
    tim_time_base_init_struct.TIM_Period            = DBG_WATCHDOG_TIMEOUT;
    tim_time_base_init_struct.TIM_ClockDivision     = TIM_CKD_DIV1;
    tim_time_base_init_struct.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit( TIM7, &tim_time_base_init_struct );

    TIM_ClearITPendingBit( TIM7, TIM_IT_Update );
    TIM_ITConfig( TIM7, TIM_IT_Update, ENABLE );

    TIM_UpdateRequestConfig( TIM7, TIM_UpdateSource_Regular );

    NVIC_EnableIRQ( TIM7_IRQn );

    TIM_Cmd( TIM7, ENABLE );
}
示例#24
0
文件: drv_WDG.c 项目: jdaheron/BLDR
/**-----------------------------------------------------------------------------
 * @brief	Initialisation du watchdog Windows.
 *
 * param[in]	Timeout_ms	Duree du timeout watchdog en ms.
 */
void WDG_InitWWDG(uint16_t Timeout_ms){

	RCC_ClocksTypeDef xRCC_Clocks;
	uint32_t ulClock_kHz;

	WWDG_DeInit();

	// Initialisation des variables
	WWDG_Reload = Timeout_ms;
	WWDG_Cnt = Timeout_ms;

	// Activation horloges
	RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

	// Configuration interruption
	WWDG_EnableIT();
	#ifdef configLIBRARY_KERNEL_INTERRUPT_PRIORITY
		NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
		NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
		NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
		NVIC_Init( &NVIC_InitStructure );
	#else
		NVIC_EnableIRQ(WWDG_IRQn);
	#endif

	// Configuration timeout
	WWDG_SetPrescaler(WWDG_Prescaler_8);
	WWDG_SetWindowValue(0x7F);

	// Activation
	WWDG_Enable(0x7F);
	WDG_Refresh();
}
示例#25
0
/**
  * @brief  Deinitializes the I2Cx peripheral registers to their default reset values.
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @retval None
  */
void I2C_DeInit(I2C_TypeDef* I2Cx) {
    /* Check the parameters */
    assert_param(IS_I2C_ALL_PERIPH(I2Cx));

    if(I2Cx == I2C1) {
        /* Enable I2C1 reset state */
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
        /* Release I2C1 from reset state */
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
    } else {
        /* Enable I2C2 reset state */
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
        /* Release I2C2 from reset state */
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
    }
}
示例#26
0
/**
  * @brief  Deinitializes the CAN peripheral registers to their default
  *   reset values.
  * @param CANx: where x can be 1 select the CAN peripheral.
  * @retval : None.
  */
void CAN_DeInit(CAN_TypeDef* CANx)
{
	/* Check the parameters */
	assert_param(IS_CAN_ALL_PERIPH(CANx));

	switch (*(uint32_t*)&CANx) {
	case CAN1_BASE:
		/* Enable CAN1 reset state */
		RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, ENABLE);
		/* Release CAN1 from reset state */
		RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, DISABLE);
		break;
	default:
		break;
	}
}
示例#27
0
文件: i2c_api.c 项目: haydar9/mbed
void i2c_reset(i2c_t *obj) {
    I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
    int timeout;
	
    // wait before reset
    timeout = LONG_TIMEOUT;
    while((I2C_GetFlagStatus(i2c, I2C_FLAG_BUSY)) && (timeout-- != 0));
	
    if (obj->i2c == I2C_1) {
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
    }
    if (obj->i2c == I2C_2) {
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
        RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
    }
}
示例#28
0
文件: usart4.c 项目: haiwil/485
//初始化IO 串口2
//pclk1:PCLK1时钟频率(Mhz)
//bound:波特率	  
void UART4_Init(u32 bound)
{  
	NVIC_InitTypeDef NVIC_InitStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);	// GPIOC时钟
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);

 	//USART_DeInit(UART4);  //复位串口2
	
		 //USART2_TX   PC.10
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PC.10
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;	//复用推挽输出
  GPIO_Init(GPIOC, &GPIO_InitStructure); //初始化PA2
   
    //USART2_RX	  PC.11
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
  GPIO_Init(GPIOC, &GPIO_InitStructure);  //初始化PA3
	
	RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4,ENABLE);
	RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4,DISABLE);

	USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	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;	//收发模式
	USART_Init(UART4, &USART_InitStructure); //初始化串口	2  	  
	
	NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;		//子优先级3
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			//IRQ通道使能
	NVIC_Init(&NVIC_InitStructure);	//根据指定的参数初始化VIC寄存器

	/* 使能串口2接收中断 */
	USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
	/* 使能串口2总线空闲中断 */
	USART_ITConfig(UART4, USART_IT_IDLE, ENABLE);
	USART_Cmd(UART4, ENABLE);                    //使能串口 	
	
}
示例#29
0
文件: ina219.c 项目: khaled777b/snaps
// Initialize the sensor
void INA219_Init(INA219* sensor)
{
	// Start with a clean slate
	//INA219_DeInit(sensor);
	
    // Initialization structures
    GPIO_InitTypeDef GPIO_InitStructure;
    I2C_InitTypeDef I2C_InitStructure;
    
    // Enable the I2C clock
    RCC_APB1PeriphClockCmd(sensor->clock, ENABLE);

    // Enable the GPIO clocks
    RCC_AHB1PeriphClockCmd(sensor->sda.clock | sensor->scl.clock, ENABLE);
    
    // Reset the I2C peripheral
	RCC_APB1PeriphResetCmd(sensor->clock, ENABLE);
    RCC_APB1PeriphResetCmd(sensor->clock, DISABLE);
    
    // Connect the GPIO pins to the I2C peripheral (alternate function, AF)
    GPIO_PinAFConfig(sensor->sda.port, sensor->sda.pinsource, sensor->af);
    GPIO_PinAFConfig(sensor->scl.port, sensor->scl.pinsource, sensor->af);

    // Set up GPIO for SDA and SCL, aka open-drain with pull-ups
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Pin = sensor->scl.pin;
    GPIO_Init(sensor->scl.port, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = sensor->sda.pin;
    GPIO_Init(sensor->sda.port, &GPIO_InitStructure);

    // Set up I2C parameters; 400khz, 7-bit addresses, "I2C mode" are important
    I2C_InitStructure.I2C_ClockSpeed = 400000;
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStructure.I2C_OwnAddress1 = 0;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

    // Initialize the I2C peripheral
	I2C_Cmd(sensor->peripheral, ENABLE);
    I2C_Init(sensor->peripheral, &I2C_InitStructure);
}
示例#30
0
///////////////////////////////
///检测总线是否为busy,若是,进行修复
///@retval -1:成功 -0:失败
///////////////////////////////
bool I2C::I2C_CHACK_BUSY_FIX(uint32_t i2cClock,uint16_t sclPin,uint16_t sdaPin)
{
	u8 Time_out=0;
	GPIO_InitTypeDef GPIO_InitStructure;

	while(I2C_GetFlagStatus(mI2C, I2C_FLAG_BUSY)&&Time_out<20)
	{
		RCC_APB1PeriphClockCmd(i2cClock,DISABLE);//开启I2C时钟
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//开启scl  sda时钟


		/* Set GPIO frequency to 50MHz */
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

		/* Select Output open-drain mode */
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
									
		/* Initialize I2Cx SCL Pin */ 
		GPIO_InitStructure.GPIO_Pin = sclPin;
		GPIO_Init(GPIOB, &GPIO_InitStructure);

		/* Initialize I2Cx SDA Pin */
		GPIO_InitStructure.GPIO_Pin = sdaPin;
		GPIO_Init(GPIOB, &GPIO_InitStructure); 
		  
		//模拟方式产生停止信号
		GPIO_ResetBits(GPIOB, sclPin);
		GPIO_ResetBits(GPIOB, sdaPin);
		DelayUs(5);
		GPIO_SetBits(GPIOB, sclPin);
		DelayUs(5);
		GPIO_SetBits(GPIOB, sdaPin);
		DelayUs(5);
		
		I2CGPIODeInit(sclPin,sdaPin);//IO设置成默认值
		RCC_APB1PeriphResetCmd(i2cClock,ENABLE);//重置clk时钟 防止有错误标志
		RCC_APB1PeriphResetCmd(i2cClock,DISABLE);//关闭clk重置
		RCC_APB1PeriphClockCmd(i2cClock,ENABLE);//开启I2C时钟
		++Time_out;

	}
	if(Time_out==20)
		return 0;
	return 1;
}