diff --git a/Src/main.c b/Src/main.c index 61fa274..212b8ac 100644 --- a/Src/main.c +++ b/Src/main.c @@ -151,7 +151,7 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { - slcanFlushUSBBuffer(); +// slcanFlushUSBBuffer(); slCanCheckCommand(); if (canRxFlags.flags.byte != 0) { slcanReciveCanFrame(hcan.pRxMsg); diff --git a/Src/slcan/slcan.c b/Src/slcan/slcan.c index ce4bfe4..e358fe6 100644 --- a/Src/slcan/slcan.c +++ b/Src/slcan/slcan.c @@ -93,28 +93,28 @@ void slcanClose() state = STATE_CONFIG; } -int slcanFlushUSBBuffer() -{ - if (dataToSend != 0) - { - if (CDC_Transmit_FS(frameBuffer, dataToSend) == USBD_OK) - { - dataToSend = 0; - return 0; - } - } - return -1; -} - -static int addToUSBBuffer(uint8_t * pointer, uint8_t len) -{ - if ((dataToSend + len) >= FRAME_BUFFER_SIZE) - return -1; // buffer overflow - - memcpy(&frameBuffer[dataToSend], pointer, len); - dataToSend += len; - return 0; -} +//int slcanFlushUSBBuffer() +//{ +// if (dataToSend != 0) +// { +// if (CDC_Transmit_FS(frameBuffer, dataToSend) == USBD_OK) +// { +// dataToSend = 0; +// return 0; +// } +// } +// return -1; +//} +// +//static int addToUSBBuffer(uint8_t * pointer, uint8_t len) +//{ +// if ((dataToSend + len) >= FRAME_BUFFER_SIZE) +// return -1; // buffer overflow +// +// memcpy(&frameBuffer[dataToSend], pointer, len); +// dataToSend += len; +// return 0; +//} @@ -125,13 +125,10 @@ static void slcanOutputFlush(void) if (hUsbDeviceFS.dev_state != USBD_STATE_CONFIGURED) // use auxiliary uart only if usb not connected HAL_UART_Transmit(&huart2,sl_frame,sl_frame_len,100); //ll todo figure out time else { - addToUSBBuffer(sl_frame, sl_frame_len); -// while (CDC_Transmit_FS(sl_frame, sl_frame_len) != USBD_OK); -// while (((USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData)->TxState) -// { -// volatile i; -// i++; -// } +// addToUSBBuffer(sl_frame, sl_frame_len); + while (((USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData)->TxState){;} //should change by hardware + while (CDC_Transmit_FS(sl_frame, sl_frame_len) != USBD_OK); + } sl_frame_len = 0; } diff --git a/Src/slcan/slcan.h b/Src/slcan/slcan.h index f1d0d8d..c8b5745 100644 --- a/Src/slcan/slcan.h +++ b/Src/slcan/slcan.h @@ -15,7 +15,7 @@ #define VERSION_FIRMWARE_MAJOR 2 -#define VERSION_FIRMWARE_MINOR 2 +#define VERSION_FIRMWARE_MINOR 3 #define VERSION_HARDWARE_MAJOR 1 #define VERSION_HARDWARE_MINOR 1 @@ -33,7 +33,7 @@ //ex TZ12020506 void slcanClose(); -int slcanFlushUSBBuffer(); +//int slcanFlushUSBBuffer(); uint8_t slcanReciveCanFrame(CanRxMsgTypeDef *pRxMsg); int slCanProccesInput(uint8_t ch); void slCanCheckCommand(); diff --git a/Src/usbd_cdc_if.c b/Src/usbd_cdc_if.c index 53a1211..46a8328 100644 --- a/Src/usbd_cdc_if.c +++ b/Src/usbd_cdc_if.c @@ -71,8 +71,8 @@ /* USER CODE BEGIN PRIVATE_DEFINES */ /* Define size for the receive and transmit buffer over CDC */ /* It's up to user to redefine and/or remove those define */ -#define APP_RX_DATA_SIZE 32 -#define APP_TX_DATA_SIZE 32 +#define APP_RX_DATA_SIZE 128 +#define APP_TX_DATA_SIZE 128 /* USER CODE END PRIVATE_DEFINES */ /** * @} @@ -230,7 +230,7 @@ static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length) break; case CDC_SET_CONTROL_LINE_STATE: - slcanClose();//ll + slcanClose(); break; case CDC_SEND_BREAK: @@ -266,14 +266,11 @@ static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len) uint32_t i; for (i =0; i != *Len; i++) { - if (slCanProccesInput(Buf[i]) != 1) - { - USBD_CDC_ReceivePacket(&hUsbDeviceFS); - } + slCanProccesInput(Buf[i]); } USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); -// USBD_CDC_ReceivePacket(&hUsbDeviceFS); + USBD_CDC_ReceivePacket(&hUsbDeviceFS); return (USBD_OK); /* USER CODE END 6 */