RPi 3B: 关于kernel log输出 – 串口问题

对于RPi 3B来说,由于加入了Bluetooth模块,使得uart0/ttyAMA0默认情况下将与Bluetooth模块进行通信,默认情况下仍然是作为一个串口设备,在指定console=ttyAMA0,115200时,在开机过程中仍会输出串口log。但如果加载了bcm2710-rpi-3-b.dtb开机时,uart0所对应的GPIO14,15将不再作为uart0使用,而是作为uart1使用,所以你需要在kernel command中指定console=serial0,115200,即便如此,输出的串口log也有可能是乱码。

  • uart0/uart1引脚定义

相关的文档请看:http://elinux.org/RPi_Low-level_peripherals

Pin Number Pin Name Hardware Notes Alt 0 Function Other Alternative Functions
P1-06 GND
P1-08 GPIO 14 Boot to Alt 0 -> UART0_TXD ALT5 = UART1_TXD
P1-10 GPIO 15 Boot to Alt 0 -> UART0_RXD ALT5 = UART1_RXD

可见GPIO14/15引脚可以功能复用:既可以作为uart0的TX/RX,也可以作为uart1的TX/RX。

  • kernel中相关的uart定义

版本号选用的是rpi-4.1.y分支:

commit 20fe468af4bb40fec0f81753da4b20a8bfc259c9
Author: Phil Elwell <phil@raspberrypi.org>
Date:   Tue Mar 15 14:10:29 2016 +0000

    bcm2835-sdhost: Workaround for "slow" sectors
    
    Some cards have been seen to cause timeouts after certain sectors are
    read. This workaround enforces a minimum delay between the stop after
    reading one of those sectors and a subsequent data command.
    
    Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will
    not be penalised by this workaround.
    
    Signed-off-by: Phil Elwell <phil@raspberrypi.org>

文件arch/arm/boot/dts/bcm2710-rpi-3-b.dts中关于uart的相关定义如下:

&gpio {
    // ...
    uart0_pins: uart0_pins {
        brcm,pins = <32 33>;
        brcm,function = <7>; /* alt3=UART0 */
        brcm,pull = <0 2>;
    };

    uart1_pins: uart1_pins {
        brcm,pins = <14 15>;
        brcm,function = <2>; /* alt5=UART1 */
        brcm,pull = <0 2>;
    };
};
// ...
&uart0 {
    pinctrl-names = "default";
    pinctrl-0 = <&uart0_pins &bt_pins>;
    status = "okay";
};

&uart1 {
    pinctrl-names = "default";
    pinctrl-0 = <&uart1_pins>;
    status = "okay";
};

由此可见,uart0被bluetooth模块占用了。

  • 串口log乱码问题

由于串口的速率可能变为 ~70kb (11.5k * (250/400))。

为什么要这么做(https://github.com/RPi-Distro/repo/issues/22):

There are some inescapable facts:

1) uart1, like the sdhost interface, uses the core clock. If the core clock changes then the baud rate will change.

2) Bluetooth uses uart0 because it has larger FIFOs and because it is immune to changes in core clock.

You can reduce clock rate fluctuations using force_turbo=1, but there is still the possibility of an enforced clock rate reduction because of an over-temperature situation. Between 80C and 85C the ARM overclock is disabled, then at 85C all other clocks (core, sdram, v3d, isp, h264) are also reduced to minimum.

It may be possible to ameliorate the issue by automatically reprogramming the uart clock divisor when the core clock changes, but that will depend on there being a suitable ratio between the overclock and the minimum. Therefore the only way to be sure that the baud rate doesn’t ever change is to set core_freq to minimum to start with, which is 250MHz.

Setting core_freq to 250MHz does not limit the ARMs to 600MHz. Those clocks are all independent.

The main clocks are controlled by the config.txt settings arm_freq, core_freq, sdram_freq, v3d_freq, isp_freq and h264_freq. gpu_freq is an alias for the non-ARM clocks that haven’t been set explicitly. Until the most recent firmware there was an oversight that meant that setting core_freq implicitly by setting gpu_freq wasn’t being communicated to the Linux world, causing incorrect baud rates. The latest rpi-update firmware fixes that issue, but you can avoid it by using core_freq instead of gpu_freq.

如何解决这个问题:

a. 在config.txt中设置core_freq=250可以解决这个问题,但同时会降低CPU的频率,从而降低系统性能。

b. 禁用BT模块: https://github.com/raspberrypi/firmware/commit/845eb064cb52af00f2ea33c0c9c54136f664a3e4

  • 相关的参考文档:
  1. http://elinux.org/RPi_Serial_Connection
  2. https://github.com/RPi-Distro/repo/issues/22
  3. https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=138162
  4. https://frillip.com/raspberry-pi-3-uart-baud-rate-workaround/

发表评论

电子邮件地址不会被公开。 必填项已用*标注