From: drowe67 Date: Fri, 31 May 2013 09:58:58 +0000 (+0000) Subject: refactored DAC UT a little, timer set up now making more sense X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=a8b939c979e3f545b2f5899e0e15cc8234c9b435;p=freetel-svn-tracking.git refactored DAC UT a little, timer set up now making more sense git-svn-id: https://svn.code.sf.net/p/freetel/code@1299 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index 0d1a8677..cc431558 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -110,7 +110,7 @@ OBJS = $(SRCS:.c=.o) ################################################### -all: libstm32f4.a $(PROJ_NAME).elf fft_test.elf ut_dac.elf +all: libstm32f4.a $(PROJ_NAME).elf fft_test.elf dac_ut.elf dl/$(PERIPHLIBZIP): mkdir -p dl @@ -134,15 +134,16 @@ fft_test.elf: $(FFT_TEST_SRCS) DAC_TEST=$(PERIPHLIBDIR)/Project/STM32F4xx_StdPeriph_Examples/DAC/DAC_SignalsGeneration DAC_TEST_SRCS=\ -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/dac_ut.c \ +src/system_stm32f4xx.c \ src/startup_stm32f4xx.s \ src/init.c -ut_dac.elf: $(DAC_TEST_SRCS) +#$(DAC_TEST)/stm32f4xx_it.c \ +#$(DAC_TEST)/system_stm32f4xx.c \ +#(PERIPHLIBDIR)/Utilities/STM32_EVAL/STM3240_41_G_EVAL/stm324xg_eval.c \ + +dac_ut.elf: $(DAC_TEST_SRCS) $(CC) $(CFLAGS) -DUSE_STM324xG_EVAL -I$(PERIPHLIBDIR)/Utilities/STM32_EVAL/STM3240_41_G_EVAL -I$(PERIPHLIBDIR)/Utilities/STM32_EVAL/Common $^ -o $@ $(LIBPATHS) $(LIBS) clean: diff --git a/codec2-dev/stm32/inc/dac_ut.h b/codec2-dev/stm32/inc/dac_ut.h new file mode 100644 index 00000000..b235e56c --- /dev/null +++ b/codec2-dev/stm32/inc/dac_ut.h @@ -0,0 +1,63 @@ +/** + ****************************************************************************** + * @file DAC/DAC_SignalsGeneration/main.h + * @author MCD Application Team + * @version V1.1.0 + * @date 18-January-2013 + * @brief Header for main.c module + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2013 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx.h" + +#if defined (USE_STM324xG_EVAL) + #include "stm324xg_eval.h" + +#elif defined (USE_STM324x7I_EVAL) + #include "stm324x7i_eval.h" + +#else + #error "Please select first the Evaluation board used in your application (in Project Options)" +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +#if defined (USE_STM324xG_EVAL) + + #define DAC_DHR12R2_ADDRESS 0x40007414 + #define DAC_DHR8R1_ADDRESS 0x40007410 + +#else /* defined (USE_STM324x7I_EVAL)*/ + + #define DAC_DHR12R2_ADDRESS 0x40007414 + #define DAC_DHR8R1_ADDRESS 0x40007410 + +#endif +/* Exported functions ------------------------------------------------------- */ + +#endif /* __MAIN_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/src/dac_ut.c b/codec2-dev/stm32/src/dac_ut.c new file mode 100644 index 00000000..72849177 --- /dev/null +++ b/codec2-dev/stm32/src/dac_ut.c @@ -0,0 +1,194 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: dac_ut.c + AUTHOR......: David Rowe + DATE CREATED: May 31 2013 + + Plays a 500 Hz sine wave sampled at 16 kHz out of PF5 on a Discovery board. + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2013 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 . +*/ + + +/* Modfied version of the following: */ + +/** + ****************************************************************************** + * @file DAC/DAC_SignalsGeneration/main.c + * @author MCD Application Team + * @version V1.1.0 + * @date 18-January-2013 + * @brief Main program body. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2013 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +#include "stm32f4xx.h" + +#define DAC_DHR12R2_ADDRESS 0x40007414 + +DAC_InitTypeDef DAC_InitStructure; + +/* 32 sample sine wave which at Fs=16kHz will be 500Hz. Note samples + are unsigned */ + +const uint16_t aSine12bit[32] = { + 2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056, + 3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, + 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647}; + +static void TIM6_Config(void); +static void DAC_Ch2_SineWaveConfig(void); + +/* Private functions ---------------------------------------------------------*/ + +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to + application main. + To reconfigure the default setting of SystemInit() function, refer to + system_stm32f4xx.c file + */ + + /* Preconfiguration before using DAC----------------------------------------*/ + GPIO_InitTypeDef GPIO_InitStructure; + + /* DMA1 clock enable */ + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); + /* GPIOA clock enable (to be used with DAC) */ + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); + /* DAC Periph clock enable */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); + + /* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + /* TIM6 Configuration ------------------------------------------------------*/ + + TIM6_Config(); + + DAC_Ch2_SineWaveConfig(); + + while (1); +} + +/** + * @brief TIM6 Configuration + * @note TIM6 configuration is based on APB1 frequency + * @note TIM6 Update event occurs each TIM6CLK/256 + * @param None + * @retval None + */ +static void TIM6_Config(void) +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + /* TIM6 Periph clock enable */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); + + /* -------------------------------------------------------- + + TIM3 input clock (TIM6CLK) is set to 2 * APB1 clock (PCLK1), since + APB1 prescaler is different from 1 (see system_stm32f4xx.c and Fig + 13 clock tree figure in DM0031020.pdf). + + Sample rate Fs = 2*PCLK1/TIM_ClockDivision + = (HCLK/2)/TIM_ClockDivision + + ----------------------------------------------------------- */ + + /* Time base configuration */ + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Period = 5250; + TIM_TimeBaseStructure.TIM_Prescaler = 0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); + + /* TIM6 TRGO selection */ + TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); + + /* TIM6 enable counter */ + TIM_Cmd(TIM6, ENABLE); +} + +/** + * @brief DAC Channel2 SineWave Configuration + * @param None + * @retval None + */ +static void DAC_Ch2_SineWaveConfig(void) +{ + DMA_InitTypeDef DMA_InitStructure; + + /* DAC channel2 Configuration */ + DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; + DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; + DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; + DAC_Init(DAC_Channel_2, &DAC_InitStructure); + + /* DMA1_Stream6 channel7 configuration **************************************/ + DMA_DeInit(DMA1_Stream6); + DMA_InitStructure.DMA_Channel = DMA_Channel_7; + DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS; + DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&aSine12bit; + DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; + DMA_InitStructure.DMA_BufferSize = 32; + DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; + DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; + DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; + DMA_Init(DMA1_Stream6, &DMA_InitStructure); + + /* Enable DMA1_Stream6 */ + DMA_Cmd(DMA1_Stream6, ENABLE); + + /* Enable DAC Channel2 */ + DAC_Cmd(DAC_Channel_2, ENABLE); + + /* Enable DMA for DAC Channel2 */ + DAC_DMACmd(DAC_Channel_2, ENABLE); +} + diff --git a/codec2-dev/stm32/src/ut_dac.c b/codec2-dev/stm32/src/ut_dac.c deleted file mode 100644 index 6cfaeb56..00000000 --- a/codec2-dev/stm32/src/ut_dac.c +++ /dev/null @@ -1,198 +0,0 @@ -/** - ****************************************************************************** - * @file DAC/DAC_SignalsGeneration/main.c - * @author MCD Application Team - * @version V1.1.0 - * @date 18-January-2013 - * @brief Main program body. - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2013 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "ut_dac.h" -#include "gdb_stdio.h" - -#ifdef __EMBEDDED__ -#define printf gdb_stdio_printf -#define fopen gdb_stdio_fopen -#define fclose gdb_stdio_fclose -#define fread gdb_stdio_fread -#define fwrite gdb_stdio_fwrite -#endif - -/** @addtogroup STM32F4xx_StdPeriph_Examples - * @{ - */ - -/** @addtogroup DAC_SignalsGeneration - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -DAC_InitTypeDef DAC_InitStructure; - - -const uint16_t aSine12bit[32] = { - 2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056, - 3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, - 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647}; - -const uint8_t aEscalator8bit[6] = {0x0, 0x33, 0x66, 0x99, 0xCC, 0xFF}; - -__IO uint8_t ubSelectedWavesForm = 1; -__IO uint8_t ubKeyPressed = SET; - -/* Private function prototypes -----------------------------------------------*/ -static void TIM6_Config(void); - -static void DAC_Ch2_SineWaveConfig(void); - -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Main program - * @param None - * @retval None - */ -int main(void) -{ - /*!< At this stage the microcontroller clock setting is already configured, - this is done through SystemInit() function which is called from startup - files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to - application main. - To reconfigure the default setting of SystemInit() function, refer to - system_stm32f4xx.c file - */ - - /* Preconfiguration before using DAC----------------------------------------*/ - GPIO_InitTypeDef GPIO_InitStructure; - - /* DMA1 clock enable */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); - /* GPIOA clock enable (to be used with DAC) */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - /* DAC Periph clock enable */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - - /* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* TIM6 Configuration ------------------------------------------------------*/ - - TIM6_Config(); - - DAC_Ch2_SineWaveConfig(); - - while (1); -} - -/** - * @brief TIM6 Configuration - * @note TIM6 configuration is based on APB1 frequency - * @note TIM6 Update event occurs each TIM6CLK/256 - * @param None - * @retval None - */ -static void TIM6_Config(void) -{ - TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; - /* TIM6 Periph clock enable */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); - - /* -------------------------------------------------------- - TIM3 input clock (TIM6CLK) is set to 2 * APB1 clock (PCLK1), - since APB1 prescaler is different from 1. - TIM6CLK = 2 * PCLK1 - TIM6CLK = HCLK / 2 = SystemCoreClock /2 - - TIM6 Update event occurs each TIM6CLK/256 - - Note: - SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. - Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() - function to update SystemCoreClock variable value. Otherwise, any configuration - based on this variable will be incorrect. - - ----------------------------------------------------------- */ - /* Time base configuration */ - TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = 1679; - TIM_TimeBaseStructure.TIM_Prescaler = 0; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; - TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); - - /* TIM6 TRGO selection */ - TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); - - /* TIM6 enable counter */ - TIM_Cmd(TIM6, ENABLE); -} - -/** - * @brief DAC Channel2 SineWave Configuration - * @param None - * @retval None - */ -static void DAC_Ch2_SineWaveConfig(void) -{ - DMA_InitTypeDef DMA_InitStructure; - - /* DAC channel2 Configuration */ - DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; - DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; - DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; - DAC_Init(DAC_Channel_2, &DAC_InitStructure); - - /* DMA1_Stream6 channel7 configuration **************************************/ - DMA_DeInit(DMA1_Stream6); - DMA_InitStructure.DMA_Channel = DMA_Channel_7; - DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS; - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&aSine12bit; - DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; - DMA_InitStructure.DMA_BufferSize = 32; - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; - DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; - DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; - DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; - DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; - DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; - DMA_Init(DMA1_Stream6, &DMA_InitStructure); - - /* Enable DMA1_Stream6 */ - DMA_Cmd(DMA1_Stream6, ENABLE); - - /* Enable DAC Channel2 */ - DAC_Cmd(DAC_Channel_2, ENABLE); - - /* Enable DMA for DAC Channel2 */ - DAC_DMACmd(DAC_Channel_2, ENABLE); -} - diff --git a/codec2-dev/stm32/src/ut_dac.h b/codec2-dev/stm32/src/ut_dac.h deleted file mode 100644 index b235e56c..00000000 --- a/codec2-dev/stm32/src/ut_dac.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - ****************************************************************************** - * @file DAC/DAC_SignalsGeneration/main.h - * @author MCD Application Team - * @version V1.1.0 - * @date 18-January-2013 - * @brief Header for main.c module - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2013 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H -#define __MAIN_H - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx.h" - -#if defined (USE_STM324xG_EVAL) - #include "stm324xg_eval.h" - -#elif defined (USE_STM324x7I_EVAL) - #include "stm324x7i_eval.h" - -#else - #error "Please select first the Evaluation board used in your application (in Project Options)" -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -#if defined (USE_STM324xG_EVAL) - - #define DAC_DHR12R2_ADDRESS 0x40007414 - #define DAC_DHR8R1_ADDRESS 0x40007410 - -#else /* defined (USE_STM324x7I_EVAL)*/ - - #define DAC_DHR12R2_ADDRESS 0x40007414 - #define DAC_DHR8R1_ADDRESS 0x40007410 - -#endif -/* Exported functions ------------------------------------------------------- */ - -#endif /* __MAIN_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/