summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-10-16 10:58:47 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-10-19 13:45:49 -0700
commit4c8553dfb13d8046a32b833321826aade31a0264 (patch)
tree5fe32dcaa4d4884895cafd8237f93b79f2ce2a07
parent979440a583ad4e3de8b4c29e7a0861206eb271aa (diff)
downloadchrome-ec-4c8553dfb13d8046a32b833321826aade31a0264.tar.gz
stm32: add synchronous debug printf
Allow use of a synchronous debug printf instead of using the full console task to save space. This can be turned on with CONFIG_DEBUG_PRINTF, and will provide essentially a one-way console for debugging. This is essentially expanding upon the debug_printf work done for zinger. BUG=chrome-os-partner:41959 BRANCH=none TEST=tested with following CLs on glados_pd by verifying we get a one-way console. Change-Id: If028b5d873261890de5b270bbc00e06bdcaa7431 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/306782 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/zinger/board.c2
-rw-r--r--board/zinger/build.mk1
-rw-r--r--board/zinger/debug.c37
-rw-r--r--board/zinger/runtime.c2
-rw-r--r--board/zinger/usb_pd_policy.c2
-rw-r--r--chip/stm32/build.mk1
-rw-r--r--chip/stm32/debug_printf.c115
-rw-r--r--chip/stm32/debug_printf.h (renamed from board/zinger/debug.h)0
-rw-r--r--common/panic_output.c2
-rw-r--r--common/printf.c4
-rw-r--r--common/system.c6
-rw-r--r--common/uart_buffering.c4
12 files changed, 128 insertions, 48 deletions
diff --git a/board/zinger/board.c b/board/zinger/board.c
index ac3b95db20..bf4b51d5c7 100644
--- a/board/zinger/board.c
+++ b/board/zinger/board.c
@@ -5,7 +5,7 @@
/* Tiny charger configuration */
#include "common.h"
-#include "debug.h"
+#include "debug_printf.h"
#include "ec_commands.h"
#include "registers.h"
#include "rsa.h"
diff --git a/board/zinger/build.mk b/board/zinger/build.mk
index 4e9e2f1f6d..249f8a3e1b 100644
--- a/board/zinger/build.mk
+++ b/board/zinger/build.mk
@@ -11,4 +11,3 @@ CHIP_FAMILY:=stm32f0
CHIP_VARIANT:=stm32f03x
board-y=board.o hardware.o runtime.o usb_pd_policy.o
-board-$(CONFIG_DEBUG_PRINTF)+=debug.o
diff --git a/board/zinger/debug.c b/board/zinger/debug.c
deleted file mode 100644
index 48c2259083..0000000000
--- a/board/zinger/debug.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Copyright (c) 2014 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.
- */
-/* Synchronous UART debug printf */
-
-#include "common.h"
-#include "printf.h"
-#include "registers.h"
-#include "util.h"
-
-static int debug_txchar(void *context, int c)
-{
- if (c == '\n') {
- while (!(STM32_USART_SR(UARTN_BASE) & STM32_USART_SR_TXE))
- ;
- STM32_USART_TDR(UARTN_BASE) = '\r';
- }
-
- /* Wait for space to transmit */
- while (!(STM32_USART_SR(UARTN_BASE) & STM32_USART_SR_TXE))
- ;
- STM32_USART_TDR(UARTN_BASE) = c;
-
- return 0;
-}
-
-
-
-void debug_printf(const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- vfnprintf(debug_txchar, NULL, format, args);
- va_end(args);
-}
diff --git a/board/zinger/runtime.c b/board/zinger/runtime.c
index 8631eea74e..502d6649de 100644
--- a/board/zinger/runtime.c
+++ b/board/zinger/runtime.c
@@ -7,7 +7,7 @@
#include "clock.h"
#include "common.h"
#include "cpu.h"
-#include "debug.h"
+#include "debug_printf.h"
#include "registers.h"
#include "system.h"
#include "task.h"
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index 477060d17d..fd9cf8be7b 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -6,7 +6,7 @@
#include "adc.h"
#include "common.h"
#include "console.h"
-#include "debug.h"
+#include "debug_printf.h"
#include "ec_commands.h"
#include "hooks.h"
#include "registers.h"
diff --git a/chip/stm32/build.mk b/chip/stm32/build.mk
index 1c1df1a789..53b48b6ab5 100644
--- a/chip/stm32/build.mk
+++ b/chip/stm32/build.mk
@@ -50,6 +50,7 @@ chip-$(CHIP_FAMILY_STM32F0)+=flash-f.o
chip-$(CHIP_FAMILY_STM32F3)+=flash-f.o
endif
chip-$(CONFIG_ADC)+=adc-$(CHIP_FAMILY).o
+chip-$(CONFIG_DEBUG_PRINTF)+=debug_printf.o
chip-$(CONFIG_PWM)+=pwm.o
chip-$(CONFIG_USB)+=usb.o usb-$(CHIP_FAMILY).o usb_endpoints.o
chip-$(CONFIG_USB_CONSOLE)+=usb_console.o
diff --git a/chip/stm32/debug_printf.c b/chip/stm32/debug_printf.c
new file mode 100644
index 0000000000..c4e151692c
--- /dev/null
+++ b/chip/stm32/debug_printf.c
@@ -0,0 +1,115 @@
+/* Copyright 2015 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.
+ */
+/* Synchronous UART debug printf */
+
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "printf.h"
+#include "registers.h"
+#include "util.h"
+
+static int debug_txchar(void *context, int c)
+{
+ if (c == '\n') {
+ while (!(STM32_USART_SR(UARTN_BASE) & STM32_USART_SR_TXE))
+ ;
+ STM32_USART_TDR(UARTN_BASE) = '\r';
+ }
+
+ /* Wait for space to transmit */
+ while (!(STM32_USART_SR(UARTN_BASE) & STM32_USART_SR_TXE))
+ ;
+ STM32_USART_TDR(UARTN_BASE) = c;
+
+ return 0;
+}
+
+
+
+void debug_printf(const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vfnprintf(debug_txchar, NULL, format, args);
+ va_end(args);
+}
+
+#ifdef CONFIG_COMMON_RUNTIME
+void cflush(void)
+{
+ /* Wait for transmit complete */
+ while (!(STM32_USART_SR(UARTN_BASE) & STM32_USART_SR_TC))
+ ;
+}
+
+int cputs(enum console_channel channel, const char *outstr)
+{
+ debug_printf(outstr);
+
+ return 0;
+}
+
+void panic_puts(const char *outstr)
+{
+ debug_printf(outstr);
+ cflush();
+}
+
+int cprintf(enum console_channel channel, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vfnprintf(debug_txchar, NULL, format, args);
+ va_end(args);
+
+ return 0;
+}
+
+void panic_printf(const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vfnprintf(debug_txchar, NULL, format, args);
+ va_end(args);
+
+ cflush();
+}
+
+int cprints(enum console_channel channel, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vfnprintf(debug_txchar, NULL, format, args);
+ va_end(args);
+
+ debug_printf("\n");
+
+ return 0;
+}
+
+void uart_init(void)
+{
+ /* Enable USART1 clock */
+ STM32_RCC_APB2ENR |= STM32_RCC_PB2_USART1;
+ /* set baudrate */
+ STM32_USART_BRR(UARTN_BASE) =
+ DIV_ROUND_NEAREST(CPU_CLOCK, CONFIG_UART_BAUD_RATE);
+ /* UART enabled, 8 Data bits, oversampling x16, no parity */
+ STM32_USART_CR1(UARTN_BASE) =
+ STM32_USART_CR1_UE | STM32_USART_CR1_TE | STM32_USART_CR1_RE;
+ /* 1 stop bit, no fancy stuff */
+ STM32_USART_CR2(UARTN_BASE) = 0x0000;
+ /* DMA disabled, special modes disabled, error interrupt disabled */
+ STM32_USART_CR3(UARTN_BASE) = 0x0000;
+
+ /* Configure GPIOs */
+ gpio_config_module(MODULE_UART, 1);
+}
+#endif
diff --git a/board/zinger/debug.h b/chip/stm32/debug_printf.h
index 38cea6fb28..38cea6fb28 100644
--- a/board/zinger/debug.h
+++ b/chip/stm32/debug_printf.h
diff --git a/common/panic_output.c b/common/panic_output.c
index 144b7a0e19..8d9cf2205d 100644
--- a/common/panic_output.c
+++ b/common/panic_output.c
@@ -26,6 +26,7 @@ static struct panic_data * const pdata_ptr = PANIC_DATA_PTR;
* @param c Character to write.
* @return 0 if the character was transmitted, 1 if it was dropped.
*/
+#ifndef CONFIG_DEBUG_PRINTF
static int panic_txchar(void *context, int c)
{
if (c == '\n')
@@ -68,6 +69,7 @@ void panic_printf(const char *format, ...)
/* Flush the transmit FIFO */
uart_tx_flush();
}
+#endif
/**
* Display a message and reboot
diff --git a/common/printf.c b/common/printf.c
index 6e1a7401e9..987f7415ca 100644
--- a/common/printf.c
+++ b/common/printf.c
@@ -13,12 +13,12 @@ static const char error_str[] = "ERROR";
#define MAX_FORMAT 1024 /* Maximum chars in a single format field */
-#ifdef CONFIG_COMMON_RUNTIME
+#ifndef CONFIG_DEBUG_PRINTF
static inline int divmod(uint64_t *n, int d)
{
return uint64divmod(n, d);
}
-#else /* !CONFIG_COMMON_RUNTIME */
+#else /* CONFIG_DEBUG_PRINTF */
/* if we are optimizing for size, remove the 64-bit support */
#define NO_UINT64_SUPPORT
static inline int divmod(uint32_t *n, int d)
diff --git a/common/system.c b/common/system.c
index 224ae7d78e..7f5a5ee5b4 100644
--- a/common/system.c
+++ b/common/system.c
@@ -448,9 +448,9 @@ static void jump_to_image(uintptr_t init_addr)
/* Prepare I2C module for sysjump */
i2c_prepare_sysjump();
#endif
- /* Flush UART output unless the UART hasn't been initialized yet */
- if (uart_init_done())
- uart_flush_output();
+
+ /* Flush UART output */
+ cflush();
/* Disable interrupts before jump */
interrupt_disable();
diff --git a/common/uart_buffering.c b/common/uart_buffering.c
index 86a3482951..949c3968d6 100644
--- a/common/uart_buffering.c
+++ b/common/uart_buffering.c
@@ -301,8 +301,8 @@ int uart_printf(const char *format, ...)
void uart_flush_output(void)
{
- /* If UART is suspended, ignore flush request. */
- if (uart_suspended)
+ /* If UART not initialized or is suspended, ignore flush request. */
+ if (!uart_init_done() || uart_suspended)
return;
/* Loop until buffer is empty */