Code Monkey home page Code Monkey logo

picotest's Introduction

Raspberry Pi Pico - LED Blink

The first program for pi pico that everyone writes.

Links

Requirements (Mac Os)

brew install cmake
brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc
git clone -b master https://github.com/raspberrypi/pico-sdk.git

Path

export PICO_SDK_PATH=path_to/repo/pico-sdk

Compile and Run

mkdir build
cd build
cmake ..
make

Recomended VSCode Extensions

  • CMAKE by Microsoft
  • CMAKE Tools by Microsoft
  • C/C++ by Microsoft
  • C/C++ Extension Pack by Microsoft
  • C/C++ Themes by Microsoft
  • Cortex-Debug by Marus25

Examples

git clone -b master https://github.com/raspberrypi/pico-examples.git

Installing OpenOCD

OpenOCD (On Chip Debugging) is used to translate commands from gdb (debugger) to SWD. This requires a second Pico device setup for debugging. If you are using a Raspberry Pi, then you can just connect via the GPIO pins and not need the extra Pico in the mix.

brew install libtool automake libusb wget pkg-config gcc texinfo
echo 'export PATH="/usr/local/opt/texinfo/bin:$PATH"' >> ~/.zshrc
git clone https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1
cd openocd
./bootstrap
./configure --enable-picoprobe --disable-werror
make
make install
openocd -v

Install Picoprobe

picoprobe is used to connect the Mac via USB to the Raspberry Pi Pico that will then be attached to the Pico that is being debugged. If you are using a Raspberry Pi, then you can just connect via the GPIO pins and not need the extra Pico in the mix.

git clone https://github.com/raspberrypi/picoprobe.git
cd picoprobe
mkdir build
cd build
cmake ..
make

See Appendix A: Using Picoprobe from the official getting started guide for the wiring diagram.

Installing gdb

Joking, you already have it!

which arm-none-eabi-gdb

Test debug

Run OpenOCD and confirm that it can attach to the Pico being debugged. Ensure the two Picos are wired up correctly.

openocd -f interface/picoprobe.cfg -f target/rp2040.cfg -s tcl
...
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections

Open another terminal while OpenOCD runs

cd <YOUR_PATH>/blink/
rm -rf build
mkdir build
cd build
export PICO_SDK_PATH=path_to/repo/pico-sdk
cmake -DCMAKE_BUILD_TYPE=Debug ..
make

Now run GDB and load the blink.elf file that was output above

arm-none-eabi-gdb hello_serial.elf

Connect OpenOCD to this gdb session

(gdb) target remote localhost:3333
(gdb) load

Set a breakpoint to stop when main() is called and run the program.

(gdb) monitor reset init
(gdb) b main
...
Breakpoint 1 at 0x1000030e: file .../blink/blink.c, line 3.

(gdb) continue
...
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00

Thread 1 hit Breakpoint 1, main ()
    at .../blink/blink.c:3
3	    stdio_init_all();

That's it! Type q or quit to exit GDB.

Congratulations! ๐Ÿฅณ ๐ŸŽ‰ You can now build, run and debug a Raspberry Pi Pico from your Mac.

picotest's People

Watchers

James Cloos avatar Kevin Asbury avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.