asynchronous usb communication

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

asynchronous usb communication

Post by Pask »

hi, i am using usb shell implementation to get some string from board over usb. i would using asynchronous transfer from board to pc over usb because i do not want an excessive communication overhead. How can i do it?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: asynchronous usb communication

Post by Giovanni »

The SERIAL_USB driver used by the shell demo includes asynchronous read and write functions as well synchronous ones. Its interface is exactly the same of a normal serial driver.

Giovanni
Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

Re: asynchronous usb communication

Post by Pask »

what is demo shell project so i can see. Thanks

I'm seeing that to write is performed on a usb chprintf().
how can I distinguish from synchronous to asynchronous?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: asynchronous usb communication

Post by Giovanni »

Pask wrote:i am using usb shell implementation to get some string from board over usb


This is the shell demo.

Pask wrote:how can I distinguish from synchronous to asynchronous?


I/O functions with TIME_IMMEDIATE as timeout parameter are asynchronous.

Giovanni
Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

Re: asynchronous usb communication

Post by Pask »

where is timeout parameter? can you give me an example pls?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: asynchronous usb communication

Post by Giovanni »

Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

Re: asynchronous usb communication

Post by Pask »

but if I set time_immediate the operation stops immediately so the data when they are sent?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: asynchronous usb communication

Post by Giovanni »

The data is sent asynchronously like you asked.

BTW, there is no performance to be gained.

Giovanni
Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

Re: asynchronous usb communication

Post by Pask »

ok, but if i want to replace a shell command function with an asynchronous version of it how i can?
for example i have the following code:

Code: Select all


static const ShellCommand commands[] = {
  {"mem", cmd_mem},
  {"threads", cmd_threads},
  {"test", cmd_test},
  {"write", cmd_write},
  {NULL, NULL}
};

static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
  size_t n, size;

  (void)argv;
  if (argc > 0) {
    chprintf(chp, "Usage: mem\r\n");
    return;
  }
  n = chHeapStatus(NULL, &size);
  chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
  chprintf(chp, "heap fragments   : %u\r\n", n);
  chprintf(chp, "heap free total  : %u bytes\r\n", size);
}



can i replace BaseSequentialStream with BaseChannel type as required from chnWriteTimeout?
So i replace chprintf with chnWriteTimeout and that's it?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: asynchronous usb communication

Post by Giovanni »

I don't understand what you are trying to do, probably we give a different meaning to the term.

Giovanni
Post Reply