element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 4040 views
  • Likes 9 likes
  • Comments 16 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
  • Coconut1
    Coconut1 7 days ago

    I had the exact same problem as described above. Bought 4 cheap Pico Boards online and encountered the connection problem when starting to debug.
    With a closer look at the board I could see that there is no 10-pin voltage regulator but a unknown 6-pin and additionally a 2MB Flash 'BY25Q16ES' from 
    the chines manufacture BYTe Semiconductor. So I was sure, these boards where counterfeit PICOs. 
    The error message then was  
               --> Error: Unknown flash device (ID 0x00154068)

    The by far easiest way to solve this, is to open the openocd.exe in a text editor and search for the entries of the table shown above.
    The 10 values of each line there will be interpreted as: 
        name,   read_cmd,   qread_cmd,    pprog_cmd,     erase_cmd,    chip_erase_cmd,     device_id,     pagesize,     sectorsize,     size_in_bytes 

    Now since I knew my Flash device, I download its data sheet and checked for the read/write/prog/erase commands and found that there already is an almost identical device 
    given with a slightly different device ID 0x001540C8. The rest was easy. 
    Seraching in a text editor (e.g. np++ in HEX-mode) for the byte-sequence "C8 40 15 00" and finding a "03 00 02 D8 C7 00 00 00" next to it, indicating the correct file position. 
    Now I changed the "C8" to "68" and saved the modified file openocd.exe.

    And it worked!!! The debugger now starts smoothly and every thing is fine ... now after 30+ hours of serching and trying.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Coconut1
    Coconut1 7 days ago

    I had the exact same problem as described above. Bought 4 cheap Pico Boards online and encountered the connection problem when starting to debug.
    With a closer look at the board I could see that there is no 10-pin voltage regulator but a unknown 6-pin and additionally a 2MB Flash BY25Q16ES from the chines manufacture BYTe Semiconductor. So I was sure, these boards where counterfeit PICOs. The error message then was
             -->  Error: Unknown flash device (ID 0x00154068)

    The by far easiest way to solve this, is to open the openocd.exe in a text editor and search for the entries of the table shown above.
    The 10 values of each line there will be interpreted as:
                 name,      read_cmd,      qread_cmd,       pprog_cmd,       erase_cmd,      chip_erase_cmd,       device_id,       pagesize,     sectorsize,      size_in_bytes

    Now since I knew my Flash device I download its data sheet and checked for the read/write/prog/erase commands and found that there already is an almost identical device
          "st m25pe16" given with a slightly different device ID 0x00158020.
    The rest was easy. Seraching in a text editor (e.g. np++ in HEX-mode) for the byte-sequence “20 80 15 00” and finding a “03 00 02 D8 C7 00 00 00” next to it, indicating the correct file position. Now I changed the "20 80" to 68 40" and saved the modified file.

    And viola … it worked. The debugger now started smoothly. Every thing is fine now … after 50+ hours of serching and trying.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps 5 months 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 5 months 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 5 months 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
>
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 © 2026 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