Skip to main content
SChen.22
Visitor II
December 16, 2022
Question

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

  • December 16, 2022
  • 7 replies
  • 5494 views

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;
}

This topic has been closed for replies.

7 replies

Senior
April 13, 2023

hi @SChen.22​ 

have you resolved the problem ?

i have the same problem with BlueNRG2N

Thank you

IVent.1
Senior
November 23, 2023

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

Senior
November 28, 2023

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 ?

 

Senior
November 28, 2023

the max SPI clock supported by the BlueNRG is 1MHz

in your case the clock is too high ! (160/64 = 2.5MHz)

Senior
November 28, 2023

malarab_0-1701185277286.png

check the config on the datasheet

IVent.1
Senior
November 28, 2023

could you send me a link to this datasheet?...thank you.

IVent.1
Senior
November 28, 2023

and also...I don't understand why I have to found that slave[0] must be 2....I looked for the protocol but I haven't found it.

Senior
November 28, 2023

After reset, the BlueNRG send to mcu [02,7F,00,00,00]

then it send  [02,7F,00,06,00]

Thats why you chould have 2 on slave[0]

Senior
November 28, 2023
IVent.1
Senior
November 30, 2023

any suggestion is welcome...