From a8b939c979e3f545b2f5899e0e15cc8234c9b435 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 31 May 2013 09:58:58 +0000 Subject: [PATCH] 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 --- codec2-dev/stm32/Makefile | 15 +-- .../stm32/{src/ut_dac.h => inc/dac_ut.h} | 0 codec2-dev/stm32/src/{ut_dac.c => dac_ut.c} | 94 +++++++++---------- 3 files changed, 53 insertions(+), 56 deletions(-) rename codec2-dev/stm32/{src/ut_dac.h => inc/dac_ut.h} (100%) rename codec2-dev/stm32/src/{ut_dac.c => dac_ut.c} (74%) 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/src/ut_dac.h b/codec2-dev/stm32/inc/dac_ut.h similarity index 100% rename from codec2-dev/stm32/src/ut_dac.h rename to codec2-dev/stm32/inc/dac_ut.h diff --git a/codec2-dev/stm32/src/ut_dac.c b/codec2-dev/stm32/src/dac_ut.c similarity index 74% rename from codec2-dev/stm32/src/ut_dac.c rename to codec2-dev/stm32/src/dac_ut.c index 6cfaeb56..72849177 100644 --- a/codec2-dev/stm32/src/ut_dac.c +++ b/codec2-dev/stm32/src/dac_ut.c @@ -1,3 +1,33 @@ +/*---------------------------------------------------------------------------*\ + + 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 @@ -25,55 +55,25 @@ ****************************************************************************** */ -/* 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 +#include "stm32f4xx.h" -/** @addtogroup STM32F4xx_StdPeriph_Examples - * @{ - */ +#define DAC_DHR12R2_ADDRESS 0x40007414 -/** @addtogroup DAC_SignalsGeneration - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ 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}; -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, @@ -123,23 +123,19 @@ static void TIM6_Config(void) 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. - - ----------------------------------------------------------- */ + + 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 = 1679; + TIM_TimeBaseStructure.TIM_Period = 5250; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; -- 2.25.1