mk2

package
v0.0.0-...-da58827 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2024 License: BSD-3-Clause Imports: 11 Imported by: 8

Documentation

Overview

Package mk2 provides hardware initialization, automatically on import, for the USB armory Mk II single board computer.

This package is only meant to be used with `GOOS=tamago GOARCH=arm` as supported by the TamaGo framework for bare metal Go on ARM SoCs, see https://github.com/usbarmory/tamago.

Index

Constants

View Source
const (
	// BT_UART_TX (UART1_TX_DATA)
	IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA = 0x020e0084
	IOMUXC_SW_PAD_CTL_PAD_UART1_TX_DATA = 0x020e0310

	// BT_UART_RX (UART1_RX_DATA)
	IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA = 0x020e0088
	IOMUXC_SW_PAD_CTL_PAD_UART1_RX_DATA = 0x020e0314
	IOMUXC_UART1_RX_DATA_SELECT_INPUT   = 0x020e0624
	DAISY_UART1_RX_DATA                 = 0b11

	// BT_UART_CTS (UART1_CTS_B)
	IOMUXC_SW_MUX_CTL_PAD_UART1_CTS_B = 0x020e008c
	IOMUXC_SW_PAD_CTL_PAD_UART1_CTS_B = 0x020e0318

	// BT_UART_RTS (UART1_RTS_B)
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO07 = 0x020e0078
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO07 = 0x020e0304
	IOMUXC_UART1_RTS_B_SELECT_INPUT  = 0x020e0620
	UART1_RTS_B_MODE                 = 8
	DAISY_GPIO1_IO07                 = 0b01

	// BT_UART_DSR (GPIO1_IO24)
	IOMUXC_SW_MUX_CTL_PAD_UART3_TX_DATA = 0x020e00a4
	IOMUXC_SW_PAD_CTL_PAD_UART3_TX_DATA = 0x020e0330

	// BT_UART_DTR (GPIO1_IO25)
	IOMUXC_SW_MUX_CTL_PAD_UART3_RX_DATA = 0x020e00a8
	IOMUXC_SW_PAD_CTL_PAD_UART3_RX_DATA = 0x020e0334

	// BT_SWDCLK
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO04 = 0x020e006c
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO04 = 0x020e02f8

	// BT_SWDIO
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO06 = 0x020e0074
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO06 = 0x020e0300

	// BT_RESET
	BT_RESET                         = 9
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO09 = 0x020e0080
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO09 = 0x020e030c

	// BT_SWITCH_1 (GPIO1_IO27)
	BT_SWITCH_1                       = 27
	IOMUXC_SW_MUX_CTL_PAD_UART3_RTS_B = 0x020e00b0
	IOMUXC_SW_PAD_CTL_PAD_UART3_RTS_B = 0x020e033c

	// BT_SWITCH_2 (GPIO1_IO26)
	BT_SWITCH_2                       = 26
	IOMUXC_SW_MUX_CTL_PAD_UART3_CTS_B = 0x020e00ac
	IOMUXC_SW_PAD_CTL_PAD_UART3_CTS_B = 0x020e0338

	DEFAULT_MODE = 0
	GPIO_MODE    = 5

	RESET_GRACE_TIME = 1 * time.Second
)

BLE module configuration constants.

On models UA-MKII-β and UA-MKII-γ a u-blox ANNA-B112 Bluetooth module is connected to UART1.

On the USB armory Mk II β revision, due to an errata, the RTS/CTS signals are connected inverted on the Bluetooth module side. This is automatically handled with a workaround by the RTS() and CTS() functions, which use the lines as GPIOs to invert their direction.

View Source
const (
	// ENET2 MUX
	IOMUXC_SW_MUX_CTL_PAD_ENET2_RX_DATA0 = 0x020e00e4
	IOMUXC_SW_MUX_CTL_PAD_ENET2_RX_DATA1 = 0x020e00e8
	IOMUXC_SW_MUX_CTL_PAD_ENET2_RX_EN    = 0x020e00ec
	IOMUXC_SW_MUX_CTL_PAD_ENET2_TX_DATA0 = 0x020e00f0
	IOMUXC_SW_MUX_CTL_PAD_ENET2_TX_DATA1 = 0x020e00f4
	IOMUXC_SW_MUX_CTL_PAD_ENET2_TX_EN    = 0x020e00f8
	IOMUXC_SW_MUX_CTL_PAD_ENET2_TX_CLK   = 0x020e00fc
	IOMUXC_SW_MUX_CTL_PAD_ENET2_RX_ER    = 0x020e0100

	// ENET2 PAD
	IOMUXC_SW_PAD_CTL_PAD_ENET2_RX_DATA0 = 0x020e0370
	IOMUXC_SW_PAD_CTL_PAD_ENET2_RX_DATA1 = 0x020e0374
	IOMUXC_SW_PAD_CTL_PAD_ENET2_RX_EN    = 0x020e0378
	IOMUXC_SW_PAD_CTL_PAD_ENET2_TX_DATA0 = 0x020e037c
	IOMUXC_SW_PAD_CTL_PAD_ENET2_TX_DATA1 = 0x020e0380
	IOMUXC_SW_PAD_CTL_PAD_ENET2_TX_EN    = 0x020e0384
	IOMUXC_SW_PAD_CTL_PAD_ENET2_TX_CLK   = 0x020e0388
	IOMUXC_SW_PAD_CTL_PAD_ENET2_RX_ER    = 0x020e038c

	// ENET2 SELECT INPUT
	IOMUXC_ENET2_REF_CLK2_SELECT_INPUT  = 0x020e057c
	IOMUXC_ENET2_MAC0_MDIO_SELECT_INPUT = 0x020e0580

	IOMUX_ALT0 = 0
	IOMUX_ALT1 = 1
	IOMUX_ALT4 = 4

	DAISY_ENET2_TX_CLK_ALT4     = 0b10
	DAISY_ENET2_GPIO1_IO06_ALT0 = 0
)

Ethernet PHY configuration constants.

On the UA-MKII-LAN the ENET2 MAC is connected to a DP83825I PHY, this board package configures it at 100 Mbps / Full-duplex mode.

View Source
const (
	PHY_ADDR = 0

	DP_CTRL     = 0x00
	CTRL_RESET  = 15
	CTRL_SPEED  = 13
	CTRL_ANEG   = 12
	CTRL_DUPLEX = 8

	DP_REGCR = 0xd
	DP_ADDAR = 0xe

	DP_RCSR      = 0x17
	RCSR_RMII_CS = 7
	RCSR_RX_BUF  = 0

	DP_LEDCR1           = 0x18
	LEDCR1_LINK_LED_DRV = 4
	LEDCR1_LINK_LED_OFF = 1

	DP_LEDCR2           = 0x469
	LEDCR2_LED2_DRV_VAL = 5
	LEDCR2_LED2_DRV_EN  = 4
)

DP83825I PHY registers

View Source
const (
	MMD_FN_ADDR = 0b00
	MMD_FN_DATA = 0b01
)

Table 22–9, MMD access control register bit definitions, 802.3-2008

View Source
const (
	// Power management controller
	PF1510_ADDR = 0x08
	// Cryptographic co-processor (UA-MKII-γ, UA-MKII-LAN)
	SE050_ADDR = 0x48
	// Cryptographic co-processor (UA-MKII-β)
	A71CH_ADDR = 0x48
	// Cryptographic co-processor (UA-MKII-β)
	ATECC_ADDR = 0x60
	// Type-C front port controller
	TUSB320_ADDR = 0x61
	// Type-C receptacle port controller (UA-MKII-β, UA-MKII-γ)
	FUSB303_ADDR = 0x31
)

The USB armory Mk II has the following components accessible as I²C targets.

View Source
const (
	// GPIO number
	WHITE = 21
	// mux control
	IOMUXC_SW_MUX_CTL_PAD_CSI_DATA00 = 0x020e01e4
	// pad control
	IOMUXC_SW_PAD_CTL_PAD_CSI_DATA00 = 0x020e0470

	// GPIO number
	BLUE = 22
	// mux control
	IOMUXC_SW_MUX_CTL_PAD_CSI_DATA01 = 0x020e01e8
	// pad control
	IOMUXC_SW_PAD_CTL_PAD_CSI_DATA01 = 0x020e0474
)

LED configuration constants

On the USB armory Mk II the following LEDs are connected:

  • pad CSI_DATA00, GPIO4_IO21: white
  • pad CSI_DATA01, GPIO4_IO22: blue

On the USB armory Mk II LAN the RJ45 connector LEDs can be controlled through the Ethernet PHY.

View Source
const (
	// USB armory Mk II (rev. β) - UA-MKII-β
	BETA = iota
	// USB armory Mk II (rev. γ) - UA-MKII-γ
	GAMMA
	// USB armory Mk II LAN - UA-MKII-LAN
	LAN
)

USB armory Mk II model revisions, WithSecure burns model information in the MSB of OTP fuses bank 4 word 2 (OCOTP_MAC0), returned by Model().

View Source
const (
	IOMUXC_SW_MUX_CTL_PAD_ENET1_TX_EN = 0x020e00d8
	IOMUXC_SW_PAD_CTL_PAD_ENET1_TX_EN = 0x020e0364

	WDOG2_WDOG_RST_B_DEB_MODE = 8
)

On the USB armory Mk II the PMIC watchdog input (WDI) is connected to the SoC external reset source (WDOG2_WDOG_RST_B_DEB) through ENET1_TX_EN/KPP_COL2 (p4081, Table 59-1. WDOG External Signals, IMX6ULLRM).

View Source
const (
	TUSB320_CSR_2      = 0x09
	CSR_ATTACHED_STATE = 6
)

Front USB port controller constants (plug: UA-MKII-β, UA-MKII-γ, receptacle: UA-MKII-LAN).

View Source
const (
	STATE_NOT_ATTACHED = iota
	STATE_ATTACHED_SRC
	STATE_ATTACHED_SNK
	STATE_ATTACHED_ACC
)

Front USB port controller modes (plug: UA-MKII-β, UA-MKII-γ, receptacle: UA-MKII-LAN).

View Source
const (
	FUSB303_CONTROL1 = 0x05
	CONTROL1_ENABLE  = 3

	FUSB303_TYPE = 0x13
)

Side receptacle USB port controller constants (UA-MKII-β, UA-MKII-γ)

View Source
const (
	TYPE_DEBUGSRC    = 1 << 6
	TYPE_DEBUGSNK    = 1 << 5
	TYPE_SINK        = 1 << 4
	TYPE_SOURCE      = 1 << 3
	TYPE_ACTIVECABLE = 1 << 2
	TYPE_AUDIOVBUS   = 1
	TYPE_AUDIO       = 0
)

Side receptacle USB port controller modes (UA-MKII-β, UA-MKII-γ)

View Source
const (
	IOMUXC_SW_MUX_CTL_PAD_CSI_DATA04 = 0x020e01f4
	IOMUXC_SW_PAD_CTL_PAD_CSI_DATA04 = 0x020e0480
	IOMUXC_USDHC1_WP_SELECT_INPUT    = 0x020e066c

	USDHC1_WP_MODE   = 8
	DAISY_CSI_DATA04 = 0b10

	IOMUXC_SW_MUX_CTL_PAD_CSI_PIXCLK = 0x020e01d8
	IOMUXC_SW_PAD_CTL_PAD_CSI_PIXCLK = 0x020e0464
	IOMUXC_USDHC2_WP_SELECT_INPUT    = 0x020e069c

	USDHC2_WP_MODE   = 1
	DAISY_CSI_PIXCLK = 0b10

	SD_BUS_WIDTH  = 4
	MMC_BUS_WIDTH = 8

	PF1510_LDO3_VOLT = 0x52
	LDO3_VOLT_1V8    = 0x10
	LDO3_VOLT_3V3    = 0x1f
)

SD/MMC configuration constants.

On the USB armory Mk II the following uSDHC interfaces are connected:

  • uSDHC1: external uSD slot (SD1, only on UA-MKII-β and UA-MKII-γ models)
  • uSDHC2: internal eMMC card (SD2/NAND)

On the USB armory Mk II β revision the maximum achievable theoretical speed modes are:

  • uSD: High Speed (HS) 25MB/s, 50MHz, 3.3V, 4-bit data bus
  • eMMC: High Speed (HS) DDR 104MB/s, 52MHz, 3.3V, 8-bit data bus

On the USB armory Mk II γ revision and LAN version (eMMC only) the maximum achievable theoretical speed modes are:

  • uSD: SDR104 75MB/s, 150MHz, 1.8V, 4-bit data bus
  • eMMC: HS200 150MB/s, 150MHz, 1.8V, 8-bit data bus

Variables

View Source
var (
	ENET2 = imx6ul.ENET2

	I2C1 = imx6ul.I2C1
	I2C2 = imx6ul.I2C2

	UART1 = imx6ul.UART1
	UART2 = imx6ul.UART2

	USB1 = imx6ul.USB1
	USB2 = imx6ul.USB2

	USDHC1 = imx6ul.USDHC1
	USDHC2 = imx6ul.USDHC2
)

Peripheral instances

View Source
var BLE = &ANNA{}

BLE module instance

View Source
var MMC = USDHC2

MMC instance

View Source
var SD = USDHC1

SD instance (UA-MKII-β, UA-MKII-γ)

Functions

func DetectDebugAccessory

func DetectDebugAccessory(timeout time.Duration) (<-chan bool, error)

DetectDebugAccessory enables debug accessory detection on the side receptacle USB port controller and polls successful detection (typically done in up to 200ms).

An error is returned if no debug accessory is detected within the timeout.

On the returned boolean channel are sent successful detection (true) or timeout (false).

func EnableDebugAccessory

func EnableDebugAccessory() (err error)

EnableDebugAccessory enables debug accessory detection on the side receptacle USB port controller.

A debug accessory allows access, among all other debug signals, to the UART2 serial console.

Note that there is a delay (typically up to 200ms) between the return of this call and the actual enabling of the debug accessory, for this reason the serial console is not immediately available.

To wait detection of a debug accessory use DetectDebugAccessory() instead.

func EnablePHY

func EnablePHY(eth *enet.ENET) error

func EnableReceptacleController

func EnableReceptacleController() (err error)

EnableReceptacleController activates the side receptacle USB port controller.

func FrontPortMode

func FrontPortMode() (mode int, err error)

FrontPortMode returns the type of attached device detected by the front USB port controller.

func Init

func Init()

Init takes care of the lower level SoC initialization triggered early in runtime setup.

func LED

func LED(name string, on bool) (err error)

LED turns on/off an LED by name.

func Model

func Model() (m uint32, s string)

Model returns the USB armory model name, to further detect SoC variants imx6ul.Model() can be used.

func ReceptacleMode

func ReceptacleMode() (mode int, err error)

ReceptacleMode returns the type of device or accessory detected by the side receptacle USB port controller.

func Reset

func Reset()

Reset asserts the PMIC watchdog signal (through the SoC external reset source) causing the USB armory Mk II board to power cycle (cold reset).

Types

type ANNA

type ANNA struct {
	sync.Mutex

	UART *uart.UART
	// contains filtered or unexported fields
}

ANNA implements the interface to the ANNA-B112 module for serial communication, reset and mode select.

func (*ANNA) BootloaderMode

func (ble *ANNA) BootloaderMode() (err error)

Enter bootloader mode by driving low SWITCH_1 and SWITCH_2 during a module reset cycle.

func (*ANNA) CTS

func (ble *ANNA) CTS(clear bool)

CTS signals the BLE module whether it is allowed to send or not data, only useful on β boards when a workaround to the RTS/CTS errata is required.

func (*ANNA) Init

func (ble *ANNA) Init() (err error)

Init initializes, in normal mode, a BLE module instance.

func (*ANNA) NormalMode

func (ble *ANNA) NormalMode() (err error)

Enter normal mode by driving high SWITCH_1 and SWITCH_2 during a module reset cycle.

func (*ANNA) RTS

func (ble *ANNA) RTS() (ready bool)

RTS returns whether the BLE module allows to send or not data, only useful on β boards when a workaround to the RTS/CTS errata is required.

func (*ANNA) Reset

func (ble *ANNA) Reset() (err error)

Reset the BLE module by toggling the RESET_N pin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL