diff --git a/src/main/drivers/io.h b/src/main/drivers/io.h index debc78d950..121e7a0e1d 100644 --- a/src/main/drivers/io.h +++ b/src/main/drivers/io.h @@ -40,18 +40,21 @@ typedef uint8_t ioConfig_t; // packed IO configuration #define IO_CONFIG(mode, speed) ((mode) | (speed)) #define IOCFG_OUT_PP IO_CONFIG(GPIO_Mode_Out_PP, GPIO_Speed_2MHz) +#define IOCFG_OUT_PP_25 IO_CONFIG(GPIO_Mode_Out_PP, GPIO_Speed_25MHz) #define IOCFG_OUT_OD IO_CONFIG(GPIO_Mode_Out_OD, GPIO_Speed_2MHz) #define IOCFG_AF_PP IO_CONFIG(GPIO_Mode_AF_PP, GPIO_Speed_2MHz) #define IOCFG_AF_OD IO_CONFIG(GPIO_Mode_AF_OD, GPIO_Speed_2MHz) #define IOCFG_IPD IO_CONFIG(GPIO_Mode_IPD, GPIO_Speed_2MHz) #define IOCFG_IPU IO_CONFIG(GPIO_Mode_IPU, GPIO_Speed_2MHz) #define IOCFG_IN_FLOATING IO_CONFIG(GPIO_Mode_IN_FLOATING, GPIO_Speed_2MHz) +#define IOCFG_IPU_25 IO_CONFIG(GPIO_Mode_IPU, GPIO_Speed_25MHz) #elif defined(STM32F3) || defined(STM32F4) #define IO_CONFIG(mode, speed, otype, pupd) ((mode) | ((speed) << 2) | ((otype) << 4) | ((pupd) << 5)) #define IOCFG_OUT_PP IO_CONFIG(GPIO_Mode_OUT, 0, GPIO_OType_PP, GPIO_PuPd_NOPULL) // TODO +#define IOCFG_OUT_PP_25 IO_CONFIG(GPIO_Mode_OUT, GPIO_Speed_25MHz, GPIO_OType_PP, GPIO_PuPd_NOPULL) #define IOCFG_OUT_OD IO_CONFIG(GPIO_Mode_OUT, 0, GPIO_OType_OD, GPIO_PuPd_NOPULL) #define IOCFG_AF_PP IO_CONFIG(GPIO_Mode_AF, 0, GPIO_OType_PP, GPIO_PuPd_NOPULL) #define IOCFG_AF_PP_PD IO_CONFIG(GPIO_Mode_AF, 0, GPIO_OType_PP, GPIO_PuPd_DOWN) @@ -60,6 +63,7 @@ typedef uint8_t ioConfig_t; // packed IO configuration #define IOCFG_IPD IO_CONFIG(GPIO_Mode_IN, 0, 0, GPIO_PuPd_DOWN) #define IOCFG_IPU IO_CONFIG(GPIO_Mode_IN, 0, 0, GPIO_PuPd_UP) #define IOCFG_IN_FLOATING IO_CONFIG(GPIO_Mode_IN, 0, 0, GPIO_PuPd_NOPULL) +#define IOCFG_IPU_25 IO_CONFIG(GPIO_Mode_IN, GPIO_Speed_25MHz, 0, GPIO_PuPd_UP) #elif defined(UNIT_TEST) diff --git a/src/main/io/serial_4way.c b/src/main/io/serial_4way.c index 6d96a36ec1..49c5805417 100644 --- a/src/main/io/serial_4way.c +++ b/src/main/io/serial_4way.c @@ -44,15 +44,15 @@ #define USE_TXRX_LED #if defined(USE_TXRX_LED) && defined(LED0) -# define RX_LED_OFF LED0_OFF -# define RX_LED_ON LED0_ON -# ifdef LED1 -# define TX_LED_OFF LED1_OFF -# define TX_LED_ON LED1_ON -# else -# define TX_LED_OFF LED0_OFF -# define TX_LED_ON LED0_ON -# endif +#define RX_LED_OFF LED0_OFF +#define RX_LED_ON LED0_ON +#ifdef LED1 +#define TX_LED_OFF LED1_OFF +#define TX_LED_ON LED1_ON +#else +#define TX_LED_OFF LED0_OFF +#define TX_LED_ON LED0_ON +#endif #else # define RX_LED_OFF do {} while(0) # define RX_LED_ON do {} while(0) @@ -120,12 +120,12 @@ void setEscLo(uint8_t selEsc) void setEscInput(uint8_t selEsc) { - IOConfigGPIO(escHardware[selEsc].io, IOCFG_IPU); + IOConfigGPIO(escHardware[selEsc].io, IOCFG_IPU_25); } void setEscOutput(uint8_t selEsc) { - IOConfigGPIO(escHardware[selEsc].io, IOCFG_OUT_PP); + IOConfigGPIO(escHardware[selEsc].io, IOCFG_OUT_PP_25); } // Initialize 4way ESC interface @@ -330,6 +330,7 @@ void esc4wayProcess(serialPort_t *serial) while(!esc4wayExitRequested) { // restart looking for new sequence from host crcIn = 0; + uint8_t esc = readByteCrc(); if(esc != cmd_Local_Escape) continue; // wait for sync character @@ -348,7 +349,6 @@ void esc4wayProcess(serialPort_t *serial) paramBuf[i] = readByteCrc(); readByteCrc(); readByteCrc(); // update input CRC - RX_LED_OFF; outLen = 0; // output handling code will send single zero byte if necessary replyAck = esc4wayAck_OK; @@ -356,8 +356,10 @@ void esc4wayProcess(serialPort_t *serial) if(crcIn != 0) // CRC of correct message == 0 replyAck = esc4wayAck_I_INVALID_CRC; + TX_LED_ON; if (replyAck == esc4wayAck_OK) replyAck = esc4wayProcessCmd(command, addr, paramBuf, inLen, &outLen); + RX_LED_OFF; // send single '\0' byte is output when length is zero (len ==0 -> 256 bytes) if(!outLen) { @@ -366,14 +368,13 @@ void esc4wayProcess(serialPort_t *serial) } crcOut = 0; - TX_LED_ON; serialBeginWrite(port); writeByteCrc(cmd_Remote_Escape); writeByteCrc(command); writeByteCrc(addr >> 8); writeByteCrc(addr & 0xff); writeByteCrc(outLen & 0xff); // only low byte is send, 0x00 -> 256B - for(int i = 0; i < outLen; i++) + for(int i = 0; i < outLen % 0x100; i++) writeByteCrc(paramBuf[i]); writeByteCrc(replyAck); writeByte(crcOut >> 8); diff --git a/src/main/io/serial_4way_avrootloader.c b/src/main/io/serial_4way_avrootloader.c index efb4610268..01a598e8b2 100644 --- a/src/main/io/serial_4way_avrootloader.c +++ b/src/main/io/serial_4way_avrootloader.c @@ -238,7 +238,7 @@ void BL_SendCMDRunRestartBootloader(void) static uint8_t BL_SendCMDSetAddress(ioMem_t *pMem) //supports only 16 bit Adr { // skip if adr == 0xFFFF - if((pMem->addr == 0xffff)) + if(pMem->addr == 0xffff) return 1; uint8_t sCMD[] = {CMD_SET_ADDRESS, 0, pMem->addr >> 8, pMem->addr & 0xff }; BL_SendBuf(sCMD, sizeof(sCMD), true); diff --git a/src/main/vcpf4/usbd_cdc_vcp.c b/src/main/vcpf4/usbd_cdc_vcp.c index 93ac1aaa5c..8b789fa48f 100644 --- a/src/main/vcpf4/usbd_cdc_vcp.c +++ b/src/main/vcpf4/usbd_cdc_vcp.c @@ -170,20 +170,16 @@ 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; - - for (i = 0; i < Len; i++) - APP_Rx_Buffer[ptr++ & (APP_RX_DATA_SIZE-1)] = Buf[i]; - - APP_Rx_ptr_in = ptr % APP_RX_DATA_SIZE; - + for (uint32_t i = 0; i < Len; i++) { + APP_Rx_Buffer[APP_Rx_ptr_in] = Buf[i]; + APP_Rx_ptr_in = (APP_Rx_ptr_in + 1) % APP_RX_DATA_SIZE; + } return USBD_OK; } uint8_t usbAvailable(void) { - return (usbData.rxBufHead != usbData.rxBufTail); + return (usbData.bufferInPosition != usbData.bufferOutPosition); } /******************************************************************************* @@ -198,8 +194,8 @@ uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len) uint32_t ch = 0; while (usbAvailable() && ch < len) { - recvBuf[ch] = usbData.rxBuf[usbData.rxBufTail]; - usbData.rxBufTail = (usbData.rxBufTail + 1) % USB_RX_BUFSIZE; + recvBuf[ch] = usbData.buffer[usbData.bufferOutPosition]; + usbData.bufferOutPosition = (usbData.bufferOutPosition + 1) % USB_RX_BUFSIZE; ch++; receiveLength--; } @@ -222,20 +218,20 @@ uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len) * @param Len: Number of data received (in bytes) * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL */ +static uint32_t rxTotalBytes = 0; +static uint32_t rxPackets = 0; + static uint16_t VCP_DataRx(uint8_t* Buf, uint32_t Len) { - uint16_t ptr = usbData.rxBufHead; - uint32_t i; + rxPackets++; - for (i = 0; i < Len; i++) - usbData.rxBuf[ptr++ & (USB_RX_BUFSIZE-1)] = Buf[i]; + for (uint32_t i = 0; i < Len; i++) { + usbData.buffer[usbData.bufferInPosition] = Buf[i]; + usbData.bufferInPosition = (usbData.bufferInPosition + 1) % USB_RX_BUFSIZE; + receiveLength++; + rxTotalBytes++; + } - usbData.rxBufHead = ptr % USB_RX_BUFSIZE; - - receiveLength = ((usbData.rxBufHead - usbData.rxBufTail) > 0 ? - (usbData.rxBufHead - usbData.rxBufTail) : - (usbData.rxBufHead + USB_RX_BUFSIZE - usbData.rxBufTail)) % USB_RX_BUFSIZE; - if(receiveLength > (USB_RX_BUFSIZE-1)) return USBD_FAIL; diff --git a/src/main/vcpf4/usbd_cdc_vcp.h b/src/main/vcpf4/usbd_cdc_vcp.h index 3ca22aa4ef..df1e29001c 100644 --- a/src/main/vcpf4/usbd_cdc_vcp.h +++ b/src/main/vcpf4/usbd_cdc_vcp.h @@ -34,7 +34,7 @@ #include "usbd_usr.h" #include "usbd_desc.h" -#define USB_RX_BUFSIZE 1024 +#define USB_RX_BUFSIZE 2048 __ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END; @@ -71,9 +71,9 @@ typedef struct } LINE_CODING; typedef struct { - uint8_t rxBuf[USB_RX_BUFSIZE]; - uint16_t rxBufHead; - uint16_t rxBufTail; + uint8_t buffer[USB_RX_BUFSIZE]; + uint16_t bufferInPosition; + uint16_t bufferOutPosition; } usbStruct_t;