won't compile
main.c@0:b079fa4ed182, 2016-11-02 (annotated)
- Committer:
- richardv
- Date:
- Wed Nov 02 23:50:52 2016 +0000
- Revision:
- 0:b079fa4ed182
DMA RAM DAC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
richardv | 0:b079fa4ed182 | 1 | /** |
richardv | 0:b079fa4ed182 | 2 | ****************************************************************************** |
richardv | 0:b079fa4ed182 | 3 | * @file DMA_RAM_DAC/main.c |
richardv | 0:b079fa4ed182 | 4 | * @author MCD Application Team |
richardv | 0:b079fa4ed182 | 5 | * @version V1.0.0 |
richardv | 0:b079fa4ed182 | 6 | * @date 20-June-2014 |
richardv | 0:b079fa4ed182 | 7 | * @brief Main program body |
richardv | 0:b079fa4ed182 | 8 | ****************************************************************************** |
richardv | 0:b079fa4ed182 | 9 | * @attention |
richardv | 0:b079fa4ed182 | 10 | * |
richardv | 0:b079fa4ed182 | 11 | * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> |
richardv | 0:b079fa4ed182 | 12 | * |
richardv | 0:b079fa4ed182 | 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
richardv | 0:b079fa4ed182 | 14 | * You may not use this file except in compliance with the License. |
richardv | 0:b079fa4ed182 | 15 | * You may obtain a copy of the License at: |
richardv | 0:b079fa4ed182 | 16 | * |
richardv | 0:b079fa4ed182 | 17 | * http://www.st.com/software_license_agreement_liberty_v2 |
richardv | 0:b079fa4ed182 | 18 | * |
richardv | 0:b079fa4ed182 | 19 | * Unless required by applicable law or agreed to in writing, software |
richardv | 0:b079fa4ed182 | 20 | * distributed under the License is distributed on an "AS IS" BASIS, |
richardv | 0:b079fa4ed182 | 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
richardv | 0:b079fa4ed182 | 22 | * See the License for the specific language governing permissions and |
richardv | 0:b079fa4ed182 | 23 | * limitations under the License. |
richardv | 0:b079fa4ed182 | 24 | * |
richardv | 0:b079fa4ed182 | 25 | ****************************************************************************** |
richardv | 0:b079fa4ed182 | 26 | */ |
richardv | 0:b079fa4ed182 | 27 | |
richardv | 0:b079fa4ed182 | 28 | /* Includes ------------------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 29 | #include "main.h" |
richardv | 0:b079fa4ed182 | 30 | |
richardv | 0:b079fa4ed182 | 31 | /** @addtogroup STM32F3348_DISCOVERY_Examples |
richardv | 0:b079fa4ed182 | 32 | * @{ |
richardv | 0:b079fa4ed182 | 33 | */ |
richardv | 0:b079fa4ed182 | 34 | |
richardv | 0:b079fa4ed182 | 35 | /** @addtogroup DMA_RAM_DAC |
richardv | 0:b079fa4ed182 | 36 | * @{ |
richardv | 0:b079fa4ed182 | 37 | */ |
richardv | 0:b079fa4ed182 | 38 | |
richardv | 0:b079fa4ed182 | 39 | /* Private typedef -----------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 40 | /* Private define ------------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 41 | /* Private macro -------------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 42 | /* Private variables ---------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 43 | uint32_t DualSine12bit[32]; |
richardv | 0:b079fa4ed182 | 44 | |
richardv | 0:b079fa4ed182 | 45 | /* Private function prototypes -----------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 46 | static void TIM_Config(void); |
richardv | 0:b079fa4ed182 | 47 | static void DAC_Config(void); |
richardv | 0:b079fa4ed182 | 48 | static void DMA_Config(void); |
richardv | 0:b079fa4ed182 | 49 | |
richardv | 0:b079fa4ed182 | 50 | /* Private functions ---------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 51 | |
richardv | 0:b079fa4ed182 | 52 | /** |
richardv | 0:b079fa4ed182 | 53 | * @brief Main program. |
richardv | 0:b079fa4ed182 | 54 | * @param None |
richardv | 0:b079fa4ed182 | 55 | * @retval None |
richardv | 0:b079fa4ed182 | 56 | */ |
richardv | 0:b079fa4ed182 | 57 | int main(void) |
richardv | 0:b079fa4ed182 | 58 | { |
richardv | 0:b079fa4ed182 | 59 | uint16_t Sine12bit[32] = { |
richardv | 0:b079fa4ed182 | 60 | 2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056, |
richardv | 0:b079fa4ed182 | 61 | 3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, |
richardv | 0:b079fa4ed182 | 62 | 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647}; |
richardv | 0:b079fa4ed182 | 63 | uint32_t Index = 0; |
richardv | 0:b079fa4ed182 | 64 | |
richardv | 0:b079fa4ed182 | 65 | /*!< At this stage the microcontroller clock setting is already configured, |
richardv | 0:b079fa4ed182 | 66 | this is done through SystemInit() function which is called from startup |
richardv | 0:b079fa4ed182 | 67 | file (startup_stm32f334x8.s) before to branch to application main. |
richardv | 0:b079fa4ed182 | 68 | To reconfigure the default setting of SystemInit() function, refer to |
richardv | 0:b079fa4ed182 | 69 | system_stm32f30x.c file |
richardv | 0:b079fa4ed182 | 70 | */ |
richardv | 0:b079fa4ed182 | 71 | |
richardv | 0:b079fa4ed182 | 72 | /* Fill DualSine12bit table */ |
richardv | 0:b079fa4ed182 | 73 | for (Index = 0; Index < 32; Index++) |
richardv | 0:b079fa4ed182 | 74 | { |
richardv | 0:b079fa4ed182 | 75 | DualSine12bit[Index] = (Sine12bit[Index] << 16) + (Sine12bit[Index]); |
richardv | 0:b079fa4ed182 | 76 | } |
richardv | 0:b079fa4ed182 | 77 | |
richardv | 0:b079fa4ed182 | 78 | /* DMA1 channel3 configuration: DualSine12bit is used as memory base address */ |
richardv | 0:b079fa4ed182 | 79 | DMA_Config(); |
richardv | 0:b079fa4ed182 | 80 | |
richardv | 0:b079fa4ed182 | 81 | /* DAC configuration ------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 82 | DAC_Config(); |
richardv | 0:b079fa4ed182 | 83 | |
richardv | 0:b079fa4ed182 | 84 | /* TIM2 configuration ------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 85 | TIM_Config(); |
richardv | 0:b079fa4ed182 | 86 | |
richardv | 0:b079fa4ed182 | 87 | while (1) |
richardv | 0:b079fa4ed182 | 88 | { |
richardv | 0:b079fa4ed182 | 89 | } |
richardv | 0:b079fa4ed182 | 90 | } |
richardv | 0:b079fa4ed182 | 91 | |
richardv | 0:b079fa4ed182 | 92 | /** |
richardv | 0:b079fa4ed182 | 93 | * @brief Configures the TIM2 |
richardv | 0:b079fa4ed182 | 94 | * @param None |
richardv | 0:b079fa4ed182 | 95 | * @retval None |
richardv | 0:b079fa4ed182 | 96 | */ |
richardv | 0:b079fa4ed182 | 97 | static void TIM_Config(void) |
richardv | 0:b079fa4ed182 | 98 | { |
richardv | 0:b079fa4ed182 | 99 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
richardv | 0:b079fa4ed182 | 100 | |
richardv | 0:b079fa4ed182 | 101 | /* TIM2 Periph clock enable */ |
richardv | 0:b079fa4ed182 | 102 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); |
richardv | 0:b079fa4ed182 | 103 | |
richardv | 0:b079fa4ed182 | 104 | /* Time base configuration */ |
richardv | 0:b079fa4ed182 | 105 | TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); |
richardv | 0:b079fa4ed182 | 106 | TIM_TimeBaseStructure.TIM_Period = 0xFF; |
richardv | 0:b079fa4ed182 | 107 | TIM_TimeBaseStructure.TIM_Prescaler = 0x0; |
richardv | 0:b079fa4ed182 | 108 | TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; |
richardv | 0:b079fa4ed182 | 109 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
richardv | 0:b079fa4ed182 | 110 | TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); |
richardv | 0:b079fa4ed182 | 111 | |
richardv | 0:b079fa4ed182 | 112 | /* TIM2 TRGO selection: update event is selected as trigger for DAC */ |
richardv | 0:b079fa4ed182 | 113 | TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); |
richardv | 0:b079fa4ed182 | 114 | |
richardv | 0:b079fa4ed182 | 115 | /* TIM2 enable counter */ |
richardv | 0:b079fa4ed182 | 116 | TIM_Cmd(TIM2, ENABLE); |
richardv | 0:b079fa4ed182 | 117 | } |
richardv | 0:b079fa4ed182 | 118 | |
richardv | 0:b079fa4ed182 | 119 | /** |
richardv | 0:b079fa4ed182 | 120 | * @brief Configures DAC channel 1 and channel 2 |
richardv | 0:b079fa4ed182 | 121 | * @param None |
richardv | 0:b079fa4ed182 | 122 | * @retval None |
richardv | 0:b079fa4ed182 | 123 | */ |
richardv | 0:b079fa4ed182 | 124 | static void DAC_Config(void) |
richardv | 0:b079fa4ed182 | 125 | { |
richardv | 0:b079fa4ed182 | 126 | DAC_InitTypeDef DAC_InitStructure; |
richardv | 0:b079fa4ed182 | 127 | GPIO_InitTypeDef GPIO_InitStructure; |
richardv | 0:b079fa4ed182 | 128 | |
richardv | 0:b079fa4ed182 | 129 | /* DAC Periph clock enable ----------------------------------------*/ |
richardv | 0:b079fa4ed182 | 130 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); |
richardv | 0:b079fa4ed182 | 131 | |
richardv | 0:b079fa4ed182 | 132 | /* SYSCFG Periph clock enable -------------------------------------*/ |
richardv | 0:b079fa4ed182 | 133 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); |
richardv | 0:b079fa4ed182 | 134 | |
richardv | 0:b079fa4ed182 | 135 | /* Enable GPIOA Periph clock --------------------------------------*/ |
richardv | 0:b079fa4ed182 | 136 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); |
richardv | 0:b079fa4ed182 | 137 | |
richardv | 0:b079fa4ed182 | 138 | /* Configure PA.04 (DAC1_OUT1), PA.05 (DAC1_OUT2) as analog */ |
richardv | 0:b079fa4ed182 | 139 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; |
richardv | 0:b079fa4ed182 | 140 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; |
richardv | 0:b079fa4ed182 | 141 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; |
richardv | 0:b079fa4ed182 | 142 | GPIO_Init(GPIOA, &GPIO_InitStructure); |
richardv | 0:b079fa4ed182 | 143 | |
richardv | 0:b079fa4ed182 | 144 | /* Remap DAC1 Cahnnel1 DMA requests from DMA2 channel 3 to DMA1 channel 3 */ |
richardv | 0:b079fa4ed182 | 145 | SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM6DAC1Ch1, ENABLE); |
richardv | 0:b079fa4ed182 | 146 | |
richardv | 0:b079fa4ed182 | 147 | /* DAC deinitialize */ |
richardv | 0:b079fa4ed182 | 148 | DAC_DeInit(DAC1); |
richardv | 0:b079fa4ed182 | 149 | |
richardv | 0:b079fa4ed182 | 150 | /* Fill DAC InitStructure */ |
richardv | 0:b079fa4ed182 | 151 | DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; |
richardv | 0:b079fa4ed182 | 152 | DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; |
richardv | 0:b079fa4ed182 | 153 | DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits2_0; |
richardv | 0:b079fa4ed182 | 154 | DAC_InitStructure.DAC_Buffer_Switch = DAC_BufferSwitch_Enable; |
richardv | 0:b079fa4ed182 | 155 | |
richardv | 0:b079fa4ed182 | 156 | /* DAC channel1 Configuration */ |
richardv | 0:b079fa4ed182 | 157 | DAC_Init(DAC1, DAC_Channel_1, &DAC_InitStructure); |
richardv | 0:b079fa4ed182 | 158 | |
richardv | 0:b079fa4ed182 | 159 | /* DAC channel2 Configuration */ |
richardv | 0:b079fa4ed182 | 160 | DAC_Init(DAC1, DAC_Channel_2, &DAC_InitStructure); |
richardv | 0:b079fa4ed182 | 161 | |
richardv | 0:b079fa4ed182 | 162 | /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is |
richardv | 0:b079fa4ed182 | 163 | automatically connected to the DAC converter. */ |
richardv | 0:b079fa4ed182 | 164 | DAC_Cmd(DAC1, DAC_Channel_1, ENABLE); |
richardv | 0:b079fa4ed182 | 165 | |
richardv | 0:b079fa4ed182 | 166 | /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is |
richardv | 0:b079fa4ed182 | 167 | automatically connected to the DAC converter. */ |
richardv | 0:b079fa4ed182 | 168 | DAC_Cmd(DAC1, DAC_Channel_2, ENABLE); |
richardv | 0:b079fa4ed182 | 169 | |
richardv | 0:b079fa4ed182 | 170 | /* Enable DMA for DAC Channel1 */ |
richardv | 0:b079fa4ed182 | 171 | DAC_DMACmd(DAC1, DAC_Channel_1, ENABLE); |
richardv | 0:b079fa4ed182 | 172 | } |
richardv | 0:b079fa4ed182 | 173 | |
richardv | 0:b079fa4ed182 | 174 | /** |
richardv | 0:b079fa4ed182 | 175 | * @brief Configures DMA1 channel3 |
richardv | 0:b079fa4ed182 | 176 | * @param None |
richardv | 0:b079fa4ed182 | 177 | * @retval None |
richardv | 0:b079fa4ed182 | 178 | */ |
richardv | 0:b079fa4ed182 | 179 | static void DMA_Config(void) |
richardv | 0:b079fa4ed182 | 180 | { |
richardv | 0:b079fa4ed182 | 181 | DMA_InitTypeDef DMA_InitStructure; |
richardv | 0:b079fa4ed182 | 182 | |
richardv | 0:b079fa4ed182 | 183 | /* Enable DMA1 clock -------------------------------------------------------*/ |
richardv | 0:b079fa4ed182 | 184 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); |
richardv | 0:b079fa4ed182 | 185 | |
richardv | 0:b079fa4ed182 | 186 | DMA_DeInit(DMA1_Channel3); |
richardv | 0:b079fa4ed182 | 187 | DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address; |
richardv | 0:b079fa4ed182 | 188 | DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit; |
richardv | 0:b079fa4ed182 | 189 | DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; |
richardv | 0:b079fa4ed182 | 190 | DMA_InitStructure.DMA_BufferSize = 32; |
richardv | 0:b079fa4ed182 | 191 | DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; |
richardv | 0:b079fa4ed182 | 192 | DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; |
richardv | 0:b079fa4ed182 | 193 | DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; |
richardv | 0:b079fa4ed182 | 194 | DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; |
richardv | 0:b079fa4ed182 | 195 | DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; |
richardv | 0:b079fa4ed182 | 196 | DMA_InitStructure.DMA_Priority = DMA_Priority_High; |
richardv | 0:b079fa4ed182 | 197 | DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; |
richardv | 0:b079fa4ed182 | 198 | DMA_Init(DMA1_Channel3, &DMA_InitStructure); |
richardv | 0:b079fa4ed182 | 199 | |
richardv | 0:b079fa4ed182 | 200 | /* Enable DMA1 Channel3 */ |
richardv | 0:b079fa4ed182 | 201 | DMA_Cmd(DMA1_Channel3, ENABLE); |
richardv | 0:b079fa4ed182 | 202 | } |
richardv | 0:b079fa4ed182 | 203 | #ifdef USE_FULL_ASSERT |
richardv | 0:b079fa4ed182 | 204 | |
richardv | 0:b079fa4ed182 | 205 | /** |
richardv | 0:b079fa4ed182 | 206 | * @brief Reports the name of the source file and the source line number |
richardv | 0:b079fa4ed182 | 207 | * where the assert_param error has occurred. |
richardv | 0:b079fa4ed182 | 208 | * @param file: pointer to the source file name |
richardv | 0:b079fa4ed182 | 209 | * @param line: assert_param error line source number |
richardv | 0:b079fa4ed182 | 210 | * @retval None |
richardv | 0:b079fa4ed182 | 211 | */ |
richardv | 0:b079fa4ed182 | 212 | void assert_failed(uint8_t* file, uint32_t line) |
richardv | 0:b079fa4ed182 | 213 | { |
richardv | 0:b079fa4ed182 | 214 | /* User can add his own implementation to report the file name and line number, |
richardv | 0:b079fa4ed182 | 215 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
richardv | 0:b079fa4ed182 | 216 | |
richardv | 0:b079fa4ed182 | 217 | /* Infinite loop */ |
richardv | 0:b079fa4ed182 | 218 | while (1) |
richardv | 0:b079fa4ed182 | 219 | { |
richardv | 0:b079fa4ed182 | 220 | } |
richardv | 0:b079fa4ed182 | 221 | } |
richardv | 0:b079fa4ed182 | 222 | #endif |
richardv | 0:b079fa4ed182 | 223 | |
richardv | 0:b079fa4ed182 | 224 | /** |
richardv | 0:b079fa4ed182 | 225 | * @} |
richardv | 0:b079fa4ed182 | 226 | */ |
richardv | 0:b079fa4ed182 | 227 | |
richardv | 0:b079fa4ed182 | 228 | /** |
richardv | 0:b079fa4ed182 | 229 | * @} |
richardv | 0:b079fa4ed182 | 230 | */ |
richardv | 0:b079fa4ed182 | 231 | |
richardv | 0:b079fa4ed182 | 232 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |