background image

 

PSoC 6 MCU: USB Audio Recorder 

www.cypress.com

 

Document Number: 002-25786 Rev. ** 

Figure 3. PDM/PCM to USB Flowchart 

Task While Loop

Wait for

Recording 

Request

Clear 

PDM/PCM 

FIFO

Enable 

PDM/PCM 

Sampling

Write to the 

Audio IN 

Endpoint Buffer

Audio IN Endpoint Callback

Read PDM/PCM 

FIFO Level

Is level too 

high?

Is level too 

low?

Increase 

Frame Size

Decrease 

Frame Size

Set Original

Frame Size

Enable the DMA 

PCM Transfer

DMA PCM Interrupt Handler

Is still 

streaming?

Disable 

PDM/PCM 

Sampling

Write to the 

Audio IN 

Endpoint Buffer

This callback is 

executed after 

transferring data to 

the USB host

This interrupt service routine is 

executed after the DMA PCM transfers 

one frame data from the PDM/PCM 

FIFO to SRAM

Yes

No

Yes

No

No

Yes

 

The audio in ‘task while’ loop waits for a recording request from the USB host. When it receives the request, it prepares the 
PDM/PCM block to sample a new frame. It initially writes a null frame to the Audio IN Endpoint buffer to initiate the streaming. 
The frame size depends on the sample rate (48 ksps), the number of channels (2x) and the time of USB transfers (1 ms). The 
overall equation is: 

𝐹𝑟𝑎𝑚𝑒 𝑠𝑖𝑧𝑒 = 𝑆𝑎𝑚𝑝𝑙𝑒 𝑅𝑎𝑡𝑒 × 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝐶ℎ𝑎𝑛𝑛𝑒𝑙𝑠 × 𝑇𝑟𝑎𝑛𝑠𝑓𝑒𝑟 𝑇𝑖𝑚𝑒 

 

In  this example,  the frame  size  is  equal  to 48000  ×  2  x  0.001  = 96 samples.  Note that  the  Audio  IN  Endpoint  Callback  also 
implements a method to change the frame size depending on the FIFO level in the PDM/PCM block. This is important because 
there are clocking differences between the USB host bus and the PSoC 6 MCU audio subsystem. 

The DMA PCM is configured to transfer an entire audio frame per trigger. It triggers when there is enough data in the PDM/PCM 
FIFO. Once it completes a transfer, it disables itself; it is enabled again only when the Audio IN Endpoint Callback is executed. 
On completion, the DMA PCM Interrupt Handler is executed, which might terminate the recording by disabling the PDM/PCM 
block or keep the streaming by writing more data to the Audio IN Endpoint buffer. 

The firmware uses FreeRTOS to execute the processes required by this application. All tasks run in the Arm® Cortex®-M4 CPU. 
The following tasks are created: 

1. 

AudioInTask: 

described i

Figure 3 

as the Task While Loop 

2. 

AudioAppTask:

 initiates the application and handles certain USB events. In this application, no USB events are handled 

in this task. 

3. 

DebugTask:

 handles messages printed to the terminal over UART (optional). 

The  example  also  uses  the  Event  Group.  It  is  used  to  notify  tasks  when  USB  events  occur.  Only  the  event  that  initiates  a 
recording is used in this application. 

The project consists of the following files: 

 

main.c

  (CM4)  contains  the  main  function,  which  is  the  entry  point  and  execution  of  the  firmware  application.  The  main 

function sets up user tasks and then starts the RTOS scheduler. The CM0+ equivalent contains the main function that starts 
up CM4. CM0+ is not used to run any application code. 

 

audio_app.c/h 

files contain the task that initializes the audio-related blocks, such as the USB and the PDM/PCM blocks, 

and handles USB events in the task main loop. 

 

audio_in.c/h 

files contain the task that handle recording requests to the Audio IN endpoint. These files also implement the 

Audio IN Data Endpoint callback and the DMA interrupt service routine. 

Summary of Contents for CE225786

Page 1: ...e PDM data line One microphone samples in the falling edge and the other in the rising edge This code example uses FreeRTOS Visit the FreeRTOS website for documentation and API references of FreeRTOS...

Page 2: ...red to the USB data endpoint buffer Figure 2 shows the overall transfers performed by the application Figure 2 Overall Transfers PDM PCM RX FIFO SRAM PCM Buffer USB Data Endpoint Buffer DMA Transfers...

Page 3: ...er an entire audio frame per trigger It triggers when there is enough data in the PDM PCM FIFO Once it completes a transfer it disables itself it is enabled again only when the Audio IN Endpoint Callb...

Page 4: ...Table 1 lists the ModusToolbox resources used in this example and how they are used in the design For pin usage and configuration open the Pins tab of the design modus file Table 1 ModusToolbox Resou...

Page 5: ...PSoC 6 MCU USB Audio Recorder www cypress com Document Number 002 25786 Rev 5 Figure 5 USBFS Configuration...

Page 6: ...hows the configuration settings for DMA_PCM Figure 6 DMA_PCM Configuration Figure 8 and Figure 8 show the platform system clock configuration Note that the FLL and PLL are used in this application The...

Page 7: ...ings Figure 9 High Frequency Clocks Configuration KIT_UART uses the default configuration for UART The following middleware libraries are used in this project FreeRTOS v10 0 1 Retarget I O USB Device...

Page 8: ...PSoC 6 MCU devices and how to build your first PSoC project AN215656 PSoC 6 MCU Dual Core CPU System Design Describes the dual CPU architecture in the PSoC 6 MCU and shows how to build a simple dual C...

Page 9: ...com Document Number 002 25786 Rev 9 Document History Document Title CE225786 PSoC 6 MCU USB Audio Recorder Document Number 002 25786 Revision ECN Orig of Change Submission Date Description of Change...

Page 10: ...of the Software is prohibited TO THE EXTENT PERMITTED BY APPLICABLE LAW CYPRESS MAKES NO WARRANTY OF ANY KIND EXPRESS OR IMPLIED WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE OR ACCOMPANYING HARDWARE I...

Reviews: