2010-10-25 11:03:38 +02:00
.SUFFIXES :
2012-03-26 10:56:01 +02:00
d e f i n e \ n
e n d e f
2010-10-25 11:03:38 +02:00
i f d e f I A R
$ { i n f o U s i n g I A R . . . }
#IAR_PATH = C:/Program\ Files/IAR\ Systems/Embedded\ Workbench\ 5.4\ Evaluation
i f e q ( $( IAR_PATH ) , )
${ error IAR_PATH not defined! You must specify IAR root directory }
e n d i f
e n d i f
### Define the CPU directory
CONTIKI_CPU = $( CONTIKI) /cpu/stm32w108
### Define the source files we have in the STM32W port
CONTIKI_CPU_DIRS = . dev hal simplemac hal/micro/cortexm3 hal/micro/cortexm3/stm32w108
2013-03-15 16:14:09 +01:00
STM32W_C = leds-arch.c leds.c clock.c watchdog.c uart1.c uart1-putchar.c slip-uart1.c slip.c\
stm32w-radio.c stm32w-systick.c uip-arch.c rtimer-arch.c adc.c micro.c sleep.c \
2012-03-27 11:34:23 +02:00
micro-common.c micro-common-internal.c clocks.c mfg-token.c nvm.c flash.c rand.c system-timer.c
2010-10-25 11:03:38 +02:00
STM32W_S = spmr.s79 context-switch.s79
i f d e f I A R
2013-03-15 16:14:09 +01:00
STM32W_C += low-level-init.c
STM32W_S += cstartup-m.s
2010-10-25 11:03:38 +02:00
e l s e
2013-03-15 16:14:09 +01:00
STM32W_C += crt-stm32w108.c
2010-10-25 11:03:38 +02:00
e n d i f
2010-12-15 12:10:20 +01:00
i f d e f E L F _ L O A D E R
ELFLOADER = elfloader-arch.c symtab.c
e n d i f
2010-10-25 11:03:38 +02:00
# .s and .s79 not specified here because in Makefile.include only .c and .S suffixes are replaced with .o.
CONTIKI_TARGET_SOURCEFILES += $( STM32W_C) \
$( SYSAPPS) $( ELFLOADER) \
$( TARGETLIBS)
CONTIKI_SOURCEFILES += $( CONTIKI_TARGET_SOURCEFILES)
i f d e f I A R
TARGET_LIBFILES = $( CONTIKI_CPU) /simplemac/library/simplemac-library.a
e l s e
ifdef PRINTF_FLOAT
2011-03-21 13:11:52 +01:00
TARGET_LIBFILES = $( CONTIKI_CPU) /simplemac/library/simplemac-library-gnu.a $( CONTIKI_CPU) /hal/micro/cortexm3/e_stdio_thumb2.a
2010-10-25 11:03:38 +02:00
else
2011-03-21 13:11:52 +01:00
TARGET_LIBFILES = $( CONTIKI_CPU) /simplemac/library/simplemac-library-gnu.a $( CONTIKI_CPU) /lib/e_stdio_intonly_thumb2.a
2010-10-25 11:03:38 +02:00
endif
e n d i f
# `$(CC) -print-file-name=thumb2/libc.a` `$(CC) -print-file-name=thumb2/libgcc.a`
### Compiler definitions
i f d e f I A R
CC = iccarm
LD = ilinkarm
AS = iasmarm
AR = iarchive
OBJCOPY = ielftool
STRIP = strip
2010-12-15 12:10:20 +01:00
i f n d e f D E B U G
2010-10-25 11:03:38 +02:00
OPTI = -Ohz --no_unroll
2010-12-15 12:10:20 +01:00
e n d i f
2013-07-11 17:50:15 +02:00
CFLAGSNO = --debug --endian= little --cpu= Cortex-M3 -e --diag_suppress Pa050 -D BOARD_HEADER = \" board.h\" \
2010-10-25 11:03:38 +02:00
-D BOARD_MB851 -D "PLATFORM_HEADER=\"hal/micro/cortexm3/compiler/iar.h\"" -D CORTEXM3 \
-D CORTEXM3_STM32W108 -D PHY_STM32W108XX -D DISABLE_WATCHDOG -D ENABLE_ADC_EXTENDED_RANGE_BROKEN \
-D __SOURCEFILE__ = \" $* .c\" -lC $( OBJECTDIR) \
2013-07-11 17:50:15 +02:00
-I $( CONTIKI) /../iar-files \
2010-10-25 11:03:38 +02:00
-I $( IAR_PATH) /arm/inc --dlib_config= DLib_Config_Normal.h
2013-07-11 17:50:15 +02:00
CFLAGS += $( CFLAGSNO) $( OPTI) -D__ICCARM__
2010-10-25 11:03:38 +02:00
AROPTS = --create
ASFLAGS = -s+ -w+ --cpu Cortex-M3 -L$( OBJECTDIR)
2013-07-11 17:50:15 +02:00
LDFLAGS += --semihosting --redirect _Printf = _PrintfSmall --redirect _Scanf = _ScanfSmall --map= contiki-$( TARGET) .map
2011-01-17 10:41:47 +01:00
ifndef COFFEE
2011-03-21 13:11:52 +01:00
LDFLAGS += --config $( CONTIKI_CPU) /iar-cfg.icf
2010-11-10 12:20:44 +01:00
endif
2010-10-25 11:03:38 +02:00
OBJOPTS = --bin
e l s e
2010-11-10 12:20:44 +01:00
# GCC
2010-12-15 12:10:20 +01:00
CC = arm-none-eabi-gcc
2010-10-25 11:03:38 +02:00
LD = arm-none-eabi-gcc
2010-12-15 12:10:20 +01:00
AS = arm-none-eabi-gcc
NM = arm-none-eabi-nm
2010-10-25 11:03:38 +02:00
AR = arm-none-eabi-ar
OBJCOPY = arm-none-eabi-objcopy
STRIP = arm-none-eabi-strip
2010-12-15 12:10:20 +01:00
SIZE = arm-none-eabi-size
i f n d e f D E B U G
OPTI = -Os -ffunction-sections
e n d i f
2013-07-15 18:22:07 +02:00
i f e q ( $( STM 32W_CPUREV ) , C C )
2013-07-11 17:50:15 +02:00
LD-EXT= -stm32w108CC
2014-02-17 14:50:00 +01:00
RAM_SIZE = 2*8192
FLASH_SIZE = 2*128*1024
2013-07-11 17:50:15 +02:00
${ warning "using stm32w108CC specific ld file" }
2013-07-15 18:22:07 +02:00
e l s e i f e q ( $( STM 32W_CPUREV ) , x B )
2013-07-11 17:50:15 +02:00
LD-EXT= -stm32w108xB
2014-02-17 14:50:00 +01:00
RAM_SIZE = 8192
FLASH_SIZE = 128*1024
2013-07-11 17:50:15 +02:00
${ warning "using stm32w108xB specific ld file" }
e l s e
2013-10-17 12:33:36 +02:00
${ error "Bad STM32W_CPUREV value or no STM32W_CPUREV value specified. Cpu revision should be specified. Please read cpu/stm32w108/README.txt for more details." }
2013-07-11 17:50:15 +02:00
e n d i f
2011-04-01 08:53:05 +02:00
CFLAGSNO = -mthumb -mcpu= cortex-m3 -D "PLATFORM_HEADER=\"hal/micro/cortexm3/compiler/gnu.h\"" \
2010-10-25 11:03:38 +02:00
-D BOARD_HEADER = \" board.h\" -g -Wall -Wno-strict-aliasing -mlittle-endian \
2013-07-11 17:50:15 +02:00
-D CORTEXM3 -D CORTEXM3_STM32W108 -D PHY_STM32W108XX -D DISABLE_WATCHDOG -D ENABLE_ADC_EXTENDED_RANGE_BROKEN \
2010-10-25 11:03:38 +02:00
-D __SOURCEFILE__ = \" $* .c\"
CFLAGS += $( CFLAGSNO) $( OPTI)
2011-04-01 08:53:05 +02:00
ASFLAGS = -mthumb -mcpu= cortex-m3 -c -g -Wall -Os -ffunction-sections \
2010-10-25 11:03:38 +02:00
-mlittle-endian -fshort-enums -x assembler-with-cpp -Wa,-EL
2013-03-15 16:14:09 +01:00
i f n d e f C P U _ L D _ C O N F I G
2013-07-11 17:50:15 +02:00
CPU_LD_CONFIG = $( CONTIKI_CPU) /gnu$( LD-EXT) .ld
2013-03-15 16:14:09 +01:00
e n d i f # CPU_LD_CONFIG
2013-07-11 17:50:15 +02:00
LDFLAGS += -L$( CONTIKI_CPU) \
-mcpu= cortex-m3 \
2010-10-25 11:03:38 +02:00
-mthumb \
2013-03-15 16:14:09 +01:00
-Wl,-T -Xlinker $( CPU_LD_CONFIG) \
2010-10-25 11:03:38 +02:00
-Wl,-static \
-u Default_Handler \
-nostartfiles \
2010-12-15 12:10:20 +01:00
-Wl,-Map -Xlinker contiki-$( TARGET) .map
i f n d e f E L F _ L O A D E R
# Do not use garbage collection when the elfloader is used.
LDFLAGS += -Wl,--gc-sections
e n d i f
2010-10-25 11:03:38 +02:00
SIZEFLAGS = -A
OBJOPTS = -O binary
e n d i f
2010-11-10 12:20:44 +01:00
2010-12-15 12:10:20 +01:00
i f d e f C O F F E E _ A D D R E S S
COFFEE = 1
e n d i f
2010-11-10 12:20:44 +01:00
2010-12-15 12:10:20 +01:00
# Default values for coffee section start.
i f n d e f C O F F E E _ A D D R E S S
COFFEE_ADDRESS = 0x8010c00
e n d i f
i f e q ( $( COFFEE ) , 1 )
CONTIKI_TARGET_SOURCEFILES += cfs-coffee.c cfs-coffee-arch.c
CFLAGS += -DCOFFEE_ADDRESS= $( COFFEE_ADDRESS)
2010-11-10 12:20:44 +01:00
#If $make invokation passed starting address use phony target to force synchronization of source to .coffeefiles section
#Warning: recompilation will not be forced if the starting address is then dropped, with dire consequences:
# -->Source that uses COFFEE_FILES and read macros for conditional compilation will be left hanging!
# -->Object modules that used .coffeefiles will overlap the .data section.
# -->$make clean is safest.
#ifeq ($(origin COFFEE_ADDRESS), command line)
# ifeq ($(COFFEE_FILES), 2) #safest to force recompilation even if eeprom address is changed, might have been switched from flash
.PHONY : coffee
coffee:
$( OBJECTDIR) /cfs-coffee-arch.o : coffee #cfs-coffee-arch uses COFFEE_FILES, COFFEE_ADDRESS
$( OBJECTDIR) /cfs-coffee.o : coffee #core routine requires recompilation
2010-12-15 12:10:20 +01:00
e l s e
# Coffee starts at the end of the flash, before NVM section.
2011-03-21 13:11:52 +01:00
COFFEE_ADDRESS = 0x801F800
2010-12-15 12:10:20 +01:00
e n d i f
2011-03-21 13:11:52 +01:00
i f n d e f I A R
2010-12-15 12:10:20 +01:00
LDFLAGS += -Wl,--section-start= .coffee= $( COFFEE_ADDRESS)
e l s e #IAR
2010-11-10 12:20:44 +01:00
2010-12-15 12:10:20 +01:00
ifeq ( $( COFFEE) ,1)
2011-03-21 13:11:52 +01:00
LDFLAGS += --config $( CONTIKI_CPU) /iar-cfg-coffee.icf
2010-12-15 12:10:20 +01:00
endif
2010-11-10 12:20:44 +01:00
e n d i f
2010-12-15 12:10:20 +01:00
2012-11-09 14:14:57 +01:00
FLASHER = sudo $( CONTIKI) /tools/stm32w/stm32w_flasher/py_files/stm32w_flasher.py
2010-10-25 11:03:38 +02:00
# Check if we are running under Windows
2012-02-22 00:57:22 +01:00
i f e q ( $( HOST_OS ) , W i n d o w s )
FLASHER = $( CONTIKI) /tools/stm32w/stm32w_flasher/stm32w_flasher.exe
2010-10-25 11:03:38 +02:00
e n d i f
i f n d e f P O R T
# Flash with jlink
FLASHEROPTS = -f -r
e l s e
# Flash on serial port with on-board bootloader
FLASHEROPTS = -f -i rs232 -p $( PORT) -r
2011-01-17 10:41:47 +01:00
ifdef BTM
#if already in bootloader mode
FLASHEROPTS += -b
2013-03-15 16:14:09 +01:00
endif
2010-10-25 11:03:38 +02:00
e n d i f
### Custom rules
ssubst = ${ patsubst %.s,%.o, ${ patsubst %.s79,%.o, $( 1) } }
CONTIKI_OBJECTFILES += ${ addprefix $( OBJECTDIR) /, ${ call ssubst, $( STM32W_S) } }
v p a t h % . s 7 9 $( CONTIKI_CPU ) / h a l / m i c r o / c o r t e x m 3
v p a t h % . s $( CONTIKI_CPU ) / h a l / m i c r o / c o r t e x m 3
i f d e f I A R
# Check if we are in cygwin environment, so we must have paths like /cygdrive/c/... (checking TERM doesn't always work.)
2010-10-26 09:26:40 +02:00
i f n e q ( , $( findstring cygdrive ,$ ( shell pwd ) ) )
2010-10-25 11:03:38 +02:00
${ info Cygwin detected. }
SEDCOMMAND = sed -e '1s,\($(OBJECTDIR)\\$*\)\.o: \(.\):,\1.o : /cygdrive/\l\2,g' -e '1!s,\($(OBJECTDIR)\\$*\)\.o: \(.\):, /cygdrive/\l\2,g' -e 's,\\\([^ ]\),/\1,g' -e 's,$$, \\,' -e '$$s, \\$$,,' < $( @:.o= .P) > $( @:.o= .d)
e l s e
SEDCOMMAND = sed -e '1s,\($(OBJECTDIR)\\$*\)\.o:,\1.o : ,g' -e '1!s,\($(OBJECTDIR)\\$*\)\.o:, ,g' -e 's,\\\([^ ]\),/\1,g' -e 's,$$, \\,' -e '$$s, \\$$,,' < $( @:.o= .P) > $( @:.o= .d)
e n d i f
2010-12-15 12:10:20 +01:00
2010-10-25 11:03:38 +02:00
CUSTOM_RULE_C_TO_OBJECTDIR_O = 1
2013-06-21 00:45:41 +02:00
$(OBJECTDIR)/%.o : %.c | $( OBJECTDIR )
2014-02-17 14:22:08 +01:00
$( TRACE_CC)
$( Q) $( CC) $( CFLAGS) $< --dependencies= m $( @:.o= .P) -o $@
2010-10-25 11:03:38 +02:00
@$( SEDCOMMAND) ; rm -f $( @:.o= .P)
@$( FINALIZE_DEPENDENCY)
2013-03-15 16:14:09 +01:00
2010-10-25 11:03:38 +02:00
CUSTOM_RULE_C_TO_CO = 1
%.co : %.c
2014-02-17 14:22:08 +01:00
$( TRACE_CC)
$( Q) $( CC) $( CFLAGS) -DAUTOSTART_ENABLE $< -o $@
2010-10-25 11:03:38 +02:00
e l s e #IAR
2010-12-15 12:10:20 +01:00
CUSTOM_RULE_C_TO_CE = 1
%.ce : %.c
2014-02-17 14:22:08 +01:00
$( TRACE_CC)
$( Q) $( CC) $( CFLAGS) -fno-merge-constants -fno-function-sections -DAUTOSTART_ENABLE -c $< -o $@
2010-12-15 12:10:20 +01:00
$( STRIP) --strip-unneeded -g -x $@
2010-10-25 11:03:38 +02:00
CUSTOM_RULE_LINK = 1
2010-12-15 12:10:20 +01:00
i f d e f C O R E
i f e q ( $( wildcard $ ( CORE ) ) , )
2013-03-15 16:14:09 +01:00
${ error $( CORE) doesn \' t exist }
2010-12-15 12:10:20 +01:00
e n d i f
2012-03-23 19:54:11 +01:00
.PHONY : symbols .c symbols .h
2010-12-15 12:10:20 +01:00
symbols.c :
2013-03-15 16:14:09 +01:00
$( NM) $( CORE) | awk -f $( CONTIKI) /tools/mknmlist > symbols.c
2010-12-15 12:10:20 +01:00
e l s e
symbols.c symbols.h :
2011-04-03 13:24:58 +02:00
cp ${ CONTIKI } /tools/empty-symbols.c symbols.c
cp ${ CONTIKI } /tools/empty-symbols.h symbols.h
2010-12-15 12:10:20 +01:00
e n d i f
%.$(TARGET) : %.co $( PROJECT_OBJECTFILES ) $( PROJECT_LIBRARIES ) contiki -$( TARGET ) .a $( OBJECTDIR ) /symbols .o
2014-02-17 14:22:08 +01:00
$( TRACE_LD)
$( Q) $( LD) $( LDFLAGS) $( TARGET_STARTFILES) ${ filter -out %.a, $^ } -Wl,-\( ${ filter %.a, $^ } $( TARGET_LIBFILES) -Wl,-\) -o $@
2010-10-25 11:03:38 +02:00
@echo >> contiki-$( TARGET) .map
@$( SIZE) $( SIZEFLAGS) $@ >> contiki-$( TARGET) .map
#%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_OBJECTFILES)
2014-02-17 14:22:08 +01:00
# $(TRACE_LD)
# $(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
2010-10-25 11:03:38 +02:00
# @echo "\n" >> contiki-$(TARGET).map
# @$(SIZE) $(SIZEFLAGS) $@ >> contiki-$(TARGET).map
e n d i f #IAR
2012-03-26 10:56:01 +02:00
MOTELIST = $( CONTIKI) /tools/stm32w/motelist-linux
2012-11-09 14:00:16 +01:00
MOTES = $( shell $( MOTELIST) 2>& - | awk '{print $$2}' | grep '\/' )
2012-03-26 10:56:01 +02:00
motelist : stm -motelist
stm-motelist :
$( MOTELIST)
stm-motes :
@echo $( MOTES)
2013-06-21 00:45:41 +02:00
$(OBJECTDIR)/%.o : %.s 79 | $( OBJECTDIR )
2014-02-17 14:22:08 +01:00
$( TRACE_AS)
$( Q) $( AS) $( ASFLAGS) -o $@ $<
2013-03-15 16:14:09 +01:00
2013-06-21 00:45:41 +02:00
$(OBJECTDIR)/%.o : %.s | $( OBJECTDIR )
2014-02-17 14:22:08 +01:00
$( TRACE_AS)
$( Q) $( AS) $( ASFLAGS) -o $@ $<
2013-03-15 16:14:09 +01:00
2010-10-25 11:03:38 +02:00
%.bin : %.$( TARGET )
2013-03-15 16:14:09 +01:00
$( OBJCOPY) $( OBJOPTS) $< $@
2012-03-26 10:56:01 +02:00
# reset all stm32w devices sequentially, as stm32w_flasher cannot access different ports in parallel
stm-reset :
$( foreach PORT, $( MOTES) , $( FLASHER) -r -p $( PORT) ; $( \n ) )
@echo Done
2013-03-15 16:14:09 +01:00
2012-03-26 10:56:01 +02:00
i f d e f M O T E
%.upload : %.bin
$( FLASHER) $( FLASHEROPTS) $< -p $( word $( MOTE) , $( MOTES) )
e l s e # MOTE
%.upload : %.bin
$( foreach PORT, $( MOTES) , $( FLASHER) $( FLASHEROPTS) $< -p $( PORT) ; $( \n ) )
e n d i f # MOTE
i f d e f M O T E
login :
$( SERIALDUMP) -b115200 -d10000 $( USBDEVPREFIX) $( word $( MOTE) , $( MOTES) )
e l s e
login :
$( SERIALDUMP) -b115200 -d10000 $( USBDEVPREFIX) $( firstword $( MOTES) )
e n d i f
2012-03-27 11:34:23 +02:00
# a target that gives a user-friendly memory profile, taking into account the RAM
# that is statically occupied by the stack as defined in cpu/stm32w108/gnu.ld
STACK_SIZE = 1280
2014-02-17 14:50:00 +01:00
i f n d e f R A M _ S I Z E
${ error no ram size configured }
e n d i f
i f n d e f F L A S H _ S I Z E
${ error no flash size configured }
e n d i f
2012-03-27 11:34:23 +02:00
%.size : %.$( TARGET )
@size -A $< | egrep "data|bss" | awk '{s+=$$2} END {s=s+$(STACK_SIZE); f=$(RAM_SIZE)-s; printf "[RAM] used %6d, free %6d\n",s,f;}'
@size -A $< | egrep "text|isr_vector" | awk '{s+=$$2} END {f=$(FLASH_SIZE)-s; printf "[Flash] used %6d, free %6d\n",s,f;}'