I'm trying to modify the usbLinkTask and create a custom parsing function for incoming USB packets so that I can control the Crazyflie solely using USB.
Originally I had modified sysLinkTask to read from USB instead of from the radio chip UART, like this:
Code: Select all
/* Syslink task, handles communication between nrf and stm and dispatch messages
*/
static USBPacket usbIn;
static void syslinkTask(void *param) {
SyslinkPacket slp;
while (1) {
/*ORIGINAL
//get an incoming radio packet (blocking fxn), read it into slp
uartslkGetPacketBlocking(&slp);
syslinkRouteIncommingPacket(&slp);
*/
//MY VERSION
usbGetDataBlocking(&usbIn);
if (!usbSlkParseIncomingPacket(&slp) {
//incoming packet is now in slp
//route the packet to the appropriate location
syslinkRouteIncommingPacket(&slp);
}
else {
//DEBUG_PRINT something
}
}
}
I want to keep the original syslink, though, and just modify the usbLinkTask to accept my control packets. But I'm running into a problem.
This is what I'm trying to do in usbLinkTask:
Code: Select all
static USBPacket usbIn;
//static CRTPPacket p;
static void usblinkTask(void *param) {
SyslinkPacket slp;
while (1) {
/*
//ORIGINAL
// Fetch a USB packet off the queue
usbGetDataBlocking(&usbIn);
p.size = usbIn.size - 1;
memcpy(&p.raw, usbIn.data, usbIn.size);
// This queuing will copy a CRTP packet size from usbIn
ASSERT(xQueueSend(crtpPacketDelivery, &p, 0) == pdTRUE);
DEBUG_PRINT("Got some USB data\n");*/
//MY VERSION
usbGetDataBlocking(&usbIn);
//DEBUG_PRINT("USB data read in successfully\n");
//DEBUG_PRINT("Read in data %c, now sending...\n", usbIn.data[0]);
//data[0] = 0x30;
//usbSendData(1, data);
//DEBUG_PRINT("USB send complete\n");
//if the packet looks valid
if (!usbslkParseIncomingPacket(&slp)) {
//incoming packet is now in slp
//DEBUG_PRINT("Parsed USB successfully, routing...\n");
//route the packet to the appropriate location
usblinkRouteIncomingPacket(&slp);
}
//otherwise the parsing found invalidity, ignore this pkt and get the next incoming USB packet
else {
DEBUG_PRINT("syslinkTask: parse failed, not routing the packet\n");
}
}
}
If I then comment out the line "usblinkRouteIncomingPacket(&slp);" as well, I get this: https://drive.google.com/file/d/1Tuazq7 ... sp=sharing, which is showing queue inexistent from within an ISR. So I'm guessing it has something to do with one of the functions in usb.c: either usbd_cf_DataIn() or usbd_cf_SOF()...any ideas?
I do see that usblinkTask is by default set up to create CRTP packets from the incoming USB data, but let's say I wanted to change the protocol of the packets and set up my own parser.
Thanks a lot!