MPLAB Harmony Bluetooth Help
|
In this demonstration application, a BM64 Module Daughter Board is used to stream A2DP audio from a Bluetooth host, such as a smartphone, to a pair of headphones connected to a codec daughter board attached to the same development board.
The demonstration can also automatically answer a voice call coming in via Hands-Free Protocol (HFP), interrupting (and pausing) any A2DP streaming in progress. Local audio is input using a microphone connected to the MIC IN input of the BM64 Module Daughter Board. When the call is terminated, streaming resumes.
There are two different projects packaged in this application.
PIC32_MX Bluetooth Audio Development Kit Project:
One project runs on the Bluetooth Audio Development Kit (BTADK). It uses the microcontroller installed on the board, namely the PIC32MX470F512L with 512 KB of Flash memory and 128 KB of RAM running at 96 MHz. The BTADK includes the following features:
The BTADK also includes an LCD display and USB interfaces, none of which are used in this project.
Note: |
The PIC32 Bluetooth Audio Development Kit does not include the BM64 Bluetooth Module Daughter Board or the AK4954 Codec Daughter Board. They must be purchased separately from microchipDIRECT, part number AC320032-3 and AC324954, respectively. |
The program takes up to approximately 13% (67 KB) of the microcontroller’s program space, and 3% (3 KB) of the RAM. No heap is used.
The following figure illustrates the application architecture:
PIC32 MZ EF Curiosity 2.0 Project:
One project runs on the PIC32 MZ EF Curiosity 2.0 board, using the PIC32MZ2048EFM144 microcontroller with 2 MB of Flash memory and 512 KB of RAM running at 198 MHz. The PIC32 MZ EF Curiosity 2.0 board includes the following features:
The PIC32 MZ EF Curiosity 2.0 board also includes an LCD display and USB interfaces, none of which are used in this project.
Note: |
The PIC32 MZ EF Curiosity 2.0 board does not include the BM64 Bluetooth Module Daughter Board or the AK4954 Codec Daughter Board. They must be purchased separately from microchipDIRECT, part number AC320032-3 and AC324954, respectively. |
The program takes up to approximately 1% (16 KB) of the PIC32MZ2048EFM144 microcontroller’s program space, and 1% (2.5 KB) of the RAM. No heap is used.
The following figure illustrates the application architecture:
The PIC32 microcontroller (MCU) runs the application code, and communicates with the BM64 over a USART interface operating at 115,200 baud. The BM64 module contains its own Bluetooth stack, so it is unnecessary to include a software Bluetooth stack in the PIC32 MCU. The buttons and LEDs are interfaced using GPIO pins. Both the BM64 and the AK4954 codec are configured in I2S ((Inter-IC Sound) slave mode and the I2S peripheral in the PIC32 as an I2S master, generating the I2S clocks. The AK4954 codec is controlled from the PIC32 using an I2C interface.
As with any MPLAB Harmony application, the SYS_Initialize function, which is located in the system_init.c source file, makes calls to initialize various subsystems, such as the clock, ports, board support package (BSP), BM64, codec, timers, and interrupts.
The BM64 and codec drivers, graphics, timers, and the application state machines are all updated through calls located in the SYS_Tasks function in system_tasks.c file. Interrupt handlers in the system_interrupt.c file are used for the four DMA channels (only channels 0 and 2 are used), the UART, and the two timers.
The application code is contained in two source files, app.c and audio.c. The former contains the application state machine (APP_Tasks). It first initializes the application, sets up a periodic timing callback, and then waits for the BM64 driver’s internal state machine to complete initialization (indicated by the function DRV_BT_GetPowerStatus returning RV_BT_STATUS_READY ). At that point the application calls a function called audioStart which initiates audio processing.
Meanwhile, the audio state machine in audio.c has received a handle to the BM64 driver by calling DRV_BT_Open, and then setting callbacks for two event handlers (AUDIO_BT_RxBufferEventHandler for buffer event handling, and _audioEventHandler for general event handling). After that it gets a handle to the codec driver by calling its DRV_CODEC_Open function with a mode of DRV_IO_INTENT_WRITE. Then it registers an event handler, AUDIO_CODEC_TxBufferEventHandler as a callback with the codec driver. Then, it waits for the application to call audioStart before it makes its first call to DRV_BT_BufferAddRead to request audio samples from the BM64.
The event handler callback is given control whenever a buffer has been processed. By default two sets of buffers are used (AUDIO_QUEUE_SIZE = 2), each with 1250 32-bit samples; however, simply by changing the queue size a circular buffer scheme can be used instead. As each buffer is handed off to be sent to the codec, the other one becomes available to be filled by the BM64.
The BM64 and codec drivers interface with their respective I2S interfaces via DMA, but this is largely transparent to the application, as it is all taken care of by MPLAB Harmony.
For the projects using the PIC32MX:
When building a new application, start by creating a 32-bit MPLAB Harmony 3 project in MPLAB X IDE by selecting File > New Project. Chose the Configuration name the based on the BSP. Select the appropriate processor (PIC32MX470F512L).
In MHC, under Available Components select the BSP PIC32MX Bluetooth Audio Development Kit. Under Audio->Templates, double-click on AK4954 Codec. Answer Yes to all questions, except the one about FreeRTOS. In the I2S Driver block, click on the + button to the right of Instances, to create a second instance of the driver. Under Bluetooth->Templates, double-click on BM64 I2S Bluetooth. Answer Yes to all questions, except the one about FreeRTOS.
You should end up with a project graph that looks like this, after rearranging the boxes:
Click on Tools->Clock Diagram and change the settings as shown:
Click on the I2S1 in the Project Graph, and change the settings as shown in green below:
Then do the same for the I2S2 block.
Click on the AK4954 block in the Project Graph, and change the settings as shown in green below:
Click on the BM64 Driver block in the Project Graph, and change the settings as shown in green below:
For projects using the PIC32MZ:
When building a new application, start by creating a 32-bit MPLAB Harmony 3 project in MPLAB X IDE by selecting File > New Project. Chose the Configuration name the based on the BSP. Select the appropriate processor (PIC32MZ2048EFM144).
In MHC, under Available Components select the BSP PIC32MZ EF Curiosity 2.0. Under Audio->Templates, double-click on AK4954 Codec. Answer Yes to all questions, except the one about FreeRTOS. In the I2S Driver block, click on the + button to the right of Instances, to create a second instance of the driver. Under Bluetooth->Templates, double-click on BM64 I2S Bluetooth. Answer Yes to all questions, except the one about FreeRTOS.
You should end up with a project graph that looks like this, after rearranging the boxes:
Click on Tools->Clock Diagram and change the settings as shown:
Click on the I2C_BB block in the Project Graph, and fill in the pin numbers and clock speed as shown below:
Click on the I2S1 in the Project Graph, and change the settings as shown in green below:
Then do the same for the I2S2 block.
Click on the AK4954 block in the Project Graph, and change the settings as shown in green below:
Click on the BM64 Driver block in the Project Graph, and change the settings as shown in green below:
Name |
Description |
This section identifies the MPLAB X IDE project name and location and lists and describes the available configurations for the Bluetooth Demonstration. | |
This section describes how to configure the supported hardware. | |
This section describes how to run the demonstration. |
MPLAB Harmony Bluetooth Help
|