Skip to content

Commit b86eca3

Browse files
author
mars
committed
added source code
1 parent 64bd66e commit b86eca3

19 files changed

Lines changed: 3770 additions & 0 deletions

firmware/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
TEMPLATEROOT = .
2+
3+
# CFLAGS = -g -Wall -Wcpp -DUSE_FULL_ASSERT
4+
CFLAGS = -O2 -Wall -Wcpp -DUSE_FULL_ASSERT
5+
CXXFLAGS = -fno-rtti -fno-exceptions -std=c++11 $(CFLAGS)
6+
# LDSCRIPT = Source/flash.ld
7+
8+
C_SRC = gpio.c periph.c
9+
CPP_SRC = main.cpp TapTempo.cpp DDS.cpp
10+
OBJS = $(C_SRC:%.c=Build/%.o) $(CPP_SRC:%.cpp=Build/%.o)
11+
12+
# object files
13+
# OBJS += $(BUILD)/stm32f10x_gpio.o
14+
# OBJS += $(BUILD)/stm32f10x_rcc.o
15+
# OBJS += $(BUILD)/startup.o
16+
OBJS += $(SYSCALLS)
17+
OBJS += $(PERIPH)
18+
# OBJS += $(STARTUP)
19+
# OBJS += $(SYSTEM)
20+
OBJS += $(BUILD)/system_stm32f10x.o
21+
OBJS += $(BUILD)/startup_stm32f10x_md_vl.o # medium density value line
22+
23+
# include common make file
24+
include $(TEMPLATEROOT)/Makefile.f1

firmware/Makefile.common

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# name of executable
2+
ELF=$(BUILD)/TapTempo.elf
3+
BIN=$(BUILD)/TapTempo.bin
4+
5+
# Tool path
6+
TOOLROOT=~/devel/OwlWare/Tools/gcc-arm-none-eabi-4_8-2014q2/bin
7+
STLINK=~/devel/stlink/
8+
9+
# Tools
10+
CC=$(TOOLROOT)/arm-none-eabi-gcc
11+
CXX=$(TOOLROOT)/arm-none-eabi-g++
12+
LD=$(TOOLROOT)/arm-none-eabi-gcc
13+
AR=$(TOOLROOT)/arm-none-eabi-ar
14+
AS=$(TOOLROOT)/arm-none-eabi-as
15+
GDB=$(TOOLROOT)/arm-none-eabi-gdb
16+
OBJCOPY=$(TOOLROOT)/arm-none-eabi-objcopy
17+
OBJDUMP=$(TOOLROOT)/arm-none-eabi-objdump
18+
STFLASH=$(STLINK)/st-flash
19+
STUTIL=$(STLINK)/st-util
20+
DFUUTIL=dfu-util
21+
22+
# Set up search path
23+
vpath %.cpp $(TEMPLATEROOT)/Source
24+
vpath %.c $(TEMPLATEROOT)/Source
25+
vpath %.s $(TEMPLATEROOT)/Source
26+
vpath %.c $(TEMPLATEROOT)/Libraries/syscalls
27+
vpath %.c $(CORE)
28+
vpath %.c $(PERIPH_FILE)/src
29+
vpath %.c $(PERIPH_FILE)/inc
30+
vpath %.c $(DEVICE)
31+
vpath %.c $(SYSTEM_FILE)
32+
vpath %.s $(STARTUP_FILE)
33+
34+
all: bin
35+
36+
# Build executable
37+
$(ELF) : $(OBJS) $(LDSCRIPT)
38+
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
39+
40+
# compile and generate dependency info
41+
$(BUILD)/%.o: %.c
42+
$(CC) -c $(CFLAGS) $< -o $@
43+
$(CC) -MM -MT"$@" $(CFLAGS) $< > $(@:.o=.d)
44+
45+
$(BUILD)/%.o: %.cpp
46+
$(CXX) -c $(CXXFLAGS) $< -o $@
47+
$(CXX) -MM -MT"$@" $(CXXFLAGS) $< > $(@:.o=.d)
48+
49+
$(BUILD)/%.o: %.s
50+
$(CC) -c $(CFLAGS) $< -o $@
51+
52+
$(BUILD)/%.s: %.c
53+
$(CC) -S $(CFLAGS) $< -o $@
54+
55+
$(BUILD)/%.s: %.cpp
56+
$(CXX) -S $(CXXFLAGS) $< -o $@
57+
58+
$(BUILD)/%.bin: $(BUILD)/%.elf
59+
$(OBJCOPY) -O binary $< $@
60+
@echo Successfully built OWL firmware $@
61+
62+
clean:
63+
rm -f $(OBJS) $(OBJS:.o=.d) $(ELF) $(CLEANOTHER) $(BIN) gdbscript
64+
65+
debug: $(ELF)
66+
echo "target extended localhost:4242" > gdbscript
67+
echo "load $(ELF)" >> gdbscript
68+
$(GDB) -x gdbscript $(ELF)
69+
# bash -c "$(GDB) -x <(echo target extended localhost:4242) $(ELF)"
70+
71+
flash: $(BIN)
72+
$(STFLASH) write $(BIN) 0x8000000
73+
74+
stlink:
75+
echo "target extended localhost:4242" > gdbscript
76+
$(GDB) -x gdbscript $(ELF)
77+
78+
etags:
79+
find $(PERIPH_FILE) -type f -iname "*.[ch]" | xargs etags --append
80+
find $(DEVICE) -type f -iname "*.[ch]" | xargs etags --append
81+
find $(CORE) -type f -iname "*.[ch]" | xargs etags --append
82+
find $(DISCOVERY_FILE) -type f -iname "*.[ch]" | xargs etags --append
83+
find . -type f -iname "*.[ch]" | xargs etags --append
84+
85+
bin: $(BIN)
86+
87+
as: $(ELF)
88+
$(OBJDUMP) -S $(ELF) > $(ELF:.elf=.s)
89+
90+
dfu: $(BIN)
91+
$(DFUUTIL) -d 0483:df11 -c 1 -i 0 -a 0 -s 0x8000000:leave -D $(BIN)
92+
@echo Uploaded $(BIN) to OWL
93+
94+
# pull in dependencies
95+
-include $(OBJS:.o=.d)

firmware/Makefile.f1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Library path
2+
LIBROOT=$(TEMPLATEROOT)/Libraries/STM32F10x_StdPeriph_Lib_V3.5.0
3+
4+
# Build path
5+
BUILD=$(TEMPLATEROOT)/Build
6+
7+
# Code Paths
8+
DEVICE=$(LIBROOT)/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/
9+
CORE=$(LIBROOT)/Libraries/CMSIS/CM3/CoreSupport/
10+
PERIPH_FILE=$(LIBROOT)/Libraries/STM32F10x_StdPeriph_Driver/
11+
SYSTEM_FILE=$(LIBROOT)/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/
12+
STARTUP_FILE=$(LIBROOT)/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/TrueSTUDIO/
13+
14+
# Processor specific
15+
LDSCRIPT ?= $(LIBROOT)/Project/STM32F10x_StdPeriph_Template/TrueSTUDIO/STM32100B-EVAL/stm32_flash.ld
16+
STARTUP ?= $(BUILD)/startup_stm32f10x_md_vl.o # medium density value line
17+
SYSTEM ?= $(BUILD)/system_stm32f10x.o
18+
PERIPH = $(BUILD)/stm32f10x_gpio.o $(BUILD)/stm32f10x_adc.o $(BUILD)/stm32f10x_rcc.o $(BUILD)/stm32f10x_pwr.o
19+
PERIPH += $(BUILD)/stm32f10x_exti.o $(BUILD)/stm32f10x_dac.o $(BUILD)/stm32f10x_tim.o $(BUILD)/stm32f10x_dma.o
20+
PERIPH += $(BUILD)/stm32f10x_usart.o
21+
PERIPH += $(BUILD)/stm32f10x_spi.o $(BUILD)/stm32f10x_i2c.o $(BUILD)/stm32f10x_dbgmcu.o
22+
PERIPH += $(BUILD)/stm32f10x_flash.o $(BUILD)/stm32f10x_fsmc.o
23+
PERIPH += $(BUILD)/misc.o # stm32f10x_comp.o
24+
SYSCALLS = $(BUILD)/libnosys_gnu.o # Syscalls/syscalls.o
25+
26+
# Compilation Flags
27+
ARCH_FLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
28+
ARCH_FLAGS += -fsingle-precision-constant -ffast-math
29+
DEF_FLAGS = -DUSE_STDPERIPH_DRIVER -DARM_MATH_CM3 -DSTM32F10X_MD_VL
30+
INC_FLAGS = -I$(TEMPLATEROOT)/Libraries -I$(DEVICE) -I$(CORE) -I$(PERIPH_FILE)/inc -I$(TEMPLATEROOT)/Source
31+
INC_FLAGS += -I$(DEVICE)/Include -I$(CORE)
32+
CFLAGS += $(ARCH_FLAGS) $(INC_FLAGS) $(DEF_FLAGS)
33+
CFLAGS += -fno-builtin -std=c99
34+
CXXFLAGS += $(ARCH_FLAGS) $(INC_FLAGS) $(DEF_FLAGS)
35+
LDFLAGS += -T$(LDSCRIPT) $(ARCH_FLAGS)
36+
37+
include $(TEMPLATEROOT)/Makefile.common

firmware/Source/DDS.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <math.h>
2+
#include "DDS.h"
3+
4+
// #define REFCLK (double)31372.549
5+
#include "sinewave.h"
6+
#include "trianglewave.h"
7+
8+
void DDS::init(){
9+
setPeriod(0);
10+
// setFrequency(1000.0);
11+
}
12+
13+
// void DDS::setFrequency(double freq){
14+
// tuning = (uint32_t)(pow(2, 32)*freq/REFCLK); // calulate DDS new tuning word
15+
// // tword_m = (unsigned long)(pow(2,32)*freq/REFCLK); // calulate DDS new tuning word
16+
// }
17+
18+
uint16_t DDS::getSine(){
19+
uint16_t icnt = accumulator >> (DDS_ACCUMULATOR_WIDTH - 12); // use upper bits of phase accumulator
20+
// read value from wave table
21+
return sinewave[icnt];
22+
}
23+
24+
uint16_t DDS::getTri(){
25+
uint16_t icnt = accumulator >> (DDS_ACCUMULATOR_WIDTH - 12);
26+
return trianglewave[icnt];
27+
}

firmware/Source/DDS.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef _DDS_H_
2+
#define _DDS_H_
3+
4+
#include <stdint.h>
5+
6+
#ifndef min
7+
#define min(a,b) ((a)<(b)?(a):(b))
8+
#endif /* min */
9+
#ifndef max
10+
#define max(a,b) ((a)>(b)?(a):(b))
11+
#endif /* max */
12+
#ifndef abs
13+
#define abs(x) ((x)>0?(x):-(x))
14+
#endif /* abs */
15+
16+
#define DDS_ACCUMULATOR_PERIOD UINT32_MAX
17+
#define DDS_ACCUMULATOR_WIDTH 32
18+
#define DDS_DATATYPE uint32_t
19+
20+
// calculated zero points
21+
#define DDS_SINE_ZERO_VALUE 2094
22+
#define DDS_RAMP_ZERO_VALUE 3900
23+
24+
#define DDS_MAX_RAMP_VALUE 3900
25+
#define DDS_MIN_RAMP_VALUE 810
26+
#define DDS_RAMP_RANGE (DDS_MAX_RAMP_VALUE-DDS_MIN_RAMP_VALUE)
27+
28+
class DDS {
29+
public:
30+
void init();
31+
void setFrequency(double freq);
32+
inline DDS_DATATYPE getPeriod(){
33+
return DDS_ACCUMULATOR_PERIOD/tuning - 1;
34+
}
35+
inline void setPeriod(DDS_DATATYPE t){
36+
tuning = DDS_ACCUMULATOR_PERIOD/(t+1);
37+
}
38+
inline void reset(){
39+
accumulator = 0;
40+
}
41+
/* increment phase accumulator */
42+
inline void clock(){
43+
accumulator += tuning;
44+
}
45+
/* return 12-bit waveforms */
46+
inline uint16_t getRisingRamp(){
47+
DDS_DATATYPE val = accumulator >> (DDS_ACCUMULATOR_WIDTH - 12);
48+
return DDS_RAMP_RANGE - (val * DDS_RAMP_RANGE)/4095 + DDS_MIN_RAMP_VALUE;
49+
}
50+
inline uint16_t getFallingRamp(){
51+
DDS_DATATYPE val = accumulator >> (DDS_ACCUMULATOR_WIDTH - 12);
52+
return (val * DDS_RAMP_RANGE)/4095 + DDS_MIN_RAMP_VALUE;
53+
}
54+
/* inline uint16_t getTri(){ */
55+
/* uint16_t tri = accumulator >> (DDS_ACCUMULATOR_WIDTH - 13); */
56+
/* return 4095 - min(abs(4095 - tri), 4095); */
57+
/* } */
58+
uint16_t getSine();
59+
uint16_t getTri();
60+
61+
private:
62+
volatile DDS_DATATYPE accumulator; // phase accumulator
63+
volatile DDS_DATATYPE tuning; // dds tuning word
64+
};
65+
66+
67+
#endif /* _DDS_H_ */

0 commit comments

Comments
 (0)