From 6fae3c2449e15c9ab5b93b65ed2a0cd861256f1d Mon Sep 17 00:00:00 2001
From: brian <brian@crocoll.ch>
Date: Wed, 10 Jan 2024 17:27:23 +0100
Subject: [PATCH] feat: full functionning UART

sudo minicom -D /dev/ttyUSB0 -b 9600

for local echo
CTRL-A, e
---
 mpu_user_console_etu.c | 10 +++++-----
 user_cmd.c             | 17 ++++++++---------
 user_cmd.h             |  3 ++-
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/mpu_user_console_etu.c b/mpu_user_console_etu.c
index 52a3be4..03e0d5b 100644
--- a/mpu_user_console_etu.c
+++ b/mpu_user_console_etu.c
@@ -66,12 +66,12 @@ void ask_user_input(void) {
 	char switch_cmd[] = "switch";
 	char status_cmd[] = "status";
 
-	PRINT("(%s) Would you like to `switch` or display `status` errors : ",
-			is_supervisor_mode ? "Supervisor" : "User")
-	;
+	PRINT("\r\n(%s) Would you like to `switch` or display `status` errors : ",
+			is_supervisor_mode ? "Supervisor" : "User");
 //	fflush(stdin);
 //	fscanf(stdin, "%s", buff);
 	uart_scanf(buff);
+	PRINT("\r\n");
 
 	if (strncmp(buff, switch_cmd, strlen(switch_cmd)) == 0) {
 		// permute through svc depending on flag
@@ -81,14 +81,14 @@ void ask_user_input(void) {
 
 	if (strncmp(buff, status_cmd, strlen(status_cmd)) == 0) {
 		if (idx_error == 0) {
-			PRINT("No errors have occurred yet\n")
+			PRINT("No errors have occurred yet\r\n")
 			;
 			return;
 		}
 
 		for (int i = 0; i < idx_error; i++) {
 			if (i < BUF_SIZE) {
-				PRINT("Address that shat the bed : 0x%x\tError code : 0x%x\n",
+				PRINT("Address that shat the bed : 0x%x\tError code : 0x%x\r\n",
 						arr_addr[i], arr_err_code[i])
 				;
 			}
diff --git a/user_cmd.c b/user_cmd.c
index 409f9e4..cdb3b6a 100644
--- a/user_cmd.c
+++ b/user_cmd.c
@@ -31,15 +31,16 @@ void SVC_Handler() {
 
 void uart_scanf(char *buff) {
 	char user_input[USER_INPUT_SIZE] = { 0 };
-	size_t idx = 1;
+	char current = 0;
+	size_t idx = 0;
 
-	while (user_input[idx - 1] != '\n') {
-		idx--;
-		user_input[idx] = uart0_rec_byte_ref();
+	while (current != '\r') {
+		current = uart0_rec_byte_ref();
+		user_input[idx] = current;
 		idx++;
 	}
 
-	user_input[idx - 1] = '\0';
+	user_input[idx-1] = '\0';
 
 	memcpy(buff, user_input, USER_INPUT_SIZE);
 }
@@ -49,10 +50,8 @@ void exec_user_read_write() {
 	int i = 0, coma_nb = 0, value_idx;
 	unsigned addr, value;
 
-	PRINT(
-			"Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):\n",
-			is_supervisor_mode ? "Supervisor" : "User")
-	;
+	PRINT("Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):\r\n",
+			is_supervisor_mode ? "Supervisor" : "User");
 
 //	fflush(stdin);
 //	fscanf(stdin, "%s", str);
diff --git a/user_cmd.h b/user_cmd.h
index 5554108..39aa642 100644
--- a/user_cmd.h
+++ b/user_cmd.h
@@ -18,7 +18,8 @@ static char uart_stdout[UART_STDOUT_SIZE] = { 0 };
 
 #define uart_printf(...) \
 	snprintf(uart_stdout, UART_STDOUT_SIZE, __VA_ARGS__); \
-	uart0_send_ref((uint8_t *)uart_stdout, UART_STDOUT_SIZE);
+	uart0_send_ref((uint8_t *)uart_stdout, UART_STDOUT_SIZE); \
+	memset(uart_stdout, 0, UART_STDOUT_SIZE);
 
 #if !UART_ENABLE
 #define PRINT printf
-- 
GitLab