Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable CAN communication #2

Merged
merged 2 commits into from
Aug 19, 2023
Merged

enable CAN communication #2

merged 2 commits into from
Aug 19, 2023

Conversation

KantaTamura
Copy link
Collaborator

@KantaTamura KantaTamura commented Aug 15, 2023

変更内容

  • mcp2517fd用のデバイスツリーを追加
  • CAN通信を行うためのカーネルモジュールの追加

変更詳細

device-tree

作成した mcp2517fd-overlay.dts をカーネルのデバイスツリービルドフォルダに追加し,一緒にビルドするようにした

kernel-module

MCP2517FDを用いたCAN通信を行うための最小限のカーネルモジュールをインストールするようにした

  • spi_bcm2835 : raspberry pi zero 2 w で使用できるSPI通信用のモジュール
  • can_dev : CAN Network Device Driver Interface
  • can_raw : これが無いとCAN通信時に address family not supported by protocol と表示される
  • mcp251xfd : MCP2517FD用のドライバ

CAN通信を試す方法

root login

'local.conf'に次の内容を加える

EXTRA_IMAGE_FEATURES:append = " debug-tweaks"

install can-utils

doc/zero/build.md の内容に加えて,meta-openembeddedmeta-oe 追加し,'local.conf' に次の内容を加える.

IMAGE_INSTALL:append = " can-utils"

candump & cangen

note
can通信する相手がいないと error-passive となり,通信できない

rootログイン後下記のコマンドを試す

$ ip link set can0 up type can bitrate 1000000
$ candump can0 &
$ cangen can0

@sasataku
Copy link
Member

PRの中にcommitが4つありますが、後半2つのcommitは、前半2つのcommitの修正なので、
git commit --amend を使って 前半2つのcommitに含めてしまうとよいです。
(詳細は会議で教えます)

@sasataku
Copy link
Member

sasataku commented Aug 17, 2023

[質問]
レシピのディレクリ・ファイルの名前や、ネストの切り方とか、どのようなポリシーで決めてますか?

i.g)
recipes-devicetree/linux/linux-raspberrypi_%.bbappend
recipes-devicetree/linux/linux-raspberrypi/scsat1-rpi/mcp2517fd-overlay.dts

Comment on lines 5 to 6
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
${LAYERDIR}/recipes-*/*/*.bbappend"
Copy link
Member

@sasataku sasataku Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta-raspberrypiとかと同じ書き方にしていると思うけど、receipeが固定で決まっているなら、*を使わずに、個別に指定してもよいのでは?

@KantaTamura
Copy link
Collaborator Author

[質問] レシピのディレクリ・ファイルの名前や、ネストの切り方とか、どのようなポリシーで決めてますか?

i.g) recipes-devicetree/linux/linux-raspberrypi_%.bbappend recipes-devicetree/linux/linux-raspberrypi/scsat1-rpi/mcp2517fd-overlay.dts

recipes-devicetreeディレクトリはrecipetool appendsrcfileを用いて生成したので,ディレクトリ名・構造はデフォルトの命名規則なのかな?と思っていました

recipetool appendsrcfile -wm scsat1-rpi ./meta-mcp2517fd virtual/kernel /tmp/mcp2517fd-overlay.dtso 'arch/${ARCH}/boot/dts/overlays/mcp2517fd-overlay.dts'

今回のMACHINE名はscsat1-rpiではなくraspberrypi0-2w-64なのでその部分は間違ってます...

meta-raspberrypiのレシピを見ていたのですが,recipetool appendsrcfileでrecipe-devicetree下にlinuxというフォルダ単体が生成されているのは,レシピに複数の機能をもたせるためで,今回の場合は下記の様なファイル構造でも問題ないということであっていますか?(layer.confは適切に修正)

meta-mcp2517fd
├─conf
│  ├─layer.conf
├─recipe-devicetree
   ├─file
   │  ├─mcp2517fd-overlay.dts
   ├─mcp2517fd-overlay.bbappend

.bb.bbappendファイルによく見れれる_1.0.bb_%.bbとなっているのはなぜでしょうか?

@yashi
Copy link
Member

yashi commented Aug 17, 2023

recipetool appendsrcfileでrecipe-devicetree下にlinuxというフォルダ単体が生成されているのは,レシピに複数の機能をもたせるためで,今回の場合は下記の様なファイル構造でも問題ないということであっていますか?

大丈夫。

多くの Layer が bitbake-layers create-layer で作ってんじゃないかな?「いらないだろ」っていうファイルが残っている repo も、たくさんあるよ。

昔作った layer だと最終的に↓こうなったけど、最初はフラットで追加するたびにディレクトリ作っていった (proj 部分だけ置換した)

$ tree -L 3 meta-proj
meta-proj
├── COPYING.MIT
├── README
├── conf
│   └── layer.conf
├── recipes-apps
│   ├── proj-app
│   │   └── proj-app_1.1.bb
│   └── proj-webapp
│       └── proj-webapp_1.0.bb
└── recipes-core
    ├── base-files
    │   └── base-files_%.bbappend
    ├── images
    │   └── proj-image.bb
    ├── systemd-conf
    │   ├── files
    │   └── systemd-conf_%.bbappend
    └── tzdata
        └── tzdata.bbappend

11 directories, 9 files

% は、 https://docs.yoctoproject.org/bitbake/singleindex.html#append-files

Copy link
Member

@yashi yashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正が必要なのは依存関係だけかな。あとは趣味程度

zero/meta-mcp2517fd/conf/layer.conf Outdated Show resolved Hide resolved
zero/meta-mcp2517fd/conf/layer.conf Outdated Show resolved Hide resolved
can controller (mcp2517fd) を認識するためのデバイス情報を追加
モジュールは未作成

Signed-off-by: KantaTamura <[email protected]>
mcp251xfd用のモジュールをインストールしている
spi_bcm2835 : spi通信
can-dev : can通信
mcp251xfd : mcp2517fd用モジュール
can-raw : 無いとエラー (address family not supported by protocol)

Signed-off-by: KantaTamura <[email protected]>
@yashi yashi merged commit c3ca689 into main Aug 19, 2023
2 checks passed
@yashi yashi deleted the wip/dt-mcp2517fd branch August 19, 2023 00:29
@yashi
Copy link
Member

yashi commented Aug 19, 2023

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants