summaryrefslogtreecommitdiff
path: root/include/uart.h
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-09-11 14:40:27 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-09-16 23:31:07 +0000
commitcdd5c206cd2125983f83ef3a54470b5e99f82031 (patch)
treeaab6c92edc49fb51a13298feeba7a2afa3dc599f /include/uart.h
parentb718dfc0598c324772171c1df94b68d5546893b5 (diff)
downloadchrome-ec-cdd5c206cd2125983f83ef3a54470b5e99f82031.tar.gz
stm32: Use DMA for UART receive
STM32 has a single-byte mailbox for UART I/O. When the core clock runs at 16Mhz we can service interrupts fast enough to handle 115200 baud input, but when we drop to 1MHz we drop characters. Using DMA to receive input solves this problem. The STM32 DMA engine can only generate interrupts when the transfer is half-done / all-done, so we need to poll the DMA receive-head-pointer to see if individual characters have been received. Do this in the tick task (every 250ms). When a character is received, poll more quickly for a bit (5 times before the next tick) so the input console is more responsive to typing. BUG=chrome-os-partner:20485 BRANCH=none TEST=Console is responsive to debug commands. For example, help -> prints help apshutdown -> shuts down AP arrow keys -> move cursor and scroll through command history Ctrl+Q, help, wait a second, Ctrl+S -> help output printed after Ctrl+S Then in chip/stm32/config_chip.h, comment out #define CONFIG_UART_RX_DMA and rebuild/reflash the EC. When the AP is up, the console works normally but after 'apshutdown', the EC drops to 1MHz core clock, and the arrow keys don't work. (This step confirms that adding DMA support did not change the behavior of systems where CONFIG_UART_RX_DMA is not defined.) Change-Id: I199448354824bd747c7b290ea7fd5ccf354c11bb Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/169406 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/uart.h')
-rw-r--r--include/uart.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/uart.h b/include/uart.h
index 9e182002e1..762d885f08 100644
--- a/include/uart.h
+++ b/include/uart.h
@@ -119,6 +119,26 @@ void uart_tx_dma_start(const char *src, int len);
int uart_rx_available(void);
/**
+ * Start a UART receive DMA transfer.
+ *
+ * DMA will be configured in circular buffer mode, so received characters
+ * will be stored into the buffer continuously.
+ *
+ * @param dest Pointer to destination buffer
+ * @param len Length of buffer in bytes
+ */
+void uart_rx_dma_start(char *dest, int len);
+
+/**
+ * Return the head of the receive DMA transfer buffer
+ *
+ * This is the next offset in the buffer which will receive a character, and
+ * will be from 0..(len-1) where len is the buffer length passed to
+ * uart_rx_dma_start().
+ */
+int uart_rx_dma_head(void);
+
+/**
* Send a character to the UART data register.
*
* If the transmit FIFO is full, blocks until there is space.