<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Illuminated Craft]]></title><description><![CDATA[The journey from a concept to a product.]]></description><link>https://illuminatedcraft.com</link><image><url>https://substackcdn.com/image/fetch/$s_!Z9Tv!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560201c6-af1b-4ba7-b0be-1556e8902719_1024x1024.png</url><title>Illuminated Craft</title><link>https://illuminatedcraft.com</link></image><generator>Substack</generator><lastBuildDate>Wed, 06 May 2026 11:10:03 GMT</lastBuildDate><atom:link href="https://illuminatedcraft.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Yuriy Nemtsov]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[illuminatedcraft@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[illuminatedcraft@substack.com]]></itunes:email><itunes:name><![CDATA[Yuriy Nemtsov]]></itunes:name></itunes:owner><itunes:author><![CDATA[Yuriy Nemtsov]]></itunes:author><googleplay:owner><![CDATA[illuminatedcraft@substack.com]]></googleplay:owner><googleplay:email><![CDATA[illuminatedcraft@substack.com]]></googleplay:email><googleplay:author><![CDATA[Yuriy Nemtsov]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Let’s Light an LED]]></title><description><![CDATA[ARM Microcontroller Basics]]></description><link>https://illuminatedcraft.com/p/lets-light-an-led</link><guid isPermaLink="false">https://illuminatedcraft.com/p/lets-light-an-led</guid><dc:creator><![CDATA[Yuriy Nemtsov]]></dc:creator><pubDate>Thu, 26 Dec 2024 06:58:42 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/4d3b0ac9-3df3-43e4-a8b8-ede0a196f69b_1536x1536.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>I&#8217;m an amateur hardware tinkerer, learning the basics of electronics, PCB design and programming a microcontroller. I&#8217;ve been at it for the last two years as a hobby and truly appreciate your feedback. Playing with hardware has been a source of joy in my life, so this post is my way of sharing what I&#8217;ve learned, hoping to smooth the journey for anyone starting down a similar path. Let&#8217;s dive in!</em></p><h2>What you&#8217;ll learn</h2><ol><li><p><strong>How to light an LED with an STM32 microcontroller</strong> by configuring GPIO pins </p></li><li><p><strong>The basics of microcontroller registers</strong> and how to manipulate them directly</p></li><li><p><strong>A step-by-step guide</strong> to writing assembly and C code for controlling an LED</p><p></p></li></ol><p>I&#8217;ve been working on the driver for an array of 110 <a href="https://en.wikipedia.org/wiki/Charlieplexing">Charlieplexed</a> LEDs of a countdown timer. The microcontroller is <a href="https://www.st.com/en/microcontrollers-microprocessors/stm32l010k4.html">STM32L010K4</a>. It&#8217;s a solid ultra-low-power 32 Mhz chip, with 16 Kb of Flash memory and a whopping 2 Kb of RAM. <em>(I mostly chose it because it was first in the massive lineup of STM32 micros, thinking it&#8217;ll be faster to learn on the chip with the fewest peripherals.</em>) I designed the LEDs to sit in a circle and two arcs, representing the minutes (inner), hours (middle) and days (outer):</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://illuminatedcraft.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Illuminated Craft! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!V9C5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!V9C5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 424w, https://substackcdn.com/image/fetch/$s_!V9C5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 848w, https://substackcdn.com/image/fetch/$s_!V9C5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 1272w, https://substackcdn.com/image/fetch/$s_!V9C5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!V9C5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png" width="728" height="735.1154551007942" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1653,&quot;width&quot;:1637,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:447401,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!V9C5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 424w, https://substackcdn.com/image/fetch/$s_!V9C5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 848w, https://substackcdn.com/image/fetch/$s_!V9C5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 1272w, https://substackcdn.com/image/fetch/$s_!V9C5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206636d2-37f4-4b7e-8cad-8d4b2b2fefcd_1637x1653.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>In retrospect, I could have added an LED driver chip (e.g. <a href="https://www.digikey.com/en/products/detail/lumissil-microsystems/IS31FL3746A-QFLS4-TR/9759696">IS31FL3746A</a>) and saved myself a ton of trouble, but one MCU seemed simpler when I started, and now that I&#8217;ve laid out the PCB <em>(by-hand on a proto-board first, with over 300 solder joints, but I&#8217;ll save that story for another time)</em> and programmed a working driver, a dedicated chip for this purpose doesn&#8217;t seem necessary. I&#8217;m also happy I took the path if only for the learnings.</p><p></p><h2><strong>Controlling LEDs</strong></h2><p>In case you are like me from about a year ago, the way you turn on an LED in this environment is by toggling a bit in a very specific memory location. It is a bit that corresponds to one of the general purpose input and output (GPIO) pins of the microcontroller. These two in the picture below&#8212;<em>which my first LED is connected to</em>&#8212; for example are pins <strong>7</strong> and <strong>14</strong>, which from the <a href="https://www.st.com/resource/en/datasheet/stm32l010k4.pdf">datasheet</a> we know are pins <strong>PA1</strong> and <strong>PB0</strong> respectively; which in turn means they&#8217;re on the GPIOA and GPIOB pin group respectively&#8212;all facts that will help us find their address.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cuH4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cuH4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 424w, https://substackcdn.com/image/fetch/$s_!cuH4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 848w, https://substackcdn.com/image/fetch/$s_!cuH4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 1272w, https://substackcdn.com/image/fetch/$s_!cuH4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cuH4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png" width="228" height="221.71428571428572" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:776,&quot;width&quot;:798,&quot;resizeWidth&quot;:228,&quot;bytes&quot;:70212,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cuH4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 424w, https://substackcdn.com/image/fetch/$s_!cuH4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 848w, https://substackcdn.com/image/fetch/$s_!cuH4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 1272w, https://substackcdn.com/image/fetch/$s_!cuH4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0988b51-2086-4d90-9a3f-55c9c5cbe10a_798x776.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The <a href="https://www.st.com/resource/en/reference_manual/rm0451-ultralowpower-stm32l0x0-advanced-armbased-32bit-mcus-stmicroelectronics.pdf">reference manual</a> that came with the MCU <em>(page 40</em> <em>of 784 btw)</em> has a memory map showing that the controller&#8217;s Peripherals/IOPORTs are somewhere between <strong>0x50000000</strong> and <strong>0x50001FFF</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PWM0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PWM0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 424w, https://substackcdn.com/image/fetch/$s_!PWM0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 848w, https://substackcdn.com/image/fetch/$s_!PWM0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 1272w, https://substackcdn.com/image/fetch/$s_!PWM0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PWM0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png" width="608" height="590.0981461286805" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1780,&quot;width&quot;:1834,&quot;resizeWidth&quot;:608,&quot;bytes&quot;:262105,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PWM0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 424w, https://substackcdn.com/image/fetch/$s_!PWM0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 848w, https://substackcdn.com/image/fetch/$s_!PWM0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 1272w, https://substackcdn.com/image/fetch/$s_!PWM0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848ddaa5-77a8-48f4-a4cf-8a29300a14cb_1834x1780.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And a page below, we can spot that <strong>GPIOA</strong> starts at 0x5000<strong>0000</strong> and <strong>GPIOB</strong> starts at 0x5000<strong>0400:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UMts!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UMts!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 424w, https://substackcdn.com/image/fetch/$s_!UMts!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 848w, https://substackcdn.com/image/fetch/$s_!UMts!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 1272w, https://substackcdn.com/image/fetch/$s_!UMts!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UMts!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png" width="556" height="267.68186638388124" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:908,&quot;width&quot;:1886,&quot;resizeWidth&quot;:556,&quot;bytes&quot;:218822,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UMts!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 424w, https://substackcdn.com/image/fetch/$s_!UMts!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 848w, https://substackcdn.com/image/fetch/$s_!UMts!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 1272w, https://substackcdn.com/image/fetch/$s_!UMts!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e596491-98e6-4919-9f86-66af7bf94456_1886x908.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>To connect an LED with its anode (+) attached to that <strong>PB0</strong> (GPIOB / pin <strong>14</strong>) and the cathode (-) attached to <strong>PA1</strong> (GPIOA / pin <strong>7</strong>), we have to make sure PB0 is sending a voltage <em>(3.3V in my case)</em> and PA1 is acting as ground. And we do that by (1) first configuring the mode of these pins to &#8220;general purpose output mode&#8221;<em>,</em> followed by (2) toggling a bit corresponding to pin 14 in the bit set/reset register (BSRR) of GPIOB. I&#8217;ll explain how this works in a bit, but long story short, those three steps are:</p><pre><code><code>1. </code><strong>0x50000000</strong> &#8592; 0xEBFFFCF<strong>7</strong>
   <strong>0x50000400</strong> &#8592; 0xFFFFFFF<strong>D</strong>
2. 0x50000<strong>418</strong> &#8592; <strong>1</strong></code></pre><p>The first question you may have is where the <a href="https://www.google.com/search?q=0xEBFFFCF7+in+binary">0xEBFFFCF7</a><code> </code>(E:1110 B:1011 F:1111 F:1111 F:1111 C:1100 F:1111 7:0111),<code> </code><a href="https://www.google.com/search?q=0xFFFFFFFD+in+binary">0xFFFFFFFD</a> (F:1111 F:1111 F:1111 F:1111 F:1111 F:1111 F:1111 D:1101),<code> </code>and 1 came from. To answer that, below is another snippet from the reference manual. It shows the bits that you need to set to configure the mode of GPIOA and GPIOB:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4HXc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4HXc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 424w, https://substackcdn.com/image/fetch/$s_!4HXc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 848w, https://substackcdn.com/image/fetch/$s_!4HXc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 1272w, https://substackcdn.com/image/fetch/$s_!4HXc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4HXc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png" width="1456" height="858" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:858,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:210495,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4HXc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 424w, https://substackcdn.com/image/fetch/$s_!4HXc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 848w, https://substackcdn.com/image/fetch/$s_!4HXc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 1272w, https://substackcdn.com/image/fetch/$s_!4HXc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03e37bed-e70c-4c37-ae43-53119f867735_1954x1152.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Let&#8217;s tackle <code>0xFFFFFFFD</code> <em>(GPIOB_MODER value)</em> first. <strong>F</strong> in hex translates to <strong>1111</strong>, of course,<strong> </strong>and<strong> D </strong>is<strong> 1101, </strong>so<strong> </strong><code>0xFFFFFFFD</code> (F:1111 F:1111 F:1111 F:1111 F:1111 F:1111 F:1111 D:1101) is:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qdm-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qdm-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 424w, https://substackcdn.com/image/fetch/$s_!qdm-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 848w, https://substackcdn.com/image/fetch/$s_!qdm-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 1272w, https://substackcdn.com/image/fetch/$s_!qdm-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qdm-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png" width="1456" height="386" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:386,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150861,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qdm-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 424w, https://substackcdn.com/image/fetch/$s_!qdm-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 848w, https://substackcdn.com/image/fetch/$s_!qdm-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 1272w, https://substackcdn.com/image/fetch/$s_!qdm-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F969063ee-4441-4885-8c10-ee3724ecd005_2790x740.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You see, all of the pins except the 0th pin, are set to &#8220;<strong>11</strong>: Analog mode (reset state)&#8221; and pin 0 of GPIOB is &#8220;<strong>01</strong>: General purpose output mode&#8221;.</p><p><code>0xEBFFFCF7</code><strong> </strong><em>(GPIOA_MODER value) </em>on the other hand uses the same idea, except instead of all analog mode, the GPIOA starts out in a different reset state. If you look at the picture 8.4.1 above, note that below the bold title it reads, <strong>&#8220;Reset value: 0xEBFF FCFF for port A&#8221;</strong> because some of the pins, by default, are set to analog mode (14 &amp; 13) and input mode (4) to enable programming and debugging the microcontroller on certain pins. And we set pin 1 to &#8220;general purpose output&#8221;. So, <code>0xEBFFFCF7</code><strong> </strong>(E:1110 B:1011 F:1111 F:1111 F:1111 C:1100 F:1111 7:0111) :</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yKep!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yKep!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 424w, https://substackcdn.com/image/fetch/$s_!yKep!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 848w, https://substackcdn.com/image/fetch/$s_!yKep!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 1272w, https://substackcdn.com/image/fetch/$s_!yKep!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yKep!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png" width="1456" height="397" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:397,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:204670,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yKep!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 424w, https://substackcdn.com/image/fetch/$s_!yKep!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 848w, https://substackcdn.com/image/fetch/$s_!yKep!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 1272w, https://substackcdn.com/image/fetch/$s_!yKep!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa439113-dc33-4a7a-8c24-93c8e567551e_3252x886.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Being able to simultaneously configure sixteen pins&#8217; modes is rather beautiful in my opinion, but not easy to grasp at first.</p><p>Finally, the <code>1</code> <em>(in 0x50000<strong>418</strong> &#8592; <strong>1</strong>)</em> is set into the bit set and reset register <em>(BSRR)</em> to send voltage to the 0th pin of the GPIOB:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CsLZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CsLZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 424w, https://substackcdn.com/image/fetch/$s_!CsLZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 848w, https://substackcdn.com/image/fetch/$s_!CsLZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!CsLZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CsLZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png" width="1456" height="908" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:908,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:238982,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CsLZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 424w, https://substackcdn.com/image/fetch/$s_!CsLZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 848w, https://substackcdn.com/image/fetch/$s_!CsLZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!CsLZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff383a2f0-400a-42da-a109-17d43a6858e9_1954x1218.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Notice the &#8220;Address offset <strong>0x18</strong>&#8221; on top. Knowing that GPIOB is at 0x50000<strong>400</strong> + 0x<strong>18</strong> tells us that the BSRR for GPIOB is <strong>0x50000418</strong>. So to &#8220;SET&#8221; the 0th bit to 1 we must write 1 into the memory at that address.</p><p></p><p>Here&#8217;s the whole sequence in <strong>assembly</strong>:</p><pre><code>ldr r0, =<strong>0x50000000</strong>    // load the <strong>GPIOA</strong> address into register r0
ldr r1, =0xEBFFFCF<strong>7</strong>    // load the <strong>mode</strong> for GPIOA into register r1
str r1, [r0, #0x00]    // write value of r1 into address at r0

ldr r0, =<strong>0x50000400</strong>    // same as above but for <strong>GPIOB</strong>
ldr r1, =0xFFFFFFF<strong>D</strong> 
str r1, [r0, #0x00]

ldr r1, =<strong>1</strong>             // load 1, which is pin 0 in PB0, into r1
str r1, [r0, #<strong>0x18</strong>]    // write that 1 into GPIOB with BSRR offset of 18</code></pre><p>And in <strong>C</strong>:</p><pre><code>*(volatile uint32_t *)(0x5000<strong>0000</strong>) = 0xEBFFFCF<strong>7</strong>;
*(volatile uint32_t *)(0x5000<strong>0400</strong>) = 0xFFFFFFF<strong>D</strong>;
*(volatile uint32_t *)(0x5000<strong>0418</strong>) = <strong>1</strong>;</code></pre><p>But, most likely, you&#8217;d want to at least use <strong>CMSIS</strong> (Cortex Microcontroller Software Interface Standard) on top, making the code a ton more readable:</p><pre><code>#include "stm32l010xb.h"

void turnOnLED() {
  GPIOA-&gt;MODER = 0xEBFFFCF<strong>7</strong>;
  GPIOB-&gt;MODER = 0xFFFFFFF<strong>D</strong>;
  GPIOB-&gt;BSRR = <strong>1</strong>;
}</code></pre><p>And to make life easier for us <em>(and avoid calculating that hex value ourselves)</em>, STM <em>(the maker of the micro)</em> maintains a library called <strong>HAL</strong> <em>(Hardware Abstraction Layer)</em>. Here&#8217;s what that looks like:</p><pre><code>#include "stm32l0xx_hal.h"

void turnOnLED() {
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  GPIO_InitStruct.Pin = GPIO_<strong>PIN_0</strong>;
  GPIO_InitStruct.Mode = <strong>GPIO_MODE_OUTPUT</strong>_PP;
  HAL_GPIO_Init(<strong>GPIOB</strong>, &amp;GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_<strong>PIN_1</strong>;
  HAL_GPIO_Init(<strong>GPIOA</strong>, &amp;GPIO_InitStruct);

  HAL_GPIO_WritePin(<strong>GPIOB</strong>, GPIO_<strong>PIN_0</strong>, GPIO_PIN_<strong>SET</strong>);
}</code></pre><p>For completeness&#8217; sake I&#8217;ll add that there&#8217;s just a bit more work you have to do before that code above works, that is to <strong>configure and enable the clocks</strong> that control GPIOA/B; but that part is handled by either the code generator / bootstrap tool that STM maintains called <strong><a href="https://www.st.com/en/development-tools/stm32cubemx.html">STM32CubeMX</a></strong> <em>(which I prefer to use along with VSCode)</em> or their IDE <strong><a href="https://www.st.com/en/development-tools/stm32cubeide.html">STM32CubeIDE</a>.</strong></p><p></p><p>There you have it: we set three values in three very specific sections of memory and that sends 3.3V to one pin, and makes sure the other acts as ground. And when it works for my timer, turning on a few LEDs looks a bit like this:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;feca937f-9571-465f-95c5-d9c9d55dbc32&quot;,&quot;duration&quot;:null}"></div><p></p><div><hr></div><p></p><p><em>This project is just a small step into the vast world of microcontroller programming. Understanding these fundamentals has been invaluable for me in tackling more complex challenges, and I hope it will do the same for you. Speaking of challenges, I&#8217;d love to share my journey&#8212;from not knowing how a resistor works (that was me two years ago!) to building a product I hope to one day see on a store shelf. If that sounds like fun, stay tuned for more!</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PB_n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PB_n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 424w, https://substackcdn.com/image/fetch/$s_!PB_n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 848w, https://substackcdn.com/image/fetch/$s_!PB_n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!PB_n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PB_n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg" width="2820" height="2109" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2109,&quot;width&quot;:2820,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1453001,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PB_n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 424w, https://substackcdn.com/image/fetch/$s_!PB_n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 848w, https://substackcdn.com/image/fetch/$s_!PB_n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!PB_n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81dca71-d1c5-40c8-b363-fc6437b0783c_2820x2109.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://illuminatedcraft.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://illuminatedcraft.com/subscribe?"><span>Subscribe now</span></a></p><p></p><p></p>]]></content:encoded></item></channel></rss>