This commit is contained in:
2024-02-02 04:09:57 +01:00
parent 43b177c468
commit a0c475f0d3

View File

@@ -1,19 +1,18 @@
#include "cmsis_os2.h" #include "cmsis_os2.h"
#include "usb_device.h" #include "usb_device.h"
#include <pb_decode.h> #include <pb_decode.h>
#include "firmware.pb.h" #include "firmware.pb.h"
#include "UsbDataHandler.h" #include "UsbDataHandler.h"
/* Define the task attributes */
#define TASK_STACK_SIZE 1024
#define TASK_PRIORITY osPriorityNormal
/* Declare the thread function */ /* Declare the thread function */
#define MAX_PACKET_SIZE 512-4 // Define your maximum packet size #define MAX_PACKET_SIZE 512-4 // Define your maximum packet size
#define NUM_BUFFERS 4 // Define the number of buffers you want to use #define NUM_BUFFERS 4 // Define the number of buffers you want to use
/* Define the task attributes */
#define TASK_STACK_SIZE 1024
#define TASK_PRIORITY osPriorityNormal
/* Declare static memory for the task */ /* Declare static memory for the task */
static uint32_t UsbDataHandler_TaskStack[TASK_STACK_SIZE]; static uint32_t UsbDataHandler_TaskStack[TASK_STACK_SIZE];
static const osThreadAttr_t UsbDataHandler_TaskAttr = { static const osThreadAttr_t UsbDataHandler_TaskAttr = {
@@ -134,6 +133,12 @@ USBD_StatusTypeDef UsbDataHandler_RxCallback(uint8_t* Buf, uint32_t Len) {
if (dataIndex == 4) { if (dataIndex == 4) {
/* Extract the packet length */ /* Extract the packet length */
packetLength = buffers[bufferIndex].pack.length; packetLength = buffers[bufferIndex].pack.length;
if (packetLength >= MAX_PACKET_SIZE ) {
dataIndex = 0;
packetLength = 0;
return USBD_FAIL;
}
} }
/* Check if we have received a full packet */ /* Check if we have received a full packet */
@@ -147,7 +152,6 @@ USBD_StatusTypeDef UsbDataHandler_RxCallback(uint8_t* Buf, uint32_t Len) {
packetLength = 0; packetLength = 0;
} }
} }
return USBD_OK; return USBD_OK;
} }