<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックRe: USB HID generic example questions</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584080#M20978</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by emanuelj on Wed Oct 08 10:17:42 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your great answer, now I got it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've implemented all my ideas and it's all working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On the device-side I've converted the incoming report to a char[] via typecast:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;static uint8_t *incoming_report;
static uint8_t *outgoing_report;
#define REPORT_SIZE 16
unsigned char buffer[REPORT_SIZE];
unsigned char message[REPORT_SIZE];

...

USBD_API-&amp;gt;hw-&amp;gt;ReadEP(hUsb, pHidCtrl-&amp;gt;epout_adr, incoming_report);

for (i=0; i&amp;lt;= REPORT_SIZE; i++)
{
buffer&lt;I&gt; = (unsigned char)(*(incoming_report+i));
}

//Do something ...

sprintf((char *)message, "value: %d", value);
outgoing_report = &amp;amp;message[0];


USBD_API-&amp;gt;hw-&amp;gt;WriteEP(hUsb, pHidCtrl-&amp;gt;epin_adr, outgoing_report, REPORT_SIZE);

...&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;maybe not the most elegant method but it's perfectly working &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Emanuel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 20:23:27 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T20:23:27Z</dc:date>
    <item>
      <title>USB HID generic example questions</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584076#M20974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by emanuelj on Fri Oct 03 02:00:23 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a beginner in USB-programming and have some questions about USB-communication.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using the usbd_lib_hid_generic-example (lpcopen v2.10) with the LPC1769 microcontroller and would like to make it communicating with a host-pc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It already works fine, but what I don't understand is that I get an error when I want to send less (and more) than 8 bytes (which I configured in hid_desc.c) from PC to the device.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;hid_desc.c is configured as it follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#define HID_INPUT_REPORT_BYTES&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/* size of report in Bytes */
#define HID_OUTPUT_REPORT_BYTES&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/* size of report in Bytes */
#define HID_FEATURE_REPORT_BYTES&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/* size of report in Bytes */&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Means this that I have to transmit 8 bytes, no more, no less, to the device?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Would it be possible to change the code that this is only the MAXIMUM number of bytes, so that I can transmit less than 8 bytes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Furthermore I don't know what FEATURE_REPORT means. Whats the purpose of a feature-report?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your answers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Emanuel&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:23:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584076#M20974</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: USB HID generic example questions</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584077#M20975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mch0 on Fri Oct 03 09:23:36 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;yes, 8 means 8 in this case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You may define more than one report of each type and these can then have different length, say three OUT reports with the first having 4 bytes, the second 7 and the third 17.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you can choose which report and hence the number of bytes yo want to send.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, according to the standard, you are still restricted to the set of discrete numbers you have specified.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Unless you know what you are doing (more than one report of a type involves an additional ID byte) I recommend you simply define a MAX number and pad reports on the host side and discard those bytes on the device side and vice versa.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A feature report is transferred via EP0 and uses control transfers, whereas the other two are transferred via the specified EPs and use interrupt transfers. Again I'd say for a starter use IN/OUT. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The only exception is, when you request some specific information from a device out of several choices. Then you must use feature reports, because with IN reports the device decides what to send.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, I recommend reading some small tutorial on HID devices, there are lots of them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:23:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584077#M20975</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: USB HID generic example questions</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584078#M20976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by emanuelj on Sat Oct 04 12:56:39 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok, thank you for your reply! I understand.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I want transmit a string, but the type of the report (which is *uint8) is therefore inappropriate. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;An example string (from PC-&amp;gt;device) consists out of 3 letters, a colon and a 3-digit number&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Example-format: "XXX:000"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The device should interpret the message and answer for instance with an acknowlegde, which could have the form "ACK"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What's the easiest way doing this? With an *uint8 format this is very awkward.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another problem in my case is the WriteEP() function. I can only call the function in HID_Ep_Hdlr() because of the set of parameters. How can I achieve a WriteEP()-function which may be called from everywhere in my program? Best would be a WriteEP(char message[len]) function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sry for my (probably stupid) questions, but I'ts the first time I've ever programmed with USB and with such a big library.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your replies!&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:23:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584078#M20976</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: USB HID generic example questions</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584079#M20977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mch0 on Sun Oct 05 03:33:48 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't give a tutorial on HID or C, but I'll try to give you a starter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;uint8_t *:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is actually a perfect fit for the generic reports.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;These are almost always defined as an array of n bytes (see report descriptor) and the uint8_t-pointer just points to the start of the report you want to receive (OUT) or send (IN).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Within the device you might then allocate two static arrays like &lt;/SPAN&gt;&lt;I&gt;uint8_t outreport[8]&lt;/I&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;I&gt;uint8_t inreport[4]&lt;/I&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The host sends an OUT-report with 8 bytes (uint8_t), 7 bytes as defined by your format and a terminating 0 for convenience.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;On the host side this could look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;char buffer[8];&lt;BR /&gt;sprintf(buffer,"%03d:%03d",num1,num2);&lt;BR /&gt;hid_write(buffer);&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then these 8 bytes arrive at the device and are (see later) available in the buffer outreport.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On the device side you retrieve them like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;if (2== sscanf((char*)outbuffer,"%d:%d",&amp;amp;num1,&amp;amp;num2))&lt;BR /&gt;{ &lt;BR /&gt;&amp;nbsp;&amp;nbsp; // got them&lt;BR /&gt;&amp;nbsp; ...&lt;BR /&gt;}&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Likewise for the answer you &lt;/SPAN&gt;&lt;I&gt;sprintf()&lt;/I&gt;&lt;SPAN&gt; on the device side into the inbuffer and &lt;/SPAN&gt;&lt;I&gt;sscanf()&lt;/I&gt;&lt;SPAN&gt; on the host side.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If your host program is compiled on a windows system make sure that you use ASCII-chars (bytes), not the native WCHAR type (16 bit).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You see, nothing arkward at all, just typecast the uint8_t-pointer to let it point to the type you need.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;USB stack usage:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The NXP ROM stack could have been documented a little bit better, but for a simple HID device it's very easy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The most important thing is to get used to callback functions. The device can NEVER EVER initiate any data transfer, it just can react to events.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So when something happens to an endpoint because THE HOST has done something your program is interrupted, the stack decodes the event and calls the endpoint handler.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here this is &lt;/SPAN&gt;&lt;I&gt;HID_Ep_Hdlr()&lt;/I&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You can then look at the event (3rd param) and take actions as appropriate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Commonly you would react to these events:&lt;/SPAN&gt;&lt;BR /&gt;&lt;I&gt;USB_EVT_IN&lt;/I&gt;&lt;SPAN&gt;: The prepared IN-report has been sent (your ACK).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;USB_EVT_OUT_NAK&lt;/I&gt;&lt;SPAN&gt;: The host tried to send a report, but the stack told the host to try later again. This is a good place for you to place a read request. Then the next try of the host will be accepted and you will get notified.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Example code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;I&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadReqEP(hUsb, pHidCtrl-&amp;gt;epout_adr, outbuffer, 8);&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;USB_EVT_OUT&lt;/I&gt;&lt;SPAN&gt;: A new report from the host is availabe and you can retrieve it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Example code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;I&gt;n=USBD_API-&amp;gt;hw-&amp;gt;ReadEP(hUsb, pHidCtrl-&amp;gt;epout_adr, outbuffer);&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now assume you want to PREPARE a report to the host: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This could like this (anywhere in the code) for your format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;I&gt;n=USBD_API-&amp;gt;hw-&amp;gt;WriteEP(g_hUsb, pHidCtrl-&amp;gt;epin_adr, inbuffer, 4);&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When the host has retrieved this report you get the &lt;/SPAN&gt;&lt;I&gt;USB_EVT_IN&lt;/I&gt;&lt;SPAN&gt; event in the callback function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For a starter or very short actions you can do all required actions within the callback handler.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For actions that take more time better set a flag (volatile variable) and handle the action in the background.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:23:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584079#M20977</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: USB HID generic example questions</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584080#M20978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by emanuelj on Wed Oct 08 10:17:42 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your great answer, now I got it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've implemented all my ideas and it's all working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On the device-side I've converted the incoming report to a char[] via typecast:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;static uint8_t *incoming_report;
static uint8_t *outgoing_report;
#define REPORT_SIZE 16
unsigned char buffer[REPORT_SIZE];
unsigned char message[REPORT_SIZE];

...

USBD_API-&amp;gt;hw-&amp;gt;ReadEP(hUsb, pHidCtrl-&amp;gt;epout_adr, incoming_report);

for (i=0; i&amp;lt;= REPORT_SIZE; i++)
{
buffer&lt;I&gt; = (unsigned char)(*(incoming_report+i));
}

//Do something ...

sprintf((char *)message, "value: %d", value);
outgoing_report = &amp;amp;message[0];


USBD_API-&amp;gt;hw-&amp;gt;WriteEP(hUsb, pHidCtrl-&amp;gt;epin_adr, outgoing_report, REPORT_SIZE);

...&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;maybe not the most elegant method but it's perfectly working &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Emanuel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:23:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584080#M20978</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: USB HID generic example questions</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584081#M20979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mch0 on Wed Oct 08 10:50:49 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Glad to help you, but at this point it might work only by sheer luck.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You have declared two pointers, but they are not initialized, i.e. can point to any location.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This might be currently unused RAM (lucky for the moment), but also could be ROM, nothing at all (unused address space) or in the worst case some *used* RAM.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The last case is the most dangerous as you will later get unexplained errors or program crashes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could instead simply write this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;I&gt;&lt;BR /&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP(hUsb, pHidCtrl-&amp;gt;epout_adr, (uint8_t*)buffer);&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then your pointer is generated "on the fly", it points to a defined location in RAM and you don't have to copy the data in the loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's already stored there by the USB stack.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second part is OK since you initialize the pointer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You could save the additional pointer as well:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;USBD_API-&amp;gt;hw-&amp;gt;WriteEP(hUsb, pHidCtrl-&amp;gt;epin_adr, (uint8_t*)message, REPORT_SIZE);&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But that's only for elegance :), your solution is quite as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;With your definitions (&lt;/SPAN&gt;&lt;I&gt;unsigned char&lt;/I&gt;&lt;SPAN&gt;) of the buffers the two typecasts to &lt;/SPAN&gt;&lt;I&gt;uint8_t&lt;/I&gt;&lt;SPAN&gt;&amp;nbsp; I introduced are probably superfluous, depends on the defintion of the type. But they don't add code either.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:23:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-HID-generic-example-questions/m-p/584081#M20979</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:23:28Z</dc:date>
    </item>
  </channel>
</rss>

