summaryrefslogtreecommitdiff
path: root/board/fusb307bgevb
diff options
context:
space:
mode:
authorYun-chieh, Lee <lyunjie@google.com>2020-09-10 17:15:18 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-21 17:34:13 +0000
commitb7dc125ebb97fcc87ff606696f4fb5315b767c45 (patch)
treed02938a264020f1c5ac4ddd8b55a53201636c68f /board/fusb307bgevb
parentad51c9b74af8b2675916e64a38f45261eff67df6 (diff)
downloadchrome-ec-b7dc125ebb97fcc87ff606696f4fb5315b767c45.tar.gz
ucsa: initial board setup
USB-C Sink Advertiser. Implement TCPM (STM32F072CB) + TCPC (FUSB307B) with adding a display module and control buttons. So a user is able to select different voltage output from choosing different PDO within a comprehensive U/I shown by display. BUG=b:162057390 TEST=make buildall BRANCH=master Signed-off-by: Yun-Chieh Lee <lyunjie@google.com> Change-Id: I41d896f9c3c8fb96dd75d4c88cf1c0052eb488f5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2402844 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'board/fusb307bgevb')
-rw-r--r--board/fusb307bgevb/board.c181
-rw-r--r--board/fusb307bgevb/board.h92
-rw-r--r--board/fusb307bgevb/build.mk13
-rw-r--r--board/fusb307bgevb/ec.tasklist11
-rw-r--r--board/fusb307bgevb/gpio.inc31
5 files changed, 328 insertions, 0 deletions
diff --git a/board/fusb307bgevb/board.c b/board/fusb307bgevb/board.c
new file mode 100644
index 0000000000..71b2c445da
--- /dev/null
+++ b/board/fusb307bgevb/board.c
@@ -0,0 +1,181 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+/* FUSB307BGEVB configuration */
+
+#include "common.h"
+#include "ec_version.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "queue_policies.h"
+#include "registers.h"
+#include "task.h"
+#include "usart-stm32f0.h"
+#include "usart_tx_dma.h"
+#include "usart_rx_dma.h"
+#include "usb_gpio.h"
+#include "usb-stream.h"
+#include "util.h"
+#include "usb_mux.h"
+#include "usb_charge.h"
+#include "usb_common.h"
+#include "usb_pd_tcpm.h"
+#include "usb_pd.h"
+#include "charge_state.h"
+#include "tcpm.h"
+#include "i2c.h"
+#include "power.h"
+#include "power_button.h"
+#include "printf.h"
+#include "timer.h"
+
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+static void tcpc_alert_event(enum gpio_signal signal)
+{
+}
+
+/******************************************************************************
+ * Build GPIO tables and expose a subset of the GPIOs over USB.
+ */
+void button_event(enum gpio_signal signal);
+#include "gpio_list.h"
+
+static enum gpio_signal const usb_gpio_list[] = {
+ GPIO_USER_BUTTON_ENTER,
+ GPIO_USER_BUTTON_UP,
+ GPIO_USER_BUTTON_DOWN,
+};
+
+/*
+ * This instantiates struct usb_gpio_config const usb_gpio, plus several other
+ * variables, all named something beginning with usb_gpio_
+ */
+USB_GPIO_CONFIG(usb_gpio,
+ usb_gpio_list,
+ USB_IFACE_GPIO,
+ USB_EP_GPIO);
+
+/******************************************************************************
+ * Setup USART1 as a loopback device, it just echo's back anything sent to it.
+ */
+static struct usart_config const loopback_usart;
+
+static struct queue const loopback_queue =
+ QUEUE_DIRECT(64, uint8_t,
+ loopback_usart.producer,
+ loopback_usart.consumer);
+
+static struct usart_rx_dma const loopback_rx_dma =
+ USART_RX_DMA(STM32_DMAC_CH3, 8);
+
+static struct usart_tx_dma const loopback_tx_dma =
+ USART_TX_DMA(STM32_DMAC_CH2, 16);
+
+static struct usart_config const loopback_usart =
+ USART_CONFIG(usart1_hw,
+ loopback_rx_dma.usart_rx,
+ loopback_tx_dma.usart_tx,
+ 115200,
+ 0,
+ loopback_queue,
+ loopback_queue);
+
+/******************************************************************************
+ * Forward USART4 as a simple USB serial interface.
+ */
+static struct usart_config const forward_usart;
+struct usb_stream_config const forward_usb;
+
+static struct queue const usart_to_usb = QUEUE_DIRECT(64, uint8_t,
+ forward_usart.producer,
+ forward_usb.consumer);
+static struct queue const usb_to_usart = QUEUE_DIRECT(64, uint8_t,
+ forward_usb.producer,
+ forward_usart.consumer);
+
+static struct usart_tx_dma const forward_tx_dma =
+ USART_TX_DMA(STM32_DMAC_CH7, 16);
+
+static struct usart_config const forward_usart =
+ USART_CONFIG(usart4_hw,
+ usart_rx_interrupt,
+ forward_tx_dma.usart_tx,
+ 115200,
+ 0,
+ usart_to_usb,
+ usb_to_usart);
+
+#define USB_STREAM_RX_SIZE 16
+#define USB_STREAM_TX_SIZE 16
+
+USB_STREAM_CONFIG(forward_usb,
+ USB_IFACE_STREAM,
+ USB_STR_STREAM_NAME,
+ USB_EP_STREAM,
+ USB_STREAM_RX_SIZE,
+ USB_STREAM_TX_SIZE,
+ usb_to_usart,
+ usart_to_usb)
+
+/******************************************************************************
+ * Handle button presses by cycling the LEDs on the board. Also run a tick
+ * handler to cycle them when they are not actively under USB control.
+ */
+static enum gpio_signal button_signal;
+
+static void button_event_deferred(void)
+{
+}
+DECLARE_DEFERRED(button_event_deferred);
+
+void button_event(enum gpio_signal signal)
+{
+ button_signal = signal;
+ hook_call_deferred(&button_event_deferred_data, 100 * MSEC);
+}
+
+/******************************************************************************
+ * Define the strings used in our USB descriptors.
+ */
+const void *const usb_strings[] = {
+ [USB_STR_DESC] = usb_string_desc,
+ [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
+ [USB_STR_PRODUCT] = USB_STRING_DESC("fusb307bgevb"),
+ [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
+ [USB_STR_STREAM_NAME] = USB_STRING_DESC("Forward"),
+ [USB_STR_CONSOLE_NAME] = USB_STRING_DESC("Shell"),
+};
+
+BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
+
+/******************************************************************************
+ * I2C interface.
+ */
+const struct i2c_port_t i2c_ports[] = {
+ {"tcpc", I2C_PORT_TCPC, 400 /* kHz */, GPIO_I2C2_SCL, GPIO_I2C2_SDA}
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+/******************************************************************************
+ * Initialize board.
+ */
+static void board_init(void)
+{
+ /* Enable button interrupts */
+ gpio_enable_interrupt(GPIO_USER_BUTTON_ENTER);
+ gpio_enable_interrupt(GPIO_USER_BUTTON_UP);
+ gpio_enable_interrupt(GPIO_USER_BUTTON_DOWN);
+ /* Enable TCPC alert interrupts */
+ gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
+
+ queue_init(&loopback_queue);
+ queue_init(&usart_to_usb);
+ queue_init(&usb_to_usart);
+ usart_init(&loopback_usart);
+ usart_init(&forward_usart);
+
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/fusb307bgevb/board.h b/board/fusb307bgevb/board.h
new file mode 100644
index 0000000000..e920c7efd1
--- /dev/null
+++ b/board/fusb307bgevb/board.h
@@ -0,0 +1,92 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Fusb307bgevb configuration */
+
+#ifndef __CROS_EC_BOARD_H
+#define __CROS_EC_BOARD_H
+
+
+/* 48 MHz SYSCLK clock frequency */
+#define CPU_CLOCK 48000000
+
+/* Enable USART1,3,4 and USB streams */
+#define CONFIG_STREAM_USART
+#define CONFIG_STREAM_USART1
+#define CONFIG_STREAM_USART4
+#define CONFIG_STREAM_USB
+#define CONFIG_CMD_USART_INFO
+
+/* the UART console is on USART2 (PA14/PA15) */
+#undef CONFIG_UART_CONSOLE
+#define CONFIG_UART_CONSOLE 2
+
+/* Optional features */
+#define CONFIG_STM_HWTIMER32
+#define CONFIG_HW_CRC
+#define CONFIG_I2C
+#define CONFIG_I2C_MASTER
+
+/* USB Configuration */
+#define CONFIG_USB
+#define CONFIG_USB_PID 0x1234
+#define CONFIG_USB_CONSOLE
+
+/* I2C master port connected to the TCPC */
+#define I2C_PORT_TCPC 0
+
+/* LCD Configuration */
+#define LCD_SLAVE_ADDR 0x27
+
+/* USB interface indexes (use define rather than enum to expand them) */
+#define USB_IFACE_STREAM 0
+#define USB_IFACE_GPIO 1
+#define USB_IFACE_SPI 2
+#define USB_IFACE_CONSOLE 3
+#define USB_IFACE_COUNT 4
+
+/* USB endpoint indexes (use define rather than enum to expand them) */
+#define USB_EP_CONTROL 0
+#define USB_EP_STREAM 1
+#define USB_EP_GPIO 2
+#define USB_EP_SPI 3
+#define USB_EP_CONSOLE 4
+#define USB_EP_COUNT 5
+
+/* Enable control of GPIOs over USB */
+#define CONFIG_USB_GPIO
+
+#undef CONFIG_WATCHDOG_HELP
+#undef CONFIG_LID_SWITCH
+
+/*
+ * Allow dangerous commands all the time, since we don't have a write protect
+ * switch.
+ */
+#define CONFIG_SYSTEM_UNLOCKED
+
+#ifndef __ASSEMBLER__
+
+/* Timer selection */
+#define TIM_CLOCK32 2
+
+#include "gpio_signal.h"
+
+/* USB string indexes */
+enum usb_strings {
+ USB_STR_DESC = 0,
+ USB_STR_VENDOR,
+ USB_STR_PRODUCT,
+ USB_STR_VERSION,
+ USB_STR_STREAM_NAME,
+ USB_STR_CONSOLE_NAME,
+
+ USB_STR_COUNT
+};
+
+void board_reset_pd_mcu(void);
+
+#endif /* !__ASSEMBLER__ */
+#endif /* __CROS_EC_BOARD_H */
diff --git a/board/fusb307bgevb/build.mk b/board/fusb307bgevb/build.mk
new file mode 100644
index 0000000000..ce45995412
--- /dev/null
+++ b/board/fusb307bgevb/build.mk
@@ -0,0 +1,13 @@
+# -*- makefile -*-
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Board specific files build
+
+# the IC is STmicro STM32F072RBT6
+CHIP:=stm32
+CHIP_FAMILY:=stm32f0
+CHIP_VARIANT:=stm32f07x
+
+board-y=board.o
diff --git a/board/fusb307bgevb/ec.tasklist b/board/fusb307bgevb/ec.tasklist
new file mode 100644
index 0000000000..0c2a274a1f
--- /dev/null
+++ b/board/fusb307bgevb/ec.tasklist
@@ -0,0 +1,11 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TASK_LIST \
+ TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
+ TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE)
diff --git a/board/fusb307bgevb/gpio.inc b/board/fusb307bgevb/gpio.inc
new file mode 100644
index 0000000000..2aef4e3d2d
--- /dev/null
+++ b/board/fusb307bgevb/gpio.inc
@@ -0,0 +1,31 @@
+/* -*- mode:c -*-
+ *
+ * Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Declare symbolic names for all the GPIOs that we care about.
+ * Note: Those with interrupt handlers must be declared first. */
+
+GPIO_INT(USER_BUTTON_ENTER, PIN(A, 0), GPIO_INT_FALLING, button_event)
+GPIO_INT(USER_BUTTON_UP, PIN(A, 1), GPIO_INT_FALLING, button_event)
+GPIO_INT(USER_BUTTON_DOWN, PIN(A, 2), GPIO_INT_FALLING, button_event)
+GPIO_INT(USB_C0_PD_INT_ODL, PIN(A, 8), GPIO_INT_FALLING | GPIO_PULL_UP, tcpc_alert_event)
+
+/*
+ * I2C pins should be configured as inputs until I2C module is
+ * initialized. This will avoid driving the lines unintentionally.
+ */
+GPIO(I2C2_SCL, PIN(B, 10), GPIO_INPUT)
+GPIO(I2C2_SDA, PIN(B, 11), GPIO_INPUT)
+
+ALTERNATE(PIN_MASK(B, 0x0C00), 1, MODULE_I2C, GPIO_ODR_HIGH ) /* I2C MASTER: PB10/11 */
+
+/* Unimplemented signals which we need to emulate for now */
+UNIMPLEMENTED(ENTERING_RW)
+UNIMPLEMENTED(WP_L)
+
+ALTERNATE(PIN_MASK(A, 0x0600), 1, MODULE_USART, 0) /* USART1: PA09/PA10 */
+ALTERNATE(PIN_MASK(A, 0xC000), 1, MODULE_UART, 0) /* USART2: PA14/PA15 */
+ALTERNATE(PIN_MASK(C, 0x0C00), 0, MODULE_USART, 0) /* USART4: PC10/PC11 */