Home Swift UNIX C Assembly Go Web MCU Research Non-Tech

How to reset Raspberry Pi Pico (reset peripheral device failed)

2023-08-15 | MCU | #Words: 429 | 中文原版

Sometimes you need to reset the Raspberry Pi Pico. One way is to press and hold the “BOOTSEL” button on the Pico and re-plug USB; another way is connecting the “RUN” and “GND” pins with a button, and then press this button and “BOOTSEL” at the same time button. This puts you into USB mode.

However, this method may not be suitable for all situations, some peripheral devices may not be successfully reset using this method. For example, sometimes after burn blink.uf2 to make the LED blink, the above method sometimes fail to stop the LED from blinking.

If the peripheral device cannot be reset, you need to compile a reset program and burn it into Pico to reset it. This reset program is collected in the official pico-examples, called hello_reset. Below is what I extracted, because offical no CMakeLists.txt file to build this binary executable file separately.

The code of hello_reset.c:

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/resets.h"

/// \tag::hello_reset[]
int main() {
    stdio_init_all();

    printf("Hello, reset!\n");

    // Put the PWM block into reset
    reset_block(RESETS_RESET_PWM_BITS);

    // And bring it out
    unreset_block_wait(RESETS_RESET_PWM_BITS);

    // Put the PWM and RTC block into reset
    reset_block(RESETS_RESET_PWM_BITS | RESETS_RESET_RTC_BITS);

    // Wait for both to come out of reset
    unreset_block_wait(RESETS_RESET_PWM_BITS | RESETS_RESET_RTC_BITS);

    return 0;
}
/// \end::hello_reset[]

The content of CMakeLists.txt:

cmake_minimum_required(VERSION 3.12)

include(pico_sdk_import.cmake)

project(hello_reset)

pico_sdk_init()


add_executable(hello_reset 
hello_reset.c
)

target_link_libraries(hello_reset pico_stdlib)

pico_add_extra_outputs(hello_reset)

In addition, remember to copy the pico_sdk_import.cmake file from pico-sdk into this directory, and then create an empty directory build:

$ cp $PICO_SDK_PATH/external/pico_sdk_import.cmake .
$ mkdir build
$ cd build

Now you can build.

$ cmake ..
$ make -j4

After the build is completed, just drag hello_reset.uf2 to Pico. Now you try it, the LED stops blinking.

If you have questions about the build, please refer to my other blog: How to use the Mac Terminal to developfor Raspberry Pi Pico using C/C++, and how to deal with various problems without using IDE or editor (such as VS Code)

I hope these will help someone in need~