Advertisement
Guest User

x86_64のUbuntu 20.04からVScodeでRaspberry Pi ZeroのGPIOに接続されたpicoをリモートデバッグする方法

a guest
Feb 6th, 2021
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. x86_64のUbuntu 20.04からVScodeでRaspberry Pi ZeroのGPIOに接続されたpicoをリモートデバッグする方法
  2.  
  3.  
  4.  
  5. 1.Raspberry Pi ZeroにOpenOCDをインストールします
  6. (かなり時間がかかります)
  7.  
  8. cd ~/pico
  9.  
  10. sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev
  11.  
  12. git clone https://github.com/raspberrypi/openocd.git --recursive --branch rp2040 --depth=1
  13.  
  14. cd openocd
  15.  
  16. ./bootstrap
  17.  
  18. ./configure --enable-picoprobe --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
  19.  
  20. make
  21.  
  22. sudo make install
  23.  
  24.  
  25.  
  26. 2.Raspberry Pi Zeroにpicoを接続します
  27. (Zeroとpicoのピンの数え方に違いがあるので注意)
  28. https://www.raspberrypi.org/documentation/usage/gpio/images/GPIO-Pinout-Diagram-2.png
  29. https://www.raspberrypi.org/documentation/pico/getting-started/static/15243f1ffd3b8ee646a1708bf4c0e866/Pico-R3-Pinout.svg
  30.  
  31. pico Zero
  32. GPIO0(1番ピン) → GPIO15(10番ピン)
  33. GPIO1(2番ピン) → GPIO14(8番ピン)
  34. GND (3番ピン) → GND (14番ピン)
  35.  
  36. picoのDebugピンのSWCLKをZeroのGPIO25(22番ピン)に接続
  37. picoのDebugピンのGND をZeroのGND (20番ピン)に接続
  38. picoのDebugピンのSWDIOをZeroのGPIO24(18番ピン)に接続
  39.  
  40. picoのUSBポートをZeroのUSBポートに接続する
  41. またZeroのUSBポートにUSB-Ethernetアダプタを接続してUbuntu 20.04のコンピュータとLANでつなぎます
  42.  
  43.  
  44.  
  45. 3.Raspberry Pi ZeroでOpenOCDを起動する
  46.  
  47. Zero上で
  48.  
  49. openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg -c "bindto 0.0.0.0"
  50.  
  51. としてOpenOCDを起動しておきます。
  52.  
  53.  
  54.  
  55. 4.Ubuntu 20.04にVScodeをインストールする
  56.  
  57. https://code.visualstudio.com/
  58. ここの一番したの真ん中にある.debのボタンを押して
  59. Ubuntu、Debian用のvscodeのパッケージをダウンロードする
  60.  
  61.  
  62. ダウンロードしたdebパッケージのファイルをaptでインストール
  63.  
  64. sudo apt install ./code_1.53.0-1612368357_amd64.deb
  65.  
  66.  
  67.  
  68. 5.vscodeの起動
  69. ここではpico-sdkのディレクトリを~/pico/pico-sdkとしてます
  70. 違うディレクトリにインストールした場合は読み替えてください
  71.  
  72. export PICO_SDK_PATH=~/pico/pico-sdk
  73.  
  74. code &
  75.  
  76.  
  77.  
  78. 6.エクステンションのインストール
  79.  
  80. CTRL+SHIFT+Xを押すとエクステンションの画面になります
  81.  
  82. C/C++ by Microsoft
  83. Native Debug by WebFreak
  84. CMake tool by Microsoft
  85.  
  86. これら3つのエクステンションをインストールします
  87.  
  88.  
  89. 7.プロジェクトのフォルダを作成し、CMakeLists.txtとソースファイルを作成します。
  90.  
  91. CTRL+SHIFT+Eを押してエクスプローラーを開きます
  92.  
  93. メニューのFileからOpen Folderを選択します
  94.  
  95. ~/pico/project/lissajous_usb01
  96.  
  97. 右上のフォルダを作成しますでフォルダを作成してください
  98.  
  99.  
  100. File→New Fileを選択
  101. File→Save Asを選択してファイル名をCMakeLists.txtにして保存します
  102.  
  103.  
  104. CMakeLists.txtに下記をコピペして保存します
  105.  
  106.  
  107. cmake_minimum_required(VERSION 3.12)
  108.  
  109. # Pull in PICO SDK (must be before project)
  110. include(~/pico/pico-sdk/external/pico_sdk_import.cmake)
  111.  
  112. project(lissajous_usb01_project)
  113. set(CMAKE_C_STANDARD 11)
  114. set(CMAKE_CXX_STANDARD 17)
  115.  
  116. # Initialize the SDK
  117. pico_sdk_init()
  118.  
  119. add_executable(
  120. lissajous_usb01 lissajous_usb01.c
  121. )
  122.  
  123. target_link_libraries(lissajous_usb01 pico_stdlib)
  124.  
  125. pico_enable_stdio_usb(lissajous_usb01 1)
  126. pico_enable_stdio_uart(lissajous_usb01 0)
  127.  
  128. pico_add_extra_outputs(lissajous_usb01)
  129.  
  130.  
  131.  
  132.  
  133. File→New Fileを選択
  134. File→Save Asを選択してファイル名をlissajous_usb01.cにして保存します
  135.  
  136.  
  137. 一番下にlissajous_usb01.cのソースプログラムを掲載してますのでそれをコピペして保存してください
  138.  
  139.  
  140. VScodeの画面左側のExplorerの空欄部分を右クリックしてNew Folderを選択します
  141. .vscode
  142. フォルダを作成します
  143. そのフォルダの下に
  144. launch.json
  145. を作成します
  146.  
  147. launch.jsonに下記内容をコピペして保存します
  148. ここで192.168.0.10はRaspberry Pi ZeroのIPアドレスを指定します
  149. また、/home/ubuntu/pico/project/lissajous_usb01/build/lissajous_usb01.elfの部分も
  150. 自分の環境に合わせて変更してください
  151.  
  152. {
  153. "version": "0.2.0",
  154. "configurations": [
  155. {
  156. "name": "OpenOCD Debug",
  157. "type": "gdb",
  158. "request": "attach",
  159. "executable": "/home/ubuntu/pico/project/lissajous_usb01/build/lissajous_usb01.elf",
  160. "target": "192.168.0.10:3333",
  161. "remote": true,
  162. "cwd": "${workspaceRoot}",
  163. "autorun": [
  164. "monitor reset halt",
  165. "load",
  166. "break main"
  167. ],
  168. "gdbpath": "gdb-multiarch"
  169. }
  170. ]
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. 8.ビルドをする
  179.  
  180. CTRL+SHIFT+Pを押してコマンドパレットを開き、CMakeと入力
  181.  
  182. CMake: Quick Startを選択します
  183.  
  184.  
  185. すると一番したのバーにCMake:[Debug]準備完了、
  186. キットが選択されていません、
  187. ビルド
  188.  
  189. ができます
  190.  
  191. コマンドパレットが開きlissajous_usb01のキットを選択してくださいと出るので
  192. GCC for arm-none-eabiを選択します
  193.  
  194.  
  195. 画面一番下のCMake:[Debug]を押します
  196. するとコマンドパレットが開くのでDebugを選択します
  197.  
  198. 画面一番下のビルドをクリックします
  199.  
  200. するとビルドが始まります
  201.  
  202.  
  203.  
  204. 9.デバッグを開始する
  205.  
  206. CTRL+SHIFT+Dを押します
  207. 画面左上のOpenOCD Debugの左側の再生ボタンをクリックします
  208. (ボタンを押す前にRaspberry Pi Zero側でOpenOCDが起動してることを確認してください)
  209.  
  210. デバッグが始まるとmainのところで停止します
  211.  
  212.  
  213.  
  214.  
  215.  
  216. 以下、lissajous_usb01.cのソースコードです
  217.  
  218. #include <stdio.h>
  219. #include <math.h>
  220. #include "pico/stdlib.h"
  221.  
  222. #define COLUMN (78)
  223.  
  224. char buf01[COLUMN * COLUMN];
  225.  
  226.  
  227. int lissajous01(int start, int end, int step, double size, double a, double b, int column, char *buf01);
  228.  
  229.  
  230. int main(int argc, char *argv[])
  231. {
  232. stdio_init_all();
  233.  
  234. while (1) {
  235. for (int i = 3; i < 9; i++) {
  236. lissajous01(0, 36000, 20, 35.0, i, 5.0, COLUMN, (char *)buf01);
  237. sleep_ms(5000);
  238. }
  239. }
  240.  
  241. return 0;
  242. }
  243.  
  244. int lissajous01(int start, int end, int step, double size, double a, double b, int column, char *buf01)
  245. {
  246. int ret;
  247. int i, j, ix, iy, column01, column02;
  248. long l;
  249. double rad01, x, y, ratio01;
  250.  
  251. ratio01 = 0.5;
  252. rad01 = 3.141592653589793 / 180.0;
  253. column01 = column;
  254. column02 = column01 * ratio01 + 0.999999999999;
  255.  
  256. for (j = 0; j < column02; j++) {
  257. for (i = 0; i < column01; i++) {
  258. *(buf01 + column01 * j + i) = 0;
  259. }
  260. }
  261.  
  262. for (l = start; l <= end; l += step) {
  263. x = size * cos(rad01 * l / 100.0 * a) + column01 / 2.0;
  264. y = size * sin(rad01 * l / 100.0 * b) * ratio01 + column02 / 2.0;
  265. ix = (int)(x + 0.5);
  266. iy = (int)(y + 0.5);
  267. if ((ix >= 0) && (ix <= column01) && (iy >= 0) && (iy <= column02)){
  268. *(buf01 + column01 * iy + ix) = 1;
  269. }
  270. }
  271.  
  272. for (j = 0; j < column02; j++) {
  273. for (i = 0; i < column01; i++) {
  274. if (*(buf01 + column01 * j + i) == 0) {
  275. putchar(' ');
  276. } else {
  277. putchar('*');
  278. }
  279. }
  280. putchar('\n');
  281. }
  282.  
  283. ret = 0;
  284. return ret;
  285. }
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement