How to use UART on TX2?

Does TX2 have a library just like “raspberry pi” to control UART and I2C?

It isn’t exactly like RPi. Details differ somewhat depending on what L4T release you use…the most recent is R28.1 (see “head -n 1 /etc/nv_tegra_release”). You might find this of interest:
http://www.jetsonhacks.com/category/hardware/gpioi2c/
https://devtalk.nvidia.com/default/topic/1007639/jetson-tx2/how-do-i-map-signal-names-to-gpio-numbers-/post/5144174/#5144174

Note that GPIO pins can be configured to do more than one function (but only one function at a time). You may see references to the device tree…this is how a GPIO pin can be set to different functionality when that pin is capable of doing more than one function.

The TX1 and TX2 boards use the same carriers…much about GPIO matches between a TX1 and TX2, but not everything…especially device tree. Methods of dealing with device tree change depending on which L4T release and which carrier board is used.

Many references you see will refer to the simplest way to see GPIO…via “echo” of a value on command line to a file in “/sys”. “/sys” layout may differ depending on L4T release and carrier (because of device tree), but explore “/sys/kernel/debug/”, e.g.:

sudo -s
find /sys/kernel/debug -name '*gpio*'
cat /sys/kernel/debug/gpio
exit

“/sys” is not a real file system, it runs in RAM and is a side effect of various drivers from which you can access some of the functionality.

Thanks,
I delete “console=tty0 console=ttyS0,115200n8” in “/boot/extlinux/extlinux.conf” to make ttyS0 useful. But I found this serial port can not work stably. Is that TX2 clock’s problem? Or this serial port can not use like this? How about ttyTHS2 or ttyTHS3?

ttyS0 is also set up in U-Boot since it is the serial console. Device tree is involved, but U-Boot itself has some of the settings being used for serial console setup. I believe you would have to modify the device tree as seen for both U-Boot and Linux to remove serial console (I wouldn’t suggest losing serial console). Information on changing the serial console to a different port can be found here…you can extrapolate from this:
https://devtalk.nvidia.com/default/topic/1025894/jetson-tx2/uart1-acts-as-default-debug-port-on-tx2-r28-1/post/5220368/#5220368

ttyTHS2 is normally available on connector J17 if your camera slot does not use it. This is probably a better option than removing serial console.

Yeah, I use ttyTHS2, and it works very well.

I can’t find /dev/ttyTHS2 in TX2 and I want use J17 as UART1. Can you help me?Please give more detail!

Install the latest jetpack and it will come back, unless you’re using a third party carrier board that doesn’t support this UART.

Can I update to the latest jetpack? Or I must reinstall jetpack? Please give more detail.Thank you!

Generally, the jetpack will re-flash the device, yes.

In all software development, you will want to make sure that all tools and source code and modifications you make to a system are controlled in some kind of configuration management system.
Source in git or svn or something, configuration in puppet or nix or shell scripts or something.

This is one of those things that software engineers learn early, just like machinists learn “wipe chips off the vise before mounting work” and drivers learn “look behind you before backing up.”
This, and making sure you have proper backups of everything.

If you don’t currently have a setup where it’s easy to recover after a re-flash, now is a great time to document what you need to re-do, and get to a good place for the future!

So that means I must reinstall jetpack rather update.That’s terrible!Thank you very much!

If I use this method as following:

sudo -s
cd /tmp
dtc -I dtb -o dts extracted.dts /boot/tegra186-quill-p3310-1000-c03-00-base.dtb

Search for “serial@c280000” where it is a block of code and not just a single line…

Change status = “disabled” to status = “okay”;

Build a modified version:

dtc -I dts -o dtb /boot/modified_tegra186-quill-p3310-1000-c03-00-base.dtb extracted.dts
cd /boot/extlinux

edit extlinux.conf…add this line between MENU LABEL line and LINUX line:

FDT /boot/modified_tegra186-quill-p3310-1000-c03-00-base.dtb

But when it’s come to the last step,it occurs the error— bash:FDT:command not found

Do you know to solve it?

I don’t know FDT.

Please avoid duplicate posts. Answered here:
https://devtalk.nvidia.com/default/topic/1009901/jetson-tx2/tx2-uart-enabling-dev-ttyths2/post/5253370/#5253370

Note that you can clone your rootfs for reference before flashing. You will find flashing results to generally be better than trying to pick pieces and fix one hole at a time.

I’m so sorry!
I felt that if I ask question in different website I can get more solution.It’s my fault.
Hope you have a good day!