Advertisement
Guest User

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

a guest
Feb 7th, 2021
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.04 KB | None | 0 0
  1. 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.  
  27.  
  28.  
  29. 2.Raspberry Pi ZeroのシリアルコンソールをUARTとして使うための設定をする
  30.  
  31. /boot/cmdline.txtを編集
  32. console=serial0,115200を削除する
  33. plymouth.ignore-serial-consolesがなければ追記します
  34.  
  35. 編集前
  36. console=serial0,115200 console=tty1 root=PARTUUID=5e3da3da-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
  37.  
  38. 編集後
  39. console=tty1 root=PARTUUID=5e3da3da-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
  40.  
  41.  
  42. /boot/config.txtに下記を追加
  43.  
  44. enable_uart=1
  45.  
  46. ttyAMA0を無効化する
  47. sudo systemctl stop serial-getty@ttyAMA0.service
  48. sudo systemctl disable serial-getty@ttyAMA0.service
  49.  
  50. 設定後、Zeroを再起動する
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. 3.Raspberry Pi Zeroにpicoを接続します
  58. (Zeroとpicoのピンの数え方に違いがあるので注意)
  59. https://www.raspberrypi.org/documentation/usage/gpio/images/GPIO-Pinout-Diagram-2.png
  60. https://www.raspberrypi.org/documentation/pico/getting-started/static/15243f1ffd3b8ee646a1708bf4c0e866/Pico-R3-Pinout.svg
  61.  
  62. pico Zero
  63. GPIO0(1番ピン) → GPIO15(10番ピン)
  64. GPIO1(2番ピン) → GPIO14(8番ピン)
  65. GND (3番ピン) → GND (14番ピン)
  66.  
  67. picoのDebugピンのSWCLKをZeroのGPIO25(22番ピン)に接続
  68. picoのDebugピンのGND をZeroのGND (20番ピン)に接続
  69. picoのDebugピンのSWDIOをZeroのGPIO24(18番ピン)に接続
  70.  
  71. picoのUSBポートをZeroのUSBポートに接続する
  72. またZeroのUSBポートにUSB-Ethernetアダプタを接続してUbuntu 20.04のコンピュータとLANでつなぎます
  73.  
  74.  
  75.  
  76. 4.Raspberry Pi ZeroでOpenOCDを起動する
  77.  
  78. Zero上で
  79.  
  80. openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg -c "bindto 0.0.0.0"
  81.  
  82. としてOpenOCDを起動しておきます。
  83.  
  84.  
  85.  
  86. 5.Ubuntu 20.04にVScodeをインストールする
  87.  
  88. https://code.visualstudio.com/
  89. ここの一番したの真ん中にある.debのボタンを押して
  90. Ubuntu、Debian用のvscodeのパッケージをダウンロードする
  91.  
  92.  
  93. ダウンロードしたdebパッケージのファイルをaptでインストール
  94.  
  95. sudo apt install ./code_1.53.0-1612368357_amd64.deb
  96.  
  97.  
  98.  
  99. 6.vscodeの起動
  100. ここではpico-sdkのディレクトリを~/pico/pico-sdkとしてます
  101. 違うディレクトリにインストールした場合は読み替えてください
  102.  
  103. export PICO_SDK_PATH=~/pico/pico-sdk
  104.  
  105. code &
  106.  
  107.  
  108.  
  109. 7.エクステンションのインストール
  110.  
  111. CTRL+SHIFT+Xを押すとエクステンションの画面になります
  112.  
  113. C/C++ by Microsoft
  114. CMake tools by Microsoft
  115. Cortex-Debug by marus25
  116.  
  117. これら3つのエクステンションをインストールします
  118.  
  119.  
  120. 8.プロジェクトのフォルダを作成し、CMakeLists.txtとソースファイルを作成します。
  121.  
  122. CTRL+SHIFT+Eを押してエクスプローラーを開きます
  123.  
  124. メニューのFileからOpen Folderを選択します
  125.  
  126. ~/pico/project/lissajous_usb01
  127.  
  128. 右上のフォルダを作成しますでフォルダを作成してください
  129.  
  130.  
  131. File→New Fileを選択
  132. File→Save Asを選択してファイル名をCMakeLists.txtにして保存します
  133.  
  134.  
  135. CMakeLists.txtに下記をコピペして保存します
  136.  
  137.  
  138. cmake_minimum_required(VERSION 3.12)
  139.  
  140. # Pull in PICO SDK (must be before project)
  141. include(~/pico/pico-sdk/external/pico_sdk_import.cmake)
  142.  
  143. project(lissajous_usb01_project)
  144. set(CMAKE_C_STANDARD 11)
  145. set(CMAKE_CXX_STANDARD 17)
  146.  
  147. # Initialize the SDK
  148. pico_sdk_init()
  149.  
  150. add_executable(
  151. lissajous_usb01 lissajous_usb01.c
  152. )
  153.  
  154. target_link_libraries(lissajous_usb01 pico_stdlib)
  155.  
  156. pico_enable_stdio_usb(lissajous_usb01 1)
  157. pico_enable_stdio_uart(lissajous_usb01 0)
  158.  
  159. pico_add_extra_outputs(lissajous_usb01)
  160.  
  161.  
  162.  
  163.  
  164. File→New Fileを選択
  165. File→Save Asを選択してファイル名をlissajous_usb01.cにして保存します
  166.  
  167.  
  168. 一番下にlissajous_usb01.cのソースプログラムを掲載してますのでそれをコピペして保存してください
  169.  
  170.  
  171. VScodeの画面左側のExplorerの空欄部分を右クリックしてNew Folderを選択します
  172.  
  173. .vscode
  174.  
  175. という名前のフォルダを作成します
  176. その.vscodeフォルダの下に
  177.  
  178. launch.json
  179.  
  180. という名前のファイルを作成します
  181.  
  182. launch.jsonに下記内容をコピペして保存します
  183. ここでgdbTargetのところの192.168.0.10はRaspberry Pi ZeroのIPアドレスを指定します
  184. 自分の環境に合わせて変更してください
  185. この内容はpico-sdkの
  186. pico/pico-examples/ide/vscode/launch-remote-openocd.json
  187. と全く同じです
  188.  
  189.  
  190. {
  191. "version": "0.2.0",
  192. "configurations": [
  193. {
  194. "name": "Pico Debug",
  195. "type":"cortex-debug",
  196. "cwd": "${workspaceRoot}",
  197. "executable": "${command:cmake.launchTargetPath}",
  198. "request": "launch",
  199. "servertype": "external",
  200. // This may need to be arm-none-eabi-gdb depending on your system
  201. "gdbPath" : "gdb-multiarch",
  202. // Connect to an already running OpenOCD instance
  203. "gdbTarget": "192.168.0.10:3333",
  204. "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
  205. "runToMain": true,
  206. // Work around for stopping at main on restart
  207. "postRestartCommands": [
  208. "break main",
  209. "continue"
  210. ]
  211. }
  212. ]
  213. }
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220. 9.ビルドをする
  221.  
  222. CTRL+SHIFT+Pを押してコマンドパレットを開き、CMakeと入力
  223.  
  224. CMake: Quick Startを選択します
  225.  
  226.  
  227. すると一番したのバーにCMake:[Debug]準備完了、
  228. キットが選択されていません、
  229. ビルド
  230.  
  231. ができます
  232.  
  233. コマンドパレットが開きlissajous_usb01のキットを選択してくださいと出るので
  234. GCC for arm-none-eabiを選択します
  235.  
  236.  
  237. 画面一番下のCMake:[Debug]を押します
  238. するとコマンドパレットが開くのでDebugを選択します
  239.  
  240. 次に画面一番下のビルドをクリックします
  241.  
  242. するとビルドが始まります
  243.  
  244.  
  245.  
  246. 10.デバッグを開始する
  247.  
  248. CTRL+SHIFT+Dを押します
  249. 画面左上のPico Debugの左側の再生ボタンをクリックします
  250. (ボタンを押す前にRaspberry Pi Zero側でOpenOCDが起動してることを確認してください)
  251. lissajous_usb01の起動対象を選択しますと聞かれるので
  252. lissajous_usb01を選択します
  253.  
  254.  
  255. デバッグが始まるとmainのところで停止します
  256.  
  257. 補足
  258. lissajous01の関数に入るには29行目にブレークポイントを設定してから
  259. continueを実行するといいかも
  260.  
  261.  
  262.  
  263. 以下、lissajous_usb01.cのソースコードです
  264.  
  265. #include <stdio.h>
  266. #include <math.h>
  267. #include "pico/stdlib.h"
  268.  
  269. #define COLUMN (78)
  270.  
  271. char buf01[COLUMN * COLUMN];
  272.  
  273.  
  274. int lissajous01(int start, int end, int step, double size, double a, double b, int column, char *buf01);
  275.  
  276.  
  277. int main(int argc, char *argv[])
  278. {
  279. stdio_init_all();
  280.  
  281. while (1) {
  282. for (int i = 3; i < 9; i++) {
  283. lissajous01(0, 36000, 20, 35.0, i, 5.0, COLUMN, (char *)buf01);
  284. sleep_ms(5000);
  285. }
  286. }
  287.  
  288. return 0;
  289. }
  290.  
  291. int lissajous01(int start, int end, int step, double size, double a, double b, int column, char *buf01)
  292. {
  293. int ret;
  294. int i, j, ix, iy, column01, column02;
  295. long l;
  296. double rad01, x, y, ratio01;
  297.  
  298. ratio01 = 0.5;
  299. rad01 = 3.141592653589793 / 180.0;
  300. column01 = column;
  301. column02 = column01 * ratio01 + 0.999999999999;
  302.  
  303. for (j = 0; j < column02; j++) {
  304. for (i = 0; i < column01; i++) {
  305. *(buf01 + column01 * j + i) = 0;
  306. }
  307. }
  308.  
  309. for (l = start; l <= end; l += step) {
  310. x = size * cos(rad01 * l / 100.0 * a) + column01 / 2.0;
  311. y = size * sin(rad01 * l / 100.0 * b) * ratio01 + column02 / 2.0;
  312. ix = (int)(x + 0.5);
  313. iy = (int)(y + 0.5);
  314. if ((ix >= 0) && (ix <= column01) && (iy >= 0) && (iy <= column02)){
  315. *(buf01 + column01 * iy + ix) = 1;
  316. }
  317. }
  318.  
  319. for (j = 0; j < column02; j++) {
  320. for (i = 0; i < column01; i++) {
  321. if (*(buf01 + column01 * j + i) == 0) {
  322. putchar(' ');
  323. } else {
  324. putchar('*');
  325. }
  326. }
  327. putchar('\n');
  328. }
  329.  
  330. ret = 0;
  331. return ret;
  332. }
  333.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement