示例#1
0
/**
 * @brief  Turns selected LED Off.
 * @param  xLed Specifies the Led to be set off.
 *         This parameter can be one of following parameters:
 *         @arg LED1
 *         @arg LED2
 *         @arg LED3
 *         @arg LED4
 *         @arg LED5
 * @retval None.
 */
void SdkEvalLedOff(SdkEvalLed xLed)
{
  if(SdkEvalGetVersion() == SDK_EVAL_VERSION_2_1 || SdkEvalGetVersion() == SDK_EVAL_VERSION_3)
    vectpxGpioPort[xLed]->BSRRL = s_vectnGpioPin[xLed];
  if(SdkEvalGetVersion() == SDK_EVAL_VERSION_D1)
    vectpxGpioPort[xLed]->BSRRH = s_vectnGpioPin[xLed];
}
示例#2
0
/**
* @brief  Initialization of the CSn pin of the EEPROM.
*         SPI, MISO, MOSI and SCLK are the same used for the BlueNRG.
*         This function can be replaced by EepromCsPinInitialization() if
*         SdkEvalSpiInit() is called.
* @param  None
* @retval None
*/
void EepromCsPinInitialization(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
#ifdef USER_DEFINED_PLATFORM 
   
  /* Configure SPI Periph Clock x CS line*/
  RCC_AHBPeriphClockCmd(EEPROM_SPI_PERIPH_CS_RCC, ENABLE);

#else /* BlueNRG SPI Driver configuration for BlueNRG Development Kits platforms */
  
  s_EepromSpiPort = s_EepromSpiPortVersion[SdkEvalGetVersion()];
  s_vectpxEepromSpiCsPort = s_vectpxEepromSpiCsPortVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiCsPin = s_vectpxEepromSpiCsPinVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiCsClk = s_vectpxEepromSpiCsClkVersion[SdkEvalGetVersion()];

  /* Configure SPI Periph Clock x CS line*/
  RCC_AHBPeriphClockCmd(s_vectnEepromSpiCsClk, ENABLE);
  
#endif /* USER_DEFINED_PLATFORM */
  
  /* Configure SPI pin: CS */
  GPIO_InitStructure.GPIO_Pin = Get_vectEepromSpiCsPin();
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_WriteBit(Get_vectEepromSpiCsPort(), Get_vectEepromSpiCsPin(), Bit_SET); 
  GPIO_Init(Get_vectEepromSpiCsPort(), &GPIO_InitStructure);
     
  /* Put the SPI chip select high to end the transaction */
  //EepromSPICSHigh(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin()); /* Is it needed ?TBR */
}/* end EepromCsPinInitialization() */
示例#3
0
/**
* @brief  Initialization of the CSn pin of the EEPROM.
*         This function is called internally by EepromCsPinInitialization.
* @param  None
* @retval None
*/
void EepromCsPinInitialization(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  s_EepromSpiPort = s_EepromSpiPortVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiCsPin = (uint16_t *)&s_vectpxEepromSpiCsPinVersion[SdkEvalGetVersion()];
  s_vectpxEepromSpiCsPort = &s_vectpxEepromSpiCsPortVersion[SdkEvalGetVersion()];
  
  if(!SdkEvalGetVersion())
  {            
    /* Configure SPI pin: CS */
    GPIO_InitStructure.GPIO_Pin = EEPROM_V2_SPI_PERIPH_CS_PIN;
    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(EEPROM_V2_SPI_PERIPH_CS_PORT, &GPIO_InitStructure);
    
    /* Enable CS GPIO clock */
    RCC_AHBPeriphClockCmd(EEPROM_V2_SPI_PERIPH_CS_RCC, ENABLE);
  }
  else
  {
    /* Configure SPI pin: CS */
    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;
    
    if(SdkEvalGetVersion()==SDK_EVAL_VERSION_3)
    {
      GPIO_InitStructure.GPIO_Pin = EEPROM_V3_SPI_PERIPH_CS_PIN;
      GPIO_Init(EEPROM_V3_SPI_PERIPH_CS_PORT, &GPIO_InitStructure);
      RCC_AHBPeriphClockCmd(EEPROM_V3_SPI_PERIPH_CS_RCC, ENABLE);
    }
    else
    {
      GPIO_InitStructure.GPIO_Pin = EEPROM_VD1_SPI_PERIPH_CS_PIN;
      GPIO_Init(EEPROM_VD1_SPI_PERIPH_CS_PORT, &GPIO_InitStructure);
      RCC_AHBPeriphClockCmd(EEPROM_VD1_SPI_PERIPH_CS_RCC, ENABLE);
    }
    
    
  }
  
  /* Put the SPI chip select high to end the transaction */
  EepromSPICSHigh();
}
示例#4
0
/**
 * @brief  Configures the Analog-to-Digital Converter and the correspondent GPIO pins.
 * @param  None.
 * @retval None.
 */
void SdkEvalPmADCInit(void)
{
  if(!SdkEvalGetVersion() ){
    ADC_InitTypeDef ADC_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    
    /* Enables ADC1 and GPIO clocks */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
    
    /* Configures ADC pins */
    GPIO_InitStructure.GPIO_Pin = ADC_V_RF_Pin | ADC_V_5V_Pin | ADC_V_3V_Pin | ADC_I_R1_Pin | ADC_I_R2_Pin;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    /* Configures ADC periferial */
    ADC_InitStructure.ADC_ScanConvMode = DISABLE;
    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;
    ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
    ADC_InitStructure.ADC_NbrOfConversion = 1;
    ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
    
    ADC_Init(ADC1, &ADC_InitStructure);
  }
}
示例#5
0
/**
 * @brief  Configures MCU GPIO and EXTI Line for GPIOs.
 * @param  xGpio Specifies the GPIO to be configured.
 *         This parameter can be one of following parameters:
 *         @arg M2S_GPIO_0: GPIO_0
 *         @arg M2S_GPIO_1: GPIO_1
 *         @arg M2S_GPIO_2: GPIO_2
 *         @arg M2S_GPIO_3: GPIO_3
 *         @arg M2S_GPIO_SDN: GPIO_SDN
 * @param  xGpioMode Specifies GPIO mode.
 *         This parameter can be one of following parameters:
 *         @arg M2S_MODE_GPIO_IN: MCU GPIO will be used as simple input.
 *         @arg M2S_MODE_EXTI_IN: MCU GPIO will be connected to EXTI line with interrupt
 *         generation capability.
 *         @arg M2S_MODE_GPIO_OUT: MCU GPIO will be used as simple output.
 * @retval None.
 */
void SdkEvalM2SGpioInit(M2SGpioPin xGpio, M2SGpioMode xGpioMode)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  EXTI_InitTypeDef EXTI_InitStructure;
  FunctionalState xExtiLine = DISABLE;
  
  /* Check the parameters */
  assert_param(IS_M2S_GPIO_PIN(xGpio));
  assert_param(IS_M2S_GPIO_MODE(xGpioMode));
  
  
  /* Enables the MCU GPIO Clock */
  RCC_AHBPeriphClockCmd(s_vectlM2SGpioClk[SdkEvalGetVersion()>>1][xGpio], ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  
  /* Configures MCU GPIO */
  if(xGpioMode == M2S_MODE_GPIO_OUT)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  
  GPIO_InitStructure.GPIO_PuPd = s_vectxM2SGpioPuPd[xGpio];
  GPIO_InitStructure.GPIO_Speed = s_vectxM2SGpioSpeed[xGpio];
  GPIO_InitStructure.GPIO_OType = s_vectxM2SGpioOType[xGpio];
  GPIO_InitStructure.GPIO_Pin = s_vectnM2SGpioPin[xGpio];
  GPIO_Init(vectpxM2SGpioPort[SdkEvalGetVersion()>>1][xGpio], &GPIO_InitStructure);
  
  /* Configures MCU GPIO EXTI line */
  EXTI_InitStructure.EXTI_Line = s_vectlM2SExtiLine[xGpio];
  EXTI_InitStructure.EXTI_Mode = s_vectxM2sGpioExtiMode[xGpio];
  EXTI_InitStructure.EXTI_Trigger = s_vectxM2SGpioExtiTrigger[xGpio];
  EXTI_InitStructure.EXTI_LineCmd = xExtiLine;
  
  if (xGpioMode == M2S_MODE_EXTI_IN)
  {
    /* Connects EXTI Line to MCU GPIO Pin */
    SYSCFG_EXTILineConfig(s_vectcM2SGpioExtiPortSource[SdkEvalGetVersion()>>1][xGpio], s_vectcM2SGpioExtiPinSource[xGpio]);
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  }
示例#6
0
/**
 * @brief  Implements a control loop to make the specified voltage equal
 *         to a reference one (with a specified tolerance on the steady state).
 *         The control loop vanishes an integral error and it ends when this error
 *         becomes constant.
 * @param  xAdcCh ADC channel.
 *         This parameter can be any value of ADC_CH_V_RF or ADC_CH_V_MCU.
 * @param  fVref Reference voltage to be reached by the specified channel 3
 *         voltage expressed in Volt.
 *         This parameter is a float.
 * @retval None.
 */
void SdkEvalPmRegulateVoltageI(SdkEvalAdcChannel xAdcCh , float fVref)
{
  if( !SdkEvalGetVersion() ){
    float fKi=0.13, fVcon;
    int cD = 0x7F;
    int nVerrC, nVerrP=0;
    
    if(xAdcCh == ADC_CH_V_RF)
    {
      /* sets the digipot value */
      SdkEvalPmDigipotWrite(DIGIPOT1, cD);
      
      /* waits for the steady state */
      for(volatile uint32_t i=0 ; i<0xFFFF ; i++);
      
      /* gets the new output value */
      fVcon=SdkEvalPmGetVRf();
    }
    
    /* computes the new error value */
    nVerrC = (int)((fVref - fVcon)*1000);
    
    while(nVerrC != nVerrP){
      /* computes the new input value */
      cD += (int)(fKi*nVerrC);
      
      /* Saturate cD to be into the range [0 , 255] */
      if(cD>255) cD=255;
      else if(cD<0) cD=0;
      
      if(xAdcCh == ADC_CH_V_RF)
      {
        /* sets the digipot value */
        SdkEvalPmDigipotWrite(DIGIPOT1, cD);
        
        /* waits for the steady state */
        for(volatile uint32_t i=0 ; i<0x3FFF ; i++);
        
        /* gets the new output value */
        fVcon=SdkEvalPmGetVRf();
      }
      
      /* stores the previous error value */
      nVerrP = nVerrC;
      
      /* computes the new error value */
      nVerrC = (int)((fVref - fVcon)*1000);
      
    }}
}
void Configure_Button(void)
{
  
#ifdef USER_DEFINED_PLATFORM    
    /* Select BUTTON_SEL  push-button */
    ButtonPort = USER_BUTTON1_GPIO_PORT;
    ButtonPin = USER_BUTTON1_GPIO_PIN;  
#else /* Runtime configuration for BlueNRG Development board and USB Dongle platform */
    /* Select button & led resource */
    if(SdkEvalGetVersion() == SDK_EVAL_VERSION_3) 
    {
      /* Select User push-button */
      ButtonPort = SCM_PS_BUTTON_GPIO_PORT;
      ButtonPin = SCM_PS_BUTTON_PIN; 
    }
    else if (SdkEvalGetVersion() == SDK_EVAL_VERSION_D1)
    {
      /* Select  button SW1 for BlueNRG USB Dongle */
      ButtonPort = SCM_PS_BUTTON_VD1_GPIO_PORT;
      ButtonPin = SCM_PS_BUTTON_VD1_PIN;
    }
#endif /* USER_DEFINED_PLATFORM */
}
示例#8
0
/**
 * @brief  Configures Button GPIO and EXTI Line.
 * @param  xButton Specifies the Button to be configured.
 *         This parameter can be one of following parameters:
 *         @arg BUTTON_WAKEUP: Wakeup Push Button
 *         @arg BUTTON_TAMPER: Tamper Push Button
 *         @arg BUTTON_KEY: Key Push Button
 *         @arg BUTTON_RIGHT: Joystick Right Push Button
 *         @arg BUTTON_LEFT: Joystick Left Push Button
 *         @arg BUTTON_UP: Joystick Up Push Button
 *         @arg BUTTON_DOWN: Joystick Down Push Button
 *         @arg BUTTON_SEL: Joystick Sel Push Button
 * @param  xButtonMode Specifies Button mode.
 *         This parameter can be one of following parameters:
 *         @arg BUTTON_MODE_GPIO: Button will be used as simple IO
 *         @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
 *         generation capability
 * @retval None.
 */
void SdkEvalPushButtonInit(SdkEvalButton xButton, SdkEvalButtonMode xButtonMode)
{  
  s_vectpxButtonPort = s_vectpxButtonPortVersion[SdkEvalGetVersion()];
  s_vectnButtonPin = (uint16_t *)s_vectnButtonPinVersion[SdkEvalGetVersion()];
  s_vectlButtonClk = (uint32_t *)s_vectlButtonClkVersion[SdkEvalGetVersion()];
  s_vectnButtonExtiLine = (uint16_t *)s_vectnButtonExtiLineVersion[SdkEvalGetVersion()];
  s_vectnButtonPortSource = (uint16_t *)s_vectnButtonPortSourceVersion[SdkEvalGetVersion()];
  s_vectnButtonPinSource = (uint16_t *)s_vectnButtonPinSourceVersion[SdkEvalGetVersion()];
  s_vectnButtonIrqn = (uint16_t *)s_vectnButtonIrqnVersion[SdkEvalGetVersion()];
  
  GPIO_InitTypeDef GPIO_InitStructure;
  EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enables the BUTTON Clock */
  RCC_AHBPeriphClockCmd(s_vectlButtonClk[xButton], ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  /* Configures Button pin as input */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = s_vectnButtonPin[xButton];
  GPIO_Init(s_vectpxButtonPort[xButton], &GPIO_InitStructure);


  if (xButtonMode == BUTTON_MODE_EXTI)
  {
    /* Connects Button EXTI Line to Button GPIO Pin */
    SYSCFG_EXTILineConfig(s_vectnButtonPortSource[xButton], s_vectnButtonPinSource[xButton]);

    /* Configures Button EXTI line */
    EXTI_InitStructure.EXTI_Line = s_vectnButtonExtiLine[xButton];
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
    
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    /* Enables and sets Button EXTI Interrupt to the lowest priority */
    NVIC_InitStructure.NVIC_IRQChannel = s_vectnButtonIrqn[xButton];
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = BUTTON_IRQ_PREEMPTION_PRIORITY;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = BUTTON_IRQ_SUB_PRIORITY;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    EXTI_ClearITPendingBit(s_vectnButtonExtiLine[xButton]);

    NVIC_Init(&NVIC_InitStructure);
  }
}
示例#9
0
/**
 * @brief  Configures the RF supply voltage switch GPIO.
 * @param  None.
 * @retval None.
 */
void SdkEvalPmRfSwitchInit(void)
{
  if(!SdkEvalGetVersion())
  {
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enables the switch and GPIO clocks */
  RCC_AHBPeriphClockCmd(RF_SWITCH_RCC, ENABLE);


  /* Configures the switch GPIO pins */
  GPIO_InitStructure.GPIO_Pin =  RF_SWITCH_Pin;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

  GPIO_Init(RF_SWITCH_Port, &GPIO_InitStructure);
  }
}
示例#10
0
/**
 * @brief  Configures the I2C interface and the correspondent GPIO pins.
 * @param  None.
 * @retval None.
 */
void SdkEvalPmI2CInit(void){
if(!SdkEvalGetVersion())
{
  I2C_InitTypeDef I2C_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enables I2C and GPIO clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

  /* GPIO AF configuration */
  GPIO_PinAFConfig(DIGIPOT_I2C_SCL_Port, DIGIPOT_I2C_SCL_RCC_SOURCE, DIGIPOT_I2C_SCL_AF);
  GPIO_PinAFConfig(DIGIPOT_I2C_SDA_Port, DIGIPOT_I2C_SDA_RCC_SOURCE, DIGIPOT_I2C_SDA_AF);

  /* Configures I2C pins: SCL and SDA */
  GPIO_InitStructure.GPIO_Pin =  DIGIPOT_I2C_SCL_Pin | DIGIPOT_I2C_SDA_Pin;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configures I2C */
  I2C_DeInit(DIGIPOT_I2C);
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = 0xA0;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = DIGIPOT_I2C_SPEED;

  /* DIGIPOT_I2C Init */
  I2C_Init(DIGIPOT_I2C, &I2C_InitStructure);

  /* DIGIPOT_I2C Enable */
  I2C_Cmd(DIGIPOT_I2C, ENABLE);
}
}
示例#11
0
/**
 * @brief  Samples, converts and returns the voltage on the specified ADC channel.
 * @param  xAdcCh ADC channel.
 *         This parameter can be any value of @ref SdkEvalAdcChannel.
 * @retval uint16_t Converted voltage in an unsiged integer 16-bit format.
 */
uint16_t SdkEvalPmGetV(SdkEvalAdcChannel xAdcCh)
{
  uint16_t convValue=2785;
  
  if( !SdkEvalGetVersion() ){

    /* ADC1 channel configuration */
    ADC_RegularChannelConfig(ADC1, xAdcCh, 1, ADC_SampleTime_48Cycles);
    
    /* Enables HSI clock */
    RCC_HSICmd(ENABLE);
    
    /* Enables ADC1 */
    ADC_Cmd(ADC1, ENABLE);
    
    /* Waits until the ADC1 is ready */
    while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET);
    
    /* Start ADC1 Software Conversion */
    ADC_SoftwareStartConv(ADC1);
    
    /* Waits until the end of conversion */
    while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
    
    /* Gets the ADC conversion value */
    convValue = ADC_GetConversionValue(ADC1);
    
    /* Disables ADC */
    ADC_Cmd(ADC1, DISABLE);
    
    /* Disables HSI clock */
    RCC_HSICmd(DISABLE);
  }
  /* Return the converted value */
  return convValue;

}
示例#12
0
/**
 * @brief  Configures LED GPIO.
 * @param  xLed Specifies the Led to be configured.
 *         This parameter can be one of following parameters:
 *         @arg LED1
 *         @arg LED2
 *         @arg LED3
 *         @arg LED4
 *         @arg LED5
 * @retval None.
 */
void SdkEvalLedInit(SdkEvalLed xLed)
{
  vectpxGpioPort = vectpxGpioPortVersion[SdkEvalGetVersion()];
  s_vectnGpioPin = (uint16_t *)s_vectnGpioPinVersion[SdkEvalGetVersion()];
  s_vectlGpioClk = (uint32_t *)s_vectlGpioClkVersion[SdkEvalGetVersion()];

  GPIO_InitTypeDef  GPIO_InitStructure;
  
  /* Enable the GPIO_LED Clock */
  RCC_AHBPeriphClockCmd(s_vectlGpioClk[xLed], ENABLE);
  
  /* Configure the GPIO_LED pin */
  GPIO_InitStructure.GPIO_Pin = s_vectnGpioPin[xLed];
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_Init(vectpxGpioPort[xLed], &GPIO_InitStructure);
  if(SdkEvalGetVersion() == SDK_EVAL_VERSION_2_1 || SdkEvalGetVersion() == SDK_EVAL_VERSION_3)
    vectpxGpioPort[xLed]->BSRRL = s_vectnGpioPin[xLed];
  if(SdkEvalGetVersion() == SDK_EVAL_VERSION_D1)
    vectpxGpioPort[xLed]->BSRRH = s_vectnGpioPin[xLed];
}
示例#13
0
/**
 * @brief  Sets the switch to supply RF voltage.
 * @param  None.
 * @retval None.
 */
void SdkEvalPmRfSwitchToVRf(void)
{
  if(!SdkEvalGetVersion() ){
  RF_SWITCH_Port->BSRRH = RF_SWITCH_Pin;
  }
}
示例#14
0
/**
* @brief  Initializes the SPI for SPIRIT
* @param  None
* @retval None
*/
void SdkEvalSpiInit(void)
{
  SPI_InitTypeDef SPI_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  
  s_SpiPort = s_SpiPortVersion[SdkEvalGetVersion()];
  s_vectnSpiPin = (uint16_t *)&s_vectpxSpiCsPinVersion[SdkEvalGetVersion()];
  s_vectpxSpiPort = &s_vectpxSpiCsPortVersion[SdkEvalGetVersion()];
  
  if(!SdkEvalGetVersion())
  {
    /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
    RCC_APB2PeriphClockCmd(SDK_EVAL_V2_SPI_PERIPH_RCC, ENABLE);
    RCC_AHBPeriphClockCmd(SDK_EVAL_V2_SPI_PERIPH_MOSI_RCC | SDK_EVAL_V2_SPI_PERIPH_MISO_RCC | SDK_EVAL_V2_SPI_PERIPH_SCLK_RCC | SDK_EVAL_V2_SPI_PERIPH_CS_RCC, ENABLE);
    
    /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/
    GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_MOSI_PORT, SDK_EVAL_V2_SPI_PERIPH_MOSI_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_MOSI_AF);
    GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_MISO_PORT, SDK_EVAL_V2_SPI_PERIPH_MISO_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_MISO_AF);
    GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_SCLK_PORT, SDK_EVAL_V2_SPI_PERIPH_SCLK_RCC_SOURCE, SDK_EVAL_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 = SDK_EVAL_V2_SPI_PERIPH_SCLK_PIN;
    GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_MISO_PIN;
    GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_MOSI_PIN;
    GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure);
    
    /* Configure SPI pin: CS */
    GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_CS_PIN;
    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(SDK_EVAL_V2_SPI_PERIPH_CS_PORT, &GPIO_InitStructure);
    
  }
  else
  {
    /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
    RCC_AHBPeriphClockCmd(SDK_EVAL_V3_SPI_PERIPH_MOSI_RCC | SDK_EVAL_V3_SPI_PERIPH_MISO_RCC | SDK_EVAL_V3_SPI_PERIPH_SCLK_RCC | SDK_EVAL_V3_SPI_PERIPH_CS_RCC, ENABLE);
    
    /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/
    GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_MOSI_PORT, SDK_EVAL_V3_SPI_PERIPH_MOSI_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_MOSI_AF);
    GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_MISO_PORT, SDK_EVAL_V3_SPI_PERIPH_MISO_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_MISO_AF);
    GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_SCLK_PORT, SDK_EVAL_V3_SPI_PERIPH_SCLK_RCC_SOURCE, SDK_EVAL_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 = SDK_EVAL_V3_SPI_PERIPH_SCLK_PIN;
    GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_MISO_PIN;
    GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_MOSI_PIN;
    GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure);
    
    /* Configure SPI pin: CS */
    GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_CS_PIN;
    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(SDK_EVAL_V3_SPI_PERIPH_CS_PORT, &GPIO_InitStructure);
    
    /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
    RCC_APB1PeriphClockCmd(SDK_EVAL_V3_SPI_PERIPH_RCC, ENABLE);     
  }
  
  /* Configure SPI peripheral */
  SPI_DeInit(s_SpiPort);
  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_SpiPort, &SPI_InitStructure);
  
  SPI_Cmd(s_SpiPort, ENABLE);
  
#ifdef FREERTOS  
  xSpiMutex = xSemaphoreCreateMutex();
  if (!xSpiMutex)
    /* Error in resource creation. */
    for (;;);
  xSemaphoreGive(xSpiMutex);  
#endif
  
  
  SdkEvalSPICSHigh();
}
示例#15
0
/**
* @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();
  
}
示例#16
0
/**
* @brief  Basic SPI configuration according to the selected platform 
* @param  None
* @retval status
*/
static int8_t EepromSpi_Configure_Platform(void)
{
#ifdef USER_DEFINED_PLATFORM 

  /* SPI Periph clock enable */
#ifdef EEPROM_SPI_PERIPH_RCC_APB1
  RCC_APB1PeriphClockCmd(EEPROM_SPI_PERIPH_RCC_APB1, ENABLE);
#else
  RCC_APB2PeriphClockCmd(EEPROM_SPI_PERIPH_RCC_APB2, ENABLE);
#endif 
    
  /* Configure SPI Periph Clocks */
  RCC_AHBPeriphClockCmd(EEPROM_SPI_PERIPH_CS_RCC | EEPROM_SPI_PERIPH_MOSI_RCC_SOURCE |  
                        EEPROM_SPI_PERIPH_MISO_RCC_SOURCE| EEPROM_SPI_PERIPH_SCLK_RCC_SOURCE, ENABLE);

#else /* BlueNRG SPI Driver configuration for BlueNRG Development Kits platforms */

  s_EepromSpiPort = s_EepromSpiPortVersion[SdkEvalGetVersion()];
  s_vectpxEepromSpiCsPort = s_vectpxEepromSpiCsPortVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiCsPin = s_vectpxEepromSpiCsPinVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiCsClk = s_vectpxEepromSpiCsClkVersion[SdkEvalGetVersion()];

  s_vectpxEepromSpiMosiPort = s_vectpxEepromSpiMosiPortVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiMosiPin = s_vectpxEepromSpiMosiPinVersion[SdkEvalGetVersion()];
  
  s_vectpxEepromSpiMosiPinSource = s_vectpxEepromSpiMosiPinSourceVersion[SdkEvalGetVersion()];
  s_vectpxEepromSpiMosiAF = s_vectpxEepromSpiMosiAFVersion[SdkEvalGetVersion()];
 
  s_vectpxEepromSpiMisoPort = s_vectpxEepromSpiMisoPortVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiMisoPin = s_vectpxEepromSpiMisoPinVersion[SdkEvalGetVersion()];  
  
  s_vectpxEepromSpiMisoPinSource = s_vectpxEepromSpiMisoPinSourceVersion[SdkEvalGetVersion()];
  s_vectpxEepromSpiMisoAF = s_vectpxEepromSpiMisoAFVersion[SdkEvalGetVersion()];

  s_vectpxEepromSpiSclkPort = s_vectpxEepromSpiSclkPortVersion[SdkEvalGetVersion()];
  s_vectnEepromSpiSclkPin = s_vectpxEepromSpiSclkPinVersion[SdkEvalGetVersion()];
  
  s_vectpxEepromSpiSclkPinSource = s_vectpxEepromSpiSclkPinSourceVersion[SdkEvalGetVersion()];
  s_vectpxEepromSpiSclkAF = s_vectpxEepromSpiSclkAFVersion[SdkEvalGetVersion()];

  if(SdkEvalGetVersion() == SDK_EVAL_VERSION_3 || SdkEvalGetVersion() == SDK_EVAL_VERSION_D1)
  {      
    /* Enable SPI2 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 | s_vectnEepromSpiCsClk, ENABLE);
  }
  else
  {
    /* Platform is not supported */
    return(-1); 
  }

#endif /* USER_DEFINED_PLATFORM */

  return(0);
}/* end EepromSpi_Configure_Platform() */