Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
lock attach
Attachments are accessible only for community members.
Not applicable
Hello,

I created a simple project that prints something to a usb serial terminal using USBD_VCOM.

If I put WFI into my main loop, it doesn't work. In fact, the USB device won't even enum.


#include //Declarations from DAVE3 Code Generation (includes SFR declaration)

int period = 100;
handle_t main_tmr;

//Write to Terminal
void write() {
char buffer[32];
sprintf(buffer, "Blah %d\r\n", period);
USBD_VCOM_SendString(buffer);
}

//Check for receive to make sure connection is established, then start write timer
void tick() {
if (USBD_VCOM_BytesReceived())
{
SYSTM001_StopTimer(main_tmr);
handle_t tmr = SYSTM001_CreateTimer(period, SYSTM001_PERIODIC, write, NULL);
SYSTM001_StartTimer(tmr);
}
}

int main(void)
{
DAVE_Init(); // Initialization of DAVE Apps
USBD_VCOM_Init();

//Start check timer
main_tmr = SYSTM001_CreateTimer(1000, SYSTM001_PERIODIC, tick, NULL);
SYSTM001_StartTimer(main_tmr);

while(1)
{
//Comment in to break USB
//asm("WFI");

}
return 0;
}



I've attached a simple demonstration app.

Can anyone reproduce this behaviour or suggest a solution?

Best,
Luke
0 Likes
2 Replies
Not applicable
Hi lerlacher,

In order for the USB VCOM to work, you need to keep running the CDC_Device_USBTask in the background.
So, if you put WFI in the while loop, basically the CPU will go into IDLE mode and all other USB tasks are not running.
This is also why the USB is not enumerated.
0 Likes
Not applicable
How are the USB tasks scheduled? Is there any kind of specification for how often they must be run? Could I do this from a timer interrupt?
0 Likes