Interfacing with the X-NUCLEO-BNRG2A1 (BlueNRG-2)
Hi,
I picked up a X-NUCLEO-BNRG2A1 (Extension board Lot:2040 for the Nucleo-64 boards), and I am trying to communicate with it through a Nucleo-F411RE Board. I basically generated a project template through CubeMX for the STM32F411RE and included the BlueNRG-2 (X-CUBE-BLE2) Pack to include Bluetooth HCL/ACI APIs along with the project template.
I also assigned in CubeMX (in the Software Packs section) that I will be using SPI1 bus, GPIOB Pin 14 for the SPI EXTI Pin, GPIOA Pin 1 for the SPI1 CS pin, and GPIOA Pin 8 for the HCI_TL_RST Reset Pin.
I also configured the SPI1 bus to be Full Duplex Master, Prescaler = 128 (to obtain 781.25KBit/s baud rate), CPOL Low, and CPHA = 2 Edge (based on the configurations found in an example project under X-CUBE-BLE2\3.2.0\Projects\NUCLEO-L476RG\Applications\SampleApp).
In case this information is needed, these solder bridges are connected:
- R117
- R82 (hence using PB14 for the SPI_IRQ Pin)
- R85 seems to be connected too (so I assume it should be fine using either PB14 or PA0 for the SPI_IRQ Pin)
- R76
I am using Page 31 of this Programming Guideline as a reference, and that SampleApp project as a reference to Initialize the device, and to Setup the Device Address. I basically call the two functions hci_init(APP_UserEvtRx, NULL); and Setup_DeviceAddress(); (the first function can be found under hci_tl.c, and the second function can be found under app_bluenrg_2.c. I ported the functions Setup_DeviceAddress() and APP_UserEvtRx() to successfully execute these functions).
My project never seems to successfully execute Startup_DeviceAddress() as it seems to not be able to communicate with the BlueNRG-2 module through SPI during these two instances:
/* get a random number from BlueNRG */
ret = hci_le_rand(random_number);
ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr);I scoped the SPI1 bus that should have exchanged data with the BlueNRG-2 and observed that only the CS lines were pulled low and then high immediately, without the STM32F411RE Nucleo toggling the SPI_SCK or SPI_MOSI (no data was sent through the SPI1 bus and the STM32F411RE immediately disabled the SPI1 communication).
Through breakpoints, I find that at HCI_TL_SPI_Send() function (found under hci_tl_interface.c), the code always fail at this block:
while(!IsDataAvailable())
{
if((HAL_GetTick() - tickstart_data_available) > TIMEOUT_DURATION)
{
result = -3;
break;
}
}
if(result == -3)
{
/* The break causes the exiting from the "while", so the CS line must be released */
HAL_GPIO_WritePin(HCI_TL_SPI_CS_PORT, HCI_TL_SPI_CS_PIN, GPIO_PIN_SET);
break;
}I concluded this because 'result' returns -3 at the end of this function, and the lines after this block of code does not get executed. This would mean that the SPI_IRQ interrupt never fired from the BlueNRG-2 Module based on the comments of the code generated by CubeMX (I tried using both PA0 and PB14 for the code and they both yield the same results).
Why is it that my BlueNRG-2 (X-NUCLEO-BNRG2A1) fails to produce an interrupt at that point? I don't think there's anything wrong with HAL_GetTick() too as I did not change the code. There was a part of the code I commented out in hci_init() that resets the BlueNRG-2 (toggles the PA8 line) too, as I noticed that after the PA8 line goes high, the whole device seems to stop working. I previously would connect the PA8 line to the RESET pin in the J12 bridge of the X-NUCLEO-BNRG2A1. I assumed that ignoring that operation would be fine for the board.
I also saw that you can flash firmware onto the X-NUCLEO-BNRG2A1 based on the Erratum Sheet here. Is this a process that needs to be done before playing with the X-NUCLEO-BNRG2A1? What is the purpose of using the STSW-BNRGFLASHER to update the firmware on the board?
Any help would be greatly appreciated. Thank you!
UPDATE:
I just got a ST-Link/V2 connector and I am trying to flash DTM_SPI.hex firmware found under BlueNRG GUI 4.0.0/Firmware/BlueNRG2/DTM. When trying to flash the firmware, the ST-Link/V2 failed to connect to the device (although the SWD interfaces is listed as connected in the BlueNRG-X Flasher Utility.
I tried disconnecting the jumper J10 and use a multimeter across the J10 pins and measured almost 0.4V. Does this mean that the X-NUCLEO-BNRG2A1 isn't getting the voltage it needs to power on? However, I also tried connecting an LED across between the 5V/3V3 pins and the GND pins in CN6 and the LED seems to light up. I also used the multimeter to scope the 5V and 3V3 pins and can verify that both pins are at 5V and 3.3V respectively.
