Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.c
00001 /** 00002 ****************************************************************************** 00003 * @file DMA_RAM_DAC/main.c 00004 * @author MCD Application Team 00005 * @version V1.0.0 00006 * @date 20-June-2014 00007 * @brief Main program body 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "main.h" 00030 00031 /** @addtogroup STM32F3348_DISCOVERY_Examples 00032 * @{ 00033 */ 00034 00035 /** @addtogroup DMA_RAM_DAC 00036 * @{ 00037 */ 00038 00039 /* Private typedef -----------------------------------------------------------*/ 00040 /* Private define ------------------------------------------------------------*/ 00041 /* Private macro -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 uint32_t DualSine12bit[32]; 00044 00045 /* Private function prototypes -----------------------------------------------*/ 00046 static void TIM_Config(void); 00047 static void DAC_Config(void); 00048 static void DMA_Config(void); 00049 00050 /* Private functions ---------------------------------------------------------*/ 00051 00052 /** 00053 * @brief Main program. 00054 * @param None 00055 * @retval None 00056 */ 00057 int main(void) 00058 { 00059 uint16_t Sine12bit[32] = { 00060 2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056, 00061 3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, 00062 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647}; 00063 uint32_t Index = 0; 00064 00065 /*!< At this stage the microcontroller clock setting is already configured, 00066 this is done through SystemInit() function which is called from startup 00067 file (startup_stm32f334x8.s) before to branch to application main. 00068 To reconfigure the default setting of SystemInit() function, refer to 00069 system_stm32f30x.c file 00070 */ 00071 00072 /* Fill DualSine12bit table */ 00073 for (Index = 0; Index < 32; Index++) 00074 { 00075 DualSine12bit[Index] = (Sine12bit[Index] << 16) + (Sine12bit[Index]); 00076 } 00077 00078 /* DMA1 channel3 configuration: DualSine12bit is used as memory base address */ 00079 DMA_Config(); 00080 00081 /* DAC configuration ------------------------------------------------------*/ 00082 DAC_Config(); 00083 00084 /* TIM2 configuration ------------------------------------------------------*/ 00085 TIM_Config(); 00086 00087 while (1) 00088 { 00089 } 00090 } 00091 00092 /** 00093 * @brief Configures the TIM2 00094 * @param None 00095 * @retval None 00096 */ 00097 static void TIM_Config(void) 00098 { 00099 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 00100 00101 /* TIM2 Periph clock enable */ 00102 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); 00103 00104 /* Time base configuration */ 00105 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); 00106 TIM_TimeBaseStructure.TIM_Period = 0xFF; 00107 TIM_TimeBaseStructure.TIM_Prescaler = 0x0; 00108 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; 00109 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 00110 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); 00111 00112 /* TIM2 TRGO selection: update event is selected as trigger for DAC */ 00113 TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); 00114 00115 /* TIM2 enable counter */ 00116 TIM_Cmd(TIM2, ENABLE); 00117 } 00118 00119 /** 00120 * @brief Configures DAC channel 1 and channel 2 00121 * @param None 00122 * @retval None 00123 */ 00124 static void DAC_Config(void) 00125 { 00126 DAC_InitTypeDef DAC_InitStructure; 00127 GPIO_InitTypeDef GPIO_InitStructure; 00128 00129 /* DAC Periph clock enable ----------------------------------------*/ 00130 RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); 00131 00132 /* SYSCFG Periph clock enable -------------------------------------*/ 00133 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 00134 00135 /* Enable GPIOA Periph clock --------------------------------------*/ 00136 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); 00137 00138 /* Configure PA.04 (DAC1_OUT1), PA.05 (DAC1_OUT2) as analog */ 00139 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; 00140 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; 00141 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 00142 GPIO_Init(GPIOA, &GPIO_InitStructure); 00143 00144 /* Remap DAC1 Cahnnel1 DMA requests from DMA2 channel 3 to DMA1 channel 3 */ 00145 SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM6DAC1Ch1, ENABLE); 00146 00147 /* DAC deinitialize */ 00148 DAC_DeInit(DAC1); 00149 00150 /* Fill DAC InitStructure */ 00151 DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; 00152 DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; 00153 DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits2_0; 00154 DAC_InitStructure.DAC_Buffer_Switch = DAC_BufferSwitch_Enable; 00155 00156 /* DAC channel1 Configuration */ 00157 DAC_Init(DAC1, DAC_Channel_1, &DAC_InitStructure); 00158 00159 /* DAC channel2 Configuration */ 00160 DAC_Init(DAC1, DAC_Channel_2, &DAC_InitStructure); 00161 00162 /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 00163 automatically connected to the DAC converter. */ 00164 DAC_Cmd(DAC1, DAC_Channel_1, ENABLE); 00165 00166 /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is 00167 automatically connected to the DAC converter. */ 00168 DAC_Cmd(DAC1, DAC_Channel_2, ENABLE); 00169 00170 /* Enable DMA for DAC Channel1 */ 00171 DAC_DMACmd(DAC1, DAC_Channel_1, ENABLE); 00172 } 00173 00174 /** 00175 * @brief Configures DMA1 channel3 00176 * @param None 00177 * @retval None 00178 */ 00179 static void DMA_Config(void) 00180 { 00181 DMA_InitTypeDef DMA_InitStructure; 00182 00183 /* Enable DMA1 clock -------------------------------------------------------*/ 00184 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); 00185 00186 DMA_DeInit(DMA1_Channel3); 00187 DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address; 00188 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit; 00189 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; 00190 DMA_InitStructure.DMA_BufferSize = 32; 00191 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 00192 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; 00193 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; 00194 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; 00195 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; 00196 DMA_InitStructure.DMA_Priority = DMA_Priority_High; 00197 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; 00198 DMA_Init(DMA1_Channel3, &DMA_InitStructure); 00199 00200 /* Enable DMA1 Channel3 */ 00201 DMA_Cmd(DMA1_Channel3, ENABLE); 00202 } 00203 #ifdef USE_FULL_ASSERT 00204 00205 /** 00206 * @brief Reports the name of the source file and the source line number 00207 * where the assert_param error has occurred. 00208 * @param file: pointer to the source file name 00209 * @param line: assert_param error line source number 00210 * @retval None 00211 */ 00212 void assert_failed(uint8_t* file, uint32_t line) 00213 { 00214 /* User can add his own implementation to report the file name and line number, 00215 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00216 00217 /* Infinite loop */ 00218 while (1) 00219 { 00220 } 00221 } 00222 #endif 00223 00224 /** 00225 * @} 00226 */ 00227 00228 /** 00229 * @} 00230 */ 00231 00232 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 03:44:51 by
1.7.2