Page 1 of 1

USB-CDC raw communication

Posted: Mon Oct 21, 2013 5:23 pm
by rubenswerk
Hello,

I would like to use the USB-CDC on an STM32F4 to do some data transmission.
Most demos use a test suite or shell with chprintf to show if it works.
The demonstrator shell works fine.

But I'd like to do some raw read/write access, first of all a simple echo application, returning all data which was received via USB-CDC.
Analysing the shell and test suites, I think chSequentialStreamWrite and chSequentialStreamRead would be the correct interfaces for what I want to do, bit I'm not sure about that. Are these functions a good choice?

If so, the the first step for my echo application would be to check if there's data available using chSequentialStreamRead, and then transmitting the received buffer with chSequentialStreamWrite. This could be done in an low priority thread infinite loop.
A better choice would be callback functions when reception/transmission is over, but I haven't seen how to do that. Is it possible?

Before I go into a wrong direction, do you think have I decided to use the correct functions?

Thank you!
Ruwe


By the way, in ARMCM4-STM32F407-LWIP-FATFS-USB / mcuconf.h there a two things I wonder about:
1. The section 'MAC driver system settings' exists twice with the same defines
2. Are there two OTG devies in the F4, and if so, are both of them used for the demo? From my understanding, it uses only one device mode.
#define STM32_USB_USE_OTG1 TRUE
#define STM32_USB_USE_OTG2 TRUE

Re: USB-CDC raw communication

Posted: Mon Oct 21, 2013 6:44 pm
by Giovanni
Hi,

The functions are the correct ones, there are also variants with timeouts.

The USB driver itself is based on callbacks, the serial_usb module translates the callbacks in those streams, this module is also the example you need in order to use callbacks. There are few functions involved that start an asynchronous transfer terminated with a callback.

Giovanni

Re: USB-CDC raw communication

Posted: Tue Oct 22, 2013 11:53 pm
by rubenswerk
Ok, thanks...
The readme.txt of ARMCM4-STM32F407-DISCOVERY-G++ demo says that it provides an USB-CDC, but in fact it doesn't. Maybe this comment should be removed.

However, now I'm using the ARMCM4-STM32F407-DISCOVERY-MEMS demo and removed the shell stuff.
Inside the main loop, this works fine:

chThdSleepMilliseconds(500);
chnWrite(&SDU1, "Hello World ", 12);

But I'm not able to receive/echo data - nothing happens:
i = chnRead(&SDU1, buf, 64);
if (i > 0)
{
i = chnWrite(&SDU1, buf, i);
}

What's wrong about that?
Buonanotte

Re: USB-CDC raw communication

Posted: Wed Oct 23, 2013 7:51 am
by Giovanni
Hard to tell, is the USB enumerated? is a terminal software running in the moment the string is printed?

I would look into this kind of details.

Giovanni