<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Loïc Chagnoleau</title>
    <subtitle>Embedded software engineer — firmware, low-level programming and reverse engineering on ARM microcontrollers.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://lchagnoleau.dev/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://lchagnoleau.dev"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2024-06-12T00:00:00+00:00</updated>
    <id>https://lchagnoleau.dev/atom.xml</id>
    <entry xml:lang="en">
        <title>STM32 minimal blinky code</title>
        <published>2024-06-12T00:00:00+00:00</published>
        <updated>2024-06-12T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lchagnoleau.dev/posts/stm32-minimal-blinky-code/"/>
        <id>https://lchagnoleau.dev/posts/stm32-minimal-blinky-code/</id>
        
        <content type="html" xml:base="https://lchagnoleau.dev/posts/stm32-minimal-blinky-code/">&lt;h2 id=&quot;introduction&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#introduction&quot; aria-label=&quot;Anchor link for: introduction&quot;&gt;Introduction&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This post will show you how to write the minimal blinky code for STM32 microcontrollers.
It is inspired by this &lt;a rel=&quot;external&quot; href=&quot;https://github.com/samvrlewis/minimal-stm32&quot;&gt;github&lt;/a&gt; project but here we will try to fully understand the code.&lt;/p&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#prerequisites&quot; aria-label=&quot;Anchor link for: prerequisites&quot;&gt;Prerequisites&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;We only need the svd file for the STM32F429 microcontroller.
We can found the official svd file on the &lt;a rel=&quot;external&quot; href=&quot;https://www.st.com/en/microcontrollers-microprocessors/stm32f429zi.html#cad-resources&quot;&gt;ST website&lt;/a&gt; -&amp;gt; STM32F4 System View Description.&lt;/p&gt;
&lt;h2 id=&quot;code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code&quot; aria-label=&quot;Anchor link for: code&quot;&gt;Code&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The Led we will use is the GPIOB pin 0.&lt;/p&gt;
&lt;h3 id=&quot;main-program&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#main-program&quot; aria-label=&quot;Anchor link for: main-program&quot;&gt;Main program&lt;/a&gt;&lt;/h3&gt;
&lt;h4 id=&quot;rcc-ahb1enr&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rcc-ahb1enr&quot; aria-label=&quot;Anchor link for: rcc-ahb1enr&quot;&gt;RCC_AHB1ENR&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;To enable the led, we start by enabling the GPIOB peripheral clock.
The register controlling the GPIOB peripheral clock is the RCC_AHB1ENR register.&lt;/p&gt;
&lt;p&gt;Following the svd file, we are looking foir the address of the RCC_AHB1ENR register.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;peripheral&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;name&amp;gt;RCC&amp;lt;/name&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;description&amp;gt;Reset and clock control&amp;lt;/description&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;groupName&amp;gt;RCC&amp;lt;/groupName&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;baseAddress&amp;gt;0x40023800&amp;lt;/baseAddress&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;addressBlock&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;register&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;name&amp;gt;AHB1ENR&amp;lt;/name&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;displayName&amp;gt;AHB1ENR&amp;lt;/displayName&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;description&amp;gt;AHB1 peripheral clock register&amp;lt;/description&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;addressOffset&amp;gt;0x30&amp;lt;/addressOffset&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We define it like this is our &lt;code&gt;maiu.c&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; PERIPH_BASE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;40000000&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;U&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; RCC_BASE&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;PERIPH_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;23800&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; RCC_AHB1ENR&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;RCC_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;30&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;  //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; Enable clock on GPIOB peripheral&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  RCC_AHB1ENR &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;gpiob-moder&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#gpiob-moder&quot; aria-label=&quot;Anchor link for: gpiob-moder&quot;&gt;GPIOB_MODER&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;The MODER register is used to set the mode of the GPIOB pin 0.
Like previously, we look for the address of the MODER register in the svd file.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;peripheral&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;name&amp;gt;GPIOB&amp;lt;/name&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;description&amp;gt;General-purpose I/Os&amp;lt;/description&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;groupName&amp;gt;GPIO&amp;lt;/groupName&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;baseAddress&amp;gt;0x40020400&amp;lt;/baseAddress&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;registers&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;register&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;name&amp;gt;MODER&amp;lt;/name&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;displayName&amp;gt;MODER&amp;lt;/displayName&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;description&amp;gt;GPIO port mode register&amp;lt;/description&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;addressOffset&amp;gt;0x0&amp;lt;/addressOffset&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To set the pin 0 as an output, we need to set the bit 0 (because we use the pin 0) of the MODER register to 1.
In the &lt;code&gt;main.c&lt;/code&gt; file, we define it like this:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; GPIOB_BASE&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;PERIPH_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;20400&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; GPIOB_MODER&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;GPIOB_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;00&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; LED_PIN&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;  //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; Put GPIOB0 into output mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  GPIOB_MODER &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;|=&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;01&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span&gt; LED_PIN &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 2&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;gpiob-odr&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#gpiob-odr&quot; aria-label=&quot;Anchor link for: gpiob-odr&quot;&gt;GPIOB_ODR&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Finally, we can toggle the pin 0 of the GPIOB port to make the led blink.
The register controlling the output of the GPIOB pin 0 is the ODR register.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;register&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;name&amp;gt;ODR&amp;lt;/name&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;displayName&amp;gt;ODR&amp;lt;/displayName&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;description&amp;gt;GPIO port output data register&amp;lt;/description&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;addressOffset&amp;gt;0x14&amp;lt;/addressOffset&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;main.c&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; GPIOB_ODR&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;GPIOB_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;14&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; LED_PIN&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  GPIOB_ODR &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span&gt; LED_PIN&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; set LED pin high&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;delay&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#delay&quot; aria-label=&quot;Anchor link for: delay&quot;&gt;Delay&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;To make the led blink, we need to add a delay.
We simply loop for a certain amount of time.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; sleep&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; sleep_time&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  while&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;sleep_time&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;--&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    __asm__&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;nop&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;vector-table&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#vector-table&quot; aria-label=&quot;Anchor link for: vector-table&quot;&gt;Vector table&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;We need to define the vector table at the beginning of the &lt;code&gt;main.c&lt;/code&gt; file.
The vector table is the first thing the microcontroller reads when it boots up.
The first address of the vector table is the stack pointer and the second address is the reset handler.&lt;/p&gt;
&lt;p&gt;We will set the stack pointer to the end of the RAM and the reset handler to the main function.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; SRAM_BASE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;20000000&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;U&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; SRAM_SIZE&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 192&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1024&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; SRAM_END&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;SRAM_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span&gt; SRAM_SIZE&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;vector_table&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; __attribute__&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;section&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;.vector_table&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;SRAM_END&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; place stack pointer at the end of SRAM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;                               //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; (stack grows down)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;main&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;      //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; reset handler, jump directly to main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;full-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#full-code&quot; aria-label=&quot;Anchor link for: full-code&quot;&gt;Full code&lt;/a&gt;&lt;/h4&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; PERIPH_BASE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;40000000&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;U&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; RCC_BASE&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;PERIPH_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;23800&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; RCC_AHB1ENR&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;RCC_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;30&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; GPIOB_BASE&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;PERIPH_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;20400&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; GPIOB_MODER&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;GPIOB_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;00&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; GPIOB_ODR&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;GPIOB_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;14&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; LED_PIN&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; SRAM_BASE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;20000000&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;U&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; SRAM_SIZE&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 192&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1024&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; SRAM_END&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;SRAM_BASE &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;+&lt;/span&gt;&lt;span&gt; SRAM_SIZE&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; sleep&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; sleep_time&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  while&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;sleep_time&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;--&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    __asm__&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;nop&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;  //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; Enable clock on GPIOB peripheral&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  RCC_AHB1ENR &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;  //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; Put GPIOB0 into output mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  GPIOB_MODER &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;|=&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; 0x&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;01&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span&gt; LED_PIN &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 2&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  while&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    GPIOB_ODR &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span&gt; LED_PIN&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; set LED pin high&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    sleep&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;1000000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    GPIOB_ODR &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span&gt; LED_PIN&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; set LED pin low&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    sleep&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;1000000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;vector_table&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; __attribute__&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;section&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;.vector_table&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;SRAM_END&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; place stack pointer at the end of SRAM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;                               //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; (stack grows down)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; long&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; *&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;main&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;      //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; reset handler, jump directly to main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;linker-script&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#linker-script&quot; aria-label=&quot;Anchor link for: linker-script&quot;&gt;Linker script&lt;/a&gt;&lt;/h3&gt;
&lt;h4 id=&quot;memory&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#memory&quot; aria-label=&quot;Anchor link for: memory&quot;&gt;MEMORY&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;In the linker script we will define the memory layout of the microcontroller.
The address of the FLASH and the RAM are defined in the datasheet of the microcontroller.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;MEMORY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    FLASH (rx)  : ORIGIN = 0x08000000, LENGTH = 2048K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    SRAM (xrw)  : ORIGIN = 0x20000000, LENGTH = 192K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;sections&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#sections&quot; aria-label=&quot;Anchor link for: sections&quot;&gt;SECTIONS&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;We will only define the &lt;code&gt;.text&lt;/code&gt; section for the code and the &lt;code&gt;.vector_table&lt;/code&gt; section for the vector table.
The &lt;code&gt;.text&lt;/code&gt; section is used to store the code and the &lt;code&gt;.vector_table&lt;/code&gt; section is used to store the vector table.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SECTIONS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .text :&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.vector_table)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.text)            /* code */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    } &amp;gt;FLASH&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;&amp;gt;FLASH&lt;/code&gt; means that the &lt;code&gt;.text&lt;/code&gt; section will be stored in the FLASH memory.&lt;/p&gt;
&lt;h4 id=&quot;full-linker-script&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#full-linker-script&quot; aria-label=&quot;Anchor link for: full-linker-script&quot;&gt;Full linker script&lt;/a&gt;&lt;/h4&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;MEMORY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    FLASH (rx)  : ORIGIN = 0x08000000, LENGTH = 2048K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    SRAM (xrw)  : ORIGIN = 0x20000000, LENGTH = 192K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SECTIONS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .text :&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.vector_table)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.text)            /* code */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    } &amp;gt;FLASH&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;makefile&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#makefile&quot; aria-label=&quot;Anchor link for: makefile&quot;&gt;Makefile&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The Makefile is used to compile the code:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;make&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;LINKER_SCRIPT&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; linker_script.ld&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;C_FLAGS&lt;/span&gt;&lt;span&gt;  =&lt;/span&gt;&lt;span&gt; -c -Og -mcpu=cortex-m4 -mthumb -g3 -ggdb3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;OPENOCD_FLAGS&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; -f interface/stlink-v2-1.cfg -f target/stm32f4x.cfg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;all&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; main.elf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;.o&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; %&lt;/span&gt;&lt;span&gt;.c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	arm-none-eabi-gcc &lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$(&lt;/span&gt;&lt;span&gt;C_FLAGS&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;)&lt;/span&gt;&lt;span&gt; -o &lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;$@&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; $&amp;lt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;main.elf&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; main.o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	arm-none-eabi-ld -T&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$(&lt;/span&gt;&lt;span&gt;LINKER_SCRIPT&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;)&lt;/span&gt;&lt;span&gt; -o main.elf main.&lt;/span&gt;&lt;span&gt;o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;clean&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	rm -rf *.o *.el&lt;/span&gt;&lt;span&gt;f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;flash&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; main.elf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	openocd &lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$(&lt;/span&gt;&lt;span&gt;OPENOCD_FLAGS&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;)&lt;/span&gt;&lt;span&gt; -c &amp;quot;program main.elf reset&amp;quot; -c &amp;quot;shutdown&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;compile-and-flash&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#compile-and-flash&quot; aria-label=&quot;Anchor link for: compile-and-flash&quot;&gt;Compile and flash&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To compile the code, you can use the following command:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;make&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To flash the code on the microcontroller, you can use the following command:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;make&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; flash&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The led should blink.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>ARM keywords cheatsheet</title>
        <published>2024-05-13T00:00:00+00:00</published>
        <updated>2024-05-13T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lchagnoleau.dev/posts/arm-cheatsheet/"/>
        <id>https://lchagnoleau.dev/posts/arm-cheatsheet/</id>
        
        <content type="html" xml:base="https://lchagnoleau.dev/posts/arm-cheatsheet/">&lt;h2 id=&quot;glossary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#glossary&quot; aria-label=&quot;Anchor link for: glossary&quot;&gt;Glossary&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;ARM&lt;/td&gt;&lt;td&gt;Advanced RISC Machines&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;RISC&lt;/td&gt;&lt;td&gt;Reduced Instruction Set Computer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;I-cache&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://lchagnoleau.dev/posts/arm-cheatsheet/#i-cache&quot;&gt;Instruction Cache&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;D-cache&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://lchagnoleau.dev/posts/arm-cheatsheet/#d-cache&quot;&gt;Data Cache&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;LR&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://lchagnoleau.dev/posts/arm-cheatsheet/#link-register&quot;&gt;Link Register&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;SP&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://lchagnoleau.dev/posts/arm-cheatsheet/#stack-pointer&quot;&gt;Stack Pointer&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;PC&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;https://lchagnoleau.dev/posts/arm-cheatsheet/#program-counter&quot;&gt;Program Counter&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;i-cache&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#i-cache&quot; aria-label=&quot;Anchor link for: i-cache&quot;&gt;I-cache&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Instruction cache is a high speed memory that stores the instructions that the CPU is likely to execute next.
It is used to speed up the execution of instructions by reducing the time it takes to fetch instructions from the main memory.
I-cache is the first place that the processor looks for instructions to execute. If the instruction is found in the cache, it is executed immediately.
If the instruction is not found in the cache, it is fetched from the main memory and stored in the cache for future use.&lt;/p&gt;
&lt;h2 id=&quot;d-cache&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#d-cache&quot; aria-label=&quot;Anchor link for: d-cache&quot;&gt;D-cache&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Data cache is a high speed memory that stores the data that the CPU is likely to access next.&lt;/p&gt;
&lt;h2 id=&quot;link-register&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#link-register&quot; aria-label=&quot;Anchor link for: link-register&quot;&gt;Link Register&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The link register is a register which holds the address to return to when a subroutine call completes.
It is also named R14.&lt;/p&gt;
&lt;h2 id=&quot;stack-pointer&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#stack-pointer&quot; aria-label=&quot;Anchor link for: stack-pointer&quot;&gt;Stack Pointer&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The stack pointer is a register which holds the address of the top of the stack. It is also named R13.&lt;/p&gt;
&lt;h2 id=&quot;program-counter&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#program-counter&quot; aria-label=&quot;Anchor link for: program-counter&quot;&gt;Program Counter&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The program counter is a register which holds the address of the next instruction to be executed. It is also named R15.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Setup a personal blog with Hugo</title>
        <published>2024-04-07T00:00:00+00:00</published>
        <updated>2024-04-07T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lchagnoleau.dev/posts/start-with-hugo/"/>
        <id>https://lchagnoleau.dev/posts/start-with-hugo/</id>
        
        <content type="html" xml:base="https://lchagnoleau.dev/posts/start-with-hugo/">&lt;p&gt;I decided to create a personal blog to share my thoughts, ideas, and projects with the world. I chose Hugo as my static site generator because of its simplicity, speed, and flexibility.
So, it&#39;s a good idea to start this blog by explaining how to setup a personal blog with Hugo and deploy it on GitHub Pages.&lt;/p&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#prerequisites&quot; aria-label=&quot;Anchor link for: prerequisites&quot;&gt;Prerequisites&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;choose-a-appropriate-theme&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#choose-a-appropriate-theme&quot; aria-label=&quot;Anchor link for: choose-a-appropriate-theme&quot;&gt;Choose a appropriate theme&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Hugo has a lot of themes available on the &lt;a rel=&quot;external&quot; href=&quot;https://themes.gohugo.io/&quot;&gt;official website&lt;/a&gt;. You can choose one that fits your needs and customize it to your liking. For this blog, I chose the &lt;a rel=&quot;external&quot; href=&quot;https://themes.gohugo.io/themes/hugo-theme-nightfall/&quot;&gt;Nightfall&lt;/a&gt; theme because of its clean design and simplicity.&lt;/p&gt;
&lt;h3 id=&quot;installation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#installation&quot; aria-label=&quot;Anchor link for: installation&quot;&gt;Installation&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To install Hugo, you can follow the instructions on the &lt;a rel=&quot;external&quot; href=&quot;https://gohugo.io/getting-started/installing/&quot;&gt;official website&lt;/a&gt;. I&#39;m using Arch Linux, so I installed Hugo with the following command:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;sudo&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; pacman&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; hugo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because I choose the Nightfall theme, I need to install &lt;a rel=&quot;external&quot; href=&quot;https://gohugo.io/functions/resources/tocss/#dart-sass&quot;&gt;dart-sass&lt;/a&gt;, following the instructions in the &lt;a rel=&quot;external&quot; href=&quot;https://github.com/LordMathis/hugo-theme-nightfall/tree/main&quot;&gt;Nightfall repository&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;sudo&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; pacman&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; dart-sass&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;start-a-new-site&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#start-a-new-site&quot; aria-label=&quot;Anchor link for: start-a-new-site&quot;&gt;Start a new site&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To create a new site with Hugo, you can use the following command:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;hugo&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; new&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; site&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; personal_blog&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will create a new directory called &lt;code&gt;personal_blog&lt;/code&gt;.
Next, we need to init hugo mod to be able to use the theme&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;hugo&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; mod&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; init&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; github.com/lchagnoleau/personal_blog&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;hugo&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; mod&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; get&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;u&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And add the following line to the &lt;code&gt;hugo.toml&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;module&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;module&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;imports&lt;/span&gt;&lt;span&gt;]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  path&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;github.com/LordMathis/hugo-theme-nightfall&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To add a new post, you can use the following command:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;hugo&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; new&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; content&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; posts/my-first-post.m&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Write your post in markdown format in the file &lt;code&gt;content/posts/my-first-post.md&lt;/code&gt; and set the &lt;code&gt;draft&lt;/code&gt; field to &lt;code&gt;false&lt;/code&gt; to publish it.&lt;/p&gt;
&lt;p&gt;Finally, we can start the server with the following command:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;hugo&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; server&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;publish-on-github&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#publish-on-github&quot; aria-label=&quot;Anchor link for: publish-on-github&quot;&gt;Publish on Github&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;create-a-github-repository&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#create-a-github-repository&quot; aria-label=&quot;Anchor link for: create-a-github-repository&quot;&gt;Create a Github repository&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;I push it into the .gitignore file&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;*&lt;/span&gt;&lt;span&gt;.lock&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;public/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;resources/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, create your Github repository and push your code to it&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;git&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; init&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; .&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;git&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; add&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; .&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;git&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; commit&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;Initial commit&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;git&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; remote&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; add&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; origin&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; git@github.com:lchagnoleau/lchagnoleau.git&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;git&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; push&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; origin&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; master&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;deploy-on-github-pages&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#deploy-on-github-pages&quot; aria-label=&quot;Anchor link for: deploy-on-github-pages&quot;&gt;Deploy on Github Pages&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The instructions to deploy the blog on Github Pages are available &lt;a rel=&quot;external&quot; href=&quot;https://gohugo.io/hosting-and-deployment/hosting-on-github/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</content>
        
    </entry>
</feed>
