Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x86_64のUbuntu 20.04からVScodeでRaspberry Pi ZeroのGPIOに接続されたpicoをリモートデバッグする方法
- 1.Raspberry Pi ZeroにOpenOCDをインストールします
- (かなり時間がかかります)
- cd ~/pico
- sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev
- git clone https://github.com/raspberrypi/openocd.git --recursive --branch rp2040 --depth=1
- cd openocd
- ./bootstrap
- ./configure --enable-picoprobe --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
- make
- sudo make install
- 2.Raspberry Pi Zeroにpicoを接続します
- (Zeroとpicoのピンの数え方に違いがあるので注意)
- https://www.raspberrypi.org/documentation/usage/gpio/images/GPIO-Pinout-Diagram-2.png
- https://www.raspberrypi.org/documentation/pico/getting-started/static/15243f1ffd3b8ee646a1708bf4c0e866/Pico-R3-Pinout.svg
- pico Zero
- GPIO0(1番ピン) → GPIO15(10番ピン)
- GPIO1(2番ピン) → GPIO14(8番ピン)
- GND (3番ピン) → GND (14番ピン)
- picoのDebugピンのSWCLKをZeroのGPIO25(22番ピン)に接続
- picoのDebugピンのGND をZeroのGND (20番ピン)に接続
- picoのDebugピンのSWDIOをZeroのGPIO24(18番ピン)に接続
- picoのUSBポートをZeroのUSBポートに接続する
- またZeroのUSBポートにUSB-Ethernetアダプタを接続してUbuntu 20.04のコンピュータとLANでつなぎます
- 3.Raspberry Pi ZeroでOpenOCDを起動する
- Zero上で
- openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg -c "bindto 0.0.0.0"
- としてOpenOCDを起動しておきます。
- 4.Ubuntu 20.04にVScodeをインストールする
- https://code.visualstudio.com/
- ここの一番したの真ん中にある.debのボタンを押して
- Ubuntu、Debian用のvscodeのパッケージをダウンロードする
- ダウンロードしたdebパッケージのファイルをaptでインストール
- sudo apt install ./code_1.53.0-1612368357_amd64.deb
- 5.vscodeの起動
- ここではpico-sdkのディレクトリを~/pico/pico-sdkとしてます
- 違うディレクトリにインストールした場合は読み替えてください
- export PICO_SDK_PATH=~/pico/pico-sdk
- code &
- 6.エクステンションのインストール
- CTRL+SHIFT+Xを押すとエクステンションの画面になります
- C/C++ by Microsoft
- Native Debug by WebFreak
- CMake tool by Microsoft
- これら3つのエクステンションをインストールします
- 7.プロジェクトのフォルダを作成し、CMakeLists.txtとソースファイルを作成します。
- CTRL+SHIFT+Eを押してエクスプローラーを開きます
- メニューのFileからOpen Folderを選択します
- ~/pico/project/lissajous_usb01
- 右上のフォルダを作成しますでフォルダを作成してください
- File→New Fileを選択
- File→Save Asを選択してファイル名をCMakeLists.txtにして保存します
- CMakeLists.txtに下記をコピペして保存します
- cmake_minimum_required(VERSION 3.12)
- # Pull in PICO SDK (must be before project)
- include(~/pico/pico-sdk/external/pico_sdk_import.cmake)
- project(lissajous_usb01_project)
- set(CMAKE_C_STANDARD 11)
- set(CMAKE_CXX_STANDARD 17)
- # Initialize the SDK
- pico_sdk_init()
- add_executable(
- lissajous_usb01 lissajous_usb01.c
- )
- target_link_libraries(lissajous_usb01 pico_stdlib)
- pico_enable_stdio_usb(lissajous_usb01 1)
- pico_enable_stdio_uart(lissajous_usb01 0)
- pico_add_extra_outputs(lissajous_usb01)
- File→New Fileを選択
- File→Save Asを選択してファイル名をlissajous_usb01.cにして保存します
- 一番下にlissajous_usb01.cのソースプログラムを掲載してますのでそれをコピペして保存してください
- VScodeの画面左側のExplorerの空欄部分を右クリックしてNew Folderを選択します
- .vscode
- フォルダを作成します
- そのフォルダの下に
- launch.json
- を作成します
- launch.jsonに下記内容をコピペして保存します
- ここで192.168.0.10はRaspberry Pi ZeroのIPアドレスを指定します
- また、/home/ubuntu/pico/project/lissajous_usb01/build/lissajous_usb01.elfの部分も
- 自分の環境に合わせて変更してください
- {
- "version": "0.2.0",
- "configurations": [
- {
- "name": "OpenOCD Debug",
- "type": "gdb",
- "request": "attach",
- "executable": "/home/ubuntu/pico/project/lissajous_usb01/build/lissajous_usb01.elf",
- "target": "192.168.0.10:3333",
- "remote": true,
- "cwd": "${workspaceRoot}",
- "autorun": [
- "monitor reset halt",
- "load",
- "break main"
- ],
- "gdbpath": "gdb-multiarch"
- }
- ]
- }
- 8.ビルドをする
- CTRL+SHIFT+Pを押してコマンドパレットを開き、CMakeと入力
- CMake: Quick Startを選択します
- すると一番したのバーにCMake:[Debug]準備完了、
- キットが選択されていません、
- ビルド
- ができます
- コマンドパレットが開きlissajous_usb01のキットを選択してくださいと出るので
- GCC for arm-none-eabiを選択します
- 画面一番下のCMake:[Debug]を押します
- するとコマンドパレットが開くのでDebugを選択します
- 画面一番下のビルドをクリックします
- するとビルドが始まります
- 9.デバッグを開始する
- CTRL+SHIFT+Dを押します
- 画面左上のOpenOCD Debugの左側の再生ボタンをクリックします
- (ボタンを押す前にRaspberry Pi Zero側でOpenOCDが起動してることを確認してください)
- デバッグが始まるとmainのところで停止します
- 以下、lissajous_usb01.cのソースコードです
- #include <stdio.h>
- #include <math.h>
- #include "pico/stdlib.h"
- #define COLUMN (78)
- char buf01[COLUMN * COLUMN];
- int lissajous01(int start, int end, int step, double size, double a, double b, int column, char *buf01);
- int main(int argc, char *argv[])
- {
- stdio_init_all();
- while (1) {
- for (int i = 3; i < 9; i++) {
- lissajous01(0, 36000, 20, 35.0, i, 5.0, COLUMN, (char *)buf01);
- sleep_ms(5000);
- }
- }
- return 0;
- }
- int lissajous01(int start, int end, int step, double size, double a, double b, int column, char *buf01)
- {
- int ret;
- int i, j, ix, iy, column01, column02;
- long l;
- double rad01, x, y, ratio01;
- ratio01 = 0.5;
- rad01 = 3.141592653589793 / 180.0;
- column01 = column;
- column02 = column01 * ratio01 + 0.999999999999;
- for (j = 0; j < column02; j++) {
- for (i = 0; i < column01; i++) {
- *(buf01 + column01 * j + i) = 0;
- }
- }
- for (l = start; l <= end; l += step) {
- x = size * cos(rad01 * l / 100.0 * a) + column01 / 2.0;
- y = size * sin(rad01 * l / 100.0 * b) * ratio01 + column02 / 2.0;
- ix = (int)(x + 0.5);
- iy = (int)(y + 0.5);
- if ((ix >= 0) && (ix <= column01) && (iy >= 0) && (iy <= column02)){
- *(buf01 + column01 * iy + ix) = 1;
- }
- }
- for (j = 0; j < column02; j++) {
- for (i = 0; i < column01; i++) {
- if (*(buf01 + column01 * j + i) == 0) {
- putchar(' ');
- } else {
- putchar('*');
- }
- }
- putchar('\n');
- }
- ret = 0;
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement