AnsweredAssumed Answered

STM32F4DISCOVERY using DAC pins A4 & A5 without the codec

Question asked by prieur.jean on Apr 10, 2013
Latest reply on Jul 15, 2013 by yannickL
Hello,

I'm using a STM32F4DISCOVERY to program the firmware of my future board. I want to use the integrated 12 bit DAC of the board to generate analog simple signals on the A4 and A5 pins, but I don't want to use the external audio codec CS43L22 of the discovery board.

On the STM32F4DISCOVERY board A4 and A5 are connected to the LIS30 and the CS43L22 but I think it's OK to use these pins for generate analog signals. Am I right ?



So I try to program with this code I found on a forum:

01.int main(void)
02.{
03.  GPIO_InitTypeDef GPIO_InitStructure;
04.  DAC_InitTypeDef DAC_InitStructure;
05.    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
06.  
07.  /* Enable DAC and GPIOC clock */
08.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
09.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM2, ENABLE);
10.  
11.  /* Configure PA.04/05 (DAC) as output -------------------------*/
12.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
13.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
14.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
15.  GPIO_Init(GPIOA, &GPIO_InitStructure);
16.  
17.  
18.  /* DAC channel1 Configuration */
19.  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
20.  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
21.  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
22.  DAC_Init(DAC_Channel_2, &DAC_InitStructure);
23.  
24.  /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
25.     automatically connected to the DAC converter. */
26.  DAC_Cmd(DAC_Channel_2, ENABLE);
27.  
28.  while (1)
29.  {
30.        int i;
31.  
32.        for(i=0; i<4096; i++)
33.          DAC_SetChannel2Data(DAC_Align_12b_R, i);
34.  }
35.  
36.  
37.  /* does not exit - kind of important */
38.  
39.  return(1);
40.}


This code works on STM32F3xx but there is some problems with STM32F4xx compactibility. Line 8, "RCC_APB2Periph_AFIO" and "RCC_APB2Periph_GPIOA" are not declared in librairies.

Is anyone know what are the RCC_APB2Periph_AFIO and RCC_APB2Periph_GPIOA equivalent in STM32F4xx ? Thanks for your help !

note: I'm using the latest STM32F4xx librairies, but not the stm32f4_discovery librairy.

Outcomes