/************************************************************************* * @brief Activate internal bootloader using GPIO RESET pin. * * @param None * @retval None ************************************************************************/ void BlueNRG_HW_Bootloader (void) { set_irq_as_output(); BlueNRG_RST(); set_irq_as_input(); }
/** * @brief Wakeup BlueNRG * @param None * @retval None */ static void WakeupBlueNRG(void) { Disable_SPI_Receiving_Path(); pTimerTxRxCallback = TimerTransmitCallback; set_irq_as_output(); TIMER_Start(StartupTimerId, SPI_FIX_TIMEOUT); TIMER_Start(TxRxTimerId, SPI_FIX_TIMEOUT+SPI_TX_TIMEOUT); LPM_Mode_Request(eLPM_SPI_TX, eLPM_Mode_LP_Stop); return; }
/** * @brief Writes data from local buffer to SPI. * @param hspi : Handle of the STM32Cube HAL SPI interface * @param data1 : First data buffer to be written * @param data2 : Second data buffer to be written * @param Nb_bytes1: Size of first data buffer to be written * @param Nb_bytes2: Size of second data buffer to be written * @retval Number of read bytes */ int32_t BlueNRG_SPI_Write(SPI_HandleTypeDef * hspi, uint8_t * data1, uint8_t * data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2) { int32_t result = 0; int32_t spi_fix_enabled = 0; #ifdef ENABLE_SPI_FIX spi_fix_enabled = 1; #endif //ENABLE_SPI_FIX unsigned char header_master[HEADER_SIZE] = { 0x0a, 0x00, 0x00, 0x00, 0x00 }; unsigned char header_slave[HEADER_SIZE] = { 0xaa, 0x00, 0x00, 0x00, 0x00 }; unsigned char read_char_buf[MAX_BUFFER_SIZE]; Disable_SPI_IRQ(); /* If the SPI_FIX is enabled the IRQ is set in Output mode, then it is pulled high and, after a delay of at least 112us, the CS line is asserted and the header transmit/receive operations are started. After these transmit/receive operations the IRQ is reset in input mode. */ if (spi_fix_enabled) { set_irq_as_output(); /* Assert CS line after at least 112us */ us150Delay(); } /* CS reset */ HAL_GPIO_WritePin(BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_RESET); /* Exchange header */ HAL_SPI_TransmitReceive(hspi, header_master, header_slave, HEADER_SIZE, TIMEOUT_DURATION); if (spi_fix_enabled) { set_irq_as_input(); } if (header_slave[0] == 0x02) { /* SPI is ready */ if (header_slave[1] >= (Nb_bytes1 + Nb_bytes2)) { /* Buffer is big enough */ if (Nb_bytes1 > 0) { HAL_SPI_TransmitReceive(hspi, data1, read_char_buf, Nb_bytes1, TIMEOUT_DURATION); } if (Nb_bytes2 > 0) { HAL_SPI_TransmitReceive(hspi, data2, read_char_buf, Nb_bytes2, TIMEOUT_DURATION); } } else { /* Buffer is too small */ result = -2; } } else { /* SPI is not ready */ result = -1; } /* Release CS line */ HAL_GPIO_WritePin(BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_SET); Enable_SPI_IRQ(); return result; }
/******************************************************************************* * @brief Writes data from local buffer to SPI. * * @param hspi : Handle of the STM32Cube HAL SPI interface * @param data1 : First data buffer to be written * @param data2 : Second data buffer to be written * @param Nb_bytes1: Size of first data buffer to be written * @param Nb_bytes2: Size of second data buffer to be written * @retval Number of read bytes * * Called by: Hal_Write_Serial * * * _All_ those routines call this using a hardcoded pointer to &SpiHandle. * CALLERs: aci_write_hal_config -> hci_send_cmd -> hci_write -> Hal_Write_Serial() * aci_gatt_init -> hci_send_cmd -> hci_write -> Hal_Write_Serial() * aci_gap_init -> hci_send_cmd -> hci_write -> Hal_Write_Serial() *******************************************************************************/ int32_t BlueNRG_SPI_Write (SPI_HandleTypeDef *hspi, uint8_t* data1, uint8_t* data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2) { int32_t result = 0; int32_t spi_fix_enabled = 0; #ifdef ENABLE_SPI_FIX spi_fix_enabled = 1; #endif //ENABLE_SPI_FIX unsigned char header_master[HEADER_SIZE] = {0x0a, 0x00, 0x00, 0x00, 0x00}; unsigned char header_slave[HEADER_SIZE] = {0xaa, 0x00, 0x00, 0x00, 0x00}; unsigned char read_char_buf [MAX_BUFFER_SIZE]; Disable_SPI_IRQ(); /* ** If the SPI_FIX is enabled, the IRQ is set in Output mode, then it is pulled ** high and, after a delay of at least 112us, the CS line is asserted and the ** header transmit/receive operations are started. ** After these transmit/receive operations the IRQ is reset in input mode. */ if (spi_fix_enabled) { set_irq_as_output(); // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV // WVD ??? !!! CROSS_PLATFORM EXPOSURE - esp for FASTER DEVICES !!! ??? // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV /* Wait to Assert CS line until after at least 112us */ us150Delay(); } /* ASSERT CS line */ ////HAL_GPIO_WritePin (BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_RESET); ASSERT_CS_BlueNRG(); // Ensure CS is set to ACTIVE /* Exchange header with BlueNRG */ ////HAL_SPI_TransmitReceive (hspi, header_master, header_slave, HEADER_SIZE, TIMEOUT_DURATION); // WORKS spi_Write_Read (BLE_BLUENRG_SPI_ID, header_master, header_slave, HEADER_SIZE, 0); if (spi_fix_enabled) { set_irq_as_input(); } if (header_slave[0] == 0x02) { /* SPI is ready */ if (header_slave[1] >= (Nb_bytes1+Nb_bytes2)) { /* ensure Buffer is big enough */ if (Nb_bytes1 > 0) { //// HAL_SPI_TransmitReceive (hspi, data1, read_char_buf, Nb_bytes1, TIMEOUT_DURATION); spi_Write_Read (BLE_BLUENRG_SPI_ID, data1, read_char_buf, Nb_bytes1, 0); } if (Nb_bytes2 > 0) { //// HAL_SPI_TransmitReceive (hspi, data2, read_char_buf, Nb_bytes2, TIMEOUT_DURATION); spi_Write_Read (BLE_BLUENRG_SPI_ID, data2, read_char_buf, Nb_bytes2, 0); } } else { /* Buffer is too small */ result = -2; } } else { /* SPI is not ready */ result = -1; } /* Release CS line */ ////HAL_GPIO_WritePin (BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_SET); DEASSERT_CS_BlueNRG(); // Ensure CS is set to NOT active Enable_SPI_IRQ(); return result; }