HPM APP
HPMicro Application solution
I2S_DMA_CHAIN solutions

Depend on SDK1.10.0

Introduction

  • The HPM6700/6400 series MCU comes with audio functionality. Supports four I2S functions, one DAO broadcasting function, one PDM digital microphone, and VAD function. I2S supports time-division multiplexing and can support up to TDM16. The I2S module supports four modes: Philips standard, MSB alignment mode, LSB alignment mode, and DSP mode.
  • This plan takes the HPM6750EVK2 development board as an example to introduce the DMA chain data transmission and reception function of I2S. The received data is collected by the microphone and the signal is passed through the codec to the MCU; The data sent by I2S can be played through DAO and the sound can be played through an external speaker.

-This scheme uses DMA chain transfer to automatically complete I2S receiving data to rx_fuff and I2S sending sine wave signals to DAO, without the need for CPU involvement. The CPU is only responsible for processing data.

Application NotesHPM I2S_DMA_CHAIN开发案例_V1.1

general_solution

i2s_dma_chain_main

Sample

DMA configuration used for receive and transmit data in I2S:

#define APP_DMA_RX BOARD_APP_HDMA
#define I2S_MASTER_RX_LINE CODEC_I2S_DATA_LINE
#define DMA_RX_CHANNEL (0U)
#define DMA_MUX_RX_CHANNEL DMA_SOC_CHN_TO_DMAMUX_CHN(APP_DMA_RX, DMA_RX_CHANNEL)
#define DMA_MUX_RX_SRC HPM_DMA_SRC_I2S0_RX
#define APP_DMA_TX BOARD_APP_HDMA
#define DMA_CHANNEL (1U)
#define DMA_MUX_CHANNEL DMA_SOC_CHN_TO_DMAMUX_CHN(APP_DMA_TX, DMA_CHANNEL)
#define DMA_MUX_SRC HPM_DMA_SRC_I2S1_TX
#define TX_DATA_LEN (32U)

Format configuration for I2S data transmission:

#define I2S_SAMPLE_RATE_HZ (16000U)
#define I2S_SAMPLE_CHANNEL (2U)
#define I2S_SAMPLE_BITDEPTH i2s_audio_depth_32_bits
#define I2S_CHANNEL_LENGTH i2s_channel_length_32_bits

Process the data received by I2S:

void rx_data_process(void)
{
if (rx_done[0] == 1)
{
/* you can process the rx data here */
rx_done[0] = 0;
for (int i = 0;i < FFT_POINTS;i++)
{
/* left channel data */
rfft_buf_l[i] = rx_buff[2 * i];
/* right channel data */
rfft_buf_r[i] = rx_buff[2 * i + 1];
}
/*FFT calculation result printing interval, print the result every 20 calculations, for testing purposes only.*/
{
printf("fft result:%d,%d,%d,%d\n",result[0],result[1],result[2],result[3]);
}
}
if (rx_done[1] == 1)
{
/* you can process the rx data here */
rx_done[1] = 0;
}
if (rx_done[0] == 1 && rx_done[0] == 1)
{
printf("rx_buff full!");
}
}
rfft_type_t rfft_buf_l[FFT_POINTS]
Definition: i2s_dma_chain.c:49
rfft_type_t rfft_buf_r[FFT_POINTS]
Definition: i2s_dma_chain.c:48
u32_t complete_count
Definition: i2s_dma_chain.c:46
uint32_t result[4]
Definition: i2s_dma_chain.c:42
rfft_type_t rfft_mag_output[FFT_POINTS]
Definition: i2s_dma_chain.c:50
void fft_cal(rfft_type_t *buf, rfft_type_t *output, uint16_t points, uint16_t shift)
FFT calculation:perform FFT calculation on the received audio data ;FFT计算:对接收到音频数据进行FFT运算
Definition: i2s_dma_chain.c:220
void rx_data_process(void)
processing received data ;处理接收的数据
Definition: i2s_dma_chain.c:352
#define FFT_SHIFT
shift base 2 logarithm value of the sample number and it can be set from 4 to 14 ;以2为底的数据个数的对数值,可以设置为...
Definition: i2s_dma_chain.h:74
#define TEST_DELAY_COUNT
FFT calculation result printing interval, print the result every 20 calculations, for testing purpose...
Definition: i2s_dma_chain.h:99
#define FFT_RESULT_INDEX
FFT calculation result index, index position corresponding to 1kHz ;FFT计算结果索引,1kHz对应的索引位置
Definition: i2s_dma_chain.h:94
#define FFT_POINTS
The number of FFT operation points, must be a power of 2 and within the range of 2^4 to 2^14 ;FFT运算的点...
Definition: i2s_dma_chain.h:79
#define FFT_RESULT_SHIFT
The FFT operation result shifted,the FFT calculation results in larger values,reduced the result in s...
Definition: i2s_dma_chain.h:84

DEMO:

int main(void)
{
board_init();
printf("i2s dma chain rx and tx example!\n");
while(1){
};
return 0;
}
int main(void)
Definition: audio_codec.c:9
void i2s_dma_tx_init(void)
I2S TX and DMA chain init ;发送数据的I2S和DMA链初始化
Definition: i2s_dma_chain.c:198
void i2s_dma_rx_init(void)
I2S RX and DMA chain init ;接收数据的I2S和DMA链初始化
Definition: i2s_dma_chain.c:344

Code Path

  • Code Path:i2s_dma_chain\software\i2s_dma

Code Configuration

  • none

Code Build

  • windows GUI create project

window gui create project

Hardware

  • The hpm6750evk2 development board used in this plan.
  • This routine requires connecting the DAO of the development board to the speakers.

Code Run

  • Run Engineering.
  • Without connecting the speaker, use the serial assistant to observe the FFT calculation results.

result fft no speaker

  • FFT calculation result after connecting the speaker on DAO.

result fft connect speaker

Licensing

HPM APP is permissively licensed using the BSD 3-clause license