diff --git a/Firmware/Shifter_System/.cproject b/Firmware/Shifter_System/.cproject
index a447d42..84cdac5 100644
--- a/Firmware/Shifter_System/.cproject
+++ b/Firmware/Shifter_System/.cproject
@@ -25,6 +25,7 @@
+
@@ -87,10 +88,19 @@
+
+
+
+
+
+
+
+
+
-
+
-
+
diff --git a/Firmware/Shifter_System/Core/Inc/retarget.h b/Firmware/Shifter_System/Core/Inc/retarget.h
new file mode 100644
index 0000000..d489b39
--- /dev/null
+++ b/Firmware/Shifter_System/Core/Inc/retarget.h
@@ -0,0 +1,32 @@
+// All credit to Carmine Noviello for this code
+// https://github.com/cnoviello/mastering-stm32/blob/master/nucleo-f030R8/system/include/retarget/retarget.h
+
+#ifndef _RETARGET_H__
+#define _RETARGET_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "stm32f4xx_hal.h"
+#include
+
+void RetargetInit(UART_HandleTypeDef *huart);
+int _isatty(int fd);
+int _write(int fd, char* ptr, int len);
+int _close(int fd);
+int _lseek(int fd, int ptr, int dir);
+int _read(int fd, char* ptr, int len);
+int _fstat(int fd, struct stat* st);
+
+// These three functions must be implemented when enabling printf with foating point values
+int _kill(int pid, int sig);
+int _getpid();
+void _exit(int);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //#ifndef _RETARGET_H__
diff --git a/Firmware/Shifter_System/Core/Src/main.c b/Firmware/Shifter_System/Core/Src/main.c
index 92b6949..0c197f7 100644
--- a/Firmware/Shifter_System/Core/Src/main.c
+++ b/Firmware/Shifter_System/Core/Src/main.c
@@ -24,6 +24,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "../../Program/Src/app.hpp"
+#include "retarget.h"
/* USER CODE END Includes */
diff --git a/Firmware/Shifter_System/Core/Src/retarget.c b/Firmware/Shifter_System/Core/Src/retarget.c
new file mode 100644
index 0000000..3e0340c
--- /dev/null
+++ b/Firmware/Shifter_System/Core/Src/retarget.c
@@ -0,0 +1,100 @@
+// All credit to Carmine Noviello for this code
+// https://github.com/cnoviello/mastering-stm32/blob/master/nucleo-f030R8/system/src/retarget/retarget.c
+
+#include <_ansi.h>
+#include <_syslist.h>
+#include
+#include
+#include
+#include
+#include
+#include <../Inc/retarget.h>
+#include
+#include
+
+#if !defined(OS_USE_SEMIHOSTING)
+
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+UART_HandleTypeDef *gHuart;
+
+void RetargetInit(UART_HandleTypeDef *huart) {
+ gHuart = huart;
+
+ /* Disable I/O buffering for STDOUT stream, so that
+ * chars are sent out as soon as they are printed. */
+ setvbuf(stdout, NULL, _IONBF, 0);
+}
+
+int _isatty(int fd) {
+ if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
+ return 1;
+
+ errno = EBADF;
+ return 0;
+}
+
+int _write(int fd, char* ptr, int len) {
+ HAL_StatusTypeDef hstatus;
+
+ if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
+ hstatus = HAL_UART_Transmit(gHuart, (uint8_t *) ptr, len, HAL_MAX_DELAY);
+ if (hstatus == HAL_OK)
+ return len;
+ else
+ return EIO;
+ }
+ errno = EBADF;
+ return -1;
+}
+
+int _close(int fd) {
+ if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
+ return 0;
+
+ errno = EBADF;
+ return -1;
+}
+
+int _lseek(int fd, int ptr, int dir) {
+ (void) fd;
+ (void) ptr;
+ (void) dir;
+
+ errno = EBADF;
+ return -1;
+}
+
+int _read(int fd, char* ptr, int len) {
+ HAL_StatusTypeDef hstatus;
+
+ if (fd == STDIN_FILENO) {
+ hstatus = HAL_UART_Receive(gHuart, (uint8_t *) ptr, 1, HAL_MAX_DELAY);
+ if (hstatus == HAL_OK)
+ return 1;
+ else
+ return EIO;
+ }
+ errno = EBADF;
+ return -1;
+}
+
+int _fstat(int fd, struct stat* st) {
+ if (fd >= STDIN_FILENO && fd <= STDERR_FILENO) {
+ st->st_mode = S_IFCHR;
+ return 0;
+ }
+
+ errno = EBADF;
+ return 0;
+}
+
+
+int _kill(int pid, int sig) { return 0; }
+int _getpid() { return 0; }
+// Added a forever loop to supress warning: "the 'noreturn' function does return"
+void _exit(int) { for(;;) { } }
+
+#endif //#if !defined(OS_USE_SEMIHOSTING)
diff --git a/Firmware/Shifter_System/Program/Src/app.cpp b/Firmware/Shifter_System/Program/Src/app.cpp
index 70a3ddb..f111cf6 100644
--- a/Firmware/Shifter_System/Program/Src/app.cpp
+++ b/Firmware/Shifter_System/Program/Src/app.cpp
@@ -14,19 +14,22 @@
// ST HAL Dependencies
#include "gpio.h"
-// 3rd Party Libraryes and Frameworks
+#include "usart.h"
+extern UART_HandleTypeDef huart2;
// DFR Custom Dependencies
-
+#include "../../Core/Inc/retarget.h"
void cppMain() {
-
+ // Enable `printf()` using USART
+ RetargetInit(&huart2);
for(;;){
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
+ printf("hi\n");
HAL_Delay(1000);
}
}