diff --git a/stmhal/Makefile b/stmhal/Makefile
index 1e8af398761b5538c3857a6d052061eec7beed80..8ee3f458f2af0de497839c1ccb1fdab8a412ad45 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -58,14 +58,16 @@ CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>'
 LDFLAGS = -nostdlib -T $(LD_FILE) -Map=$(@:.elf=.map) --cref
 LIBS =
 
+# Remove uncalled code from the final image.
+CFLAGS += -fdata-sections -ffunction-sections
+LDFLAGS += --gc-sections
+
 # Debugging/Optimization
 ifeq ($(DEBUG), 1)
 CFLAGS += -g -DPENDSV_DEBUG
 COPT = -O0
 else
-CFLAGS += -fdata-sections -ffunction-sections
 COPT += -Os -DNDEBUG
-LDFLAGS += --gc-sections
 endif
 
 # uncomment this if you want libgcc
diff --git a/stmhal/uart.c b/stmhal/uart.c
index b353f5d9e372a8f6dced68cc66e7e38e08e87177..374545163622a7a066a0817c9c8b2a3de1d906d5 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -115,7 +115,7 @@ void uart_deinit(void) {
 STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
     USART_TypeDef *UARTx;
     IRQn_Type irqn;
-    uint32_t GPIO_Pin, GPIO_Pin2;
+    uint32_t GPIO_Pin, GPIO_Pin2 = 0;
     uint8_t GPIO_AF_UARTx = 0;
     GPIO_TypeDef* GPIO_Port = NULL;
     GPIO_TypeDef* GPIO_Port2 = NULL;