Final version.
Fork of F746_SAI_IO by
BSP_AudioIn_Overwrite.cpp@14:ca9e6663f29f, 2017-08-30 (annotated)
- Committer:
- mladjo1993
- Date:
- Wed Aug 30 07:47:22 2017 +0000
- Revision:
- 14:ca9e6663f29f
- Parent:
- 13:2757dd069581
Final version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:eade5d3ae0eb | 1 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:eade5d3ae0eb | 2 | // Overwrite functuions and define calback function |
MikamiUitOpen | 0:eade5d3ae0eb | 3 | // for functions in stm32746g_discovery_audio.cpp |
MikamiUitOpen | 0:eade5d3ae0eb | 4 | // |
MikamiUitOpen | 0:eade5d3ae0eb | 5 | // Original version: BSP_overwrite.cpp by Nanase |
MikamiUitOpen | 0:eade5d3ae0eb | 6 | // https://developer.mbed.org/users/nanase/code/DISCO-F746NG_Oscilloscope/ |
MikamiUitOpen | 0:eade5d3ae0eb | 7 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:eade5d3ae0eb | 8 | |
MikamiUitOpen | 0:eade5d3ae0eb | 9 | #include "BSP_AudioIn_Overwrite.hpp" |
MikamiUitOpen | 0:eade5d3ae0eb | 10 | |
MikamiUitOpen | 0:eade5d3ae0eb | 11 | // These three callback functions are modyfied by Mikami |
MikamiUitOpen | 0:eade5d3ae0eb | 12 | void BSP_AUDIO_IN_HalfTransfer_CallBack() |
MikamiUitOpen | 0:eade5d3ae0eb | 13 | { |
mladjo1993 | 13:2757dd069581 | 14 | etf::SaiIO::Captured1st(); |
MikamiUitOpen | 0:eade5d3ae0eb | 15 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 16 | |
MikamiUitOpen | 0:eade5d3ae0eb | 17 | void BSP_AUDIO_IN_TransferComplete_CallBack() |
MikamiUitOpen | 0:eade5d3ae0eb | 18 | { |
mladjo1993 | 13:2757dd069581 | 19 | etf::SaiIO::Captured2nd(); |
MikamiUitOpen | 0:eade5d3ae0eb | 20 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 21 | |
MikamiUitOpen | 0:eade5d3ae0eb | 22 | void BSP_AUDIO_IN_Error_CallBack() |
MikamiUitOpen | 0:eade5d3ae0eb | 23 | { |
mladjo1993 | 13:2757dd069581 | 24 | etf::SaiIO::ErrorTrap(); |
MikamiUitOpen | 0:eade5d3ae0eb | 25 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 26 | |
MikamiUitOpen | 0:eade5d3ae0eb | 27 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:eade5d3ae0eb | 28 | // Followings are original by Nanase |
MikamiUitOpen | 0:eade5d3ae0eb | 29 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:eade5d3ae0eb | 30 | |
MikamiUitOpen | 0:eade5d3ae0eb | 31 | DMA_HandleTypeDef hdma_sai_rx; |
MikamiUitOpen | 0:eade5d3ae0eb | 32 | |
MikamiUitOpen | 0:eade5d3ae0eb | 33 | void AUDIO_IN_SAIx_DMAx_IRQHandler() |
MikamiUitOpen | 0:eade5d3ae0eb | 34 | { |
MikamiUitOpen | 0:eade5d3ae0eb | 35 | HAL_DMA_IRQHandler(&hdma_sai_rx); |
MikamiUitOpen | 0:eade5d3ae0eb | 36 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 37 | |
MikamiUitOpen | 0:eade5d3ae0eb | 38 | void BSP_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params) |
MikamiUitOpen | 0:eade5d3ae0eb | 39 | { |
MikamiUitOpen | 0:eade5d3ae0eb | 40 | GPIO_InitTypeDef gpio_init_structure; |
MikamiUitOpen | 0:eade5d3ae0eb | 41 | |
MikamiUitOpen | 0:eade5d3ae0eb | 42 | /* Enable SAI clock */ |
MikamiUitOpen | 0:eade5d3ae0eb | 43 | AUDIO_IN_SAIx_CLK_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 44 | |
MikamiUitOpen | 0:eade5d3ae0eb | 45 | /* Enable SD GPIO clock */ |
MikamiUitOpen | 0:eade5d3ae0eb | 46 | AUDIO_IN_SAIx_SD_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 47 | /* CODEC_SAI pin configuration: SD pin */ |
MikamiUitOpen | 0:eade5d3ae0eb | 48 | gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN; |
MikamiUitOpen | 0:eade5d3ae0eb | 49 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
MikamiUitOpen | 0:eade5d3ae0eb | 50 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 51 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
MikamiUitOpen | 0:eade5d3ae0eb | 52 | gpio_init_structure.Alternate = AUDIO_IN_SAIx_SD_AF; |
MikamiUitOpen | 0:eade5d3ae0eb | 53 | HAL_GPIO_Init(AUDIO_IN_SAIx_SD_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:eade5d3ae0eb | 54 | |
MikamiUitOpen | 0:eade5d3ae0eb | 55 | /* Enable Audio INT GPIO clock */ |
MikamiUitOpen | 0:eade5d3ae0eb | 56 | AUDIO_IN_INT_GPIO_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 57 | /* Audio INT pin configuration: input */ |
MikamiUitOpen | 0:eade5d3ae0eb | 58 | gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN; |
MikamiUitOpen | 0:eade5d3ae0eb | 59 | gpio_init_structure.Mode = GPIO_MODE_INPUT; |
MikamiUitOpen | 0:eade5d3ae0eb | 60 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 61 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
MikamiUitOpen | 0:eade5d3ae0eb | 62 | HAL_GPIO_Init(AUDIO_IN_INT_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:eade5d3ae0eb | 63 | |
MikamiUitOpen | 0:eade5d3ae0eb | 64 | /* Enable the DMA clock */ |
MikamiUitOpen | 0:eade5d3ae0eb | 65 | AUDIO_IN_SAIx_DMAx_CLK_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 66 | |
MikamiUitOpen | 0:eade5d3ae0eb | 67 | if(hsai->Instance == AUDIO_IN_SAIx) |
MikamiUitOpen | 0:eade5d3ae0eb | 68 | { |
MikamiUitOpen | 0:eade5d3ae0eb | 69 | /* Configure the hdma_sai_rx handle parameters */ |
MikamiUitOpen | 0:eade5d3ae0eb | 70 | hdma_sai_rx.Init.Channel = AUDIO_IN_SAIx_DMAx_CHANNEL; |
MikamiUitOpen | 0:eade5d3ae0eb | 71 | hdma_sai_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; |
MikamiUitOpen | 0:eade5d3ae0eb | 72 | hdma_sai_rx.Init.PeriphInc = DMA_PINC_DISABLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 73 | hdma_sai_rx.Init.MemInc = DMA_MINC_ENABLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 74 | hdma_sai_rx.Init.PeriphDataAlignment = AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE; |
MikamiUitOpen | 0:eade5d3ae0eb | 75 | hdma_sai_rx.Init.MemDataAlignment = AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE; |
MikamiUitOpen | 0:eade5d3ae0eb | 76 | hdma_sai_rx.Init.Mode = DMA_CIRCULAR; |
MikamiUitOpen | 0:eade5d3ae0eb | 77 | hdma_sai_rx.Init.Priority = DMA_PRIORITY_HIGH; |
MikamiUitOpen | 0:eade5d3ae0eb | 78 | hdma_sai_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 79 | hdma_sai_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 80 | hdma_sai_rx.Init.MemBurst = DMA_MBURST_SINGLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 81 | hdma_sai_rx.Init.PeriphBurst = DMA_MBURST_SINGLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 82 | |
MikamiUitOpen | 0:eade5d3ae0eb | 83 | hdma_sai_rx.Instance = AUDIO_IN_SAIx_DMAx_STREAM; |
MikamiUitOpen | 0:eade5d3ae0eb | 84 | |
MikamiUitOpen | 0:eade5d3ae0eb | 85 | /* Associate the DMA handle */ |
MikamiUitOpen | 0:eade5d3ae0eb | 86 | __HAL_LINKDMA(hsai, hdmarx, hdma_sai_rx); |
MikamiUitOpen | 0:eade5d3ae0eb | 87 | |
MikamiUitOpen | 0:eade5d3ae0eb | 88 | /* Deinitialize the Stream for new transfer */ |
MikamiUitOpen | 0:eade5d3ae0eb | 89 | HAL_DMA_DeInit(&hdma_sai_rx); |
MikamiUitOpen | 0:eade5d3ae0eb | 90 | |
MikamiUitOpen | 0:eade5d3ae0eb | 91 | /* Configure the DMA Stream */ |
MikamiUitOpen | 0:eade5d3ae0eb | 92 | HAL_DMA_Init(&hdma_sai_rx); |
MikamiUitOpen | 0:eade5d3ae0eb | 93 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 94 | |
MikamiUitOpen | 0:eade5d3ae0eb | 95 | /* SAI DMA IRQ Channel configuration */ |
MikamiUitOpen | 0:eade5d3ae0eb | 96 | HAL_NVIC_SetPriority(AUDIO_IN_SAIx_DMAx_IRQ, AUDIO_IN_IRQ_PREPRIO, 0); |
MikamiUitOpen | 0:eade5d3ae0eb | 97 | HAL_NVIC_EnableIRQ(AUDIO_IN_SAIx_DMAx_IRQ); |
MikamiUitOpen | 0:eade5d3ae0eb | 98 | |
MikamiUitOpen | 0:eade5d3ae0eb | 99 | /* Audio INT IRQ Channel configuration */ |
MikamiUitOpen | 0:eade5d3ae0eb | 100 | HAL_NVIC_SetPriority(AUDIO_IN_INT_IRQ, AUDIO_IN_IRQ_PREPRIO, 0); |
MikamiUitOpen | 0:eade5d3ae0eb | 101 | HAL_NVIC_EnableIRQ(AUDIO_IN_INT_IRQ); |
MikamiUitOpen | 0:eade5d3ae0eb | 102 | } |