2 ******************************************************************************
4 * @author MCD Application Team
6 * @date 19-September-2011
7 * @brief This file provides the hardware tests
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
21 /* Includes ------------------------------------------------------------------*/
24 //Library config for this project!!!!!!!!!!!
25 #include "stm32f4xx_conf.h"
28 /* Private typedef -----------------------------------------------------------*/
29 /* Private define ------------------------------------------------------------*/
30 #define MEMS_PASSCONDITION 15
31 /* Private macro -------------------------------------------------------------*/
32 /* Private variables ---------------------------------------------------------*/
33 /* Init Structure definition */
34 RCC_ClocksTypeDef RCC_Clocks;
35 ADC_InitTypeDef ADC_InitStructure;
36 ADC_CommonInitTypeDef ADC_CommonInitStructure;
38 __IO uint16_t ConvData1, ConvData2;
39 __IO uint16_t counter0 = 0, counter1 = 0, Idx = 0;
40 uint8_t ADC_Channel[2] = {ADC_Channel_2, ADC_Channel_3};
42 uint8_t GPIO_Pin [2] = {GPIO_Pin_2, GPIO_Pin_3};
44 uint16_t count = 0, count1 = 24, Left_Right = 0;
45 const int16_t sinebuf[48] = {0, 4276, 8480, 12539, 16383, 19947, 23169, 25995,
46 28377, 30272, 31650, 32486, 32767, 32486, 31650, 30272,
47 28377, 25995, 23169, 19947, 16383, 12539, 8480, 4276,
48 0, -4276, -8480, -12539, -16383, -19947, -23169, -25995,
49 -28377, -30272, -31650, -32486, -32767, -32486, -31650, -30272,
50 -28377, -25995, -23169, -19947, -16383, -12539, -8480, -4276
52 extern __IO uint32_t TimingDelay;
54 extern LIS302DL_InitTypeDef LIS302DL_InitStruct;
55 extern LIS302DL_FilterConfigTypeDef LIS302DL_FilterStruct;
57 extern __IO int8_t X_Offset, Y_Offset, Z_Offset;
58 extern uint8_t Buffer[6];
59 /* Private function prototypes -----------------------------------------------*/
60 /* Private functions ---------------------------------------------------------*/
62 * @brief Test MEMS Hardware.
63 * The main objectif of this test is to check the hardware connection of the
68 void Accelerometer_MEMS_Test(void)
70 uint8_t temp, memsteststatus = 0x00;
71 uint8_t xdata, ydata = 0;
73 /* MEMS configuration ------------------------------------------------------*/
74 /* Set configuration of LIS302DL*/
75 LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
76 LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100;
77 LIS302DL_InitStruct.Axes_Enable = LIS302DL_X_ENABLE | LIS302DL_Y_ENABLE;
78 LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3;
79 LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
80 LIS302DL_Init(&LIS302DL_InitStruct);
82 /* Set configuration of Internal High Pass Filter of LIS302DL*/
83 LIS302DL_FilterStruct.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER;
84 LIS302DL_FilterStruct.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1;
85 LIS302DL_FilterStruct.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2;
86 LIS302DL_FilterConfig(&LIS302DL_FilterStruct);
88 /* Required delay for the MEMS Accelerometre: Turn-on time = 3/Output data Rate
92 /* Read WHO_AM_I register */
93 LIS302DL_Read(&temp, LIS302DL_WHO_AM_I_ADDR, 1);
95 /* Check device identification register, this register should contains
96 the device identifier that for LIS302DL is set to 0x3B */
103 /* Wait until detecting all MEMS direction or timeout */
104 while((memsteststatus == 0x00)&&(TimingDelay != 0x00))
106 LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 4);
107 xdata = ABS((int8_t)(Buffer[0]));
108 ydata = ABS((int8_t)(Buffer[2]));
109 /* Check test PASS condition */
110 if ((xdata > MEMS_PASSCONDITION) || (ydata > MEMS_PASSCONDITION))
113 memsteststatus = 0x01;
117 /* MEMS test status: PASS */
118 if(memsteststatus != 0x00)
120 /* Turn Green LED ON: signaling MEMS Test PASS */
121 STM_EVAL_LEDOn(LED4);
123 /* Waiting User Button is pressed */
124 while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET)
127 /* Waiting User Button is Released */
128 while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)
131 /* Turn Green LED OFF: signaling the end of MEMS Test and switching to
133 STM_EVAL_LEDOff(LED4);
135 /* MEMS test status: Timeout occurs */
143 * @brief Test USB Hardware.
144 * The main objectif of this test is to check the hardware connection of the
145 * Audio and USB peripheral.
151 GPIO_InitTypeDef GPIO_InitStructure;
153 /******************************** USB Test **********************************/
155 /*----------------- Part1: without cables connected ------------------------*/
157 /* GPIOA, GPIOC and GPIOD clock enable */
158 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | \
159 RCC_AHB1Periph_GPIOD, ENABLE);
161 /* GPIOD Configuration: Pins 5 in output push-pull */
162 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
163 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
164 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
165 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
166 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
167 GPIO_Init(GPIOD, &GPIO_InitStructure);
169 /* Turn LED8 ON using PD5 */
170 GPIO_ResetBits(GPIOD, GPIO_Pin_5);
172 /* GPIOC Configuration: Pin 0 in output push-pull */
173 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
174 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
175 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
176 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
177 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
178 GPIO_Init(GPIOC, &GPIO_InitStructure);
180 /* GPIOA Configuration: Pin 9 in input pull-up */
181 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
182 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
183 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
184 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
185 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
186 GPIO_Init(GPIOA, &GPIO_InitStructure);
188 /* Turn LED7 ON using PC0 (5v) */
189 GPIO_ResetBits(GPIOC, GPIO_Pin_0);
191 /* Waiting delay 10ms */
194 if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9) == Bit_RESET)
199 /* GPIOA Configuration: Pins 10 in output push-pull */
200 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
201 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
202 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
203 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
204 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
205 GPIO_Init(GPIOA, &GPIO_InitStructure);
207 /* Waiting delay 10ms */
210 /* Check the ID level without cable connected */
211 if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10) == Bit_RESET)
216 /* Turn LED7 OFF using PC0 */
217 GPIO_SetBits(GPIOC, GPIO_Pin_0);
219 /* GPIOA Configuration: Pins 11, 12 in input pull-up */
220 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
221 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
222 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
223 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
224 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
225 GPIO_Init(GPIOA, &GPIO_InitStructure);
227 /* GPIOA Configuration: Pin 9 in output push-pull */
228 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
229 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
230 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
231 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
232 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
233 GPIO_Init(GPIOA, &GPIO_InitStructure);
234 GPIO_ResetBits(GPIOA, GPIO_Pin_9);
236 /* Waiting delay 10ms */
239 /* Check PA11 and PA12 level without cable connected */
240 if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET) || \
241 (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET))
246 /* GPIOA Configuration: Pins 12 in input pull-up */
247 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
248 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
249 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
250 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
251 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
252 GPIO_Init(GPIOA, &GPIO_InitStructure);
254 /* GPIOA Configuration: Pin 11 in output push-pull */
255 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
256 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
257 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
258 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
259 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
260 GPIO_Init(GPIOA, &GPIO_InitStructure);
261 GPIO_ResetBits(GPIOA, GPIO_Pin_11);
263 /* Waiting delay 10ms */
266 /* Check PA12 level without cable connected */
267 if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET)
272 /* GPIOA Configuration: Pins 11 in input pull-up */
273 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
274 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
275 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
276 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
277 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
278 GPIO_Init(GPIOA, &GPIO_InitStructure);
280 /* GPIOA Configuration: Pin 12 in output push-pull */
281 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
282 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
283 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
284 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
285 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
286 GPIO_Init(GPIOA, &GPIO_InitStructure);
287 GPIO_ResetBits(GPIOA, GPIO_Pin_12);
289 /* Waiting delay 10ms */
292 /* Check PA12 level without cable connected */
293 if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET)
298 /* GPIOA Configuration: Pins 9 in output push-pull */
299 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
300 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
301 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
302 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
303 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
304 GPIO_Init(GPIOA, &GPIO_InitStructure);
306 /* Turn LED7 ON using PA9 */
307 GPIO_SetBits(GPIOA, GPIO_Pin_9);
309 /* Turn Green LED ON: signaling Audio USB Test part1 PASS */
310 STM_EVAL_LEDOn(LED4);
312 /* Waiting User Button is pressed */
313 while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET)
316 /* Waiting User Button is Released */
317 while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET)
320 /* Turn Green LED OFF: signaling the end of Audio USB Test part1 and switching to
322 STM_EVAL_LEDOff(LED4);
324 /* Turn LED7 OFF using PA9 */
325 GPIO_ResetBits(GPIOA, GPIO_Pin_9);
327 /* Turn LED8 OFF using PD5 */
328 GPIO_SetBits(GPIOD, GPIO_Pin_5);
330 /*--------------- Part2: with Audio USB cables connected ------------------*/
332 /*********************************** USB Test *******************************/
333 /* Check the ID level with cable connected */
334 if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10) != Bit_RESET)
339 /* GPIOA Configuration: Pins 11, 12 in input pull-down */
340 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
341 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
342 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
343 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
344 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
345 GPIO_Init(GPIOA, &GPIO_InitStructure);
347 /* GPIOA Configuration: Pin 9 in output push-pull */
348 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
349 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
350 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
351 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
352 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
353 GPIO_Init(GPIOA, &GPIO_InitStructure);
354 GPIO_SetBits(GPIOA, GPIO_Pin_9);
356 /* Waiting delay 10ms */
359 /* Check PA11 and PA12 level with cable connected */
360 if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET) || \
361 (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET))
366 /* GPIOA Configuration: Pins 9, 12 in input pull-down */
367 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_12;
368 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
369 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
370 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
371 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
372 GPIO_Init(GPIOA, &GPIO_InitStructure);
374 /* GPIOA Configuration: Pin 11 in output push-pull */
375 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
376 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
377 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
378 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
379 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
380 GPIO_Init(GPIOA, &GPIO_InitStructure);
381 GPIO_SetBits(GPIOA, GPIO_Pin_11);
383 /* Waiting delay 10ms */
386 /* Check PA9 and PA12 level with cable connected */
387 if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9) == Bit_RESET)|| \
388 (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET))
393 /* GPIOA Configuration: Pins 9, 11 in input pull-down */
394 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_11;
395 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
396 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
397 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
398 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
399 GPIO_Init(GPIOA, &GPIO_InitStructure);
401 /* GPIOA Configuration: Pin 12 in output push-pull */
402 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
403 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
404 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
405 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
406 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
407 GPIO_Init(GPIOA, &GPIO_InitStructure);
408 GPIO_SetBits(GPIOA, GPIO_Pin_12);
410 /* Waiting delay 10ms */
413 /* Check PA9 and PA12 level with cable connected */
414 if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9) == Bit_RESET)|| \
415 (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET))
420 /* GPIOA Configuration: Pins 11, 12 in input pull-down */
421 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
422 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
423 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
424 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
425 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
426 GPIO_Init(GPIOA, &GPIO_InitStructure);
428 /* GPIOA Configuration: Pin 9 in output push-pull */
429 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
430 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
431 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
432 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
433 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
434 GPIO_Init(GPIOA, &GPIO_InitStructure);
436 /* Turn LED7 OFF using PA9 */
437 GPIO_ResetBits(GPIOA, GPIO_Pin_9);
441 * @brief Test Audio Hardware.
442 * The main objectif of this test is to check the hardware connection of the
447 void Audio_Test(void)
449 GPIO_InitTypeDef GPIO_InitStructure;
450 uint8_t audioteststatus = 0x00;
452 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
453 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
455 /* Set the current audio interface: I2S or DAC */
456 EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S);
458 /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOs...) */
459 if (EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 87, I2S_AudioFreq_48k) !=0)
463 /* I2S code to be exectued under the I2S interrupt */
466 /* ADC Common Init */
467 ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
468 ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div8;
469 ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
470 ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles;
471 ADC_CommonInit(&ADC_CommonInitStructure);
473 /* ADC peripherals Init */
474 ADC_StructInit(&ADC_InitStructure);
475 ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;
476 ADC_InitStructure.ADC_ScanConvMode = DISABLE;
477 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
478 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
479 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
480 ADC_InitStructure.ADC_NbrOfConversion = 1;
481 ADC_Init(ADC1, &ADC_InitStructure);
483 ADC_Init(ADC2, &ADC_InitStructure);
485 /* Configure ADC Channels pin as analog input */
486 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
487 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
488 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
489 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
490 GPIO_Init(GPIOA, &GPIO_InitStructure);
492 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 ;
493 GPIO_Init(GPIOA, &GPIO_InitStructure);
498 /* ADCperipheral[PerIdx] Regular Channel Config */
499 ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_56Cycles);
500 /* ADCperipheral[PerIdx] Regular Channel Config */
501 ADC_RegularChannelConfig(ADC2, ADC_Channel_3, 1, ADC_SampleTime_56Cycles);
503 ADC_Cmd(ADC1, ENABLE);
504 ADC_Cmd(ADC2, ENABLE);
507 /* Wait until detecting 500 data*/
508 while((audioteststatus == 0)&&(TimingDelay != 0))
510 ADC_SoftwareStartConv(ADC1);
511 while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
512 ConvData1 = ADC_GetConversionValue(ADC1);
514 ADC_SoftwareStartConv(ADC2);
515 while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET);
516 ConvData2 = ADC_GetConversionValue(ADC2);
518 /* 1.75V equals to 150 */
519 if ((ConvData1 > 150) && (ConvData2 < 10) && (counter1 != 500))
523 if ((ConvData1 < 10) && (ConvData2 > 150) && (counter0 != 500))
527 if((counter1 == 500) && (counter0 == 500))
533 /* Disable ADC Peripherals */
534 ADC_Cmd(ADC1, DISABLE);
535 ADC_Cmd(ADC2, DISABLE);
537 /* Audio test status: FAIL */
538 if(audioteststatus == 0)
544 EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_DAC);
545 /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOs...) */
546 if (EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 100, I2S_AudioFreq_48k) !=0)
551 /* DAC code to be exectued under the I2S interrupt */
558 ADC_Cmd(ADC1, ENABLE);
559 ADC_Cmd(ADC2, ENABLE);
562 /* Wait until detecting 50 data*/
563 while((audioteststatus == 0)&&(TimingDelay != 0))
566 ADC_SoftwareStartConv(ADC1);
567 while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
569 ConvData1 = ADC_GetConversionValue(ADC1);
571 ADC_SoftwareStartConv(ADC2);
572 while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET);
574 ConvData2 = ADC_GetConversionValue(ADC2);
576 /* 2.0V equals to 170 */
577 if ((ConvData1 > 170) && (ConvData2 > 170) &&(counter1 != 500))
581 if ((ConvData1 < 10) && (ConvData2 < 10) && (counter0 != 500))
585 if((counter1 == 500) && (counter0 == 500))
591 /* Audio test status: FAIL */
592 if(audioteststatus == 0x00)
597 /* Turn Green LED ON: signaling Audio USB Test part2 PASS */
598 STM_EVAL_LEDOn(LED4);
600 /* Waiting User_Button pressed */
601 while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET)
604 /* Turn Green LED OFF: signaling the end of Audio USB Test part2 */
605 STM_EVAL_LEDOff(LED4);
609 * @brief Test Micophone MEMS Hardware.
610 * The main objectif of this test is to check the hardware connection of the
611 * Microphone MEMS peripheral.
615 void Microphone_MEMS_Test(void)
617 uint16_t data = 0x00;
618 uint8_t index = 0x00;
619 I2S_InitTypeDef I2S_InitStructure;
620 GPIO_InitTypeDef GPIO_InitStructure;
622 /* Enable the SPI clock */
623 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
625 /* Enable GPIO clocks */
626 RCC_AHB1PeriphClockCmd(SPI_SCK_GPIO_CLK | SPI_MOSI_GPIO_CLK, ENABLE);
628 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
629 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
630 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
631 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
633 /* SPI SCK pin configuration */
634 GPIO_InitStructure.GPIO_Pin = SPI_SCK_PIN;
635 GPIO_Init(SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
637 /* Connect SPI pins to AF5 */
638 GPIO_PinAFConfig(SPI_SCK_GPIO_PORT, SPI_SCK_SOURCE, SPI_SCK_AF);
640 /* SPI MOSI pin configuration */
641 GPIO_InitStructure.GPIO_Pin = SPI_MOSI_PIN;
642 GPIO_Init(SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
644 GPIO_PinAFConfig(SPI_MOSI_GPIO_PORT, SPI_MOSI_SOURCE, SPI_MOSI_AF);
646 /* I2S configuration -------------------------------------------------------*/
647 SPI_I2S_DeInit(SPI2);
648 I2S_InitStructure.I2S_AudioFreq = 64000;
649 I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
650 I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
651 I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
652 I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
653 I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
654 /* Initialize the I2S peripheral with the structure above */
655 I2S_Init(SPI2, &I2S_InitStructure);
657 /* Enable the I2S peripheral */
658 I2S_Cmd(SPI2, ENABLE);
660 /* Waiting until MEMS microphone ready : Wake-up Time */
664 /* Wait until detect the click on the MEMS microphone or TimeOut delay*/
665 while((index < 30) && (TimingDelay != 0x00))
667 /* Waiting RXNE Flag or TimeOut delay */
668 while((SPI_I2S_GetFlagStatus(SPI2, SPI_FLAG_RXNE) == RESET)&& (TimingDelay != 0x00))
670 data = SPI_I2S_ReceiveData(SPI2);
677 /* MEMS microphone test status: Timeout occurs */
684 /*--------------------------------
685 Callbacks implementation:
686 the callbacks prototypes are defined in the stm324xg_eval_audio_codec.h file
687 and their implementation should be done in the user code if they are needed.
688 Below some examples of callback implementations.
689 --------------------------------------------------------*/
691 * @brief Calculates the remaining file size and new position of the pointer.
695 void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
697 /* Calculate the remaining audio data in the file and the new size
698 for the DMA transfer. If the Audio files size is less than the DMA max
699 data transfer size, so there is no calculation to be done, just restart
700 from the beginning of the file ... */
701 /* Check if the end of file has been reached */
706 * @brief Manages the DMA Half Transfer complete interrupt.
710 void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size)
712 #ifdef AUDIO_MAL_MODE_CIRCULAR
714 /* Display message on the LCD screen */
715 LCD_DisplayStringLine(Line8, " 1/2 Buffer Reached ");
717 #endif /* AUDIO_MAL_MODE_CIRCULAR */
719 /* Generally this interrupt routine is used to load the buffer when
720 a streaming scheme is used: When first Half buffer is already transferred load
721 the new data to the first half of buffer while DMA is transferring data from
722 the second half. And when Transfer complete occurs, load the second half of
723 the buffer while the DMA is transferring from the first half ... */
729 * @brief Get next data sample callback
731 * @retval Next data sample to be sent
733 uint16_t EVAL_AUDIO_GetSampleCallBack(void)
741 /* Get the next sample to be sent */
742 data = sinebuf[count++];
752 /* Get the next sample to be sent */
753 data = sinebuf[count1++];
764 /* Get the next sample to be sent */
765 data = 32768 + sinebuf[count++];
777 * @brief Manages the DMA FIFO error interrupt.
781 void EVAL_AUDIO_Error_CallBack(void* pData)
783 /* Stop the program with an infinite loop */
787 /* could also generate a system reset to recover from the error */
791 #ifndef USE_DEFAULT_TIMEOUT_CALLBACK
793 * @brief Basic management of the timeout situation.
797 uint32_t Codec_TIMEOUT_UserCallback(void)
799 /* Block communication and all processes */
804 #endif /* USE_DEFAULT_TIMEOUT_CALLBACK */
805 /*----------------------------------------------------------------------------*/
808 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/