Advanced
30 min

Incorporate high-quality Bluetooth audio streaming into your projects with BM62 and STM32F091RC

Fully qualified Bluetooth 5.0 stereo audio module

BT Audio 2 Click with Nucleo-64 with STM32F091RC MCU

Published Mar 15, 2024

Click board™

BT Audio 2 Click

Dev. board

Nucleo-64 with STM32F091RC MCU

Compiler

NECTO Studio

MCU

STM32F091RC

Create the next generation of portable audio devices and voice communication systems

A

A

Hardware Overview

How does it work?

BT Audio 2 Click is based on BM62, a Bluetooth stereo audio module from Microchip. It includes advanced audio features, such as multi-band dynamic range control, parametric multi-band equalizer, audio widening, and virtual bass are inbuilt. The audio effect algorithms improve the user’s audio listening experience in terms of better audio quality after audio signal processing. The input and output audios have different stages, and each stage can be programmed to vary the gain response characteristics. A Digital Signal Processor (DSP) performs speech and audio processing. Advanced speech features, such as acoustic echo cancellation and noise reduction, are built. To

reduce nonlinear distortion and to help echo cancellation, an outgoing signal level to the speaker is monitored and adjusted to avoid saturation of speaker output or microphone input. BT Audio 2 Click supports one analog (line-in) signal from the external audio source. The DSP can process the analog (line-in) signal to generate different sound effects (multi-band dynamic range compression and audio widening), which can be configured using the DSP tool. Also, the module has an AFH function to avoid RF interference. It has an algorithm to check the nearby interference and to choose a clear channel for the transceiver Bluetooth signal. The on-chip Power Management

Unit (PMU) has two main features: a lithium-ion and lithium-polymer battery charger and a voltage regulator. A power switch switches the power source between the battery and an adapter. Also, the PMU provides current to drive two LEDs. The LED and button settings can be configured. This Click Board™ uses the UART communication interface and is designed to be operated only with a 3.3V logic level. A proper logic voltage level conversion should be performed before the Click board™ is used with MCUs with different logic levels.

BT Audio 2 Click hardware overview image

Features overview

Development board

Nucleo-64 with STM32F091RC MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32F091RC MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

256

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

32768

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 accessories 1 image

These standard small stereo earphones offer a high-quality listening experience with their top-notch stereo cable and connector. Designed for universal compatibility, they effortlessly connect to all MIKROE mikromedia and multimedia boards, making them an ideal choice for your electronic projects. With a rated power of 100mW, the earphones provide crisp audio across a broad frequency range from 20Hz to 20kHz. They boast a sensitivity of 100 ± 5dB and an impedance of 32Ω ± 15%, ensuring optimal sound quality. The Φ15mm speaker delivers clear and immersive audio. Cost-effective and versatile, these earphones are perfect for testing your prototype devices, offering an affordable and reliable audio solution to complement your projects.

BT Audio 2 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

External Address Bus Negative
PC0
AN
Reset
PC12
RST
System Configuration PIn 1
PB12
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
NC
NC
3.3V
Ground
GND
GND
Multifunction button / Power-On
PC8
PWM
System Configuration PIn 2
PC14
INT
UART TX
PA2
TX
UART RX
PA3
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

BT Audio 2 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-64 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo-64 with STM32F091RC MCU as your development board.

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
LTE IoT 5 Click front image hardware assembly
Prog-cut hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
Nucleo-64 with STM32XXX MCU Access MB 1 Mini B Conn - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for BT Audio 2 Click driver.

Key functions:

  • btaudio2_set_device_name - This function sets the local device name

  • btaudio2_make_call - This function makes a call to the specified phone number

  • btaudio2_volume_up - This function increases the volume of a specified gain mask

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief BT Audio 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of BT Audio 2 click board by reading the commands
 * received from remote device and performing adequate actions accordingly.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and configures the click board.
 *
 * ## Application Task
 * Reads all the received events and parses them.
 *
 * ## Additional Function
 * - static err_t btaudio2_event_handler ( btaudio2_t *ctx ) - This function handles SPP data event 
 * and several BTM state events added in. The other events will just be displayed on the USB UART in hex format.
 *
 * @note
 * We have used the Serial Bluetooth Terminal smartphone application for the test. 
 * A smartphone and the click board must be paired in order to exchange messages
 * with each other. So make sure to pair your device with the click board and
 * connect it to using the Serial Bluetooth Terminal application, then you will be able 
 * to send commands listed below.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "btaudio2.h"

static btaudio2_t btaudio2;
static log_t logger;

// Bluetooth device name
#define DEVICE_NAME                 "BT Audio 2 click"

// SPP Commands list
#define COMMAND_PLAY                "play"          // play music
#define COMMAND_PAUSE               "pause"         // pause music
#define COMMAND_STOP                "stop"          // stop music
#define COMMAND_NEXT                "next"          // next song
#define COMMAND_PREVIOUS            "prev"          // previous song
#define COMMAND_VOLUME_UP           "up"            // volume up
#define COMMAND_VOLUME_DOWN         "down"          // volume down
#define COMMAND_MODE_UP             "mode"          // switch equalizer mode
#define COMMAND_CALL                "call"          // call command followed by the number
#define COMMAND_VOICE               "voice"         // start voice recognition app

/**
 * @brief BT Audio 2 event handler function.
 * @details This function handles SPP data event and several BTM state events added in.
 * The other events will just be displayed on the USB UART in hex format.
 * @param[in] ctx : Click context object.
 * See #btaudio2_t object definition for detailed explanation.
 * @return @li @c  >=0 - Command ACK event response,
 *         @li @c   -1 - Error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t btaudio2_event_handler ( btaudio2_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    btaudio2_cfg_t btaudio2_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    btaudio2_cfg_setup( &btaudio2_cfg );
    BTAUDIO2_MAP_MIKROBUS( btaudio2_cfg, MIKROBUS_1 );
    if ( UART_ERROR == btaudio2_init( &btaudio2, &btaudio2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( BTAUDIO2_OK != btaudio2_default_cfg ( &btaudio2 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    if ( BTAUDIO2_OK != btaudio2_set_device_name ( &btaudio2, DEVICE_NAME ) )
    {
        log_error( &logger, " Set device name." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    if ( BTAUDIO2_OK == btaudio2_read_event ( &btaudio2 ) ) 
    {
        btaudio2_event_handler ( &btaudio2 );
    }
}

int main ( void ) 
{
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

static err_t btaudio2_event_handler ( btaudio2_t *ctx )
{
    err_t error_flag = BTAUDIO2_OK;
    static btaudio2_eq_mode_t eq_mode = BTAUDIO2_EQ_MODE_OFF;
    switch ( ctx->event_packet.opcode )
    {
        case BTAUDIO2_EVT_REPORT_SPP_DATA:
        {
            if ( 0 == ctx->event_packet.param_buf[ 1 ] ) // single packet
            {                
                uint16_t payload_len = ( ( uint16_t ) ctx->event_packet.param_buf[ 4 ] << 8 ) | 
                                                      ctx->event_packet.param_buf[ 5 ];
                if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_PLAY ) )
                {
                    error_flag |= btaudio2_send_mmi_action ( ctx, 0, BTAUDIO2_MMI_PLAY_PAUSE_MUSIC );
                    log_printf( &logger, " > play music\r\n\n" );
                } 
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_PAUSE ) )
                {
                    error_flag |= btaudio2_send_mmi_action ( ctx, 0, BTAUDIO2_MMI_PLAY_PAUSE_MUSIC );
                    log_printf( &logger, " > pause music\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_STOP ) )
                {
                    error_flag |= btaudio2_send_mmi_action ( ctx, 0, BTAUDIO2_MMI_STOP_MUSIC );
                    log_printf( &logger, " > stop music\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_NEXT ) )
                {
                    error_flag |= btaudio2_send_mmi_action ( ctx, 0, BTAUDIO2_MMI_NEXT_SONG );
                    log_printf( &logger, " > next song\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_PREVIOUS ) )
                {
                    error_flag |= btaudio2_send_mmi_action ( ctx, 0, BTAUDIO2_MMI_PREVIOUS_SONG );
                    log_printf( &logger, " > previous song\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_VOLUME_UP ) )
                {
                    error_flag |= btaudio2_volume_up ( &btaudio2, 0, BTAUDIO2_VOLUME_MASK_A2DP );
                    log_printf( &logger, " > volume up\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_VOLUME_DOWN ) )
                {
                    error_flag |= btaudio2_volume_down ( &btaudio2, 0, BTAUDIO2_VOLUME_MASK_A2DP );
                    log_printf( &logger, " > volume down\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_CALL ) )
                {
                    uint8_t phone_number[ 19 ] = { 0 };
                    memcpy ( phone_number, strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_CALL ) + 5, payload_len - 7 );
                    error_flag |= btaudio2_make_call ( &btaudio2, 0x00, phone_number );
                    log_printf( &logger, " > calling number: %s\r\n\n", phone_number );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_VOICE ) )
                {
                    error_flag |= btaudio2_send_mmi_action ( ctx, 0, BTAUDIO2_MMI_VOICE_DIAL );
                    log_printf( &logger, " > start voice recognition\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_MODE_UP ) )
                {
                    if ( BTAUDIO2_EQ_MODE_USER1 == eq_mode )
                    {
                        eq_mode = BTAUDIO2_EQ_MODE_OFF;
                    }
                    else
                    {
                        eq_mode++;
                    }
                    btaudio2_set_eq_mode ( &btaudio2, eq_mode );
                    log_printf( &logger, " > equalizer mode: " );
                    switch ( eq_mode )
                    {
                        case BTAUDIO2_EQ_MODE_OFF:
                        {
                            log_printf( &logger, "off\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_SOFT:
                        {
                            log_printf( &logger, "soft\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_BASS:
                        {
                            log_printf( &logger, "bass\r\n\n" );
                            break;
                        } 
                        case BTAUDIO2_EQ_MODE_TREBLE:
                        {
                            log_printf( &logger, "treble\r\n\n" );
                            break;
                        }  
                        case BTAUDIO2_EQ_MODE_CLASSIC:
                        {
                            log_printf( &logger, "classic\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_ROCK:
                        {
                            log_printf( &logger, "rock\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_JAZZ:
                        {
                            log_printf( &logger, "jazz\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_POP:
                        {
                            log_printf( &logger, "pop\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_DANCE:
                        {
                            log_printf( &logger, "dance\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_RNB:
                        {
                            log_printf( &logger, "rnb\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_USER1:
                        {
                            log_printf( &logger, "user1\r\n\n" );
                            break;
                        }
                        default:
                        {
                            log_printf( &logger, "unknown\r\n\n" );
                            break;
                        }
                    }
                }
                else
                {
                    log_printf( &logger, " Unknown command: ", &ctx->event_packet.param_buf[ 6 ] );
                    for ( uint16_t cnt = 0; cnt < payload_len; cnt++ )
                    {
                        log_printf( &logger, "%c", ctx->event_packet.param_buf[ cnt + 6 ] );
                    }
                    log_printf( &logger, "\r\n\n" );
                }
            }
            break;
        }
        case BTAUDIO2_EVT_BTM_STATE:
        {
            switch ( ctx->event_packet.param_buf[ 0 ] )
            {
                case BTAUDIO2_BTM_STATE_PAIRING_SUCCESSFULL:
                {
                    log_printf( &logger, " < Pairing successfull - linked device ID: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO2_BTM_STATE_SCO_LINK_CONNECTED:
                {
                    log_printf( &logger, " < SCO link connected - linked device ID: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO2_BTM_STATE_SCO_LINK_DISCONNECTED:
                {
                    log_printf( &logger, " < SCO link disconnected - linked device ID: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO2_BTM_STATE_ACL_CONNECTED:
                {
                    log_printf( &logger, " < ACL connected - linked data base: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO2_BTM_STATE_ACL_DISCONNECTED:
                {
                    log_printf( &logger, " < ACL disconnected - " );
                    if ( 0 == ctx->event_packet.param_buf[ 1 ] )
                    {
                        log_printf( &logger, "disconnection\r\n\n" );
                    }
                    else if ( 1 == ctx->event_packet.param_buf[ 1 ] )
                    {
                        log_printf( &logger, "link loss\r\n\n" );
                    }
                    break;
                }
                case BTAUDIO2_BTM_STATE_STANDBY_STATE:
                {
                    log_printf( &logger, " < Standby state\r\n\n" );
                    break;
                }
                case BTAUDIO2_BTM_STATE_UNKNOWN_AUDIO_SOURCE:
                {
                    log_printf( &logger, " < Unknown audio source\r\n\n" );
                    break;
                }
                case BTAUDIO2_BTM_STATE_AUX_IN_AUDIO_SOURCE:
                {
                    log_printf( &logger, " < AUX-IN audio source\r\n\n" );
                    break;
                }
                case BTAUDIO2_BTM_STATE_A2DP_AUDIO_SOURCE:
                {
                    log_printf( &logger, " < A2DP audio source\r\n\n" );
                    break;
                }
                default:
                {
                    log_printf( &logger, " < EVENT BTM STATE: " );
                    for ( uint16_t cnt = 0; cnt < ctx->event_packet.param_len; cnt++ )
                    {
                        log_printf( &logger, "0x%.2X ", ( uint16_t ) ctx->event_packet.param_buf[ cnt ] );
                    }
                    log_printf( &logger, "\r\n\n" );
                    break;
                }
            }
            break;
        }
        default: 
        {
            log_printf( &logger, " < EVENT 0x%.2X: ", ( uint16_t ) ctx->event_packet.opcode );
            for ( uint16_t cnt = 0; cnt < ctx->event_packet.param_len; cnt++ )
            {
                log_printf( &logger, "0x%.2X ", ( uint16_t ) ctx->event_packet.param_buf[ cnt ] );
            }
            log_printf( &logger, "\r\n\n" );
            break;
        }
    }
    return error_flag;
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.