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>
This commit is contained in:
Anton Staaf
2014-11-10 11:31:29 -08:00
committed by chrome-internal-fetch
parent 8e25d9e1fc
commit 48b8c34aed
5 changed files with 51 additions and 10 deletions

View File

@@ -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);

View File

@@ -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
};

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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