won't compile
Diff: main.c
- Revision:
- 0:b079fa4ed182
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.c Wed Nov 02 23:50:52 2016 +0000 @@ -0,0 +1,232 @@ +/** + ****************************************************************************** + * @file DMA_RAM_DAC/main.c + * @author MCD Application Team + * @version V1.0.0 + * @date 20-June-2014 + * @brief Main program body + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * 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 "main.h" + +/** @addtogroup STM32F3348_DISCOVERY_Examples + * @{ + */ + +/** @addtogroup DMA_RAM_DAC + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint32_t DualSine12bit[32]; + +/* Private function prototypes -----------------------------------------------*/ +static void TIM_Config(void); +static void DAC_Config(void); +static void DMA_Config(void); + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + * @param None + * @retval None + */ +int main(void) +{ + uint16_t Sine12bit[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}; + uint32_t Index = 0; + + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_stm32f334x8.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_stm32f30x.c file + */ + + /* Fill DualSine12bit table */ + for (Index = 0; Index < 32; Index++) + { + DualSine12bit[Index] = (Sine12bit[Index] << 16) + (Sine12bit[Index]); + } + + /* DMA1 channel3 configuration: DualSine12bit is used as memory base address */ + DMA_Config(); + + /* DAC configuration ------------------------------------------------------*/ + DAC_Config(); + + /* TIM2 configuration ------------------------------------------------------*/ + TIM_Config(); + + while (1) + { + } +} + +/** + * @brief Configures the TIM2 + * @param None + * @retval None + */ +static void TIM_Config(void) +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + + /* TIM2 Periph clock enable */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); + + /* Time base configuration */ + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Period = 0xFF; + TIM_TimeBaseStructure.TIM_Prescaler = 0x0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); + + /* TIM2 TRGO selection: update event is selected as trigger for DAC */ + TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); + + /* TIM2 enable counter */ + TIM_Cmd(TIM2, ENABLE); +} + +/** + * @brief Configures DAC channel 1 and channel 2 + * @param None + * @retval None + */ +static void DAC_Config(void) +{ + DAC_InitTypeDef DAC_InitStructure; + GPIO_InitTypeDef GPIO_InitStructure; + + /* DAC Periph clock enable ----------------------------------------*/ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); + + /* SYSCFG Periph clock enable -------------------------------------*/ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); + + /* Enable GPIOA Periph clock --------------------------------------*/ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); + + /* Configure PA.04 (DAC1_OUT1), PA.05 (DAC1_OUT2) as analog */ + 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); + + /* Remap DAC1 Cahnnel1 DMA requests from DMA2 channel 3 to DMA1 channel 3 */ + SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM6DAC1Ch1, ENABLE); + + /* DAC deinitialize */ + DAC_DeInit(DAC1); + + /* Fill DAC InitStructure */ + DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; + DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; + DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits2_0; + DAC_InitStructure.DAC_Buffer_Switch = DAC_BufferSwitch_Enable; + + /* DAC channel1 Configuration */ + DAC_Init(DAC1, DAC_Channel_1, &DAC_InitStructure); + + /* DAC channel2 Configuration */ + DAC_Init(DAC1, DAC_Channel_2, &DAC_InitStructure); + + /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is + automatically connected to the DAC converter. */ + DAC_Cmd(DAC1, DAC_Channel_1, ENABLE); + + /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is + automatically connected to the DAC converter. */ + DAC_Cmd(DAC1, DAC_Channel_2, ENABLE); + + /* Enable DMA for DAC Channel1 */ + DAC_DMACmd(DAC1, DAC_Channel_1, ENABLE); +} + +/** + * @brief Configures DMA1 channel3 + * @param None + * @retval None + */ +static void DMA_Config(void) +{ + DMA_InitTypeDef DMA_InitStructure; + + /* Enable DMA1 clock -------------------------------------------------------*/ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); + + DMA_DeInit(DMA1_Channel3); + DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address; + DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit; + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; + 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_Word; + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; + DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; + DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; + DMA_Init(DMA1_Channel3, &DMA_InitStructure); + + /* Enable DMA1 Channel3 */ + DMA_Cmd(DMA1_Channel3, ENABLE); +} +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} +#endif + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/