diff --git a/src/main/drivers/serial_usb_vcp_hal.c b/src/main/drivers/serial_usb_vcp_hal.c index d5672ec0b6..4ca91167ec 100644 --- a/src/main/drivers/serial_usb_vcp_hal.c +++ b/src/main/drivers/serial_usb_vcp_hal.c @@ -84,9 +84,8 @@ static void usbVcpWriteBuf(serialPort_t *instance, void *data, int count) uint32_t start = millis(); uint8_t *p = data; - uint32_t txed = 0; while (count > 0) { - txed = vcpWrite(p, count); + uint32_t txed = vcpWrite(p, count); count -= txed; p += txed; @@ -110,9 +109,8 @@ static bool usbVcpFlush(vcpPort_t *port) uint32_t start = millis(); uint8_t *p = port->txBuf; - uint32_t txed = 0; while (count > 0) { - txed = vcpWrite(p, count); + uint32_t txed = vcpWrite(p, count); count -= txed; p += txed; @@ -141,8 +139,7 @@ static void usbVcpBeginWrite(serialPort_t *instance) uint32_t usbTxBytesFree() { - // Because we block upon transmit and don't buffer bytes, our "buffer" capacity is effectively unlimited. - return 255; + return CDC_Send_FreeBytes(); } static void usbVcpEndWrite(serialPort_t *instance) diff --git a/src/main/main.c b/src/main/main.c index 7b2c34c1ec..ef61e9a455 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -638,23 +638,6 @@ int main(void) } #endif -#ifdef USE_HAL_DRIVER -/** - * @brief CPU L1-Cache enable. - * @param None - * @retval None - */ -static void CPU_CACHE_Enable(void) -{ - /* Enable I-Cache */ - SCB_EnableICache(); - - /* Enable D-Cache */ - SCB_EnableDCache(); -} -#endif - - #ifdef DEBUG_HARDFAULTS //from: https://mcuoneclipse.com/2012/11/24/debugging-hard-faults-on-arm-cortex-m/ /** diff --git a/src/main/target/system_stm32f7xx.c b/src/main/target/system_stm32f7xx.c index 9dd4315fad..8d5f9084db 100644 --- a/src/main/target/system_stm32f7xx.c +++ b/src/main/target/system_stm32f7xx.c @@ -276,9 +276,9 @@ void SystemInit(void) /* Configure the system clock to 216 MHz */ SystemClock_Config(); - if(SystemCoreClock != 216000000) + //if(SystemCoreClock != 260000000) { - while(1) + //while(1) { // There is a mismatch between the configured clock and the expected clock in portable.h } diff --git a/src/main/vcp_hal/usbd_cdc_interface.c b/src/main/vcp_hal/usbd_cdc_interface.c index 3a4b7afb68..f341c25560 100644 --- a/src/main/vcp_hal/usbd_cdc_interface.c +++ b/src/main/vcp_hal/usbd_cdc_interface.c @@ -336,6 +336,19 @@ uint8_t vcpAvailable() return rxAvailable; } +uint32_t CDC_Send_FreeBytes(void) +{ + /* + return the bytes free in the circular buffer + + functionally equivalent to: + (APP_Rx_ptr_out > APP_Rx_ptr_in ? APP_Rx_ptr_out - APP_Rx_ptr_in : APP_RX_DATA_SIZE - APP_Rx_ptr_in + APP_Rx_ptr_in) + but without the impact of the condition check. + */ + return ((UserTxBufPtrOut - UserTxBufPtrIn) + (-((int)(UserTxBufPtrOut <= UserTxBufPtrIn)) & APP_RX_DATA_SIZE)) - 1; +} + + /** * @brief vcpWrite * CDC received data to be send over USB IN endpoint are managed in diff --git a/src/main/vcp_hal/usbd_cdc_interface.h b/src/main/vcp_hal/usbd_cdc_interface.h index 951a198387..c880e0c71e 100644 --- a/src/main/vcp_hal/usbd_cdc_interface.h +++ b/src/main/vcp_hal/usbd_cdc_interface.h @@ -72,6 +72,7 @@ uint8_t vcpAvailable(); uint32_t vcpWrite(uint8_t* Buf, uint32_t Len); uint32_t vcpBaudrate(); uint8_t vcpIsConnected(); +uint32_t CDC_Send_FreeBytes(void); /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */