cancel
Showing results for 
Search instead for 
Did you mean: 

BNRG2A1 Sample project fail to run. BLE_STATUS_TIMEOUT after hci_send_req command.

SChen.22
Associate

Paired the BNRG2A1 module with the STM32L476RG as recommended in the sample application. But when debugging I realised that the hciReadPktRxQueue is always empty leading to timeout.

I have made no modification to the sample application and even with the same hardware is unable to run the application. Any ideas on how to get it running?

This is the original hc_send_req that constantly timeout.

int hci_send_req(struct hci_request* r, BOOL async)
{
  uint8_t *ptr;
  uint16_t opcode = htobs(cmd_opcode_pack(r->ogf, r->ocf));
  hci_event_pckt *event_pckt;
  hci_spi_pckt *hci_hdr;
 
  tHciDataPacket * hciReadPacket = NULL;
  tListNode hciTempQueue;
  
  list_init_head(&hciTempQueue);
 
  free_event_list();
  
  send_cmd(r->ogf, r->ocf, r->clen, r->cparam);
  
  if (async)
  {
    return 0;
  }
  
  while (1) 
  {
    evt_cmd_complete  *cc;
    evt_cmd_status    *cs;
    evt_le_meta_event *me;
    uint32_t len;
    
    uint32_t tickstart = HAL_GetTick();
      
    while (1)
    {
      if ((HAL_GetTick() - tickstart) > HCI_DEFAULT_TIMEOUT_MS)
      {
        goto failed;
      }
      
      if (!list_is_empty(&hciReadPktRxQueue)) 
      {
        break;
      }
    }
    
    /* Extract packet from HCI event queue. */
    list_remove_head(&hciReadPktRxQueue, (tListNode **)&hciReadPacket);    
    
    hci_hdr = (void *)hciReadPacket->dataBuff;
 
    if (hci_hdr->type == HCI_EVENT_PKT)
    {
      event_pckt = (void *)(hci_hdr->data);
    
      ptr = hciReadPacket->dataBuff + (1 + HCI_EVENT_HDR_SIZE);
      len = hciReadPacket->data_len - (1 + HCI_EVENT_HDR_SIZE);
    
      switch (event_pckt->evt) 
      {      
      case EVT_CMD_STATUS:
        cs = (void *) ptr;
        
        if (cs->opcode != opcode)
          goto failed;
        
        if (r->event != EVT_CMD_STATUS) {
          if (cs->status) {
            goto failed;
          }
          break;
        }
 
        r->rlen = MIN(len, r->rlen);
        BLUENRG_memcpy(r->rparam, ptr, r->rlen);
        goto done;
      
      case EVT_CMD_COMPLETE:
        cc = (void *) ptr;
      
        if (cc->opcode != opcode)
          goto failed;
      
        ptr += EVT_CMD_COMPLETE_SIZE;
        len -= EVT_CMD_COMPLETE_SIZE;
      
        r->rlen = MIN(len, r->rlen);
        BLUENRG_memcpy(r->rparam, ptr, r->rlen);
        goto done;
      
      case EVT_LE_META_EVENT:
        me = (void *) ptr;
      
        if (me->subevent != r->event)
          break;
      
        len -= 1;
        r->rlen = MIN(len, r->rlen);
        BLUENRG_memcpy(r->rparam, me->data, r->rlen);
        goto done;
      
      case EVT_HARDWARE_ERROR:            
        goto failed;
      
      default:      
        break;
      }
    }
    
    /* If there are no more packets to be processed, be sure there is at list one
       packet in the pool to process the expected event.
       If no free packets are available, discard the processed event and insert it
       into the pool. */
    if (list_is_empty(&hciReadPktPool) && list_is_empty(&hciReadPktRxQueue)) {
      list_insert_tail(&hciReadPktPool, (tListNode *)hciReadPacket);
      hciReadPacket=NULL;
    }
    else {
      /* Insert the packet in a different queue. These packets will be
      inserted back in the main queue just before exiting from send_req(), so that
      these events can be processed by the application.
    */
    list_insert_tail(&hciTempQueue, (tListNode *)hciReadPacket);
      hciReadPacket=NULL;
    }
  }
  
failed: 
  if (hciReadPacket!=NULL) {
    list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket);
  }
  move_list(&hciReadPktRxQueue, &hciTempQueue);
 
  return -1;
  
done:
  /* Insert the packet back into the pool.*/
  list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); 
  move_list(&hciReadPktRxQueue, &hciTempQueue);
 
  return 0;
}

27 REPLIES 27
malarab
Senior II

hi @SChen.22​ 

have you resolved the problem ?

i have the same problem with BlueNRG2N

Thank you

Hallo, have you solved the problem?...I'm facing with it.

hi @IVent.1 

in my case it was a hardware problem.

i have designed my own PCB and they was a problem in the self value for SMPS.

so the chip was not supplied correctly (the internal regulator was not able to generate VDD1V2)

by changing the value of the self between pin 26 and 27 the problem was resolved.

in your case, witch hardware do you use ?

 

I'm using Nucleo stm32u575. I have checked...and miso, mosi, clk is arriving to the board of the bluenrg2a1. But when I'm doing the first requests, the interrupt from the bluenrg never trigger. in hci_tl_lowlevel_init, I'vwe written:

HAL_EXTI_GetHandle(&hexti0, EXTI_LINE_0);
HAL_EXTI_RegisterCallback(&hexti0, HAL_EXTI_COMMON_CB_ID, hci_tl_lowlevel_isr);
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);

 

and in int32_t HCI_TL_SPI_Init(void* pConf)

/*Configure EXTI Line */
GPIO_InitStruct.Pin = HCI_TL_SPI_EXTI_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(HCI_TL_SPI_EXTI_PORT, &GPIO_InitStruct);

 

What is the power configuration ? (DC-DC converter is active or not ?)

How DIO12 (pin 29) is set ?

what is the state of SWO and SWCLK pin ? these 2 pin should not be set to not enter in BOOT mode

I've checked with an oscilloscope and the interrupt from the bluenrg arrives phisically to the cn8 of the nucleo, but the interrupt doesn't rise in my firmware...so I think that the power of the board is set correctly and the bluenrg is not in boot mode.

to have a double check,

check if you receive the initialisation frame on MISO after the hard reset of the BlueNRG (or soft reset)

 

if you have detect the interruption on the oscilloscope, it is maybe a connection problem between the blue NRG and the mcu. or a wrong soft configuration (you configure the wrong pin !)

whitch pin do you use ?i dont know about stm32u575, but maybe any SB should be configured to have the correct connection ?

 

check GPIO registers on debug mode to check if the pin is configured correctly.

the pin is the correct one...without the bluenrg inserted, if I use this pin as an output, I can set or reset it.

try to set a breakpoint in the IRQ Handler to be sure if the interruption is received.

the problem is maybe in the HAL Callback (i dont use it so i am not sure how to set it)

you can try this code (to be adapted with your mcu ref)

 

void EXTI0_IRQHandler(void)
{
if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_0) != RESET)
{
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_0);
hci_tl_lowlevel_isr();
}
}