<?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>Microcontroller Programming Archives | DMC, Inc.</title>
	<atom:link href="https://static.dmcinfo.com/blog/tag/microcontroller-programming/feed/index.xml" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Thu, 09 Jul 2026 19:13:15 +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>Microcontroller Programming Archives | DMC, Inc.</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Trying Out ARM Mbed OS’s New Support for USB Device with Some Retro Hardware</title>
		<link>https://static.dmcinfo.com/blog/21018/trying-out-arm-mbed-oss-new-support-for-usb-device-with-some-retro-hardware/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Fri, 30 Aug 2019 09:24:58 +0000</pubDate>
				<category><![CDATA[Circuit Design]]></category>
		<category><![CDATA[Embedded Development & Programming]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Microcontroller Programming]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/21018/trying-out-arm-mbed-oss-new-support-for-usb-device-with-some-retro-hardware/</guid>

					<description><![CDATA[<p>Many products feature USB to facilitate communication between various devices, to transfer files easily, support hardware peripherals or add other features. While working on embedded systems, we have developed a variety of devices that utilize USB in these ways. The ease of implementation of USB largely depends on the hardware and software infrastructure that the [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21018/trying-out-arm-mbed-oss-new-support-for-usb-device-with-some-retro-hardware/">Trying Out ARM Mbed OS’s New Support for USB Device with Some Retro Hardware</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Many products feature USB to facilitate communication between various devices, to transfer files easily, support hardware peripherals or add other features. While working on embedded systems, we have developed a variety of devices that utilize USB in these ways.</p>



<p class="wp-block-paragraph">The ease of implementation of USB largely depends on the hardware and software infrastructure that the microcontroller manufacturer provides. As of release 5.12.0, ARM Mbed OS began supporting USB device for several targets. This provides a nice layer of abstraction between the various manufacturers’ USB implementations and the USB class code. There are a variety of USB classes that are supported by default: USB MSD, USB HID, and USB Audio.</p>



<p class="wp-block-paragraph">In this blog, I’m going to try out this new USB device support and create a USB Mouse out of an old joystick.</p>



<h2 class="wp-block-heading" id="h-setting-up-the-project">Setting up the Project</h2>



<p class="wp-block-paragraph">I want to test out the USB HID class which will allow the device to interface with the PC as a USB mouse. I am going to start by creating a <strong>basic ARM Mbed OS</strong> project. If you have never done that before, take a look at <a href="/latest-thinking/blog/id/9536/nucleo-uart-tutorial-mbed-style">this guide.</a></p>



<p class="wp-block-paragraph">For this project, I am using a <strong>NUCLEO_F429ZI</strong> development board which is one of the supported targets for using mbed’s USB device. I set the target in my project by using the command <strong>“mbed target NUCLEO_F429ZI”.</strong> Make sure that your compiler is also set correctly according to the compiler that you have installed.</p>



<p class="wp-block-paragraph">For the test, I am going to copy-and-paste the example main from the file mbed/usb/device/USBHID/USBMouse.h.</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>#include "mbed.h"
#include "USBMouse.h" 

USBMouse mouse;

int main(void)
{
  while (1)
  {
      mouse.move(20, 0);
      wait(0.5);
  }
}</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">#include</span><span style="color: #569CD6"> </span><span style="color: #CE9178">&quot;mbed.h&quot;</span></span>
<span class="line"><span style="color: #C586C0">#include</span><span style="color: #569CD6"> </span><span style="color: #CE9178">&quot;USBMouse.h&quot;</span><span style="color: #569CD6"> </span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">USBMouse mouse;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">int</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">main</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">void</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #C586C0">while</span><span style="color: #D4D4D4"> (</span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">  {</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #9CDCFE">mouse</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">move</span><span style="color: #D4D4D4">(</span><span style="color: #B5CEA8">20</span><span style="color: #D4D4D4">, </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #DCDCAA">wait</span><span style="color: #D4D4D4">(</span><span style="color: #B5CEA8">0.5</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">Try and compile the project by running<strong> “mbed compile.”</strong> If you successfully build this project, then you are ready for the next steps. If not, make sure the target you are using is supported by ARM Mbed OS’s new USB device.</p>



<p class="wp-block-paragraph">Note, not all of the targets with hardware USB support Mbed’s USB device abstraction! Also, make sure you have the latest version of ARM Mbed OS in your project.</p>



<h2 class="wp-block-heading" id="h-running-a-quick-test">Running a Quick Test</h2>



<p class="wp-block-paragraph">Load the compiled program onto your target development kit. I am using a NUCLEO which has a STLINK on-board, so the development kit shows up as a drive when I plug it in. Just drag-and-drop the compiled<strong> “_your_project_name_.bin”</strong> onto the drive to program.</p>



<p class="wp-block-paragraph">To test the USB HID device, plug in the User USB port to the PC in addition to the debugging port which is needed for power. On your PC, you should see that a new USB device is detected. Once setup, your PC’s cursor should slowly move across your screen in 0.5-second steps.</p>



<p class="wp-block-paragraph">We are now ready to bring in the retro hardware to complete our USB device!</p>



<h2 class="wp-block-heading" id="h-adding-some-more-hardware">Adding Some More Hardware</h2>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/mbed-apple-joystick.jpg" alt="apple joystick"/></figure>



<p class="wp-block-paragraph">I have an old Apple Joystick IIe that I want&nbsp;to use&nbsp;as a USB joystick; so I need a custom USB adapter. The joystick electronics are very simple. There are two pushbuttons with pull-down resistors and two variable resistors, one for each axis, with one side tied to V+.</p>



<p class="wp-block-paragraph">To interface to the joystick, I connect 3.3 V on the NUCLEO to the V+, connect the GND on the NUCLEO to the joystick ground, connect the push-button outputs to digital inputs on the NUCLEO, and connect each axis output to a NUCLEO analog input with a 100 K ohm resistor to ground.</p>



<p class="wp-block-paragraph">I pulled all of this together quickly with a small prototyping board. The connector itself is just half of an RS232 serial cable.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/mbed-microcontroller.jpg" alt="microcontroler for joystick"/></figure>



<p class="wp-block-paragraph">Now, with a bit of firmware, we can get this retro joystick to operate with any modern OS.</p>



<p class="wp-block-paragraph">The code below is what I quickly put together to read the analog inputs of the joystick, read the button presses, and send corresponding USB Mouse events. When using one of the various supported USB device classes, Mbed can substantially decrease the required development time.</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>#include "mbed.h"
#include "USBMouse.h"

USBMouse mouse;

AnalogIn ainx(A0);
AnalogIn ainy(A1);

DigitalIn right_button(D6);
DigitalIn left_button(D7);

int main()
{
	float x = 0;
	float y = 0;

	bool prev_right_button = true;
	bool prev_left_button = true;
	
	const float mid_x = ainx.read() * 100.0;
	const float mid_y = ainy.read() * 100.0;
	
	while (1)
	{
		// Update the X, Y position
		y = ainy.read() * 100.0;
		x = ainx.read() * 100.0;

		float x_move = x - mid_x;
		float y_move = y - mid_y;

		if (x_move &lt; 0)
			x_move = 2 * x_move;
		if (y_move &lt; 0)
			y_move = 2 * y_move;

		if ((abs(x_move) > 4.0) || (abs(y_move) > 4.0))
		{
			mouse.move(-1 * x_move, -1 * y_move);
		}

		// Update the button presses
		bool current_right_button = right_button;
		bool current_left_button = left_button;

		if (prev_right_button != current_right_button)
		{
			if (current_right_button)
			{
				mouse.press(MOUSE_RIGHT);
			}
			else
			{
				mouse.release(MOUSE_RIGHT);
			}
			prev_right_button = current_right_button;
		}

		if (prev_left_button != current_left_button)
		{
			if (current_left_button)
			{
				mouse.press(MOUSE_LEFT);
			}
			else
			{
				mouse.release(MOUSE_LEFT);
			}
			prev_left_button = current_left_button;
		}

		wait_ms(10);
	}
}</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">#include</span><span style="color: #569CD6"> </span><span style="color: #CE9178">&quot;mbed.h&quot;</span></span>
<span class="line"><span style="color: #C586C0">#include</span><span style="color: #569CD6"> </span><span style="color: #CE9178">&quot;USBMouse.h&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">USBMouse mouse;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #4EC9B0">AnalogIn</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">ainx</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">A0</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #4EC9B0">AnalogIn</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">ainy</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">A1</span><span style="color: #D4D4D4">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #4EC9B0">DigitalIn</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">right_button</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">D6</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #4EC9B0">DigitalIn</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">left_button</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">D7</span><span style="color: #D4D4D4">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">int</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">main</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #569CD6">float</span><span style="color: #D4D4D4"> x = </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #569CD6">float</span><span style="color: #D4D4D4"> y = </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #569CD6">bool</span><span style="color: #D4D4D4"> prev_right_button = </span><span style="color: #569CD6">true</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #569CD6">bool</span><span style="color: #D4D4D4"> prev_left_button = </span><span style="color: #569CD6">true</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">	</span></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">float</span><span style="color: #D4D4D4"> mid_x = </span><span style="color: #9CDCFE">ainx</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">read</span><span style="color: #D4D4D4">() * </span><span style="color: #B5CEA8">100.0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">float</span><span style="color: #D4D4D4"> mid_y = </span><span style="color: #9CDCFE">ainy</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">read</span><span style="color: #D4D4D4">() * </span><span style="color: #B5CEA8">100.0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">	</span></span>
<span class="line"><span style="color: #D4D4D4">	</span><span style="color: #C586C0">while</span><span style="color: #D4D4D4"> (</span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">	{</span></span>
<span class="line"><span style="color: #6A9955">		// Update the X, Y position</span></span>
<span class="line"><span style="color: #D4D4D4">		y = </span><span style="color: #9CDCFE">ainy</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">read</span><span style="color: #D4D4D4">() * </span><span style="color: #B5CEA8">100.0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">		x = </span><span style="color: #9CDCFE">ainx</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">read</span><span style="color: #D4D4D4">() * </span><span style="color: #B5CEA8">100.0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #569CD6">float</span><span style="color: #D4D4D4"> x_move = x - mid_x;</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #569CD6">float</span><span style="color: #D4D4D4"> y_move = y - mid_y;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> (x_move &lt; </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">			x_move = </span><span style="color: #B5CEA8">2</span><span style="color: #D4D4D4"> * x_move;</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> (y_move &lt; </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">			y_move = </span><span style="color: #B5CEA8">2</span><span style="color: #D4D4D4"> * y_move;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> ((</span><span style="color: #DCDCAA">abs</span><span style="color: #D4D4D4">(x_move) &gt; </span><span style="color: #B5CEA8">4.0</span><span style="color: #D4D4D4">) || (</span><span style="color: #DCDCAA">abs</span><span style="color: #D4D4D4">(y_move) &gt; </span><span style="color: #B5CEA8">4.0</span><span style="color: #D4D4D4">))</span></span>
<span class="line"><span style="color: #D4D4D4">		{</span></span>
<span class="line"><span style="color: #D4D4D4">			</span><span style="color: #9CDCFE">mouse</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">move</span><span style="color: #D4D4D4">(-</span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> * x_move, -</span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> * y_move);</span></span>
<span class="line"><span style="color: #D4D4D4">		}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">		// Update the button presses</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #569CD6">bool</span><span style="color: #D4D4D4"> current_right_button = right_button;</span></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #569CD6">bool</span><span style="color: #D4D4D4"> current_left_button = left_button;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">		</span><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> (prev_right_button != current_right_button)</span></span>
<span class="line"><span style="color: #D4D4D4">		{</span></span>
<span class="line"><span style="color: #D4D4D4">			</span><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> (current_right_button)</span></span>
<span class="line"><span style="color: #D4D4D4">			{</span></span>
<span class="line"><span style="color: #D4D4D4">				</span><span style="color: #9CDCFE">mouse</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">press</span><span style="color: #D4D4D4">(MOUSE_RIGHT);</span></span>
<span class="line"><span style="color: #D4D4D4">			}</span></span>
<span class="line"><span style="color: #D4D4D4">			</span><span style="color: #C586C0">else</span></span>
<span class="line"><span style="color: #D4D4D4">			{</span></span>
<span class="line"><span style="color: #D4D4D4">				</span><span style="color: #9CDCFE">mouse</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">release</span><span style="color: #D4D4D4">(MOUSE_RIGHT);</span></span>
<span class="line"><span style="color: #D4D4D4">			}</span></span>
<span class="line"><span style="color: #D4D4D4">			prev_right_button = current_right_button;</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: #C586C0">if</span><span style="color: #D4D4D4"> (prev_left_button != current_left_button)</span></span>
<span class="line"><span style="color: #D4D4D4">		{</span></span>
<span class="line"><span style="color: #D4D4D4">			</span><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> (current_left_button)</span></span>
<span class="line"><span style="color: #D4D4D4">			{</span></span>
<span class="line"><span style="color: #D4D4D4">				</span><span style="color: #9CDCFE">mouse</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">press</span><span style="color: #D4D4D4">(MOUSE_LEFT);</span></span>
<span class="line"><span style="color: #D4D4D4">			}</span></span>
<span class="line"><span style="color: #D4D4D4">			</span><span style="color: #C586C0">else</span></span>
<span class="line"><span style="color: #D4D4D4">			{</span></span>
<span class="line"><span style="color: #D4D4D4">				</span><span style="color: #9CDCFE">mouse</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">release</span><span style="color: #D4D4D4">(MOUSE_LEFT);</span></span>
<span class="line"><span style="color: #D4D4D4">			}</span></span>
<span class="line"><span style="color: #D4D4D4">			prev_left_button = current_left_button;</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">wait_ms</span><span style="color: #D4D4D4">(</span><span style="color: #B5CEA8">10</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">	}</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<h2 class="wp-block-heading" id="h-testing-it-out">Testing it Out</h2>



<p class="wp-block-paragraph">Plug it into the PC and try out this retro joystick working with a modern machine!</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/mbed-joystick-and-controller.jpg" alt="joystick and controller"/></figure>



<p class="wp-block-paragraph">This is a great way to get a simple USB device going, but often a product will require more customization or non-supported USB class. If this is the case for you, <a href="/contact">come talk</a> to our <a href="/services/embedded-development-and-embedded-programming">embedded development and programming group</a> to see what solution makes sense for you!</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21018/trying-out-arm-mbed-oss-new-support-for-usb-device-with-some-retro-hardware/">Trying Out ARM Mbed OS’s New Support for USB Device with Some Retro Hardware</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>DMC&#8217;s Custom Bootloader</title>
		<link>https://static.dmcinfo.com/blog/21075/dmcs-custom-bootloader/</link>
		
		<dc:creator><![CDATA[Zachary Gracia]]></dc:creator>
		<pubDate>Thu, 22 Aug 2019 13:44:10 +0000</pubDate>
				<category><![CDATA[Circuit Design]]></category>
		<category><![CDATA[Embedded Development & Programming]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[Microcontroller Programming]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/21075/dmcs-custom-bootloader/</guid>

					<description><![CDATA[<p>For anyone who has worked on an embedded project, you can understand the hassle of loading code onto a microcontroller. To alleviate this issue and cut down on the extra time that comes from this process, DMC designed and built a custom boot loading tool. This boot loader communicates with MCUs using UART (Universal Asynchronous [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21075/dmcs-custom-bootloader/">DMC&#8217;s Custom Bootloader</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">For anyone who has worked on an <a href="/services/embedded-development-and-embedded-programming">embedded project</a>, you can understand the hassle of loading code onto a microcontroller. To alleviate this issue and cut down on the extra time that comes from this process, DMC designed and built a custom boot loading tool. This boot loader communicates with MCUs using UART (Universal Asynchronous Receiver/Transmitter). UART communication uses physical circuitry to send and receive serial data between two devices.</p>

<figure class="wp-block-image"><img decoding="async" alt="dmc custom bootloader" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/dmc-custom-bootloader-edited.png"  /></figure>

<p class="wp-block-paragraph">The DMC boot loader has three important features that help improve its use. The first of which is it has an onboard micro USB port. This port allows for serial communication with a CPU via a USB to micro USB cord (like you would use to charge a phone).</p>

<p class="wp-block-paragraph">The second important feature of the boot loader is that it has onboard reset and boot buttons. This allows for the user to easily put their MCU into boot loading mode by resetting the MCU while pressing the bootloader button.</p>

<p class="wp-block-paragraph">The third feature of this board that is important is the five-pin connector. This connector is how the bootloader communicates with the target MCU.</p>

<p class="wp-block-paragraph">For most DMC embedded projects, there is a standard 5 pin header that is compatible with the boot loader&rsquo;s connector. Through this mounting, we can send and receive the serial data, as well as reset and put the board into boot loading mode. Even if a board doesn&rsquo;t have a compatible mount, you can manually connect the boot loader&rsquo;s TX, RX, boot, ground, and reset pins to the appropriate locations on the target board to achieve the same functionality.</p>

<p class="wp-block-paragraph">This tool is one example of many internal initiatives DMC has undertaken to be more efficient and profitable.</p>

<p class="wp-block-paragraph">Learn more about <a href="/services/embedded-development-and-embedded-programming">DMC&apos;s Embedded Development and Programming Solutions</a>. <a href="/contact">Contact us</a> for additional information.</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21075/dmcs-custom-bootloader/">DMC&#8217;s Custom Bootloader</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Oxidizing Bare Metal: Rust Programming for ARM Microcontrollers</title>
		<link>https://static.dmcinfo.com/blog/21750/oxidizing-bare-metal-rust-programming-for-arm-microcontrollers/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Fri, 19 Apr 2019 12:33:02 +0000</pubDate>
				<category><![CDATA[Embedded Development & Programming]]></category>
		<category><![CDATA[Low-Power Embedded Design]]></category>
		<category><![CDATA[Product Development]]></category>
		<category><![CDATA[ARM Microcontrollers]]></category>
		<category><![CDATA[Embedded Systems]]></category>
		<category><![CDATA[Microcontroller Programming]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/21750/oxidizing-bare-metal-rust-programming-for-arm-microcontrollers-4/</guid>

					<description><![CDATA[<p>Being an embedded systems developer is always an exciting challenge. One of the downsides though is that in general, programming and development tools are somewhat limited. Developers are almost always restricted to C/C++ and often can&#8217;t rely on more extensive open source libraries. However, recently there have been many efforts to expand high-level language support [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21750/oxidizing-bare-metal-rust-programming-for-arm-microcontrollers/">Oxidizing Bare Metal: Rust Programming for ARM Microcontrollers</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Being an <a href="/services/embedded-development-and-embedded-programming">embedded systems developer</a> is always an exciting challenge. One of the downsides though is that in general, programming and development tools are somewhat limited. Developers are almost always restricted to C/C++ and often can&#8217;t rely on more extensive open source libraries. However, recently there have been many efforts to expand high-level language support to ARM-based bare metal targets.</p>



<p class="wp-block-paragraph">Projects using MicroPython and JerryScript attempt to provide a means to write Python and JavaScript code and provide frameworks for “compiling” and running scripts on a variety of bare-metal targets. However, these types of frameworks have some inherent drawbacks. JavaScript and Python are both interpreted languages with garbage collection and weak typing. Running these languages requires relying on&nbsp;a run time or more complex cross compiler.</p>



<h2 class="wp-block-heading" id="h-a-new-language-for-embedded-systems">A New Language for Embedded Systems</h2>



<p class="wp-block-paragraph">More recently, Rust has emerged as an appealing language for applications that require <strong>memory safety and efficiency</strong>. Both of these features are often critical for embedded devices. Manual memory management often creates bugs which are hard to isolate and are not always easily remedied due to the resource constraints of embedded devices.</p>



<p class="wp-block-paragraph">Additionally, C/C++, even given all of its faults, remains a highly efficient language due to the control it provides developers and because it can use many target-specific optimizations at compile time. C/C++ sets a high benchmark for speed that is difficult for interpreted languages to match.</p>



<p class="wp-block-paragraph">Rust, fortunately, solves both problems in ways that are particularly well suited to <a href="/services/embedded-development-and-embedded-programming/embedded-systems-platforms">microcontrollers</a>. Rust does not require any run-time engine for garbage collection or memory management. Rust instead chooses to enforce memory safety at compile time. Furthermore, because Rust compiles to LLVM, target optimizations rivaling those achievable with C/C++ are possible. Recently, the Rust core team has made support for new target architectures a priority, and there are already many open source projects aimed at expanding support for embedded devices in Rust.</p>



<p class="wp-block-paragraph"><img decoding="async" alt="" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Rust-Board-3.jpg"><span style="font-size:12px;"><em>Nucleo PCB Running on Rust</em></span></p>



<h2 class="wp-block-heading" id="h-getting-started-with-rust">Getting Started with Rust</h2>



<p class="wp-block-paragraph">The <a href="https://docs.rust-embedded.org/book/index.html" target="_blank">Embedded Rust Book</a> provides many details regarding getting started with Rust on embedded devices. For this blog, I’ll highlight a few key components that make up the Rust embedded landscape. Specifically, I’ll be discussing support for <strong>ARM Cortex M based microcontrollers</strong>.</p>



<p class="wp-block-paragraph">The Rust ecosystem is built on an extensive library of packages called “Crates.” A few specific crates, “cortex-m” and “cortex-m-rt”, make up the core support for ARM targets. These packages provide the bare minimum of code to get a basic program up and running. It allows access and control of the core ARM registers.</p>



<p class="wp-block-paragraph">Below is an example of setting up the systick peripheral taken from the Rust Embedded Book.</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">Rust</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>use cortex_m::peripheral::{syst, Peripherals};
use cortex_m_rt::entry;

#&#91;entry&#93;
fn main() -> ! {
    let mut peripherals = Peripherals::take().unwrap();
    let mut systick = peripherals.SYST;
    systick.set_clock_source(syst::SystClkSource::Core);
    systick.set_reload(1_000);
    systick.clear_current();
    systick.enable_counter();
    while !systick.has_wrapped() {
        // Loop
    }

    loop {}
}</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: #569CD6">use</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">cortex_m</span><span style="color: #D4D4D4">::</span><span style="color: #4EC9B0">peripheral</span><span style="color: #D4D4D4">::{syst, </span><span style="color: #4EC9B0">Peripherals</span><span style="color: #D4D4D4">};</span></span>
<span class="line"><span style="color: #569CD6">use</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">cortex_m_rt</span><span style="color: #D4D4D4">::entry;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">#&#91;entry&#93;</span></span>
<span class="line"><span style="color: #569CD6">fn</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">main</span><span style="color: #D4D4D4">() -&gt; ! {</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">mut</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">peripherals</span><span style="color: #D4D4D4"> = </span><span style="color: #4EC9B0">Peripherals</span><span style="color: #D4D4D4">::</span><span style="color: #DCDCAA">take</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">unwrap</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">mut</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">systick</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">peripherals</span><span style="color: #D4D4D4">.SYST;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">systick</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">set_clock_source</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">syst</span><span style="color: #D4D4D4">::</span><span style="color: #4EC9B0">SystClkSource</span><span style="color: #D4D4D4">::</span><span style="color: #4EC9B0">Core</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">systick</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">set_reload</span><span style="color: #D4D4D4">(</span><span style="color: #B5CEA8">1_000</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">systick</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">clear_current</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">systick</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">enable_counter</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">while</span><span style="color: #D4D4D4"> !</span><span style="color: #9CDCFE">systick</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">has_wrapped</span><span style="color: #D4D4D4">() {</span></span>
<span class="line"><span style="color: #6A9955">        // Loop</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: #C586C0">loop</span><span style="color: #D4D4D4"> {}</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">To implement something more interesting than a simple timer, we’ll need a <strong>Peripheral Access</strong> crate. These crates are typically specific to a <a href="/services/embedded-development-and-embedded-programming/embedded-systems-platforms">vendor and family</a> of microcontrollers. For example, the <strong>STM32F4 crate</strong> provides an API for accessing various peripherals such as GPIO, UART, and I2C for the STM32F4 family of devices.</p>



<p class="wp-block-paragraph">Pulling in a Peripheral Access crate, we can build a program for toggling an LED:</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">Rust</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>fn main() -> ! {
    let mut peripherals = stm32f429::Peripherals::take().unwrap();

    //Enable gpio b clock
    let rcc = &amp;peripherals.RCC;
    rcc.ahb1enr.write(|w| w.gpioben().bit(true));

    //set pin 14 to output
    let gpio = &amp;peripherals.GPIOB;
    gpio.moder.write(|w| w.moder14().bits(1));

    //Turn on led
    gpio.odr.write(|w| w.odr14().set_bit());

    loop {

        delay(10000);
        if  gpio.odr.read().odr14().bit()
        {
            gpio.odr.write(|w| w.odr14().clear_bit());
        }
        else {
            gpio.odr.write(|w| w.odr14().set_bit());
        }
        
    }
}

fn delay(count: u32) {
     for _ in 0..count { cortex_m::asm::nop() }
}</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: #569CD6">fn</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">main</span><span style="color: #D4D4D4">() -&gt; ! {</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">mut</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">peripherals</span><span style="color: #D4D4D4"> = </span><span style="color: #4EC9B0">stm32f429</span><span style="color: #D4D4D4">::</span><span style="color: #4EC9B0">Peripherals</span><span style="color: #D4D4D4">::</span><span style="color: #DCDCAA">take</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">unwrap</span><span style="color: #D4D4D4">();</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">    //Enable gpio b clock</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">rcc</span><span style="color: #D4D4D4"> = &amp;</span><span style="color: #9CDCFE">peripherals</span><span style="color: #D4D4D4">.RCC;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">rcc</span><span style="color: #D4D4D4">.ahb1enr.</span><span style="color: #DCDCAA">write</span><span style="color: #D4D4D4">(|</span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">| </span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">gpioben</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">bit</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">true</span><span style="color: #D4D4D4">));</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">    //set pin 14 to output</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">gpio</span><span style="color: #D4D4D4"> = &amp;</span><span style="color: #9CDCFE">peripherals</span><span style="color: #D4D4D4">.GPIOB;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">gpio</span><span style="color: #D4D4D4">.moder.</span><span style="color: #DCDCAA">write</span><span style="color: #D4D4D4">(|</span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">| </span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">moder14</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">bits</span><span style="color: #D4D4D4">(</span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4">));</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">    //Turn on led</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">gpio</span><span style="color: #D4D4D4">.odr.</span><span style="color: #DCDCAA">write</span><span style="color: #D4D4D4">(|</span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">| </span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">odr14</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">set_bit</span><span style="color: #D4D4D4">());</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">loop</span><span style="color: #D4D4D4"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #DCDCAA">delay</span><span style="color: #D4D4D4">(</span><span style="color: #B5CEA8">10000</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">if</span><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">gpio</span><span style="color: #D4D4D4">.odr.</span><span style="color: #DCDCAA">read</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">odr14</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">bit</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">gpio</span><span style="color: #D4D4D4">.odr.</span><span style="color: #DCDCAA">write</span><span style="color: #D4D4D4">(|</span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">| </span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">odr14</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">clear_bit</span><span style="color: #D4D4D4">());</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">else</span><span style="color: #D4D4D4"> {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">gpio</span><span style="color: #D4D4D4">.odr.</span><span style="color: #DCDCAA">write</span><span style="color: #D4D4D4">(|</span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">| </span><span style="color: #9CDCFE">w</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">odr14</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">set_bit</span><span style="color: #D4D4D4">());</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">fn</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">delay</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">count</span><span style="color: #D4D4D4">: </span><span style="color: #4EC9B0">u32</span><span style="color: #D4D4D4">) {</span></span>
<span class="line"><span style="color: #D4D4D4">     </span><span style="color: #C586C0">for</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">_</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">in</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">..</span><span style="color: #9CDCFE">count</span><span style="color: #D4D4D4"> { </span><span style="color: #4EC9B0">cortex_m</span><span style="color: #D4D4D4">::</span><span style="color: #4EC9B0">asm</span><span style="color: #D4D4D4">::</span><span style="color: #DCDCAA">nop</span><span style="color: #D4D4D4">() }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">Although Rust is an exciting new option for embedded development, it will take some time for it to supplant C/C++ as the standard. A lack of official support from major silicon vendors like <a href="/services/embedded-development-and-embedded-programming/embedded-systems-platforms">ST, NXP, and Silicon Labs</a> means that adding support for new microcontrollers can be a tedious process. Additionally, C/C++ frameworks like ARM&#8217;s mbed offer large, general purpose libraries and drivers that can be used across a variety of ARM targets with little to no modification.</p>



<p class="wp-block-paragraph">Learn more about DMC&#8217;s <a href="/services/embedded-development-and-embedded-programming/product-development">Embedded Product Development</a> Services and <a href="/services/embedded-development-and-embedded-programming/embedded-systems-platforms">Embedded Systems Platforms</a> expertise.</p>
<p>The post <a href="https://static.dmcinfo.com/blog/21750/oxidizing-bare-metal-rust-programming-for-arm-microcontrollers/">Oxidizing Bare Metal: Rust Programming for ARM Microcontrollers</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
