From 3d430cbe44dd240c6e586b18eee71808659e76e7 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 17:35:01 +0200 Subject: [PATCH 01/31] Add first working version of Arduino Due Makefile --- Makefile.Arduino | 199 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 Makefile.Arduino diff --git a/Makefile.Arduino b/Makefile.Arduino new file mode 100644 index 0000000..e1ca330 --- /dev/null +++ b/Makefile.Arduino @@ -0,0 +1,199 @@ +#!/usr/bin/make +# makefile for the arduino due (works with arduino IDE 1.6.11) +# +# USAGE: put this file in the same dir as your .ino file is. +# configure the PORT variable and ADIR at the top of the file +# to match your local configuration. +# Type make upload to compile and upload. +# Type make monitor to watch the serial port with gnu screen. +# +# TODO: +# * support libraries +# * handle possibly missing files in the currently hard coded ar step +# when assembling core.a together. +# * see what to do about the $(SAM)/cores/arduino/wiring_pulse_asm.S" add -x assembler-with-cpp +# and this one: $(SAM)/cores/arduino/avr/dtostrf.c +# +# LICENSE: GPLv2 or later (at your option) +# +# This file can be found at https://github.com/pauldreik/arduino-due-makefile +# +# By Paul Dreik http://www.pauldreik.se/ +# 20130503 initial version +# 20160924 updated to work with arduino 1.6.11 + +#user specific settings: +#where to find the IDE +ADIR:=$(HOME)/.arduino15 +#which serial port to use (add a file with SUBSYSTEMS=="usb", +#ATTRS{product}=="Arduino Due Prog. Port", ATTRS{idProduct}=="003d", +#ATTRS{idVendor}=="2341", SYMLINK+="arduino_due" in /etc/udev/rules.d/ +#to get this working). Do not prefix the port with /dev/, just take +#the basename. +PORT:=ttyACM0 +#if you want to verify the bossac upload, define this to -v +VERIFY:= + + +#end of user configuration. + + +#then some general settings. They should not be necessary to modify. +#CXX:=$(ADIR)/tools/g++_arm_none_eabi/bin/arm-none-eabi-g++ +CXX:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ +#CC:=$(ADIR)/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc +CC:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc +OBJCOPY:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-objcopy + +C:=$(CC) +#SAM:=arduino/sam/ +SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.9 +#CMSIS:=arduino/sam/system/CMSIS/ +#LIBSAM:=arduino/sam/system/libsam +TMPDIR:=$(PWD)/build +AR:=$(ADIR)/tools/g++_arm_none_eabi/bin/arm-none-eabi-ar +AR:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-ar + + +#all these values are hard coded and should maybe be configured somehow else, +#like olikraus does in his makefile. +DEFINES:=-Dprintf=iprintf -DF_CPU=84000000 -DARDUINO=10611 -D__SAM3X8E__ -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON \ + -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino Due"' + +INCLUDES:=-I$(SAM)/system/libsam -I$(SAM)/system/CMSIS/CMSIS/Include/ \ + -I$(SAM)/system/CMSIS/Device/ATMEL/ -I$(SAM)/cores/arduino \ + -I$(SAM)/variants/arduino_due_x + +#also include the current dir for convenience +INCLUDES += -I. + +#compilation flags common to both c and c++ +COMMON_FLAGS:=-g -Os -w -ffunction-sections -fdata-sections -nostdlib \ + --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb \ + -fno-threadsafe-statics +#for compiling c (do not warn, this is not our code) +CFLAGS:=$(COMMON_FLAGS) -std=gnu11 +#for compiling c++ +CXXFLAGS:=$(COMMON_FLAGS) -fno-rtti -fno-exceptions -std=gnu++11 -Wall -Wextra + +#let the results be named after the project +PROJNAME:=$(shell basename *.ino .ino) + +#we will make a new mainfile from the ino file. +NEWMAINFILE:=$(TMPDIR)/$(PROJNAME).ino.cpp + +#our own sourcefiles is the (converted) ino file and any local cpp files +MYSRCFILES:=$(NEWMAINFILE) $(shell ls *.cpp 2>/dev/null) +MYOBJFILES:=$(addsuffix .o,$(addprefix $(TMPDIR)/,$(notdir $(MYSRCFILES)))) + +#These source files are the ones forming core.a +CORESRCXX:=$(shell ls ${SAM}/cores/arduino/*.cpp ${SAM}/cores/arduino/USB/*.cpp ${SAM}/variants/arduino_due_x/variant.cpp) +CORESRC:=$(shell ls ${SAM}/cores/arduino/*.c) + +#hey this one is needed too: $(SAM)/cores/arduino/wiring_pulse_asm.S" add -x assembler-with-cpp +#and this one: /1.6.9/cores/arduino/avr/dtostrf.c but it seems to work +#anyway, probably because I do not use that functionality. + +#convert the core source files to object files. assume no clashes. +COREOBJSXX:=$(addprefix $(TMPDIR)/core/,$(notdir $(CORESRCXX)) ) +COREOBJSXX:=$(addsuffix .o,$(COREOBJSXX)) +COREOBJS:=$(addprefix $(TMPDIR)/core/,$(notdir $(CORESRC)) ) +COREOBJS:=$(addsuffix .o,$(COREOBJS)) + +default: + @echo default rule, does nothing. Try make compile or make upload. + +#This rule is good to just make sure stuff compiles, without having to wait +#for bossac. +compile: $(TMPDIR)/$(PROJNAME).elf + +#This is a make rule template to create object files from the source files. +# arg 1=src file +# arg 2=object file +# arg 3= XX if c++, empty if c +define OBJ_template +$(2): $(1) + $(C$(3)) -MD -c $(C$(3)FLAGS) $(DEFINES) $(INCLUDES) $(1) -o $(2) +endef +#now invoke the template both for c++ sources +$(foreach src,$(CORESRCXX), $(eval $(call OBJ_template,$(src),$(addsuffix .o,$(addprefix $(TMPDIR)/core/,$(notdir $(src)))),XX) ) ) +#...and for c sources: +$(foreach src,$(CORESRC), $(eval $(call OBJ_template,$(src),$(addsuffix .o,$(addprefix $(TMPDIR)/core/,$(notdir $(src)))),) ) ) + +#and our own c++ sources +$(foreach src,$(MYSRCFILES), $(eval $(call OBJ_template,$(src),$(addsuffix .o,$(addprefix $(TMPDIR)/,$(notdir $(src)))),XX) ) ) + + +clean: + test ! -d $(TMPDIR) || rm -rf $(TMPDIR) + $(RM) GitVersion.h + +.PHONY: upload default + +$(TMPDIR): + mkdir -p $(TMPDIR) + +$(TMPDIR)/core: + mkdir -p $(TMPDIR)/core + +#creates the cpp file from the .ino file +$(NEWMAINFILE): $(PROJNAME).ino + cat $(SAM)/cores/arduino/main.cpp > $(NEWMAINFILE) + cat $(PROJNAME).ino >> $(NEWMAINFILE) + echo 'extern "C" void __cxa_pure_virtual() {while (true);}' >> $(NEWMAINFILE) + +#include the dependencies for our own files +-include $(MYOBJFILES:.o=.d) + +#create the core library from the core objects. Do this EXACTLY as the +#arduino IDE does it, seems *really* picky about this. +#Sorry for the hard coding. +$(TMPDIR)/core.a: $(TMPDIR)/core $(COREOBJS) $(COREOBJSXX) + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_shift.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_analog.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/itoa.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/cortex_handlers.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/hooks.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/WInterrupts.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/syscalls_sam3.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/iar_calls_sam3.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_digital.c.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/Print.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/USARTClass.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/WString.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/PluggableUSB.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/USBCore.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/CDC.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_pulse.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/UARTClass.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/main.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/new.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/watchdog.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/Stream.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/RingBuffer.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/IPAddress.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/Reset.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/WMath.cpp.o + $(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/variant.cpp.o + +#link our own object files with core to form the elf file +$(TMPDIR)/$(PROJNAME).elf: $(TMPDIR)/core.a $(TMPDIR)/core/syscalls_sam3.c.o $(MYOBJFILES) + $(CC) -mcpu=cortex-m3 -mthumb -Os -Wl,--gc-sections -T$(SAM)/variants/arduino_due_x/linker_scripts/gcc/flash.ld -Wl,-Map,$(NEWMAINFILE).map -o $@ -L$(TMPDIR) -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid $(MYOBJFILES) $(TMPDIR)/core/variant.cpp.o $(SAM)/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a $(SAM)/system/CMSIS/CMSIS/Lib/GCC/libarm_cortexM3l_math.a $(TMPDIR)/core.a -Wl,--end-group -lm -gcc + +#copy from the hex to our bin file (why?) +$(TMPDIR)/$(PROJNAME).bin: $(TMPDIR)/$(PROJNAME).elf + $(OBJCOPY) -O binary $< $@ + +#upload to the arduino by first resetting it (stty) and the running bossac +upload: $(TMPDIR)/$(PROJNAME).bin + stty -F /dev/$(PORT) cs8 1200 hupcl + $(ADIR)/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i -d --port=$(PORT) -U false -e -w $(VERIFY) -b $(TMPDIR)/$(PROJNAME).bin -R + +# Export the current git version if the index file exists, else 000... +GitVersion.h: +ifneq ("$(wildcard .git/index)","") + echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@ +else + echo "#define GITVERSION \"0000000\"" > $@ +endif From 07b7801821fd5af0523a967da297a7f09b6482ea Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 17:39:15 +0200 Subject: [PATCH 02/31] A little less verbose and add verfiy --- Makefile.Arduino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index e1ca330..4e430a6 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -32,7 +32,7 @@ ADIR:=$(HOME)/.arduino15 #the basename. PORT:=ttyACM0 #if you want to verify the bossac upload, define this to -v -VERIFY:= +VERIFY:=-v #end of user configuration. @@ -188,7 +188,7 @@ $(TMPDIR)/$(PROJNAME).bin: $(TMPDIR)/$(PROJNAME).elf #upload to the arduino by first resetting it (stty) and the running bossac upload: $(TMPDIR)/$(PROJNAME).bin stty -F /dev/$(PORT) cs8 1200 hupcl - $(ADIR)/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i -d --port=$(PORT) -U false -e -w $(VERIFY) -b $(TMPDIR)/$(PROJNAME).bin -R + $(ADIR)/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i --port=$(PORT) -U false -e -w $(VERIFY) -b $(TMPDIR)/$(PROJNAME).bin -R # Export the current git version if the index file exists, else 000... GitVersion.h: From 59a9b3018f5374982bf3b4b51d676af5801f9412 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 21:57:32 +0200 Subject: [PATCH 03/31] Add a define to Makefile --- Makefile.Arduino | 4 +++- SerialPort.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index 4e430a6..58032d0 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -58,7 +58,8 @@ AR:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-e #all these values are hard coded and should maybe be configured somehow else, #like olikraus does in his makefile. DEFINES:=-Dprintf=iprintf -DF_CPU=84000000 -DARDUINO=10611 -D__SAM3X8E__ -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON \ - -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino Due"' + -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino Due"' \ + -DMADEBYMAKEFILE INCLUDES:=-I$(SAM)/system/libsam -I$(SAM)/system/CMSIS/CMSIS/Include/ \ -I$(SAM)/system/CMSIS/Device/ATMEL/ -I$(SAM)/cores/arduino \ @@ -105,6 +106,7 @@ default: #This rule is good to just make sure stuff compiles, without having to wait #for bossac. +compile: GitVersion.h compile: $(TMPDIR)/$(PROJNAME).elf #This is a make rule template to create object files from the source files. diff --git a/SerialPort.cpp b/SerialPort.cpp index 4b64bd0..3cb392d 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -22,7 +22,7 @@ #include "Config.h" #include "Globals.h" -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(MADEBYMAKEFILE) #include "GitVersion.h" #endif From f15fcc17ec3d531efc5c085ed82e1d46ada5bea5 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 22:18:25 +0200 Subject: [PATCH 04/31] Update Arduino Makefile to latest SAM version --- Makefile.Arduino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index 58032d0..5392075 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -47,7 +47,7 @@ OBJCOPY:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-n C:=$(CC) #SAM:=arduino/sam/ -SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.9 +SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.11 #CMSIS:=arduino/sam/system/CMSIS/ #LIBSAM:=arduino/sam/system/libsam TMPDIR:=$(PWD)/build @@ -92,7 +92,7 @@ CORESRCXX:=$(shell ls ${SAM}/cores/arduino/*.cpp ${SAM}/cores/arduino/USB/*.cpp CORESRC:=$(shell ls ${SAM}/cores/arduino/*.c) #hey this one is needed too: $(SAM)/cores/arduino/wiring_pulse_asm.S" add -x assembler-with-cpp -#and this one: /1.6.9/cores/arduino/avr/dtostrf.c but it seems to work +#and this one: /1.6.11/cores/arduino/avr/dtostrf.c but it seems to work #anyway, probably because I do not use that functionality. #convert the core source files to object files. assume no clashes. From bb42bdc42281f441ab3b2a886553402ce2f4d9f2 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 22:31:59 +0200 Subject: [PATCH 05/31] Add build/ dir for Arduino Makefile to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ca38dc6..64deba0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ obj/ bin/ STM32F4XX_Lib/ GitVersion.h +build/ From 27618658a9ce8820b171ee3d9e3fc38332233308 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 22:43:02 +0200 Subject: [PATCH 06/31] Force rebuild of GitVersion.h --- Makefile.Arduino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index 5392075..12e6962 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -130,7 +130,7 @@ clean: test ! -d $(TMPDIR) || rm -rf $(TMPDIR) $(RM) GitVersion.h -.PHONY: upload default +.PHONY: .FORCE upload default $(TMPDIR): mkdir -p $(TMPDIR) @@ -193,9 +193,11 @@ upload: $(TMPDIR)/$(PROJNAME).bin $(ADIR)/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i --port=$(PORT) -U false -e -w $(VERIFY) -b $(TMPDIR)/$(PROJNAME).bin -R # Export the current git version if the index file exists, else 000... -GitVersion.h: +GitVersion.h: .FORCE ifneq ("$(wildcard .git/index)","") echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@ else echo "#define GITVERSION \"0000000\"" > $@ endif + +.FORCE: From fa251afdcbb2e501167a54c574cad03e9e1ff843 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 22:58:35 +0200 Subject: [PATCH 07/31] Add define for default Makefile --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8c93c7a..3b1e789 100644 --- a/Makefile +++ b/Makefile @@ -85,11 +85,11 @@ MCFLAGS=-mcpu=cortex-m4 -mthumb -mlittle-endian \ # COMPILE FLAGS # STM32F4 Discovery board: -DEFS_DIS=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F40_41xxx -DSTM32F4_DISCOVERY -DHSE_VALUE=$(OSC) +DEFS_DIS=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F40_41xxx -DSTM32F4_DISCOVERY -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE # Pi board: -DEFS_PI=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_PI -DARDUINO_MODE_PINS -DSEND_RSSI_DATA -DSERIAL_REPEATER -DHSE_VALUE=$(OSC) +DEFS_PI=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_PI -DARDUINO_MODE_PINS -DSEND_RSSI_DATA -DSERIAL_REPEATER -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE # STM32F4 Nucleo 446 board: -DEFS_NUCLEO=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_NUCLEO -DHSE_VALUE=$(OSC) +DEFS_NUCLEO=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE CFLAGS=-c $(MCFLAGS) $(INCLUDES) CXXFLAGS=-c $(MCFLAGS) $(INCLUDES) From 871c328914c05f39d5893e12adff6091a8bef631 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 12 Apr 2017 23:00:39 +0200 Subject: [PATCH 08/31] Cleanup Makefile.Arduino --- Makefile.Arduino | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index 12e6962..36c3dd4 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -1,26 +1,13 @@ #!/usr/bin/make # makefile for the arduino due (works with arduino IDE 1.6.11) # +# The original file can be found at https://github.com/pauldreik/arduino-due-makefile +# # USAGE: put this file in the same dir as your .ino file is. # configure the PORT variable and ADIR at the top of the file # to match your local configuration. # Type make upload to compile and upload. -# Type make monitor to watch the serial port with gnu screen. # -# TODO: -# * support libraries -# * handle possibly missing files in the currently hard coded ar step -# when assembling core.a together. -# * see what to do about the $(SAM)/cores/arduino/wiring_pulse_asm.S" add -x assembler-with-cpp -# and this one: $(SAM)/cores/arduino/avr/dtostrf.c -# -# LICENSE: GPLv2 or later (at your option) -# -# This file can be found at https://github.com/pauldreik/arduino-due-makefile -# -# By Paul Dreik http://www.pauldreik.se/ -# 20130503 initial version -# 20160924 updated to work with arduino 1.6.11 #user specific settings: #where to find the IDE From cfb6e31e2f540fb6865e2a48b6a1c44bf0c336b4 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 13 Apr 2017 09:35:21 +0200 Subject: [PATCH 09/31] Remove Arduino compiler warning --- SerialPort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPort.cpp b/SerialPort.cpp index 3cb392d..09c6979 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -81,7 +81,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #endif #if defined(GITVERSION) -#define concat(a, b) a " GitID #"b"" +#define concat(a, b) a " GitID #" b "" const char HARDWARE[] = concat(DESCRIPTION, GITVERSION); #else #define concat(a, b, c) a " (Build: " b " " c ")" From 9386fb2e113c3ed45ab8b66b4f333c7f4e3e36c2 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 14 Apr 2017 14:19:00 +0100 Subject: [PATCH 10/31] Make modem debugging a run-time parameter, not compile-time. --- CWIdTX.cpp | 2 -- DMRDMORX.cpp | 2 -- DMRDMOTX.cpp | 2 -- DMRIdleRX.cpp | 2 -- DMRSlotRX.cpp | 2 -- DMRTX.cpp | 2 -- DStarRX.cpp | 5 +---- DStarTX.cpp | 2 -- Debug.h | 16 +--------------- IO.cpp | 7 ------- P25RX.cpp | 2 -- P25TX.cpp | 2 -- SerialPort.cpp | 22 +++++++++++++++++++--- SerialPort.h | 1 + YSFRX.cpp | 2 -- YSFTX.cpp | 2 -- 16 files changed, 22 insertions(+), 51 deletions(-) diff --git a/CWIdTX.cpp b/CWIdTX.cpp index 2019d2b..189e774 100644 --- a/CWIdTX.cpp +++ b/CWIdTX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "CWIdTX.h" diff --git a/DMRDMORX.cpp b/DMRDMORX.cpp index 1da0d89..2c3bdef 100644 --- a/DMRDMORX.cpp +++ b/DMRDMORX.cpp @@ -16,8 +16,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DMRDMORX.h" diff --git a/DMRDMOTX.cpp b/DMRDMOTX.cpp index 6ce2957..19d55b2 100644 --- a/DMRDMOTX.cpp +++ b/DMRDMOTX.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DMRSlotType.h" diff --git a/DMRIdleRX.cpp b/DMRIdleRX.cpp index 74f8912..3d2b5f5 100644 --- a/DMRIdleRX.cpp +++ b/DMRIdleRX.cpp @@ -16,8 +16,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DMRIdleRX.h" diff --git a/DMRSlotRX.cpp b/DMRSlotRX.cpp index a26aee2..0d34560 100644 --- a/DMRSlotRX.cpp +++ b/DMRSlotRX.cpp @@ -16,8 +16,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DMRSlotRX.h" diff --git a/DMRTX.cpp b/DMRTX.cpp index fd719c0..aa25bfd 100644 --- a/DMRTX.cpp +++ b/DMRTX.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DMRSlotType.h" diff --git a/DStarRX.cpp b/DStarRX.cpp index 38ebe09..6c4f342 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DStarRX.h" @@ -439,12 +437,11 @@ void CDStarRX::processData(bool bit) bool syncSeen = false; if (m_dataBits >= SYNC_SCAN_START && m_dataBits <= (SYNC_POS + 1U)) { if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) <= DATA_SYNC_ERRS) { -#if defined(WANT_DEBUG) if (m_dataBits < SYNC_POS) DEBUG2("DStarRX: found data sync in Data, early", SYNC_POS - m_dataBits); else DEBUG1("DStarRX: found data sync in Data"); -#endif + m_rxBufferBits = DSTAR_DATA_LENGTH_BITS; m_dataBits = 0U; syncSeen = true; diff --git a/DStarTX.cpp b/DStarTX.cpp index 865738b..ec0bc9f 100644 --- a/DStarTX.cpp +++ b/DStarTX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DStarTX.h" diff --git a/Debug.h b/Debug.h index 667856d..e8be149 100644 --- a/Debug.h +++ b/Debug.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,9 +20,6 @@ #define DEBUG_H #include "Config.h" - -#if defined(WANT_DEBUG) - #include "Globals.h" #define DEBUG1(a) serial.writeDebug((a)) @@ -32,16 +29,5 @@ #define DEBUG5(a,b,c,d,e) serial.writeDebug((a),(b),(c),(d),(e)) #define ASSERT(a) serial.writeAssert((a),#a,__FILE__,__LINE__) -#else - -#define DEBUG1(a) -#define DEBUG2(a,b) -#define DEBUG3(a,b,c) -#define DEBUG4(a,b,c,d) -#define DEBUG5(a,b,c,d,e) -#define ASSERT(a) - -#endif - #endif diff --git a/IO.cpp b/IO.cpp index 22163d9..47ecff2 100644 --- a/IO.cpp +++ b/IO.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "IO.h" @@ -346,11 +344,6 @@ void CIO::getOverflow(bool& adcOverflow, bool& dacOverflow) adcOverflow = m_adcOverflow > 0U; dacOverflow = m_dacOverflow > 0U; -#if defined(WANT_DEBUG) - if (m_adcOverflow > 0U || m_dacOverflow > 0U) - DEBUG3("IO: adc/dac", m_adcOverflow, m_dacOverflow); -#endif - m_adcOverflow = 0U; m_dacOverflow = 0U; } diff --git a/P25RX.cpp b/P25RX.cpp index 616fd1c..9228c5b 100644 --- a/P25RX.cpp +++ b/P25RX.cpp @@ -16,8 +16,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "P25RX.h" diff --git a/P25TX.cpp b/P25TX.cpp index a762fa9..e53e363 100644 --- a/P25TX.cpp +++ b/P25TX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "P25TX.h" diff --git a/SerialPort.cpp b/SerialPort.cpp index 09c6979..c54b646 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" @@ -94,7 +92,8 @@ const uint8_t PROTOCOL_VERSION = 1U; CSerialPort::CSerialPort() : m_buffer(), m_ptr(0U), -m_len(0U) +m_len(0U), +m_debug(false) { } @@ -230,6 +229,8 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) bool ysfLoDev = (data[0U] & 0x08U) == 0x08U; bool simplex = (data[0U] & 0x80U) == 0x80U; + m_debug = (data[0U] & 0x10U) == 0x10U; + bool dstarEnable = (data[1U] & 0x01U) == 0x01U; bool dmrEnable = (data[1U] & 0x02U) == 0x02U; bool ysfEnable = (data[1U] & 0x04U) == 0x04U; @@ -931,6 +932,9 @@ void CSerialPort::writeRSSIData(const uint8_t* data, uint8_t length) void CSerialPort::writeDebug(const char* text) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -948,6 +952,9 @@ void CSerialPort::writeDebug(const char* text) void CSerialPort::writeDebug(const char* text, int16_t n1) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -968,6 +975,9 @@ void CSerialPort::writeDebug(const char* text, int16_t n1) void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -991,6 +1001,9 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2) void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -1017,6 +1030,9 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3, int16_t n4) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; diff --git a/SerialPort.h b/SerialPort.h index c856ffa..8dc7658 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -61,6 +61,7 @@ private: uint8_t m_buffer[256U]; uint8_t m_ptr; uint8_t m_len; + bool m_debug; void sendACK(); void sendNAK(uint8_t err); diff --git a/YSFRX.cpp b/YSFRX.cpp index 8a283b1..88c6f83 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -16,8 +16,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "YSFRX.h" diff --git a/YSFTX.cpp b/YSFTX.cpp index b768aed..7c771e3 100644 --- a/YSFTX.cpp +++ b/YSFTX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "YSFTX.h" From caa73c6c4a4245d2672b7c8651d39d21aba675cf Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 14 Apr 2017 14:22:47 +0100 Subject: [PATCH 11/31] Remove the optional wide filters for C4FSK modes. --- Config.h | 5 ----- DMRDMOTX.cpp | 7 ------- DMRTX.cpp | 7 ------- IO.cpp | 7 ------- P25TX.cpp | 7 ------- YSFTX.cpp | 7 ------- 6 files changed, 40 deletions(-) diff --git a/Config.h b/Config.h index 78ef5d8..c7fb2b8 100644 --- a/Config.h +++ b/Config.h @@ -60,11 +60,6 @@ // Use separate mode pins to switch external filters/bandwidth for example // #define STM32F4_NUCLEO_MODE_PINS -// To use wider C4FSK filters for DMR, System Fusion and P25 on transmit -// #define WIDE_C4FSK_FILTERS_TX -// To use wider C4FSK filters for DMR, System Fusion and P25 on receive -// #define WIDE_C4FSK_FILTERS_RX - // Pass RSSI information to the host // #define SEND_RSSI_DATA diff --git a/DMRDMOTX.cpp b/DMRDMOTX.cpp index 19d55b2..33966d9 100644 --- a/DMRDMOTX.cpp +++ b/DMRDMOTX.cpp @@ -22,18 +22,11 @@ #include "Globals.h" #include "DMRSlotType.h" -#if defined(WIDE_C4FSK_FILTERS_TX) -// Generated using rcosdesign(0.2, 4, 5, 'sqrt') in MATLAB -static q15_t DMR_C4FSK_FILTER[] = {0, 0, 0, 0, 688, -680, -2158, -3060, -2724, -775, 2684, 7041, 11310, 14425, 15565, 14425, - 11310, 7041, 2684, -775, -2724, -3060, -2158, -680, 688}; // numTaps = 25, L = 5 -const uint16_t DMR_C4FSK_FILTER_PHASE_LEN = 5U; // phaseLength = numTaps/L -#else // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB static q15_t DMR_C4FSK_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 const uint16_t DMR_C4FSK_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L -#endif const q15_t DMR_LEVELA = 2889; const q15_t DMR_LEVELB = 963; diff --git a/DMRTX.cpp b/DMRTX.cpp index aa25bfd..12013b7 100644 --- a/DMRTX.cpp +++ b/DMRTX.cpp @@ -22,18 +22,11 @@ #include "Globals.h" #include "DMRSlotType.h" -#if defined(WIDE_C4FSK_FILTERS_TX) -// Generated using rcosdesign(0.2, 4, 5, 'sqrt') in MATLAB -static q15_t DMR_C4FSK_FILTER[] = {0, 0, 0, 0, 688, -680, -2158, -3060, -2724, -775, 2684, 7041, 11310, 14425, 15565, 14425, - 11310, 7041, 2684, -775, -2724, -3060, -2158, -680, 688}; // numTaps = 25, L = 5 -const uint16_t DMR_C4FSK_FILTER_PHASE_LEN = 5U; // phaseLength = numTaps/L -#else // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB static q15_t DMR_C4FSK_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 const uint16_t DMR_C4FSK_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L -#endif const q15_t DMR_LEVELA = 2889; const q15_t DMR_LEVELB = 963; diff --git a/IO.cpp b/IO.cpp index 47ecff2..352e22c 100644 --- a/IO.cpp +++ b/IO.cpp @@ -22,18 +22,11 @@ #include "Globals.h" #include "IO.h" -#if defined(WIDE_C4FSK_FILTERS_RX) -// Generated using rcosdesign(0.2, 4, 5, 'sqrt') in MATLAB -static q15_t C4FSK_FILTER[] = {688, -680, -2158, -3060, -2724, -775, 2684, 7041, 11310, 14425, 15565, 14425, - 11310, 7041, 2684, -775, -2724, -3060, -2158, -680, 688, 0}; -const uint16_t C4FSK_FILTER_LEN = 22U; -#else // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB static q15_t C4FSK_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401, 0}; const uint16_t C4FSK_FILTER_LEN = 42U; -#endif // Generated using gaussfir(0.5, 4, 5) in MATLAB static q15_t GMSK_FILTER[] = {8, 104, 760, 3158, 7421, 9866, 7421, 3158, 760, 104, 8, 0}; diff --git a/P25TX.cpp b/P25TX.cpp index e53e363..1dde485 100644 --- a/P25TX.cpp +++ b/P25TX.cpp @@ -23,18 +23,11 @@ #include "P25Defines.h" -#if defined(WIDE_C4FSK_FILTERS_TX) -// Generated using rcosdesign(0.2, 4, 5, 'normal') in MATLAB -// numTaps = 20, L = 5 -static q15_t P25_C4FSK_FILTER[] = {-1392, -2602, -3043, -2238, 0, 3460, 7543, 11400, 14153, 15152, 14153, 11400, 7543, 3460, 0, -2238, -3043, -2602, -1392, 0}; -const uint16_t P25_C4FSK_FILTER_PHASE_LEN = 4U; // phaseLength = numTaps/L -#else // Generated using rcosdesign(0.2, 8, 5, 'normal') in MATLAB // numTaps = 40, L = 5 static q15_t P25_C4FSK_FILTER[] = {-413, -751, -845, -587, 0, 740, 1348, 1520, 1063, 0, -1383, -2583, -3021, -2222, 0, 3435, 7488, 11318, 14053, 15044, 14053, 11318, 7488, 3435, 0, -2222, -3021, -2583, -1383, 0, 1063, 1520, 1348, 740, 0, -587, -845, -751, -413, 0}; const uint16_t P25_C4FSK_FILTER_PHASE_LEN = 8U; // phaseLength = numTaps/L -#endif // Generated in MATLAB using the following commands, and then normalised for unity gain // shape2 = 'Inverse-sinc Lowpass'; diff --git a/YSFTX.cpp b/YSFTX.cpp index 7c771e3..5c72efd 100644 --- a/YSFTX.cpp +++ b/YSFTX.cpp @@ -23,18 +23,11 @@ #include "YSFDefines.h" -#if defined(WIDE_C4FSK_FILTERS_TX) -// Generated using rcosdesign(0.2, 4, 5, 'sqrt') in MATLAB -static q15_t YSF_C4FSK_FILTER[] = {0, 0, 0, 0, 688, -680, -2158, -3060, -2724, -775, 2684, 7041, 11310, 14425, 15565, 14425, - 11310, 7041, 2684, -775, -2724, -3060, -2158, -680, 688}; // numTaps = 25, L = 5 -const uint16_t YSF_C4FSK_FILTER_PHASE_LEN = 5U; // phaseLength = numTaps/L -#else // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB static q15_t YSF_C4FSK_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 const uint16_t YSF_C4FSK_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L -#endif const q15_t YSF_LEVELA_HI = 3900; const q15_t YSF_LEVELB_HI = 1300; From c7eb072d2fff377610963d8324b19e3952e57ebc Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 14 Apr 2017 14:47:37 +0100 Subject: [PATCH 12/31] Add an extra flter for P25 RX. --- IO.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/IO.h b/IO.h index 25559c7..339b4ac 100644 --- a/IO.h +++ b/IO.h @@ -60,12 +60,14 @@ private: CSampleRB m_txBuffer; CRSSIRB m_rssiBuffer; - arm_fir_instance_q15 m_C4FSKFilter; - arm_fir_instance_q15 m_GMSKFilter; - arm_fir_instance_q15 m_P25Filter; - q15_t m_C4FSKState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare - q15_t m_GMSKState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare - q15_t m_P25State[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare + arm_fir_instance_q15 m_rrcFilter; + arm_fir_instance_q15 m_rcFilter; + arm_fir_instance_q15 m_gaussianFilter; + arm_fir_instance_q15 m_boxcarFilter; + q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare + q15_t m_rcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare + q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare + q15_t m_boxcarState[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare bool m_pttInvert; q15_t m_rxLevel; From a6ed1e96671850a03e68ad53e1568959f4e68d7d Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 15 Apr 2017 10:22:56 +0100 Subject: [PATCH 13/31] Finish committing the last change. --- DMRDMOTX.cpp | 12 ++++---- DMRTX.cpp | 12 ++++---- DStarTX.cpp | 12 ++++---- IO.cpp | 83 +++++++++++++++++++++++++++++++--------------------- P25TX.cpp | 20 ++++++------- YSFTX.cpp | 12 ++++---- 6 files changed, 83 insertions(+), 68 deletions(-) diff --git a/DMRDMOTX.cpp b/DMRDMOTX.cpp index 33966d9..fe64db6 100644 --- a/DMRDMOTX.cpp +++ b/DMRDMOTX.cpp @@ -23,10 +23,10 @@ #include "DMRSlotType.h" // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB -static q15_t DMR_C4FSK_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, +static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 -const uint16_t DMR_C4FSK_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L +const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L const q15_t DMR_LEVELA = 2889; const q15_t DMR_LEVELB = 963; @@ -68,10 +68,10 @@ m_cachPtr(0U) { ::memset(m_modState, 0x00U, 16U * sizeof(q15_t)); - m_modFilter.L = DMR_RADIO_SYMBOL_LENGTH; - m_modFilter.phaseLength = DMR_C4FSK_FILTER_PHASE_LEN; - m_modFilter.pCoeffs = DMR_C4FSK_FILTER; - m_modFilter.pState = m_modState; + m_modFilter.L = DMR_RADIO_SYMBOL_LENGTH; + m_modFilter.phaseLength = RRC_0_2_FILTER_PHASE_LEN; + m_modFilter.pCoeffs = RRC_0_2_FILTER; + m_modFilter.pState = m_modState; } void CDMRDMOTX::process() diff --git a/DMRTX.cpp b/DMRTX.cpp index 12013b7..e202a3f 100644 --- a/DMRTX.cpp +++ b/DMRTX.cpp @@ -23,10 +23,10 @@ #include "DMRSlotType.h" // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB -static q15_t DMR_C4FSK_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, +static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 -const uint16_t DMR_C4FSK_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L +const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L const q15_t DMR_LEVELA = 2889; const q15_t DMR_LEVELB = 963; @@ -73,10 +73,10 @@ m_abort() { ::memset(m_modState, 0x00U, 16U * sizeof(q15_t)); - m_modFilter.L = DMR_RADIO_SYMBOL_LENGTH; - m_modFilter.phaseLength = DMR_C4FSK_FILTER_PHASE_LEN; - m_modFilter.pCoeffs = DMR_C4FSK_FILTER; - m_modFilter.pState = m_modState; + m_modFilter.L = DMR_RADIO_SYMBOL_LENGTH; + m_modFilter.phaseLength = RRC_0_2_FILTER_PHASE_LEN; + m_modFilter.pCoeffs = RRC_0_2_FILTER; + m_modFilter.pState = m_modState; ::memcpy(m_newShortLC, EMPTY_SHORT_LC, 12U); ::memcpy(m_shortLC, EMPTY_SHORT_LC, 12U); diff --git a/DStarTX.cpp b/DStarTX.cpp index ec0bc9f..4ed0bf6 100644 --- a/DStarTX.cpp +++ b/DStarTX.cpp @@ -28,8 +28,8 @@ const uint8_t BIT_SYNC = 0xAAU; const uint8_t FRAME_SYNC[] = {0xEAU, 0xA6U, 0x00U}; // Generated using gaussfir(0.35, 1, 5) in MATLAB -static q15_t DSTAR_GMSK_FILTER[] = {0, 0, 0, 0, 212, 743, 1974, 3965, 6026, 6929, 6026, 3965, 1974, 743, 212}; // numTaps = 15, L = 5 -const uint16_t DSTAR_GMSK_FILTER_PHASE_LEN = 3U; // phaseLength = numTaps/L +static q15_t GAUSSIAN_0_35_FILTER[] = {0, 0, 0, 0, 212, 743, 1974, 3965, 6026, 6929, 6026, 3965, 1974, 743, 212}; // numTaps = 15, L = 5 +const uint16_t GAUSSIAN_0_35_FILTER_PHASE_LEN = 3U; // phaseLength = numTaps/L const q15_t DSTAR_LEVEL0 = -4000; const q15_t DSTAR_LEVEL1 = 4000; @@ -198,10 +198,10 @@ m_txDelay(60U) // 100ms { ::memset(m_modState, 0x00U, 20U * sizeof(q15_t)); - m_modFilter.L = DSTAR_RADIO_BIT_LENGTH; - m_modFilter.phaseLength = DSTAR_GMSK_FILTER_PHASE_LEN; - m_modFilter.pCoeffs = DSTAR_GMSK_FILTER; - m_modFilter.pState = m_modState; + m_modFilter.L = DSTAR_RADIO_BIT_LENGTH; + m_modFilter.phaseLength = GAUSSIAN_0_35_FILTER_PHASE_LEN; + m_modFilter.pCoeffs = GAUSSIAN_0_35_FILTER; + m_modFilter.pState = m_modState; } void CDStarTX::process() diff --git a/IO.cpp b/IO.cpp index 352e22c..f6e73a8 100644 --- a/IO.cpp +++ b/IO.cpp @@ -23,18 +23,23 @@ #include "IO.h" // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB -static q15_t C4FSK_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, +static q15_t RRC_0_2_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401, 0}; -const uint16_t C4FSK_FILTER_LEN = 42U; +const uint16_t RRC_0_2_FILTER_LEN = 42U; + +// Generated using rcosdesign(0.2, 8, 5, 'normal') in MATLAB +static q15_t RC_0_2_FILTER[] = {0, -413, -750, -845, -587, 0, 741, 1347, 1520, 1062, 0, -1383, -2582, -3021, -2222, 0, 3434, 7487, 11318, 14054, 15044, 14054, + 11318, 7487, 3434, 0, -2222, -3021, -2582, -1383, 0, 1062, 1520, 1347, 741, 0, -587, -845, -750, -413}; +const uint16_t RC_0_2_FILTER_LEN = 40U; // Generated using gaussfir(0.5, 4, 5) in MATLAB -static q15_t GMSK_FILTER[] = {8, 104, 760, 3158, 7421, 9866, 7421, 3158, 760, 104, 8, 0}; -const uint16_t GMSK_FILTER_LEN = 12U; +static q15_t GAUSSIAN_0_5_FILTER[] = {8, 104, 760, 3158, 7421, 9866, 7421, 3158, 760, 104, 8, 0}; +const uint16_t GAUSSIAN_0_5_FILTER_LEN = 12U; // One symbol boxcar filter -static q15_t P25_FILTER[] = {3000, 3000, 3000, 3000, 3000, 0}; -const uint16_t P25_FILTER_LEN = 6U; +static q15_t BOXCAR_FILTER[] = {3000, 3000, 3000, 3000, 3000, 0}; +const uint16_t BOXCAR_FILTER_LEN = 6U; const uint16_t DC_OFFSET = 2048U; @@ -43,12 +48,14 @@ m_started(false), m_rxBuffer(RX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE), m_rssiBuffer(RX_RINGBUFFER_SIZE), -m_C4FSKFilter(), -m_GMSKFilter(), -m_P25Filter(), -m_C4FSKState(), -m_GMSKState(), -m_P25State(), +m_rrcFilter(), +m_rcFilter(), +m_gaussianFilter(), +m_boxcarFilter(), +m_rrcState(), +m_rcState(), +m_gaussianState(), +m_boxcarState(), m_pttInvert(false), m_rxLevel(128 * 128), m_cwIdTXLevel(128 * 128), @@ -64,21 +71,26 @@ m_dacOverflow(0U), m_watchdog(0U), m_lockout(false) { - ::memset(m_C4FSKState, 0x00U, 70U * sizeof(q15_t)); - ::memset(m_GMSKState, 0x00U, 40U * sizeof(q15_t)); - ::memset(m_P25State, 0x00U, 30U * sizeof(q15_t)); + ::memset(m_rrcState, 0x00U, 70U * sizeof(q15_t)); + ::memset(m_rcState, 0x00U, 70U * sizeof(q15_t)); + ::memset(m_gaussianState, 0x00U, 40U * sizeof(q15_t)); + ::memset(m_boxcarState, 0x00U, 30U * sizeof(q15_t)); - m_C4FSKFilter.numTaps = C4FSK_FILTER_LEN; - m_C4FSKFilter.pState = m_C4FSKState; - m_C4FSKFilter.pCoeffs = C4FSK_FILTER; + m_rrcFilter.numTaps = RRC_0_2_FILTER_LEN; + m_rrcFilter.pState = m_rrcState; + m_rrcFilter.pCoeffs = RRC_0_2_FILTER; - m_GMSKFilter.numTaps = GMSK_FILTER_LEN; - m_GMSKFilter.pState = m_GMSKState; - m_GMSKFilter.pCoeffs = GMSK_FILTER; + m_rcFilter.numTaps = RC_0_2_FILTER_LEN; + m_rcFilter.pState = m_rcState; + m_rcFilter.pCoeffs = RC_0_2_FILTER; - m_P25Filter.numTaps = P25_FILTER_LEN; - m_P25Filter.pState = m_P25State; - m_P25Filter.pCoeffs = P25_FILTER; + m_gaussianFilter.numTaps = GAUSSIAN_0_5_FILTER_LEN; + m_gaussianFilter.pState = m_gaussianState; + m_gaussianFilter.pCoeffs = GAUSSIAN_0_5_FILTER; + + m_boxcarFilter.numTaps = BOXCAR_FILTER_LEN; + m_boxcarFilter.pState = m_boxcarState; + m_boxcarFilter.pCoeffs = BOXCAR_FILTER; initInt(); } @@ -160,21 +172,21 @@ void CIO::process() if (m_modemState == STATE_IDLE) { if (m_dstarEnable) { q15_t GMSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_GMSKFilter, samples, GMSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_gaussianFilter, samples, GMSKVals, RX_BLOCK_SIZE); dstarRX.samples(GMSKVals, rssi, RX_BLOCK_SIZE); } if (m_p25Enable) { q15_t P25Vals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_P25Filter, samples, P25Vals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals, RX_BLOCK_SIZE); p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } if (m_dmrEnable || m_ysfEnable) { q15_t C4FSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_C4FSKFilter, samples, C4FSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_rrcFilter, samples, C4FSKVals, RX_BLOCK_SIZE); if (m_dmrEnable) { if (m_duplex) @@ -189,14 +201,14 @@ void CIO::process() } else if (m_modemState == STATE_DSTAR) { if (m_dstarEnable) { q15_t GMSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_GMSKFilter, samples, GMSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_gaussianFilter, samples, GMSKVals, RX_BLOCK_SIZE); dstarRX.samples(GMSKVals, rssi, RX_BLOCK_SIZE); } } else if (m_modemState == STATE_DMR) { if (m_dmrEnable) { q15_t C4FSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_C4FSKFilter, samples, C4FSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_rrcFilter, samples, C4FSKVals, RX_BLOCK_SIZE); if (m_duplex) { // If the transmitter isn't on, use the DMR idle RX to detect the wakeup CSBKs @@ -211,20 +223,23 @@ void CIO::process() } else if (m_modemState == STATE_YSF) { if (m_ysfEnable) { q15_t C4FSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_C4FSKFilter, samples, C4FSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_rrcFilter, samples, C4FSKVals, RX_BLOCK_SIZE); ysfRX.samples(C4FSKVals, rssi, RX_BLOCK_SIZE); } } else if (m_modemState == STATE_P25) { if (m_p25Enable) { - q15_t P25Vals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_P25Filter, samples, P25Vals, RX_BLOCK_SIZE); + q15_t P25Vals1[RX_BLOCK_SIZE]; + ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals1, RX_BLOCK_SIZE); - p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); + q15_t P25Vals2[RX_BLOCK_SIZE]; + ::arm_fir_fast_q15(&m_rcFilter, P25Vals1, P25Vals2, RX_BLOCK_SIZE); + + p25RX.samples(P25Vals2, rssi, RX_BLOCK_SIZE); } } else if (m_modemState == STATE_DSTARCAL) { q15_t GMSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_GMSKFilter, samples, GMSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_gaussianFilter, samples, GMSKVals, RX_BLOCK_SIZE); calDStarRX.samples(GMSKVals, RX_BLOCK_SIZE); } else if (m_modemState == STATE_RSSICAL) { diff --git a/P25TX.cpp b/P25TX.cpp index 1dde485..a6147ba 100644 --- a/P25TX.cpp +++ b/P25TX.cpp @@ -25,18 +25,18 @@ // Generated using rcosdesign(0.2, 8, 5, 'normal') in MATLAB // numTaps = 40, L = 5 -static q15_t P25_C4FSK_FILTER[] = {-413, -751, -845, -587, 0, 740, 1348, 1520, 1063, 0, -1383, -2583, -3021, -2222, 0, 3435, 7488, 11318, 14053, 15044, 14053, +static q15_t RC_0_2_FILTER[] = {-413, -751, -845, -587, 0, 740, 1348, 1520, 1063, 0, -1383, -2583, -3021, -2222, 0, 3435, 7488, 11318, 14053, 15044, 14053, 11318, 7488, 3435, 0, -2222, -3021, -2583, -1383, 0, 1063, 1520, 1348, 740, 0, -587, -845, -751, -413, 0}; -const uint16_t P25_C4FSK_FILTER_PHASE_LEN = 8U; // phaseLength = numTaps/L +const uint16_t RC_0_2_FILTER_PHASE_LEN = 8U; // phaseLength = numTaps/L // Generated in MATLAB using the following commands, and then normalised for unity gain // shape2 = 'Inverse-sinc Lowpass'; // d2 = fdesign.interpolator(2, shape2); // h2 = design(d2, 'SystemObject', true); -static q15_t P25_LP_FILTER[] = {170, 401, 340, -203, -715, -478, 281, 419, -440, -1002, -103, 1114, 528, -1389, -1520, 1108, 2674, -388, -4662, +static q15_t LOWPASS_FILTER[] = {170, 401, 340, -203, -715, -478, 281, 419, -440, -1002, -103, 1114, 528, -1389, -1520, 1108, 2674, -388, -4662, -2132, 9168, 20241, 20241, 9168, -2132, -4662, -388, 2674, 1108, -1520, -1389, 528, 1114, -103, -1002, -440, 419, 281, -478, -715, -203, 340, 401, 170}; -const uint16_t P25_LP_FILTER_LEN = 44U; +const uint16_t LOWPASS_FILTER_LEN = 44U; const q15_t P25_LEVELA = 1698; const q15_t P25_LEVELB = 566; @@ -59,14 +59,14 @@ m_txDelay(240U) // 200ms ::memset(m_modState, 0x00U, 16U * sizeof(q15_t)); ::memset(m_lpState, 0x00U, 70U * sizeof(q15_t)); - m_modFilter.L = P25_RADIO_SYMBOL_LENGTH; - m_modFilter.phaseLength = P25_C4FSK_FILTER_PHASE_LEN; - m_modFilter.pCoeffs = P25_C4FSK_FILTER; - m_modFilter.pState = m_modState; + m_modFilter.L = P25_RADIO_SYMBOL_LENGTH; + m_modFilter.phaseLength = RC_0_2_FILTER_PHASE_LEN; + m_modFilter.pCoeffs = RC_0_2_FILTER; + m_modFilter.pState = m_modState; - m_lpFilter.numTaps = P25_LP_FILTER_LEN; + m_lpFilter.numTaps = LOWPASS_FILTER_LEN; m_lpFilter.pState = m_lpState; - m_lpFilter.pCoeffs = P25_LP_FILTER; + m_lpFilter.pCoeffs = LOWPASS_FILTER; } void CP25TX::process() diff --git a/YSFTX.cpp b/YSFTX.cpp index 5c72efd..e6010b9 100644 --- a/YSFTX.cpp +++ b/YSFTX.cpp @@ -24,10 +24,10 @@ #include "YSFDefines.h" // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB -static q15_t YSF_C4FSK_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, +static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 -const uint16_t YSF_C4FSK_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L +const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L const q15_t YSF_LEVELA_HI = 3900; const q15_t YSF_LEVELB_HI = 1300; @@ -54,10 +54,10 @@ m_loDev(false) { ::memset(m_modState, 0x00U, 16U * sizeof(q15_t)); - m_modFilter.L = YSF_RADIO_SYMBOL_LENGTH; - m_modFilter.phaseLength = YSF_C4FSK_FILTER_PHASE_LEN; - m_modFilter.pCoeffs = YSF_C4FSK_FILTER; - m_modFilter.pState = m_modState; + m_modFilter.L = YSF_RADIO_SYMBOL_LENGTH; + m_modFilter.phaseLength = RRC_0_2_FILTER_PHASE_LEN; + m_modFilter.pCoeffs = RRC_0_2_FILTER; + m_modFilter.pState = m_modState; } void CYSFTX::process() From f31cceac18bc88dfeac145d35538388c12a73b4d Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sat, 15 Apr 2017 13:44:00 -0300 Subject: [PATCH 14/31] Fixing TX inverse SINC filter for P25, and change TX filters for gain=1 --- DMRDMOTX.cpp | 16 ++++++++-------- DMRTX.cpp | 16 ++++++++-------- DStarTX.cpp | 6 +++--- P25TX.cpp | 23 +++++++++++------------ YSFTX.cpp | 24 ++++++++++++------------ 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/DMRDMOTX.cpp b/DMRDMOTX.cpp index fe64db6..3adb172 100644 --- a/DMRDMOTX.cpp +++ b/DMRDMOTX.cpp @@ -23,15 +23,15 @@ #include "DMRSlotType.h" // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB -static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, - 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, - -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 -const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L +static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 850, 219, -720, -1548, -1795, -1172, 237, 1927, 3120, 3073, 1447, -1431, -4544, -6442, + -5735, -1633, 5651, 14822, 23810, 30367, 32767, 30367, 23810, 14822, 5651, -1633, -5735, -6442, + -4544, -1431, 1447, 3073, 3120, 1927, 237, -1172, -1795, -1548, -720, 219, 850}; // numTaps = 45, L = 5 +const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L -const q15_t DMR_LEVELA = 2889; -const q15_t DMR_LEVELB = 963; -const q15_t DMR_LEVELC = -963; -const q15_t DMR_LEVELD = -2889; +const q15_t DMR_LEVELA = 1362; +const q15_t DMR_LEVELB = 454; +const q15_t DMR_LEVELC = -454; +const q15_t DMR_LEVELD = -1362; // The PR FILL and BS Data Sync pattern. const uint8_t IDLE_DATA[] = diff --git a/DMRTX.cpp b/DMRTX.cpp index e202a3f..0c5d055 100644 --- a/DMRTX.cpp +++ b/DMRTX.cpp @@ -23,15 +23,15 @@ #include "DMRSlotType.h" // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB -static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, - 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, - -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 -const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L +static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 850, 219, -720, -1548, -1795, -1172, 237, 1927, 3120, 3073, 1447, -1431, -4544, -6442, + -5735, -1633, 5651, 14822, 23810, 30367, 32767, 30367, 23810, 14822, 5651, -1633, -5735, -6442, + -4544, -1431, 1447, 3073, 3120, 1927, 237, -1172, -1795, -1548, -720, 219, 850}; // numTaps = 45, L = 5 +const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L -const q15_t DMR_LEVELA = 2889; -const q15_t DMR_LEVELB = 963; -const q15_t DMR_LEVELC = -963; -const q15_t DMR_LEVELD = -2889; +const q15_t DMR_LEVELA = 1362; +const q15_t DMR_LEVELB = 454; +const q15_t DMR_LEVELC = -454; +const q15_t DMR_LEVELD = -1362; // The PR FILL and BS Data Sync pattern. const uint8_t IDLE_DATA[] = diff --git a/DStarTX.cpp b/DStarTX.cpp index 4ed0bf6..031d75d 100644 --- a/DStarTX.cpp +++ b/DStarTX.cpp @@ -28,11 +28,11 @@ const uint8_t BIT_SYNC = 0xAAU; const uint8_t FRAME_SYNC[] = {0xEAU, 0xA6U, 0x00U}; // Generated using gaussfir(0.35, 1, 5) in MATLAB -static q15_t GAUSSIAN_0_35_FILTER[] = {0, 0, 0, 0, 212, 743, 1974, 3965, 6026, 6929, 6026, 3965, 1974, 743, 212}; // numTaps = 15, L = 5 +static q15_t GAUSSIAN_0_35_FILTER[] = {0, 0, 0, 0, 1001, 3514, 9333, 18751, 28499, 32767, 28499, 18751, 9333, 3514, 1001}; // numTaps = 15, L = 5 const uint16_t GAUSSIAN_0_35_FILTER_PHASE_LEN = 3U; // phaseLength = numTaps/L -const q15_t DSTAR_LEVEL0 = -4000; -const q15_t DSTAR_LEVEL1 = 4000; +const q15_t DSTAR_LEVEL0 = -841; +const q15_t DSTAR_LEVEL1 = 841; const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; diff --git a/P25TX.cpp b/P25TX.cpp index a6147ba..59ea804 100644 --- a/P25TX.cpp +++ b/P25TX.cpp @@ -25,23 +25,22 @@ // Generated using rcosdesign(0.2, 8, 5, 'normal') in MATLAB // numTaps = 40, L = 5 -static q15_t RC_0_2_FILTER[] = {-413, -751, -845, -587, 0, 740, 1348, 1520, 1063, 0, -1383, -2583, -3021, -2222, 0, 3435, 7488, 11318, 14053, 15044, 14053, - 11318, 7488, 3435, 0, -2222, -3021, -2583, -1383, 0, 1063, 1520, 1348, 740, 0, -587, -845, -751, -413, 0}; -const uint16_t RC_0_2_FILTER_PHASE_LEN = 8U; // phaseLength = numTaps/L +static q15_t RC_0_2_FILTER[] = {-897, -1636, -1840, -1278, 0, 1613, 2936, 3310, 2315, 0, -3011, -5627, -6580, -4839, + 0, 7482, 16311, 24651, 30607, 32767, 30607, 24651, 16311, 7482, 0, -4839, -6580, -5627, + -3011, 0, 2315, 3310, 2936, 1613, 0, -1278, -1840, -1636, -897, 0}; // numTaps = 40, L = 5 +const uint16_t RC_0_2_FILTER_PHASE_LEN = 8U; // phaseLength = numTaps/L // Generated in MATLAB using the following commands, and then normalised for unity gain // shape2 = 'Inverse-sinc Lowpass'; -// d2 = fdesign.interpolator(2, shape2); +// d2 = fdesign.interpolator(1, shape2); // h2 = design(d2, 'SystemObject', true); -static q15_t LOWPASS_FILTER[] = {170, 401, 340, -203, -715, -478, 281, 419, -440, -1002, -103, 1114, 528, -1389, -1520, 1108, 2674, -388, -4662, - -2132, 9168, 20241, 20241, 9168, -2132, -4662, -388, 2674, 1108, -1520, -1389, 528, 1114, -103, -1002, -440, 419, - 281, -478, -715, -203, 340, 401, 170}; -const uint16_t LOWPASS_FILTER_LEN = 44U; +static q15_t LOWPASS_FILTER[] = {1376, -2393, 4584, -8933, 22325, 22325, -8933, 4584, -2393, 1376}; +const uint16_t LOWPASS_FILTER_LEN = 10U; -const q15_t P25_LEVELA = 1698; -const q15_t P25_LEVELB = 566; -const q15_t P25_LEVELC = -566; -const q15_t P25_LEVELD = -1698; +const q15_t P25_LEVELA = 1260; +const q15_t P25_LEVELB = 420; +const q15_t P25_LEVELC = -420; +const q15_t P25_LEVELD = -1260; const uint8_t P25_START_SYNC = 0x77U; diff --git a/YSFTX.cpp b/YSFTX.cpp index e6010b9..c0361c6 100644 --- a/YSFTX.cpp +++ b/YSFTX.cpp @@ -24,20 +24,20 @@ #include "YSFDefines.h" // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB -static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, - 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, - -553, -847, -731, -340, 104, 401}; // numTaps = 45, L = 5 -const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L +static q15_t RRC_0_2_FILTER[] = {0, 0, 0, 0, 850, 219, -720, -1548, -1795, -1172, 237, 1927, 3120, 3073, 1447, -1431, -4544, -6442, + -5735, -1633, 5651, 14822, 23810, 30367, 32767, 30367, 23810, 14822, 5651, -1633, -5735, -6442, + -4544, -1431, 1447, 3073, 3120, 1927, 237, -1172, -1795, -1548, -720, 219, 850}; // numTaps = 45, L = 5 +const uint16_t RRC_0_2_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L -const q15_t YSF_LEVELA_HI = 3900; -const q15_t YSF_LEVELB_HI = 1300; -const q15_t YSF_LEVELC_HI = -1300; -const q15_t YSF_LEVELD_HI = -3900; +const q15_t YSF_LEVELA_HI = 1893; +const q15_t YSF_LEVELB_HI = 631; +const q15_t YSF_LEVELC_HI = -631; +const q15_t YSF_LEVELD_HI = -1893; -const q15_t YSF_LEVELA_LO = 1950; -const q15_t YSF_LEVELB_LO = 650; -const q15_t YSF_LEVELC_LO = -650; -const q15_t YSF_LEVELD_LO = -1950; +const q15_t YSF_LEVELA_LO = 948; +const q15_t YSF_LEVELB_LO = 316; +const q15_t YSF_LEVELC_LO = -316; +const q15_t YSF_LEVELD_LO = -948; const uint8_t YSF_START_SYNC = 0x77U; const uint8_t YSF_END_SYNC = 0xFFU; From 68dfdf0c21378ea921a6001ab9640b1bdf876ddb Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sun, 16 Apr 2017 10:25:34 -0300 Subject: [PATCH 15/31] Testing low pass filter for P25 RX --- IO.cpp | 39 ++++++++++++--------------------------- IO.h | 6 ++---- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/IO.cpp b/IO.cpp index f6e73a8..776911f 100644 --- a/IO.cpp +++ b/IO.cpp @@ -28,18 +28,13 @@ static q15_t RRC_0_2_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 147 -553, -847, -731, -340, 104, 401, 0}; const uint16_t RRC_0_2_FILTER_LEN = 42U; -// Generated using rcosdesign(0.2, 8, 5, 'normal') in MATLAB -static q15_t RC_0_2_FILTER[] = {0, -413, -750, -845, -587, 0, 741, 1347, 1520, 1062, 0, -1383, -2582, -3021, -2222, 0, 3434, 7487, 11318, 14054, 15044, 14054, - 11318, 7487, 3434, 0, -2222, -3021, -2582, -1383, 0, 1062, 1520, 1347, 741, 0, -587, -845, -750, -413}; -const uint16_t RC_0_2_FILTER_LEN = 40U; - // Generated using gaussfir(0.5, 4, 5) in MATLAB static q15_t GAUSSIAN_0_5_FILTER[] = {8, 104, 760, 3158, 7421, 9866, 7421, 3158, 760, 104, 8, 0}; const uint16_t GAUSSIAN_0_5_FILTER_LEN = 12U; // One symbol boxcar filter -static q15_t BOXCAR_FILTER[] = {3000, 3000, 3000, 3000, 3000, 0}; -const uint16_t BOXCAR_FILTER_LEN = 6U; +static q15_t LP_FILTER[] = {130, -392, -1347, 3758, 14235, 14235, 3758, -1347, -392, 130}; +const uint16_t LP_FILTER_LEN = 10U; const uint16_t DC_OFFSET = 2048U; @@ -49,13 +44,11 @@ m_rxBuffer(RX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE), m_rssiBuffer(RX_RINGBUFFER_SIZE), m_rrcFilter(), -m_rcFilter(), m_gaussianFilter(), -m_boxcarFilter(), +m_lpFilter(), m_rrcState(), -m_rcState(), m_gaussianState(), -m_boxcarState(), +m_lpState(), m_pttInvert(false), m_rxLevel(128 * 128), m_cwIdTXLevel(128 * 128), @@ -72,25 +65,20 @@ m_watchdog(0U), m_lockout(false) { ::memset(m_rrcState, 0x00U, 70U * sizeof(q15_t)); - ::memset(m_rcState, 0x00U, 70U * sizeof(q15_t)); ::memset(m_gaussianState, 0x00U, 40U * sizeof(q15_t)); - ::memset(m_boxcarState, 0x00U, 30U * sizeof(q15_t)); + ::memset(m_lpState, 0x00U, 40U * sizeof(q15_t)); m_rrcFilter.numTaps = RRC_0_2_FILTER_LEN; m_rrcFilter.pState = m_rrcState; m_rrcFilter.pCoeffs = RRC_0_2_FILTER; - m_rcFilter.numTaps = RC_0_2_FILTER_LEN; - m_rcFilter.pState = m_rcState; - m_rcFilter.pCoeffs = RC_0_2_FILTER; - m_gaussianFilter.numTaps = GAUSSIAN_0_5_FILTER_LEN; m_gaussianFilter.pState = m_gaussianState; m_gaussianFilter.pCoeffs = GAUSSIAN_0_5_FILTER; - m_boxcarFilter.numTaps = BOXCAR_FILTER_LEN; - m_boxcarFilter.pState = m_boxcarState; - m_boxcarFilter.pCoeffs = BOXCAR_FILTER; + m_lpFilter.numTaps = LP_FILTER_LEN; + m_lpFilter.pState = m_lpState; + m_lpFilter.pCoeffs = LP_FILTER; initInt(); } @@ -179,7 +167,7 @@ void CIO::process() if (m_p25Enable) { q15_t P25Vals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_lpFilter, samples, P25Vals, RX_BLOCK_SIZE); p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } @@ -229,13 +217,10 @@ void CIO::process() } } else if (m_modemState == STATE_P25) { if (m_p25Enable) { - q15_t P25Vals1[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals1, RX_BLOCK_SIZE); + q15_t P25Vals[RX_BLOCK_SIZE]; + ::arm_fir_fast_q15(&m_lpFilter, samples, P25Vals, RX_BLOCK_SIZE); - q15_t P25Vals2[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_rcFilter, P25Vals1, P25Vals2, RX_BLOCK_SIZE); - - p25RX.samples(P25Vals2, rssi, RX_BLOCK_SIZE); + p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } } else if (m_modemState == STATE_DSTARCAL) { q15_t GMSKVals[RX_BLOCK_SIZE]; diff --git a/IO.h b/IO.h index 339b4ac..c5913f1 100644 --- a/IO.h +++ b/IO.h @@ -61,13 +61,11 @@ private: CRSSIRB m_rssiBuffer; arm_fir_instance_q15 m_rrcFilter; - arm_fir_instance_q15 m_rcFilter; arm_fir_instance_q15 m_gaussianFilter; - arm_fir_instance_q15 m_boxcarFilter; + arm_fir_instance_q15 m_lpFilter; q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare - q15_t m_rcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare - q15_t m_boxcarState[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare + q15_t m_lpState[40U]; // NoTaps + BlockSize - 1, 18 + 20 - 1 plus some spare bool m_pttInvert; q15_t m_rxLevel; From 3760404af9c948ac123fd0400991cfa6878726ee Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sun, 16 Apr 2017 10:28:30 -0300 Subject: [PATCH 16/31] Fix comments --- IO.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IO.h b/IO.h index c5913f1..7a23374 100644 --- a/IO.h +++ b/IO.h @@ -65,7 +65,7 @@ private: arm_fir_instance_q15 m_lpFilter; q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare - q15_t m_lpState[40U]; // NoTaps + BlockSize - 1, 18 + 20 - 1 plus some spare + q15_t m_lpState[40U]; // NoTaps + BlockSize - 1, 10 + 20 - 1 plus some spare bool m_pttInvert; q15_t m_rxLevel; From 8b31a53e4ea8773f32ac4a3fbff9a433b2b132f1 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 17 Apr 2017 09:25:38 +0100 Subject: [PATCH 17/31] Revert the DMR DMO TX changes. --- DMRDMOTX.cpp | 69 +++----------------------------------------------- DMRDMOTX.h | 5 ---- SerialPort.cpp | 1 - 3 files changed, 4 insertions(+), 71 deletions(-) diff --git a/DMRDMOTX.cpp b/DMRDMOTX.cpp index 6ce2957..e1ac6c6 100644 --- a/DMRDMOTX.cpp +++ b/DMRDMOTX.cpp @@ -42,21 +42,6 @@ const q15_t DMR_LEVELB = 963; const q15_t DMR_LEVELC = -963; const q15_t DMR_LEVELD = -2889; -// The PR FILL and BS Data Sync pattern. -const uint8_t IDLE_DATA[] = - {0x53U, 0xC2U, 0x5EU, 0xABU, 0xA8U, 0x67U, 0x1DU, 0xC7U, 0x38U, 0x3BU, 0xD9U, - 0x36U, 0x00U, 0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U, 0x03U, 0xF6U, - 0xE4U, 0x65U, 0x17U, 0x1BU, 0x48U, 0xCAU, 0x6DU, 0x4FU, 0xC6U, 0x10U, 0xB4U}; - -const uint8_t CACH_INTERLEAVE[] = - {1U, 2U, 3U, 5U, 6U, 7U, 9U, 10U, 11U, 13U, 15U, 16U, 17U, 19U, 20U, 21U, 23U, - 25U, 26U, 27U, 29U, 30U, 31U, 33U, 34U, 35U, 37U, 39U, 40U, 41U, 43U, 44U, 45U, 47U, - 49U, 50U, 51U, 53U, 54U, 55U, 57U, 58U, 59U, 61U, 63U, 64U, 65U, 67U, 68U, 69U, 71U, - 73U, 74U, 75U, 77U, 78U, 79U, 81U, 82U, 83U, 85U, 87U, 88U, 89U, 91U, 92U, 93U, 95U}; - -const uint8_t EMPTY_SHORT_LC[] = - {0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; - const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) @@ -71,9 +56,7 @@ m_modState(), m_poBuffer(), m_poLen(0U), m_poPtr(0U), -m_txDelay(240U), // 200ms -m_idle(), -m_cachPtr(0U) +m_txDelay(240U) // 200ms { ::memset(m_modState, 0x00U, 16U * sizeof(q15_t)); @@ -92,15 +75,11 @@ void CDMRDMOTX::process() m_poLen = m_txDelay; } else { - createCACH(m_poBuffer + 0U, 0U); + for (unsigned int i = 0U; i < 72U; i++) + m_poBuffer[i] = DMR_SYNC; for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++) - m_poBuffer[i + 3U] = m_fifo.get(); - - createCACH(m_poBuffer + 36U, 1U); - - for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++) - m_poBuffer[i + 39U] = m_idle[i]; + m_poBuffer[i + 39U] = m_fifo.get(); m_poLen = 72U; } @@ -184,43 +163,3 @@ void CDMRDMOTX::setTXDelay(uint8_t delay) m_txDelay = 1200U; } -void CDMRDMOTX::createCACH(uint8_t* buffer, uint8_t slotIndex) -{ - if (m_cachPtr >= 12U) - m_cachPtr = 0U; - - ::memcpy(buffer, EMPTY_SHORT_LC + m_cachPtr, 3U); - - bool at = true; - bool tc = slotIndex == 1U; - bool ls0 = true; // For 1 and 2 - bool ls1 = true; - - if (m_cachPtr == 0U) // For 0 - ls1 = false; - else if (m_cachPtr == 9U) // For 3 - ls0 = false; - - bool h0 = at ^ tc ^ ls1; - bool h1 = tc ^ ls1 ^ ls0; - bool h2 = at ^ tc ^ ls0; - - buffer[0U] |= at ? 0x80U : 0x00U; - buffer[0U] |= tc ? 0x08U : 0x00U; - buffer[1U] |= ls1 ? 0x80U : 0x00U; - buffer[1U] |= ls0 ? 0x08U : 0x00U; - buffer[1U] |= h0 ? 0x02U : 0x00U; - buffer[2U] |= h1 ? 0x20U : 0x00U; - buffer[2U] |= h2 ? 0x02U : 0x00U; - - m_cachPtr += 3U; -} - -void CDMRDMOTX::setColorCode(uint8_t colorCode) -{ - ::memcpy(m_idle, IDLE_DATA, DMR_FRAME_LENGTH_BYTES); - - CDMRSlotType slotType; - slotType.encode(colorCode, DT_IDLE, m_idle); -} - diff --git a/DMRDMOTX.h b/DMRDMOTX.h index 2e49ff7..62ef2c1 100644 --- a/DMRDMOTX.h +++ b/DMRDMOTX.h @@ -37,8 +37,6 @@ public: uint8_t getSpace() const; - void setColorCode(uint8_t colorCode); - private: CSerialRB m_fifo; arm_fir_interpolate_instance_q15 m_modFilter; @@ -47,10 +45,7 @@ private: uint16_t m_poLen; uint16_t m_poPtr; uint32_t m_txDelay; - uint8_t m_idle[DMR_FRAME_LENGTH_BYTES]; - uint8_t m_cachPtr; - void createCACH(uint8_t* buffer, uint8_t slotIndex); void writeByte(uint8_t c); }; diff --git a/SerialPort.cpp b/SerialPort.cpp index 09c6979..c67c8f3 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -282,7 +282,6 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) dmrTX.setColorCode(colorCode); dmrRX.setColorCode(colorCode); dmrRX.setDelay(dmrDelay); - dmrDMOTX.setColorCode(colorCode); dmrDMORX.setColorCode(colorCode); dmrIdleRX.setColorCode(colorCode); From 1d6ca99df9f0a625780f21061af1ce6d3cc32d5f Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 17 Apr 2017 23:01:19 +0200 Subject: [PATCH 18/31] Make Makefile compatible with builds on Windows --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 4b2a78c..260ae5d 100644 --- a/Makefile +++ b/Makefile @@ -188,8 +188,14 @@ endif # Export the current git version if the index file exists, else 000... GitVersion.h: +ifdef SYSTEMROOT + echo #define GITVERSION "0000000" > $@ +else ifdef SystemRoot + echo #define GITVERSION "0000000" > $@ +else ifneq ("$(wildcard .git/index)","") echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@ else echo "#define GITVERSION \"0000000\"" > $@ endif +endif From 99ac6146d9f16e33bcde3f9c44f2abd17436a48d Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 24 Apr 2017 18:02:36 +0100 Subject: [PATCH 19/31] Add a ring buffer to the serial repeater. Uncompiled on the STM32 platform. --- Debug.h | 1 - SerialArduino.cpp | 16 ++++++++++++- SerialPort.cpp | 57 +++++++++++++++++-------------------------- SerialPort.h | 14 +++++------ SerialSTM.cpp | 61 ++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 96 insertions(+), 53 deletions(-) diff --git a/Debug.h b/Debug.h index e8be149..599fbfd 100644 --- a/Debug.h +++ b/Debug.h @@ -27,7 +27,6 @@ #define DEBUG3(a,b,c) serial.writeDebug((a),(b),(c)) #define DEBUG4(a,b,c,d) serial.writeDebug((a),(b),(c),(d)) #define DEBUG5(a,b,c,d,e) serial.writeDebug((a),(b),(c),(d),(e)) -#define ASSERT(a) serial.writeAssert((a),#a,__FILE__,__LINE__) #endif diff --git a/SerialArduino.cpp b/SerialArduino.cpp index e723fee..7240a41 100644 --- a/SerialArduino.cpp +++ b/SerialArduino.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -54,6 +54,20 @@ int CSerialPort::availableInt(uint8_t n) } } +int CSerialPort::availableForWriteInt(uint8_t n) +{ + switch (n) { + case 1U: + return Serial.availableForWrite(); + case 2U: + return Serial2.availableForWrite(); + case 3U: + return Serial3.availableForWrite(); + default: + return false; + } +} + uint8_t CSerialPort::readInt(uint8_t n) { switch (n) { diff --git a/SerialPort.cpp b/SerialPort.cpp index d3b9be4..19c7f52 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -93,7 +93,8 @@ CSerialPort::CSerialPort() : m_buffer(), m_ptr(0U), m_len(0U), -m_debug(false) +m_debug(false), +m_repeat() { } @@ -643,8 +644,10 @@ void CSerialPort::process() break; #if defined(SERIAL_REPEATER) - case MMDVM_SERIAL: - writeInt(3U, m_buffer + 3U, m_len - 3U); + case MMDVM_SERIAL: { + for (uint8_t i = 3U; i < m_len; i++) + m_repeat.put(m_buffer[i]); + } break; #endif @@ -661,9 +664,22 @@ void CSerialPort::process() } #if defined(SERIAL_REPEATER) - // Drain any incoming serial data - while (availableInt(3U)) - readInt(3U); + // Write any outgoing serial data + uint16_t space = m_repeat.getData(); + if (space > 0U) { + int avail = availableForWriteInt(3U); + if (avail < space) + space = avail; + + for (uint16_t i = 0U; i < space; i++) { + uint8_t c = m_repeat.get(); + writeInt(3U, &c, 1U); + } + } + + // Read any incoming serial data + while (availableInt(3U)) + readInt(3U); #endif } @@ -1058,32 +1074,3 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n writeInt(1U, reply, count, true); } - -void CSerialPort::writeAssert(bool cond, const char* text, const char* file, long line) -{ - if (cond) - return; - - uint8_t reply[200U]; - - reply[0U] = MMDVM_FRAME_START; - reply[1U] = 0U; - reply[2U] = MMDVM_DEBUG2; - - uint8_t count = 3U; - for (uint8_t i = 0U; text[i] != '\0'; i++, count++) - reply[count] = text[i]; - - reply[count++] = ' '; - - for (uint8_t i = 0U; file[i] != '\0'; i++, count++) - reply[count] = file[i]; - - reply[count++] = (line >> 8) & 0xFF; - reply[count++] = (line >> 0) & 0xFF; - - reply[1U] = count; - - writeInt(1U, reply, count, true); -} - diff --git a/SerialPort.h b/SerialPort.h index 8dc7658..69ce699 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -21,6 +21,7 @@ #include "Config.h" #include "Globals.h" +#include "SerialRB.h" class CSerialPort { @@ -55,13 +56,12 @@ public: void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3); void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3, int16_t n4); - void writeAssert(bool cond, const char* text, const char* file, long line); - private: - uint8_t m_buffer[256U]; - uint8_t m_ptr; - uint8_t m_len; - bool m_debug; + uint8_t m_buffer[256U]; + uint8_t m_ptr; + uint8_t m_len; + bool m_debug; + CSerialRB m_repeat; void sendACK(); void sendNAK(uint8_t err); @@ -74,9 +74,9 @@ private: // Hardware versions void beginInt(uint8_t n, int speed); int availableInt(uint8_t n); + int availableForWriteInt(uint8_t n); uint8_t readInt(uint8_t n); void writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush = false); }; #endif - diff --git a/SerialSTM.cpp b/SerialSTM.cpp index 8fdb127..eb543c8 100644 --- a/SerialSTM.cpp +++ b/SerialSTM.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2016 by Jim McLaughlin KI6ZUM * Copyright (C) 2016, 2017 by Andy Uribe CA6JAU + * Copyright (c) 2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -207,7 +208,7 @@ void InitUSART1(int speed) RXSerialfifoinit1(); } -uint8_t AvailUSART1(void) +uint8_t AvailUSART1() { if (RXSerialfifolevel1() > 0U) return 1U; @@ -215,7 +216,12 @@ uint8_t AvailUSART1(void) return 0U; } -uint8_t ReadUSART1(void) +int AvailForWriteUSART1() +{ + return TXSerialfifolevel1(); +} + +uint8_t ReadUSART1() { uint8_t data_c = RXSerialfifo1[RXSerialfifotail1]; @@ -395,7 +401,7 @@ void InitUSART2(int speed) RXSerialfifoinit2(); } -uint8_t AvailUSART2(void) +uint8_t AvailUSART2() { if (RXSerialfifolevel2() > 0U) return 1U; @@ -403,7 +409,12 @@ uint8_t AvailUSART2(void) return 0U; } -uint8_t ReadUSART2(void) +int AvailForWriteUSART2() +{ + return TXSerialfifolevel2(); +} + +uint8_t ReadUSART2() { uint8_t data_c = RXSerialfifo2[RXSerialfifotail2]; @@ -583,7 +594,7 @@ void InitUSART3(int speed) RXSerialfifoinit3(); } -uint8_t AvailUSART3(void) +uint8_t AvailUSART3() { if (RXSerialfifolevel3() > 0U) return 1U; @@ -591,7 +602,12 @@ uint8_t AvailUSART3(void) return 0U; } -uint8_t ReadUSART3(void) +int AvailForWriteUSART3() +{ + return TXSerialfifolevel3(); +} + +uint8_t ReadUSART3() { uint8_t data_c = RXSerialfifo3[RXSerialfifotail3]; @@ -775,7 +791,7 @@ void InitUART5(int speed) RXSerialfifoinit5(); } -uint8_t AvailUART5(void) +uint8_t AvailUART5() { if (RXSerialfifolevel5() > 0U) return 1U; @@ -783,7 +799,12 @@ uint8_t AvailUART5(void) return 0U; } -uint8_t ReadUART5(void) +int AvailForWriteUSART5() +{ + return TXSerialfifolevel5(); +} + +uint8_t ReadUART5() { uint8_t data_c = RXSerialfifo5[RXSerialfifotail5]; @@ -847,7 +868,29 @@ int CSerialPort::availableInt(uint8_t n) return AvailUART5(); #endif default: - return false; + return 0; + } +} + +int CSerialPort::availableForWriteInt(uint8_t n) +{ + switch (n) { + case 1U: + #if defined(STM32F4_DISCOVERY) + return AvailForWriteUSART3(); + #elif defined(STM32F4_PI) + return AvailForWriteUSART1(); + #elif defined(STM32F4_NUCLEO) + return AvailForWriteUSART2(); + #endif + case 3U: + #if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER) + return AvailForWriteUSART1(); + #else + return AvailForWriteUART5(); + #endif + default: + return 0; } } From 0fb75f974e2cbac66bfcd9f670dfa44ed3ff9bf0 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 25 Apr 2017 08:03:10 +0100 Subject: [PATCH 20/31] Fix typo USART5 -> UART5 --- SerialSTM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialSTM.cpp b/SerialSTM.cpp index eb543c8..426f780 100644 --- a/SerialSTM.cpp +++ b/SerialSTM.cpp @@ -799,7 +799,7 @@ uint8_t AvailUART5() return 0U; } -int AvailForWriteUSART5() +int AvailForWriteUART5() { return TXSerialfifolevel5(); } From 7e15d1ac70b2a9b489c9a823374203d0ec04ae0d Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 26 Apr 2017 08:18:00 +0100 Subject: [PATCH 21/31] Fix the TX FIFO write level calculation. --- SerialSTM.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SerialSTM.cpp b/SerialSTM.cpp index 426f780..7f6ba47 100644 --- a/SerialSTM.cpp +++ b/SerialSTM.cpp @@ -218,7 +218,7 @@ uint8_t AvailUSART1() int AvailForWriteUSART1() { - return TXSerialfifolevel1(); + return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel1(); } uint8_t ReadUSART1() @@ -411,7 +411,7 @@ uint8_t AvailUSART2() int AvailForWriteUSART2() { - return TXSerialfifolevel2(); + return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel2(); } uint8_t ReadUSART2() @@ -604,7 +604,7 @@ uint8_t AvailUSART3() int AvailForWriteUSART3() { - return TXSerialfifolevel3(); + return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel3(); } uint8_t ReadUSART3() @@ -801,7 +801,7 @@ uint8_t AvailUART5() int AvailForWriteUART5() { - return TXSerialfifolevel5(); + return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel5(); } uint8_t ReadUART5() From 2506690e9849879393648efe217a066e6871d95f Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 28 Apr 2017 16:55:55 +0100 Subject: [PATCH 22/31] Revert "Fix comments" This reverts commit 3760404af9c948ac123fd0400991cfa6878726ee. --- IO.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IO.h b/IO.h index 7a23374..c5913f1 100644 --- a/IO.h +++ b/IO.h @@ -65,7 +65,7 @@ private: arm_fir_instance_q15 m_lpFilter; q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare - q15_t m_lpState[40U]; // NoTaps + BlockSize - 1, 10 + 20 - 1 plus some spare + q15_t m_lpState[40U]; // NoTaps + BlockSize - 1, 18 + 20 - 1 plus some spare bool m_pttInvert; q15_t m_rxLevel; From a2cf35629ba684c837c089ca2055cfddf768637b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 28 Apr 2017 16:56:18 +0100 Subject: [PATCH 23/31] Revert "Testing low pass filter for P25 RX" This reverts commit 68dfdf0c21378ea921a6001ab9640b1bdf876ddb. --- IO.cpp | 39 +++++++++++++++++++++++++++------------ IO.h | 6 ++++-- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/IO.cpp b/IO.cpp index 776911f..f6e73a8 100644 --- a/IO.cpp +++ b/IO.cpp @@ -28,13 +28,18 @@ static q15_t RRC_0_2_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 147 -553, -847, -731, -340, 104, 401, 0}; const uint16_t RRC_0_2_FILTER_LEN = 42U; +// Generated using rcosdesign(0.2, 8, 5, 'normal') in MATLAB +static q15_t RC_0_2_FILTER[] = {0, -413, -750, -845, -587, 0, 741, 1347, 1520, 1062, 0, -1383, -2582, -3021, -2222, 0, 3434, 7487, 11318, 14054, 15044, 14054, + 11318, 7487, 3434, 0, -2222, -3021, -2582, -1383, 0, 1062, 1520, 1347, 741, 0, -587, -845, -750, -413}; +const uint16_t RC_0_2_FILTER_LEN = 40U; + // Generated using gaussfir(0.5, 4, 5) in MATLAB static q15_t GAUSSIAN_0_5_FILTER[] = {8, 104, 760, 3158, 7421, 9866, 7421, 3158, 760, 104, 8, 0}; const uint16_t GAUSSIAN_0_5_FILTER_LEN = 12U; // One symbol boxcar filter -static q15_t LP_FILTER[] = {130, -392, -1347, 3758, 14235, 14235, 3758, -1347, -392, 130}; -const uint16_t LP_FILTER_LEN = 10U; +static q15_t BOXCAR_FILTER[] = {3000, 3000, 3000, 3000, 3000, 0}; +const uint16_t BOXCAR_FILTER_LEN = 6U; const uint16_t DC_OFFSET = 2048U; @@ -44,11 +49,13 @@ m_rxBuffer(RX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE), m_rssiBuffer(RX_RINGBUFFER_SIZE), m_rrcFilter(), +m_rcFilter(), m_gaussianFilter(), -m_lpFilter(), +m_boxcarFilter(), m_rrcState(), +m_rcState(), m_gaussianState(), -m_lpState(), +m_boxcarState(), m_pttInvert(false), m_rxLevel(128 * 128), m_cwIdTXLevel(128 * 128), @@ -65,20 +72,25 @@ m_watchdog(0U), m_lockout(false) { ::memset(m_rrcState, 0x00U, 70U * sizeof(q15_t)); + ::memset(m_rcState, 0x00U, 70U * sizeof(q15_t)); ::memset(m_gaussianState, 0x00U, 40U * sizeof(q15_t)); - ::memset(m_lpState, 0x00U, 40U * sizeof(q15_t)); + ::memset(m_boxcarState, 0x00U, 30U * sizeof(q15_t)); m_rrcFilter.numTaps = RRC_0_2_FILTER_LEN; m_rrcFilter.pState = m_rrcState; m_rrcFilter.pCoeffs = RRC_0_2_FILTER; + m_rcFilter.numTaps = RC_0_2_FILTER_LEN; + m_rcFilter.pState = m_rcState; + m_rcFilter.pCoeffs = RC_0_2_FILTER; + m_gaussianFilter.numTaps = GAUSSIAN_0_5_FILTER_LEN; m_gaussianFilter.pState = m_gaussianState; m_gaussianFilter.pCoeffs = GAUSSIAN_0_5_FILTER; - m_lpFilter.numTaps = LP_FILTER_LEN; - m_lpFilter.pState = m_lpState; - m_lpFilter.pCoeffs = LP_FILTER; + m_boxcarFilter.numTaps = BOXCAR_FILTER_LEN; + m_boxcarFilter.pState = m_boxcarState; + m_boxcarFilter.pCoeffs = BOXCAR_FILTER; initInt(); } @@ -167,7 +179,7 @@ void CIO::process() if (m_p25Enable) { q15_t P25Vals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_lpFilter, samples, P25Vals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals, RX_BLOCK_SIZE); p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } @@ -217,10 +229,13 @@ void CIO::process() } } else if (m_modemState == STATE_P25) { if (m_p25Enable) { - q15_t P25Vals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_lpFilter, samples, P25Vals, RX_BLOCK_SIZE); + q15_t P25Vals1[RX_BLOCK_SIZE]; + ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals1, RX_BLOCK_SIZE); - p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); + q15_t P25Vals2[RX_BLOCK_SIZE]; + ::arm_fir_fast_q15(&m_rcFilter, P25Vals1, P25Vals2, RX_BLOCK_SIZE); + + p25RX.samples(P25Vals2, rssi, RX_BLOCK_SIZE); } } else if (m_modemState == STATE_DSTARCAL) { q15_t GMSKVals[RX_BLOCK_SIZE]; diff --git a/IO.h b/IO.h index c5913f1..339b4ac 100644 --- a/IO.h +++ b/IO.h @@ -61,11 +61,13 @@ private: CRSSIRB m_rssiBuffer; arm_fir_instance_q15 m_rrcFilter; + arm_fir_instance_q15 m_rcFilter; arm_fir_instance_q15 m_gaussianFilter; - arm_fir_instance_q15 m_lpFilter; + arm_fir_instance_q15 m_boxcarFilter; q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare + q15_t m_rcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare - q15_t m_lpState[40U]; // NoTaps + BlockSize - 1, 18 + 20 - 1 plus some spare + q15_t m_boxcarState[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare bool m_pttInvert; q15_t m_rxLevel; From 7b6801741165a4906ad486a09126d732fd9acf91 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 29 Apr 2017 10:08:38 +0100 Subject: [PATCH 24/31] Finish reverting to the master branch P25 filtering. --- IO.cpp | 21 +++------------------ IO.h | 2 -- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/IO.cpp b/IO.cpp index f6e73a8..35d4a7a 100644 --- a/IO.cpp +++ b/IO.cpp @@ -28,11 +28,6 @@ static q15_t RRC_0_2_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 147 -553, -847, -731, -340, 104, 401, 0}; const uint16_t RRC_0_2_FILTER_LEN = 42U; -// Generated using rcosdesign(0.2, 8, 5, 'normal') in MATLAB -static q15_t RC_0_2_FILTER[] = {0, -413, -750, -845, -587, 0, 741, 1347, 1520, 1062, 0, -1383, -2582, -3021, -2222, 0, 3434, 7487, 11318, 14054, 15044, 14054, - 11318, 7487, 3434, 0, -2222, -3021, -2582, -1383, 0, 1062, 1520, 1347, 741, 0, -587, -845, -750, -413}; -const uint16_t RC_0_2_FILTER_LEN = 40U; - // Generated using gaussfir(0.5, 4, 5) in MATLAB static q15_t GAUSSIAN_0_5_FILTER[] = {8, 104, 760, 3158, 7421, 9866, 7421, 3158, 760, 104, 8, 0}; const uint16_t GAUSSIAN_0_5_FILTER_LEN = 12U; @@ -49,11 +44,9 @@ m_rxBuffer(RX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE), m_rssiBuffer(RX_RINGBUFFER_SIZE), m_rrcFilter(), -m_rcFilter(), m_gaussianFilter(), m_boxcarFilter(), m_rrcState(), -m_rcState(), m_gaussianState(), m_boxcarState(), m_pttInvert(false), @@ -72,7 +65,6 @@ m_watchdog(0U), m_lockout(false) { ::memset(m_rrcState, 0x00U, 70U * sizeof(q15_t)); - ::memset(m_rcState, 0x00U, 70U * sizeof(q15_t)); ::memset(m_gaussianState, 0x00U, 40U * sizeof(q15_t)); ::memset(m_boxcarState, 0x00U, 30U * sizeof(q15_t)); @@ -80,10 +72,6 @@ m_lockout(false) m_rrcFilter.pState = m_rrcState; m_rrcFilter.pCoeffs = RRC_0_2_FILTER; - m_rcFilter.numTaps = RC_0_2_FILTER_LEN; - m_rcFilter.pState = m_rcState; - m_rcFilter.pCoeffs = RC_0_2_FILTER; - m_gaussianFilter.numTaps = GAUSSIAN_0_5_FILTER_LEN; m_gaussianFilter.pState = m_gaussianState; m_gaussianFilter.pCoeffs = GAUSSIAN_0_5_FILTER; @@ -229,13 +217,10 @@ void CIO::process() } } else if (m_modemState == STATE_P25) { if (m_p25Enable) { - q15_t P25Vals1[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals1, RX_BLOCK_SIZE); + q15_t P25Vals[RX_BLOCK_SIZE]; + ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals, RX_BLOCK_SIZE); - q15_t P25Vals2[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_rcFilter, P25Vals1, P25Vals2, RX_BLOCK_SIZE); - - p25RX.samples(P25Vals2, rssi, RX_BLOCK_SIZE); + p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } } else if (m_modemState == STATE_DSTARCAL) { q15_t GMSKVals[RX_BLOCK_SIZE]; diff --git a/IO.h b/IO.h index 339b4ac..80a6d28 100644 --- a/IO.h +++ b/IO.h @@ -61,11 +61,9 @@ private: CRSSIRB m_rssiBuffer; arm_fir_instance_q15 m_rrcFilter; - arm_fir_instance_q15 m_rcFilter; arm_fir_instance_q15 m_gaussianFilter; arm_fir_instance_q15 m_boxcarFilter; q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare - q15_t m_rcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare q15_t m_boxcarState[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare From 1a9c0d3ee7187857a7f0b6ae1f4b8da3350f5734 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 1 May 2017 09:22:05 +0100 Subject: [PATCH 25/31] Bump the version date. --- SerialPort.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPort.cpp b/SerialPort.cpp index 19c7f52..3ee2f21 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -73,9 +73,9 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #if defined(EXTERNAL_OSC) -#define DESCRIPTION "MMDVM 20170406 TCXO (D-Star/DMR/System Fusion/P25/RSSI/CW Id)" +#define DESCRIPTION "MMDVM 20170501 TCXO (D-Star/DMR/System Fusion/P25/RSSI/CW Id)" #else -#define DESCRIPTION "MMDVM 20170406 (D-Star/DMR/System Fusion/P25/RSSI/CW Id)" +#define DESCRIPTION "MMDVM 20170501 (D-Star/DMR/System Fusion/P25/RSSI/CW Id)" #endif #if defined(GITVERSION) From 9722c85585487333be9da53e0c155838c7141a55 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 5 May 2017 08:10:36 +0100 Subject: [PATCH 26/31] Normalise the inverse-sinc lowpass filter to unity gain. --- P25TX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/P25TX.cpp b/P25TX.cpp index 59ea804..2901a74 100644 --- a/P25TX.cpp +++ b/P25TX.cpp @@ -34,7 +34,7 @@ const uint16_t RC_0_2_FILTER_PHASE_LEN = 8U; // phaseLength = numTaps/L // shape2 = 'Inverse-sinc Lowpass'; // d2 = fdesign.interpolator(1, shape2); // h2 = design(d2, 'SystemObject', true); -static q15_t LOWPASS_FILTER[] = {1376, -2393, 4584, -8933, 22325, 22325, -8933, 4584, -2393, 1376}; +static q15_t LOWPASS_FILTER[] = {1294, -2251, 4312, -8402, 20999, 20999, -8402, 4312, -2251, 1294}; const uint16_t LOWPASS_FILTER_LEN = 10U; const q15_t P25_LEVELA = 1260; From e53aec348e74893ffba17f87528ab2ad4abcd5e6 Mon Sep 17 00:00:00 2001 From: Wojciech Krutnik Date: Wed, 31 May 2017 15:04:00 +0200 Subject: [PATCH 27/31] Change port definition for bootloader (BL_PORT) in Makefile.CMSIS --- Makefile.CMSIS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.CMSIS b/Makefile.CMSIS index 703821e..a4ee604 100644 --- a/Makefile.CMSIS +++ b/Makefile.CMSIS @@ -39,7 +39,7 @@ OBJDIR:=obj BINDIR:=bin # Port definition for programming via bootloader (using stm32flash) -BL_PORT:=/dev/ttyUSB0 +BL_PORT:=ttyUSB0 @@ -102,7 +102,7 @@ program: $(HEX) $(ELF) .PHONY: program_bl program_bl: $(HEX) $(ELF) - stm32flash -w $(HEX) -v $(BL_PORT) + stm32flash -w $(HEX) -v /dev/$(BL_PORT) $(SIZE) $(ELF) .PHONY: run From 6d5f098e41d83d35b8f88897796003f3d68117d3 Mon Sep 17 00:00:00 2001 From: Wojciech Krutnik Date: Wed, 31 May 2017 15:05:58 +0200 Subject: [PATCH 28/31] Move host communication port from USART2 to USART1 --- IOSTM_CMSIS.cpp | 16 ++++++------ SerialSTM_CMSIS.cpp | 59 +++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 6f75fe2..abf8747 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -46,8 +46,8 @@ TX PA4 analog output (DAC_OUT1) EXT_CLK PA15 input (AF: TIM2_CH1_ETR) -USART2_TXD PA2 output (AF) -USART2_RXD PA3 input (AF) +USART1_TXD PA9 output (AF) +USART1_RXD PA10 input (AF) */ @@ -91,10 +91,10 @@ USART2_RXD PA3 input (AF) #define SRC_EXT_CLK 15 #define PORT_EXT_CLK GPIOA -#define PIN_USART2_TXD 2 -#define PORT_USART2_TXD GPIOA -#define PIN_USART2_RXD 3 -#define PORT_USART2_RXD GPIOA +#define PIN_USART1_TXD 9 +#define PORT_USART1_TXD GPIOA +#define PIN_USART1_RXD 10 +#define PORT_USART1_RXD GPIOA #else // defined(STM32F1_POG) #error "Either STM32F1_POG, or sth need to be defined" @@ -188,8 +188,8 @@ static inline void GPIOInit() #endif #endif - GPIOConfigPin(PORT_USART2_TXD, PIN_USART2_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1); - GPIOConfigPin(PORT_USART2_RXD, PIN_USART2_RXD, GPIO_CRL_CNF0_0); + GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1); + GPIOConfigPin(PORT_USART1_RXD, PIN_USART1_RXD, GPIO_CRL_CNF0_0); AFIO->MAPR = (AFIO->MAPR & ~AFIO_MAPR_SWJ_CFG) | AFIO_MAPR_SWJ_CFG_1; } diff --git a/SerialSTM_CMSIS.cpp b/SerialSTM_CMSIS.cpp index 3f57b68..38127ac 100644 --- a/SerialSTM_CMSIS.cpp +++ b/SerialSTM_CMSIS.cpp @@ -26,10 +26,11 @@ Pin definitions (configuration in IOSTM_CMSIS.c): - Host communication: -USART2 - TXD PA2 - RXD PA3 +USART1 - TXD PA9 - RXD PA10 */ + #if defined(STM32F1) // BaudRate calculator macro @@ -42,22 +43,22 @@ USART2 - TXD PA2 - RXD PA3 #define USART_BUFFER_SIZE 256U DECLARE_RINGBUFFER_TYPE(USARTBuffer, USART_BUFFER_SIZE); -/* ************* USART2 ***************** */ -static volatile USARTBuffer_t txBuffer2={.size=USART_BUFFER_SIZE}; -static volatile USARTBuffer_t rxBuffer2={.size=USART_BUFFER_SIZE}; +/* ************* USART1 ***************** */ +static volatile USARTBuffer_t txBuffer1={.size=USART_BUFFER_SIZE}; +static volatile USARTBuffer_t rxBuffer1={.size=USART_BUFFER_SIZE}; extern "C" { - bitband_t txe = (bitband_t)BITBAND_PERIPH(&USART2->SR, USART_SR_TXE_Pos); - bitband_t rxne = (bitband_t)BITBAND_PERIPH(&USART2->SR, USART_SR_RXNE_Pos); - bitband_t txeie = (bitband_t)BITBAND_PERIPH(&USART2->CR1, USART_CR1_TXEIE_Pos); + bitband_t txe = (bitband_t)BITBAND_PERIPH(&USART1->SR, USART_SR_TXE_Pos); + bitband_t rxne = (bitband_t)BITBAND_PERIPH(&USART1->SR, USART_SR_RXNE_Pos); + bitband_t txeie = (bitband_t)BITBAND_PERIPH(&USART1->CR1, USART_CR1_TXEIE_Pos); - RAMFUNC void USART2_IRQHandler() + RAMFUNC void USART1_IRQHandler() { /* Transmitting data */ if(*txe){ - if(!(RINGBUFF_EMPTY(txBuffer2))){ - USART2->DR = RINGBUFF_READ(txBuffer2); + if(!(RINGBUFF_EMPTY(txBuffer1))){ + USART1->DR = RINGBUFF_READ(txBuffer1); }else{ /* Buffer empty */ *txeie = 0; /* Don't send further data */ } @@ -65,42 +66,42 @@ extern "C" { /* Receiving data */ if(*rxne){ - RINGBUFF_WRITE(rxBuffer2, USART2->DR); + RINGBUFF_WRITE(rxBuffer1, USART1->DR); } } } -void USART2Init(int speed) +void USART1Init(int speed) { - RCC->APB1ENR |= RCC_APB1ENR_USART2EN; + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; - USART2->BRR = USART_BRR(36000000UL, speed); + USART1->BRR = USART_BRR(72000000UL, speed); - USART2->CR1 = USART_CR1_UE | USART_CR1_TE | + USART1->CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE; // Enable USART and RX interrupt - NVIC_EnableIRQ(USART2_IRQn); + NVIC_EnableIRQ(USART1_IRQn); } -RAMFUNC void USART2TxData(const uint8_t* data, uint16_t length) +RAMFUNC void USART1TxData(const uint8_t* data, uint16_t length) { - NVIC_DisableIRQ(USART2_IRQn); + NVIC_DisableIRQ(USART1_IRQn); /* Check remaining space in buffer */ - if(RINGBUFF_COUNT(txBuffer2) + length > RINGBUFF_SIZE(txBuffer2)){ - NVIC_EnableIRQ(USART2_IRQn); + if(RINGBUFF_COUNT(txBuffer1) + length > RINGBUFF_SIZE(txBuffer1)){ + NVIC_EnableIRQ(USART1_IRQn); return; } /* Append data to buffer */ while(length--){ - RINGBUFF_WRITE(txBuffer2, *(data++)); + RINGBUFF_WRITE(txBuffer1, *(data++)); } /* Start sending data */ - USART2->CR1 |= USART_CR1_TXEIE; + USART1->CR1 |= USART_CR1_TXEIE; - NVIC_EnableIRQ(USART2_IRQn); + NVIC_EnableIRQ(USART1_IRQn); } @@ -110,7 +111,7 @@ void CSerialPort::beginInt(uint8_t n, int speed) { switch (n) { case 1U: - USART2Init(speed); + USART1Init(speed); break; default: break; @@ -121,7 +122,7 @@ int CSerialPort::availableInt(uint8_t n) { switch (n) { case 1U: - return !RINGBUFF_EMPTY(rxBuffer2); + return !RINGBUFF_EMPTY(rxBuffer1); default: return false; } @@ -131,7 +132,7 @@ uint8_t CSerialPort::readInt(uint8_t n) { switch (n) { case 1U: - return RINGBUFF_READ(rxBuffer2); + return RINGBUFF_READ(rxBuffer1); default: return 0U; } @@ -139,15 +140,15 @@ uint8_t CSerialPort::readInt(uint8_t n) void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush) { - bitband_t tc = (bitband_t)BITBAND_PERIPH(&USART2->SR, USART_SR_TC_Pos); + bitband_t tc = (bitband_t)BITBAND_PERIPH(&USART1->SR, USART_SR_TC_Pos); switch (n) { case 1U: - USART2TxData(data, length); + USART1TxData(data, length); *tc = 0; if (flush) { - while (!RINGBUFF_EMPTY(txBuffer2) || !tc) + while (!RINGBUFF_EMPTY(txBuffer1) || !tc) ; } break; From 96c214c35961c5c73745ada4576278c4fc86e701 Mon Sep 17 00:00:00 2001 From: SQ6POG Date: Thu, 1 Jun 2017 17:05:29 +0200 Subject: [PATCH 29/31] Added starting LED animation for MMDVM_pog board. --- IOSTM_CMSIS.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 6f75fe2..a865604 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -143,6 +143,46 @@ void GPIOConfigPin(GPIO_TypeDef *port_ptr, uint32_t pin, uint32_t mode_cnf_value *cr_ptr = cr_value; // save localized value to CRL / CRL } +#if defined(STM32F1_POG) +void FancyLEDEffect() +{ + bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25}; + + for(int i=0; i<7; i++){ + *foo[i] = 0x01; + } + GPIOConfigPin(PORT_USART2_TXD, PIN_USART2_TXD, GPIO_CRL_MODE0_1); + *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x00; + delay(SystemCoreClock/1000*100); + for(int i=0; i<7; i++){ + *foo[i] = 0x00; + } + *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x01; + delay(SystemCoreClock/1000*20); + *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x00; + delay(SystemCoreClock/1000*10); + *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x01; + + *foo[0] = 0x01; + for(int i=1; i<7; i++){ + delay(SystemCoreClock/1000*10); + *foo[i-1] = 0x00; + *foo[i] = 0x01; + } + for(int i=5; i>=0; i--){ + delay(SystemCoreClock/1000*10); + *foo[i+1] = 0x00; + *foo[i] = 0x01; + } + delay(SystemCoreClock/1000*10); + *foo[5+1-6] = 0x00; + *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x00; + delay(SystemCoreClock/1000*10); + *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x01; + GPIOConfigPin(PORT_USART2_TXD, PIN_USART2_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1); + delay(SystemCoreClock/1000*50); +} +#endif static inline void GPIOInit() { @@ -295,6 +335,9 @@ void CIO::initInt() GPIOInit(); ADCInit(); DACInit(); +#if defined(STM32F1_POG) + FancyLEDEffect(); +#endif } void CIO::startInt() From 00a7f15011200957eaa3dfdb4623e822abf0f62a Mon Sep 17 00:00:00 2001 From: Steve N4IRS Date: Sun, 4 Jun 2017 08:27:12 -0400 Subject: [PATCH 30/31] Fix USART2 to USART1 after PR 94 --- IOSTM_CMSIS.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 98c457e..80d1531 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -151,17 +151,17 @@ void FancyLEDEffect() for(int i=0; i<7; i++){ *foo[i] = 0x01; } - GPIOConfigPin(PORT_USART2_TXD, PIN_USART2_TXD, GPIO_CRL_MODE0_1); - *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x00; + GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1); + *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00; delay(SystemCoreClock/1000*100); for(int i=0; i<7; i++){ *foo[i] = 0x00; } - *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x01; + *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01; delay(SystemCoreClock/1000*20); - *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x00; + *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00; delay(SystemCoreClock/1000*10); - *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x01; + *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01; *foo[0] = 0x01; for(int i=1; i<7; i++){ @@ -176,10 +176,10 @@ void FancyLEDEffect() } delay(SystemCoreClock/1000*10); *foo[5+1-6] = 0x00; - *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x00; + *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00; delay(SystemCoreClock/1000*10); - *((bitband_t)BITBAND_PERIPH(&PORT_USART2_TXD->ODR, PIN_USART2_TXD)) = 0x01; - GPIOConfigPin(PORT_USART2_TXD, PIN_USART2_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1); + *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01; + GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1); delay(SystemCoreClock/1000*50); } #endif From 1dc23a4aa61d7e7703fe30d531c9ae33b587b49e Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 6 Jun 2017 10:50:53 +0200 Subject: [PATCH 31/31] Fix Arduino Makefile to include GitVersion on upload --- Makefile.Arduino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index 36c3dd4..3baccd3 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -175,7 +175,7 @@ $(TMPDIR)/$(PROJNAME).bin: $(TMPDIR)/$(PROJNAME).elf $(OBJCOPY) -O binary $< $@ #upload to the arduino by first resetting it (stty) and the running bossac -upload: $(TMPDIR)/$(PROJNAME).bin +upload: GitVersion.h $(TMPDIR)/$(PROJNAME).bin stty -F /dev/$(PORT) cs8 1200 hupcl $(ADIR)/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i --port=$(PORT) -U false -e -w $(VERIFY) -b $(TMPDIR)/$(PROJNAME).bin -R