Browse Source

Adding support for semihosting

Kevin Lee 6 years ago
parent
commit
8699bcbd7e

+ 8 - 4
STM32L432KC_Template/CMSIS/Device/ST/STM32L4xx/Source/Makefile

@@ -6,8 +6,10 @@ CORTEX_M=4
 # Use newlib-nano. To disable it, specify USE_NANO=
 USE_NANO=--specs=nano.specs
 
-# Use seimhosting or not
-# USE_SEMIHOST=--specs=rdimon.specs
+# Use semihosting 
+USE_SEMIHOST=--specs=rdimon.specs
+
+# Use retarget
 # USE_SEMIHOST=--specs=nosys.specs
 
 # Compiler & Linker
@@ -38,8 +40,10 @@ ARCH_FLAGS=-mthumb -mcpu=cortex-m$(CORTEX_M)
 CFLAGS=$(ARCH_FLAGS) $(INCLUDES) -g -flto -ffunction-sections -fdata-sections
 
 # Link for code size and create a map file
-LFLAGS=$(USE_NANO) $(USE_SEMIHOST) -nostartfiles -Wl,--gc-sections,-Map=$(PROJECT).map
-# LFLAGS=$(USE_NANO) $(USE_SEMIHOST) -Wl,--gc-sections,-Map=$(PROJECT).map
+# If not using semihosting/retarget:
+# LFLAGS=$(USE_NANO) $(USE_SEMIHOST) -nostartfiles -Wl,--gc-sections,-Map=$(PROJECT).map
+# Else:
+LFLAGS=$(USE_NANO) $(USE_SEMIHOST) -Wl,--gc-sections,-Map=$(PROJECT).map
 
 all: $(PROJECT).bin $(PROJECT).dis $(PROJECT).axf
 

+ 10 - 4
STM32L432KC_Template/CMSIS/Device/ST/STM32L4xx/Source/main.c

@@ -1,11 +1,17 @@
-// #include <stdio.h>
-
+#include "stm32l4xx.h"
+#include <stdio.h>
 #include <stdint.h>
 
+// Required if semihosting is enabled
+extern void initialise_monitor_handles(void);
+
 void main()
 {
+	// Required if semihosting is enabled
+	initialise_monitor_handles();
+
 	for (;;) {
-	 //    printf("Hello, world!");
-		// printf("\n");
+	     printf("Hello, world!\n");
 	}
 }
+