aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test/cli-test.c
diff options
context:
space:
mode:
authorFredrik Thulin <fredrik@thulin.net>2016-06-01 21:03:05 +0200
committerFredrik Thulin <fredrik@thulin.net>2016-06-01 21:03:05 +0200
commit9915d1ba46e30990ea149c7a09d1d2ed0d13a331 (patch)
tree160f184c1dfc8548de8c6293a5d16376c65ab6ec /projects/cli-test/cli-test.c
parent2d08b2038a5cf14a92d8ca3e10fb3421e73e5b74 (diff)
Implement circular buffer UART RX using interrupts.
Diffstat (limited to 'projects/cli-test/cli-test.c')
-rw-r--r--projects/cli-test/cli-test.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c
index 26ebbc2..b90d0dd 100644
--- a/projects/cli-test/cli-test.c
+++ b/projects/cli-test/cli-test.c
@@ -49,6 +49,9 @@
extern uint32_t update_crc(uint32_t crc, uint8_t *buf, int len);
+/* MGMT UART interrupt receive buffer (data will be put in a larger ring buffer) */
+volatile uint8_t uart_rx;
+
int cmd_show_cpuspeed(struct cli_def *cli, const char *command, char *argv[], int argc)
{
@@ -286,6 +289,22 @@ void do_early_dfu_jump(void)
while (1);
}
+/* Callback for HAL_UART_Receive_IT(). */
+void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
+{
+ if (huart->Instance == huart_mgmt.Instance) {
+ mgmt_cli_uart_isr((const uint8_t *) &uart_rx, 1);
+
+ /* Set things up to receive another byte. */
+ HAL_UART_Receive_IT(huart, (uint8_t *) &uart_rx, 1);
+ }
+}
+
+void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
+{
+ led_on(LED_RED);
+ led_on(LED_YELLOW);
+}
int
main()
@@ -318,7 +337,7 @@ main()
/* embedded_cli_loop returns when the user enters 'quit' or 'exit' */
- cli_print(&cli, "Rebooting in 4 seconds");
+ cli_print(&cli, "Rebooting in 3 seconds");
HAL_Delay(3000);
HAL_NVIC_SystemReset();