ut_dac producing a 500hz sine wave at Fs=16kHz
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 31 May 2013 07:38:36 +0000 (07:38 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 31 May 2013 07:38:36 +0000 (07:38 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1298 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/stm32/Makefile
codec2-dev/stm32/README.txt
codec2-dev/stm32/src/main.c
codec2-dev/stm32/src/ut_dac.c [new file with mode: 0644]
codec2-dev/stm32/src/ut_dac.h [new file with mode: 0644]

index 62dd061e98e68fec75b8a1b8817a07304d77458f..0d1a8677bec58cc2655b808b383336959b87f8b4 100644 (file)
@@ -138,6 +138,7 @@ src/ut_dac.c \
 $(DAC_TEST)/stm32f4xx_it.c \
 $(DAC_TEST)/system_stm32f4xx.c \
 $(PERIPHLIBDIR)/Utilities/STM32_EVAL/STM3240_41_G_EVAL/stm324xg_eval.c \
+gdb_stdio.c \
 src/startup_stm32f4xx.s \
 src/init.c
 
index dd310d6f38b2c528a640c33e112f841fae278e7d..dec57cf393dcebab165668060fc2c86bf3c22e3f 100644 (file)
@@ -53,7 +53,7 @@ Getting Started
 
 . Place a copy of hts1a.raw in the stlink directory and start st-util:
 
-   ~/stlink$ cp ~/codec2-dev/raw/hts1a.raw .
+   ~/stlink$ cp ~/codec2-dev/raw/hts1a.raw stm_in.raw
    ~/stlink$ sudo ./st-util -f /home/david/codec2-dev/stm32/stm32f4_codec2.elf
 
 . In _another_ console start gdb:
@@ -90,7 +90,7 @@ Getting Started
 . gdb will prints various debug messages, and the codec output file
   will be written to ~/stlink.
   
-  ~/stlink$ play -r 8000 -s -2 hts1a_out.raw
+  ~/stlink$ play -r 8000 -s -2 stm_out.raw
 
 Process
 -------
index c1d2356f48a116b19f6490f0064b327f5d7ce0ce..28d8ba75dd52dcb666ad2f954d888c53306ba4ad 100644 (file)
@@ -38,13 +38,13 @@ static void c2demo(int mode, char inputfile[], char outputfile[])
 \r
     fin = fopen(inputfile, "rb");\r
     if (fin == NULL) {\r
-        printf("Error opening input file: %s\n",inputfile);\r
+        printf("Error opening input file: %s\n\nTerminating....\n",inputfile);\r
         exit(1);\r
     }\r
 \r
     fout = fopen(outputfile, "wb");\r
     if (fout == NULL) {\r
-        printf("Error opening output file: %s\n",outputfile);\r
+        printf("Error opening output file: %s\n\nTerminating....\n",outputfile);\r
         exit(1);\r
     }\r
 \r
@@ -98,7 +98,7 @@ static void c2speedtest(int mode, char inputfile[])
 \r
     fin = fopen(inputfile, "rb");\r
     if (fin == NULL) {\r
-        printf("Error opening input file: %s\n",inputfile);\r
+        printf("Error opening input file: %s\nTerminating....\n",inputfile);\r
         exit(1);\r
     }\r
 \r
@@ -130,7 +130,7 @@ void gpio_init() {
                                          // purpose output\r
 }\r
 \r
-int main(void) {\r
+int main(int argc, char *argv[]) {\r
     SystemInit();\r
     gpio_init();\r
     machdep_timer_init ();\r
@@ -140,14 +140,14 @@ int main(void) {
     /* File I/O test for profiling or (with #define DUMP)\r
        dumping states for optimisation and tiuning */\r
 \r
-    c2demo(CODEC2_MODE_1600, "hts1a.raw", "hts1a_out.raw");\r
+    c2demo(CODEC2_MODE_1600, "stm_in.raw", "stm_out.raw");\r
 \r
     printf("Starting c2 speed test\n");\r
     \r
     /* Another test of execution speed. Look at PD13 with a\r
        oscilliscope.  On time is enc, off is dec */\r
 \r
-    c2speedtest(CODEC2_MODE_1600, "hts1a.raw");\r
+    c2speedtest(CODEC2_MODE_1600, "stm_in.raw");\r
 \r
     printf("Finished\n");\r
 \r
diff --git a/codec2-dev/stm32/src/ut_dac.c b/codec2-dev/stm32/src/ut_dac.c
new file mode 100644 (file)
index 0000000..6cfaeb5
--- /dev/null
@@ -0,0 +1,198 @@
+/**\r
+  ******************************************************************************\r
+  * @file    DAC/DAC_SignalsGeneration/main.c \r
+  * @author  MCD Application Team\r
+  * @version V1.1.0\r
+  * @date    18-January-2013\r
+  * @brief   Main program body.\r
+  ******************************************************************************\r
+  * @attention\r
+  *\r
+  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>\r
+  *\r
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");\r
+  * You may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at:\r
+  *\r
+  *        http://www.st.com/software_license_agreement_liberty_v2\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software \r
+  * distributed under the License is distributed on an "AS IS" BASIS, \r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  *\r
+  ******************************************************************************\r
+  */\r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "ut_dac.h"\r
+#include "gdb_stdio.h"\r
+\r
+#ifdef __EMBEDDED__\r
+#define printf gdb_stdio_printf\r
+#define fopen gdb_stdio_fopen\r
+#define fclose gdb_stdio_fclose\r
+#define fread gdb_stdio_fread\r
+#define fwrite gdb_stdio_fwrite\r
+#endif\r
+\r
+/** @addtogroup STM32F4xx_StdPeriph_Examples\r
+  * @{\r
+  */\r
+\r
+/** @addtogroup DAC_SignalsGeneration\r
+  * @{\r
+  */ \r
+\r
+/* Private typedef -----------------------------------------------------------*/\r
+/* Private define ------------------------------------------------------------*/\r
+/* Private macro -------------------------------------------------------------*/\r
+/* Private variables ---------------------------------------------------------*/\r
+DAC_InitTypeDef  DAC_InitStructure;\r
+\r
+\r
+const uint16_t aSine12bit[32] = {\r
+                      2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056,\r
+                      3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, \r
+                      599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647};\r
+\r
+const uint8_t aEscalator8bit[6] = {0x0, 0x33, 0x66, 0x99, 0xCC, 0xFF};\r
+\r
+__IO uint8_t ubSelectedWavesForm = 1;\r
+__IO uint8_t ubKeyPressed = SET; \r
+\r
+/* Private function prototypes -----------------------------------------------*/\r
+static void TIM6_Config(void);\r
+\r
+static void DAC_Ch2_SineWaveConfig(void);\r
+\r
+/* Private functions ---------------------------------------------------------*/\r
+\r
+/**\r
+  * @brief   Main program\r
+  * @param  None\r
+  * @retval None\r
+  */\r
+int main(void)\r
+{\r
+  /*!< At this stage the microcontroller clock setting is already configured, \r
+       this is done through SystemInit() function which is called from startup\r
+       files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to \r
+       application main. \r
+       To reconfigure the default setting of SystemInit() function, refer to\r
+       system_stm32f4xx.c file\r
+     */    \r
+\r
+  /* Preconfiguration before using DAC----------------------------------------*/\r
+  GPIO_InitTypeDef GPIO_InitStructure;\r
+\r
+  /* DMA1 clock enable */\r
+  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);\r
+  /* GPIOA clock enable (to be used with DAC) */\r
+  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);                         \r
+  /* DAC Periph clock enable */\r
+  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);\r
+\r
+  /* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */\r
+  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;\r
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;\r
+  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;\r
+  GPIO_Init(GPIOA, &GPIO_InitStructure);\r
+\r
+  /* TIM6 Configuration ------------------------------------------------------*/\r
+\r
+  TIM6_Config();  \r
+    \r
+  DAC_Ch2_SineWaveConfig();\r
+\r
+  while (1);\r
+}\r
+\r
+/**             \r
+  * @brief  TIM6 Configuration\r
+  * @note   TIM6 configuration is based on APB1 frequency\r
+  * @note   TIM6 Update event occurs each TIM6CLK/256   \r
+  * @param  None\r
+  * @retval None\r
+  */\r
+static void TIM6_Config(void)\r
+{\r
+  TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;\r
+  /* TIM6 Periph clock enable */\r
+  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);\r
+  \r
+  /* --------------------------------------------------------\r
+  TIM3 input clock (TIM6CLK) is set to 2 * APB1 clock (PCLK1), \r
+  since APB1 prescaler is different from 1.   \r
+    TIM6CLK = 2 * PCLK1  \r
+    TIM6CLK = HCLK / 2 = SystemCoreClock /2 \r
+          \r
+  TIM6 Update event occurs each TIM6CLK/256 \r
+\r
+  Note: \r
+   SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.\r
+   Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()\r
+   function to update SystemCoreClock variable value. Otherwise, any configuration\r
+   based on this variable will be incorrect.    \r
+\r
+  ----------------------------------------------------------- */\r
+  /* Time base configuration */\r
+  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); \r
+  TIM_TimeBaseStructure.TIM_Period = 1679;          \r
+  TIM_TimeBaseStructure.TIM_Prescaler = 0;       \r
+  TIM_TimeBaseStructure.TIM_ClockDivision = 0;    \r
+  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  \r
+  TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);\r
+\r
+  /* TIM6 TRGO selection */\r
+  TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);\r
+  \r
+  /* TIM6 enable counter */\r
+  TIM_Cmd(TIM6, ENABLE);\r
+}\r
+\r
+/**\r
+  * @brief  DAC  Channel2 SineWave Configuration\r
+  * @param  None\r
+  * @retval None\r
+  */\r
+static void DAC_Ch2_SineWaveConfig(void)\r
+{\r
+  DMA_InitTypeDef DMA_InitStructure;\r
+  \r
+  /* 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_Init(DAC_Channel_2, &DAC_InitStructure);\r
+\r
+  /* DMA1_Stream6 channel7 configuration **************************************/\r
+  DMA_DeInit(DMA1_Stream6);\r
+  DMA_InitStructure.DMA_Channel = DMA_Channel_7;  \r
+  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS;\r
+  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&aSine12bit;\r
+  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;\r
+  DMA_InitStructure.DMA_BufferSize = 32;\r
+  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;\r
+  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;\r
+  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;\r
+  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;\r
+  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;\r
+  DMA_InitStructure.DMA_Priority = DMA_Priority_High;\r
+  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         \r
+  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;\r
+  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;\r
+  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;\r
+  DMA_Init(DMA1_Stream6, &DMA_InitStructure);\r
+\r
+  /* Enable DMA1_Stream6 */\r
+  DMA_Cmd(DMA1_Stream6, ENABLE);\r
+\r
+  /* Enable DAC Channel2 */\r
+  DAC_Cmd(DAC_Channel_2, ENABLE);\r
+\r
+  /* Enable DMA for DAC Channel2 */\r
+  DAC_DMACmd(DAC_Channel_2, ENABLE);\r
+}\r
+\r
diff --git a/codec2-dev/stm32/src/ut_dac.h b/codec2-dev/stm32/src/ut_dac.h
new file mode 100644 (file)
index 0000000..b235e56
--- /dev/null
@@ -0,0 +1,63 @@
+/**\r
+  ******************************************************************************\r
+  * @file    DAC/DAC_SignalsGeneration/main.h \r
+  * @author  MCD Application Team\r
+  * @version V1.1.0\r
+  * @date    18-January-2013\r
+  * @brief   Header for main.c module\r
+  ******************************************************************************\r
+  * @attention\r
+  *\r
+  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>\r
+  *\r
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");\r
+  * You may not use this file except in compliance with the License.\r
+  * You may obtain a copy of the License at:\r
+  *\r
+  *        http://www.st.com/software_license_agreement_liberty_v2\r
+  *\r
+  * Unless required by applicable law or agreed to in writing, software \r
+  * distributed under the License is distributed on an "AS IS" BASIS, \r
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  * See the License for the specific language governing permissions and\r
+  * limitations under the License.\r
+  *\r
+  ******************************************************************************\r
+  */\r
+  \r
+/* Define to prevent recursive inclusion -------------------------------------*/\r
+#ifndef __MAIN_H\r
+#define __MAIN_H\r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "stm32f4xx.h"\r
+\r
+#if defined (USE_STM324xG_EVAL)\r
+  #include "stm324xg_eval.h"\r
+\r
+#elif defined (USE_STM324x7I_EVAL) \r
+  #include "stm324x7i_eval.h"\r
+\r
+#else\r
+ #error "Please select first the Evaluation board used in your application (in Project Options)"\r
+#endif\r
+\r
+/* Exported types ------------------------------------------------------------*/\r
+/* Exported constants --------------------------------------------------------*/\r
+/* Exported macro ------------------------------------------------------------*/\r
+#if defined (USE_STM324xG_EVAL)\r
+\r
+  #define DAC_DHR12R2_ADDRESS    0x40007414\r
+  #define DAC_DHR8R1_ADDRESS     0x40007410\r
+\r
+#else /* defined (USE_STM324x7I_EVAL)*/ \r
+\r
+  #define DAC_DHR12R2_ADDRESS    0x40007414\r
+  #define DAC_DHR8R1_ADDRESS     0x40007410\r
+\r
+#endif\r
+/* Exported functions ------------------------------------------------------- */\r
+\r
+#endif /* __MAIN_H */\r
+\r
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r