Acessando a console serial na Raspberry Pi
- por Sergio Prado
Nenhum kit de desenvolvimento é completo sem uma interface de console serial, normalmente provida por uma conexão RS-232.
É esta interface de console que permite executar operações de baixo nível no equipamento, como acessar a linha de comandos do bootloader ou depurar o kernel, sendo imprescíndivel quando trabalhamos com desenvolvimento ou adaptação do sistema operacional para a plataforma.
E com a Raspberry Pi não é diferente. Ela provê uma console serial via RS-232, disponível no barramento externo de GPIOs:
Para a conexão serial, você vai usar o Ground, o GPIO 14 (TX) e o GPIO 15 (RX), conforme imagem abaixo:
Se você for conectar à uma porta serial no seu PC, ou usar um cabo conversor USB/Serial sem suporte à 3,3V como entrada, você vai precisar de um conversor de nível 3,3V para RS-232, já que o SoC da Broadcom trabalha com este nível de tensão. Se você estiver com espírito de MacGyver, pode construir um conversor usando o MAX3232CPE (dá uma olhada neste artigo aqui).
Mas se você quiser praticidade, pode comprar um cabo conversor RS232/USB que suporte 3,3V como entrada, como esse da FTDI. Eu comprei um lá no ebay e (surpreendentemente) funcionou que é uma beleza! :)
Outra possibilidade é usar o Bus Pirate, o canivete suíço dos analisadores de barramentos!
Com o cabo, placa ou ferramenta em mãos, é só ligar nos pinos especificados na imagem mais acima, configurar seu programa de console favorito em 115200,8N1 e curtir o boot do Linux na Raspberry Pi!
Uncompressing Linux... done, booting the kernel. Initializing cgroup subsys cpu Linux version 3.2.27-cutdown (root@ubuntu) (gcc version 4.6.3 (crosstool-NG hg+default-366637520035) ) #1 PREEMPT Sat Oct 20 16:12:56 BST 2012 CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache Machine: BCM2708 Memory policy: ECC disabled, Data cache writeback Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512 Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0x2 bcm2708.serial=0xff0782fa smsc95xx.macaddr=B8:27:EB:07:82:FA sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x8000000 vc_mem.mem_size=0x10000000 dwc_otg.speed=0 dwc_otg.lpm_enable=0 root=/dev/ram0 init=/sbin/init console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 PID hash table entries: 512 (order: -1, 2048 bytes) Dentry cache hash table entries: 16384 (order: 4, 65536 bytes) Inode-cache hash table entries: 8192 (order: 3, 32768 bytes) Memory: 128MB = 128MB total Memory: 121960k/121960k available, 9112k reserved, 0K highmem Virtual kernel memory layout: vector : 0xffff0000 - 0xffff1000 ( 4 kB) fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) vmalloc : 0xc8800000 - 0xe8000000 ( 504 MB) lowmem : 0xc0000000 - 0xc8000000 ( 128 MB) modules : 0xbf000000 - 0xc0000000 ( 16 MB) .text : 0xc0008000 - 0xc03b6000 (3768 kB) .init : 0xc03b6000 - 0xc0753cfc (3704 kB) .data : 0xc0754000 - 0xc0776f40 ( 140 kB) .bss : 0xc0776f64 - 0xc07c003c ( 293 kB) NR_IRQS:330 sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 4294967ms timer_set_mode: unhandled mode:1 timer_set_mode: unhandled mode:3 Console: colour dummy device 80x30 console [tty1] enabled Calibrating delay loop... 531.66 BogoMIPS (lpj=2658304) pid_max: default: 32768 minimum: 301 Mount-cache hash table entries: 512 CPU: Testing write buffer coherency: ok devtmpfs: initialized NET: Registered protocol family 16 bcm2708.uart_clock = 0 mailbox: Broadcom VideoCore Mailbox driver bcm2708_vcio: mailbox at f200b880 bcm_power: Broadcom power driver bcm_power_open() -> 0 bcm_power_request(0, 8) bcm_mailbox_read -> 00000080, 0 bcm_power_request -> 0 Serial: AMBA PL011 UART driver dev:f1: ttyAMA0 at MMIO 0x20201000 (irq = 83) is a PL011 rev3 console [ttyAMA0] enabled bio: create slab at 0 SCSI subsystem initialized usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb Switching to clocksource stc FS-Cache: Loaded CacheFiles: Loaded NET: Registered protocol family 2 IP route cache hash table entries: 1024 (order: 0, 4096 bytes) TCP established hash table entries: 4096 (order: 3, 32768 bytes) TCP bind hash table entries: 4096 (order: 2, 16384 bytes) TCP: Hash tables configured (established 4096 bind 4096) TCP reno registered UDP hash table entries: 256 (order: 0, 4096 bytes) UDP-Lite hash table entries: 256 (order: 0, 4096 bytes) NET: Registered protocol family 1 bcm2708_dma: DMA manager at c890a000 bcm2708_gpio: bcm2708_gpio_probe c0759a98 vc-mem: phys_addr:0x00000000 mem_base=0x08000000 mem_size:0x10000000(256 MiB) msgmni has been set to 238 io scheduler noop registered io scheduler deadline registered io scheduler cfq registered (default) Console: switching to colour frame buffer device 82x26 brd: module loaded loop: module loaded vcos: [1]: vchiq_init_state: slot_zero = 0xffd80000, is_master = 0 vcos: [1]: vchiq_init_state: called vcos: [1]: vchiq: initialised - version 2 (min 2), device 253.0 usbcore: registered new interface driver smsc95xx cdc_ncm: 04-Aug-2011 usbcore: registered new interface driver cdc_ncm dwc_otg: version 3.00a 10-AUG-2012 (platform bus) Core Release: 2.80a Setting default values for core params Finished setting default values for core params Using Buffer DMA mode Periodic Transfer Interrupt Enhancement - disabled Multiprocessor Interrupt Enhancement - disabled OTG VER PARAM: 0, OTG VER FLAG: 0 Dedicated Tx FIFOs mode dwc_otg bcm2708_usb: DWC OTG Controller dwc_otg bcm2708_usb: new USB bus registered, assigned bus number 1 dwc_otg bcm2708_usb: irq 32, io mem 0x00000000 Init: Port Power? op_state=1 Init: Power Port (0) usb usb1: New USB device found, idVendor=1d6b, idProduct=0002 usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 usb usb1: Product: DWC OTG Controller usb usb1: Manufacturer: Linux 3.2.27-cutdown dwc_otg_hcd usb usb1: SerialNumber: bcm2708_usb hub 1-0:1.0: USB hub found hub 1-0:1.0: 1 port detected usbcore: registered new interface driver uas Initializing USB Mass Storage driver... usbcore: registered new interface driver usb-storage USB Mass Storage support registered. usbcore: registered new interface driver libusual mousedev: PS/2 mouse device common for all mice cpuidle: using governor ladder cpuidle: using governor menu sdhci: Secure Digital Host Controller Interface driver sdhci: Copyright(c) Pierre Ossman sdhci: Enable low-latency mode bcm_power_open() -> 1 mmc0: SDHCI controller on BCM2708_Arasan [platform] using platform's DMA mmc0: BCM2708 SDHC host at 0x20300000 DMA 2 IRQ 77 sdhci-pltfm: SDHCI platform and OF driver helper usbcore: registered new interface driver usbhid usbhid: USB HID core driver TCP cubic registered Initializing XFRM netlink socket NET: Registered protocol family 17 VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5 Freeing init memory: 3700K mmc0: problem reading SD Status register. Indeed it is in host mode hprt0 = 00021501 mmc0: new high speed SDHC card at address e624 mmcblk0: mmc0:e624 SU04G 3.69 GiB mmcblk0: p1 udevd[42]: starting version 182 usb 1-1: new high-speed USB device number 2 using dwc_otg Indeed it is in host mode hprt0 = 00001101 usb 1-1: New USB device found, idVendor=0424, idProduct=9512 usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 hub 1-1:1.0: USB hub found hub 1-1:1.0: 3 ports detected usb 1-1.1: new high-speed USB device number 3 using dwc_otg usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00 usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 smsc95xx v1.0.4 smsc95xx 1-1.1:1.0: eth0: register 'smsc95xx' at usb-bcm2708_usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:07:82:fa smsc95xx 1-1.1:1.0: eth0: link up, 100Mbps, full-duplex, lpa 0x45E1 Please press Enter to activate this console. sh-4.2# |
Os testes acima foram feitos com a distribuição raspbmc. O bootloader não emite nenhuma mensagem na console, por isso só vemos as mensagens a partir do boot do kernel.
No próximo post, vamos estudar o processo de boot da Raspberry Pi. Até lá!
Um abraço,
Sergio Prado