mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
stm32f1x_cl: Add initial support for STM32F1x connectivity line
This currently supports the stm32f107, but support will be added for the F105 shortly (missing a linker script and I can't properly test without a devkit).
This commit is contained in:
parent
0a88373add
commit
5c6018f0e2
169
cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl
Normal file
169
cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl
Normal file
@ -0,0 +1,169 @@
|
||||
# Adapted from Makefile.stm32f103
|
||||
|
||||
# Default to STM32F107VCT7
|
||||
ifndef SUBTARGET
|
||||
$(warning SUBTARGET not defined, defaulting to STM32F107VCT)
|
||||
SUBTARGET = 7VCT
|
||||
endif
|
||||
|
||||
### libopencm3 specifics
|
||||
OPENCM3_BASE=
|
||||
OPENCM3_FAMILY=STM32F1
|
||||
OPENCM3_LIB=opencm3_stm32f1
|
||||
|
||||
ifndef OPENCM3_BASE
|
||||
$(error OPENCM3_BASE not defined. Please set definition to root of libopencm3)
|
||||
endif
|
||||
### Code common for all ARM CPUs
|
||||
|
||||
CONTIKI_CPU_ARM=$(CONTIKI)/cpu/arm
|
||||
CONTIKI_CPU_ARM_COMMON=$(CONTIKI_CPU_ARM)/common
|
||||
|
||||
### Define the CPU directory
|
||||
CONTIKI_CPU=$(CONTIKI_CPU_ARM)/stm32f1x_cl
|
||||
|
||||
### Define the source files we have in the STM32F1x_cl port
|
||||
|
||||
CONTIKI_CPU_DIRS = .
|
||||
|
||||
STM32F1x = clock.c util.c uip-log.c symbols.c
|
||||
|
||||
#Using the opencm3 usb library for now
|
||||
#include $(CONTIKI_CPU_ARM_COMMON)/usb/Makefile.usb
|
||||
|
||||
#No SD support for now...This is a TODO
|
||||
#include $(CONTIKI_CPU_ARM_COMMON)/SD-card/Makefile.sdcard
|
||||
|
||||
TARGETLIBS = random.c
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += $(STM32F1x) $(TARGETLIBS)
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
PREFIX = arm-none-eabi
|
||||
|
||||
### Compiler definitions
|
||||
CC = $(PREFIX)-gcc
|
||||
LD = $(PREFIX)-ld
|
||||
AS = $(PREFIX)-as
|
||||
AR = $(PREFIX)-ar
|
||||
NM = $(PREFIX)-nm
|
||||
OBJCOPY = $(PREFIX)-objcopy
|
||||
STRIP = $(PREFIX)-strip
|
||||
|
||||
XSLTPROC=xsltproc
|
||||
|
||||
PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)}
|
||||
|
||||
LINKERSCRIPT = $(CONTIKI_CPU)/STM32F10$(SUBTARGET).ld
|
||||
|
||||
# DFU-UTIL program upload
|
||||
DFU_UTIL=dfu-util
|
||||
DFU_UTIL_OFFSET=0x08000000
|
||||
|
||||
# Use dfu-util by default
|
||||
PROG=dfuutil
|
||||
|
||||
ARCH_FLAGS= -mcpu=cortex-m3 -mthumb
|
||||
|
||||
#CONTIKI_CFLAGS = -DWITH_UIP -DWITH_ASCII
|
||||
|
||||
CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) \
|
||||
-I$(OPENCM3_BASE)/include \
|
||||
-I$(CONTIKI)/platform/$(TARGET) \
|
||||
${addprefix -I,$(APPDIRS)} \
|
||||
-DMCK=$(MCK) -DSUBTARGET=$(SUBTARGET) \
|
||||
-Wall $(ARCH_FLAGS) -g -DSTM32F1 -MD
|
||||
|
||||
CFLAGS += $(CONTIKI_CFLAGS) $(CFLAGSNO) -Os
|
||||
|
||||
LDFLAGS += -L $(CONTIKI_CPU) -T $(LINKERSCRIPT) \
|
||||
-Wl,--start-group -lc -lgcc -Wl,--end-group\
|
||||
-nostartfiles -Wl,--gc-sections $(ARCH_FLAGS)
|
||||
|
||||
EXTERN_LIBS += -L $(OPENCM3_BASE)/lib -l$(OPENCM3_LIB)
|
||||
|
||||
CDEPFLAGS = $(CFLAGS) -D __MAKING_DEPS__
|
||||
|
||||
### Setup directory search path for source files
|
||||
|
||||
CUSTOM_RULE_C_TO_OBJECTDIR_O=yes
|
||||
CUSTOM_RULE_C_TO_O=yes
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $< -c
|
||||
|
||||
$(OBJECTDIR)/%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
CUSTOM_RULE_S_TO_OBJECTDIR_O = yes
|
||||
%.o: %.S
|
||||
$(CC) $(CFLAGS) $< -c
|
||||
|
||||
$(OBJECTDIR)/%.o: %.S
|
||||
$(CC) $(CFLAGS) $< -c -o $@
|
||||
|
||||
|
||||
CUSTOM_RULE_C_TO_CO=yes
|
||||
|
||||
%.co: %.c
|
||||
$(CC) $(CFLAGS) $< -c -o $@
|
||||
|
||||
CUSTOM_RULE_C_TO_CE=yes
|
||||
|
||||
%.ce: %.o
|
||||
$(LD) $(LDFLAGS) --relocatable -T $(CONTIKI_CPU)/merge-rodata.ld $< -o $@
|
||||
$(STRIP) -K _init -K _fini --strip-unneeded -g -x $@
|
||||
|
||||
CUSTOM_RULE_LINK=yes
|
||||
|
||||
%-stripped.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
$(STRIP) --strip-unneeded -g -x $@
|
||||
|
||||
%-stripped.o: %.o
|
||||
$(STRIP) --strip-unneeded -g -x -o $@ $<
|
||||
|
||||
%.o: ${CONTIKI_TARGET}/loader/%.S
|
||||
$(AS) -o $(notdir $(<:.S=.o)) $<
|
||||
|
||||
%-nosyms.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a # $(OBJECTDIR)/empty-symbols.o
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) -lc $(filter %.a,$^) $(EXTERN_LIBS)
|
||||
|
||||
|
||||
%.ihex: %.$(TARGET)
|
||||
$(OBJCOPY) $^ -O ihex $@
|
||||
|
||||
%.bin: %.$(TARGET)
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
.PHONY: symbols.c
|
||||
ifdef CORE
|
||||
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUP) $(OBJECTDIR)/symbols.o
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) -lc $(filter %.a,$^)
|
||||
|
||||
symbols.c: $(CORE)
|
||||
$(NM) $< | awk -f $(CONTIKI_CPU)/builtins.awk -f ../../tools/mknmlist > symbols.c
|
||||
|
||||
else
|
||||
%.$(TARGET): %-nosyms.$(TARGET)
|
||||
ln -sf $< $@
|
||||
endif
|
||||
|
||||
empty-symbols.c:
|
||||
cp ${CONTIKI}/tools/empty-symbols.c symbols.c
|
||||
cp ${CONTIKI}/tools/empty-symbols.h symbols.h
|
||||
|
||||
# Don't use core/loader/elfloader.c, use elfloader-otf.c instead
|
||||
$(OBJECTDIR)/elfloader.o:
|
||||
echo -n >$@
|
||||
|
||||
clean: clean_cpu
|
||||
|
||||
.PHONY: stm32test_clean
|
||||
|
||||
clean_cpu:
|
||||
-rm -rf $(BUILTSRCDIR)
|
||||
|
||||
.PRECIOUS: %-nosyms.$(TARGET)
|
54
cpu/arm/stm32f1x_cl/STM32F107VCT.ld
Normal file
54
cpu/arm/stm32f1x_cl/STM32F107VCT.ld
Normal file
@ -0,0 +1,54 @@
|
||||
MEMORY
|
||||
{
|
||||
CODE (rx) : ORIGIN = 0x08000000, LENGTH = 256K
|
||||
DATA (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
/* Section Definitions */
|
||||
|
||||
EXTERN (vector_table)
|
||||
ENTRY(reset_handler)
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/* Make sure the vector table is at address 0 */
|
||||
|
||||
.text : {
|
||||
*(.vectors)
|
||||
*(.text*)
|
||||
. = ALIGN(4);
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
} >CODE
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = . ;
|
||||
PROVIDE (etext = .);
|
||||
|
||||
.data :
|
||||
{
|
||||
_data = . ;
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
_edata = . ;
|
||||
PROVIDE (_edata = .);
|
||||
} >DATA AT >CODE
|
||||
_data_loadaddr = LOADADDR(.data);
|
||||
|
||||
/* .bss section which is used for uninitialized data */
|
||||
|
||||
.bss :
|
||||
{
|
||||
__bss_start = . ;
|
||||
__bss_start__ = . ;
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = . ;
|
||||
} >DATA
|
||||
. = ALIGN(4);
|
||||
|
||||
_end = .;
|
||||
PROVIDE (_end = .);
|
||||
}
|
||||
PROVIDE(_stack = ORIGIN(DATA) + LENGTH(DATA));
|
78
cpu/arm/stm32f1x_cl/clock.c
Normal file
78
cpu/arm/stm32f1x_cl/clock.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include <sys/clock.h>
|
||||
#include <sys/cc.h>
|
||||
#include <sys/etimer.h>
|
||||
#include <debug-uart.h>
|
||||
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
|
||||
static volatile clock_time_t current_clock = 0;
|
||||
static volatile unsigned long current_seconds = 0;
|
||||
static unsigned int second_countdown = CLOCK_SECOND;
|
||||
|
||||
void sys_tick_handler(void) __attribute__ ((interrupt));
|
||||
|
||||
void
|
||||
sys_tick_handler(void)
|
||||
{
|
||||
current_clock++;
|
||||
if(etimer_pending() && etimer_next_expiration_time() <= current_clock) {
|
||||
etimer_request_poll();
|
||||
/* printf("%d,%d\n", clock_time(),etimer_next_expiration_time ()); */
|
||||
}
|
||||
|
||||
if(--second_countdown == 0) {
|
||||
current_seconds++;
|
||||
second_countdown = CLOCK_SECOND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
clock_init()
|
||||
{
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
|
||||
/*72mhz / 8 / 1000 */
|
||||
systick_set_reload(MCK / 8 / CLOCK_SECOND);
|
||||
|
||||
systick_interrupt_enable();
|
||||
systick_counter_enable();
|
||||
}
|
||||
|
||||
clock_time_t
|
||||
clock_time(void)
|
||||
{
|
||||
return current_clock;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
clock_seconds(void)
|
||||
{
|
||||
return current_seconds;
|
||||
}
|
||||
|
||||
/* TODO: This code needs to be evaluated for the stm32f107 and
|
||||
* implemented
|
||||
*/
|
||||
#if 0
|
||||
/* The inner loop takes 4 cycles. The outer 5+SPIN_COUNT*4. */
|
||||
|
||||
#define SPIN_TIME 2 /* us */
|
||||
#define SPIN_COUNT (((MCK*SPIN_TIME/1000000)-5)/4)
|
||||
|
||||
#ifndef __MAKING_DEPS__
|
||||
|
||||
void
|
||||
clock_delay(unsigned int t)
|
||||
{
|
||||
#ifdef __THUMBEL__
|
||||
asm
|
||||
volatile
|
||||
("1: mov r1,%2\n2:\tsub r1,#1\n\tbne 2b\n\tsub %0,#1\n\tbne 1b\n":"=l"
|
||||
(t):"0"(t), "l"(SPIN_COUNT));
|
||||
#else
|
||||
#error Must be compiled in thumb mode
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif /* __MAKING_DEPS__ */
|
13
cpu/arm/stm32f1x_cl/mtarch.h
Normal file
13
cpu/arm/stm32f1x_cl/mtarch.h
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Implementation of multithreading in ARM Cortex-M3. To be done.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MTARCH_H__
|
||||
#define __MTARCH_H__
|
||||
|
||||
struct mtarch_thread {
|
||||
short mt_thread;
|
||||
};
|
||||
|
||||
#endif /* __MTARCH_H__ */
|
16
cpu/arm/stm32f1x_cl/rtimer-arch.c
Normal file
16
cpu/arm/stm32f1x_cl/rtimer-arch.c
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
void
|
||||
rtimer_arch_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
rtimer_arch_set(rtimer_clock_t t)
|
||||
{
|
||||
}
|
||||
|
||||
rtimer_clock_t
|
||||
rtimer_arch_now(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
22
cpu/arm/stm32f1x_cl/rtimer-arch.h
Normal file
22
cpu/arm/stm32f1x_cl/rtimer-arch.h
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* \file
|
||||
* Header file for the STM32F107-specific rtimer code
|
||||
* \author
|
||||
* Jeff Ciesielski <jeffciesielski@gmail.com>
|
||||
* Adapted from stm32f103 example
|
||||
*/
|
||||
|
||||
#ifndef __RTIMER_ARCH_H__
|
||||
#define __RTIMER_ARCH_H__
|
||||
|
||||
#include "sys/rtimer.h"
|
||||
|
||||
#define RTIMER_ARCH_SECOND (MCK/1024)
|
||||
|
||||
void rtimer_arch_init(void);
|
||||
|
||||
void rtimer_arch_set(rtimer_clock_t t);
|
||||
|
||||
rtimer_clock_t rtimer_arch_now(void);
|
||||
|
||||
#endif /* __RTIMER_ARCH_H__ */
|
7
cpu/arm/stm32f1x_cl/uip-log.c
Normal file
7
cpu/arm/stm32f1x_cl/uip-log.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
uip_log(char *msg)
|
||||
{
|
||||
printf("uip: %s\n", msg);
|
||||
}
|
12
cpu/arm/stm32f1x_cl/util.c
Normal file
12
cpu/arm/stm32f1x_cl/util.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t retval;
|
||||
|
||||
uint32_t
|
||||
get_msp(void)
|
||||
{
|
||||
asm("ldr r1, =retval");
|
||||
asm("mrs r0, msp");
|
||||
asm("str r0, [r1]");
|
||||
return retval;
|
||||
}
|
5
cpu/arm/stm32f1x_cl/util.h
Normal file
5
cpu/arm/stm32f1x_cl/util.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
#include <stdint.h>
|
||||
uint32_t get_msp(void);
|
||||
#endif /*_UTIL_H_*/
|
Loading…
Reference in New Issue
Block a user