歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> U-Boot串口初始化詳解

U-Boot串口初始化詳解

日期:2017/3/1 10:26:00   编辑:Linux編程

目錄

零、概述
一、init_baudrate
二、serial_init
三、console_init_f
四、devices_init
五、console_init_r
六、打印信息
七、為什麼要使用devlist,std_device[]?

零、概述


上面這張圖是U-Boot中串口設備驅動的流程,從寄存器級別的設置到最後終端信息的輸出。下面我們詳細講解每一個步驟。

一、init_baudrate

該函數設置了gd->bd->bi_baudrate。

  1. static int init_baudrate (void)
  2. {
  3. char tmp[64]; /* long enough for environment variables */
  4. int i = getenv_r ("baudrate", tmp, sizeof (tmp));
  5. gd->bd->bi_baudrate = gd->baudrate = (i > 0)
  6. ? (int) simple_strtoul (tmp, NULL, 10)
  7. : CONFIG_BAUDRATE;
  8. //#define CONFIG_BAUDRATE 115200 定義在/include/configs/smdk2410.c中
  9. //如果環境中沒有保存,則使用宏定義的參數
  10. return (0);
  11. }

二、serial_init

UART控制器的初始化。

  1. void serial_setbrg (void)
  2. {
  3. S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);
  4. int i;
  5. unsigned int reg = 0;
  6. /* value is calculated so : (int)(PCLK/16./baudrate) -1 */
  7. reg = get_PCLK() / (16 * gd->baudrate) - 1;
  8. /* FIFO enable, Tx/Rx FIFO clear */
  9. uart->UFCON = 0x07;
  10. uart->UMCON = 0x0;
  11. /* Normal,No parity,1 stop,8 bit */
  12. uart->ULCON = 0x3;
  13. /*
  14. * tx=level,rx=edge,disable timeout int.,enable rx error int.,
  15. * normal,interrupt or polling
  16. */
  17. uart->UCON = 0x245;
  18. uart->UBRDIV = reg;
  19. #ifdef CONFIG_HWFLOW
  20. uart->UMCON = 0x1; /* RTS up */
  21. #endif
  22. for (i = 0; i < 100; i++);
  23. }
  24. /*
  25. * Initialise the serial port with the given baudrate. The settings
  26. * are always 8 data bits, no parity, 1 stop bit, no start bits.
  27. *
  28. */
  29. int serial_init (void)
  30. {
  31. serial_setbrg ();//UART寄存器設置
  32. return (0);
  33. }
Copyright © Linux教程網 All Rights Reserved