After a lot of research, I found a solution to get 1-wire to work with the w1-gpio driver on a Jetson AGX Xavier with a DS18B20.
Important!!! Jetson AGX support 1-ware only for specific pins connected to tegra_aon_gpio
like 16 pin.
Other pins did not work.
To get gpio PIN number use cat /sys/kernel/debug/gpio
For example pin 16 have ID=GPIO3_PBB.00 → gpio-313 (PBB.00 |onewire@0 ) out hi
So pin 16 = gpio-313 (number used next in w1-gpio-cl module command)
Different Jetson models and JetPack versions use different gpio numbers!
To make it work, there are 2 options.
In both cases, you must compile the kernel with w1 support.
- Option to use w1-master driver from Linux kernel + dtb patch.
- Option to use w1-gpio-cl module GitHub - pstolarz/w1-gpio-cl: Command line configured kernel mode 1-wire bus master driver. w1-gpio standard Linux module enhancement/substitution. - it’s better. And work for Jetson Nano, NX, etc.
To compile the Linux kernel with the w1-gpio driver:
-
Download the sources of the kernel you are using.
For example JP5.2.1 https://developer.download.nvidia.com/embedded/L4T/r35_Release_v2.1/sources/public_sources.tbz2
-
Add lines to file Linux_for_Tegra/sources/kernel/kernel-5.10/arch/arm64/configs/tegra_defconfig
CONFIG_W1=y
CONFIG_W1_MASTER_GPIO=y
CONFIG_W1_SLAVE_THERM=y
NVIDIA please add these lines as default for Linux_for_Tegra.
Because it’s only 1 KB to kernel, but in this case we don’t need to rebuild the kernel to support w1.
- To build use
Linux_for_Tegra/sources/nvbuild.sh -o ./kernel_out
Now kernel in Linux_for_Tegra/sources/kernel_out/arch/arm64/boot/Image
- Copy the new kernel file into jetson and replace
/boot/Image
with it and reboot. No need to flash it. Just replace the file.
Your system now supports the 1-wire driver.
Option to use w1-master with dtb patch ( Hard way)
Dtb is used to select the pin you use for 1-wire. In the example TEGRA194_MAIN_GPIO(B, 0)
this is pin 16 GPIO3_PBB.00 = (B, 0)
Add to file Linux_for_Tegra/sources/hardware/nvidia/platform/t19x/galen/kernel-dts/tegra194-p2888-0001-p2822-0000.dts
/ {
onewire@0 {
compatible = "w1-gpio";
gpios = <&tegra_aon_gpio TEGRA194_MAIN_GPIO(B, 0) GPIO_ACTIVE_HIGH>; // 40-pin conn., pin 16
status = "okay";
};
};
Compile dtb with Linux_for_Tegra/sources/nvbuild.sh -o ./kernel_out
and flash them using SDK Manager.
I also tested a dtb overlay for this. It’s better this way and you don’t need to flash dtb.
Option to use w1-gpio-cl
Compile w1-gpio-cl according to instructions from github.
For Jetson I used:
- Copy the kernel sources from (1) to jetson.
Call make tegra_defconfig modules_prepare
in sources.
- In w1-gpio-cl sources
export KERNEL_SRC=/home/jetson/Linux_for_Tegra/kernel/kernel-5.10 # path to kernel sources from (1)
make
make install
- To start w1-gpio-cl on 16 pin call
sudo modprobe -v w1-gpio-cl m1="gdt=313,od"
Result:
Now ls /sys/devices/w1_bus_master1
shows all DS18B20.
For example my DS18B20 ID name like 28-937abc0164ff
And temperature cat /sys/devices/w1_bus_master1/28-937abc0164ff/temperature
→ 26437
this is 26.437 ℃
PS. Wiring diagram like Raspberry pi. With a 4.7k resistor from VCC to the data pin.