Raspberry Pi Zero WでPC(macbook)とのSerial通信

# 目的
自作Linuxカーネルドライバの勉強をRaspbianを題材にしているので、Raspberry PiでSerial通信が有効になれば色々動作確認が楽になる。

# 目標
Raspberry pi - PC間をUARTで繋いでsystem logをみる。
コマンドを叩ける
起動ログが見れる

# やり方
(Raspberry pi zero w) - (Serial - USB変換アダプター) - (PC / macbook pro)
変換アダプターは、FT232のSerial-USB変換ボードをAmazonから仕入れた。
Switch Scienceや秋月からも別の種類のものを買ってみたところ、動作するものとしないものがあった。
macbook proで以下のは動作させることが出来た
買ったのは[これ](https://amzn.to/2tmqC3s)になります

不良品などがあるので、価格もそんなに高くないため動かなかったら、色々設定を見直したりせずに別のものを購入する方が結果的に早く目的に近づける気がします。

## Raspberry pi 側
GPIOピンの中にSerialのRX/TXピンがあるのでGPIO MAPを見て接続する。
こちらの投稿を参考にした
https://qiita.com/hidenorly/items/f6ffe79fb6f81740eff3
[GPIO MAP](https://cdn.sparkfun.com/assets/learn_tutorials/6/7/6/PiZero_1.pdf)を参考にPin 8 TX Pin10 RXをPC側のそれぞれRX TXに繋いだ。TX -> RX , RX -> TXに繋がないと駄目。
こんな感じになります
![IMG_1146.jpg](https://qiita-image-store.s3.amazonaws.com/0/181375/64ab1882-8759-ae99-94da-93d25709c63e.jpeg)
![IMG_1147.jpg](https://qiita-image-store.s3.amazonaws.com/0/181375/778cfefd-6acd-cf98-ed9c-9079eb7ec12e.jpeg)

## Raspberry Pi Zero側の設定
Raspberry Pi Zero W側のbootドライブの```/boot/config.txt ```最後尾にSerialを有効にするための設定を追記する
```
enable_uart=1
```

## macOS側
windowsはTeraTermなどがおすすめ
macOSはそれと同じような使い勝手のものが分からないので適当にSerialToolsというアプリを使います。
設定は```Baud rate = 115200,bit 8,stop bit1```で立ち上げればアクセスできる

### 追記
アプリだと微妙に使いづらいので結局
``` screen /dev/tty.usbserial-AK05US9F 115200,cs8 ```
screenコマンドがTeraTermと同じような端末操作が出来るので使いやすい

## ログ
```
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.14.79+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1159 Sun Nov 4 17:28:08 GMT 2018
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] OF: fdt: Machine model: Raspberry Pi Zero W Rev 1.1
[    0.000000] Memory policy: Data cache writeback
[    0.000000] cma: Reserved 8 MiB at 0x1b400000
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
[    0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=1360 bcm2708_fb.fbheight=768 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:5A:C5:2E vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=PARTUUID=af9ad747-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[    0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 435228K/458752K available (6435K kernel code, 588K rwdata, 1992K rodata, 444K init, 673K bss, 15332K reserved, 8192K cma-reserved)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xdc800000 - 0xff800000   ( 560 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xdc000000   ( 448 MB)
[    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
[    0.000000]       .text : 0xc0008000 - 0xc0650e90   (6436 kB)
[    0.000000]       .init : 0xc08cf000 - 0xc093e000   ( 444 kB)
[    0.000000]       .data : 0xc093e000 - 0xc09d1000   ( 588 kB)
[    0.000000]        .bss : 0xc09d6904 - 0xc0a7eeac   ( 674 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] ftrace: allocating 24117 entries in 71 pages
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000031] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
[    0.000075] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.000167] bcm2835: system timer (irq = 27)
[    0.000745] Console: colour dummy device 80x30
[    0.001327] console [tty1] enabled
[    0.001386] Calibrating delay loop… 697.95 BogoMIPS (lpj=3489792)
[    0.060345] pid_max: default: 32768 minimum: 301
[    0.060861] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.060916] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.062236] Disabling memory control group subsystem
[    0.062443] CPU: Testing write buffer coherency: ok
[    0.063619] Setting up static identity map for 0x8200 - 0x8238
[    0.064907] devtmpfs: initialized
[    0.074336] random: get_random_u32 called from bucket_table_alloc+0x88/0x1c4 with crng_init=0
[    0.075252] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
[    0.075667] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.075738] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.077095] pinctrl core: initialized pinctrl subsystem
[    0.078488] NET: Registered protocol family 16
[    0.081469] DMA: preallocated 1024 KiB pool for atomic coherent allocations
[    0.087726] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers.
[    0.087798] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.087942] Serial: AMBA PL011 UART driver
[    0.090912] bcm2835-mbox 2000b880.mailbox: mailbox enabled
[    0.091709] uart-pl011 20201000.serial: could not find pctldev for node /soc/gpio@7e200000/uart0_pins, deferring probe
[    0.131613] bcm2835-dma 20007000.dma: DMA legacy API manager at dc80d000, dmachans=0x1
[    0.133879] SCSI subsystem initialized
[    0.134144] usbcore: registered new interface driver usbfs
[    0.134274] usbcore: registered new interface driver hub
[    0.134507] usbcore: registered new device driver usb
[    0.140835] raspberrypi-firmware soc:firmware: Attached to firmware from 2018-11-04 16:31
[    0.142873] clocksource: Switched to clocksource timer
[    0.231646] VFS: Disk quotas dquot_6.6.0
[    0.231823] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.232140] FS-Cache: Loaded
[    0.232496] CacheFiles: Loaded
[    0.249630] NET: Registered protocol family 2
[    0.250868] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
[    0.251001] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[    0.251121] TCP: Hash tables configured (established 4096 bind 4096)
[    0.251298] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.251359] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.251737] NET: Registered protocol family 1
[    0.252499] RPC: Registered named UNIX socket transport module.
[    0.252554] RPC: Registered udp transport module.
[    0.252581] RPC: Registered tcp transport module.
[    0.252605] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.254642] hw perfevents: no irqs for PMU, sampling events not supported
[    0.254774] hw perfevents: enabled with armv6_1176 PMU driver, 3 counters available
[    0.258509] workingset: timestamp_bits=14 max_order=17 bucket_order=3
[    0.270587] FS-Cache: Netfs ‘nfs’ registered for caching
[    0.271970] NFS: Registering the id_resolver key type
[    0.272062] Key type id_resolver registered
[    0.272094] Key type id_legacy registered
[    0.272143] nfs4filelayout_init: NFSv4 File Layout Driver Registering…
[    0.276957] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.277441] io scheduler noop registered
[    0.277490] io scheduler deadline registered (default)
[    0.278042] io scheduler cfq registered
[    0.278089] io scheduler mq-deadline registered
[    0.278119] io scheduler kyber registered
[    0.280414] BCM2708FB: allocated DMA memory 5b500000
[    0.280525] BCM2708FB: allocated DMA channel 0 @ dc80d000
[    0.306221] Console: switching to colour frame buffer device 170x48
[    0.326540] Serial: 8250/16550 driver, 1 ports, IRQ sharing enabled
[    0.329617] bcm2835-rng 20104000.rng: hwrng registered
[    0.330098] vc-mem: phys_addr:0x00000000 mem_base=0x1ec00000 mem_size:0x20000000(512 MiB)
[    0.331489] vc-sm: Videocore shared memory driver
[    0.332353] gpiomem-bcm2835 20200000.gpiomem: Initialised: Registers at 0x20200000
[    0.352378] brd: module loaded
[    0.365285] loop: module loaded
[    0.365475] Loading iSCSI transport class v2.0-870.
[    0.366546] usbcore: registered new interface driver smsc95xx
[    0.366812] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    0.395140] dwc_otg 20980000.usb: base=0xf0980000
[    0.595777] Core Release: 2.80a
[    0.595950] Setting default values for core params
[    0.602179] Finished setting default values for core params
[    0.808715] Using Buffer DMA mode
[    0.814859] Periodic Transfer Interrupt Enhancement - disabled
[    0.820942] Multiprocessor Interrupt Enhancement - disabled
[    0.827037] OTG VER PARAM: 0, OTG VER FLAG: 0
[    0.833148] Dedicated Tx FIFOs mode
[    0.840102] WARN::dwc_otg_hcd_init:1046: FIQ DMA bounce buffers: virt = 0xdb514000 dma = 0x5b514000 len=9024
[    0.846518] FIQ FSM acceleration enabled for :
[    0.846518] Non-periodic Split Transactions
[    0.846518] Periodic Split Transactions
[    0.846518] High-Speed Isochronous Endpoints
[    0.846518] Interrupt/Control Split Transaction hack enabled
[    0.877705] WARN::hcd_init_fiq:459: FIQ on core 0 at 0xc049c7ac
[    0.883962] WARN::hcd_init_fiq:460: FIQ ASM at 0xc049ca88 length 36
[    0.890060] WARN::hcd_init_fiq:486: MPHI regs_base at 0xf0006000
[    0.896237] dwc_otg 20980000.usb: DWC OTG Controller
[    0.902426] dwc_otg 20980000.usb: new USB bus registered, assigned bus number 1
[    0.908716] dwc_otg 20980000.usb: irq 56, io mem 0x00000000
[    0.915011] Init: Port Power? op_state=1
[    0.921098] Init: Power Port (0)
[    0.927549] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    0.933700] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.939765] usb usb1: Product: DWC OTG Controller
[    0.945816] usb usb1: Manufacturer: Linux 4.14.79+ dwc_otg_hcd
[    0.951924] usb usb1: SerialNumber: 20980000.usb
[    0.959265] hub 1-0:1.0: USB hub found
[    0.965685] hub 1-0:1.0: 1 port detected
[    0.973574] usbcore: registered new interface driver usb-storage
[    0.980343] mousedev: PS/2 mouse device common for all mice
[    0.986725] IR NEC protocol handler initialized
[    0.992925] IR RC5(x/sz) protocol handler initialized
[    0.998999] IR RC6 protocol handler initialized
[    1.005031] IR JVC protocol handler initialized
[    1.010838] IR Sony protocol handler initialized
[    1.016633] IR SANYO protocol handler initialized
[    1.022323] IR Sharp protocol handler initialized
[    1.027959] IR MCE Keyboard/mouse protocol handler initialized
[    1.033723] IR XMP protocol handler initialized
[    1.040818] bcm2835-wdt 20100000.watchdog: Broadcom BCM2835 watchdog timer
[    1.047327] bcm2835-cpufreq: min=700000 max=1000000
[    1.053920] sdhci: Secure Digital Host Controller Interface driver
[    1.059819] sdhci: Copyright(c) Pierre Ossman
[    1.066304] mmc-bcm2835 20300000.mmc: could not get clk, deferring probe
[    1.073308] sdhost-bcm2835 20202000.mmc: could not get clk, deferring probe
[    1.079558] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.086228] ledtrig-cpu: registered to indicate activity on CPUs
[    1.092400] hidraw: raw HID events driver (C) Jiri Kosina
[    1.098686] usbcore: registered new interface driver usbhid
[    1.104734] usbhid: USB HID core driver
[    1.111487] vchiq: vchiq_init_state: slot_zero = db580000, is_master = 0
[    1.119579] [vc_sm_connected_init]: start
[    1.131303] [vc_sm_connected_init]: end - returning 0
[    1.138560] Initializing XFRM netlink socket
[    1.144605] NET: Registered protocol family 17
[    1.150590] Key type dns_resolver registered
[    1.158224] registered taskstats version 1
[    1.172688] uart-pl011 20201000.serial: cts_event_workaround enabled
[    1.178930] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[    1.187758] console [ttyS0] disabled
[    1.193968] 20215040.serial: ttyS0 at MMIO 0x0 (irq = 160, base_baud = 31250000) is a 16550
[    2.159966] console [ttyS0] enabled
[    2.171483] mmc-bcm2835 20300000.mmc: mmc_debug:0 mmc_debug2:0
[    2.183823] mmc-bcm2835 20300000.mmc: DMA channel allocated
[    2.254477] sdhost: log_buf @ db513000 (5b513000)
[    2.292039] random: fast init done
[    2.310185] mmc1: queuing unknown CIS tuple 0x80 (2 bytes)
[    2.323744] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    2.337129] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    2.348832] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[    2.361987] of_cfs_init
[    2.391116] of_cfs_init: OK
[    2.401347] Waiting for root device PARTUUID=af9ad747-02…
[    2.413937] mmc1: queuing unknown CIS tuple 0x80 (7 bytes)
[    2.470460] mmc0: host does not support reading read-only switch, assuming write-enable
[    2.486874] mmc0: Problem switching card into high-speed mode!
[    2.499940] mmc0: new SDHC card at address 0001
[    2.512131] mmcblk0: mmc0:0001 SPCC 14.6 GiB
[    2.525826]  mmcblk0: p1 p2
[    2.556763] EXT4-fs (mmcblk0p2): INFO: recovery required on readonly filesystem
[    2.570738] EXT4-fs (mmcblk0p2): write access will be enabled during recovery
[    2.620555] mmc1: new high speed SDIO card at address 0001
[    2.726425] EXT4-fs (mmcblk0p2): recovery complete
[    2.751867] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    2.766692] VFS: Mounted root (ext4 filesystem) readonly on device 179:2.
[    2.796484] devtmpfs: mounted
[    2.808552] Freeing unused kernel memory: 444K
[    2.819388] This architecture does not have kernel memory protection.
[    3.699750] systemd[1]: System time before build time, advancing clock.
[    3.917740] NET: Registered protocol family 10
[    3.930682] Segment Routing with IPv6
[    3.973945] ip_tables: (C) 2000-2006 Netfilter Core Team
[    4.022487] random: systemd: uninitialized urandom read (16 bytes read)
[    4.045743] systemd[1]: systemd 232 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
[    4.078831] systemd[1]: Detected architecture arm.
[    4.116883] systemd[1]: Set hostname to <raspberrypi>.
[    4.213149] random: systemd: uninitialized urandom read (16 bytes read)
[    4.411538] random: systemd-cryptse: uninitialized urandom read (16 bytes read)
[    5.399702] systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[    5.423933] systemd[1]: Listening on Journal Socket (/dev/log).
[    5.446856] systemd[1]: Created slice System Slice.
[    5.468852] systemd[1]: Created slice system-getty.slice.
[    5.496644] systemd[1]: Mounting Debug File System…
[    5.574750] systemd[1]: Listening on udev Control Socket.
[    5.599573] systemd[1]: Created slice system-serial\x2dgetty.slice.
```

出来た