From d384fae9f472256b2b345e4809f25cd35a073e62 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 25 Jun 2016 10:06:29 +1000 Subject: [PATCH] Fix for needing to slow down serial in the CLI for F4 targets. Problem is with the CLI in configurator dropping packets. It is understood that too much processing occurs following each packet, and the receive buffer starts to drop packets in the configurator. Once the BF config is updated, this fix can be removed. --- src/main/drivers/serial_usb_vcp.c | 1 + src/main/io/serial_cli.c | 32 ++++++++++++++++++++++++++----- src/main/target/common.h | 5 +++++ src/main/vcpf4/usbd_cdc_vcp.c | 14 ++++++-------- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/main/drivers/serial_usb_vcp.c b/src/main/drivers/serial_usb_vcp.c index 5dc3ddb87..d4a25e693 100644 --- a/src/main/drivers/serial_usb_vcp.c +++ b/src/main/drivers/serial_usb_vcp.c @@ -117,6 +117,7 @@ static bool usbVcpFlush(vcpPort_t *port) if (count == 0) { return true; } + if (!usbIsConnected() || !usbIsConfigured()) { return false; } diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index d7279327f..04a0526de 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -1902,10 +1902,11 @@ static void dumpValues(uint16_t valueSection) cliPrintf("set %s = ", valueTable[i].name); cliPrintVar(value, 0); cliPrint("\r\n"); - -#ifdef STM32F4 + +#ifdef USE_SLOW_SERIAL_CLI delay(2); #endif + } } @@ -1979,6 +1980,9 @@ static void cliDump(char *cmdline) if (yaw < 0) cliWrite(' '); cliPrintf("%s\r\n", ftoa(yaw, buf)); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } #ifdef USE_SERVOS @@ -2000,6 +2004,10 @@ static void cliDump(char *cmdline) masterConfig.customServoMixer[i].max, masterConfig.customServoMixer[i].box ); + +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } #endif @@ -2012,12 +2020,18 @@ static void cliDump(char *cmdline) if (featureNames[i] == NULL) break; cliPrintf("feature -%s\r\n", featureNames[i]); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } for (i = 0; ; i++) { // reenable what we want. if (featureNames[i] == NULL) break; if (mask & (1 << i)) cliPrintf("feature %s\r\n", featureNames[i]); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } @@ -2077,6 +2091,9 @@ static void cliDump(char *cmdline) for (channel = 0; channel < INPUT_SOURCE_COUNT; channel++) { if (servoDirection(i, channel) < 0) { cliPrintf("smix reverse %d %d r\r\n", i , channel); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } } } @@ -2109,6 +2126,9 @@ static void cliDump(char *cmdline) changeControlRateProfile(currentRateIndex); cliRateProfile(""); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } cliPrint("\r\n# restore original profile selection\r\n"); @@ -2133,7 +2153,8 @@ static void cliDump(char *cmdline) } } -void cliDumpProfile(uint8_t profileIndex) { +void cliDumpProfile(uint8_t profileIndex) +{ if (profileIndex >= MAX_PROFILE_COUNT) // Faulty values return; @@ -2148,7 +2169,8 @@ void cliDumpProfile(uint8_t profileIndex) { cliRateProfile(""); } -void cliDumpRateProfile(uint8_t rateProfileIndex) { +void cliDumpRateProfile(uint8_t rateProfileIndex) +{ if (rateProfileIndex >= MAX_RATEPROFILES) // Faulty values return; @@ -2718,7 +2740,7 @@ static void cliSet(char *cmdline) cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui cliPrint("\r\n"); -#ifdef STM32F4 +#ifdef USE_SLOW_SERIAL_CLI delay(2); #endif } diff --git a/src/main/target/common.h b/src/main/target/common.h index a9d961e4d..9a8d6aede 100644 --- a/src/main/target/common.h +++ b/src/main/target/common.h @@ -18,11 +18,16 @@ #pragma once #ifdef STM32F4 + #define TASK_GYROPID_DESIRED_PERIOD 125 #define SCHEDULER_DELAY_LIMIT 10 +#define USE_SLOW_SERIAL_CLI + #else + #define TASK_GYROPID_DESIRED_PERIOD 1000 #define SCHEDULER_DELAY_LIMIT 100 + #endif #define SERIAL_RX diff --git a/src/main/vcpf4/usbd_cdc_vcp.c b/src/main/vcpf4/usbd_cdc_vcp.c index b42757adf..93ac1aaa5 100644 --- a/src/main/vcpf4/usbd_cdc_vcp.c +++ b/src/main/vcpf4/usbd_cdc_vcp.c @@ -153,12 +153,11 @@ static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len) *******************************************************************************/ uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) { - if(USB_Tx_State!=1) - { - VCP_DataTx(ptrBuffer,sendLength); - return sendLength; - } - return 0; + if (USB_Tx_State) + return 0; + + VCP_DataTx(ptrBuffer, sendLength); + return sendLength; } /** @@ -171,7 +170,6 @@ uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) */ static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len) { - uint16_t ptr = APP_Rx_ptr_in; uint32_t i; @@ -179,7 +177,7 @@ static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len) APP_Rx_Buffer[ptr++ & (APP_RX_DATA_SIZE-1)] = Buf[i]; APP_Rx_ptr_in = ptr % APP_RX_DATA_SIZE; - + return USBD_OK; }