![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Version using MEMS microphone and CODEC for the program "F746_RealtimeSpectrumAnalyzer". "F746_RealtimeSpectrumAnalyzer" の入力を MEMS のマイクと CODEC に変更.このプログラムは Tomona Nanase さんが作成し DISCO-F746NG_Oscilloscope の名前で登録しているプログラムで, CODEC を使って入力する部分を参考にして作成.このプログラムの説明は,CQ出版社のインターフェース誌,2016年4月号に掲載.
Dependencies: BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed
Diff: byNanase/BSP_overwrite.cpp
- Revision:
- 0:0e5131366580
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/byNanase/BSP_overwrite.cpp Wed Jan 06 12:46:15 2016 +0000 @@ -0,0 +1,95 @@ +#include "main.h" + +DMA_HandleTypeDef hdma_sai_rx; + +/* ----- AUDIO IN ----- */ + +void BSP_AUDIO_IN_HalfTransfer_CallBack(void) +{ + audio_in_buffer_offset = 0; + audio_in_buffer_length = BufferSize / 2; + audio_in_buffer_captured = true; +} + +void BSP_AUDIO_IN_TransferComplete_CallBack(void) +{ + audio_in_buffer_offset = BufferSize / 2; + audio_in_buffer_length = BufferSize / 2; + audio_in_buffer_captured = true; +} + +void BSP_AUDIO_IN_Error_CallBack(void) +{ + error_trap(); +} + +void AUDIO_IN_SAIx_DMAx_IRQHandler(void) +{ + HAL_DMA_IRQHandler(&hdma_sai_rx); +} + +void BSP_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params) +{ + //static DMA_HandleTypeDef hdma_sai_rx; + GPIO_InitTypeDef gpio_init_structure; + + /* Enable SAI clock */ + AUDIO_IN_SAIx_CLK_ENABLE(); + + /* Enable SD GPIO clock */ + AUDIO_IN_SAIx_SD_ENABLE(); + /* CODEC_SAI pin configuration: SD pin */ + gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN; + gpio_init_structure.Mode = GPIO_MODE_AF_PP; + gpio_init_structure.Pull = GPIO_NOPULL; + gpio_init_structure.Speed = GPIO_SPEED_FAST; + gpio_init_structure.Alternate = AUDIO_IN_SAIx_SD_AF; + HAL_GPIO_Init(AUDIO_IN_SAIx_SD_GPIO_PORT, &gpio_init_structure); + + /* Enable Audio INT GPIO clock */ + AUDIO_IN_INT_GPIO_ENABLE(); + /* Audio INT pin configuration: input */ + gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN; + gpio_init_structure.Mode = GPIO_MODE_INPUT; + gpio_init_structure.Pull = GPIO_NOPULL; + gpio_init_structure.Speed = GPIO_SPEED_FAST; + HAL_GPIO_Init(AUDIO_IN_INT_GPIO_PORT, &gpio_init_structure); + + /* Enable the DMA clock */ + AUDIO_IN_SAIx_DMAx_CLK_ENABLE(); + + if(hsai->Instance == AUDIO_IN_SAIx) { + /* Configure the hdma_sai_rx handle parameters */ + hdma_sai_rx.Init.Channel = AUDIO_IN_SAIx_DMAx_CHANNEL; + hdma_sai_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_sai_rx.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_sai_rx.Init.MemInc = DMA_MINC_ENABLE; + hdma_sai_rx.Init.PeriphDataAlignment = AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE; + hdma_sai_rx.Init.MemDataAlignment = AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE; + hdma_sai_rx.Init.Mode = DMA_CIRCULAR; + hdma_sai_rx.Init.Priority = DMA_PRIORITY_HIGH; + hdma_sai_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + hdma_sai_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; + hdma_sai_rx.Init.MemBurst = DMA_MBURST_SINGLE; + hdma_sai_rx.Init.PeriphBurst = DMA_MBURST_SINGLE; + + hdma_sai_rx.Instance = AUDIO_IN_SAIx_DMAx_STREAM; + + /* Associate the DMA handle */ + __HAL_LINKDMA(hsai, hdmarx, hdma_sai_rx); + + /* Deinitialize the Stream for new transfer */ + HAL_DMA_DeInit(&hdma_sai_rx); + + /* Configure the DMA Stream */ + HAL_DMA_Init(&hdma_sai_rx); + } + + /* SAI DMA IRQ Channel configuration */ + HAL_NVIC_SetPriority(AUDIO_IN_SAIx_DMAx_IRQ, AUDIO_IN_IRQ_PREPRIO, 0); + HAL_NVIC_EnableIRQ(AUDIO_IN_SAIx_DMAx_IRQ); + + /* Audio INT IRQ Channel configuration */ + HAL_NVIC_SetPriority(AUDIO_IN_INT_IRQ, AUDIO_IN_IRQ_PREPRIO, 0); + HAL_NVIC_EnableIRQ(AUDIO_IN_INT_IRQ); +}