Simple test application for the STMicroelectronics X-NUCLEO-CCA02M1 MEMS Microphones Expansion Board, built against mbed classic.

Dependencies:   X_NUCLEO_CCA02M1 mbed ST_Events-old

Fork of HelloWorld_CCA02M1_mbedOS by ST

Recording audio with the X-NUCLEO-CCA02M1 Expansion Board

This application provides a simple example of usage of the X-NUCLEO-CCA02M1 MEMS Microphones Expansion Board, built against mbed classic 2.x.

It shows how to record a 2-channel stereo signal as an array of PCM samples (16 bit/sample) that can be acquired through an audio SW like Audacity, for example.

Microphones configuration

Currently the configurations supported are the following:

  • Stereo@48KHz
  • Stereo@44.1KHz (default, CD audio quality)
  • Stereo@32KHz
  • Stereo@16KHz
  • Stereo@8KHz
  • Mono@48KHz
  • Mono@44.1KHz
  • Mono@32KHz
  • Mono@16KHz
  • Mono@8KHz

Mono configurations need a Jumper connecting PB_5 and PB_13 on the Morpho connector to properly work.


Platform compatibility

  • This board can be currently used with the Nucleo F4 Family only, please see the ST_I2S library compatibility for further information.
  • Please note that the main application makes use of the "events" library (i.e. the "ST_Events" library imported as "events" library), which is not included into the "mbed" library.
  • The application built against mbed OS can be found here.


Acquiring through the USB on Windows

In order to acquire the recorded PCM audio channel with an audio SW on a PC, please connect the expansion board to a USB port of the PC, and the Nucleo board to a USB power supply.
On Windows, click on the speaker icon on the bottom bar, select "Recording devices", "Microphone", "Properties", then click on the "Advanced" panel, and select "1/2 channels, 16 bit, 16/32KHz" according to board configuration.
Open your preferred audio SW, like "Audacity" for example, configure it to acquire a 2-channel stereo at 16KHz (for default configuration), and record.

Committer:
Davidroid
Date:
Wed Dec 12 16:13:19 2018 +0000
Revision:
18:0d6b37356014
Parent:
17:97dffa2e68f7
Update with the new version of the library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davide.aliprandi@st.com 0:7d07f4df31e1 1 /**
davide.aliprandi@st.com 0:7d07f4df31e1 2 ******************************************************************************
davide.aliprandi@st.com 0:7d07f4df31e1 3 * @file main.cpp
davide.aliprandi@st.com 0:7d07f4df31e1 4 * @author Davide Aliprandi, STMicroelectronics
davide.aliprandi@st.com 0:7d07f4df31e1 5 * @version V1.0.0
davide.aliprandi@st.com 0:7d07f4df31e1 6 * @date October 28th, 2016
davide.aliprandi@st.com 0:7d07f4df31e1 7 * @brief mbed test application for the STMicroelectronics X-NUCLEO-CCA02M1
davide.aliprandi@st.com 0:7d07f4df31e1 8 * MEMS Microphones Expansion Board.
davide.aliprandi@st.com 0:7d07f4df31e1 9 ******************************************************************************
davide.aliprandi@st.com 0:7d07f4df31e1 10 * @attention
davide.aliprandi@st.com 0:7d07f4df31e1 11 *
davide.aliprandi@st.com 0:7d07f4df31e1 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
davide.aliprandi@st.com 0:7d07f4df31e1 13 *
davide.aliprandi@st.com 0:7d07f4df31e1 14 * Redistribution and use in source and binary forms, with or without modification,
davide.aliprandi@st.com 0:7d07f4df31e1 15 * are permitted provided that the following conditions are met:
davide.aliprandi@st.com 0:7d07f4df31e1 16 * 1. Redistributions of source code must retain the above copyright notice,
davide.aliprandi@st.com 0:7d07f4df31e1 17 * this list of conditions and the following disclaimer.
davide.aliprandi@st.com 0:7d07f4df31e1 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
davide.aliprandi@st.com 0:7d07f4df31e1 19 * this list of conditions and the following disclaimer in the documentation
davide.aliprandi@st.com 0:7d07f4df31e1 20 * and/or other materials provided with the distribution.
davide.aliprandi@st.com 0:7d07f4df31e1 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
davide.aliprandi@st.com 0:7d07f4df31e1 22 * may be used to endorse or promote products derived from this software
davide.aliprandi@st.com 0:7d07f4df31e1 23 * without specific prior written permission.
davide.aliprandi@st.com 0:7d07f4df31e1 24 *
davide.aliprandi@st.com 0:7d07f4df31e1 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
davide.aliprandi@st.com 0:7d07f4df31e1 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
davide.aliprandi@st.com 0:7d07f4df31e1 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
davide.aliprandi@st.com 0:7d07f4df31e1 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
davide.aliprandi@st.com 0:7d07f4df31e1 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
davide.aliprandi@st.com 0:7d07f4df31e1 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
davide.aliprandi@st.com 0:7d07f4df31e1 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
davide.aliprandi@st.com 0:7d07f4df31e1 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
davide.aliprandi@st.com 0:7d07f4df31e1 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
davide.aliprandi@st.com 0:7d07f4df31e1 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
davide.aliprandi@st.com 0:7d07f4df31e1 35 *
davide.aliprandi@st.com 0:7d07f4df31e1 36 ******************************************************************************
davide.aliprandi@st.com 0:7d07f4df31e1 37 */
davide.aliprandi@st.com 0:7d07f4df31e1 38
davide.aliprandi@st.com 0:7d07f4df31e1 39
davide.aliprandi@st.com 0:7d07f4df31e1 40 /* Includes ------------------------------------------------------------------*/
davide.aliprandi@st.com 0:7d07f4df31e1 41
davide.aliprandi@st.com 0:7d07f4df31e1 42 /* mbed specific header files. */
davide.aliprandi@st.com 0:7d07f4df31e1 43 #include "mbed.h"
davide.aliprandi@st.com 0:7d07f4df31e1 44
davide.aliprandi@st.com 0:7d07f4df31e1 45
davide.aliprandi@st.com 0:7d07f4df31e1 46 #if DEVICE_I2S
davide.aliprandi@st.com 0:7d07f4df31e1 47
davide.aliprandi@st.com 0:7d07f4df31e1 48 /* Expansion Board specific header files. */
davide.aliprandi@st.com 0:7d07f4df31e1 49 #include "XNucleoCCA02M1.h"
davide.aliprandi@st.com 0:7d07f4df31e1 50
davide.aliprandi@st.com 0:7d07f4df31e1 51
davide.aliprandi@st.com 0:7d07f4df31e1 52 /* Variables -----------------------------------------------------------------*/
davide.aliprandi@st.com 0:7d07f4df31e1 53
Davidroid 7:760d8e527b67 54 /*
Davidroid 7:760d8e527b67 55 * Initialization parameters.
Davidroid 7:760d8e527b67 56 * Note: put a jumper to connect PB_5 and PB_13 on the MORPHO connector when
Davidroid 7:760d8e527b67 57 * running a mono configuration.
Davidroid 7:760d8e527b67 58 */
davide.aliprandi@st.com 0:7d07f4df31e1 59 XNucleoCCA02M1_init_t init =
davide.aliprandi@st.com 0:7d07f4df31e1 60 {
Davidroid 12:203c08553f4d 61 44100, /* Default Sampling Frequency [Hz]. */
Davidroid 12:203c08553f4d 62 2 /* Default number of channels. */
davide.aliprandi@st.com 0:7d07f4df31e1 63 };
davide.aliprandi@st.com 0:7d07f4df31e1 64
davide.aliprandi@st.com 0:7d07f4df31e1 65
davide.aliprandi@st.com 0:7d07f4df31e1 66 /* Functions -----------------------------------------------------------------*/
davide.aliprandi@st.com 0:7d07f4df31e1 67
davide.aliprandi@st.com 0:7d07f4df31e1 68 /**
davide.aliprandi@st.com 0:7d07f4df31e1 69 * @brief Entry point function of mbedOS.
davide.aliprandi@st.com 0:7d07f4df31e1 70 * @param None
davide.aliprandi@st.com 0:7d07f4df31e1 71 * @retval None
davide.aliprandi@st.com 0:7d07f4df31e1 72 */
davide.aliprandi@st.com 0:7d07f4df31e1 73 int main(void)
davide.aliprandi@st.com 0:7d07f4df31e1 74 {
davide.aliprandi@st.com 0:7d07f4df31e1 75 /*----- Initialization. -----*/
davide.aliprandi@st.com 0:7d07f4df31e1 76
davide.aliprandi@st.com 0:7d07f4df31e1 77 /* Initializing MEMS Microphones Expansion Board on the I2S1 interface. */
davide.aliprandi@st.com 0:7d07f4df31e1 78 XNucleoCCA02M1 *microphones = new XNucleoCCA02M1(PB_15, PB_13);
davide.aliprandi@st.com 0:7d07f4df31e1 79 if (microphones->init(&init) != COMPONENT_OK)
davide.aliprandi@st.com 0:7d07f4df31e1 80 {
davide.aliprandi@st.com 0:7d07f4df31e1 81 error("Initialization of the MEMS Microphones Expansion Board failed.\r\n");
davide.aliprandi@st.com 0:7d07f4df31e1 82 exit(EXIT_FAILURE);
davide.aliprandi@st.com 0:7d07f4df31e1 83 }
davide.aliprandi@st.com 0:7d07f4df31e1 84
davide.aliprandi@st.com 0:7d07f4df31e1 85 /* Enabling transmission via USB. */
davide.aliprandi@st.com 0:7d07f4df31e1 86 microphones->enable_usb();
davide.aliprandi@st.com 0:7d07f4df31e1 87
davide.aliprandi@st.com 0:7d07f4df31e1 88 /* Printing to the console. */
davide.aliprandi@st.com 0:7d07f4df31e1 89 printf("MEMS Microphones Application Example\r\n\n");
davide.aliprandi@st.com 0:7d07f4df31e1 90
davide.aliprandi@st.com 0:7d07f4df31e1 91
davide.aliprandi@st.com 0:7d07f4df31e1 92 /*----- Recording. -----*/
davide.aliprandi@st.com 0:7d07f4df31e1 93
davide.aliprandi@st.com 0:7d07f4df31e1 94 /* Printing to the console. */
davide.aliprandi@st.com 0:7d07f4df31e1 95 printf("--> Recording...\r\n");
davide.aliprandi@st.com 0:7d07f4df31e1 96 microphones->record();
Davidroid 17:97dffa2e68f7 97
Davidroid 17:97dffa2e68f7 98 /* Dispatching forever the I2S queue. */
Davidroid 17:97dffa2e68f7 99 I2S::i2s_bh_queue.dispatch_forever();
davide.aliprandi@st.com 0:7d07f4df31e1 100 }
davide.aliprandi@st.com 0:7d07f4df31e1 101
davide.aliprandi@st.com 0:7d07f4df31e1 102 #else // DEVICE_I2S
davide.aliprandi@st.com 0:7d07f4df31e1 103
davide.aliprandi@st.com 0:7d07f4df31e1 104 int main(void)
davide.aliprandi@st.com 0:7d07f4df31e1 105 {
davide.aliprandi@st.com 0:7d07f4df31e1 106 printf("The target does not support I2S API.\r\n");
davide.aliprandi@st.com 0:7d07f4df31e1 107 }
davide.aliprandi@st.com 0:7d07f4df31e1 108
davide.aliprandi@st.com 0:7d07f4df31e1 109 #endif // DEVICE_I2S