Simple test application for the STMicroelectronics X-NUCLEO-CCA01M1 Sound Terminal Expansion Board, built against mbed classic.

Dependencies:   X_NUCLEO_CCA01M1 ST_Events-old mbed

Fork of HelloWorld_CCA01M1_mbedOS by ST

Playing audio with the X-NUCLEO-CCA01M1 Expansion Board

This application provides a simple example of usage of the X-NUCLEO-CCA01M1 Sound Terminal Expansion Board, built against mbed classic.

It shows how to play a 2-channel stereo signal stored in an array of PCM samples directly on the speakers connected to the expansion board.

It also allows to stop/play the audio by pressing the user button on the Nucleo board.


Platform compatibility

  • This board can be currently used with a Nucleo-F401RE board only and has been tested with the default configuration provided by this example.
  • Please note that the main application makes use of the "events" library, which is not included into the "mbed" library.
  • The application built against mbed OS 5.x can be found here.
Committer:
Davidroid
Date:
Mon May 15 15:51:10 2017 +0000
Revision:
9:34ebb3f5a2ad
Parent:
7:94e3191477c5
Simple test application for the STMicroelectronics X-NUCLEO-CCA01M1 MEMS Microphones Expansion Board, built against mbed classic.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nikapov 0:8d09369ca839 1 /**
nikapov 0:8d09369ca839 2 ******************************************************************************
nikapov 0:8d09369ca839 3 * @file main.cpp
nikapov 0:8d09369ca839 4 * @author Davide Aliprandi, STMicroelectronics
nikapov 0:8d09369ca839 5 * @version V1.0.0
nikapov 0:8d09369ca839 6 * @date March 25th, 2016
nikapov 0:8d09369ca839 7 * @brief mbed test application for the STMicroelectronics X-NUCLEO-CCA01M1
nikapov 0:8d09369ca839 8 * Sound Terminal Expansion Board.
nikapov 0:8d09369ca839 9 ******************************************************************************
nikapov 0:8d09369ca839 10 * @attention
nikapov 0:8d09369ca839 11 *
nikapov 0:8d09369ca839 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nikapov 0:8d09369ca839 13 *
nikapov 0:8d09369ca839 14 * Redistribution and use in source and binary forms, with or without modification,
nikapov 0:8d09369ca839 15 * are permitted provided that the following conditions are met:
nikapov 0:8d09369ca839 16 * 1. Redistributions of source code must retain the above copyright notice,
nikapov 0:8d09369ca839 17 * this list of conditions and the following disclaimer.
nikapov 0:8d09369ca839 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nikapov 0:8d09369ca839 19 * this list of conditions and the following disclaimer in the documentation
nikapov 0:8d09369ca839 20 * and/or other materials provided with the distribution.
nikapov 0:8d09369ca839 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nikapov 0:8d09369ca839 22 * may be used to endorse or promote products derived from this software
nikapov 0:8d09369ca839 23 * without specific prior written permission.
nikapov 0:8d09369ca839 24 *
nikapov 0:8d09369ca839 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nikapov 0:8d09369ca839 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nikapov 0:8d09369ca839 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nikapov 0:8d09369ca839 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nikapov 0:8d09369ca839 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nikapov 0:8d09369ca839 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nikapov 0:8d09369ca839 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nikapov 0:8d09369ca839 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nikapov 0:8d09369ca839 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nikapov 0:8d09369ca839 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nikapov 0:8d09369ca839 35 *
nikapov 0:8d09369ca839 36 ******************************************************************************
nikapov 0:8d09369ca839 37 */
nikapov 0:8d09369ca839 38
nikapov 0:8d09369ca839 39
nikapov 0:8d09369ca839 40 /* Includes ------------------------------------------------------------------*/
nikapov 0:8d09369ca839 41
nikapov 0:8d09369ca839 42 /* mbed specific header files. */
nikapov 0:8d09369ca839 43 #include "mbed.h"
nikapov 0:8d09369ca839 44
nikapov 0:8d09369ca839 45
nikapov 0:8d09369ca839 46 #if DEVICE_I2S
nikapov 0:8d09369ca839 47
nikapov 0:8d09369ca839 48 /* Helper header files. */
nikapov 0:8d09369ca839 49 #include "DevI2C.h"
nikapov 0:8d09369ca839 50
nikapov 0:8d09369ca839 51 /* Component specific header files. */
davide.aliprandi@st.com 5:ac729170df5f 52 #include "STA350BW.h"
nikapov 0:8d09369ca839 53
nikapov 0:8d09369ca839 54 /* My song header file. */
nikapov 0:8d09369ca839 55 #include "my_song.h"
nikapov 0:8d09369ca839 56
nikapov 0:8d09369ca839 57
nikapov 0:8d09369ca839 58 /* Definitions ---------------------------------------------------------------*/
nikapov 0:8d09369ca839 59
nikapov 0:8d09369ca839 60 /* Events. */
nikapov 0:8d09369ca839 61 #define PLAY_STOP_EVENT (0x1)
nikapov 0:8d09369ca839 62
nikapov 0:8d09369ca839 63
nikapov 0:8d09369ca839 64 /* Variables -----------------------------------------------------------------*/
nikapov 0:8d09369ca839 65
nikapov 0:8d09369ca839 66 /* Initialization parameters. */
Davidroid 7:94e3191477c5 67 STA350BW_init_t init =
nikapov 0:8d09369ca839 68 {
nikapov 0:8d09369ca839 69 32000, /* Default Sampling Frequency [Hz]. */
nikapov 0:8d09369ca839 70 100 /* Default Volume. */
nikapov 0:8d09369ca839 71 };
nikapov 0:8d09369ca839 72
nikapov 0:8d09369ca839 73 /* Sound Terminal Component. */
nikapov 0:8d09369ca839 74 STA350BW *sound_terminal;
nikapov 0:8d09369ca839 75
nikapov 0:8d09369ca839 76
nikapov 0:8d09369ca839 77 /* Functions -----------------------------------------------------------------*/
nikapov 0:8d09369ca839 78
nikapov 0:8d09369ca839 79 /**
nikapov 0:8d09369ca839 80 * @brief Entry point function of mbedOS.
nikapov 0:8d09369ca839 81 * @param None
nikapov 0:8d09369ca839 82 * @retval None
nikapov 0:8d09369ca839 83 */
nikapov 0:8d09369ca839 84 int main(void)
nikapov 0:8d09369ca839 85 {
nikapov 0:8d09369ca839 86 /*----- Initialization. -----*/
nikapov 0:8d09369ca839 87
nikapov 0:8d09369ca839 88 /* Initializing I2C bus. */
Davidroid 4:6bb9e11d322b 89 DevI2C *dev_i2c = new DevI2C(PB_9, PB_8);
nikapov 0:8d09369ca839 90
nikapov 0:8d09369ca839 91 /* Initializing Sound Terminal Component. */
nikapov 0:8d09369ca839 92 #ifndef USE_I2S2
nikapov 0:8d09369ca839 93 sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_1, *dev_i2c, PB_15, PB_13, PB_12, NC, PC_6);
nikapov 0:8d09369ca839 94 #else
nikapov 0:8d09369ca839 95 sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_2, *dev_i2c, PC_12, PC_10, PA_4, NC, PC_7);
nikapov 0:8d09369ca839 96 #endif
davide.aliprandi@st.com 5:ac729170df5f 97 if (sound_terminal->init(&init) != COMPONENT_OK)
nikapov 0:8d09369ca839 98 {
nikapov 0:8d09369ca839 99 error("Initialization of the Sound Terminal Expansion Board failed.\r\n");
nikapov 0:8d09369ca839 100 exit(EXIT_FAILURE);
nikapov 0:8d09369ca839 101 }
nikapov 0:8d09369ca839 102
nikapov 0:8d09369ca839 103 /* Setting Sound Terminal Component's parameters. */
davide.aliprandi@st.com 5:ac729170df5f 104 sound_terminal->set_frequency(MY_SONG_AUDIO_FREQUENCY);
davide.aliprandi@st.com 5:ac729170df5f 105 sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, 60);
nikapov 0:8d09369ca839 106
nikapov 0:8d09369ca839 107 /* Printing to the console. */
nikapov 0:8d09369ca839 108 printf("Sound Terminal Application Example\r\n\n");
nikapov 0:8d09369ca839 109
nikapov 0:8d09369ca839 110
nikapov 0:8d09369ca839 111 /*----- Playing. -----*/
nikapov 0:8d09369ca839 112
nikapov 0:8d09369ca839 113 /* Printing to the console. */
nikapov 0:8d09369ca839 114 printf("--> Playing...\r\n");
davide.aliprandi@st.com 5:ac729170df5f 115 sound_terminal->play((int16_t *) my_song, (uint16_t) sizeof(my_song), true);
Davidroid 9:34ebb3f5a2ad 116
Davidroid 9:34ebb3f5a2ad 117 /* Dispatching forever the I2S queue. */
Davidroid 9:34ebb3f5a2ad 118 I2S::i2s_bh_queue.dispatch_forever();
nikapov 0:8d09369ca839 119 }
nikapov 0:8d09369ca839 120
nikapov 0:8d09369ca839 121 #else // DEVICE_I2S
nikapov 0:8d09369ca839 122
nikapov 0:8d09369ca839 123 int main(void)
nikapov 0:8d09369ca839 124 {
nikapov 0:8d09369ca839 125 printf("The target does not support I2S API.\r\n");
nikapov 0:8d09369ca839 126 }
nikapov 0:8d09369ca839 127
nikapov 0:8d09369ca839 128 #endif // DEVICE_I2S