Console UART Functionality of the SAMA5D2 Series Arm® Cortex®-A5 Microprocessor Unit (MPU) in the Linux® Kernel

Last modified by Microchip on 2024/06/20 12:43

Introduction

This training topic shows how to configure the Console Universal Asynchronous Receiver Transmitter (UART) functionality of the SAMA5D2 Series Arm® Cortex®-A5 Microprocessor Unit (MPU) in the Linux® kernel.

The default Console UART configuration for the ATSAMA5D27-SOM1-EK1 is UART1, which is connected to the J-LINK-OB microprocessor U4, which in turn provides a Serial-to-USB conversion to the micro-USB connector J10. In this topic, you will switch the Console UART from UART1 to UART2 and access the Console UART from the mikroBUS™ 2 expansion socket.

Recall that the Boot Process for the SAMA5D2 Series MPUs follows the order of:

  1. ROM Boot Code
  2. at91bootstrap
  3. u-boot-at91
  4. linux-at91

Each of the steps has configuration information that points it to the specified Console UART. In order to switch the Console UART from UART1 to UART2, you will have to alter the default configuration files and Device Trees. We show you how in this training topic.


Prerequisites

This application is developed for the ATSAMA5D27-SOM1-EK1 development platform:

This application is developed using the Buildroot build system.


Hardware

For this application, you will be switching the console UART from UART1 to UART2 on the ATSAMA5D27-SOM1-EK1 Evaluation Kit.

UART1

The ATSAMA5D27 SOM1 contains five UART peripherals to provide two-pin serial communications. By default, the console UART is configured to UART1 which connects to the U4 J-Link-OB microcontroller and the J10 micro-USB connector. The U4 J-Link-OB provides an onboard Serial-to-USB converter.

The figures below show the debugging capabilities of the SOM1-EK1 and a snippet of the schematic diagram of UART1.

Debugging features of the ATSAMA5D27-SOM1-EK1

Schematic NameUART1Package Pin
DBUG_RXDURXD1PD2
DBUG_TXDUTXD1PD3

Schematic of UART1

UART2 on mikroBUS

You will control the UART2 peripheral from the ATSAMA5D27 SOM1 on the mikroBUS 2 expansion socket.

The figures below show the expansion capability of the SOM1-EK1 and a snippet of the schematic for the mikroBUS 2 connectors.

Expansion features of the ATSAMA5D27-SOM1-EK1

mikroBUS 2 pinSchematic NameUART2Package Pin
J30 pin 3RX_mBUS2URXD2PD23
J30 pin 4TX_mBUS2UTXD2PD24

​For more details on the Package and Pinout of the SAMA5D2, refer to “Table 6-2. Pinouts” in SAMA5D2 Series Datasheet.

mikroBUS 2

Schematic of mikrobus socket 2 on the ATSAMA5D27-SOM1-EK1


Buildroot Configuration

Objective: Using Buildroot, build a bootable image and Flash it onto an SD memory card for the ATSAMA5D27-SOM1-EK1 development board.

Follow the steps for building the image on the "Buildroot - Create Project with Default Configurationpage. In the topic, you will use the default configuration file: atmel_sama5d27_som1_ek_mmc_dev_defconfig

In order to switch the Console UART from UART1 to UART2, changes are required for each of the stages of the Boot Process. We show you below the changes you will need to make.


at91bootstrap3

Objective: Change the Debug Unit (DBGU) Settings in the file: buildroot-at91/output/build/at91bootstrap3-v3.8.12/board/sama5d27_som1_ek/sama5d27_som1_ek.h

/*
 * DBGU Settings
 */
#define USART_BASE  AT91C_BASE_UART2
#define CONFIG_SYS_DBGU_RXD_PIN  AT91C_PIN_PD(23)
#define CONFIG_SYS_DBGU_TXD_PIN  AT91C_PIN_PD(24)
#define CONFIG_SYS_DBGU_ID  AT91C_ID_UART2

u-boot-at91

Objective: Change the following definitions in the file: buildroot-at91/output/build/uboot-linux4sam_6.0/arch/arm/dts/at91-sama5d27_som1_ek.dts

52    chosen {
53        u-boot,dm-pre-reloc;
54        stdout-path = &uart2;
55    };
.
.
124   uart2: serial@f8024000 {
125       pinctrl-names = "default";
126       pinctrl-0 = <&pinctrl_uart2_default>;
127       status = "okay";
128       u-boot,dm-pre-reloc;
129   };
.
.
207   pinctrl_uart2_default: uart2_default {
208       pinmux = <PIN_PD23__URXD2>,
209                <PIN_PD24__UTXD2>;
210       bias-disable;
211       u-boot,dm-pre-reloc;
212   };

Line 54 change the stdout-path from uart1 to uart2.

Line 124 change definitions from uart1 to uart2.

Line 127 enable uart2.

Line 207 change definitions from uart1 to uart2.

Objective: Add the following lines of code in the file: buildroot-at91/output/build/uboot-linux4sam_6.0/board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c

38    #ifdef CONFIG_DEBUG_UART_BOARD_INIT
39    static void board_uart1_hw_init(void)
40    {
41        atmel_pio4_set_a_periph(AT91_PIO_PORTD, 2, ATMEL_PIO_PUEN_MASK);  /* URXD1 */
42        atmel_pio4_set_a_periph(AT91_PIO_PORTD, 3, 0);  /* UTXD1 */
43
44        at91_periph_clk_enable(ATMEL_ID_UART1);
45    }
46
46a      static void board_uart2_hw_init(void)
46b      {
46c          atmel_pio4_set_a_periph(AT91_PIO_PORTD, 23, ATMEL_PIO_PUEN_MASK); /* URXD2 */
46d          atmel_pio4_set_a_periph(AT91_PIO_PORTD, 24, 0); /* UTXD2 */
46e
46f          at91_periph_clk_enable(ATMEL_ID_UART2);
46g      }
46h
47    void board_debug_uart_init(void)
48    {
49        board_uart2_hw_init();
50    }
51    #endif

Lines 46a through 46h add the following lines of code to initialize uart2 hardware.

Line 49 change uart1 to uart2 to call the initialization of the uart2 hardware.

Objective: Change the following definitions in the file: buildroot-at91/output/build/uboot-linux4sam_6.0/configs/sama5d27_som1_ek_mmc_defconfig

14    CONFIG_DEBUG_UART_BASE=0xf8024000
.
.
26    CONFIG_BOOTARGS="console=ttyS2,115200 earlyprintk root=/dev/mmcblk0p2 rw rootwait"

Line 14 change CONFIG_DEBUG_UART_BASE from 0xf8020000 to 0xf8024000.

Line 26 change CONFIG_BOOTARGS console from ttyS0 to ttyS2


Kernel

The Buildroot default configuration file: atmel_sama5d27_som1_ek_mmc_dev_defconfig has UART2 enabled in the Linux Kernel. Therefore, there are no changes required in the kernel.

Objective: Observe the UART2 definitions in the file: buildroot-at91/output/build/uboot-linux4sam_6.0/arch/arm/dts/at91-sama5d27_som1_ek.dts

56    aliases {
57       serial0 = &uart1; /* DBGU */
58       serial1 = &uart4; /* mikro BUS 1 */
59       serial2 = &uart2; /* mikro BUS 2 */
60       i2c1  = &i2c1;
61       i2c2  = &i2c2;
62    };
.
.
165   uart2: serial@f8024000 {
166      pinctrl-names = "default";
167      pinctrl-0 = <&pinctrl_mikrobus2_uart>;
168      atmel,use-dma-rx;
169      atmel,use-dma-tx;
170      status = "okay";
171   };
.
.
516   pinctrl_mikrobus2_uart: mikrobus2_uart {
517      pinmux = <PIN_PD23__URXD2>,
518               <PIN_PD24__UTXD2>;
519      bias-disable;
520   };

Line 59 shows the alias of uart2 is serial2; uart2 will be registered as ttyS2.

Line 170 shows uart2 was enabled with the default setting

Line 517 shows PD23 and PD24 were selected for uart2 on mikroBUS 2.


RomBOOT

The console UART can be changed during RomBOOT. Refer to "Section 16", "Standard Boot Strategies" in the SAMA5D2 Series Datasheet (DS60001476). The Boot Configuration Word UART_CONSOLE bits select the pins and UART interface used for the console.

A listing of UARTs and IOSETs configurable for the Console

 The Boot Configuration Word is very important for MPU booting. Before modifying it, make sure you are familiar with "Section 16", and "Standard Boot Strategies" in the SAMA5D2 Series Datasheet (DS60001476) and understand the relationship between Fuses and Backup Registers (BUREG).

The Boot Configuration Word can be updated by SAM-BA® In-System Programmer (ISP). Here is a command example:

$ sudo ./sam-ba -p usb -d sama5d2 -a bootconfig -c writecfg:bscr:valid,bureg0 -c writecfg:bureg0:UART2_IOSET2

Connection

For the Hands-On portion of this topic, connect a Serial-to-USB converter (TTL level) to UART2 on the mikroBUS 2 expansion slot to your PC.

mikroBUS 2 pinSchematic NameSerial-to-USB Adapter
J30 pin 3RX_mBUS2TXD
J30 pin 4TX_mBUS2RXD

 Photo showing serial-to-usb adapter connected to mBUS2


Hands-On

Run your favorite terminal emulation program on your PC to view the booting sequence on the newly assigned console UART.

Screen capture of Console window showing boot up on UART2


Summary

In this topic, you reconfigured the Console UART to UART2 in the at91bootstrap3, u-boot-at91, and kernel. You viewed the system boot-up while connected to UART2 on the mikroBUS 2 expansion slot.