LAN969x USART

1. LAN969x USART

1.1. SoC Resources

LAN969X SoC have 4 FLEXCOMs (Flexible Serial Communication Controller). In order to use flexcom USART interface, a specific flexcom should be configured in USART mode.

1.2. Kernel configurations

Following kernel config options should be enabled to use LAN969x flexcom USART interface:

  • CONFIG_MFD_AT91_USART - USART driver config option.

1.3. Devicetree Configuration

To use Flexcom USART interface, following configurations are required in device tree.

  • Each of the flexcom flx0, flx1, flx2 and flx3 nodes can be configured in USART mode ATMEL_FLEXCOM_MODE_USART to use USART interface.

  • compatible string must be set to atmel,at91sam9260-usart.

  • reg property must be set with register address and length as <0x200 0x200>.

  • GPIO pins for TXD and RXD pins should be configured to pinctrl-0 property. Also add cts and rts pins, if present. List of possible TXD and RXD pin mappings are as in below table:

FLEXCOM ID ALT Mode RXD pin TXD pin

flx0

ALT 2

GPIO3

GPIO4

flx2

ALT 3

GPIO15

GPIO16

flx1

ALT 2

GPIO28

GPIO29

flx3

ALT 2

GPIO55

GPIO56

flx2

ALT 1

GPIO65

GPIO66

  • interrupts property must set with interrupt details. Interrupt number[CPU INTR] corresponding to a flexcom must be configured as defined in below table:

FLEXCOM ID Shared Peripheral Interrupt CPU INTR

flx0

78

46

flx1

79

47

flx2

80

48

flx3

81

49

Note that Shared peripheral interrupt lines start at index ID32. So, CPU INTR must be calculated as [Shared peripheral interrupt number - 32].

  • Input clock clocks property must be set to &fabric_clk. Note that Fabric clock (250Mhz) is clock used by AXI, AHB fabric and APB bridges which connects all peripherals. clock-names must be set to usart.

  • GPIO flexcom shared pins should be configured as per board design.

  • dmas must be set to phandle dma0 and Peripheral ID as listed below:

FLEXCOM ID Tx channel PerID Rx channel PerID

flx0

3

2

flx1

3

2

flx2

7

6

flx3

9

8

1.3.2. Example

Following example shows how a flexcom USART should be defined in a EVB-LAN9696-24port DT. Here Flexcom0 is used as the console.

/ {
	model = "lan969x ev23x71a (pcb8398)";
	aliases {
		serial0 = &usart0;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

&flx0 {
	atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_USART>;
	status = "okay";

	usart0: serial@200 {
		pinctrl-0 = <&fc0_pins>;
		pinctrl-names = "default";
		status = "okay";
	};
};

&flx2 {
	atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_SPI>;
	status = "okay";

	spi2: spi@400 {
		pinctrl-0 = <&fc2_pins>;
		pinctrl-names = "default";
		cs-gpios = <&gpio 63 GPIO_ACTIVE_LOW>;
		status = "okay";

		spi@0 {
			compatible = "mchp,synce_dpll";
			reg = <0>;
			spi-max-frequency = <8000000>;
		};
	};
};

&flx3 {
	atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_TWI>;
	status = "okay";

	i2c3: i2c@600 {
		pinctrl-0 = <&fc3_pins>;
		pinctrl-names = "default";
		i2c-analog-filter;
		i2c-digital-filter;
		i2c-digital-filter-width-ns = <35>;
		i2c-sda-hold-time-ns = <1500>;
		status = "okay";
	};
};

&gpio {
	fc0_pins: fc0-pins {
		pins = "GPIO_3", "GPIO_4";
		function = "fc";
	};

	fc2_pins: fc2-pins {
		pins = "GPIO_64", "GPIO_65", "GPIO_66";
		function = "fc";
	};

	fc3_pins: fc3-pins {
		pins = "GPIO_55", "GPIO_56";
		function = "fc";
	};
};

1.4. UserSpace

1.4.1. Confirm instances are created

  • Check if a tty device is created in /dev/ directory. This can be also be verified by executing dmesg | tail (on host PC) once the board is powered-up.

  • Connect to console using minicom -s /dev/ttyACM0

1.4.2. Example on how to use

Following demonstrates above DT flexcom examples on EVB-LAN9696-24port board:

1.4.2.1. FLEXCOM USART as console

In order to use flexcom0 USART as console, add console=ttyAT0,115200n8 to uboot bootargs environment variable and pass it to the kernel, then this usart will become the console.

First identify and connect to /dev/ttyACMx (Here x is port number) on Host machine. For Linux users, minicom application can be used to connect to console.

# dmesg | tail
[1124607.685978] usb 1-6.1.4: USB disconnect, device number 27
[1124610.736013] usb 1-6.1.4: new full-speed USB device number 122 using xhci_hcd
[1124610.852447] usb 1-6.1.4: New USB device found, idVendor=04d8, idProduct=00df, bcdDevice= 1.01
[1124610.852451] usb 1-6.1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[1124610.852452] usb 1-6.1.4: Product: MCP2200 USB Serial Port Emulator
[1124610.852453] usb 1-6.1.4: Manufacturer: Microchip Technology Inc.
[1124610.852454] usb 1-6.1.4: SerialNumber: 0013263668
[1124610.866007] cdc_acm 1-6.1.4:1.0: ttyACM1: USB ACM device
[1124610.867021] hid-generic 0003:04D8:00DF.0012: hiddev1,hidraw2: USB HID v1.11 Device [Microchip Technology Inc. MCP2200 USB Serial Port Emulator] on usb-0000:00:14.0-6.1.4/input2
[1124613.768165] usb 1-4.1: reset high-speed USB device number 118 using xhci_hcd
#
# minicom -s /dev/ttyACM1
U-Boot 2023.04 (Nov 07 2023 - 14:41:53 +0100)

CPU:   ARM A53
Model: lan969x ev23x71a (pcb8398)
DRAM:  896 MiB (effective 897.9 MiB)
Core:  27 devices, 16 uclasses, devicetree: fit
MMC:   emmc@e0830000: 0
Loading Environment from SPIFlash... SF: Detected sst26wf016 with page size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial
Out:   serial
Err:   serial
Net:   eth0: switch@0
Hit any key to stop autoboot:  0
7168283 bytes read in 163 ms (41.9 MiB/s)
Working FDT set to 64000000
## Loading kernel from FIT Image at 64000000 ...
   Using 'lan9698_ev23x71a_0_at_lan969x' configuration
   Trying 'kernel' kernel subimage
     Description:  Kernel
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0x640000c8
     Data Size:    6976499 Bytes = 6.7 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: 0x60000000
     Entry Point:  0x60000000
   Verifying Hash Integrity ... OK
## Loading fdt from FIT Image at 64000000 ...
   Using 'lan9698_ev23x71a_0_at_lan969x' configuration
   Trying 'fdt_lan9698_ev23x71a_0_at_lan969x' fdt subimage
     Description:  Flattened Device Tree
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x646cb5fc
     Data Size:    27258 Bytes = 26.6 KiB
     Architecture: AArch64
   Verifying Hash Integrity ... OK
   Booting using the fdt blob at 0x646cb5fc
Working FDT set to 646cb5fc
   Uncompressing Kernel Image
   Loading Device Tree to 0000000096b22000, end 0000000096b2ba79 ... OK
Working FDT set to 96b22000
   Loading Device Tree to 0000000096b15000, end 0000000096b21a79 ... OK
Working FDT set to 96b15000

Starting kernel ...

Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Seeding 256 bits and crediting
Saving 256 bits of creditable seed for next boot
Starting iptables: OK
Starting network: OK
Starting dropbear sshd: OK

Welcome to SMBStaX
vcoreiii login: root
#