cancel
Showing results for 
Search instead for 
Did you mean: 

B-L475E-IOT01A2 - When using the XCUBE-BLE2 pack it seems that MCU hangs when the code resets the BLE module during initialization

Dimitrios Bako
Associate II

Hello,

I use the B-L475E-IOT01A2 board and I try to integrate/experiment with the BLE module.

I created a new project using the STM32CubeIDE where I let the IDE apply the basic configuration for the board.

Then I select the BLE2 pack which I configure to use the SensorDemoBLESensor application.

In the Pinout & Configuration tab I apply the platform settings for the XCUBE BLE2 pack.

So far, the code is only what is generated by the IDE tool.

In other words, I have not intervened in the code yet.

When I flash the code the MCU seemed to hang.

So I started in debug mode and I found out that it hangs when the HCI_TL_RST_PIN is set with GPIO_PIN_SET value as seen in the following code block (line 8):

int32_t HCI_TL_SPI_Reset(void)
{
  // Deselect CS PIN for BlueNRG to avoid spurious commands
  HAL_GPIO_WritePin(HCI_TL_SPI_CS_PORT, HCI_TL_SPI_CS_PIN, GPIO_PIN_SET);
 
  HAL_GPIO_WritePin(HCI_TL_RST_PORT, HCI_TL_RST_PIN, GPIO_PIN_RESET);
  HAL_Delay(5);
  HAL_GPIO_WritePin(HCI_TL_RST_PORT, HCI_TL_RST_PIN, GPIO_PIN_SET);
  HAL_Delay(5);
  return 0;
}

This code block is from the hci_tl_interface.c file.

I believe that the project should work just fine since it is an example application automated by the tool to work with this particular board.

I also tried to comment out line 8 of the code above.

In this case the MCU did not hang but I got the following error in my serial terminal:

Read Static Random address failed.
Static Random address not well formed.

Debugging again I found that the problem is at the following code block in the hci_tl_interface.c file:

    /*
     * Wait until BlueNRG-2 is ready.
     * When ready it will raise the IRQ pin.
     */
    while(!IsDataAvailable())
    {
      if((HAL_GetTick() - tickstart_data_available) > TIMEOUT_DURATION)
      {
        result = -3;
        break;
      }
    }

A timeout happened since the BlueNRG was not ready.

Am I missing something?

Do I also have to intervene somehow on the board?

Any help would be appreciated!

Thank you!

1 REPLY 1
MOhamed_Mehery
Associate III

I understand your issue.

The error is caused by the fact that the BlueNRG module is not ready when the code tries to read the static random address. This can happen if the BlueNRG module is not properly reset.

To fix the issue, you need to make sure that the BlueNRG module is properly reset before you try to flash the code. You can do this by adding the following code to the beginning of the

main()

function:

Code snippet

// Reset the BlueNRG module

HAL_GPIO_WritePin(HCI_TL_RST_PORT, HCI_TL_RST_PIN, GPIO_PIN_RESET);

HAL_Delay(5);

HAL_GPIO_WritePin(HCI_TL_RST_PORT, HCI_TL_RST_PIN, GPIO_PIN_SET);

HAL_Delay(5);

Once you have added this code, you should be able to flash the code without any errors.

Here are some additional troubleshooting tips:

Make sure that the BlueNRG module is properly connected to the board.

Make sure that the BlueNRG module is properly powered.