<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Firmware Programming Archives | DMC, Inc.</title>
	<atom:link href="https://static.dmcinfo.com/blog/tag/firmware-programming/feed/index.xml" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Tue, 16 Jun 2026 14:30:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://static.dmcinfo.com/wp-content/uploads/2025/04/site-icon-150x150.png</url>
	<title>Firmware Programming Archives | DMC, Inc.</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Adding a USB Device Endpoint to an STM Example Project</title>
		<link>https://static.dmcinfo.com/blog/21837/adding-a-usb-device-endpoint-to-an-stm-example-project/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Wed, 27 Mar 2019 09:49:22 +0000</pubDate>
				<category><![CDATA[Embedded Development & Programming]]></category>
		<category><![CDATA[Firmware Programming]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/21837/adding-a-usb-device-endpoint-to-an-stm-example-project-2/</guid>

					<description><![CDATA[<p>When writing customized drivers for USB devices, it is beneficial to start by using one of the examples provided by ST. Examples provide a working base from which to build on, as well as reducing the amount of code required. In our case, we were implementing a USB TMC IEEE488 driver for a test and [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21837/adding-a-usb-device-endpoint-to-an-stm-example-project/">Adding a USB Device Endpoint to an STM Example Project</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">When writing customized drivers for USB devices, it is beneficial to start by using one of the examples provided by <a href="https://www.st.com/content/st_com/en.html" target="_blank">ST</a>. Examples provide a working base from which to build on, as well as reducing the amount of code required. In our case, we were implementing a <strong>USB TMC IEEE488 driver</strong> for a test and measurement device. After starting with a base example, we needed to add an interrupt IN endpoint to the device.</p>



<p class="wp-block-paragraph">USB TMC IEEE488 requires an interrupt IN endpoint which is used for the required <strong>Read Status Byte</strong>&nbsp;request and can also be used for the user-defined service requests (which are optional). The interrupt endpoint does not function as a true interrupt;&nbsp;the host will periodically poll the endpoint until it reads a response – if it sent a request. There are a few important steps to creating this endpoint, which can then be used to expand and improve the <strong>USB TMC</strong> <strong>functionality </strong>of the device.</p>



<p class="wp-block-paragraph">Starting with the <a href="https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html">STM32CubeMX</a>, I created a project for the development board I am working with, <strong>NUCLEO STM32F303RE</strong>, making sure to enable the <strong>USB peripheral</strong>, and selecting <strong>Human Interface Device (HID)</strong> for the <strong>USB FS IP</strong>. I used <a href="https://atollic.com/truestudio/" target="_blank">Atollic’s TrueSTUDIO</a> as the <strong>IDE </strong>for this project.</p>



<h2 class="wp-block-heading" id="h-adding-descriptors">Adding Descriptors</h2>



<p class="wp-block-paragraph">Let us start with the <strong>descriptors</strong>. We need to let the device and host know that we have a new endpoint, and what the configurations of this endpoint are. Here is an example:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>/* USB TMC device Configuration Descriptor */
__ALIGN_BEGIN uint8_t USBD_TMC_CfgFSDesc&#91;USB_TMC_CONFIG_DESC_SIZ&#93; __ALIGN_END =
{
		/*Configuration Descriptor*/
		USB_LEN_CFG_DESC,   		/* bLength: Configuration Descriptor size */
		USB_DESC_TYPE_CONFIGURATION,     /* bDescriptorType: Configuration */
		USB_TMC_CONFIG_DESC_SIZ,         /* wTotalLength:no of returned bytes */
		0x00,
		0x01,   				/* bNumInterfaces: 1 interface */
		0x01,   				/* bConfigurationValue: Configuration value */
		0x00,   				/* iConfiguration: Index of string descriptor describing the configuration */
		0xC0,   				/* bmAttributes: self powered */
		0x32,   				/* MaxPower 100 mA */

		/*---------------------------------------------------------------------------*/

		/*Interface Descriptor */
		USB_LEN_IF_DESC,   			/* bLength: Interface Descriptor size */
		USB_DESC_TYPE_INTERFACE,  		/* bDescriptorType: Interface */
		/* Interface descriptor type */
		0x00,   				/* bInterfaceNumber: Number of Interface */
		0x00,   				/* bAlternateSetting: Alternate setting */
		0x03,   				/* bNumEndpoints: THREE endpoints used */
		0xfe,   				/* bInterfaceClass: Application Class */
		0x03,   				/* bInterfaceSubClass: Assigned by USB-IF */
		USBTMC_USB488,   			/* bInterfaceProtocol: USBTMC_NO_PROTOCOL */
		0x00,   				/* iInterface: */

		/*Endpoint BULK_IN Descriptor*/
…

		/*Endpoint BULK_OUT Descriptor*/
…

		/*Endpoint Interrupt Descriptor*/
		USB_LEN_EP_DESC,   			/* bLength: Endpoint Descriptor size */
		USB_DESC_TYPE_ENDPOINT,      	/* bDescriptorType: Endpoint */
		TMC_INT_EP,                    	/* bEndpointAddress */
		0x03,                            /* bmAttributes: Interrupt */
		LOBYTE(TMC_INT_PACKET_SIZE),  	/* wMaxPacketSize: */
		HIBYTE(TMC_INT_PACKET_SIZE),
		0x80		                    /* bInterval: see 9-13 USB 2.0 */

} ;</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #6A9955">/* USB TMC device Configuration Descriptor */</span></span>
<span class="line"><span style="color: #D4D4D4">__ALIGN_BEGIN </span><span style="color: #569CD6">uint8_t</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">USBD_TMC_CfgFSDesc</span><span style="color: #D4D4D4">&#91;USB_TMC_CONFIG_DESC_SIZ&#93; __ALIGN_END =</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">		/*Configuration Descriptor*/</span></span>
<span class="line"><span style="color: #D4D4D4">		USB_LEN_CFG_DESC,</span><span style="color: #6A9955">   		/* bLength: Configuration Descriptor size */</span></span>
<span class="line"><span style="color: #D4D4D4">		USB_DESC_TYPE_CONFIGURATION,</span><span style="color: #6A9955">     /* bDescriptorType: Configuration */</span></span>
<span class="line"><span style="color: #D4D4D4">		USB_TMC_CONFIG_DESC_SIZ,</span><span style="color: #6A9955">         /* wTotalLength:no of returned bytes */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x00</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x01</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bNumInterfaces: 1 interface */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x01</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bConfigurationValue: Configuration value */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x00</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* iConfiguration: Index of string descriptor describing the configuration */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0xC0</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bmAttributes: self powered */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x32</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* MaxPower 100 mA */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">		/*---------------------------------------------------------------------------*/</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">		/*Interface Descriptor */</span></span>
<span class="line"><span style="color: #D4D4D4">		USB_LEN_IF_DESC,</span><span style="color: #6A9955">   			/* bLength: Interface Descriptor size */</span></span>
<span class="line"><span style="color: #D4D4D4">		USB_DESC_TYPE_INTERFACE,</span><span style="color: #6A9955">  		/* bDescriptorType: Interface */</span></span>
<span class="line"><span style="color: #6A9955">		/* Interface descriptor type */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x00</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bInterfaceNumber: Number of Interface */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x00</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bAlternateSetting: Alternate setting */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x03</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bNumEndpoints: THREE endpoints used */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0xfe</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bInterfaceClass: Application Class */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x03</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* bInterfaceSubClass: Assigned by USB-IF */</span></span>
<span class="line"><span style="color: #D4D4D4">		USBTMC_USB488,</span><span style="color: #6A9955">   			/* bInterfaceProtocol: USBTMC_NO_PROTOCOL */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x00</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">   				/* iInterface: */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">		/*Endpoint BULK_IN Descriptor*/</span></span>
<span class="line"><span style="color: #D4D4D4">…</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">		/*Endpoint BULK_OUT Descriptor*/</span></span>
<span class="line"><span style="color: #D4D4D4">…</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">		/*Endpoint Interrupt Descriptor*/</span></span>
<span class="line"><span style="color: #D4D4D4">		USB_LEN_EP_DESC,</span><span style="color: #6A9955">   			/* bLength: Endpoint Descriptor size */</span></span>
<span class="line"><span style="color: #D4D4D4">		USB_DESC_TYPE_ENDPOINT,</span><span style="color: #6A9955">      	/* bDescriptorType: Endpoint */</span></span>
<span class="line"><span style="color: #D4D4D4">		TMC_INT_EP,</span><span style="color: #6A9955">                    	/* bEndpointAddress */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x03</span><span style="color: #D4D4D4">,</span><span style="color: #6A9955">                            /* bmAttributes: Interrupt */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #DCDCAA">LOBYTE</span><span style="color: #D4D4D4">(TMC_INT_PACKET_SIZE),</span><span style="color: #6A9955">  	/* wMaxPacketSize: */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #DCDCAA">HIBYTE</span><span style="color: #D4D4D4">(TMC_INT_PACKET_SIZE),</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #B5CEA8">0x80</span><span style="color: #6A9955">		                    /* bInterval: see 9-13 USB 2.0 */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">} ;</span></span></code></pre></div>



<p class="wp-block-paragraph">Along with having the right descriptor sizes, it is important to remember to increase the number of endpoints to the number you are using (in my case 3).</p>



<p class="wp-block-paragraph">I have defined the endpoint address as:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>#define TMC_BULK_OUT_EP                     	0x01    //  0B00000001
#define TMC_BULK_IN_EP                      	0x81    //  0B10000001
#define TMC_INT_EP                          	0x82    //  0B10000010</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">#define</span><span style="color: #569CD6"> TMC_BULK_OUT_EP                     	</span><span style="color: #B5CEA8">0x01</span><span style="color: #6A9955">    //  0B00000001</span></span>
<span class="line"><span style="color: #C586C0">#define</span><span style="color: #569CD6"> TMC_BULK_IN_EP                      	</span><span style="color: #B5CEA8">0x81</span><span style="color: #6A9955">    //  0B10000001</span></span>
<span class="line"><span style="color: #C586C0">#define</span><span style="color: #569CD6"> TMC_INT_EP                          	</span><span style="color: #B5CEA8">0x82</span><span style="color: #6A9955">    //  0B10000010</span></span></code></pre></div>



<p class="wp-block-paragraph">The <strong>0x80 bit</strong> defined this endpoint as an IN endpoint, and the <strong>0x02 bit</strong> defines the address of this endpoint.</p>



<h2 class="wp-block-heading" id="h-update-initialization-amp-de-initialization">Update Initialization &amp; De-Initialization</h2>



<p class="wp-block-paragraph">Next, we need to update the initialization and de-initialization to include the interrupt endpoint we just added. For example:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>		/* Open EP INT */
		USBD_LL_OpenEP(pdev,
				TMC_INT_EP,
				USBD_EP_TYPE_INTR,
				TMC_INT_PACKET_SIZE);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #6A9955">		/* Open EP INT */</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #DCDCAA">USBD_LL_OpenEP</span><span style="color: #D4D4D4">(pdev,</span></span>
<span class="line"><span style="color: #D4D4D4">				TMC_INT_EP,</span></span>
<span class="line"><span style="color: #D4D4D4">				USBD_EP_TYPE_INTR,</span></span>
<span class="line"><span style="color: #D4D4D4">				TMC_INT_PACKET_SIZE);</span></span></code></pre></div>



<p class="wp-block-paragraph">And</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>	/* Open EP INT */
	USBD_LL_CloseEP(pdev,
			TMC_INT_EP);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #6A9955">	/* Open EP INT */</span></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #DCDCAA">USBD_LL_CloseEP</span><span style="color: #D4D4D4">(pdev,</span></span>
<span class="line"><span style="color: #D4D4D4">			TMC_INT_EP);</span></span></code></pre></div>



<p class="wp-block-paragraph">You can then use the transmit functions of the <strong>hardware abstraction layer (or HAL)</strong> to send data through the endpoint.</p>



<pre class="wp-block-code"><code>
USBD_LL_Transmit(pdev, TMC_INT_EP, htmc-&gt;IntBuffer, htmc-&gt;IntLength);
</code></pre>



<h2 class="wp-block-heading" id="h-update-the-usbd-conf-c-file">Update the USBD_CONF.C File</h2>



<p class="wp-block-paragraph">For the final section, we must now go ahead and update the<strong> usbd_conf.c file</strong>. Here we initialize the necessary structures for the new endpoint to function correctly.</p>



<p class="wp-block-paragraph">As well as making sure the number of endpoints is correct, we must also make sure that we have an allocated <strong>FIFO stack</strong> for the new endpoint to use. If not handled correctly, the lower level drivers will be called to handle a message transmission but will not have access to the memory to send the transmission and will instead always send an empty buffer.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>  hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  hpcd_USB_OTG_FS.Init.dev_endpoints = 5;
  hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;
  hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  if (HAL_PCD_Init(&amp;hpcd_USB_OTG_FS) != HAL_OK)
  {
  _Error_Handler(__FILE__, __LINE__);
  }

  HAL_PCDEx_SetRxFiFo(&amp;hpcd_USB_OTG_FS, 0x80);
  HAL_PCDEx_SetTxFiFo(&amp;hpcd_USB_OTG_FS, 0, 0x40);
  HAL_PCDEx_SetTxFiFo(&amp;hpcd_USB_OTG_FS, 1, 0x60);
  HAL_PCDEx_SetTxFiFo(&amp;hpcd_USB_OTG_FS, 2, 0x20);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Instance = USB_OTG_FS;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.dev_endpoints = </span><span style="color: #B5CEA8">5</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;</span></span>
<span class="line"><span style="color: #D4D4D4">  hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> (</span><span style="color: #DCDCAA">HAL_PCD_Init</span><span style="color: #D4D4D4">(&amp;</span><span style="color: #9CDCFE">hpcd_USB_OTG_FS</span><span style="color: #D4D4D4">) != HAL_OK)</span></span>
<span class="line"><span style="color: #D4D4D4">  {</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #DCDCAA">_Error_Handler</span><span style="color: #D4D4D4">(__FILE__, __LINE__);</span></span>
<span class="line"><span style="color: #D4D4D4">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #DCDCAA">HAL_PCDEx_SetRxFiFo</span><span style="color: #D4D4D4">(&amp;</span><span style="color: #9CDCFE">hpcd_USB_OTG_FS</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">0x80</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #DCDCAA">HAL_PCDEx_SetTxFiFo</span><span style="color: #D4D4D4">(&amp;</span><span style="color: #9CDCFE">hpcd_USB_OTG_FS</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">0x40</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #DCDCAA">HAL_PCDEx_SetTxFiFo</span><span style="color: #D4D4D4">(&amp;</span><span style="color: #9CDCFE">hpcd_USB_OTG_FS</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">0x60</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #DCDCAA">HAL_PCDEx_SetTxFiFo</span><span style="color: #D4D4D4">(&amp;</span><span style="color: #9CDCFE">hpcd_USB_OTG_FS</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">2</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">0x20</span><span style="color: #D4D4D4">);</span></span></code></pre></div>



<p class="wp-block-paragraph">These changes should be sufficient to have a new, functional endpoint (in this case an interrupt in endpoint) added to an existing TrueSTUDIO example for STM microcontrollers.</p>



<p class="wp-block-paragraph">After the endpoint functionality is integrated with the rest of your USB driver and application code, this endpoint should be fully functional in the transmission of data. Below is a screenshot of the <a href="https://www.wireshark.org/" target="_blank">Wireshark</a>&nbsp;capture of the USB communications. There are control, bulk and interrupt endpoint messages, with the interrupt IN message highlighted below (note the endpoint information).</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Screenshot-of-the-Wireshark-capture-of-the-USB-communications-large-1.png" alt="Screenshot of the Wireshark capture of the USB communications."/></figure>



<p class="wp-block-paragraph">&nbsp;</p>



<p class="wp-block-paragraph">Learn more about DMC&#8217;s <a href="https://static.dmcinfo.com/services/embedded-development-and-embedded-programming/firmware-programming">Firmware Programming Services</a> or <a href="https://static.dmcinfo.com/contact">Contact Us</a> to get started on a project today.&nbsp;</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21837/adding-a-usb-device-endpoint-to-an-stm-example-project/">Adding a USB Device Endpoint to an STM Example Project</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
