element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Solving Error: Unknown flash device: An OpenOCD Upgrade for Pi Pico / Xiao and other RP2040 Boards
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 19 May 2024 12:09 AM Date Created
  • Views 2934 views
  • Likes 9 likes
  • Comments 14 comments
  • pico-euro
  • openocd
  • rpiintermediate
  • pico
  • Xiao
  • xiao rp2040
  • rp2040
  • pico-eurocard
  • raspberry_pi_projects
  • picoprobe
  • pi pico
Related
Recommended

Solving Error: Unknown flash device: An OpenOCD Upgrade for Pi Pico / Xiao and other RP2040 Boards

shabaz
shabaz
19 May 2024

Table of Contents

  • Introduction
  • What is the Problem?
  • What is the Long Solution
    • Flash Chip Identifiers
  • Short Solution
  • Summary

Introduction

There exists software called OpenOCD that plays a fairly crucial role in the software development process. In brief, the software (which runs on a PC) connects to a microcontroller for Flash uploading and debugging purposes.

The purpose of this blog post is not to describe OpenOCD usage, the diagram below shows where OpenOCD is inserted as part of the overall programming and debug solution (if you're not using such a solution with your Pi Pico or other RP2040 microcontroller based board, it's highly recommended to explore it, because it allows for rapid programming and testing!).

This blog post is simply for one purpose: to explain how to resolve a problem when using OpenOCD with Pi Pico-like boards such as the (excellent) Xiao RP2040 .

image

What is the Problem?

The RP2040 microcontroller, like many other microcontrollers, uses an interface called JTAG for programming and debugging. There are two pins, labelled SWDIO and SWCLK (they might be abbreviated to SWD and SWC) which are used to transport JTAG. The interface is called Serial Wire Debug (SWD). On the Pi Pico board, you can see the interface at the opposite far end to the USB connector (some versions of the Pi Pico have the SWD interface pins elsewhere).

If you look in the diagram above, there are two Pi Pico boards. The purple one acts as a translator between USB and Serial Wire Debug. The pink one is the board that is being programmed or debugged.

That all works fine for Pi Pico boards. However, Jan Cumps  discovered an interesting problem; some RP2040 boards cannot work in the pink location. OpenOCD throws an error:

Info : accepting 'gdb' connection on tcp/50000
Error: Unknown flash device (ID 0x00156085)
Error: auto_probe failed

The problem is, that the Xiao RP2040 happens to use a different Flash chip compared to the original Pi Pico board. The Xiao board is not unique, there will be plenty of other RP2040 boards, all with different Flash chips. The ‘official’ OpenOCD release from raspberrypi.com is actually quite ancient; they have not bothered to keep it up-to-date, it doesn’t affect their Pi Pico board, but it will affect every piece of hardware based on the RP2040 if it happens to use a Flash chip which isn’t encoded inside the OpenOCD software.

What is the Long Solution

There may be a possibility to skip the check with OpenOCD, but that’s not as good as simply updating OpenOCD to support the Flash chip. That’s what we did!

The old Pi Pico datasheet used to explain how to build new OpenOCD releases, but it’s no longer present in the most recent datasheet versions.

In brief, the steps for Windows users are:

(a) Install MSYS2 on your PC

(b) Open up an MSYS2 MINGW64 terminal

(c) Type:

pacman -Syu

(d) Close the terminal (it may have closed anyway) and re-open it and type:

pacman -Su

(e) Close the terminal, and then re-open it, but this time as Administrator

(f) Type the following:

pacman -S mingw-w64-x86_64-toolchain git make libtool pkg-config autoconf automake texinfo mingw-w64-x86_64-libusb

(g) Close the terminal, and then re-open (not as Administrator)

(h) Create a folder, and then inside that, type:

git clone https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1

(i) Go to the openocd/src/flash/nor folder

(j) Edit the spi.c file and add the Flash chip identifier to it. This is discussed further below!

(k) Go back to the openocd folder, and then type:

./bootstrap
./configure --enable-picoprobe --disable-werror
make -j4

After all that, openocd will be built.

Flash Chip Identifiers

The spi.c file in the openocd/src/flash/nor folder contains dozens of Flash chip identifiers, as shown here:

image

We decided to simply replace the old raspberrypi.org spi.c file with the newer spi.c file at the official openocd page plus the additional spi.c change here.

Short Solution

Download the pre-built OpenOCD. You'll need to extract it with 7-Zip software.

This pre-built version was bundled together and tested by Jan on both Xiao RP2040 boards, and Pi Pico ones. It should also work with many other RP2040 boards.

Summary

OpenOCD is necessary to use the Serial Wire Debug (SWD) programming and debugging solution with the PicoProbe, which is an RP2040-based USB-to-SWD adapter.

You may encounter Error: Unknown flash device messages when attempting via SWD to program some RP2040 boards such as the Xiao RP2040.

The problem is resolved by modifying the OpenOCD source code to add a Flash memory identifier. Since that process is quite involved, a ready-built OpenOCD release for Windows is available to download.

Thanks for reading.

  • Sign in to reply
  • Jan Cumps
    Jan Cumps 9 days ago in reply to jjdean

    heads-up: the Raspberry Pico VSCode extension comes with an openocd version that has all of this solved.

    It installs it in your %USER%/.pico-sdk/openocd directory. No need anymore to struggle with custom builds.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jjdean
    jjdean 9 days ago in reply to doctea

    Hi, were you ever able to solve this problem? I'm having the same issue after copying rp2040.cfg and openocd.exe from shabaz.

    Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps 24 days ago in reply to fischp

    If the flash ic has readable markings, we may be able to get around this.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fischp
    fischp 24 days ago in reply to fischp

    So...  I reposted my issues with the Raspberry Pi forum and got a person from the company.  It turns out that the picos I bought from Amazon are counterfeit, with no markings on the back indicating that the product was a real pico.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fischp
    fischp 24 days ago in reply to Jan Cumps

    I actually have only one breakpoint set.  I'm not sure how the other ones got there, I was thinking it might be a VS Code  "thing" similar to how ESP's in the PlatformIO environment stop at the setup, before any user code starts executing.  Just a guess though.

    I tried removing the one breakpoint that I had and this is the tail of the log:

    Info : CMSIS-DAP: Interface ready
    Info : clock speed 5000 kHz
    Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
    Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001
    Info : [rp2040.core0] Cortex-M0+ r0p1 processor detected
    Info : [rp2040.core0] target has 4 breakpoints, 2 watchpoints
    Info : [rp2040.core0] Examination succeed
    Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected
    Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints
    Info : [rp2040.core1] Examination succeed
    Info : [rp2040.core0] starting gdb server on 50000
    Info : Listening on port 50000 for gdb connections
    Info : accepting 'gdb' connection on tcp/50000
    Info : no SDFP found
    Error: RP2040 rev 2, QSPI Flash id = 0x154068 not recognised
    Error: auto_probe failed
    Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
    Error: attempted 'gdb' connection rejected
    Error: error handling USB events: System call interrupted (perhaps due to signal)
    [rp2040.core0] halted due to breakpoint, current mode: Thread
    xPSR: 0x61000000 pc: 0x10000c10 msp: 0x20041fc0
    [rp2040.core1] halted due to debug-request, current mode: Thread
    xPSR: 00000000 pc: 00000000 msp: 00000000
    Error: [rp2040.core1] Polling failed, trying to reexamine
    Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001
    Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected
    Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints
    Info : [rp2040.core1] Examination succeed
    shutdown command invoked
    [2025-08-29T14:40:40.957Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
    GDB server session ended. This terminal will be reused, waiting for next session to start...

    So with no breakpoints, it still thinks it has breakpoints set.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube