Created and ran power UT to estimate current consumption of smartmic uC, only 60mA
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 30 May 2014 06:17:49 +0000 (06:17 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 30 May 2014 06:17:49 +0000 (06:17 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1617 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/stm32/Makefile
codec2-dev/stm32/inc/stm32f4_adc.h [new file with mode: 0644]
codec2-dev/stm32/src/adc_rec.c [new file with mode: 0644]
codec2-dev/stm32/src/dac_play.c
codec2-dev/stm32/src/dac_ut.c
codec2-dev/stm32/src/stm32f4_adc.c
codec2-dev/stm32/src/stm32f4_dac.c

index 583105e35e934b401f9d14e34619f3ae4b576393..0288407a7111c4a8028240421a49b630af1930d8 100644 (file)
@@ -110,7 +110,7 @@ OBJS = $(SRCS:.c=.o)
 
 ###################################################
 
-all: libstm32f4.a $(PROJ_NAME).elf fft_test.elf dac_ut.elf dac_play.elf adc_ut.elf timer_ut.elf
+all: libstm32f4.a $(PROJ_NAME).elf fft_test.elf dac_ut.elf dac_play.elf adc_rec.elf pwm_ut.elf power_ut.elf
 
 dl/$(PERIPHLIBZIP):
        mkdir -p dl
@@ -155,7 +155,8 @@ src/init.c
 dac_play.elf: $(DAC_PLAY_SRCS)
        $(CC) $(CFLAGS) -O0 $^ -o $@ $(LIBPATHS) $(LIBS)
 
-ADC_UT_SRCS=\
+ADC_REC_SRCS=\
+src/adc_rec.c \
 ../src/fifo.c \
 gdb_stdio.c \
 src/stm32f4_adc.c \
@@ -163,17 +164,48 @@ src/system_stm32f4xx.c \
 src/startup_stm32f4xx.s \
 src/init.c
 
-adc_ut.elf: $(ADC_UT_SRCS)
+adc_rec.elf: $(ADC_REC_SRCS)
        $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
 
-TIMER_UT_SRCS=\
-gdb_stdio.c \
-src/timer_ut.c \
+PWM_UT_SRCS=\
+src/stm32f4_pwm.c \
 src/system_stm32f4xx.c \
 src/startup_stm32f4xx.s \
 src/init.c
 
-timer_ut.elf: $(TIMER_UT_SRCS)
+pwm_ut.elf: $(PWM_UT_SRCS)
+       $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
+
+POWER_UT_SRCS=\
+src/power_ut.c \
+gdb_stdio.c \
+../src/fifo.c \
+src/stm32f4_adc.c \
+src/stm32f4_dac.c \
+src/system_stm32f4xx.c \
+src/startup_stm32f4xx.s \
+src/init.c \
+src/stm32f4_timer.c \
+
+POWER_UT_SRCS += \
+$(CODEC2_SRC)/lpc.c \
+$(CODEC2_SRC)/nlp.c \
+$(CODEC2_SRC)/postfilter.c \
+$(CODEC2_SRC)/sine.c \
+$(CODEC2_SRC)/codec2.c \
+$(CODEC2_SRC)/kiss_fft.c \
+$(CODEC2_SRC)/interp.c \
+$(CODEC2_SRC)/lsp.c \
+$(CODEC2_SRC)/phase.c \
+$(CODEC2_SRC)/quantise.c \
+$(CODEC2_SRC)/pack.c \
+$(CODEC2_SRC)/codebook.c \
+$(CODEC2_SRC)/codebookd.c \
+$(CODEC2_SRC)/codebookjvm.c \
+$(CODEC2_SRC)/codebookge.c \
+$(CODEC2_SRC)/dump.c 
+
+power_ut.elf: $(POWER_UT_SRCS)
        $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
 
 clean:
diff --git a/codec2-dev/stm32/inc/stm32f4_adc.h b/codec2-dev/stm32/inc/stm32f4_adc.h
new file mode 100644 (file)
index 0000000..b14110c
--- /dev/null
@@ -0,0 +1,34 @@
+/*---------------------------------------------------------------------------*\
+
+  FILE........: stm32f4_adc.h
+  AUTHOR......: David Rowe
+  DATE CREATED: 30 May 2014
+
+  ADC driver module for STM32F4.
+
+\*---------------------------------------------------------------------------*/
+
+/*
+  Copyright (C) 2014 David Rowe
+
+  All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License version 2.1, as
+  published by the Free Software Foundation.  This program is
+  distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __STM32F4_ADC__
+#define __STM32F4_ADC__
+
+void adc_open(void);
+int adc_read(short buf[], int n); 
+
+#endif
diff --git a/codec2-dev/stm32/src/adc_rec.c b/codec2-dev/stm32/src/adc_rec.c
new file mode 100644 (file)
index 0000000..3d5992f
--- /dev/null
@@ -0,0 +1,58 @@
+/*---------------------------------------------------------------------------*\\r
+\r
+  FILE........: adc_rec.c\r
+  AUTHOR......: David Rowe\r
+  DATE CREATED: 30 May 2014\r
+\r
+  Recordss a 16 kHz sample rate raw file from the STM32F4 ADC.\r
+\r
+\*---------------------------------------------------------------------------*/\r
+\r
+/*\r
+  Copyright (C) 2014 David Rowe\r
+\r
+  All rights reserved.\r
+\r
+  This program is free software; you can redistribute it and/or modify\r
+  it under the terms of the GNU Lesser General Public License version 2.1, as\r
+  published by the Free Software Foundation.  This program is\r
+  distributed in the hope that it will be useful, but WITHOUT ANY\r
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public\r
+  License for more details.\r
+\r
+  You should have received a copy of the GNU Lesser General Public License\r
+  along with this program; if not, see <http://www.gnu.org/licenses/>.\r
+*/\r
+\r
+#include <stdlib.h>\r
+#include "stm32f4_adc.h"\r
+#include "gdb_stdio.h"\r
+\r
+#define REC_TIME_SECS 10\r
+#define N   2000\r
+#define FS  16000\r
+\r
+int main(void){\r
+    short  buf[N];\r
+    FILE  *frec;\r
+    int    i, bufs;\r
+\r
+    adc_open();\r
+\r
+    frec = fopen("stm_out.raw", "wb");\r
+    if (frec == NULL) {\r
+        printf("Error opening input file: stm_out.raw\n\nTerminating....\n");\r
+        exit(1);\r
+    }\r
+    bufs = FS*REC_TIME_SECS/N;\r
+\r
+    printf("Starting!\n");\r
+    for(i=0; i<bufs; i++) {\r
+        while(adc_read(buf, N) == -1);\r
+        fwrite(buf, sizeof(short), N, frec);  \r
+        printf(".");\r
+    }\r
+    fclose(frec);\r
+    printf("Finished!\n");\r
+}\r
index 979b30d5ce3c32b315978ce645c44797be83fbff..ba0ec1ab6aba434d269545f033d0125f82bacb92 100644 (file)
@@ -4,7 +4,7 @@
   AUTHOR......: David Rowe\r
   DATE CREATED: 1 June 2013\r
 \r
-  Plays a 16 kHz sample rate raw file to the Discovery DAC.\r
+  Plays a 16 kHz sample rate raw file to the STM32F4 DAC.\r
 \r
 \*---------------------------------------------------------------------------*/\r
 \r
index c60b9179e9655a375dd5d9c5b323849ace415e0f..139dc75918ec4e59949033d50898c1657b29ad0f 100644 (file)
@@ -4,7 +4,7 @@
   AUTHOR......: David Rowe\r
   DATE CREATED: May 31 2013\r
 \r
-  Plays a 500 Hz sine wave sampled at 16 kHz out of PF5 on a Discovery board.\r
+  Plays a 500 Hz sine wave sampled at 16 kHz out of PA5 on a Discovery board.\r
 \r
 \*---------------------------------------------------------------------------*/\r
 \r
@@ -35,7 +35,7 @@
    are 16 bit 2's complement, the DAC driver convertsto 12 bit\r
    unsigned. */\r
 \r
-const short aSine[] = {\r
+short aSine[] = {\r
     -16,    6384,   12528,  18192,   23200,   27232,   30256,   32128,   32752,   32128,\r
     30256,   27232,   23152,   18192,   12528,    6384,     -16,   -6416,  -12560,  -18224,\r
     -23184,  -27264,  -30288,  -32160,  -32768,  -32160,  -30288,  -27264,  -23184,  -18224,\r
@@ -43,6 +43,10 @@ const short aSine[] = {
 };\r
 \r
 int main(void) {\r
+    int i;\r
+\r
+    //for(i=0; i<32; i++)\r
+    //    aSine[i] /= 2;\r
 \r
     dac_open();\r
 \r
index ea065961b9ca2a3a3f71faf7664b6bca1e89b0ab..62fe8a990455cca8df524835dfeb3a0bf03ca175 100644 (file)
   [X] just get ADC to run at all, prove its sampling something....
   [X] as above with DMA
   [X] half and finished interrupts, ISR
-  [ ] timer config to drive ADC conversion, measure sample rate and confirm 16kHz
-  + larger ADC DMA buffer
-  + fifos
-  + work out a way to unit test
+  [X] timer config to drive ADC conversion, measure sample rate and confirm 16kHz
+      + larger ADC DMA buffer
+      + fifos
+      + work out a way to unit test
   [ ] ADC working at same time as DAC
-  [ ] remove (or make optional) the TIM_Config() code that sends PWM output to pins
+  [X] remove (or make optional) the TIM_Config() code that sends PWM output to pins
   [ ] check comments still valid
+  [X] convert to driver
+  [ ] way to determine which timers are used so they don't get re-sued
+  [ ] way to select different pins/ADCs for multiple channels, multiple channel support
+  [ ] access functions for halff/full/overflow to trap any issues
+  [ ] should FIFOs be in this drivr or in UTs connected to stdio?  SmartMic will just need
+      40ms of buffering
 
 \*---------------------------------------------------------------------------*/
 
  
 #include "codec2_fifo.h"
 #include "gdb_stdio.h"
+#include "stm32f4_adc.h"
 
 #define ADC_BUF_SZ   320
-#define FIFO_SZ      8000
+#define FIFO_SZ      1000
 
 struct FIFO *DMA2_Stream0_fifo;
 unsigned short adc_buf[ADC_BUF_SZ];
@@ -71,82 +78,23 @@ uint16_t aSRC_Buffer[3] = {0, 0, 0};
 void Timer1Config();
 void adc_configure();
 
-#define REC_TIME_SECS 30
-#define N   2000
-#define FS  16000
-
-int main(void){
-    short  buf[N];
-    FILE  *frec;
-    int    i, bufs;
-
+void adc_open(void) {
     DMA2_Stream0_fifo = fifo_create(FIFO_SZ);
     assert(DMA2_Stream0_fifo != NULL);
 
     Timer1Config();
     adc_configure();
     ADC_SoftwareStartConv(ADC1);
-
-    frec = fopen("stm_out.raw", "wb");
-    if (frec == NULL) {
-        printf("Error opening input file: stm_out.raw\n\nTerminating....\n");
-        exit(1);
-    }
-    bufs = FS*REC_TIME_SECS/N;
-
-    printf("Starting!\n");
-    for(i=0; i<bufs; i++) {
-        //ConvertedValue = adc_convert();
-        //printf("ConvertedValue = %d\n", ConvertedValue); 
-        printf("adc_buf: %d %d  half: %d full: %d adc_overflow: %d\n", 
-               adc_buf[0],adc_buf[ADC_BUF_SZ-1],
-               half, full, adc_overflow);
-        while(fifo_read(DMA2_Stream0_fifo, buf, N) == -1);
-        fwrite(buf, sizeof(short), N, frec);      
-    }
-    fclose(frec);
-    printf("Finished!\n");
 }
 
-/* DR: TIM_Config configures a couple of I/O pins for PWM output from
-   Timer1 Channel 3.  Note I dont think any of this is needed, except
-   perhaps to check timer frequency.  Can be removed down the track. */
-
-/**
-  * @brief  Configure the TIM1 Pins.
-  * @param  None
-  * @retval None
-  */
-static void TIM_Config(void)
-{
-  GPIO_InitTypeDef GPIO_InitStructure;
-  
-  /* GPIOA and GPIOB clock enable */
-  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB, ENABLE);
+/* n signed 16 bit samples in buf[] if return != -1 */
 
-  /* GPIOA Configuration: Channel 3 as alternate function push-pull */
-
-  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
-  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
-  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
-  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
-  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
-  GPIO_Init(GPIOA, &GPIO_InitStructure); 
-  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_TIM1);
-
-  /* GPIOB Configuration: Channel 3N as alternate function push-pull */
-
-  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
-  GPIO_Init(GPIOB, &GPIO_InitStructure);
-  GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_TIM1);
+int adc_read(short buf[], int n) {   
+    return fifo_read(DMA2_Stream0_fifo, buf, n);
 }
 
 void Timer1Config() {
 
-    /* TIM Configuration */
-
-    TIM_Config();
-
     /* TIM1 example -------------------------------------------------
   
        TIM1 input clock (TIM1CLK) is set to 2 * APB2 clock (PCLK2), since APB2 
index 2512532c82e9d855eef9e9a540361fc5c7ff7947..8ef8107f27dfa66055c4caeba5fe6cd6857728b1 100644 (file)
@@ -36,7 +36,7 @@
 #define DAC_DHR12L2_ADDRESS    0x40007418\r
 \r
 #define DAC_BUF_SZ   320\r
-#define FIFO_SZ      8000\r
+#define FIFO_SZ      1000\r
 #define DAC_MAX      4096\r
 \r
 DAC_InitTypeDef  DAC_InitStructure;\r
@@ -149,7 +149,7 @@ static void DAC_Ch2_Config(void)
   /* DAC channel2 Configuration */\r
   DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;\r
   DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;\r
-  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;\r
+  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;\r
   DAC_Init(DAC_Channel_2, &DAC_InitStructure);\r
 \r
   /* DMA1_Stream6 channel7 configuration **************************************/\r