<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://maebli.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://maebli.github.io/" rel="alternate" type="text/html" /><updated>2026-01-25T19:33:00+00:00</updated><id>https://maebli.github.io/feed.xml</id><title type="html">Michael Aebli’s Pages</title><subtitle>This is Michael&apos;s Blog.</subtitle><author><name>maebli</name></author><entry><title type="html">First Steps with Raspberry Pi Pico</title><link href="https://maebli.github.io/pico/hardware/2021/02/17/raspberry-pi.html" rel="alternate" type="text/html" title="First Steps with Raspberry Pi Pico" /><published>2021-02-17T20:00:00+00:00</published><updated>2021-02-17T20:00:00+00:00</updated><id>https://maebli.github.io/pico/hardware/2021/02/17/raspberry-pi</id><content type="html" xml:base="https://maebli.github.io/pico/hardware/2021/02/17/raspberry-pi.html"><![CDATA[<p><em>The new addition to the growing Raspberry family is the Raspberry Pi Pico. The board is well documented in the PDF <a href="https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf">Getting Started with Pico</a>. I’m reporting here on my first uses of the board.</em></p>

<h1 id="table-of-content">Table of content</h1>
<!-- MarkdownTOC autolink="true" -->

<ul>
  <li><a href="#installing-development-environment">Installing Development Environment</a></li>
  <li><a href="#trying-the-examples">Trying the examples</a>
    <ul>
      <li><a href="#blink-example">Blink example</a></li>
    </ul>
  </li>
  <li><a href="#debugging-the-little-guy">Debugging The Little Guy</a>
    <ul>
      <li><a href="#using-a-segger-header-and-a-raspberry-pi">Using a Segger Header and a Raspberry Pi</a>
        <ul>
          <li><a href="#the-pi-pico-side-of-things">The Pi Pico Side of Things</a></li>
          <li><a href="#the-pi-side-of-things">The Pi Side of Things</a></li>
          <li><a href="#the-resulting-pcb-layout">The Resulting PCB Layout</a></li>
        </ul>
      </li>
      <li><a href="#using-one-of-the-cores-for-debugging">Using One of the Cores for Debugging</a></li>
      <li><a href="#using-an-additional-pico-as-debugger">Using an Additional Pico as Debugger</a></li>
    </ul>
  </li>
</ul>

<!-- /MarkdownTOC -->

<h2 id="installing-development-environment">Installing Development Environment</h2>

<p>To get started run the following code. Note you can disable certain aspects of the script, following options exist by running <code class="language-plaintext highlighter-rouge">$SKIP_VSCODE</code>, <code class="language-plaintext highlighter-rouge">$SKIP_OPENOCD</code> so you can run <code class="language-plaintext highlighter-rouge">export SKIP_VSCODE=1</code> before to not install Visual Studio Code.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh 
<span class="nb">chmod</span> +x pico_setup.sh
./pico_setup.sh
<span class="nb">sudo </span>reboot
</code></pre></div></div>
<h2 id="trying-the-examples">Trying the examples</h2>

<p>To build the examples, follow the instructions in the datasheet and run cmake and then make in the example directory.</p>

<h3 id="blink-example">Blink example</h3>

<p>To make the blink example do the following. I did the building over <code class="language-plaintext highlighter-rouge">ssh</code> on a Pi Zero and then copied the resulting binary via <code class="language-plaintext highlighter-rouge">scp</code>.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ~/pico/pico-examples
<span class="nb">mkdir </span>build
<span class="nb">cd </span>build
cmake ..
<span class="nb">cd </span>blink
make
</code></pre></div></div>
<p>Drag and drop the resulting	<code class="language-plaintext highlighter-rouge">blink.uf2</code> on to the drive that pops up when you plug in a blank pico or when you press the white BOOTSEL button whilst plugin in the device.</p>

<p><img src="/assets/img/pio-blink-example.gif" alt="" /></p>

<h2 id="debugging-the-little-guy">Debugging The Little Guy</h2>

<p>Lets talk about debugging.</p>

<p><img src="/assets/img/segger-pi-debug.jpg" alt="" />
<img src="/assets/img/raspi-debug.jpg" alt="" /></p>

<p><em>The images above show the finished pcb. On the left the pico is being debugged with a Segger and on the right the pico is being debugged by a pi zero.</em></p>

<h3 id="using-a-segger-header-and-a-raspberry-pi">Using a Segger Header and a Raspberry Pi</h3>

<p>This is my preferred way of debugging. I summarize the theory here and I have ordered a PCB. Once it arrives I will do further testing and talk about it in another blog post.
The PCB I made is missing the Vref port. I had to add that in hindsight with a flying wire. Also what I had to realize it only works with the latest versions of segger software. I used a J-Link V10 firmware, a <em>v10.10 J-Link EDU Hardware</em> and a <em>V6.98b Segger DLL / Software</em> to get it running, I tested it in J-Link Commander as can be seen in the screenshot. Then selecting the device type <em>RP2040_M0_1</em> or <em>RP2040_M0_0</em> a connection can be established as is seen in the command line log bellow:</p>

<pre><code class="language-cmd">Type "connect" to establish a target connection, '?' for help
J-Link&gt;
Unknown command. '?' for help.
J-Link&gt;con
Please specify device / core. &lt;Default&gt;: RP2040_M0_1
Type '?' for selection dialog
Device&gt;
Please specify target interface:
  J) JTAG (Default)
  S) SWD
  T) cJTAG
TIF&gt;S
Specify target interface speed [kHz]. &lt;Default&gt;: 4000 kHz
Speed&gt;
Device "RP2040_M0_1" selected.


Connecting to target via SWD
ConfigTargetSettings() start
J-Link script: ConfigTargetSettings()
ConfigTargetSettings() end
InitTarget() start
InitTarget() end
Found SW-DP with ID 0x0BC12477
DPIDR: 0x0BC12477
Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x04770031)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410CC601. Implementer code: 0x41 (ARM)
Found Cortex-M0 r0p1, Little endian.
FPUnit: 4 code (BP) slots and 0 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB008 SCS
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 000BB00A DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 000BB00B FPB
Cortex-M0 identified.
</code></pre>

<h4 id="the-pi-pico-side-of-things">The Pi Pico Side of Things</h4>

<p>There is no debugging header which is compatible with an existing SWD debugger such as <a href="https://www.segger.com/products/debug-probes/j-link/accessories/adapters/10-pin-needle-adapter/">10 pin header</a>. The board exposes the SWDIO, SWDCLK and GND as reference on the far end of the board. SWO (Serial Wire Output) is not available for RP0240 as it is a feature of ARM M3 and above. The board will have to be powered, this can happen over USB, but will require at least two cables going to the board, which can become a bit of an annoyance. The documentation suggests to use a Raspberry Pi with jumper cables. I decided to make a little adapter PCB to the 10 pin Segger header. The Vsys I made to be attached by a cable via a schottkey diode, as it is on the far end of the pico and I don’t want to cover that space with pcb.</p>

<p><img src="/assets/img/pico-hat-segger.png" alt="" /></p>

<h4 id="the-pi-side-of-things">The Pi Side of Things</h4>

<p>Next up we need to connect a debug probe either a Pi, <a href="https://wiki.segger.com/Raspberry_Pi_Pico">Segger</a> or ST-Link (not sure if that’s supported, will have to try it out). Lets start with the Pi and stay loyal to the eco system.
The documentation has the following default pinout for the Pi when bitbanging the SWD interface using OpenOCD.</p>

<table>
  <thead>
    <tr>
      <th>Raspberry Pi</th>
      <th style="text-align: center">Raspberry Pi Pico</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>5V (Pin 4)</td>
      <td style="text-align: center">Vsys</td>
    </tr>
    <tr>
      <td>GND (Pin 20)</td>
      <td style="text-align: center">SWD GND</td>
    </tr>
    <tr>
      <td>GPIO24 (Pin 18)</td>
      <td style="text-align: center">SWDIO</td>
    </tr>
    <tr>
      <td>GPIO25 (Pin 22)</td>
      <td style="text-align: center">SWCLK</td>
    </tr>
  </tbody>
</table>

<p><img src="/assets/img/raspi-hat.png" alt="" /></p>

<h4 id="the-resulting-pcb-layout">The Resulting PCB Layout</h4>

<p><img src="/assets/img/pico-hat-pcb.png" alt="" />
<img src="/assets/img/pi-hat-pcb.png" alt="" /></p>

<p><em>Left: Pi Pico Hat, Right: Pi Hat (note, option is to mount the pi directly on two 20 pin headers)</em></p>

<h3 id="using-one-of-the-cores-for-debugging">Using One of the Cores for Debugging</h3>

<p>Raspberry Pi Foundation employees in <a href="https://theamphour.com/529-embedded-hardware-with-the-raspberry-pi-team/">“The Amp Hour Electronics” Podcast #529</a> mentioned that this is a planned feature for the future. Basically one core debugs the other and debugging is done over USB. A GitHub user has already implemented something in this direction in the repos <a href="https://github.com/majbthrd/pico-debug/">Pico Debug</a>.
This is a very neat solution, as we don’t often need two cores for micro controller projects. It uses <a href="https://www.keil.com/support/man/docs/dapdebug/dapdebug_introduction.htm">ARM’s open source CEMIS-DAP Debugger</a>.
At the time of writing, the Pico Debug requires the use of a fork of the pico-sdk which has not been merged. This means pico-debug is not officially supported yet.</p>

<p><em>WARNING: If you’ve already installed the pico-sdk than this won’t work, you have to uninstall the official version first or change PICO_SDK_PATH.</em></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>
<span class="nb">mkdir </span>pico
<span class="nb">cd </span>pico
git clone https://github.com/majbthrd/pico-sdk.git <span class="nt">--branch</span> pll_init
<span class="nb">cd </span>pico-sdk
git submodule update <span class="nt">--init</span>
<span class="nb">cd</span> ..
git clone <span class="nt">-b</span> master https://github.com/raspberrypi/pico-examples.git
<span class="nb">sudo </span>apt update
<span class="nb">sudo </span>apt <span class="nb">install </span>cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential
<span class="nb">cd</span> ./pico/pico-examples
<span class="nb">mkdir </span>build
<span class="nb">cd </span>build
<span class="nb">export </span><span class="nv">PICO_SDK_PATH</span><span class="o">=</span>../../pico-sdk
cmake <span class="nt">-DCMAKE_BUILD_TYPE</span><span class="o">=</span>Debug ..
<span class="nb">cd</span> ./pico/pico-examples/build/picoboard/blinky
make <span class="nt">-j4</span>
</code></pre></div></div>

<p>I used another method to make this build. To build the debug image I used a Debian docker image which I pulled from docker hub to cross compile the binaries. In docker you have to also install <code class="language-plaintext highlighter-rouge">apt get install pytho3 git</code> in order for the build to work. This way you don’t have to have to separate sdk’s on your pi with separate paths. You also don’t need a Pi Zero or other Pi to build.</p>

<p>You can download the image for the debug core from the <a href="https://github.com/majbthrd/pico-debug/releases.">Pico Debug Release Page</a></p>

<h3 id="using-an-additional-pico-as-debugger">Using an Additional Pico as Debugger</h3>

<p>Another alternative is to use a second pico with the firmware <a href="https://www.raspberrypi.org/documentation/pico/getting-started/static/fec949af3d02572823529a1b8c1140a7/picoprobe.uf2">picoprobe.uf2</a> on the SWD interface.</p>]]></content><author><name>maebli</name></author><category term="pico" /><category term="hardware" /><summary type="html"><![CDATA[The new addition to the growing Raspberry family is the Raspberry Pi Pico. The board is well documented in the PDF Getting Started with Pico. I’m reporting here on my first uses of the board.]]></summary></entry></feed>