DAVE Tip of the day: Things to do when use USBVC001 with RTOS?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
1) Check "Use RTOS" in USBLD001 UI
445.attach
2) Change the stack size to 2048 in RTOS001 RTX tab
443.attach
3) Place "USBVC001_Init()" inside the thread function
4) Add main USB management task "USB_USBTask()" right after the application tasks (eg. USBVC001_SendString((const char *)"Hello World" in the following example)

* Thread declaration */
void USB_Thread (void const *Argument);

int main(void)
{

DAVE_Init();

osThreadId ThreadId1;

/* Thread definition */
osThreadDef(USB_Thread, osPriorityNormal, 1, 0);
/* Thread creation */
ThreadId1 = osThreadCreate(osThread(USB_Thread),NULL);
if (ThreadId1 != NULL)
{
/* Start the OS kernel explicitly.*/
osKernelStart();
}
return 0;
}

void USB_Thread(void const *Argument)
{
uint16_t Bytes = 0;

/* Buffer to receive data */
int8_t RxBuffer[10] = { 0 };

USBVC001_Init();

while(1)
{
/* Check if bytes are received */
Bytes = USBVC001_BytesReceived();

if(Bytes)
{
/* Receive the byte */
USBVC001_ReceiveByte(&RxBuffer[0]);

/* Send the receive data back to the host */
USBVC001_SendString((const char *)"Hello World");
}

/* Main USB management task */
USB_USBTask();
...
}
0 Likes
1 Reply
Tobias_Gerber
Employee
Employee
It seems that in the USB_Thread() - while(1) loop, there shouldn't be RTOS calls like osDelay().
On the other side, USBVC001- send() or Receive() functions should be in this loop, Otherwise I see an unstable behavior. Maybe a Send/Receive (in other thread) crashes with USB_USBTask();

Does anybody has the same findings?
0 Likes