![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CQエレクトロニクス・セミナ「実習・マイコンを動かしながら学ぶディジタル・フィルタ」で使うプログラムを,入力として STM32F746 の内蔵 ADC を使うように変更したもの. http://seminar.cqpub.co.jp/ccm/ES18-0020
Dependencies: mbed Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
F746_SAI_IO_New/BSP_AudioIn_Overwrite.cpp@1:501a83a5ee9d, 2017-11-08 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Nov 08 11:43:52 2017 +0000
- Revision:
- 1:501a83a5ee9d
- Parent:
- 0:ab7a35d87173
2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:ab7a35d87173 | 1 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:ab7a35d87173 | 2 | // Overwrite functuions and define calback function |
MikamiUitOpen | 0:ab7a35d87173 | 3 | // for functions in stm32746g_discovery_audio.cpp |
MikamiUitOpen | 0:ab7a35d87173 | 4 | // |
MikamiUitOpen | 0:ab7a35d87173 | 5 | // Original version: BSP_overwrite.cpp by Nanase |
MikamiUitOpen | 0:ab7a35d87173 | 6 | // https://developer.mbed.org/users/nanase/code/DISCO-F746NG_Oscilloscope/ |
MikamiUitOpen | 0:ab7a35d87173 | 7 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:ab7a35d87173 | 8 | |
MikamiUitOpen | 0:ab7a35d87173 | 9 | #include "BSP_AudioIn_Overwrite.hpp" |
MikamiUitOpen | 0:ab7a35d87173 | 10 | |
MikamiUitOpen | 0:ab7a35d87173 | 11 | // These three callback functions are modyfied by Mikami |
MikamiUitOpen | 0:ab7a35d87173 | 12 | void BSP_AUDIO_IN_HalfTransfer_CallBack() |
MikamiUitOpen | 0:ab7a35d87173 | 13 | { |
MikamiUitOpen | 0:ab7a35d87173 | 14 | Mikami::SaiIO::Captured1st(); |
MikamiUitOpen | 0:ab7a35d87173 | 15 | } |
MikamiUitOpen | 0:ab7a35d87173 | 16 | |
MikamiUitOpen | 0:ab7a35d87173 | 17 | void BSP_AUDIO_IN_TransferComplete_CallBack() |
MikamiUitOpen | 0:ab7a35d87173 | 18 | { |
MikamiUitOpen | 0:ab7a35d87173 | 19 | Mikami::SaiIO::Captured2nd(); |
MikamiUitOpen | 0:ab7a35d87173 | 20 | } |
MikamiUitOpen | 0:ab7a35d87173 | 21 | |
MikamiUitOpen | 0:ab7a35d87173 | 22 | void BSP_AUDIO_IN_Error_CallBack() |
MikamiUitOpen | 0:ab7a35d87173 | 23 | { |
MikamiUitOpen | 0:ab7a35d87173 | 24 | Mikami::SaiIO::ErrorTrap(); |
MikamiUitOpen | 0:ab7a35d87173 | 25 | } |
MikamiUitOpen | 0:ab7a35d87173 | 26 | |
MikamiUitOpen | 0:ab7a35d87173 | 27 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:ab7a35d87173 | 28 | // Followings are original by Nanase |
MikamiUitOpen | 0:ab7a35d87173 | 29 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:ab7a35d87173 | 30 | |
MikamiUitOpen | 0:ab7a35d87173 | 31 | DMA_HandleTypeDef hdma_sai_rx; |
MikamiUitOpen | 0:ab7a35d87173 | 32 | |
MikamiUitOpen | 0:ab7a35d87173 | 33 | void AUDIO_IN_SAIx_DMAx_IRQHandler() |
MikamiUitOpen | 0:ab7a35d87173 | 34 | { |
MikamiUitOpen | 0:ab7a35d87173 | 35 | HAL_DMA_IRQHandler(&hdma_sai_rx); |
MikamiUitOpen | 0:ab7a35d87173 | 36 | } |
MikamiUitOpen | 0:ab7a35d87173 | 37 | |
MikamiUitOpen | 0:ab7a35d87173 | 38 | void BSP_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params) |
MikamiUitOpen | 0:ab7a35d87173 | 39 | { |
MikamiUitOpen | 0:ab7a35d87173 | 40 | GPIO_InitTypeDef gpio_init_structure; |
MikamiUitOpen | 0:ab7a35d87173 | 41 | |
MikamiUitOpen | 0:ab7a35d87173 | 42 | /* Enable SAI clock */ |
MikamiUitOpen | 0:ab7a35d87173 | 43 | AUDIO_IN_SAIx_CLK_ENABLE(); |
MikamiUitOpen | 0:ab7a35d87173 | 44 | |
MikamiUitOpen | 0:ab7a35d87173 | 45 | /* Enable SD GPIO clock */ |
MikamiUitOpen | 0:ab7a35d87173 | 46 | AUDIO_IN_SAIx_SD_ENABLE(); |
MikamiUitOpen | 0:ab7a35d87173 | 47 | /* CODEC_SAI pin configuration: SD pin */ |
MikamiUitOpen | 0:ab7a35d87173 | 48 | gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN; |
MikamiUitOpen | 0:ab7a35d87173 | 49 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
MikamiUitOpen | 0:ab7a35d87173 | 50 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:ab7a35d87173 | 51 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
MikamiUitOpen | 0:ab7a35d87173 | 52 | gpio_init_structure.Alternate = AUDIO_IN_SAIx_SD_AF; |
MikamiUitOpen | 0:ab7a35d87173 | 53 | HAL_GPIO_Init(AUDIO_IN_SAIx_SD_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:ab7a35d87173 | 54 | |
MikamiUitOpen | 0:ab7a35d87173 | 55 | /* Enable Audio INT GPIO clock */ |
MikamiUitOpen | 0:ab7a35d87173 | 56 | AUDIO_IN_INT_GPIO_ENABLE(); |
MikamiUitOpen | 0:ab7a35d87173 | 57 | /* Audio INT pin configuration: input */ |
MikamiUitOpen | 0:ab7a35d87173 | 58 | gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN; |
MikamiUitOpen | 0:ab7a35d87173 | 59 | gpio_init_structure.Mode = GPIO_MODE_INPUT; |
MikamiUitOpen | 0:ab7a35d87173 | 60 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:ab7a35d87173 | 61 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
MikamiUitOpen | 0:ab7a35d87173 | 62 | HAL_GPIO_Init(AUDIO_IN_INT_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:ab7a35d87173 | 63 | |
MikamiUitOpen | 0:ab7a35d87173 | 64 | /* Enable the DMA clock */ |
MikamiUitOpen | 0:ab7a35d87173 | 65 | AUDIO_IN_SAIx_DMAx_CLK_ENABLE(); |
MikamiUitOpen | 0:ab7a35d87173 | 66 | |
MikamiUitOpen | 0:ab7a35d87173 | 67 | if(hsai->Instance == AUDIO_IN_SAIx) |
MikamiUitOpen | 0:ab7a35d87173 | 68 | { |
MikamiUitOpen | 0:ab7a35d87173 | 69 | /* Configure the hdma_sai_rx handle parameters */ |
MikamiUitOpen | 0:ab7a35d87173 | 70 | hdma_sai_rx.Init.Channel = AUDIO_IN_SAIx_DMAx_CHANNEL; |
MikamiUitOpen | 0:ab7a35d87173 | 71 | hdma_sai_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; |
MikamiUitOpen | 0:ab7a35d87173 | 72 | hdma_sai_rx.Init.PeriphInc = DMA_PINC_DISABLE; |
MikamiUitOpen | 0:ab7a35d87173 | 73 | hdma_sai_rx.Init.MemInc = DMA_MINC_ENABLE; |
MikamiUitOpen | 0:ab7a35d87173 | 74 | hdma_sai_rx.Init.PeriphDataAlignment = AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE; |
MikamiUitOpen | 0:ab7a35d87173 | 75 | hdma_sai_rx.Init.MemDataAlignment = AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE; |
MikamiUitOpen | 0:ab7a35d87173 | 76 | hdma_sai_rx.Init.Mode = DMA_CIRCULAR; |
MikamiUitOpen | 0:ab7a35d87173 | 77 | hdma_sai_rx.Init.Priority = DMA_PRIORITY_HIGH; |
MikamiUitOpen | 0:ab7a35d87173 | 78 | hdma_sai_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; |
MikamiUitOpen | 0:ab7a35d87173 | 79 | hdma_sai_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; |
MikamiUitOpen | 0:ab7a35d87173 | 80 | hdma_sai_rx.Init.MemBurst = DMA_MBURST_SINGLE; |
MikamiUitOpen | 0:ab7a35d87173 | 81 | hdma_sai_rx.Init.PeriphBurst = DMA_MBURST_SINGLE; |
MikamiUitOpen | 0:ab7a35d87173 | 82 | |
MikamiUitOpen | 0:ab7a35d87173 | 83 | hdma_sai_rx.Instance = AUDIO_IN_SAIx_DMAx_STREAM; |
MikamiUitOpen | 0:ab7a35d87173 | 84 | |
MikamiUitOpen | 0:ab7a35d87173 | 85 | /* Associate the DMA handle */ |
MikamiUitOpen | 0:ab7a35d87173 | 86 | __HAL_LINKDMA(hsai, hdmarx, hdma_sai_rx); |
MikamiUitOpen | 0:ab7a35d87173 | 87 | |
MikamiUitOpen | 0:ab7a35d87173 | 88 | /* Deinitialize the Stream for new transfer */ |
MikamiUitOpen | 0:ab7a35d87173 | 89 | HAL_DMA_DeInit(&hdma_sai_rx); |
MikamiUitOpen | 0:ab7a35d87173 | 90 | |
MikamiUitOpen | 0:ab7a35d87173 | 91 | /* Configure the DMA Stream */ |
MikamiUitOpen | 0:ab7a35d87173 | 92 | HAL_DMA_Init(&hdma_sai_rx); |
MikamiUitOpen | 0:ab7a35d87173 | 93 | } |
MikamiUitOpen | 0:ab7a35d87173 | 94 | |
MikamiUitOpen | 0:ab7a35d87173 | 95 | /* SAI DMA IRQ Channel configuration */ |
MikamiUitOpen | 0:ab7a35d87173 | 96 | HAL_NVIC_SetPriority(AUDIO_IN_SAIx_DMAx_IRQ, AUDIO_IN_IRQ_PREPRIO, 0); |
MikamiUitOpen | 0:ab7a35d87173 | 97 | HAL_NVIC_EnableIRQ(AUDIO_IN_SAIx_DMAx_IRQ); |
MikamiUitOpen | 0:ab7a35d87173 | 98 | |
MikamiUitOpen | 0:ab7a35d87173 | 99 | /* Audio INT IRQ Channel configuration */ |
MikamiUitOpen | 0:ab7a35d87173 | 100 | HAL_NVIC_SetPriority(AUDIO_IN_INT_IRQ, AUDIO_IN_IRQ_PREPRIO, 0); |
MikamiUitOpen | 0:ab7a35d87173 | 101 | HAL_NVIC_EnableIRQ(AUDIO_IN_INT_IRQ); |
MikamiUitOpen | 0:ab7a35d87173 | 102 | } |