/**
 * @brief  Resets the BlueNRG.
 * @param  None
 * @retval None
 */
void BlueNRG_RST(void)
{
  uint8_t ubnRFResetTimerID;
  
  GPIO_InitTypeDef GPIO_InitStruct;
  
  GPIO_InitStruct.Pin = BNRG_SPI_RESET_PIN;
  GPIO_InitStruct.Speed = BNRG_SPI_RESET_SPEED;
  TIMER_Create(eTimerModuleID_Interrupt, &ubnRFResetTimerID, eTimerMode_SingleShot, pf_nRFResetTimerCallBack);
  
  BNRG_SPI_RESET_CLK_ENABLE();
  
  HAL_GPIO_WritePin(BNRG_SPI_RESET_PORT, BNRG_SPI_RESET_PIN, GPIO_PIN_RESET);
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
  
  TIMER_Start(ubnRFResetTimerID, BLUENRG_HOLD_TIME_IN_RESET);
  ubnRFresetTimerLock = 1;
  while(ubnRFresetTimerLock == 1);
  
  HAL_GPIO_WritePin(BNRG_SPI_RESET_PORT, BNRG_SPI_RESET_PIN, GPIO_PIN_SET);
  
#if 1
  /*
   * Limitation in HAL V1.1.0
   * The HAL_GPIO_Init() is first configuring the Mode of the IO before the Pull UP configuration
   * To avoid glitch on the IO, the configuration shall go through an extra step OUTPUT/PULLUP
   * to set upfront the PULL UP configuration.
   */
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
#endif
  
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
  
  TIMER_Start(ubnRFResetTimerID, BLUENRG_HOLD_TIME_AFTER_RESET);
  ubnRFresetTimerLock = 1;
  while(ubnRFresetTimerLock == 1);
  TIMER_Delete(ubnRFResetTimerID);
  
  return;
}
示例#2
0
/**
 * @brief  This function is used for low level initialization of the SPI 
 *         communication with the BlueNRG Expansion Board.
 * @param  Pointer to the handle of the STM32Cube HAL SPI interface.
 * @retval None
 */
void HAL_SPI_MspInit(SPI_HandleTypeDef * hspi)
{
	GPIO_InitTypeDef GPIO_InitStruct;
	if (hspi->Instance == BNRG_SPI_INSTANCE) {
		/* Enable peripherals clock */

		/* Enable GPIO Ports Clock */
		BNRG_SPI_RESET_CLK_ENABLE();
		BNRG_SPI_SCLK_CLK_ENABLE();
		BNRG_SPI_MISO_CLK_ENABLE();
		BNRG_SPI_MOSI_CLK_ENABLE();
		BNRG_SPI_CS_CLK_ENABLE();
		BNRG_SPI_IRQ_CLK_ENABLE();

		/* Enable SPI clock */
		BNRG_SPI_CLK_ENABLE();

		/* Reset */
		GPIO_InitStruct.Pin = BNRG_SPI_RESET_PIN;
		GPIO_InitStruct.Mode = BNRG_SPI_RESET_MODE;
		GPIO_InitStruct.Pull = BNRG_SPI_RESET_PULL;
		GPIO_InitStruct.Speed = BNRG_SPI_RESET_SPEED;
		GPIO_InitStruct.Alternate = BNRG_SPI_RESET_ALTERNATE;
		HAL_GPIO_Init(BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
		HAL_GPIO_WritePin(BNRG_SPI_RESET_PORT, BNRG_SPI_RESET_PIN, GPIO_PIN_RESET);	/*Added to avoid spurious interrupt from the BlueNRG */

		/* SCLK */
		GPIO_InitStruct.Pin = BNRG_SPI_SCLK_PIN;
		GPIO_InitStruct.Mode = BNRG_SPI_SCLK_MODE;
		GPIO_InitStruct.Pull = BNRG_SPI_SCLK_PULL;
		GPIO_InitStruct.Speed = BNRG_SPI_SCLK_SPEED;
		GPIO_InitStruct.Alternate = BNRG_SPI_SCLK_ALTERNATE;
		HAL_GPIO_Init(BNRG_SPI_SCLK_PORT, &GPIO_InitStruct);

		/* MISO */
		GPIO_InitStruct.Pin = BNRG_SPI_MISO_PIN;
		GPIO_InitStruct.Mode = BNRG_SPI_MISO_MODE;
		GPIO_InitStruct.Pull = BNRG_SPI_MISO_PULL;
		GPIO_InitStruct.Speed = BNRG_SPI_MISO_SPEED;
		GPIO_InitStruct.Alternate = BNRG_SPI_MISO_ALTERNATE;
		HAL_GPIO_Init(BNRG_SPI_MISO_PORT, &GPIO_InitStruct);

		/* MOSI */
		GPIO_InitStruct.Pin = BNRG_SPI_MOSI_PIN;
		GPIO_InitStruct.Mode = BNRG_SPI_MOSI_MODE;
		GPIO_InitStruct.Pull = BNRG_SPI_MOSI_PULL;
		GPIO_InitStruct.Speed = BNRG_SPI_MOSI_SPEED;
		GPIO_InitStruct.Alternate = BNRG_SPI_MOSI_ALTERNATE;
		HAL_GPIO_Init(BNRG_SPI_MOSI_PORT, &GPIO_InitStruct);

		/* NSS/CSN/CS */
		GPIO_InitStruct.Pin = BNRG_SPI_CS_PIN;
		GPIO_InitStruct.Mode = BNRG_SPI_CS_MODE;
		GPIO_InitStruct.Pull = BNRG_SPI_CS_PULL;
		GPIO_InitStruct.Speed = BNRG_SPI_CS_SPEED;
		GPIO_InitStruct.Alternate = BNRG_SPI_CS_ALTERNATE;
		HAL_GPIO_Init(BNRG_SPI_CS_PORT, &GPIO_InitStruct);
		HAL_GPIO_WritePin(BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN,
				  GPIO_PIN_SET);

		/* IRQ -- INPUT */
		GPIO_InitStruct.Pin = BNRG_SPI_IRQ_PIN;
		GPIO_InitStruct.Mode = BNRG_SPI_IRQ_MODE;
		GPIO_InitStruct.Pull = BNRG_SPI_IRQ_PULL;
		GPIO_InitStruct.Speed = BNRG_SPI_IRQ_SPEED;
		GPIO_InitStruct.Alternate = BNRG_SPI_IRQ_ALTERNATE;
		HAL_GPIO_Init(BNRG_SPI_IRQ_PORT, &GPIO_InitStruct);

		/* Configure the NVIC for SPI */
		HAL_NVIC_SetPriority(BNRG_SPI_EXTI_IRQn, 4, 0);
		HAL_NVIC_EnableIRQ(BNRG_SPI_EXTI_IRQn);
	}
}
/**************************************************************************
*                           BlueNRG_GPIO_Init
*
* @brief  This function is used for low level initialization of the SPI
*         communication support with the BlueNRG Expansion Board.
*
* @param  Pointer to the handle of the STM32Cube HAL SPI interface.
* @retval None
*************************************************************************/
void  BlueNRG_GPIO_Init (SPI_HandleTypeDef* hspi)
{
  GPIO_InitTypeDef  GPIO_InitStruct;


//  09/13/15        ---- NO ONE CALLS THIS LOGIC ANYMORE !!! ----
//                   is now handled in mnet_connect_network()

         //---------------------------------------------------
         // Configure GPIOs for control of BLE NRG module
         //---------------------------------------------------

         //---------------------------------------------------
         // Configure RESET pin:  PA8 - Arduino D7 on Nucleo.
         //---------------------------------------------------
    pin_Config (BLE_BLUENRG_RESET, GPIO_OUTPUT, PIN_USE_PULLUP);
    pin_Low (BLE_BLUENRG_RESET);    // and set it LOW, to prevent spurius interrupts during config

         //-------------------------------------------------------------------
         // Configure SPI CS pin:  PA1 - Arduino A1 on Nucleo.
         //
         // Rest of SPI pins will be auto-configured on spi_Init call (below)
         //-------------------------------------------------------------------
    pin_Config (BLE_BLUENRG_SPI_CS, GPIO_OUTPUT, PIN_USE_PULLUP);
    pin_High (BLE_BLUENRG_SPI_CS);  // and set it HIGH, to De-Assert CS during config

         //---------------------------------------------------
         // Configure IRQ pin:  PA0 - Arduino A0 on Nucleo
         //---------------------------------------------------
    pin_Config_IRQ_Pin (BLE_BLUENRG_IRQ_PIN, GPIO_RUPT_MODE_RISING, 0, BLE_BLUENRG_IRQn, 4);

         // and setup associated NVIC EXTI entries
    HAL_NVIC_SetPriority (BLE_BLUENRG_IRQn, 4, 0);
    HAL_NVIC_EnableIRQ (BLE_BLUENRG_IRQn);


#if WVD_SHUTOFF                              // 06/20/15 - debug L0 issues
  if (hspi->Instance == BNRG_SPI_INSTANCE)   // 0620/15 - L0 is skipping this ==> wrong instance ???
    {
        /* Enable GPIO Ports Clock */
    BNRG_SPI_RESET_CLK_ENABLE();
    BNRG_SPI_SCLK_CLK_ENABLE();
    BNRG_SPI_MISO_CLK_ENABLE();
    BNRG_SPI_MOSI_CLK_ENABLE();
    BNRG_SPI_CS_CLK_ENABLE();
    BNRG_SPI_IRQ_CLK_ENABLE();

        /* Enable SPI clock */
    BNRG_SPI_CLK_ENABLE();

        /* Reset */
    GPIO_InitStruct.Pin       = BNRG_SPI_RESET_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_RESET_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_RESET_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_RESET_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_RESET_ALTERNATE;
    HAL_GPIO_Init (BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
    HAL_GPIO_WritePin (BNRG_SPI_RESET_PORT, BNRG_SPI_RESET_PIN, GPIO_PIN_RESET); // force RESET
	/* Added to avoid spurious interrupt from the BlueNRG */
#endif

        /* SCLK */
    GPIO_InitStruct.Pin       = BNRG_SPI_SCLK_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_SCLK_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_SCLK_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_SCLK_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_SCLK_ALTERNATE;
    HAL_GPIO_Init(BNRG_SPI_SCLK_PORT, &GPIO_InitStruct);

        /* MISO */
    GPIO_InitStruct.Pin       = BNRG_SPI_MISO_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_MISO_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_MISO_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_MISO_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_MISO_ALTERNATE;
    HAL_GPIO_Init(BNRG_SPI_MISO_PORT, &GPIO_InitStruct);

        /* MOSI */
    GPIO_InitStruct.Pin       = BNRG_SPI_MOSI_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_MOSI_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_MOSI_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_MOSI_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_MOSI_ALTERNATE;
    HAL_GPIO_Init(BNRG_SPI_MOSI_PORT, &GPIO_InitStruct);

#if WVD_SHUTOFF                              // 06/20/15 - debug L0 issues
        /* NSS/CSN/CS */
    GPIO_InitStruct.Pin       = BNRG_SPI_CS_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_CS_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_CS_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_CS_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_CS_ALTERNATE;
    HAL_GPIO_Init (BNRG_SPI_CS_PORT, &GPIO_InitStruct);
    HAL_GPIO_WritePin (BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_SET);  // De-Assert BLE CS

        /* IRQ -- INPUT */
    GPIO_InitStruct.Pin       = BNRG_SPI_IRQ_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_IRQ_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_IRQ_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_IRQ_SPEED;
#if defined(STM32F103xB)
#else
    GPIO_InitStruct.Alternate = BNRG_SPI_IRQ_ALTERNATE;
#endif
    HAL_GPIO_Init (BNRG_SPI_IRQ_PORT, &GPIO_InitStruct);

 #if L0_TESTING_MOVED     // 06/20/15
        /* Configure the NVIC for SPI */
    HAL_NVIC_SetPriority (BNRG_SPI_EXTI_IRQn, 4, 0);
    HAL_NVIC_EnableIRQ (BNRG_SPI_EXTI_IRQn);
 #endif
   }
#endif                              // WVD_SHUTOFF

}