summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2014-11-10 11:31:29 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-13 03:14:37 +0000
commit48b8c34aedd018ff603f00c1daa97a382bd7055e (patch)
treee3da23aaf9bf1408c83d4db93670942aa17f6c4e
parent8e25d9e1fc4e23c8f379dac8bd9fbdbf09b602c3 (diff)
downloadchrome-ec-48b8c34aedd018ff603f00c1daa97a382bd7055e.tar.gz
ryu: Enable PD/EC console over USB
This enables forwarding of the local PD/EC console over debug USB. It gates the console functionality based on the CCD mode that is set. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Enable partial CCD mode on ryu and verify that it is enumerated by the host correctly, but doesn't respond to console input, and doesn't generate output. Enable full CCD mode on ryu and verify that it is enumerated and that the console works as expected. Verify that the console still works by default on the discovery-stm32f072 board. Change-Id: I0325ce9689486c41387d6075330be1d7d42f1d42 Reviewed-on: https://chromium-review.googlesource.com/229342 Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org>
-rw-r--r--board/ryu/board.c9
-rw-r--r--board/ryu/board.h10
-rw-r--r--chip/stm32/usb_console.c12
-rw-r--r--common/case_closed_debug.c19
-rw-r--r--include/usb_console.h11
5 files changed, 51 insertions, 10 deletions
diff --git a/board/ryu/board.c b/board/ryu/board.c
index 65019c4d2d..fef69fe46a 100644
--- a/board/ryu/board.c
+++ b/board/ryu/board.c
@@ -43,10 +43,11 @@ void unhandled_evt(enum gpio_signal signal)
#include "gpio_list.h"
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("Ryu - Raiden debug"),
- [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
+ [USB_STR_DESC] = usb_string_desc,
+ [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
+ [USB_STR_PRODUCT] = USB_STRING_DESC("Ryu debug"),
+ [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
+ [USB_STR_CONSOLE_NAME] = USB_STRING_DESC("EC_PD"),
};
BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
diff --git a/board/ryu/board.h b/board/ryu/board.h
index 8c21e1b700..17d1796eaf 100644
--- a/board/ryu/board.h
+++ b/board/ryu/board.h
@@ -91,11 +91,16 @@
#define CONFIG_USB_INHIBIT_INIT
/* USB interface indexes (use define rather than enum to expand them) */
-#define USB_IFACE_COUNT 0
+#define USB_IFACE_CONSOLE 0
+#define USB_IFACE_COUNT 1
/* USB endpoint indexes (use define rather than enum to expand them) */
#define USB_EP_CONTROL 0
-#define USB_EP_COUNT 1
+#define USB_EP_CONSOLE 1
+#define USB_EP_COUNT 2
+
+/* Enable console over USB */
+#define CONFIG_USB_CONSOLE
/* Enable Case Closed Debugging */
#define CONFIG_CASE_CLOSED_DEBUG
@@ -133,6 +138,7 @@ enum usb_strings {
USB_STR_VENDOR,
USB_STR_PRODUCT,
USB_STR_VERSION,
+ USB_STR_CONSOLE_NAME,
USB_STR_COUNT
};
diff --git a/chip/stm32/usb_console.c b/chip/stm32/usb_console.c
index 1e3dc30fd4..cf7f6d7825 100644
--- a/chip/stm32/usb_console.c
+++ b/chip/stm32/usb_console.c
@@ -28,6 +28,7 @@ static volatile int rx_buf_tail;
static int last_tx_ok = 1;
static int is_reset;
+static int is_enabled = 1;
/* USB-Serial descriptors */
const struct usb_interface_descriptor USB_IFACE_DESC(USB_IFACE_CONSOLE) = {
@@ -128,6 +129,9 @@ static int __tx_char(void *context, int c)
static void usb_enable_tx(int len)
{
+ if (!is_enabled)
+ return;
+
btable_ep[USB_EP_CONSOLE].tx_count = len;
STM32_TOGGLE_EP(USB_EP_CONSOLE, EP_TX_MASK, EP_TX_VALID, 0);
}
@@ -182,6 +186,9 @@ int usb_getc(void)
if (rx_buf_tail == rx_buf_head)
return -1;
+ if (!is_enabled)
+ return -1;
+
c = rx_buf[rx_buf_tail];
rx_buf_tail = RX_BUF_NEXT(rx_buf_tail);
return c;
@@ -237,3 +244,8 @@ int usb_vprintf(const char *format, va_list args)
usb_enable_tx(tx_idx);
return ret;
}
+
+void usb_console_enable(int enabled)
+{
+ is_enabled = enabled;
+}
diff --git a/common/case_closed_debug.c b/common/case_closed_debug.c
index 08e5e8411d..270253b50e 100644
--- a/common/case_closed_debug.c
+++ b/common/case_closed_debug.c
@@ -9,15 +9,20 @@
#include "common.h"
#include "usb_api.h"
-
-#if !defined(CONFIG_USB_INHIBIT_INIT)
-#error "CONFIG_USB_INHIBIT_INIT must be defined to use Case Closed Debugging"
-#endif
+#include "usb_console.h"
#if !defined(CONFIG_USB)
#error "CONFIG_USB must be defined to use Case Closed Debugging"
#endif
+#if !defined(CONFIG_USB_CONSOLE)
+#error "CONFIG_USB_CONSOLE must be defined to use Case Closed Debugging"
+#endif
+
+#if !defined(CONFIG_USB_INHIBIT_INIT)
+#error "CONFIG_USB_INHIBIT_INIT must be defined to use Case Closed Debugging"
+#endif
+
static enum ccd_mode current_mode = CCD_MODE_DISABLED;
void ccd_set_mode(enum ccd_mode new_mode)
@@ -32,6 +37,12 @@ void ccd_set_mode(enum ccd_mode new_mode)
current_mode = new_mode;
+ /*
+ * Only enable forwarding the local console over USB if we are now in
+ * the fully enabled mode.
+ */
+ usb_console_enable(new_mode == CCD_MODE_ENABLED);
+
if (new_mode != CCD_MODE_DISABLED) {
ccd_board_connect();
usb_init();
diff --git a/include/usb_console.h b/include/usb_console.h
index 9666fa425a..18526cfd87 100644
--- a/include/usb_console.h
+++ b/include/usb_console.h
@@ -10,6 +10,8 @@
#ifdef CONFIG_USB_CONSOLE
+#include <stdarg.h>
+
/**
* Put a null-terminated string to the USB console, like fputs().
*
@@ -41,6 +43,15 @@ int usb_putc(int c);
*/
int usb_getc(void);
+/**
+ * Enable and Disable the USB console.
+ *
+ * By default the console is enabled, this should not be a problem since it
+ * is not accessible until the USB peripheral is also initialized, which can
+ * be delayed.
+ */
+void usb_console_enable(int enabled);
+
#define usb_va_start va_start
#define usb_va_end va_end
#else