<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="https://blog.implrust.com/feed_style.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <tabi:metadata xmlns:tabi="https://github.com/welpo/tabi">
        <tabi:base_url>https:&#x2F;&#x2F;blog.implrust.com</tabi:base_url>
        <tabi:separator>
            •
        </tabi:separator>
        <tabi:about_feeds>This is a web feed, also known as an Atom feed. Subscribe by copying the URL from the address bar into your newsreader. Visit About Feeds to learn more and get started. It&#x27;s free.</tabi:about_feeds>
        <tabi:visit_the_site>Visit website</tabi:visit_the_site>
        <tabi:recent_posts>Recent posts</tabi:recent_posts>
        <tabi:last_updated_on>Updated on $DATE</tabi:last_updated_on>
        <tabi:default_theme></tabi:default_theme>
        <tabi:post_listing_date>date</tabi:post_listing_date>
        <tabi:current_section>embedded-rust</tabi:current_section>
    </tabi:metadata><link rel="extra-stylesheet" href="https://blog.implrust.com/skins/lowcontrast_orange.css?h=43aaccb17d8ec616ace4" /><title>impl Blog for Rust - embedded-rust</title>
        <subtitle>impl Rust Blog Posts</subtitle>
    <link href="https://blog.implrust.com/tags/embedded-rust/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://blog.implrust.com/tags/embedded-rust/" rel="alternate" type="text/html"/>
    <generator uri="https://www.getzola.org/">Zola</generator><updated>2026-08-04T00:00:00+00:00</updated><id>https://blog.implrust.com/tags/embedded-rust/atom.xml</id><entry xml:lang="en">
        <title>Setting Up an Embedded Rust Development Environment</title>
        <published>2026-08-04T00:00:00+00:00</published>
        <updated>2026-08-04T00:00:00+00:00</updated>
        <author>
            <name>implFerris</name>
        </author>
        <link rel="alternate" href="https://blog.implrust.com/posts/2026/08/embedded-rust-development-environment/" type="text/html"/>
        <id>https://blog.implrust.com/posts/2026/08/embedded-rust-development-environment/</id>
        
            <content type="html">&lt;p&gt;When developing embedded applications with Rust, you will need to install a few tools on your computer.&lt;&#x2F;p&gt;
&lt;p&gt;If you’ve already written Rust programs on your desktop, most of the setup is already done. We only need to add support for embedded targets and install a few additional tools for flashing and debugging firmware.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;install-rust&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#install-rust&quot; aria-label=&quot;Anchor link for: install-rust&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Install Rust&lt;&#x2F;h2&gt;
&lt;p&gt;If you do not already have Rust installed, download and install it from the official Rust website. I recommend following the installation instructions on the official Rust website:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.org&#x2F;tools&#x2F;install&#x2F;&quot;&gt;https:&#x2F;&#x2F;rust-lang.org&#x2F;tools&#x2F;install&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;On Linux and macOS, you can install Rust by running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;curl&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; --proto&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;=https&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; --tlsv1.2 -sSf&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; https:&#x2F;&#x2F;sh.rustup.rs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;On Windows, download and run the installer from the Rust website.&lt;&#x2F;p&gt;
&lt;div class=&quot;admonition tip&quot;&gt;
    &lt;div class=&quot;admonition-icon admonition-icon-tip&quot;&gt;&lt;&#x2F;div&gt;
    &lt;div class=&quot;admonition-content&quot;&gt;
        &lt;strong class=&quot;admonition-title&quot;&gt;TIP&lt;&#x2F;strong&gt;
        &lt;p&gt;To be frank, if this is your first time learning Rust, I do not recommend jumping straight into Embedded Rust. Spend some time learning the basics of Rust first. It will make your Embedded Rust journey much easier.&lt;&#x2F;p&gt;
&lt;p&gt;After all, I assume you chose Rust not because you just want to copy and paste code. You want to understand how things work, enjoy the learning process, and benefit from the safety that Rust provides.&lt;&#x2F;p&gt;

    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;p&gt;Once the installation is complete, verify it by running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rustc&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rustup&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You should see the installed versions printed on the screen.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;install-the-arm-cortex-m-target&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#install-the-arm-cortex-m-target&quot; aria-label=&quot;Anchor link for: install-the-arm-cortex-m-target&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Install the ARM Cortex-M Target&lt;&#x2F;h2&gt;
&lt;p&gt;Rust supports many embedded architectures, including ARM Cortex-M, RISC-V, and Xtensa.&lt;&#x2F;p&gt;
&lt;p&gt;In this article, we’ll install the ARM Cortex-M targets, as they are used by many popular development boards such as the Raspberry Pi Pico, Raspberry Pi Pico W, Pico 2, and STM32 Blue Pill.&lt;&#x2F;p&gt;
&lt;div class=&quot;admonition note&quot;&gt;
    &lt;div class=&quot;admonition-icon admonition-icon-note&quot;&gt;&lt;&#x2F;div&gt;
    &lt;div class=&quot;admonition-content&quot;&gt;
        &lt;strong class=&quot;admonition-title&quot;&gt;NOTE&lt;&#x2F;strong&gt;
        &lt;p&gt;If you’re developing for an ESP32 board, the setup process is slightly different because ESP32 uses a different architecture. You’ll need to install the appropriate Rust target and development tools.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re looking for a step-by-step guide, I also have a dedicated free book on &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;esp32.implrust.com&#x2F;&quot;&gt;Embedded Rust with ESP32&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;

    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;p&gt;Different microcontrollers use different Cortex-M cores, so Rust provides a separate compilation target for each one.&lt;&#x2F;p&gt;
&lt;p&gt;Some common targets are:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Cortex-M Core&lt;&#x2F;th&gt;&lt;th&gt;Rust Target&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Cortex-M0 &#x2F; M0+&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;thumbv6m-none-eabi&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Cortex-M3&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;thumbv7m-none-eabi&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Cortex-M4 &#x2F; M7&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;thumbv7em-none-eabi&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Cortex-M4F &#x2F; M7F&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;thumbv7em-none-eabihf&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Cortex-M33&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;thumbv8m.main-none-eabihf&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Install the target for boards based on the ARM Cortex-M0+ core, such as the Raspberry Pi Pico and Pico W.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rustup&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; target add thumbv6m-none-eabi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Install the target for boards based on the ARM Cortex-M3 core, such as the STM32 Blue Pill (STM32F103).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rustup&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; target add thumbv7m-none-eabi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Install the target for boards based on the ARM Cortex-M33 core with hardware floating-point support, such as the Raspberry Pi Pico 2 (RP2350).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rustup&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; target add thumbv8m.main-none-eabihf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;install-probe-rs&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#install-probe-rs&quot; aria-label=&quot;Anchor link for: install-probe-rs&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Install probe-rs&lt;&#x2F;h2&gt;
&lt;p&gt;Once you’ve compiled your Embedded Rust application, you’ll need a way to flash it onto your development board and debug it. &lt;code&gt;probe-rs&lt;&#x2F;code&gt;, a modern tool for flashing, debugging, and interacting with embedded microcontrollers.&lt;&#x2F;p&gt;
&lt;p&gt;I recommend following the installation instructions on the official probe-rs website:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;probe.rs&#x2F;docs&#x2F;getting-started&#x2F;installation&#x2F;&quot;&gt;https:&#x2F;&#x2F;probe.rs&#x2F;docs&#x2F;getting-started&#x2F;installation&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Once the installation is complete, verify it by running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;probe-rs&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If the version is printed successfully, probe-rs is installed correctly.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;install-cargo-generate&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#install-cargo-generate&quot; aria-label=&quot;Anchor link for: install-cargo-generate&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Install cargo-generate&lt;&#x2F;h2&gt;
&lt;p&gt;When starting a new project, you’ll often need to create the same files and write the same configuration before you can begin writing code. &lt;code&gt;cargo-generate&lt;&#x2F;code&gt; is a tool that helps to create a new project from a template, so you don’t have to set up everything manually.&lt;&#x2F;p&gt;
&lt;p&gt;I normally use &lt;code&gt;cargo-generate&lt;&#x2F;code&gt; to create new projects from templates. There are many templates available from the community, and once you’re familiar with the Rust ecosystem, you can create your own templates, store them in a Git repository or local directory, and use them to generate future projects.&lt;&#x2F;p&gt;
&lt;p&gt;Install it by running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; install cargo-generate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Verify the installation by running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; generate&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;install-cargo-binutils-optional&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#install-cargo-binutils-optional&quot; aria-label=&quot;Anchor link for: install-cargo-binutils-optional&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Install cargo-binutils (Optional)&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;cargo-binutils&lt;&#x2F;code&gt; provides additional commands for inspecting compiled binaries. It can display firmware size, disassemble machine code, and inspect symbols.&lt;&#x2F;p&gt;
&lt;p&gt;While it isn’t required for Embedded Rust development, it can be useful when debugging or exploring what the compiler generated.&lt;&#x2F;p&gt;
&lt;p&gt;Install it by running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; install cargo-binutils&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;rustup&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; component add llvm-tools&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That’s it! Your Embedded Rust development environment is now ready.&lt;&#x2F;p&gt;
</content>
        <summary type="html">Set up a complete Embedded Rust development environment. Install Rust, configure the ARM Cortex-M target, install probe-rs, and verify your setup before programming embedded microcontrollers.</summary>
        </entry><entry xml:lang="en">
        <title>Analyzing PIO Blink Using Logic Analyzer on Raspberry Pi Pico with Embedded Rust</title>
        <published>2026-02-08T00:00:00+00:00</published>
        <updated>2026-02-08T00:00:00+00:00</updated>
        <author>
            <name>implFerris</name>
        </author>
        <link rel="alternate" href="https://blog.implrust.com/posts/2026/02/logic-analyzer-raspberry-pi-pico-pio/" type="text/html"/>
        <id>https://blog.implrust.com/posts/2026/02/logic-analyzer-raspberry-pi-pico-pio/</id>
        
            <content type="html">&lt;p&gt;In earlier posts, we used a logic analyzer to inspect simple GPIO signals and UART communication. In this post, we will use the logic analyzer to inspect a signal generated by PIO, which is specific to the Raspberry Pi Pico variants (RP2040 and RP2350 chips).&lt;&#x2F;p&gt;
&lt;p&gt;If you do not know what PIO is, I recommend checking the introduction in the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;rp2040.implrust.com&#x2F;pio&#x2F;index.html&quot;&gt;“impl Rust for RP2040”&lt;&#x2F;a&gt; book. I will still give a short overview here so that we are all on the same page before looking at logic analyzer captures.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;pio&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#pio&quot; aria-label=&quot;Anchor link for: pio&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
PIO&lt;&#x2F;h2&gt;
&lt;p&gt;PIO, short for Programmable I&#x2F;O, is a hardware block available on RP2040 and RP2350 microcontrollers. It allows us to write small programs that run independently of the main CPU and directly control GPIO pins.&lt;&#x2F;p&gt;
&lt;p&gt;Each PIO block contains a few state machines. A state machine executes instructions from a small instruction memory, one instruction at a time, and can drive pins, sample pins, and move data in and out through FIFOs.&lt;&#x2F;p&gt;
&lt;p&gt;The important part for this post is that PIO timing is instruction-driven. Unlike CPU code, where timing depends on compiler output, interrupts, and scheduling, PIO timing is deterministic. Each instruction takes a known number of cycles to execute.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;pio-clock-divider&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#pio-clock-divider&quot; aria-label=&quot;Anchor link for: pio-clock-divider&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
PIO Clock Divider&lt;&#x2F;h3&gt;
&lt;p&gt;Each PIO state machine has its own clock divider. This divider controls how fast instructions are executed.&lt;&#x2F;p&gt;
&lt;p&gt;On RP2040, the PIO instruction clock is derived from the system clock like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;state_machine_clock&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; = clk_sys &#x2F; clock_divider&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In our setup:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;System clock = 125 MHz&lt;&#x2F;li&gt;
&lt;li&gt;PIO clock divider = 65535&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So the instruction execution rate becomes:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;125,000,000&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &#x2F; 65,535 ≈ 1,907.38 instructions per second&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This means the PIO state machine executes roughly 1.9 thousand instructions per second.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;instruction-cycles-and-delays&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#instruction-cycles-and-delays&quot; aria-label=&quot;Anchor link for: instruction-cycles-and-delays&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Instruction Cycles and Delays&lt;&#x2F;h3&gt;
&lt;p&gt;By default, every PIO instruction takes exactly one instruction cycle to execute.&lt;&#x2F;p&gt;
&lt;p&gt;PIO also supports an instruction delay modifier, written using square brackets. For example:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;set&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; pins,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This means:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;1 cycle for the instruction itself&lt;&#x2F;li&gt;
&lt;li&gt;31 additional delay cycles&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So the total execution time for that instruction is 32 instruction cycles.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;time-per-instruction&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#time-per-instruction&quot; aria-label=&quot;Anchor link for: time-per-instruction&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Time Per Instruction&lt;&#x2F;h2&gt;
&lt;p&gt;Since we know the instruction execution rate, we can compute the time taken by one instruction cycle.&lt;&#x2F;p&gt;
&lt;p&gt;With a clock divider of 65535:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &#x2F; 1,907.38 s ≈&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.0005243&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; s&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That means approximately:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;0.524 ms (524,300 nanoseconds) per instruction cycle&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;project-source-code&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#project-source-code&quot; aria-label=&quot;Anchor link for: project-source-code&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Project Source Code&lt;&#x2F;h2&gt;
&lt;p&gt;You can clone the project used in this post from the following repository:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;git&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; clone https:&#x2F;&#x2F;github.com&#x2F;ImplFerris&#x2F;rp2040-projects&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; rp2040-projects&#x2F;embassy&#x2F;pio&#x2F;hello-blinky&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This project contains the exact PIO program and Embassy setup used for the logic analyzer measurements shown in this post.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;pio-program&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#pio-program&quot; aria-label=&quot;Anchor link for: pio-program&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Pio Program&lt;&#x2F;h3&gt;
&lt;p&gt;This is the PIO assembly program used to generate the blinking signal that we will analyze with the logic analyzer.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; prg&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; pio_asm!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;    set pindirs, 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;    loop:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        set pins, 1 [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        set pins, 0 [30]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        nop [31]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        jmp loop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This program runs in an infinite loop and drives a single GPIO pin HIGH and LOW.&lt;&#x2F;p&gt;
&lt;p&gt;The delays are added using the instruction delay modifier. Each instruction with [31] takes a total of 32 PIO cycles to execute. The one place where [30] is used is intentional. The jmp loop instruction takes one extra cycle while the pin is LOW, so reducing the delay on &lt;code&gt;set pins, 0&lt;&#x2F;code&gt; keeps the HIGH and LOW durations equal.&lt;&#x2F;p&gt;
&lt;p&gt;Because the program timing is entirely instruction-based, we can predict the exact HIGH time, LOW time, and output frequency before even connecting the logic analyzer.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;hardware-setup&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#hardware-setup&quot; aria-label=&quot;Anchor link for: hardware-setup&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Hardware Setup&lt;&#x2F;h2&gt;
&lt;p&gt;The hardware setup is very simple. We connect the logic analyzer to the same GPIO pin that drives the LED, so we can observe exactly what the LED sees.&lt;&#x2F;p&gt;
&lt;p&gt;The external LED is connected to GPIO15 through a resistor. The logic analyzer channel is connected in parallel to the same GPIO pin.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Source&lt;&#x2F;th&gt;&lt;th&gt;Connected To&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;GPIO15&lt;&#x2F;td&gt;&lt;td&gt;Resistor =&amp;gt; LED =&amp;gt; GND&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Logic Analyzer CH1&lt;&#x2F;td&gt;&lt;td&gt;GPIO15&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Logic Analyzer GND&lt;&#x2F;td&gt;&lt;td&gt;Pico GND&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;With this setup, the GPIO pin drives both the LED and the logic analyzer input at the same time. The LED gives us a visual confirmation of the blinking, while the logic analyzer lets us inspect the exact timing and waveform.&lt;&#x2F;p&gt;
&lt;p&gt;Make sure the logic analyzer ground and the Pico ground are connected. Without a common ground, the captured signal will be unreliable.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;start-the-capture&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#start-the-capture&quot; aria-label=&quot;Anchor link for: start-the-capture&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Start the Capture&lt;&#x2F;h2&gt;
&lt;p&gt;Open PulseView as usual. For this capture, I have configured the sample rate to 20 kHz and the number of samples to 1 million.&lt;&#x2F;p&gt;
&lt;p&gt;Once the settings are in place, click Run to start the capture. PulseView will record the signal and automatically stop once it reaches the configured number of samples.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;measuring-timing-with-cursors-in-pulseview&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#measuring-timing-with-cursors-in-pulseview&quot; aria-label=&quot;Anchor link for: measuring-timing-with-cursors-in-pulseview&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Measuring Timing with Cursors in PulseView&lt;&#x2F;h2&gt;
&lt;p&gt;Up to this point, we have been looking at captured waveforms mainly to understand their overall shape and behavior. To measure timing more precisely, PulseView provides a cursor feature that is very useful.&lt;&#x2F;p&gt;
&lt;p&gt;When you enable &lt;code&gt;Show Cursors&lt;&#x2F;code&gt; in PulseView, two movable time markers appear on the waveform. Each cursor represents a specific point in time on the capture. By placing the cursors on two edges or points of interest, PulseView shows the exact time difference between them.&lt;&#x2F;p&gt;
&lt;p&gt;This makes it easy to measure how long a signal stays HIGH, how long it stays LOW, or the full period of a repeating waveform.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;verifying-the-timing-on-the-logic-analyzer&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#verifying-the-timing-on-the-logic-analyzer&quot; aria-label=&quot;Anchor link for: verifying-the-timing-on-the-logic-analyzer&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Verifying the Timing on the Logic Analyzer&lt;&#x2F;h2&gt;
&lt;p&gt;With the capture complete, we can now use the cursors to measure the actual timing of the signal generated by PIO.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;img&#x2F;2026&#x2F;02&#x2F;logic-analyzer-show-cursors-pio.png&quot;  alt=&quot;logic-analyzer-show-cursors-pio&quot; style=&quot;width:400px; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;p&gt;In the capture above, the cursors are placed across one full HIGH-LOW cycle of the waveform. PulseView directly shows the measured period as roughly 268 ms, which corresponds to a frequency of about 3.7 Hz.&lt;&#x2F;p&gt;
&lt;p&gt;To understand why the measured period comes out to around 268 ms, let us now work through the timing of the PIO program step by step.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;high-phase-timing&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#high-phase-timing&quot; aria-label=&quot;Anchor link for: high-phase-timing&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
High Phase Timing&lt;&#x2F;h3&gt;
&lt;p&gt;The pin goes HIGH when the &lt;code&gt;set pins, 1&lt;&#x2F;code&gt; instruction executes and stays HIGH until &lt;code&gt;set pins, 0&lt;&#x2F;code&gt; executes.&lt;&#x2F;p&gt;
&lt;p&gt;While the pin is HIGH, the following instructions run:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;set pins, 1 [31]&lt;&#x2F;code&gt;&lt;br &#x2F;&gt;
The instruction itself takes 1 cycle, and the delay adds 31 more cycles.&lt;br &#x2F;&gt;
Total: 32 cycles&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;nop [31]&lt;&#x2F;code&gt; repeated 7 times&lt;br &#x2F;&gt;
Each &lt;code&gt;nop [31]&lt;&#x2F;code&gt; takes 32 cycles.&lt;br &#x2F;&gt;
Total: 7 x 32 = 224 cycles&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So the total number of instruction cycles while the pin is HIGH is:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;32&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 224&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 256&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; cycles&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With each instruction cycle taking about 0.524 ms, the total HIGH time becomes:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;256&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.524&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ms ≈&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 134&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ms&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;low-phase-timing&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#low-phase-timing&quot; aria-label=&quot;Anchor link for: low-phase-timing&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Low Phase Timing&lt;&#x2F;h3&gt;
&lt;p&gt;The LOW phase starts when &lt;code&gt;set pins, 0&lt;&#x2F;code&gt; executes and lasts until the program loops back and sets the pin HIGH again.&lt;&#x2F;p&gt;
&lt;p&gt;While the pin is LOW, the following instructions run:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;set pins, 0 [30]&lt;&#x2F;code&gt;&lt;br &#x2F;&gt;
The instruction itself takes 1 cycle, and the delay adds 30 more cycles.&lt;br &#x2F;&gt;
Total: 31 cycles&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;nop [31]&lt;&#x2F;code&gt; repeated 7 times&lt;br &#x2F;&gt;
Total: 7 x 32 = 224 cycles&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;jmp loop&lt;&#x2F;code&gt;&lt;br &#x2F;&gt;
This instruction takes 1 cycle&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So the total number of instruction cycles while the pin is LOW is:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;31&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 224&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 256&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; cycles&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This again gives:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;256&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.524&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ms ≈&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 134&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ms&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;putting-it-all-together&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#putting-it-all-together&quot; aria-label=&quot;Anchor link for: putting-it-all-together&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Putting It All Together&lt;&#x2F;h3&gt;
&lt;p&gt;From the instruction count, we end up with:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;HIGH time ≈ 134 ms&lt;&#x2F;li&gt;
&lt;li&gt;LOW time ≈ 134 ms&lt;&#x2F;li&gt;
&lt;li&gt;Full period ≈ 268 ms&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This matches approximately what we measured using the logic analyzer.&lt;&#x2F;p&gt;
</content>
        <summary type="html">In this post, we use a logic analyzer to study a GPIO signal generated by a PIO state machine on the RP2040. We derive the timing from instruction cycles and validate it on real hardware with Embedded Rust.</summary>
        </entry><entry xml:lang="en">
        <title>Working with Fixed-Point Numbers in Rust Using the fixed Crate</title>
        <published>2025-12-20T00:00:00+00:00</published>
        <updated>2025-12-20T00:00:00+00:00</updated>
        <author>
            <name>implFerris</name>
        </author>
        <link rel="alternate" href="https://blog.implrust.com/posts/2025/12/fixed-point-crate-in-rust/" type="text/html"/>
        <id>https://blog.implrust.com/posts/2025/12/fixed-point-crate-in-rust/</id>
        
            <content type="html">&lt;img src=&quot;&#x2F;img&#x2F;2025&#x2F;12&#x2F;fixed-point-number-illustration.png&quot;  alt=&quot;Fixed Point number illustration&quot; style=&quot;width:400px; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;p&gt;While revising the Pico Pico book (an embedded Rust book for the Raspberry Pi Pico 2), I was working on the PWM chapter for controlling servo motors. In that chapter, embassy-rp uses a fixed-point number to store the PWM clock divider. Both the integer and fractional parts are stored together in a single field called divider, using a type from the “fixed” crate.&lt;&#x2F;p&gt;
&lt;p&gt;Instead of explaining fixed-point numbers briefly there, I decided it made more sense to write a separate blog post. That is how this post came to be. Here, I will give a short introduction to fixed-point numbers and explain how to use them in Rust.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-fixed-point&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#what-is-fixed-point&quot; aria-label=&quot;Anchor link for: what-is-fixed-point&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
What is Fixed Point?&lt;&#x2F;h2&gt;
&lt;p&gt;A fixed-point number is a way to represent fractional (non-integer) values using only integer arithmetic. Unlike floating-point numbers (like &lt;code&gt;f32&lt;&#x2F;code&gt; or &lt;code&gt;f64&lt;&#x2F;code&gt;), fixed-point numbers reserve a predetermined number of bits for the fractional part. This makes them predictable, fast, and ideal for embedded systems where floating-point hardware might be unavailable or too slow.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;understanding-fixed-point-notation&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#understanding-fixed-point-notation&quot; aria-label=&quot;Anchor link for: understanding-fixed-point-notation&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Understanding Fixed-Point Notation&lt;&#x2F;h2&gt;
&lt;p&gt;This idea is explained well in the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;fixed&#x2F;&quot;&gt;fixed crate&lt;&#x2F;a&gt; documentation, but let me give a quick overview.&lt;&#x2F;p&gt;
&lt;p&gt;The key idea is this. If you have n total bits and you choose f bits for the fractional part, then you automatically have &lt;code&gt;n - f&lt;&#x2F;code&gt; bits left for the integer part. Once this split is chosen, the position of the decimal point is fixed.&lt;&#x2F;p&gt;
&lt;p&gt;Fixed-point numbers maintain uniform spacing between consecutive values throughout their range. The step size formula is &lt;code&gt;1&#x2F;2^f&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For example, consider a 16-bit fixed-point number where 4 bits are used for the fraction. Here, f = 4, so the remaining 16 - 4 = 12 bits are used for the integer part. With 4 fractional bits, the smallest step size is 1 &#x2F; 2⁴ = 0.0625. This means fractional values are represented as multiples of 0.0625. After 0.0625, the next value is 0.125, and the numbers continue to increase in fixed, evenly spaced steps.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;binary-representation&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#binary-representation&quot; aria-label=&quot;Anchor link for: binary-representation&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Binary Representation&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s use a 16-bit unsigned number as an example. Normally, to store an integer like 5, the binary representation would be &lt;code&gt;0000_0000_0000_0101&lt;&#x2F;code&gt;. With fixed-point representation, we dedicate a predetermined number of bits for the fractional part, depending on our precision needs. The remaining upper bits store the integer part.&lt;&#x2F;p&gt;
&lt;p&gt;For instance, if we allocate the last 4 bits for the fraction, we have 12 bits left for the integer.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;example-4-fractional-bits&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#example-4-fractional-bits&quot; aria-label=&quot;Anchor link for: example-4-fractional-bits&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Example: 4 Fractional bits&lt;&#x2F;h3&gt;
&lt;p&gt;Here’s how the bits map to their values:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Bit Position&lt;&#x2F;th&gt;&lt;th&gt;15&lt;&#x2F;th&gt;&lt;th&gt;14&lt;&#x2F;th&gt;&lt;th&gt;13&lt;&#x2F;th&gt;&lt;th&gt;12&lt;&#x2F;th&gt;&lt;th&gt;11&lt;&#x2F;th&gt;&lt;th&gt;10&lt;&#x2F;th&gt;&lt;th&gt;9&lt;&#x2F;th&gt;&lt;th&gt;8&lt;&#x2F;th&gt;&lt;th&gt;7&lt;&#x2F;th&gt;&lt;th&gt;6&lt;&#x2F;th&gt;&lt;th&gt;5&lt;&#x2F;th&gt;&lt;th&gt;4&lt;&#x2F;th&gt;&lt;th&gt;.&lt;&#x2F;th&gt;&lt;th&gt;3&lt;&#x2F;th&gt;&lt;th&gt;2&lt;&#x2F;th&gt;&lt;th&gt;1&lt;&#x2F;th&gt;&lt;th&gt;0&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Weight&lt;&#x2F;td&gt;&lt;td&gt;2¹¹&lt;&#x2F;td&gt;&lt;td&gt;2¹⁰&lt;&#x2F;td&gt;&lt;td&gt;2⁹&lt;&#x2F;td&gt;&lt;td&gt;2⁸&lt;&#x2F;td&gt;&lt;td&gt;2⁷&lt;&#x2F;td&gt;&lt;td&gt;2⁶&lt;&#x2F;td&gt;&lt;td&gt;2⁵&lt;&#x2F;td&gt;&lt;td&gt;2⁴&lt;&#x2F;td&gt;&lt;td&gt;2³&lt;&#x2F;td&gt;&lt;td&gt;2²&lt;&#x2F;td&gt;&lt;td&gt;2¹&lt;&#x2F;td&gt;&lt;td&gt;2⁰&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;2⁻¹&lt;&#x2F;td&gt;&lt;td&gt;2⁻²&lt;&#x2F;td&gt;&lt;td&gt;2⁻³&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁴&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;The decimal point (shown as &lt;code&gt;.&lt;&#x2F;code&gt; in the table) is just for our understanding, it doesn’t actually exist in memory. With 4 fractional bits, the smallest value we can represent is 2⁻⁴ = 0.0625, giving us a precision of 1&#x2F;16.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;example-8-fractional-bits&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#example-8-fractional-bits&quot; aria-label=&quot;Anchor link for: example-8-fractional-bits&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Example: 8 Fractional bits&lt;&#x2F;h3&gt;
&lt;p&gt;If we need more precision, we can allocate more bits to the fractional part. With 8 fractional bits, we get:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Bit Position&lt;&#x2F;th&gt;&lt;th&gt;15&lt;&#x2F;th&gt;&lt;th&gt;14&lt;&#x2F;th&gt;&lt;th&gt;13&lt;&#x2F;th&gt;&lt;th&gt;12&lt;&#x2F;th&gt;&lt;th&gt;11&lt;&#x2F;th&gt;&lt;th&gt;10&lt;&#x2F;th&gt;&lt;th&gt;9&lt;&#x2F;th&gt;&lt;th&gt;8&lt;&#x2F;th&gt;&lt;th&gt;.&lt;&#x2F;th&gt;&lt;th&gt;7&lt;&#x2F;th&gt;&lt;th&gt;6&lt;&#x2F;th&gt;&lt;th&gt;5&lt;&#x2F;th&gt;&lt;th&gt;4&lt;&#x2F;th&gt;&lt;th&gt;3&lt;&#x2F;th&gt;&lt;th&gt;2&lt;&#x2F;th&gt;&lt;th&gt;1&lt;&#x2F;th&gt;&lt;th&gt;0&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Weight&lt;&#x2F;td&gt;&lt;td&gt;2⁷&lt;&#x2F;td&gt;&lt;td&gt;2⁶&lt;&#x2F;td&gt;&lt;td&gt;2⁵&lt;&#x2F;td&gt;&lt;td&gt;2⁴&lt;&#x2F;td&gt;&lt;td&gt;2³&lt;&#x2F;td&gt;&lt;td&gt;2²&lt;&#x2F;td&gt;&lt;td&gt;2¹&lt;&#x2F;td&gt;&lt;td&gt;2⁰&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;2⁻¹&lt;&#x2F;td&gt;&lt;td&gt;2⁻²&lt;&#x2F;td&gt;&lt;td&gt;2⁻³&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁴&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁵&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁶&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁷&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁸&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;With 8 fractional bits, our smallest representable value is 2⁻⁸ = 0.00390625 (1&#x2F;256), giving us finer precision but reducing the maximum integer we can represent.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;fixed-crate-types&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#fixed-crate-types&quot; aria-label=&quot;Anchor link for: fixed-crate-types&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Fixed Crate Types&lt;&#x2F;h2&gt;
&lt;p&gt;The fixed crate provides fixed-point number types in different sizes. The number in the type name tells you how many bits are used in total.&lt;&#x2F;p&gt;
&lt;p&gt;For example, FixedI8 and FixedU8 are 8-bit fixed-point numbers. FixedI16 and FixedU16 are 16-bit types. In the same way, there are 32-bit, 64-bit, and even 128-bit fixed-point types, both signed (FixedI*) and unsigned (FixedU*).&lt;&#x2F;p&gt;
&lt;p&gt;What makes these types flexible is the extra generic parameter that controls how many bits are used for the fractional part. For example, &lt;code&gt;FixedU16&amp;lt;extra::U4&amp;gt;&lt;&#x2F;code&gt; is a 16-bit unsigned fixed-point number where 4 bits are used for the fraction. That leaves 16 - 4 = 12 bits for the integer part. If you use &lt;code&gt;FixedU16&amp;lt;U0&amp;gt;&lt;&#x2F;code&gt;, there are no fractional bits, so it behaves just like a normal u16.&lt;&#x2F;p&gt;
&lt;p&gt;The crate also provides convenient type aliases so you do not always have to write the generic form. For example, U12F4 represents a unsigned fixed-point number with 12 integer bits and 4 fractional bits. You can use it directly like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;types&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;U12F4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;example-1&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#example-1&quot; aria-label=&quot;Anchor link for: example-1&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Example 1&lt;&#x2F;h2&gt;
&lt;p&gt;Create a new Rust project, add the &lt;code&gt;fixed&lt;&#x2F;code&gt; crate as a dependency, and replace main.rs with the following code.&lt;&#x2F;p&gt;
&lt;p&gt;To make things easier to understand, the example prints the same value in several different forms.&lt;&#x2F;p&gt;
&lt;p&gt;First, it prints the fixed-point value itself. The :.4 formatting is only for display and shows four digits after the decimal point.&lt;&#x2F;p&gt;
&lt;p&gt;Next, it uses helper methods from the fixed crate to print the fractional part and the integer part separately.&lt;&#x2F;p&gt;
&lt;p&gt;Then it prints the binary representation in two different ways.&lt;&#x2F;p&gt;
&lt;p&gt;The first binary print ({:b}) is a human-friendly representation provided by the fixed crate. It inserts a binary point to show where the fractional bits are. This can feel a little confusing at first glance, at least it did for me. But once you get used to reading it, it actually becomes easier to reason about fixed-point values.&lt;&#x2F;p&gt;
&lt;p&gt;The second binary print uses to_bits(), which returns the raw 16-bit value stored internally. For clarity, the integer bits and the fractional bits are manually separated with an underscore when printing.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;FixedU16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; types&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;extra&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;types&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; main&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;    &#x2F;&#x2F; let f_u16: FixedU16&amp;lt;extra::U4&amp;gt; = FixedU16::from_num(5.75); &#x2F;&#x2F; you can use this approach&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; FixedU16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;extra&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;U4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; types&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;U12F4&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;from_num&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;5&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;75&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt; &#x2F;&#x2F; or this approach&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    assert_eq!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;75&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Fixed Point: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:.4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Fraction: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;frac&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Integer: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Binary with Fraction repr: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:b&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;    &#x2F;&#x2F; println!(&amp;quot;Actual binary: {:016b}&amp;quot;, f_u16.to_bits());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; format!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:016b&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;to_bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; formatted&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; format!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        &amp;quot;{}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;_&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;        &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;12&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;        &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;12&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    );&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Actual binary: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; formatted&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;F32: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;to_num&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you run this code, you will see output like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; Point:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 5.7500&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Frac:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.75&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Int:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Binary&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; with Fraction repr:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 101.11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Actual&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; binary: 000000000101_1100&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;F32:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 5.75&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When I first saw Binary with Fraction repr: 101.11, it was confusing. My brain read the 11 in the fractional part as the number three. That is not how fixed-point fractions work.&lt;&#x2F;p&gt;
&lt;p&gt;To understand what this value really represents, let’s look at the binary representation.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Bit Position&lt;&#x2F;th&gt;&lt;th&gt;15&lt;&#x2F;th&gt;&lt;th&gt;14&lt;&#x2F;th&gt;&lt;th&gt;13&lt;&#x2F;th&gt;&lt;th&gt;12&lt;&#x2F;th&gt;&lt;th&gt;11&lt;&#x2F;th&gt;&lt;th&gt;10&lt;&#x2F;th&gt;&lt;th&gt;9&lt;&#x2F;th&gt;&lt;th&gt;8&lt;&#x2F;th&gt;&lt;th&gt;7&lt;&#x2F;th&gt;&lt;th&gt;6&lt;&#x2F;th&gt;&lt;th&gt;5&lt;&#x2F;th&gt;&lt;th&gt;4&lt;&#x2F;th&gt;&lt;th&gt;.&lt;&#x2F;th&gt;&lt;th&gt;3&lt;&#x2F;th&gt;&lt;th&gt;2&lt;&#x2F;th&gt;&lt;th&gt;1&lt;&#x2F;th&gt;&lt;th&gt;0&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Stored Bit&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Weight&lt;&#x2F;td&gt;&lt;td&gt;2¹¹&lt;&#x2F;td&gt;&lt;td&gt;2¹⁰&lt;&#x2F;td&gt;&lt;td&gt;2⁹&lt;&#x2F;td&gt;&lt;td&gt;2⁸&lt;&#x2F;td&gt;&lt;td&gt;2⁷&lt;&#x2F;td&gt;&lt;td&gt;2⁶&lt;&#x2F;td&gt;&lt;td&gt;2⁵&lt;&#x2F;td&gt;&lt;td&gt;2⁴&lt;&#x2F;td&gt;&lt;td&gt;2³&lt;&#x2F;td&gt;&lt;td&gt;2²&lt;&#x2F;td&gt;&lt;td&gt;2¹&lt;&#x2F;td&gt;&lt;td&gt;2⁰&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;2⁻¹&lt;&#x2F;td&gt;&lt;td&gt;2⁻²&lt;&#x2F;td&gt;&lt;td&gt;2⁻³&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁴&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;The integer part is straightforward. The bits 101 represent the value 5 using normal binary rules.&lt;&#x2F;p&gt;
&lt;p&gt;The fractional part is where the confusion usually comes from. Each fractional bit represents a negative power of two.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;fraction&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.5&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.25&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.125&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.0625&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That adds up to 0.75.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;example-2&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#example-2&quot; aria-label=&quot;Anchor link for: example-2&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Example 2&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s look at one more example. This time, I try to represent the value 20.3. I keep the same fixed-point configuration as before, with 4 fractional bits.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;FixedU16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; types&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;extra&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;types&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; main&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; FixedU16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;extra&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;U4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; FixedU16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;from_num&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;20&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    assert_eq!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 20&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;3125&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Fixed Point: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:.4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Fraction: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;frac&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Integer: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Binary with Fraction repr: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:b&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;    &#x2F;&#x2F; println!(&amp;quot;Actual binary: {:016b}&amp;quot;, f_u16.to_bits());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; format!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;:016b&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;to_bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; formatted&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; format!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        &amp;quot;{}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;_&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;        &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;12&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;        &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;12&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    );&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Actual binary: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; formatted&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;F32: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{}&amp;quot;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; f_u16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;to_num&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you expect the line assert_eq!(f_u16, 20.3125) to fail, you might be surprised. It does not fail. The code compiles successfully and produces the following output:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; Point:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 20.3125&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Fraction:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Integer:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 20&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Binary&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; with Fraction repr:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 10100.0101&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Actual&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; binary: 000000010100_0101&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;F32:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 20.3125&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This happens because 20.3 cannot be represented exactly using this fixed-point format. As stated earlier, the fractional part can only increase in steps of 1 &#x2F; 2^f. With 4 fractional bits, the step size is: &lt;code&gt;1 &#x2F; 2^4 = 0.0625&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So the fraction 0.3 must be rounded to the nearest multiple of 0.0625. The value 0.3125 is a valid multiple:  &lt;code&gt;0.0625 × 5 = 0.3125&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the binary, it is represented like this:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Bit Position&lt;&#x2F;th&gt;&lt;th&gt;15&lt;&#x2F;th&gt;&lt;th&gt;14&lt;&#x2F;th&gt;&lt;th&gt;13&lt;&#x2F;th&gt;&lt;th&gt;12&lt;&#x2F;th&gt;&lt;th&gt;11&lt;&#x2F;th&gt;&lt;th&gt;10&lt;&#x2F;th&gt;&lt;th&gt;9&lt;&#x2F;th&gt;&lt;th&gt;8&lt;&#x2F;th&gt;&lt;th&gt;7&lt;&#x2F;th&gt;&lt;th&gt;6&lt;&#x2F;th&gt;&lt;th&gt;5&lt;&#x2F;th&gt;&lt;th&gt;4&lt;&#x2F;th&gt;&lt;th&gt;.&lt;&#x2F;th&gt;&lt;th&gt;3&lt;&#x2F;th&gt;&lt;th&gt;2&lt;&#x2F;th&gt;&lt;th&gt;1&lt;&#x2F;th&gt;&lt;th&gt;0&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Stored Bit&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Weight&lt;&#x2F;td&gt;&lt;td&gt;2¹¹&lt;&#x2F;td&gt;&lt;td&gt;2¹⁰&lt;&#x2F;td&gt;&lt;td&gt;2⁹&lt;&#x2F;td&gt;&lt;td&gt;2⁸&lt;&#x2F;td&gt;&lt;td&gt;2⁷&lt;&#x2F;td&gt;&lt;td&gt;2⁶&lt;&#x2F;td&gt;&lt;td&gt;2⁵&lt;&#x2F;td&gt;&lt;td&gt;2⁴&lt;&#x2F;td&gt;&lt;td&gt;2³&lt;&#x2F;td&gt;&lt;td&gt;2²&lt;&#x2F;td&gt;&lt;td&gt;2¹&lt;&#x2F;td&gt;&lt;td&gt;2⁰&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;2⁻¹&lt;&#x2F;td&gt;&lt;td&gt;2⁻²&lt;&#x2F;td&gt;&lt;td&gt;2⁻³&lt;&#x2F;td&gt;&lt;td&gt;2⁻⁴&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;If we calculate the fractional part:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;fraction&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.5&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.25&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.125&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; ×&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.0625&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0.3125&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;in-raspberry-pi-pico-2-rp2350&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#in-raspberry-pi-pico-2-rp2350&quot; aria-label=&quot;Anchor link for: in-raspberry-pi-pico-2-rp2350&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
In Raspberry Pi Pico 2 (RP2350)&lt;&#x2F;h2&gt;
&lt;p&gt;On the Raspberry Pi Pico 2 (RP2350), the PWM clock divider controls how fast the PWM counter runs. The PWM counting rate is calculated by dividing the system clock frequency by this divider value.&lt;&#x2F;p&gt;
&lt;p&gt;The divider register stores the value using a fixed point format. It is split into an integer part and a fractional part. The upper 8 bits represent the integer portion of the divider, and 4 bits represent the fractional portion. Together, these bits form a fixed point number, allowing finer control over the PWM frequency.&lt;&#x2F;p&gt;
&lt;p&gt;The following code snippet is from the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;embassy-rs&#x2F;rp-pac&#x2F;blob&#x2F;86fd095ca5056d24a61f0235ed6b07bbcec572d5&#x2F;src&#x2F;rp235x&#x2F;pwm&#x2F;regs.rs#L220&quot;&gt;rp-pac&lt;&#x2F;a&gt; crate and shows how the divider register is defined.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;#[&lt;&#x2F;span&gt;&lt;span&gt;doc &lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;INT and FRAC form a fixed-point fractional number. Counting rate is system clock frequency divided by this number. Fractional division uses simple 1st-order sigma-delta.&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;#[&lt;&#x2F;span&gt;&lt;span&gt;repr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;transparent&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;#[&lt;&#x2F;span&gt;&lt;span&gt;derive&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;Copy&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Clone&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Eq&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; PartialEq&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; ChDiv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; ChDiv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    #[&lt;&#x2F;span&gt;&lt;span&gt;inline&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;always&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-modifier&quot;&gt; const&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; frac&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; val&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-logical&quot;&gt; &amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0x0f&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;        val&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; u8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    #[&lt;&#x2F;span&gt;&lt;span&gt;inline&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;always&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-modifier&quot;&gt; const&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; int&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; val&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-logical&quot;&gt; &amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 4&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0xff&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;        val&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; u8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Although the register is defined as a 32 bit unsigned integer, only 12 bits are actually used. Of these, 8 bits are used for the integer part and 4 bits for the fractional part.&lt;&#x2F;p&gt;
&lt;p&gt;In the embassy-rp crate, the divider is represented using a type from the fixed crate. When configuring the PWM hardware, this fixed point value is converted into a u32 and written directly to the register.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control&quot;&gt;if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;divider&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; FixedU16&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;fixed&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;types&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;extra&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;U4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;from_bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0xFFF&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    panic!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Requested divider is too large&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;&amp;quot;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;p&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;div&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;write_value&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;ChDiv&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;config&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;divider&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;to_bits&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        <summary type="html">In this post, we take a quick look at fixed-point numbers and how to use them in Rust. We also briefly explain why they are useful in embedded and other scenarios, with examples using the fixed crate.</summary>
        </entry><entry xml:lang="en">
        <title>Getting started: How to Learn Embedded Rust for Beginners</title>
        <published>2025-12-12T00:00:00+00:00</published>
        <updated>2025-12-12T00:00:00+00:00</updated>
        <author>
            <name>implFerris</name>
        </author>
        <link rel="alternate" href="https://blog.implrust.com/posts/2025/12/how-to-learn-embedded-rust/" type="text/html"/>
        <id>https://blog.implrust.com/posts/2025/12/how-to-learn-embedded-rust/</id>
        
            <content type="html">&lt;img src=&quot;&#x2F;img&#x2F;embedded-rust.png&quot; width=&quot;550&quot; alt=&quot;Learning Embedded Rust&quot; style=&quot;width:550px; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;p&gt;As a beginner, you might wonder where to start with Embedded Rust. I have been in the same place, and I have seen many others recently asking the same question. So I decided to write this blog post to help. In this guide, I will explain how to get started, what to focus on first, and share a list of useful resources including books, YouTube videos, and other material you can learn from.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;table-of-contents&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#table-of-contents&quot; aria-label=&quot;Anchor link for: table-of-contents&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Table of Contents&lt;&#x2F;h2&gt;
&lt;!-- toc --&gt;
&lt;h2 id=&quot;are-you-new-to-embedded-programming-or-just-to-embedded-rust&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#are-you-new-to-embedded-programming-or-just-to-embedded-rust&quot; aria-label=&quot;Anchor link for: are-you-new-to-embedded-programming-or-just-to-embedded-rust&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Are you new to embedded programming or just to Embedded Rust?&lt;&#x2F;h2&gt;
&lt;p&gt;Where you should begin depends on your background. If you are an absolute beginner to embedded programming itself, your learning path will be different from someone who already understands embedded development and only wants to learn Embedded Rust. Even within those groups, goals can vary, such as learning for a hobby or for professional work. I’ll do my best to address a broad audience while covering the most common scenarios.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;if-you-already-have-embedded-programming-experience&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#if-you-already-have-embedded-programming-experience&quot; aria-label=&quot;Anchor link for: if-you-already-have-embedded-programming-experience&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
If you already have embedded programming experience&lt;&#x2F;h3&gt;
&lt;p&gt;If you already have embedded experience, you can jump straight into the official “&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rust-embedded.org&#x2F;book&#x2F;intro&#x2F;tooling.html&quot;&gt;The Embedded Rust Book&lt;&#x2F;a&gt;” to learn Rust-specific concepts. After that, check out the “&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;embassy.dev&#x2F;book&#x2F;&quot;&gt;Embassy book&lt;&#x2F;a&gt;” for async embedded development. From there, explore the examples in the Hardware Abstraction Layer (HAL) for your specific chip. The Embedded Rust ecosystem has excellent HAL documentation and examples to help you get productive quickly.&lt;&#x2F;p&gt;
&lt;p&gt;The remaining sections focus on resources for embedded programming beginners.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#prerequisites&quot; aria-label=&quot;Anchor link for: prerequisites&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Prerequisites&lt;&#x2F;h2&gt;
&lt;p&gt;Before learning Embedded Rust, make sure you are comfortable with these basics:&lt;&#x2F;p&gt;
&lt;h4 id=&quot;rust-basics&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#rust-basics&quot; aria-label=&quot;Anchor link for: rust-basics&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Rust basics&lt;&#x2F;h4&gt;
&lt;p&gt;If you’re completely new to Rust, start with the official &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;&quot;&gt;Rust Book&lt;&#x2F;a&gt; first. Understanding Rust’s ownership, borrowing, and type system is essential before tackling embedded development. Come back to this guide once you’re comfortable with basic Rust concepts.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;electronics-fundamentals&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#electronics-fundamentals&quot; aria-label=&quot;Anchor link for: electronics-fundamentals&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Electronics Fundamentals&lt;&#x2F;h4&gt;
&lt;p&gt;You’ll need a basic understanding of electronics concepts like voltage, current, resistance, and how components like LEDs and resistors work. There are plenty of free tutorials and YouTube videos covering electronics basics for beginners. You don’t need to be an expert, just understand the fundamentals.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;hardware-to-get-started&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#hardware-to-get-started&quot; aria-label=&quot;Anchor link for: hardware-to-get-started&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Hardware to Get Started&lt;&#x2F;h2&gt;
&lt;p&gt;Now, the question is: What hardware should you get? But before answering that, let me briefly explain what microcontrollers and development boards are.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;what-are-microcontrollers-and-development-boards&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#what-are-microcontrollers-and-development-boards&quot; aria-label=&quot;Anchor link for: what-are-microcontrollers-and-development-boards&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
What are Microcontrollers and Development Boards?&lt;&#x2F;h3&gt;
&lt;p&gt;A &lt;strong&gt;microcontroller&lt;&#x2F;strong&gt; is a small computer on a single chip that includes a processor, memory, and input&#x2F;output peripherals. Unlike your laptop or phone, microcontrollers are designed to perform specific tasks efficiently with minimal power consumption. They’re found everywhere; in your washing machine, car, smart thermostat, and countless other devices.&lt;&#x2F;p&gt;
&lt;p&gt;A &lt;strong&gt;development board&lt;&#x2F;strong&gt; (or “devboard”) is a circuit board that contains a microcontroller along with supporting components like voltage regulators, USB connectors, and pins that make it easy to connect sensors and other hardware. Development boards are designed to make prototyping and learning easier. You can start programming immediately without needing to design your own circuit.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;which-board-should-you-get&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#which-board-should-you-get&quot; aria-label=&quot;Anchor link for: which-board-should-you-get&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Which Board Should You Get?&lt;&#x2F;h3&gt;
&lt;p&gt;If you already have a board, great! You can start with that. Otherwise, let me give you a straightforward recommendation without overwhelming you with options.&lt;&#x2F;p&gt;
&lt;div class=&quot;admonition tip&quot;&gt;
    &lt;div class=&quot;admonition-icon admonition-icon-tip&quot;&gt;&lt;&#x2F;div&gt;
    &lt;div class=&quot;admonition-content&quot;&gt;
        &lt;strong class=&quot;admonition-title&quot;&gt;TIP&lt;&#x2F;strong&gt;
        &lt;p&gt;My recommendation: Get an ESP32 development board.&lt;&#x2F;p&gt;

    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;p&gt;Why? ESP32 boards are widely available, affordable, and include built-in WiFi and Bluetooth, which opens up many project possibilities. They have solid Embedded Rust support through the esp-rs project.&lt;&#x2F;p&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;esp32.implrust.com&#x2F;images&#x2F;esp32-devkitv1.jpg&quot; width=&quot;250&quot; alt=&quot;ESP32 Devkit V1&quot; style=&quot;width:400px; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;p&gt;&lt;strong&gt;Look for these boards - they all use the original ESP32 chip:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;“ESP32 DevKit V1” - This is my top recommendation because my open-source book is based on this board, making it easy to follow along with tutorials and examples.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;“ESP32 DevKit C”&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Any board using the original ESP32 chip should be fine. There might be slight differences in pin layout and labeling, but the code and core features remain the same.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;&#x2F;strong&gt; ESP32 comes in different variants (original ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6, etc.). I’m recommending the &lt;strong&gt;original ESP32&lt;&#x2F;strong&gt; (also called ESP32-WROOM or ESP32-WROOM-32). Make sure you’re getting a plain “ESP32” board, not the S-series or C-series variants, as those are different chips with different architectures.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Alternative option: Raspberry Pi Pico 2&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If you can’t find an ESP32 board where you live, the &lt;strong&gt;Raspberry Pi Pico 2&lt;&#x2F;strong&gt; (with RP2350 chip) is an excellent alternative.. The main tradeoff is it lacks WiFi and Bluetooth, but it’s perfect for learning embedded fundamentals.  There’s also a Pico 2 W variant that supports WiFi and Bluetooth, though you may need to adjust the code slightly when following tutorials with it.&lt;&#x2F;p&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;pico.implrust.com&#x2F;images&#x2F;pico2.png&quot; width=&quot;350&quot; alt=&quot;Raspberry Pi Pico 2&quot; style=&quot;width:400px; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;h3 id=&quot;but-why-esp32-devkit-v1&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#but-why-esp32-devkit-v1&quot; aria-label=&quot;Anchor link for: but-why-esp32-devkit-v1&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
But, Why ESP32 DevKit V1?&lt;&#x2F;h3&gt;
&lt;p&gt;Let me share my journey learning Embedded Rust as a beginner, which will help explain my recommendation.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;My First Board: micro:bit v2&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The micro:bit was my first device. I chose it because the official Embedded Rust book had examples for it, so I thought I’d just buy one and follow along. The micro:bit is a nice board with built-in features like a microphone, speaker, and LED matrix, which are great for getting started quickly.&lt;&#x2F;p&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;mb2.implrust.com&#x2F;images&#x2F;microbit.jpg&quot; width=&quot;450&quot; alt=&quot;Microbit (v2)&quot; style=&quot;width:450px; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;p&gt;However, I soon hit limitations. Connecting external components wasn’t straightforward. I needed an edge connector or expansion board to add sensors, buttons, or other peripherals. This added extra cost and complexity. The board itself was also expensive, costing about three times more than an ESP32 DevKit V1.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;My Second Board: Raspberry Pi Pico 2&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Next, I bought a Raspberry Pi Pico 2 (with the RP2350 chip). It’s an excellent board, and I documented my learning in an open-source book called “Pico Pico” that I’m currently revising based on my experience.&lt;&#x2F;p&gt;
&lt;p&gt;However, there is one thing I did not like: every time you want to run your new program on the board, you must press a button and reconnect the USB cable. And if you make changes again, you need to unplug and repeat the same steps. This becomes tiring very quickly.&lt;&#x2F;p&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;pico.implrust.com&#x2F;debugging&#x2F;images&#x2F;Debug%20Probe%20for%20Raspberry%20Pi%20Pico%202%20-%20Rust%20Debugging.jpg&quot; width=&quot;550&quot; alt=&quot;Raspberry Pi Pico Debug Probe&quot; style=&quot;width:550px; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;p&gt;This problem can be solved with a debug probe, a separate piece of hardware. With a debug probe. With a debug probe, you can write and debug your code seamlessly without unplugging anything. However, buying a board plus a debug probe brings the total cost to about three times that of an ESP32 DevKit V1. But, the advantage is that you get proper debugging capabilities that work across different boards, but it’s an extra expense that’s not strictly necessary when you’re just starting out on a tight budget.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;My Third Board: ESP32 DevKit V1&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Then I discovered the ESP32 DevKit V1, and everything changed. This board is a beast in terms of what it offers for the price. Here’s why it became my top recommendation:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;No button pressing needed: Just plug it in and write your code into the device. The board handles everything automatically.&lt;&#x2F;li&gt;
&lt;li&gt;Built-in WiFi and Bluetooth: Perfect for IoT projects without needing extra modules.&lt;&#x2F;li&gt;
&lt;li&gt;Very affordable: Making it one of the cheapest options.&lt;&#x2F;li&gt;
&lt;li&gt;Easy to connect components&lt;&#x2F;li&gt;
&lt;li&gt;Widely available: Easy to find from multiple sellers worldwide.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Even other ESP32 series often cost more or lack either WiFi or Bluetooth. The ESP32 on the DevKit V1 gives you the best bang for your buck.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;The Bottom Line&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If you’re just starting out and want the most flexibility at the lowest cost, get an ESP32 DevKit V1. You can build real projects with WiFi and Bluetooth connectivity without spending extra on debug probes or expansion boards.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;additional-components&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#additional-components&quot; aria-label=&quot;Anchor link for: additional-components&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Additional Components&lt;&#x2F;h3&gt;
&lt;p&gt;Apart from the development board, you’ll need some additional electronic components. Some are essentials like breadboards, jumper wires, and resistors. Others are optional, like LEDs (well, maybe not so optional!), various sensors, and other components. You can buy these as you progress through your learning journey.&lt;&#x2F;p&gt;
&lt;p&gt;Wow, I didn’t expect to write this much about hardware itself!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;embedded-rust-basics&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#embedded-rust-basics&quot; aria-label=&quot;Anchor link for: embedded-rust-basics&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Embedded Rust Basics&lt;&#x2F;h2&gt;
&lt;p&gt;Now that we’ve decided on which development board to buy, let’s focus on how to use it and where to go from here. I’ll be recommending only open source and free resources, which should be more than enough to get you started.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-embedded-rust-book&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#the-embedded-rust-book&quot; aria-label=&quot;Anchor link for: the-embedded-rust-book&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
The Embedded Rust book&lt;&#x2F;h3&gt;
&lt;p&gt;Regardless of which board you choose, the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rust-embedded.org&#x2F;book&#x2F;intro&#x2F;index.html&quot;&gt;first book&lt;&#x2F;a&gt; I recommend is the official book by the Embedded Rust Working Group. This will introduce you to the basic concepts of embedded Rust development.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;embassy-book&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#embassy-book&quot; aria-label=&quot;Anchor link for: embassy-book&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Embassy Book&lt;&#x2F;h3&gt;
&lt;p&gt;Embassy is an async framework for embedded Rust. You can start learning it from the official &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;embassy.dev&#x2F;book&#x2F;&quot;&gt;Embassy Book&lt;&#x2F;a&gt;. It explains how async works on microcontrollers and shows a few examples.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;rustybits-youtube-channel&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#rustybits-youtube-channel&quot; aria-label=&quot;Anchor link for: rustybits-youtube-channel&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Rustybits Youtube channel&lt;&#x2F;h3&gt;
&lt;p&gt;This is one of my favorite channels for learning Embedded Rust. The creator explains concepts very clearly with helpful videos like “From Zero to Async in Embedded Rust”.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@therustybits&#x2F;videos&quot;&gt;https:&#x2F;&#x2F;www.youtube.com&#x2F;@therustybits&#x2F;videos&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;learning-path-for-esp32&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#learning-path-for-esp32&quot; aria-label=&quot;Anchor link for: learning-path-for-esp32&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Learning Path for ESP32&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;the-rust-on-esp-book&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#the-rust-on-esp-book&quot; aria-label=&quot;Anchor link for: the-rust-on-esp-book&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
The Rust on ESP Book&lt;&#x2F;h3&gt;
&lt;p&gt;The next resource is the official “&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.espressif.com&#x2F;projects&#x2F;rust&#x2F;book&#x2F;introduction&#x2F;index.html&quot;&gt;The Rust on ESP Book&lt;&#x2F;a&gt;”. This book covers ESP32 and its variants, showing you how to set up your development tools and explaining the basic concepts of the ESP embedded Rust ecosystem.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;impl-rust-for-esp32-book&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#impl-rust-for-esp32-book&quot; aria-label=&quot;Anchor link for: impl-rust-for-esp32-book&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
impl Rust for ESP32 Book&lt;&#x2F;h3&gt;
&lt;p&gt;Next up is the book I wrote called “&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;esp32.implrust.com&#x2F;&quot;&gt;impl Rust for ESP32&lt;&#x2F;a&gt;”. This is an &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ImplFerris&#x2F;esp32-book&quot;&gt;open source book&lt;&#x2F;a&gt; that uses the ESP32 DevKit V1 with Rust to build simple and fun projects. You’ll explore hands-on examples like turning on an LED when the room gets darker using an LDR sensor, using an ultrasonic sensor to detect nearby objects, controlling an LED through WiFi, drawing images and text on an OLED display, playing songs and alarm sounds with a buzzer, controlling a servo motor, running a web server and more.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;examples&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#examples&quot; aria-label=&quot;Anchor link for: examples&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Examples&lt;&#x2F;h3&gt;
&lt;p&gt;Once you understand the basics, you can explore the examples section of the HAL (Hardware Abstraction Layer) or other crates you’ll be using. The esp-hal repository has a nice set of examples:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;esp-rs&#x2F;esp-hal&#x2F;tree&#x2F;main&#x2F;examples&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;esp-rs&#x2F;esp-hal&#x2F;tree&#x2F;main&#x2F;examples&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;learning-path-for-raspberry-pi-pico-2&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#learning-path-for-raspberry-pi-pico-2&quot; aria-label=&quot;Anchor link for: learning-path-for-raspberry-pi-pico-2&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Learning Path for Raspberry Pi Pico 2&lt;&#x2F;h2&gt;
&lt;p&gt;If you bought the Pico 2 (RP2350 chip) or if you “have” the older Pico version (RP2040), you can follow this learning path.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;pico-pico-book&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#pico-pico-book&quot; aria-label=&quot;Anchor link for: pico-pico-book&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Pico Pico Book&lt;&#x2F;h3&gt;
&lt;p&gt;As I mentioned earlier, I wrote a book for the Raspberry Pi Pico 2 also. You can read it &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pico.implrust.com&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;. This is an &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ImplFerris&#x2F;pico-pico&quot;&gt;open source book&lt;&#x2F;a&gt; that uses the Pico 2 with Rust to build simple and fun projects. Like the ESP32 book, this also includes similar hands-on examples with various sensors and components.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;examples-1&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#examples-1&quot; aria-label=&quot;Anchor link for: examples-1&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Examples&lt;&#x2F;h3&gt;
&lt;p&gt;Once you understand the basics, you can explore the examples in the rp-hal repository. It has a good collection of examples for the Raspberry Pi Pico:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;For Raspberry Pi Pico 2 (RP2350):&lt;&#x2F;strong&gt;
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rp-rs&#x2F;rp-hal&#x2F;tree&#x2F;main&#x2F;rp235x-hal-examples&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;rp-rs&#x2F;rp-hal&#x2F;tree&#x2F;main&#x2F;rp235x-hal-examples&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;For Raspberry Pi Pico (RP2040):&lt;&#x2F;strong&gt;
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rp-rs&#x2F;rp-hal&#x2F;tree&#x2F;main&#x2F;rp2040-hal-examples&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;rp-rs&#x2F;rp-hal&#x2F;tree&#x2F;main&#x2F;rp2040-hal-examples&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;learning-path-for-microbit-v2&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#learning-path-for-microbit-v2&quot; aria-label=&quot;Anchor link for: learning-path-for-microbit-v2&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Learning Path for Microbit:v2&lt;&#x2F;h2&gt;
&lt;p&gt;If you bought a micro:bit v2 board and want to learn Embedded Rust with it, these resources will help you.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;micro-bit-v2-embedded-discovery-book&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#micro-bit-v2-embedded-discovery-book&quot; aria-label=&quot;Anchor link for: micro-bit-v2-embedded-discovery-book&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
micro::bit v2 Embedded Discovery Book&lt;&#x2F;h3&gt;
&lt;p&gt;This book, written by the official Embedded Rust Working Group, teaches embedded Rust using the BBC micro:bit v2. It is an introductory course that helps you learn how microcontrollers work and how to write embedded Rust code for them.&lt;&#x2F;p&gt;
&lt;p&gt;You can read it online here:&lt;br &#x2F;&gt;
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rust-embedded.org&#x2F;discovery-mb2&#x2F;index.html&quot;&gt;https:&#x2F;&#x2F;docs.rust-embedded.org&#x2F;discovery-mb2&#x2F;index.html&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;impl-rust-for-microbit&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#impl-rust-for-microbit&quot; aria-label=&quot;Anchor link for: impl-rust-for-microbit&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
impl Rust for Microbit&lt;&#x2F;h3&gt;
&lt;p&gt;This is an &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ImplFerris&#x2F;microbit-book&quot;&gt;open source book&lt;&#x2F;a&gt; that teaches Embedded Rust on the BBC micro:bit v2 with hands-on, simple projects. It builds practical skills by walking through examples like controlling LEDs, reading sensors, and interacting with buttons and displays. The book is beginner friendly and focuses on learning by doing.&lt;&#x2F;p&gt;
&lt;p&gt;You can read it online here:&lt;br &#x2F;&gt;
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;mb2.implrust.com&#x2F;&quot;&gt;https:&#x2F;&#x2F;mb2.implrust.com&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;other-resources&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#other-resources&quot; aria-label=&quot;Anchor link for: other-resources&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Other Resources&lt;&#x2F;h2&gt;
&lt;p&gt;Here are some other useful resources related to Embedded Rust.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;curated-list-awesome-embedded-rust&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#curated-list-awesome-embedded-rust&quot; aria-label=&quot;Anchor link for: curated-list-awesome-embedded-rust&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Curated List - Awesome Embedded Rust&lt;&#x2F;h3&gt;
&lt;p&gt;This is a curated list of resources for embedded and low-level programming in Rust. It includes useful crates, tools, books, tutorials, and more.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-embedded&#x2F;awesome-embedded-rust&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;rust-embedded&#x2F;awesome-embedded-rust&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;writing-an-os-in-rust&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#writing-an-os-in-rust&quot; aria-label=&quot;Anchor link for: writing-an-os-in-rust&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Writing an OS in Rust&lt;&#x2F;h3&gt;
&lt;p&gt;You might wonder what writing an OS has to do with embedded Rust. In many embedded systems, there is no underlying OS at all. Your firmware is the only thing running on the device. This series gives a great introduction to low-level concepts that are also useful in embedded development. You will not be writing a full operating system, but you will learn many fundamentals.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;os.phil-opp.com&#x2F;&quot;&gt;https:&#x2F;&#x2F;os.phil-opp.com&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;rust-embedded-driver-red-book&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#rust-embedded-driver-red-book&quot; aria-label=&quot;Anchor link for: rust-embedded-driver-red-book&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Rust Embedded Driver (RED) Book&lt;&#x2F;h3&gt;
&lt;p&gt;I have also written an open source book that focuses on building drivers in Embedded Rust. This book is slightly more advanced than my board-specific books, so it is best explored after completing the introductory material. It offers step-by-step guidance on writing drivers from the ground up for components such as the DHT22 sensor, the MAX7219 LED display (including an embedded-graphics implementation), RTC modules, and a platform-agnostic RTC HAL to illustrate the embedded-hal concept.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;red.implrust.com&#x2F;&quot;&gt;https:&#x2F;&#x2F;red.implrust.com&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;wokwi-platform&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#wokwi-platform&quot; aria-label=&quot;Anchor link for: wokwi-platform&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Wokwi Platform&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;wokwi.com&#x2F;&quot;&gt;Wokwi&lt;&#x2F;a&gt; is an online simulator for embedded projects. It lets you write code, connect virtual components, and test circuits in the browser. It supports boards like Arduino, ESP32, and Raspberry Pi Pico, and it also supports running Embedded Rust projects. It is a quick way to experiment, learn, and verify ideas without using real hardware.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;img&#x2F;wokwi-simulation-max7219-embedded-rust.jpeg&quot; alt=&quot;Embedded Rust - Simulation with Wokwi MAX7219 Display&quot; style=&quot; height:auto; display:block; margin:auto;&quot;&#x2F;&gt;
&lt;p&gt;You can run simulations directly in the browser or through the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.wokwi.com&#x2F;vscode&#x2F;getting-started&quot;&gt;Wokwi for VS Code&lt;&#x2F;a&gt; extension. In my experience, the Rust simulator on the website can be unreliable, while the VS Code extension works more consistently. However, nothing fully replaces having fun with real hardware.&lt;&#x2F;p&gt;
</content>
        <summary type="html">Want to learn Embedded Rust but not sure where to begin? In this post, I will show you how to get started with Embedded Rust and share tutorials, books, videos, and other useful resources you can learn from.</summary>
        </entry>
</feed>
