From a0aeeb5ff448d891dad3c9c8bfebe4a3a8e99cfc Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 22 Feb 2019 23:42:08 +0100 Subject: [PATCH] cpu/msp430: update to modern gcc & newlib --- cpu/msp430_common/msp430-main.c | 50 --------------------------------- makefiles/arch/msp430.inc.mk | 23 ++++++++------- 2 files changed, 13 insertions(+), 60 deletions(-) diff --git a/cpu/msp430_common/msp430-main.c b/cpu/msp430_common/msp430-main.c index aa171b68db..8b8b63a6ef 100644 --- a/cpu/msp430_common/msp430-main.c +++ b/cpu/msp430_common/msp430-main.c @@ -104,54 +104,16 @@ init_ports(void) P2IE = 0; } -/*---------------------------------------------------------------------------*/ -/* msp430-ld may align _end incorrectly. Workaround in cpu_init. */ -extern int _end; /* Not in sys/unistd.h */ -static char *cur_break = (char *) &_end; - void msp430_cpu_init(void) { irq_disable(); init_ports(); irq_enable(); - - periph_init(); - - if ((uintptr_t)cur_break & 1) { /* Workaround for msp430-ld bug!*/ - cur_break++; - } } /*---------------------------------------------------------------------------*/ #define asmv(arg) __asm__ __volatile__(arg) -#define STACK_EXTRA 32 - -/* - * Allocate memory from the heap. Check that we don't collide with the - * stack right now (some other routine might later). A watchdog might - * be used to check if cur_break and the stack pointer meet during - * runtime. - */ -void *sbrk(int incr) -{ - char *stack_pointer; - - asmv("mov r1, %0" : "=r"(stack_pointer)); - stack_pointer -= STACK_EXTRA; - - if (incr > (stack_pointer - cur_break)) { - return (void *) - 1; /* ENOMEM */ - } - - void *old_break = cur_break; - cur_break += incr; - /* - * If the stack was never here then [old_break .. cur_break] should - * be filled with zeros. - */ - return old_break; -} /*---------------------------------------------------------------------------*/ /* * Mask all interrupts that can be masked. @@ -178,17 +140,5 @@ splx_(int sr) asmv("bis %0, r2" : : "r"(sr)); asmv("nop"); } -/*---------------------------------------------------------------------------*/ - -size_t strnlen(const char *s, size_t maxlen) -{ - size_t len; - - for (len = 0; len < maxlen; len++, s++) { - if (!*s) - break; - } - return (len); -} extern void board_init(void); diff --git a/makefiles/arch/msp430.inc.mk b/makefiles/arch/msp430.inc.mk index e500c86087..88b10f2f0a 100644 --- a/makefiles/arch/msp430.inc.mk +++ b/makefiles/arch/msp430.inc.mk @@ -1,21 +1,24 @@ -# Target architecture for the build. Use msp430 if you are unsure. -TARGET_ARCH ?= msp430 +# Target architecture for the build. Use msp430-elf if you are unsure. +TARGET_ARCH ?= msp430-elf + +MSP430_SUPPORT_FILES ?= $(RIOTCPU)/msp430_common/vendor/msp430-gcc-support-files # define build specific options -CFLAGS_CPU = -mmcu=$(CPU_MODEL) -# default std set to gnu99 of not overwritten by user -ifeq (, $(filter -std=%, $(CFLAGS))) - CFLAGS += -std=gnu99 -endif +CFLAGS_CPU = -mmcu=$(CPU_MODEL) -isystem $(MSP430_SUPPORT_FILES)/include CFLAGS_LINK = -ffunction-sections -fdata-sections -CFLAGS_DBG ?= -gdwarf-2 +CFLAGS_DBG ?= -g -gdwarf-2 CFLAGS_OPT ?= -Os + CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) ASFLAGS += $(CFLAGS_CPU) --defsym $(CPU_MODEL)=1 $(CFLAGS_DBG) -# export linker flags -LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -Wl,--gc-sections -static -lgcc + +LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) +LINKFLAGS += -Wl,--gc-sections -Wl,-L$(MSP430_SUPPORT_FILES)/include OPTIONAL_CFLAGS_BLACKLIST += -fdiagnostics-color OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation OPTIONAL_CFLAGS_BLACKLIST += -gz + +# msp430 uses newlib by default +DEFAULT_MODULE += newlib