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

Dependencies:   X_NUCLEO_CCA02M1

Fork of HelloWorld_CCA02M1 by ST Expansion SW Team

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 OS.

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.
  • The application built against mbed classic 2.x 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.

main.cpp

Committer:
Davidroid
Date:
2018-12-12
Revision:
18:175347231903
Parent:
12:203c08553f4d

File content as of revision 18:175347231903:

/**
 ******************************************************************************
 * @file    main.cpp
 * @author  Davide Aliprandi, STMicroelectronics
 * @version V1.0.0
 * @date    October 28th, 2016
 * @brief   mbed test application for the STMicroelectronics X-NUCLEO-CCA02M1
 *          MEMS Microphones Expansion Board.
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 *   3. Neither the name of STMicroelectronics nor the names of its contributors
 *      may be used to endorse or promote products derived from this software
 *      without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ******************************************************************************
 */


/* Includes ------------------------------------------------------------------*/

/* mbed specific header files. */
#include "mbed.h"
#include "rtos.h"


#if DEVICE_I2S

/* Expansion Board specific header files. */
#include "XNucleoCCA02M1.h"


/* Variables -----------------------------------------------------------------*/

/*
 * Initialization parameters.
 * Note: put a jumper to connect PB_5 and PB_13 on the MORPHO connector when
 *       running a mono configuration.
 */
XNucleoCCA02M1_init_t init =
{
	44100,  /* Default Sampling Frequency [Hz]. */
    2       /* Default number of channels. */
};

/* Thread to manage I2S peripherals. */
static rtos::Thread i2s_bh_daemon;


/* Functions -----------------------------------------------------------------*/

/**
 * @brief  Entry point function of mbedOS.
 * @param  None
 * @retval None
 */
int main(void)
{
    /*----- Initialization. -----*/

    /* Initializing MEMS Microphones Expansion Board on the I2S1 interface. */
    XNucleoCCA02M1 *microphones = new XNucleoCCA02M1(PB_15, PB_13);
    if (microphones->init(&init) != COMPONENT_OK)
    {
        error("Initialization of the MEMS Microphones Expansion Board failed.\r\n");
        exit(EXIT_FAILURE);
    }

    /* Starting a thread to manage I2S peripherals. */
    Callback<void()> i2s_bh_task(&I2S::i2s_bh_queue, &events::EventQueue::dispatch_forever);
    i2s_bh_daemon.start(i2s_bh_task);

    /* Enabling transmission via USB. */
    microphones->enable_usb();

    /* Printing to the console. */
    printf("MEMS Microphones Application Example\r\n\n");


    /*----- Recording. -----*/

    /* Printing to the console. */
    printf("--> Recording...\r\n");
    microphones->record();
}

#else // DEVICE_I2S

int main(void)
{
    printf("The target does not support I2S API.\r\n");
}

#endif // DEVICE_I2S