<?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: Please help me understand LPCopen CDC example</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Please-help-me-understand-LPCopen-CDC-example/m-p/578926#M19915</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by SeleneSW on Wed Dec 30 09:22:32 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi abonent,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;While implementing USB CDC communication in one of our projects, I had your problem too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After some investigation, as you saw, I've found that the &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt;&lt;SPAN&gt; function is broken in the sense that overrides the &lt;/SPAN&gt;&lt;STRONG&gt;pVcom-&amp;gt;rx_buff&lt;/STRONG&gt;&lt;SPAN&gt; buffer with new data every time the interrupt is called.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In this way if the &lt;/SPAN&gt;&lt;STRONG&gt;vcom_bread&lt;/STRONG&gt;&lt;SPAN&gt; function is not called fast enought we lose some packets.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've managed to fix this, implementing a check inside the &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt;&lt;SPAN&gt; function, and if there is no space in the buffer for the new packet, I just don't do the &lt;/SPAN&gt;&lt;STRONG&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP&lt;/STRONG&gt;&lt;SPAN&gt; call (with the side effect that the interrupt will not be called any time soon, because the USB peripheral has no space), and later in the &lt;/SPAN&gt;&lt;STRONG&gt;vcom_bread&lt;/STRONG&gt;&lt;SPAN&gt; when I make room reading data, I call the &lt;/SPAN&gt;&lt;STRONG&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP&lt;/STRONG&gt;&lt;SPAN&gt; enabling the interrupt again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 20:18:04 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T20:18:04Z</dc:date>
    <item>
      <title>Please help me understand LPCopen CDC example</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Please-help-me-understand-LPCopen-CDC-example/m-p/578925#M19914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by abonent on Sun Jan 25 12:50:14 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;I'm using this &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.embeddedartists.com%2Fproducts%2Fboards%2Flpc11u35_qsb.php" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.embeddedartists.com/products/boards/lpc11u35_qsb.php&lt;/A&gt;&lt;SPAN&gt; board, plus LPC-Link2 and LPCXpresso v7.5.0 [Build 254] [2014-10-31] for my experiments.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;I took LPCopen package &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.lpcware.com%2Fsystem%2Ffiles%2Flpcopen_v2_03_lpcxpresso_nxp_lpcxpresso_11u37h.zip" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.lpcware.com/system/files/lpcopen_v2_03_lpcxpresso_nxp_lpcxpresso_11u37h.zip&lt;/A&gt;&lt;SPAN&gt; and imported &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;STRONG&gt;nxp_lpcxpresso_11u37_usbd_rom_cdc&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;nxp_lpcxpresso_11u37h_board_lib&lt;/STRONG&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;STRONG&gt;lpc_chip_11uxx_lib&lt;/STRONG&gt;&lt;SPAN&gt; projects. I built it successfully and flashed on the board. The board enumerated as CDCserial device and I was able to talk to it using serial terminal, strings sent to it were correctly echoed back. So far everything OK.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When my mainline code looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
while (1)
{
//dly_ms(1);
LPC_GPIO-&amp;gt;NOT[0]&amp;nbsp; = (1&amp;lt;&amp;lt;7);
if (vcom_connected() != 0)
{
rdCnt = vcom_bread(&amp;amp;g_rxBuff[0], 256);
if (rdCnt)
vcom_write(&amp;amp;g_rxBuff[0], rdCnt);
}
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;all data are correctly echoed. However, once I uncomment the dly_ms function (doing simple delay loop for approximately 1ms), most of the characters is missing. From message "Hello world" I usually receive only "d" or "ld" characters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I plan to use the LPC device to process data from stream od characters and the delay represents time delay caused by data processing. I expect the incomming data to be NAK-ed while the LPC is busy with data processing (should be done in USB interrupts) and I don't care about slow data transfer, but lost data is problem. I put breakpoint at the &lt;/SPAN&gt;&lt;STRONG&gt;vcom_write&lt;/STRONG&gt;&lt;SPAN&gt; function and the received data (to send back to PC) is the one or two symbols I receive in terminal, so it looks like the data is lost at the receiving part of code. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I took a look at &lt;/SPAN&gt;&lt;STRONG&gt;vcom_bread&lt;/STRONG&gt;&lt;SPAN&gt; function and it looks like it just reads data from &lt;/SPAN&gt;&lt;STRONG&gt;pVcom&lt;/STRONG&gt;&lt;SPAN&gt; structure, filled by &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt;&lt;SPAN&gt; handler and it looks a bit more complicated and honestly I don't understand it much:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/* VCOM bulk EP_OUT endpoint handler */
static ErrorCode_t VCOM_bulk_out_hdlr(USBD_HANDLE_T hUsb, void *data, uint32_t event)
{
VCOM_DATA_T *pVcom = (VCOM_DATA_T *) data;
switch (event) {
case USB_EVT_OUT:
pVcom-&amp;gt;rx_count = USBD_API-&amp;gt;hw-&amp;gt;ReadEP(hUsb, USB_CDC_OUT_EP, pVcom-&amp;gt;rx_buff);
if (pVcom-&amp;gt;rx_flags &amp;amp; VCOM_RX_BUF_QUEUED) {
pVcom-&amp;gt;rx_flags &amp;amp;= ~VCOM_RX_BUF_QUEUED;
if (pVcom-&amp;gt;rx_count != 0) {
pVcom-&amp;gt;rx_flags |= VCOM_RX_BUF_FULL;
}

}
else if (pVcom-&amp;gt;rx_flags &amp;amp; VCOM_RX_DB_QUEUED) {
pVcom-&amp;gt;rx_flags &amp;amp;= ~VCOM_RX_DB_QUEUED;
pVcom-&amp;gt;rx_flags |= VCOM_RX_DONE;
}
break;
case USB_EVT_OUT_NAK:
/* queue free buffer for RX */
if ((pVcom-&amp;gt;rx_flags &amp;amp; (VCOM_RX_BUF_FULL | VCOM_RX_BUF_QUEUED)) == 0) {
USBD_API-&amp;gt;hw-&amp;gt;ReadReqEP(hUsb, USB_CDC_OUT_EP, pVcom-&amp;gt;rx_buff, VCOM_RX_BUF_SZ);
pVcom-&amp;gt;rx_flags |= VCOM_RX_BUF_QUEUED;
}
break;
default:
break;
}
return LPC_OK;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;I see that when OUT event on givent endpoint happens, the &lt;/SPAN&gt;&lt;STRONG&gt;pVcom-&amp;gt;rx_buff&lt;/STRONG&gt;&lt;SPAN&gt; is overwritten by new data, regardless whether it was read or not. Honestly, I don't understand the meaning of flags &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_RX_BUF_QUEUED, VCOM_RX_BUF_FULL, VCOM_RX_DB_QUEUED&lt;/STRONG&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_RX_DONE&lt;/STRONG&gt;&lt;SPAN&gt;, as well as what the handler actually does. I looked into documentation and it was quite sparse&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
static ErrorCode_t VCOM_bulk_out_hdlr ( USBD_HANDLE_T&amp;nbsp; hUsb,
void *&amp;nbsp; data,
uint32_t&amp;nbsp; event 
) 
static

Definition at line 65 of file cdc_vcom.c.
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;and explanation of the flags I just can't find.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;TLDR version: I have no idea why my data are lost when I don't read it very often from main loop. The documentation didn't help me much.&lt;BR /&gt;&lt;/I&gt;&lt;BR /&gt;&lt;SPAN&gt;Could anybody, please, help me with understanding why the data from OUT transaction are lost when &lt;/SPAN&gt;&lt;STRONG&gt;vcom_bread &lt;/STRONG&gt;&lt;SPAN&gt; function is not called often and how to fix the code?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:18:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Please-help-me-understand-LPCopen-CDC-example/m-p/578925#M19914</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me understand LPCopen CDC example</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Please-help-me-understand-LPCopen-CDC-example/m-p/578926#M19915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by SeleneSW on Wed Dec 30 09:22:32 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi abonent,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;While implementing USB CDC communication in one of our projects, I had your problem too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After some investigation, as you saw, I've found that the &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt;&lt;SPAN&gt; function is broken in the sense that overrides the &lt;/SPAN&gt;&lt;STRONG&gt;pVcom-&amp;gt;rx_buff&lt;/STRONG&gt;&lt;SPAN&gt; buffer with new data every time the interrupt is called.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In this way if the &lt;/SPAN&gt;&lt;STRONG&gt;vcom_bread&lt;/STRONG&gt;&lt;SPAN&gt; function is not called fast enought we lose some packets.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've managed to fix this, implementing a check inside the &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt;&lt;SPAN&gt; function, and if there is no space in the buffer for the new packet, I just don't do the &lt;/SPAN&gt;&lt;STRONG&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP&lt;/STRONG&gt;&lt;SPAN&gt; call (with the side effect that the interrupt will not be called any time soon, because the USB peripheral has no space), and later in the &lt;/SPAN&gt;&lt;STRONG&gt;vcom_bread&lt;/STRONG&gt;&lt;SPAN&gt; when I make room reading data, I call the &lt;/SPAN&gt;&lt;STRONG&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP&lt;/STRONG&gt;&lt;SPAN&gt; enabling the interrupt again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:18:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Please-help-me-understand-LPCopen-CDC-example/m-p/578926#M19915</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me understand LPCopen CDC example</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Please-help-me-understand-LPCopen-CDC-example/m-p/578927#M19916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by abonent on Wed Dec 30 13:15:24 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: SeleneSW&lt;/STRONG&gt;&lt;BR /&gt;Hi abonent,&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SeleneSW - thank you much for your response. Since it is almost year since I tried to solve this problem, I don't remember very much details.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: SeleneSW&lt;/STRONG&gt;&lt;BR /&gt; While implementing USB CDC communication in one of our projects, I had your problem too.&lt;BR /&gt;After some investigation, as you saw, I've found that the &lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt; function is broken in the sense that overrides the &lt;STRONG&gt;pVcom-&amp;gt;rx_buff&lt;/STRONG&gt; buffer with new data every time the interrupt is called.&lt;BR /&gt;In this way if the &lt;STRONG&gt;vcom_bread&lt;/STRONG&gt; function is not called fast enought we lose some packets.&lt;BR /&gt;I've managed to fix this, implementing a check inside the &lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt; function, and if there is no space in the buffer for the new packet, I just don't do the &lt;STRONG&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP&lt;/STRONG&gt; call (with the side effect that the interrupt will not be called any time soon, because the USB peripheral has no space), &lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, not reading &lt;/SPAN&gt;&lt;STRONG&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP&lt;/STRONG&gt;&lt;SPAN&gt; is safe and doesn't have any adverse effects? I barely remember setting up simple state machine and checking room in data buffer and once it was full, I didn't do EP reading, hoping in NAKed packets, but I recall it locked down virtual COM port. Perhaps my implementation was wrong, so I can try to reimplement it again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: SeleneSW&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;and later in the &lt;STRONG&gt;vcom_bread&lt;/STRONG&gt; when I make room reading data, I call the &lt;STRONG&gt;USBD_API-&amp;gt;hw-&amp;gt;ReadEP&lt;/STRONG&gt; enabling the interrupt again.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Well, maybe this is my problem, I didn't perform EP reading in &lt;/SPAN&gt;&lt;STRONG&gt;vcom_bread&lt;/STRONG&gt;&lt;SPAN&gt; function, but expected the &lt;/SPAN&gt;&lt;STRONG&gt;VCOM_bulk_out_hdlr&lt;/STRONG&gt;&lt;SPAN&gt; to be called again - seems like I was wrong. Thank you for this information, I'll try to find the old code and rework it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:18:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Please-help-me-understand-LPCopen-CDC-example/m-p/578927#M19916</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:18:05Z</dc:date>
    </item>
  </channel>
</rss>

