PERIPHLIBURL = http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/
PERIPHLIBZIP = stm32f4_dsp_stdperiph_lib.zip
-PERIPHLIBVER = V1.4.0
+PERIPHLIBVER = V1.1.0
PERIPHLIBNAME = STM32F4xx_DSP_StdPeriph_Lib
PERIPHLIBDIR = $(PERIPHLIBNAME)_$(PERIPHLIBVER)
CMSIS = $(PERIPHLIBDIR)/Libraries/CMSIS
fdmdv_dump_rt.elf: $(FDMDV_DUMP_RT_SRCS) src/stm32f4_dac.o src/stm32f4_adc.o
$(CC) $(CFLAGS) -O3 $^ -o $@ $(LIBPATHS) $(LIBS)
+# ---------------------------------------------------------------------------
+
TUNER_UT_SRCS=\
src/tuner_ut.c \
../src/fifo.c \
src/stm32f4_dac.c \
-src/stm32f4_adc_tuner.c \
+src/iir_tuner.c \
src/sm1000_leds_switches.c \
src/debugblinky.c \
src/system_stm32f4xx.c \
src/startup_stm32f4xx.s \
src/init.c
-tuner_ut.elf: $(ADCDAC_UT_SRCS)
- $(CC) $(CFLAGS) -O0 $^ -o $@ $(LIBPATHS) $(LIBS)
+# this needs to be compiled without the optimiser or ugly things happen
+# would be nice to work out why as ISRs need to run fast
+
+src/stm32f4_adc_tuner.o: src/stm32f4_adc_tuner.c
+ $(CC) $(CFLAGS) $^ -c -o $@
+
+tuner_ut.elf: $(TUNER_UT_SRCS) src/stm32f4_adc_tuner.o
+ $(CC) $(CFLAGS) -O3 $^ -o $@ $(LIBPATHS) $(LIBS)
$(OBJCOPY) -O binary tuner_ut.elf tuner_ut.bin
+# ---------------------------------------------------------------------------------
+
clean:
rm -f *.o
rm -f *.elf
/*---------------------------------------------------------------------------*\
- FILE........: stm32f4_adc.h
+ FILE........: stm32f4_adc_tuner.h
AUTHOR......: David Rowe
DATE CREATED: 19 Feb 2015
\r
while(adc2_read(buf, SINE_SAMPLES) == -1);\r
\r
- if (switch_select()) {\r
+ if (!switch_select()) {\r
for(i=0; i<SINE_SAMPLES; i++)\r
- buf[i] = 0;\r
+ buf[i] = aSine[i];\r
}\r
\r
- dac1_write(buf, SINE_SAMPLES);\r
+ dac2_write(buf, SINE_SAMPLES);\r
}\r
\r
}\r
#endif
#include "stm32f4_adc_tuner.h"
+#include "iir_tuner.h"
/* Filter coefficients of IIR tuner (BETA1) and FIR equaliser (BETA2).
Note neat trick to relate BETA2 to BETA1 by the decimation rate */
ADC -> signed conversion - IIR BPF - Decimate - FIR Equaliser -> FIFO
*/
-void inline iir_tuner(float dec_buf[], unsigned short adc_buf[]) {
+void iir_tuner(float dec_buf[], unsigned short adc_buf[]) {
int i, j, k;
float x, y, z;
\r
Main program for SM1000.\r
\r
+ TODO\r
+\r
+ [ ] make led blink 1-2-3 times for "mode"\r
+\r
\*---------------------------------------------------------------------------*/\r
\r
/*\r
#include "codec2_fdmdv.h"\r
#include "sm1000_leds_switches.h"\r
#include <stm32f4xx_gpio.h>\r
+#include <stdlib.h>\r
\r
#define FREEDV_NSAMPLES_16K (2*FREEDV_NSAMPLES)\r
\r
if (adc2_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) {\r
GPIOE->ODR = (1 << 3);\r
\r
+ /* clipping indicator */\r
+\r
+ led_err(0);\r
+ for (i=0; i<FREEDV_NSAMPLES_16K; i++) {\r
+ if (abs(adc16k[FDMDV_OS_TAPS_16K+i]) > 28000)\r
+ led_err(1);\r
+ }\r
+\r
fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES);\r
\r
if (ss.mode == ANALOG) {\r
}\r
if (ss.mode == DV) {\r
freedv_tx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k);\r
+ for(i=0; i<FREEDV_NSAMPLES; i++)\r
+ dac8k[FDMDV_OS_TAPS_8K+i] *= 0.398; /* 8dB back off from peak */\r
fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES); \r
dac1_write(dac16k, FREEDV_NSAMPLES_16K);\r
}\r
if (ss.mode == TONE) {\r
- while(dac1_write((short*)aSine, SINE_SAMPLES) == 0);\r
+ short buf[SINE_SAMPLES];\r
+ for(i=0; i<FREEDV_NSAMPLES; i++)\r
+ buf[i] = aSine[i]*0.398; /* 8dB back off from peak */ \r
+ while(dac1_write(buf, SINE_SAMPLES) == 0);\r
}\r
\r
led_ptt(1); led_rt(0); led_err(0); not_cptt(0);\r
next_state = ss->state;\r
switch(ss->state) {\r
case SS_IDLE:\r
- if (switch_select()) {\r
+ if (switch_select() == 0) {\r
downTicker = FIFTY_MS;\r
next_state = SS_DEBOUNCE_DOWN;\r
}\r
}\r
break;\r
case SS_WAIT_BUTTON_UP:\r
- if (switch_select() == 0) {\r
+ if (switch_select() == 1) {\r
downTicker = FIFTY_MS;\r
next_state = SS_DEBOUNCE_UP;\r
}\r
#include "codec2_fifo.h"
#include "stm32f4_adc_tuner.h"
#include "debugblinky.h"
-#include "iir_tuner.c"
+#include "iir_tuner.h"
struct FIFO *adc1_fifo;
unsigned short adc_buf[ADC_TUNER_BUF_SZ];
void DMA2_Stream0_IRQHandler(void) {
float dec_buf[ADC_TUNER_N/2];
+ /* PE0 is asserted high for the duration of this ISR
+
GPIOE->ODR = (1 << 0);
/* Half transfer interrupt */
/* write first half to fifo */
- if (fifo_write(adc1_fifo, (short)dec_buf, ADC_TUNER_N) == -1) {
+ if (fifo_write(adc1_fifo, (short*)dec_buf, ADC_TUNER_N) == -1) {
adc_overflow1++;
}
/* write second half to fifo */
- if (fifo_write(adc1_fifo, (short)dec_buf, ADC_TUNER_N) == -1) {
+ if (fifo_write(adc1_fifo, (short*)dec_buf, ADC_TUNER_N) == -1) {
adc_overflow1++;
}
#include "sm1000_leds_switches.h"\r
\r
int main(void) {\r
- short buf[SINE_SAMPLES];\r
- int i;\r
+ float tuner_out[ADC_TUNER_N];\r
\r
dac_open(4*DAC_BUF_SZ);\r
- adc_open(4*ADC_TUNER_N;\r
+ adc_open(4*ADC_TUNER_N);\r
sm1000_leds_switches_init();\r
\r
while (1) {\r
\r
- while(adc1_read(buf, ADC_TUNER_N) == -1);\r
+ while(adc1_read((short *)tuner_out, ADC_TUNER_N) == -1);\r
\r
- /*\r
- if (switch_select()) {\r
- for(i=0; i<SINE_SAMPLES; i++)\r
- buf[i] = 0;\r
- }\r
- \r
- dac1_write(buf, SINE_SAMPLES);\r
- */\r
}\r
\r
}\r