diff --git a/arch/arm/src/stm32/stm32_hciuart.c b/arch/arm/src/stm32/stm32_hciuart.c index f27e367cfd6..d8ae5c9b06a 100644 --- a/arch/arm/src/stm32/stm32_hciuart.c +++ b/arch/arm/src/stm32/stm32_hciuart.c @@ -1154,7 +1154,7 @@ static ssize_t hciuart_copytorxbuffer(const struct hciuart_config_s *config) nxsem_post(&state->rxwait); } - wlinfo("nbytes %ld\n", (long)nbytes); + wlinfo("rxhead %u rxtail %u nbytes %ld\n", rxhead, rxtail, (long)nbytes); return nbytes; } @@ -1171,7 +1171,7 @@ static ssize_t hciuart_copyfromrxbuffer(const struct hciuart_config_s *config, uint8_t *dest, size_t destlen) { struct hciuart_state_s *state; - ssize_t nbytes = 0; + ssize_t nbytes; uint16_t rxhead; uint16_t rxtail; uint8_t rxbyte; @@ -1181,20 +1181,14 @@ static ssize_t hciuart_copyfromrxbuffer(const struct hciuart_config_s *config, state = config->state; rxhead = state->rxhead; rxtail = state->rxtail; + nbytes = 0; - /* Is there data available in the Rx FIFO? */ + /* Is there data available in the Rx buffer? Is there space in the user + * buffer? + */ - while ((hciuart_getreg32(config, STM32_USART_SR_OFFSET) & USART_SR_RXNE) != 0) + while (rxhead != rxtail && nbytes < destlen) { - /* Is the Rx buffer empty? Is there space in the user buffer? */ - - if (rxhead == rxtail && nbytes < destlen) - { - /* Yes, stop the copy and update the indices */ - - break; - } - /* Get a byte from the head of the Rx buffer */ rxbyte = config->rxbuffer[rxhead]; @@ -1202,6 +1196,9 @@ static ssize_t hciuart_copyfromrxbuffer(const struct hciuart_config_s *config, /* And add it to the caller's buffer buffer */ dest[nbytes] = rxbyte; + + /* Update indices and counts */ + nbytes++; if (++rxhead >= config->rxbufsize) @@ -1218,7 +1215,7 @@ static ssize_t hciuart_copyfromrxbuffer(const struct hciuart_config_s *config, state->rxhead = rxhead; - wlinfo("nbytes %ld\n", (long)nbytes); + wlinfo("rxhead %u rxtail %u nbytes %ld\n", rxhead, rxtail, (long)nbytes); return nbytes; } diff --git a/configs/stm32f4discovery/hciuart/defconfig b/configs/stm32f4discovery/hciuart/defconfig index 033acfb1140..c4af81370e5 100644 --- a/configs/stm32f4discovery/hciuart/defconfig +++ b/configs/stm32f4discovery/hciuart/defconfig @@ -12,6 +12,7 @@ CONFIG_ARCH_BOARD="stm32f4discovery" CONFIG_ARCH_BUTTONS=y CONFIG_ARCH_CHIP_STM32=y CONFIG_ARCH_CHIP_STM32F407VG=y +CONFIG_ARCH_INTERRUPTSTACK=2048 CONFIG_ARCH_STACKDUMP=y CONFIG_ARCH="arm" CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y @@ -65,7 +66,6 @@ CONFIG_RAM_SIZE=114688 CONFIG_RAM_START=0x20000000 CONFIG_RAW_BINARY=y CONFIG_RR_INTERVAL=200 -CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_WAITPID=y CONFIG_SDCLONE_DISABLE=y diff --git a/drivers/wireless/bluetooth/bt_uart.c b/drivers/wireless/bluetooth/bt_uart.c index b6f37a51ca6..1d9c203223c 100644 --- a/drivers/wireless/bluetooth/bt_uart.c +++ b/drivers/wireless/bluetooth/bt_uart.c @@ -212,6 +212,7 @@ static FAR struct bt_buf_s *btuart_acl_recv(FAR struct btuart_upperhalf_s *upper static void btuart_rxwork(FAR void *arg) { FAR struct btuart_upperhalf_s *upper; + FAR const struct btuart_lowerhalf_s *lower; static FAR struct bt_buf_s *buf; static unsigned int hdrlen; static int remaining; @@ -219,7 +220,8 @@ static void btuart_rxwork(FAR void *arg) uint8_t type; upper = (FAR struct btuart_upperhalf_s *)arg; - DEBUGASSERT(upper != NULL); + DEBUGASSERT(upper != NULL && upper->lower != NULL); + lower = upper->lower; /* Beginning of a new packet. Read the first byte to get the packet type. */ @@ -251,8 +253,7 @@ static void btuart_rxwork(FAR void *arg) if (buf == NULL) { - FAR const struct btuart_lowerhalf_s *lower = upper->lower; - DEBUGASSERT(lower != NULL); + /* Failed to allocate a buffer. Drain the Rx data and fail the read. */ nread = lower->rxdrain(lower); wlwarn("WARNING: Discarded %ld bytes\n", (long)nread); @@ -276,9 +277,15 @@ static void btuart_rxwork(FAR void *arg) remaining -= nread; } + wlinfo("Full packet received\n"); + + /* Drain any un-read bytes from the Rx buffer */ + + nread = lower->rxdrain(lower); + wlwarn("WARNING: Discarded %ld bytes\n", (long)nread); + /* Pass buffer to the stack */ - wlinfo("Full packet received\n"); upper->busy = false; bt_hci_receive(buf); return;