<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cyril Marpaud on Medium]]></title>
        <description><![CDATA[Stories by Cyril Marpaud on Medium]]></description>
        <link>https://medium.com/@cyril.marpaud?source=rss-8e8b38934535------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*alRxQtTIjav7bXU_V5i2cg.jpeg</url>
            <title>Stories by Cyril Marpaud on Medium</title>
            <link>https://medium.com/@cyril.marpaud?source=rss-8e8b38934535------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 03:41:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cyril.marpaud/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Impl Snake For Micro:bit — Embedded async Rust on BBC Micro:bit with Embassy]]></title>
            <link>https://medium.com/@cyril.marpaud/impl-snake-for-micro-bit-embedded-async-rust-on-bbc-micro-bit-with-embassy-a517a23f1228?source=rss-8e8b38934535------2</link>
            <guid isPermaLink="false">https://medium.com/p/a517a23f1228</guid>
            <category><![CDATA[arm-cortex-m4]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[embassy]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[microbit]]></category>
            <dc:creator><![CDATA[Cyril Marpaud]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 13:02:10 GMT</pubDate>
            <atom:updated>2024-10-28T13:02:10.916Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Impl Snake For Micro:bit — Embedded async Rust on BBC Micro:bit with Embassy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*0oc2TOQZ9JigqAYDTPAy1Q.png" /><figcaption>Rust on Micro:bit</figcaption></figure><p>In this article, I will guide you through creating a <a href="https://en.wikipedia.org/wiki/Snake_(video_game_genre)">Snake</a> game in embedded Rust on the <a href="https://microbit.org/">BBC Micro:bit</a> using the asynchronous framework <a href="https://embassy.dev/">Embassy</a>.</p><p>The <a href="https://microbit.org/">BBC Micro:bit</a> is a small educational board. It is equipped with an ARM Cortex-M4F nRF52833 microcontroller, a 5⨉5 LED matrix, 3 buttons (one of which is touch-sensitive), a microphone, a speaker, Bluetooth capabilities, and much more.</p><p><a href="https://gitlab.com/cyril-marpaud/impl_snake_for_microbit">The complete source code of the project</a> is available on GitLab.</p><p>Although I tried to make this article accessible to as many people as possible, some prior knowledge of Rust is recommended to understand the technical details.</p><h3>The Stack</h3><p>Here’s an overview of the software stack we will be using:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/0*bzyBVxVKemmKHAEa.png" /><figcaption>The stack</figcaption></figure><p>I will briefly explain the function of each layer in the sections below. Note that for our implementation, we only need to focus on the application layer, as the others are provided by the Rust ecosystem thanks to the incredible efforts of the community.</p><h3>Architecture Support</h3><p>The lowest layer (i.e., the closest to the hardware) concerns architecture support. Our microcontroller is an ARM Cortex-M4F, so we will use the <a href="https://crates.io/crates/cortex-m">cortex-m</a> and <a href="https://crates.io/crates/cortex-m-rt">cortex-m-rt</a> crates, but there are others, such as <a href="https://crates.io/crates/riscv">riscv</a> or <a href="https://crates.io/crates/x86_64">x86_64</a>. In general, these crates provide the code necessary to boot a microcontroller and interact with it (interrupts, specific instructions, etc.).</p><h3>Peripheral Access Crate</h3><p>The next layer is called the PAC. These are crates that provide structures and functions for reading/writing to the registers of a microcontroller in a standardized way, enabling the configuration and access to all peripherals (GPIO, SPI, I²C, etc.) without risking memory corruption or hardware errors.</p><p>PACs are generated using the <a href="https://crates.io/crates/svd2rust">svd2rust</a> tool, which converts an <a href="https://arm-software.github.io/CMSIS_5/SVD/html/index.html">SVD file</a> describing a microcontroller&#39;s hardware into a comprehensive API.</p><p>This layer is inherently unsafe (as it reads/writes values to arbitrary addresses), but it serves the purpose of providing a safe API for embedded developers.</p><h3>Hardware Abstraction Layer</h3><p>In the embedded ecosystem, the <a href="https://crates.io/crates/embedded-hal">embedded-hal</a> and <a href="https://crates.io/crates/embedded-hal-async">embedded-hal-async</a> crates play a central role. They define traits that allow for interacting with peripherals in a generic way, which facilitates code reuse and portability across different targets.</p><p>Microcontroller manufacturers often provide specific HALs, but these are typically tailored to individual hardware and lack cross-platform compatibility. The embedded-hal and embedded-hal-async crates address this issue by offering a common high-level interface, allowing for the development of reusable, generic drivers across multiple targets.</p><p>The HAL we will use is an implementation of those traits called<a href="https://crates.io/crates/embassy-nrf">embassy-nrf</a>, which provides drivers for the peripherals of the nRF52833 microcontroller.</p><h3>Operating System: Embassy</h3><p>Although an operating system is not strictly necessary, it is often much more convenient to delegate task and interrupt management to a third-party library. This is the role of <a href="https://github.com/embassy-rs/embassy">Embassy</a>, which provides an asynchronous runtime for microcontrollers.</p><p>It allows multiple tasks to run concurrently (either in parallel or not) in a non-blocking, asynchronous manner. This enables quick responses to events while improving performance compared to a traditional preemptive kernel and keeping the code clean and organized, without the complexity of interrupt-based programming.</p><h3>The Application</h3><p>Our application sits atop all these software layers. Thanks to them, we have all the tools needed to schedule tasks and access the microcontroller’s peripherals through high-level abstractions. This allows us to focus on developing our Snake game without worrying about the technical details.</p><h3>Flashing with <a href="https://probe.rs/">Probe-rs</a></h3><p>To flash our application onto the board, we will use probe-rs, a powerful and flexible open-source debugging and flashing tool for embedded systems. It allows developers to program and debug a wide variety of microcontroller targets, such as ARM Cortex-M, RISC-V, and STM32 families, among many others. Probe-rs abstracts away the intricacies of different debug probes and programming interfaces, making it easier to work with a wide range of hardware.</p><p>The tool supports a <a href="https://probe.rs/targets/">wide range of targets</a>, including <a href="https://probe.rs/targets/master/nRF52833_xxAA">our nRF52833_xxAA</a>, which we’ll be using for this project. Installation instructions are available on <a href="https://probe.rs/docs/getting-started/installation/#using-install-scripts">the tool’s documentation page</a>.</p><p>We can verify the installation with the following command:</p><pre>probe-rs --help</pre><p>To run software on a target, you can use the command probe-rs run, specifying the target chip with the --chip argument. For example:</p><pre>probe-rs run --chip nRF52833_xxAA</pre><p>This command automatically flashes and starts the program on the specified microcontroller.</p><h3>Using cargo-embassy</h3><p>It is possible to create a project manually by following <a href="https://embassy.dev/book/#_starting_a_project_from_scratch">the instructions in Embassy’s documentation</a>. However, it is much easier and quicker to use a template that will take care of creating all the necessary configuration for us.</p><p>This is exactly what <a href="https://crates.io/crates/cargo-embassy">cargo-embassy</a> was created for. Let’s start by installing it:</p><pre>cargo install cargo-embassy<br>cargo embassy --help</pre><p>Next, let’s generate a preconfigured project in the snake directory:</p><pre>cargo embassy init --chip nrf52833_xxAA snake</pre><h3>Project Structure</h3><p>Here’s a screenshot of the filetree structure of the project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/0*ObV6hsqy2LGXxcMK.png" /></figure><h4>.cargo/config.toml</h4><p>It contains the configuration for the runner, which allows probe-rs to flash the target automatically when we use the cargo run command, and the compilation target that has been set to thumbv7em-none-eabihf:</p><pre>[target.thumbv7em-none-eabihf]<br>runner = &#39;probe-rs run --chip nRF52833_xxAA&#39;<br><br>[build]<br>target = &quot;thumbv7em-none-eabihf&quot;</pre><h4>Cargo.toml</h4><p>It declares all our project’s dependencies, including:</p><ul><li>cortex-m and cortex-m-rt for supporting the microcontroller&#39;s architecture</li><li>defmt and defmt-rtt for execution logs</li><li>embassy-* for our application&#39;s functionality</li><li>panic-halt and panic-probe for panic handling</li></ul><h4>The src folder</h4><p>It contains both main.rs, which I will describe in the next section, and fmt.rs, which provides the components necessary for displaying execution or crash logs:</p><ul><li>assertions (assert, assert_eq, assert_ne, and debug versions)</li><li>panic (panic, unwrap, unreachable, todo...)</li><li>logs (trace, debug, info, warn, error)</li></ul><h4>memory.x</h4><p>It is <a href="https://docs.rs/cortex-m-rt/latest/cortex_m_rt/#requirements">a prerequisite for using the cortex-m-rt crate</a>. It describes the memory layout of the microcontroller.</p><h4>build.rs</h4><p>The build script is preconfigured to ensure that memory.x is available in the appropriate folder during compilation. We also need two specific linker scripts: link.x (provided by the <a href="https://crates.io/crates/cortex-m-rt">cortex-m-rt crate</a>) and <a href="https://defmt.ferrous-systems.com/setup.html#linker-script">defmt.x</a> (for logs), which build.rs also takes care of.</p><h4>Embed.toml</h4><p>It specifies the target for the <a href="https://probe.rs/docs/tools/cargo-embed/">cargo embed</a> command.</p><h3>Testing the Project</h3><p>Let’s start with the main.rs file, which for now consists of the minimal code to blink an LED.</p><p>We are in no_std mode:</p><pre>#![no_std]<br>#![no_main]</pre><p>The main function is asynchronous, and the entry point is declared via the <a href="https://docs.rs/embassy-executor/latest/embassy_executor/attr.main.html">embassy_executor::main</a> macro:</p><pre>#[embassy_executor::main]<br>async fn main(_spawner: Spawner)</pre><p>We will later see how to use this <a href="https://docs.rs/embassy-executor/latest/embassy_executor/struct.Spawner.html">Spawner</a> to start tasks.</p><p>We begin by initializing the board and retrieving the peripheral we are interested in (here, a simple output pin):</p><pre>let p = embassy_nrf::init(Default::default());<br>let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);</pre><p>Then we loop, toggling its state on and off:</p><pre>loop {<br>  led.set_high();<br>  Timer::after_millis(500).await;<br>  led.set_low();<br>  Timer::after_millis(500).await;<br>}</pre><p>The pin used by the template (P0_13) does not correspond to an LED on our board. By examining <a href="https://github.com/microbit-foundation/microbit-v2-hardware/blob/main/V2.21/MicroBit_V2.2.1_nRF52820%20schematic.PDF">the schematic of the board</a>, we can see that each LED is at the intersection of a row and a column of the matrix. To turn one on, we need to manipulate two LEDs (ROW1 and COL1, for example).</p><p><a href="https://tech.microbit.org/hardware/schematic/#v2-pinmap">The pin mapping</a> gives the correspondence between the name and number of a pin. ROW1 corresponds to P0_21, while P0_28 corresponds to COL1.</p><p>According to the schematic, for the LED to light up, its row must be high and its column must be low. We will initialize these two pins to low, then toggle one regularly to see it blink:</p><pre>let mut row1 = Output::new(p.P0_21, Level::Low, OutputDrive::Standard);<br>let mut col1 = Output::new(p.P0_28, Level::Low, OutputDrive::Standard);<br><br>loop {<br>  row1.set_high();<br>  Timer::after_millis(500).await;<br>  row1.set_low();<br>  Timer::after_millis(500).await;<br>}</pre><p>If the LED blinks, congratulations, your project is now set up! We can move on to more advanced tasks.</p><h3>Architecture</h3><p>We will create three tasks:</p><ul><li>The first will control the display through the LED matrix rows and columns.</li><li>The second will manage the controller through the button pins.</li><li>The last will handle the game logic (using the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/rng/struct.Rng.html">RNG</a> to generate the snake’s food).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/0*1yxql_ZabNfQsFoz.png" /><figcaption>The architecture</figcaption></figure><p>A task is nothing more than a simple function that runs continuously. It can communicate with other tasks via primitives like <a href="https://docs.embassy.dev/embassy-sync/git/default/channel/struct.Channel.html">Channel</a> or <a href="https://docs.embassy.dev/embassy-sync/git/default/signal/struct.Signal.html">Signal</a>.</p><p>We annotate the function with <a href="https://docs.rs/embassy-executor/latest/embassy_executor/attr.task.html">the task macro</a> and start the task with <a href="https://docs.rs/embassy-executor/latest/embassy_executor/struct.Spawner.html#method.spawn">Spawner::spawn</a>:</p><pre>#[embassy_executor::task]<br>async fn mytask() {<br>  loop {<br>    info!(&quot;Hello, World!&quot;);<br>    Timer::after_millis(500).await;<br>  }<br>}<br><br>spawner.spawn(mytask());</pre><p>This task now runs concurrently with other tasks and uses asynchronous programming to yield control whenever it encounters an <a href="https://doc.rust-lang.org/std/keyword.await.html">await</a> point. This is the principle of a <a href="https://en.wikipedia.org/wiki/Cooperative_multitasking"><strong>cooperative</strong></a> system, as opposed to <a href="https://en.wikipedia.org/wiki/Preemption_(computing)"><strong>preemptive</strong></a>.</p><h3>The Screen</h3><p>Our first task involves display, so let’s start by creating a structure representing the screen and a mechanism to receive the images to display:</p><pre>mod image {<br>  pub const ROWS: usize = 5;<br>  pub const COLS: usize = 5;<br><br>  pub type Image = [[u8; COLS]; ROWS];<br>  pub static IMG_SIG: Signal&lt;CriticalSectionRawMutex, Image&gt; = Signal::new();<br>}</pre><p>A <a href="https://docs.rs/embassy-sync/latest/embassy_sync/signal/struct.Signal.html">Signal</a> is a synchronization primitive that allows tasks to send data to each other. It is declared static to be shared and is protected from concurrent access by a <a href="https://docs.embassy.dev/embassy-sync/git/default/critical_section/struct.CriticalSectionRawMutex.html">CriticalSectionRawMutex</a>.</p><p>Next, let’s pass the pins corresponding to the LED matrix rows and columns to our task via two arrays:</p><pre>use embassy_nrf::gpio::Pin;<br><br>let rows = [<br>  p.P0_21.degrade(),<br>  p.P0_22.degrade(),<br>  p.P0_15.degrade(),<br>  p.P0_24.degrade(),<br>  p.P0_19.degrade(),<br>];<br>let cols = [<br>  p.P0_28.degrade(),<br>  p.P0_11.degrade(),<br>  p.P0_31.degrade(),<br>  p.P1_05.degrade(),<br>  p.P0_30.degrade(),<br>];</pre><p>Since each pin has a different type, we need to convert them to a unique type to insert them into an array. The <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/gpio/trait.Pin.html#method.degrade">degrade()</a> method of the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/gpio/trait.Pin.html">Pin trait</a> allows us to do this by transforming them into <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/gpio/struct.AnyPin.html">AnyPin</a>.</p><p>We can now modify the task prototype:</p><pre>#[embassy_executor::task]<br>async fn display_task(r_pins: [AnyPin; image::ROWS], c_pins: [AnyPin; image::COLS]) { ... }</pre><p>Let’s move on to implementing the task itself: we’ll start by initializing the pins in output mode:</p><pre>let mut r_pins = r_pins.map(|r| Output::new(r, Level::Low, OutputDrive::Standard));<br>let mut c_pins = c_pins.map(|c| Output::new(c, Level::High, OutputDrive::Standard)</pre><p>Then, we need to wait for the first image to be signaled for display:</p><pre>let mut img = image::IMG_SIG.wait().await;</pre><p>The <a href="https://docs.rs/embassy-sync/latest/embassy_sync/signal/struct.Signal.html#method.wait">wait</a> function returns a <a href="https://doc.rust-lang.org/std/future/trait.Future.html">Future</a> that will resolve when the signal is emitted (i.e., when the main task sends its first image). We can thus await it.</p><p>Considering the electrical schematic, it’s not possible to manage the image all at once because lighting two diagonal LEDs also lights the other two LEDs on the same row and column. We will therefore display the image line by line very quickly, relying on persistence of vision.</p><p>To do this, we need a <a href="https://docs.rs/embassy-time/latest/embassy_time/struct.Ticker.html">Ticker</a> with the appropriate frequency. 60Hz is enough for the human eye not to notice. Knowing that we have 5 lines, we can initialize it as follows:</p><pre>let mut ticker = Ticker::every(Duration::from_hz(60 * img.len() as u64));</pre><p>From here, we can start the display loop, which will:</p><ul><li>Display a row of the image</li><li>Wait for a tick</li><li>Turn off the row</li><li>If a new image is signaled, update it</li></ul><pre>loop {<br>  for (r_pin, r_img) in r_pins.iter_mut().zip(img) {<br>    c_pins<br>      .iter_mut()<br>      .zip(r_img)<br>      .filter(|(_, c_img)| *c_img != 0)<br>      .for_each(|(pin, _)| pin.set_low());<br>    r_pin.set_high();<br><br>    ticker.next().await;<br><br>    r_pin.set_low();<br>    c_pins.iter_mut().for_each(|pin| pin.set_high());<br>    if let Some(new_img) = IMG_SIG.try_take() {<br>      img = new_img;<br>      break;<br>    }<br>  }<br>}</pre><p>We can test this mechanism by sending it a fixed image:</p><pre>const HAPPY: Image = [<br>  [0, 1, 0, 1, 0],<br>  [0, 1, 0, 1, 0],<br>  [0, 0, 0, 0, 0],<br>  [1, 0, 0, 0, 1],<br>  [0, 1, 1, 1, 0],<br>];<br><br>image::IMG_SIG.signal(HAPPY);</pre><p>We now have a functional screen; all that remains is to send actual images to display.</p><h3>The Controller</h3><p>The control task is a bit simpler: the touch button will be used to start a game, and buttons A and B will direct the snake. We will pass them separately to the main task via a <a href="https://docs.rs/embassy-sync/latest/embassy_sync/channel/struct.Channel.html">Channel</a> and a <a href="https://docs.rs/embassy-sync/latest/embassy_sync/signal/struct.Signal.html">Signal</a>, respectively:</p><pre>pub static BTN_CHAN: Channel&lt;CriticalSectionRawMutex, Button, 10&gt; = Channel::new();<br>pub static TOUCH_SIG: Signal&lt;CriticalSectionRawMutex, ()&gt; = Signal::new();<br><br>pub enum Button {<br>  A,<br>  B,<br>}</pre><p>The type transmitted by the signal is (), meaning it transmits no data, only the &quot;start signal&quot; matters.</p><p>As with the screen, pass the pins corresponding to the buttons to the task:</p><pre>let (btn_a, btn_b, touch) = (p.P0_14.degrade(), p.P0_23.degrade(), p.P1_04.degrade());<br>spawner.spawn(control_task(btn_a, btn_b, touch));</pre><p>Modify the task prototype accordingly:</p><pre>#[embassy_executor::task]<br>async fn control_task(btn_a: AnyPin, btn_b: AnyPin, touch: AnyPin) { ... }</pre><p>Convert these pins to <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/gpio/struct.Input.html">Input</a>s, allowing us to retrieve their respective states. We can see from <a href="https://github.com/microbit-foundation/microbit-v2-hardware/blob/main/V2.21/MicroBit_V2.2.1_nRF52820%20schematic.PDF">the electrical schematic</a> that A and B have pull-up resistors, while the touch button does not:</p><pre>let mut btn_a = Input::new(btn_a, Pull::Up);<br>let mut btn_b = Input::new(btn_b, Pull::Up);<br>let mut touch = Input::new(touch, Pull::None);</pre><p>Electrically, a button is a switch that closes when pressed. We will wait for a button state change from high to low, then transmit it to the main task using the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/gpio/struct.Input.html#method.wait_for_falling_edge">Input::wait_for_falling_edge</a> function.</p><p>This function is asynchronous and returns a future. We have three events to monitor, and we can use the <a href="https://docs.rs/embassy-futures/latest/embassy_futures/select/fn.select3.html">select3</a> macro from the <a href="https://docs.rs/embassy-futures/latest/embassy_futures/index.html">embassy-futures crate</a> to handle this:</p><pre>match select3(<br>  btn_a.wait_for_falling_edge(),<br>  btn_b.wait_for_falling_edge(),<br>  touch.wait_for_falling_edge(),<br>).await { ... }</pre><p>When a button is pressed, one of the match arms is executed, allowing us to determine which button it is via <a href="https://docs.rs/embassy-futures/latest/embassy_futures/select/enum.Either3.html">Either3</a>:</p><pre>match { ... } {<br>  Either3::First(_) =&gt; BTN_CHAN.send(Button::A).await,<br>  Either3::Second(_) =&gt; BTN_CHAN.send(Button::B).await,<br>  Either3::Third(_) =&gt; TOUCH_SIG.signal(()),<br>}</pre><p>Since switches are mechanical components, they can be subject to bouncing. To prevent triggering the same event multiple times, we can add a debounce delay:</p><pre>Timer::after_millis(200).await;</pre><p>Finally, place this match in an infinite loop to continuously listen for commands:</p><pre>loop {<br>  match select3(<br>    btn_a.wait_for_falling_edge(),<br>    btn_b.wait_for_falling_edge(),<br>    touch.wait_for_falling_edge(),<br>  )<br>  .await<br>  {<br>    Either3::First(_) =&gt; BTN_CHAN.send(Button::A).await,<br>    Either3::Second(_) =&gt; BTN_CHAN.send(Button::B).await,<br>    Either3::Third(_) =&gt; TOUCH_SIG.signal(()),<br>  }<br><br>  Timer::after_millis(200).await;<br>}</pre><p>Our controller is ready; we will retrieve commands in the main task when appropriate.</p><h3>Handling the Game</h3><p>This section is not intended to describe the operation of the Snake game in detail, but to focus on the interesting aspects related to embedded systems. For reference, <a href="https://gitlab.com/cyril-marpaud/impl_snake_for_microbit">the complete source code of the project</a> is available on GitLab.</p><p>Broadly speaking, the main task will loop over the play function, which itself consists of the game’s three stages:</p><pre>struct Game {<br>  state: State,<br>  snake: Snake,<br>  food: Food,<br>}<br><br>#[embassy_executor::task]<br>pub async fn main_task(rng: RNG) {<br>  let mut game = Game::new(rng);<br><br>  loop {<br>    game.play().await;<br>  }<br>}<br>pub async fn play(&amp;mut self) {<br>  self.waiting_state().await;<br>  self.ongoing_state().await;<br>  self.over_state().await;<br>}</pre><h3>Generating the Food: Random Numbers</h3><p>Start this task by passing it the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/peripherals/struct.RNG.html">RNG</a> (<strong>R</strong>andom <strong>N</strong>umber <strong>G</strong>enerator):</p><pre>let rng = p.RNG;<br>spawner.spawn(main_task(rng));</pre><p>As the name suggests, it allows us to generate random numbers, which is useful for placing the snake’s food randomly on the screen.</p><p>As with the LEDs and buttons, the first step is to transform this peripheral into a usable programmatic object. This is what the new method does when initializing the game&#39;s state:</p><pre>pub fn new(rng: RNG) -&gt; Game {<br>  Game {<br>    state: Default::default(),<br>    snake: Default::default(),<br>    food: Food::new(Rng::new(rng, Irqs)),<br>  }<br>}</pre><p>The <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/rng/struct.Rng.html">Rng</a> object returned by the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/rng/struct.Rng.html#method.new">Rng::new</a> method implements the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/rng/struct.Rng.html#impl-RngCore-for-Rng%3C&#39;d,+T%3E">RngCore trait</a>. This is very interesting because the <a href="https://docs.rs/rand/latest/rand/trait.Rng.html">rand crate</a> defines the <a href="https://docs.rs/rand/latest/rand/trait.Rng.html">Rng trait</a> as a subtrait of RngCore.</p><p>This means that we can use the Rng trait with our peripheral to generate random numbers more sophisticatedly than using the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/rng/struct.Rng.html#implementations">low-level API of the embassy_nrf crate</a>.</p><p>For example, to generate a random number between 0 and 25:</p><pre>Resources// Import the trait into the local scope<br>use rand::Rng;<br><br>// ...<br>let rng = Rng::new(rng, Irqs);<br>let rand = rng.gen_range(0..25)</pre><h3>Binding Interrupts</h3><p>The more curious among you might be wondering what the Irqs structure passed to Rng::new is and what it is for. It is a structure generated by the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/macro.bind_interrupts.html">bind_interrupts macro</a>, which ensures at compile-time that the RNG interrupts are bound to ISRs (<a href="https://en.wikipedia.org/wiki/Interrupt_handler"><strong>I</strong>nterrupt <strong>S</strong>ervice <strong>R</strong>outines</a>).</p><p>Indeed, most peripherals in a microcontroller can generate interrupts to inform the core of an event. For example:</p><ul><li>An I²C or SPI peripheral generates an interrupt to signal that a message is available on the bus.</li><li>An RNG generates an interrupt to indicate that it has finished generating a random number.</li><li><a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/macro.bind_interrupts.html?search=InterruptHandler">etc.</a></li></ul><p>When one of these interrupts occurs, the core is interrupted and executes the corresponding ISR, which is a specific function that handles the interrupt. It is important to bind the interrupts we are interested in to ISRs to ensure they are executed when the events of interest occur.</p><p>In main.rs, we just need to bind the RNG interrupt to its ISR for everything to work correctly:</p><pre>bind_interrupts!(struct Irqs {<br>  RNG =&gt; embassy_nrf::rng::InterruptHandler&lt;RNG&gt;;<br>});</pre><h3>Storing Data on no_std</h3><p>Finally, I want to mention the <a href="https://crates.io/crates/heapless">heapless crate</a>, which allows us to define static data structures. This means that the size of these structures is known at compile-time, and they do not require dynamic allocation. This is very useful for embedded systems where memory is limited and dynamic allocation is undesirable.</p><p>The Snake structure in my source code is a <a href="https://docs.rs/heapless/latest/heapless/struct.Vec.html">Vec</a> with a capacity of 25 elements, the size of the screen. This means that the snake can never exceed this size, and the memory needed to store it is allocated at compile-time:</p><pre>use heapless::Vec;<br><br>struct Coords {<br>  x: usize,<br>  y: usize,<br>}<br>enum Direction {<br>  Up,<br>  Right,<br>  Down,<br>  Left,<br>}<br>struct Snake(Vec&lt;Coords, { ROWS * COLS }&gt;, Direction);</pre><p>Other structures like <a href="https://docs.rs/heapless/latest/heapless/struct.Deque.html">Deque</a>, <a href="https://docs.rs/heapless/latest/heapless/struct.IndexMap.html">IndexMap</a>, or <a href="https://docs.rs/heapless/latest/heapless/struct.String.html">String</a> are also available.</p><h3>Bonus: Adding Sound</h3><p>The example project contains an additional task that uses the board’s speaker to play simple sounds. To do this, it uses the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/pwm/struct.Pwm.html">PWM</a> (<a href="https://en.wikipedia.org/wiki/Pulse-width_modulation"><strong>P</strong>ulse <strong>W</strong>idth <strong>M</strong>odulation</a>) peripheral, which generates signals of variable frequency.</p><p>We can see from <a href="https://tech.microbit.org/hardware/schematic/#v2-pinmap">the pin mapping</a> that the speaker is assigned to pin P0_00. We need to send the PWM signal to this pin. A simple technique is to use the <a href="https://docs.embassy.dev/embassy-nrf/git/nrf52832/pwm/struct.SimplePwm.html">SimplePwm driver</a>.</p><p>For the rest, feel free to explore this path ;)</p><h3>Conclusion</h3><p>This project demonstrates Rust’s strengths for embedded development, especially with async programming. Rust’s memory safety and zero-cost abstractions translate directly into reliability and performance, making it well-suited for production-ready embedded and IoT.</p><p>The async model in Embassy introduces a concurrency approach where tasks are efficiently woken by wakers, similar to the way microcontrollers respond to hardware interrupts. This approach allows tasks to react quickly to events while maintaining a clean and organized code structure, without the complexity of traditional interrupt-driven programming. The PAC+HAL stack further showcases Rust’s flexibility, combining low-level control with high-level abstractions to balance precision and ease of use.</p><p>Rust’s rich ecosystem, including tools like probe-rs and built-in cross-compiling support, streamlines the development process compared to more traditional languages. Setting up projects, flashing, debugging, and leveraging crates like heapless for memory-efficient data handling become more intuitive, enabling scalable and reliable embedded solutions.</p><p>As embedded systems demand modern practices, Rust’s approach to safety, async programming, and hardware flexibility, empowered by a rich ecosystem, establishes it as a mature, production-ready option for modern embedded and IoT projects.</p><h3>Further Reading</h3><ul><li><a href="https://www.youtube.com/watch?v=8_Pj6q_mVQw">Rust Lyon Meetup #8: impl Snake for Micro:bit</a></li><li><a href="https://tweedegolf.nl/en/blog/65/async-rust-vs-rtos-showdown">Async Rust vs RTOS showdown!</a></li><li><a href="https://notgull.net/why-not-threads/">Why choose async/await over threads?</a></li><li><a href="https://interrupt.memfault.com/blog/embedded-async-rust">Asynchronous Rust on Cortex-M Microcontrollers</a></li><li><a href="https://en.wikipedia.org/wiki/Snake_(video_game_genre)">Snake (video game genre) — Wikipedia</a></li><li><a href="https://en.wikipedia.org/wiki/Pulse-width_modulation">Pulse Width Modulation — Wikipedia</a></li><li><a href="https://en.wikipedia.org/wiki/Cooperative_multitasking">Cooperative Multitasking — Wikipedia</a></li><li><a href="https://en.wikipedia.org/wiki/Preemption_(computing)">Preemption (Computing) — Wikipedia</a></li><li><a href="https://en.wikipedia.org/wiki/Interrupt_handler">Interrupt Handler — Wikipedia</a></li></ul><h3>BBC Micro:bit</h3><ul><li><a href="https://microbit.org/">BBC Micro:bit</a></li><li><a href="https://tech.microbit.org/hardware/">Micro:bit Hardware Documentation</a></li><li><a href="https://tech.microbit.org/hardware/schematic/#v2-pinmap">Micro:bit V2 Pin Mapping</a></li><li><a href="https://github.com/microbit-foundation/microbit-v2-hardware/blob/main/V2.21/MicroBit_V2.2.1_nRF52820%20schematic.PDF">Micro:bit V2.2.1 Schematic</a></li></ul><h3>The Rust Language</h3><ul><li><a href="https://www.rust-lang.org/">Rust Programming Language</a></li><li><a href="https://doc.rust-lang.org/std/keyword.await.html">Rust Async Await Documentation</a></li><li><a href="https://doc.rust-lang.org/std/future/trait.Future.html">Rust Futures</a></li></ul><h3>Embassy</h3><ul><li><a href="https://embassy.dev/">Embassy — Async Rust for Embedded Systems</a></li><li><a href="https://github.com/adinack/cargo-embassy">Cargo Embassy</a></li></ul><h3>Probe-rs</h3><ul><li><a href="https://probe.rs/">Probe-rs</a></li><li><a href="https://probe.rs/docs/getting-started/installation/#using-install-scripts">Probe-rs Installation Guide</a></li><li><a href="https://probe.rs/targets/">Supported Targets for Probe-rs</a></li><li><a href="https://probe.rs/targets/master/nRF52833_xxAA">nRF52833_xxAA Target — Probe-rs</a></li></ul><h3>Dependencies</h3><ul><li><a href="https://docs.rs/heapless/">Heapless Crate</a>My</li><li><a href="https://docs.rs/cortex-m-rt/latest/cortex_m_rt/#requirements">Cortex-M-RT Crate Requirements</a></li><li><a href="https://defmt.ferrous-systems.com/setup.html#linker-script">Defmt Setup for Logs</a></li></ul><h3>Whoami</h3><p>My name is <a href="https://cyril-marpaud.gitlab.io/en/">Cyril Marpaud</a>, I’m an embedded systems freelance engineer and a Rust enthusiast 🦀 I have 10 years experience and am currently living in Lyon (France).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/111/0*g3F5gy2z8yepDtrx" /><figcaption>Interested ? Contact me on LinkedIn !</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a517a23f1228" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded Rust on BBC Micro Bit: Unlocking Vec and HashMap]]></title>
            <link>https://medium.com/better-programming/embedded-rust-on-bbc-micro-bit-unlocking-vec-and-hashmap-172445df8217?source=rss-8e8b38934535------2</link>
            <guid isPermaLink="false">https://medium.com/p/172445df8217</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[arm]]></category>
            <category><![CDATA[bbc-microbit]]></category>
            <dc:creator><![CDATA[Cyril Marpaud]]></dc:creator>
            <pubDate>Fri, 24 Mar 2023 10:07:23 GMT</pubDate>
            <atom:updated>2023-03-31T08:22:03.572Z</atom:updated>
            <content:encoded><![CDATA[<h4>Explore embedded programming with Rust</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*n0usI63TAzwh-ajdAsbQbg.png" /><figcaption>Ferris on BBC micro:bit</figcaption></figure><p>As an engineer having spent most of 2022 learning <a href="https://www.rust-lang.org/">the Rust language</a>, I was a little worried about the <a href="https://docs.rust-embedded.org/book/intro/no-std.html">no_std</a> side of embedded systems programming.</p><p>Embedded systems, like the <a href="https://en.wikipedia.org/wiki/Micro_Bit">BBC Micro Bit</a> (a small <a href="https://en.wikipedia.org/wiki/ARM_Cortex-M#Cortex-M4">ARM Cortex-M4F</a>-based computer designed for educational purposes featuring a 5×5 LED matrix, multiple sensors, Bluetooth Low Energy capabilities and a lot more), are usually programmed as bare_metal devices in a no_std environment, meaning we can&#39;t use the <a href="https://doc.rust-lang.org/std/index.html">std</a> crate where Vec and HashMap, among others, reside.</p><p>While very understandable when considering older devices, the growing specs and capabilities of modern devices make it increasingly tempting to use higher-level abstractions. The purpose of this tutorial is thus to demonstrate how to enable the use of <a href="https://doc.rust-lang.org/std/vec/struct.Vec.html">Vec</a> and <a href="https://doc.rust-lang.org/std/collections/struct.HashMap.html">HashMap</a> on a BBC Micro Bit.</p><p>The original article and associated examples are available in my <a href="https://gitlab.com/cyril-marpaud/microbit_vec_hashmap">Micro Bit Vec and HashMap</a> GitLab repository. Let us now initiate this endeavor.</p><h3>Requirements</h3><p>This tutorial does not require much, except:</p><ul><li>A computer with internet access</li><li>A <a href="https://microbit.org/">BBC Micro Bit</a></li><li>A USB cable</li><li>Less than an hour of your time</li></ul><h3>Setting up the OS</h3><p>It is assumed that you have a fully functional 22.10 Ubuntu Linux distribution up and running. If you don’t, <a href="https://gitlab.com/cyril-marpaud/rust_esp_quickstart/-/blob/main/README.md#the-os">detailed instructions to set one up can be found in my previous tutorial</a>.</p><h3>Setting up the development environment</h3><p>First of all, we are going to install a few required dependencies. Open a terminal (the default shortcut is Ctrl+Alt+T) and run the following command:</p><pre>sudo apt install --yes curl gcc libudev-dev=251.4-1ubuntu7 pkg-config</pre><p><em>(installing version </em><em>251.4-1ubuntu7.1 of </em><em>libudev-dev induces a crash on my machine so I&#39;m using the version </em><em>251.4-1ubuntu7 instead)</em></p><p>We also need to install <a href="https://www.rust-lang.org/">Rust</a> and <a href="https://doc.rust-lang.org/stable/cargo/">Cargo</a>. <a href="https://rustup.rs/">Rustup</a> can take care of that for us:</p><pre>curl --proto &#39;=https&#39; --tlsv1.2 --fail --show-error --silent https://sh.rustup.rs | sh -s -- -y<br>source &quot;$HOME/.cargo/env&quot;</pre><p>As we will be compiling for an ARM Cortex-M4F microcontroller, we have to install <a href="https://doc.rust-lang.org/beta/rustc/platform-support.html">the adequate target</a>:</p><pre>rustup target add thumbv7em-none-eabihf</pre><p>After compilation comes flashing. <a href="https://probe.rs/docs/tools/cargo-embed/">cargo embed</a> is the solution we will be using for that purpose. Install it like so:</p><pre>cargo install cargo-embed</pre><p>Finally, a udev rule will take care of granting USB access to the Micro Bit:</p><pre>echo &quot;SUBSYSTEMS==\&quot;usb\&quot;, ATTRS{idVendor}==\&quot;0d28\&quot;, ATTRS{idProduct}==\&quot;0204\&quot;, MODE=\&quot;0660\&quot;, GROUP=\&quot;plugdev\&quot;&quot; | sudo tee /etc/udev/rules.d/99-microbit.rules &gt; /dev/null<br>sudo udevadm control --reload-rules &amp;&amp; sudo udevadm trigger</pre><h3>Setting up the project</h3><p>Cargo makes it easy to create a Rust project and add the adequate dependencies:</p><pre>cargo init microbit<br>cd microbit<br>cargo add cortex-m-rt microbit-v2 panic_halt</pre><p>Now, cargo embed needs to know which device it has to flash. Create a file named Embed.toml at the root of the project with the following content:</p><pre>[default.general]<br>chip = &quot;nrf52833_xxAA&quot;</pre><p>We can either specify a --target flag each time we compile our software or set that up once and for all in a configuration file. Moreover, our device&#39;s memory layout needs to be provided to the linker. Create the following .cargo/config file which will do just that for us:</p><pre>mkdir .cargo<br>touch .cargo/config</pre><pre>[target.&#39;cfg(all(target_arch = &quot;arm&quot;, target_os = &quot;none&quot;))&#39;]<br>rustflags = [<br>	&quot;-C&quot;, &quot;link-arg=-Tlink.x&quot;,<br>]<br><br>[build]<br>target = &quot;thumbv7em-none-eabihf&quot;</pre><p>Finally, open src/main.rs and copy/paste this LED-blink minimal example inside:</p><pre>#![no_main]<br>#![no_std]<br><br>use cortex_m_rt::entry;<br>use microbit::{<br>  board::Board,<br>  hal::{prelude::*, timer::Timer},<br>};<br>use panic_halt as _;<br><br>#[entry]<br>fn main() -&gt; ! {<br>  let mut board = Board::take().expect(&quot;Failed to take board&quot;);<br>  let mut timer = Timer::new(board.TIMER0);<br>  let mut row = board.display_pins.row1;<br>  let delay = 150u16;<br><br>  board.display_pins.col1.set_low().expect(&quot;Failed to set col1 low&quot;);<br><br>  loop {<br>    row.set_high().expect(&quot;Failed to set row1 high&quot;);<br>    timer.delay_ms(delay);<br>    row.set_low().expect(&quot;Failed to set row1 low&quot;);<br>    timer.delay_ms(delay);<br>  }<br>}</pre><h3>Blinking an LED</h3><p>Plug the board to your computer then compile the program and flash it single-handedly with this simple command:</p><pre>cargo embed</pre><p>When the process ends, you should see the upper-left LED blink. Congratulations!</p><h3>Unlocking Vec</h3><p>I have to admit that I shamefully lied when I told you <a href="https://doc.rust-lang.org/std/index.html?search=vec">Vec resides in the </a><a href="https://doc.rust-lang.org/std/index.html?search=vec">std crate</a> as <a href="https://doc.rust-lang.org/alloc/vec/struct.Vec.html">it is actually available in the </a><a href="https://doc.rust-lang.org/alloc/vec/struct.Vec.html">alloc crate</a>. As the name suggests, using it requires an allocator.</p><p>Luckily, the embedded-alloc crate provides us with one (there is <a href="https://github.com/rust-embedded/embedded-alloc">a complete example in the associated Github repository</a>). We also need the cortex-m crate to handle critical sections. Add them to the project&#39;s dependencies like so:</p><pre>cargo add embedded-alloc<br>cargo add cortex-m --features critical-section-single-core</pre><p>Then, in src/main.rs, we need to customize a few things. Import Vec and declare a global allocator:</p><pre>extern crate alloc;<br>use alloc::vec::Vec;<br><br>use embedded_alloc::Heap;<br><br>#[global_allocator]<br>static HEAP: Heap = Heap::empty();</pre><p>At the beginning of the main function, initialize the allocator and a size for our heap (the Micro Bit has 128KiB of RAM):</p><pre>{<br>  use core::mem::MaybeUninit;<br>  const HEAP_SIZE: usize = 8192; // 8KiB<br>  static mut HEAP_MEM: [MaybeUninit&lt;u8&gt;; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];<br>  unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }<br>}</pre><p>Replace the main loop, using Vec:</p><pre>let mut vec = Vec::new();<br>vec.push(true);<br>vec.push(false);<br>vec.push(true);<br>vec.push(false);<br>vec.push(false);<br>vec.push(false);<br><br>vec.iter().cycle().for_each(|v| {<br>	match v {<br>		true =&gt; row.set_high().expect(&quot;Failed to set row high&quot;),<br>		false =&gt; row.set_low().expect(&quot;Failed to set row low&quot;),<br>	}<br>	timer.delay_ms(delay);<br>});<br><br>loop {}</pre><p>Finally, compile and flash:</p><pre>cargo embed</pre><p>The LED should now be blinking in a heartbeat pattern. You are using Rust’s Vec on a Micro Bit, congratulations!</p><h3>Unlocking HashMap</h3><p>Unlike Vec, <a href="https://doc.rust-lang.org/std/index.html?search=HashMap">the </a><a href="https://doc.rust-lang.org/std/index.html?search=HashMap">alloc crate does not suffice for </a><a href="https://doc.rust-lang.org/std/index.html?search=HashMap">HashMap</a>, full std is required (which in turn requires a nightly toolchain because std is not supported for our platform). To avoid having to type +nightly each time we invoke cargo or rustup, create a file named rust-toolchain.toml with the following content:</p><pre>[toolchain]<br>channel = &quot;nightly&quot;</pre><p>As building the std crate requires its source code, use rustup to fetch that component:</p><pre>rustup component add rust-src</pre><p>In .cargo/config, add the following lines (panic_abort is needed here because of <a href="https://github.com/rust-lang/rust/issues/83805#issuecomment-812874115">a currently unresolved issue</a>):</p><pre>[unstable]<br>build-std = [&quot;std&quot;, &quot;panic_abort&quot;]</pre><p>The std crate provides an allocator, we can therefore remove those lines from src/main.rs:</p><pre>#![no_std]</pre><pre>extern crate alloc;<br>use alloc::vec::Vec;</pre><p>std also provides a panic handler, the import and panic-halt dependency can therefore be removed:</p><pre>use panic_halt as _;</pre><pre>cargo remove panic-halt</pre><p>Now that we are rid of those useless parts, there are a few things we need to add. As we’re building std for an unsupported (thus flagged <em>unstable</em>) platform, we need the restricted_std feature. Add it to src/main.rs:</p><pre>#![feature(restricted_std)</pre><p>Import HashMap:</p><pre>use std::{<br>	collections::{hash_map::DefaultHasher, HashMap},<br>	hash::BuildHasherDefault,<br>};</pre><p>And use it instead of Vec:</p><pre>let mut hm = HashMap::with_hasher(BuildHasherDefault::&lt;DefaultHasher&gt;::default());<br>hm.insert(0, false);<br>hm.insert(1, true);<br>hm.insert(2, false);<br>hm.insert(3, true);<br>hm.insert(4, true);<br>hm.insert(5, true);<br><br>hm.values().cycle().for_each(|v| {<br>	match v {<br>		true =&gt; row.set_high().expect(&quot;Failed to set row high&quot;),<br>		false =&gt; row.set_low().expect(&quot;Failed to set row low&quot;),<br>	}<br>	timer.delay_ms(delay);<br>});<br><br>loop {}</pre><p>The reason we are providing our own hasher is that the default one relies on the sys crate which is platform dependent. Our platform being unsupported, <a href="https://github.com/rust-lang/rust/tree/master/library/std/src/sys/unsupported">the associated implementation</a> either does nothing or <a href="https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unsupported/common.rs#L15">fails</a>.</p><p>Therefore, keep in mind that using anything from said sys crate will either fail or hang (in particular: threads). HashMap is fine though, and the above snippet should make the LED blink in an inverted heartbeat pattern:</p><pre>cargo embed</pre><p>Rust’s HashMap on a Micro Bit, Hooray !</p><h3>Actually using HashMap</h3><p>The <a href="https://gitlab.com/cyril-marpaud/microbit_vec_hashmap/-/tree/main/alphabet">alphabet folder</a> of my Gitlab repository demonstrates how to display caracters on the LED matrix using a HashMap. You can flash it by running the following commands:</p><pre>cd	# We need to move out of the &quot;microbit&quot; folder we created earlier<br>sudo apt install --yes git<br>git clone https://gitlab.com/cyril-marpaud/microbit_vec_hashmap.git<br>cd microbit_vec_hashmap/alphabet<br>cargo embed</pre><h3>Conclusion</h3><p>The ability to use Rust collections on a device as humble as the BBC micro:bit represents a remarkable achievement in embedded programming. Thanks to recent hardware advances, even modest embedded devices can now support high-level abstractions that were once the exclusive domain of larger and more expensive systems.</p><p>Rust’s efficiency and modern design make it an ideal language for taking advantage of these new capabilities and pushing the limits of what is possible on a microcontroller: developers can create complex and sophisticated projects that once seemed impossible on such small devices, from data-driven sensors to interactive games and applications.</p><p>Whether you are a seasoned expert or just getting started, the future of embedded programming is brighter than ever, and Rust is leading the way.</p><h3>See also (aka useful links)</h3><h3>Documentation</h3><ul><li><a href="https://www.rust-lang.org/">The Rust Language</a></li><li><a href="https://en.wikipedia.org/wiki/Micro_Bit">BBC Micro Bit</a></li></ul><h3>Crates</h3><ul><li><a href="https://docs.rs/microbit-v2/0.13.0/microbit/">microbit</a></li><li><a href="https://docs.rs/lsm303agr/latest/lsm303agr/index.html">LMS303AGR</a></li><li><a href="https://docs.rs/tiny-led-matrix/latest/tiny_led_matrix/">tiny_led_matrix</a></li><li><a href="https://docs.rs/cortex-m/0.7.7/cortex_m/">cortex_m</a></li><li><a href="https://docs.rs/cortex-m-log/latest/cortex_m_log/">cortex_m_log</a></li><li><a href="https://crates.io/crates/minimult_cortex-m">minimult_cortex-m</a></li><li><a href="https://docs.rs/embedded-alloc/0.5.0/embedded_alloc/">embedded_alloc</a></li></ul><h3>Tutorials</h3><ul><li><a href="https://docs.rust-embedded.org/discovery/microbit/index.html">Discovery</a></li><li><a href="https://blog.timhutt.co.uk/std-embedded-rust/index.html">std on Micro Bit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=172445df8217" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/embedded-rust-on-bbc-micro-bit-unlocking-vec-and-hashmap-172445df8217">Embedded Rust on BBC Micro Bit: Unlocking Vec and HashMap</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up a Zola website with HayFlow theme in under 15 minutes]]></title>
            <link>https://medium.com/@cyril.marpaud/how-to-set-up-a-zola-website-with-hayflow-theme-in-under-15-minutes-5df9b14b0882?source=rss-8e8b38934535------2</link>
            <guid isPermaLink="false">https://medium.com/p/5df9b14b0882</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[zola]]></category>
            <category><![CDATA[landing-pages]]></category>
            <dc:creator><![CDATA[Cyril Marpaud]]></dc:creator>
            <pubDate>Fri, 10 Mar 2023 21:07:52 GMT</pubDate>
            <atom:updated>2023-03-10T22:54:34.716Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>(This article was written by <a href="https://fr.wikipedia.org/wiki/ChatGPT">ChatGPT</a> based on <a href="https://gitlab.com/cyril-marpaud/hayflow/-/blob/main/README.md">HayFlow’s readme</a>.)</blockquote><p>If you’re looking for a clean, modern-looking website theme that’s easy to set up, HayFlow is a great option. This theme is designed to work with Zola, a static site generator written in Rust, and it features a dark theme with a particles background, vertical arrows for navigation, and a few card types to choose from. Best of all, it requires only Markdown editing, so you don’t need to know HTML or CSS to use it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*MKkRMZwO6eoU6k-8tVBtZg.png" /><figcaption>A landing page built with Zola and HayFlow theme</figcaption></figure><h3>Prerequisites</h3><p>Before you begin, you’ll need to make sure you have <a href="https://www.getzola.org/documentation/getting-started/installation/">Zola</a> installed on your system. You’ll also need to have <a href="https://git-scm.com/downloads">Git</a> installed to be able to clone the HayFlow theme repository.</p><h3>Live demo</h3><p>See <a href="https://cyril-marpaud.gitlab.io/">my personal website</a> to get a sense of what can be accomplished in a few minutes with this theme. Its source code is also available as an example in my <a href="https://gitlab.com/cyril-marpaud/cyril-marpaud.gitlab.io">Gitlab website repository</a>.</p><h3>1. Initialize a new Zola website</h3><p>The first step is to initialize a new Zola website. Open your terminal and navigate to the directory where you want to create your new website. Then, enter the following command:</p><pre>zola init mywebsite</pre><p>This will create a new directory called <em>mywebsite</em> with the basic files and folders needed to run a Zola website.</p><h3>2. Download and install the HayFlow theme</h3><p>Next, you need to download and install the HayFlow theme. To do this, navigate to the <em>mywebsite</em> directory in your terminal and clone the repository:</p><pre>cd mywebsite<br>git clone git@gitlab.com:cyril-marpaud/hayflow.git themes/hayflow</pre><p>This will download the HayFlow theme from the GitLab repository and place it in a new directory called <em>themes/hayflow</em>.</p><h3>3. Configure your website to use the HayFlow theme</h3><p>Now that you have the HayFlow theme installed, you need to tell Zola to use it for your website. Open the <em>config.toml</em> file in your text editor and add the following line at the top:</p><pre>theme = &quot;hayflow&quot;</pre><p>This tells Zola to use the HayFlow theme for your website. Save the file and close it.</p><h3>4. Run your website</h3><p>With your website set up and customized, you’re ready to run it. Open your terminal, navigate to the <em>mywebsite</em> directory, and enter the following command:</p><pre>zola serve</pre><p>This will start a local web server and open your website in your default web browser. You should now see your landing page.</p><h3>5. Customize your landing page</h3><p>With the HayFlow theme installed and configured, you’re ready to customize your landing page. Open the <em>config.toml</em> file again and scroll down to the <em>[extra]</em> section. This is where you can add variables to customize your landing page.</p><p>There are three variables you can use to customize your landing page:</p><ul><li><em>name</em>: This is your name.</li><li><em>roles</em>: This is an array of strings that represent your roles or areas of expertise.</li><li><em>links</em>: This is an array of objects that represent links to your social media profiles or other pages. You can use any free icon from <a href="https://fontawesome.com/search?o=r&amp;m=free">Font Awesome</a>.</li></ul><p>To add your own information, simply replace the default values with your own. For example:</p><pre>[extra]<br>name = { first = &quot;John&quot;, last = &quot;Doe&quot; }<br><br>roles = [&quot;Web Developer&quot;, &quot;Graphic Designer&quot;, &quot;Social Media Manager&quot;]<br><br>links = [<br>  { icon = &quot;fa-brands fa-twitter&quot;, url = &quot;https://twitter.com/johndoe&quot; },<br>  { icon = &quot;fa-brands fa-linkedin&quot;, url = &quot;https://www.linkedin.com/in/johndoe&quot; },<br>  { icon = &quot;fa-solid fa-envelope&quot;, url = &quot;johndoe@example.com&quot; },<br>]</pre><p>Once you’ve made your changes, save the <em>config.toml</em> file and close it.</p><h3>6. Add additional sections to your landing page</h3><p>One of the great features of the HayFlow theme is its support for multiple sections on your landing page. You can create new sections by adding new folders inside the <em>content</em> directory and adding Markdown files to those folders.</p><p>For example, to create a new section called “Pizza”, create a new folder inside the <em>content</em> directory with the name of your section (e.g. pizza) and add an <em>_index.md</em> file inside it with the following front matter:</p><pre>+++<br>title = &quot;Pizza&quot;<br>+++</pre><p>This will create a new section on your landing page with the title “Pizza”. You can add your own content to the section by editing the <em>_index.md</em> file.</p><h3>7. Customize section cards</h3><p>HayFlow offers three types of cards for your sections: <em>simple</em>, <em>columns</em>, and <em>list</em>. By default, sections use the simple card type, but you can customize this by adding a <em>card_type </em>variable to the front matter of your <em>_index.md </em>file.</p><p>For example, to create a section with a columns card type, create a new folder inside the content directory with the name of your section (e.g. <em>ingredients</em>) and add an <em>_index.md</em> file with the following front matter:</p><pre>+++<br>title = &quot;Ingredients&quot;<br>[extra]<br>card_type = &quot;columns&quot;<br>+++</pre><p>Next, create three additional Markdown files inside the <em>ingredients</em> folder with names like <em>one.md</em>, <em>two.md</em>, and <em>three.md</em>. These files will contain the content for your columns. Here’s an example for the <em>one.md </em>file:</p><pre>+++<br>title = &quot;Tomatoes&quot;<br>[extra]<br>icons = [&quot;fa-solid fa-tomato&quot;]<br>+++<br>Tomatoes are a delicious ingredient in many pizza recipes.</pre><p>This will create a column card with a tomato icon and the title “Tomatoes”.</p><p>If you want to create a section with a <em>list</em> card type, the process is similar. Just set the <em>card_type</em> variable to <em>list</em> in your <em>_index.md</em> file and create Markdown files for each item in your list. You can optionally set a <em>link </em>variable detailing the corresponding URL if applicable.</p><h3>Conclusion</h3><p>With HayFlow, you can have a beautiful and functional landing page up and running in just a few minutes. The modular design and support for multiple sections make it easy to customize your page to fit your needs, and the use of Markdown makes it easy for anyone to create and maintain their own landing page.</p><p>Whether you’re a freelancer, a small business owner, or just looking to create a personal website, HayFlow is a great choice for your landing page. So why not give it a try and see what you can create?</p><h3>Whoami</h3><p>My name is <a href="https://www.linkedin.com/in/cyrilmarpaud/">Cyril Marpaud, I’m an embedded systems freelance engineer and a Rust enthusiast 🦀</a> I have nearly 10 years experience and am currently living in Lyon (France).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5df9b14b0882" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded Rust on ESP32C3 Board, a Hands-on Quickstart Guide]]></title>
            <link>https://medium.com/@cyril.marpaud/embedded-rust-on-esp32c3-board-a-hands-on-quickstart-guide-a20fe5ff9b4b?source=rss-8e8b38934535------2</link>
            <guid isPermaLink="false">https://medium.com/p/a20fe5ff9b4b</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[visual-studio-code]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <dc:creator><![CDATA[Cyril Marpaud]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 19:01:37 GMT</pubDate>
            <atom:updated>2023-03-24T10:09:55.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*z4SR97vy_7Cmvlwxqygaig.png" /></figure><p>Today, I’ll be showing you how to use the <a href="https://www.rust-lang.org/">Rust programming language</a> on a <a href="https://github.com/esp-rs/esp-rust-board">Rust ESP board</a>, a recent embedded platform packed with Wi-Fi and Bluetooth capabilities.</p><p>We won’t go through the details of <a href="https://esp-rs.github.io/book/overview/index.html">no_std vs </a><a href="https://esp-rs.github.io/book/overview/index.html">std</a>development, just know that the latter allows us to use full Wi-Fi and Bluetooth capabilities along with the actual entire <a href="https://doc.rust-lang.org/std/index.html">Rust Standard Library</a> with ease which is usually <strong>NOT</strong> straightforward but hey, this is 2023, enjoy!</p><p>The original article and associated examples are available in my <a href="https://gitlab.com/cyril-marpaud/rust_esp_quickstart">Rust ESP Quickstart</a> GitLab repository.</p><h3>TL;DR</h3><p>If you are already running Linux and just want to flash your ESP board with a fully configured Rust “Hello, World!” project, see the <a href="https://gitlab.com/cyril.marpaud/rust_esp_quickstart/-/blob/main/script/setup.sh">script/setup.sh script</a>, it should help you get started in no time. Be aware, though, that it has been made for a freshly installed 22.10 Ubuntu distribution and is untested on any other platform yet (i.e. use it at your own risks). On the other hand, please read on if you intend to walk the learning path instead.</p><h3>Requirements</h3><p>Here’s everything we are going to need during our little adventure:</p><ul><li>A computer with internet access</li><li>A <a href="https://github.com/esp-rs/esp-rust-board">Rust ESP Board</a> (this is open hardware so you can either buy one or build one yourself!)</li><li>A USB cable</li><li>An empty USB stick that we are going to erase completely so don’t forget to <strong>BACKUP YOUR DATA FIRST</strong> (A 16GiB one is fine)</li><li>Less than an hour of your time</li></ul><h3>The OS</h3><p>We’ll be using a live 22.10 Ubuntu distribution so that:</p><ul><li>anyone with a decent computer can follow this guide</li><li>our setups are the exact same, thus greatly reducing the rate of environment-related errors</li><li>everything is instantly reversible, meaning that your computer will be left completely <strong>untouched</strong></li><li>we won’t need to go through an actual Linux installation</li></ul><p>One drawback of this solution is that each reboot will wipe the environment but feel free to actually install linux if persistence across said reboots is required.</p><h3>Making a bootable USB stick</h3><h4>Installing usb-creator-gtk on Linux</h4><p>Open a terminal (the default shortcut is Ctrl+ Alt+ T on Ubuntu) and run those commands:</p><pre>sudo apt update<br>sudo apt install --yes usb-creator-gtk</pre><h4>Installing Win32DiskImager on Windows</h4><p>Download the installer from <a href="https://sourceforge.net/projects/win32diskimager/">the project’s page</a> and run it.</p><h4>Flashing the USB stick</h4><p>In both cases, we will need to select the ISO image we want to flash and the device we want to use then click the <strong>Write</strong> or <strong>Make startup disk</strong> button. The process should complete within a few minutes.</p><h4>Booting Ubuntu</h4><p>Let’s ask <a href="https://chat.openai.com/">ChatGPT</a> how to do that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*lfuigJjppIqWv2-aXALQZw.png" /><figcaption>Booting a computer from a USB stick</figcaption></figure><p>Thank you ChatGPT ! Finally, hit that <strong>Try Ubuntu</strong> button to be greeted with a GNOME desktop.</p><p>The next steps require internet access so connect to a Wi-Fi (see the top-right corner menu) or wired network if you want to go old-school.</p><h3>The tools</h3><p>Here, we are going to make <strong>heavy</strong> use of a terminal. On Ubuntu, you can open one by pressing Ctrl+ Alt+ T. You might want to copy/paste the following commands to avoid typos but suit yourself!</p><h4>Build dependencies</h4><p>We need a few more packages than Ubuntu provides by default. Please bear with the trauma of installing them:</p><pre>sudo add-apt-repository --yes universe<br>sudo apt install --yes clang curl git libudev-dev libssl-dev pkg-config python3-pip</pre><h4>Rust and Cargo components</h4><p>We’ll now use <a href="https://rustup.rs/">Rustup</a> to install both <a href="https://github.com/rust-lang/rust">Rust</a> and <a href="https://github.com/rust-lang/cargo">Cargo</a> (Rust’s package manager):</p><p>Moreover, we need a few additional Cargo modules:</p><ul><li>espflash to flash the device (see <a href="https://github.com/esp-rs/espflash">espflash</a>)</li><li>ldproxy to forward linker arguments (see <a href="https://github.com/esp-rs/embuild/tree/f2cbbf9795676af52d2ffb53f102d70cac25116a/ldproxy">ldproxy</a>)</li><li>cargo-generate to generate projects according to a template (see <a href="https://github.com/cargo-generate/cargo-generate">cargo-generate</a>)</li></ul><pre>cargo install espflash ldproxy cargo-generate</pre><h3>Generating a project</h3><p>The awesome <a href="https://github.com/esp-rs/esp-idf-template">ESP IDF Template</a> will save us the pain of configuring a fully functional project ourselves, use it like so:</p><pre>cargo generate --git https://github.com/esp-rs/esp-idf-template cargo</pre><p>During the process, you will be asked a few things:</p><ul><li>a <strong>Project Name</strong>. Go wild and use <strong>test-project</strong>, for instance</li><li>an <strong>ESP-IDF native build version</strong>. Go with the <strong>stable</strong> one (it is <strong>v4.4</strong> at the moment)</li><li>an <strong>MCU</strong>. Our board is equipped with an <strong>ESP32C3</strong></li><li>support for <strong>dev containers</strong>. We don’t need that for now so that’s a <strong>false</strong></li><li>STD support. We’re building an std app so that’s a <strong>true</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*biacn1_KQugeDsDF.png" /><figcaption>For those who feel like cheating</figcaption></figure><h3>Hello, World!</h3><h4>Getting access to the USB peripheral</h4><p>You might like “Permission Denied” errors. If not, those commands will create a <em>udev</em> rule to avoid that when accessing our board through USB:</p><pre>echo &quot;SUBSYSTEMS==\&quot;usb\&quot;, ATTRS{idVendor}==\&quot;303a\&quot;, ATTRS{idProduct}==\&quot;1001\&quot;, MODE=\&quot;0660\&quot;, GROUP=\&quot;plugdev\&quot;&quot; | sudo tee /etc/udev/rules.d/99-esp-rust-board.rules &gt; /dev/null<br>sudo udevadm control --reload-rules &amp;&amp; sudo udevadm trigger</pre><h4>Flash, run &amp; monitor</h4><p>Now make use of that USB cable and connect the board to your computer, then run this simple yet elegant command:</p><pre>cargo run</pre><p>If everything goes smoothly, Cargo should build the project, flash it on the MCU and finally run it, meaning that a line reading “Hello, World!” should be displayed in the terminal. Hit Ctrl+ R to restart the program (not very useful at that point but it might be later) or Ctrl+ C to quit monitoring it.</p><p>Congratulations, you are officially programming Rust on your ESP board !</p><h3>The IDE</h3><p>We could configure Vim, Emacs or any other terminal-based IDE, but the low-friction solution is to use Visual Studio Code with the appropriate extensions. This way, we are only a few clicks away from syntax highlighting, code completion and much more.</p><h4>VSCodium</h4><p>It is the exact same as VSCode but without telemetry/tracking stuff, plus it uses MIT license (see <a href="https://vscodium.com/">the official website</a>). Install and run it like so:</p><pre>snap install codium --classic<br>codium</pre><p>An <strong>Open Folder</strong> button should be visible in the explorer tab on the left. Click it to add our project to the workspace. We are now able to edit source code way more handily than in a terminal.</p><h4>Extensions</h4><p>Go to the extensions tab and type “rust analyzer” in the search bar, then click the <strong>install</strong> button (“Rust language support for Visual Studio Code”). That’s it! You can find more information about it on the <a href="https://rust-analyzer.github.io/">official website</a>. The <a href="https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml">Even Better TOML</a> and <a href="https://marketplace.visualstudio.com/items?itemName=serayuzgur.crates">crates</a> extensions might also be of interest to you.</p><h3>Going further</h3><p>The <a href="https://gitlab.com/cyril.marpaud/rust_esp_quickstart/-/tree/main/examples">examples folder</a> of this repository contains three projects:</p><ul><li><strong>blink</strong>: makes the LED connected to GPIO7 blink</li><li><strong>i2c-sensors</strong>: read and display data from the embedded SHTC3 &amp; ICM42670 I2C sensors (temperature, humidity, accelerometer &amp; gyroscope)</li><li><strong>Wi-Fi</strong>: very basic Wi-Fi connection + ping example, just uncomment and fill WIFI_SSID and WIFI_PWD environment variables at the bottom of .cargo/config.toml</li></ul><h3>Conclusion</h3><p>As a kid, I used to boot my sister’s laptop from a live 8.04 “Hardy Heron” Ubuntu CD (you could order one for free back then!) to bypass her password protection. This way, no one ever knew what I was doing (meerely looking for cheat codes for the games I used to play at the time 😉️). Today, I still believe this technique is of great value to anyone wishing to try something out without breaking anything.</p><p>Growing up, I then had the pleasure to learn how embedded development can sometimes be a pain: messy setup, weird and abstruse error messages… But hopefully, it has been less than an hour since you began reading this article and you are now able to use a modern language with std support on a recent Wi-Fi-enabled microcontroller. Ain&#39;t that marvelous ?</p><p>I hope you enjoyed it as much as I do, especially when considering the tremendous amount of work that was needed to make this so easy for us.</p><p>Cheers!</p><h3>See also (aka useful links)</h3><h4>Documentation</h4><ul><li><a href="https://www.rust-lang.org/">The Rust Language</a></li><li><a href="https://github.com/esp-rs/esp-rust-board">The Rust ESP Board</a></li><li><a href="https://github.com/esp-rs">Espressif’s Rust-related repos</a></li></ul><h4>Crates</h4><ul><li><a href="https://github.com/esp-rs/esp-rust-board-bsp">Board Support Package</a></li><li><a href="https://docs.rs/esp32c3-hal/latest/esp32c3_hal/">ESP32C3 </a><a href="https://docs.rs/esp32c3-hal/latest/esp32c3_hal/">no_std Hardware Abstraction Layer</a></li><li><a href="https://esp-rs.github.io/esp-idf-hal/esp_idf_hal/">ESP32C3 </a><a href="https://esp-rs.github.io/esp-idf-hal/esp_idf_hal/">std Hardware Abstraction Layer</a></li><li><a href="https://github.com/esp-rs/esp-template">esp-template: </a><a href="https://github.com/esp-rs/esp-template">no_std project template</a></li><li><a href="https://github.com/esp-rs/esp-idf-template">esp-idf-template: </a><a href="https://github.com/esp-rs/esp-idf-template">std-enabled project template</a></li><li><a href="https://docs.rs/embedded-svc/latest/embedded_svc/">embedded-svc: service-related traits</a></li><li><a href="https://esp-rs.github.io/esp-idf-svc/esp_idf_svc/">esp-idf-svc: </a><a href="https://esp-rs.github.io/esp-idf-svc/esp_idf_svc/">embedded-svc implementation</a></li><li><a href="https://docs.rs/shared-bus/latest/shared_bus/">shared-bus: share I2C/SPI/ADC buses between peripherals (namely: sensors)</a></li><li><a href="https://docs.rs/shtcx/latest/shtcx/">shtcx: access the SHTC3 embedded temperature+humidity I2C sensor</a></li><li><a href="https://docs.rs/icm42670/latest/icm42670/">icm42670: access the ICM42670 embedded temperature+accelerometer+gyroscope I2C sensor</a></li></ul><h4>Examples</h4><ul><li><a href="https://github.com/ivmarkov/rust-esp32-std-demo">A complete STD demo on ESP32C3</a></li><li><a href="https://wokwi.com/projects/357177745915181057">A Rust ESP Board simulator (simple </a><a href="https://wokwi.com/projects/357177745915181057">no_std blink project)</a></li></ul><h4>Tutorials</h4><ul><li><a href="https://esp-rs.github.io/book/">Rust on ESP book</a></li><li><a href="https://espressif-trainings.ferrous-systems.com/">Embedded Rust on Espressif (Ferrous Systems training)</a></li><li><a href="https://betterprogramming.pub/rust-for-iot-is-it-time-67b14ab34b8">Another quickstart guide</a></li></ul><h3>Whoami</h3><p>My name is <a href="https://www.linkedin.com/in/cyrilmarpaud/">Cyril Marpaud, I’m an embedded systems freelance engineer and a Rust enthusiast 🦀</a> I have nearly 10 years experience and am currently living in Lyon (France).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a20fe5ff9b4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>