BNRG2A1 Sample project fail to run. BLE_STATUS_TIMEOUT after hci_send_req command.
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;
}