Final version.
Fork of F746_SAI_IO by
BSP_AudioOut_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 functions |
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_Sweep/ |
MikamiUitOpen | 0:eade5d3ae0eb | 7 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:eade5d3ae0eb | 8 | #include "BSP_AudioOut_Overwrite.hpp" |
MikamiUitOpen | 0:eade5d3ae0eb | 9 | |
MikamiUitOpen | 0:eade5d3ae0eb | 10 | // These three callback functions are modyfied by Mikami |
MikamiUitOpen | 0:eade5d3ae0eb | 11 | void BSP_AUDIO_OUT_HalfTransfer_CallBack() |
MikamiUitOpen | 0:eade5d3ae0eb | 12 | { |
mladjo1993 | 13:2757dd069581 | 13 | etf::SaiIO::FillBuffer1st(); |
MikamiUitOpen | 0:eade5d3ae0eb | 14 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 15 | |
MikamiUitOpen | 0:eade5d3ae0eb | 16 | void BSP_AUDIO_OUT_TransferComplete_CallBack() |
MikamiUitOpen | 0:eade5d3ae0eb | 17 | { |
mladjo1993 | 13:2757dd069581 | 18 | etf::SaiIO::FillBuffer2nd(); |
MikamiUitOpen | 0:eade5d3ae0eb | 19 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 20 | |
MikamiUitOpen | 0:eade5d3ae0eb | 21 | void BSP_AUDIO_OUT_Error_CallBack() |
MikamiUitOpen | 0:eade5d3ae0eb | 22 | { |
mladjo1993 | 13:2757dd069581 | 23 | etf::SaiIO::ErrorTrap(); |
MikamiUitOpen | 0:eade5d3ae0eb | 24 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 25 | |
MikamiUitOpen | 0:eade5d3ae0eb | 26 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:eade5d3ae0eb | 27 | // Followings are original by Nanase |
MikamiUitOpen | 0:eade5d3ae0eb | 28 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:eade5d3ae0eb | 29 | |
MikamiUitOpen | 0:eade5d3ae0eb | 30 | DMA_HandleTypeDef hdma_sai_tx; |
MikamiUitOpen | 0:eade5d3ae0eb | 31 | |
MikamiUitOpen | 0:eade5d3ae0eb | 32 | void AUDIO_OUT_SAIx_DMAx_IRQHandler() |
MikamiUitOpen | 0:eade5d3ae0eb | 33 | { |
MikamiUitOpen | 0:eade5d3ae0eb | 34 | HAL_DMA_IRQHandler(&hdma_sai_tx); |
MikamiUitOpen | 0:eade5d3ae0eb | 35 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 36 | |
MikamiUitOpen | 0:eade5d3ae0eb | 37 | void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params) |
MikamiUitOpen | 0:eade5d3ae0eb | 38 | { |
MikamiUitOpen | 0:eade5d3ae0eb | 39 | //static DMA_HandleTypeDef hdma_sai_tx; |
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_OUT_SAIx_CLK_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 44 | |
MikamiUitOpen | 0:eade5d3ae0eb | 45 | /* Enable GPIO clock */ |
MikamiUitOpen | 0:eade5d3ae0eb | 46 | AUDIO_OUT_SAIx_MCLK_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 47 | AUDIO_OUT_SAIx_SCK_SD_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 48 | AUDIO_OUT_SAIx_FS_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 49 | |
MikamiUitOpen | 0:eade5d3ae0eb | 50 | /* CODEC_SAI pins configuration: FS, SCK, MCK and SD pins ------------------*/ |
MikamiUitOpen | 0:eade5d3ae0eb | 51 | gpio_init_structure.Pin = AUDIO_OUT_SAIx_FS_PIN; |
MikamiUitOpen | 0:eade5d3ae0eb | 52 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
MikamiUitOpen | 0:eade5d3ae0eb | 53 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 54 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
MikamiUitOpen | 0:eade5d3ae0eb | 55 | gpio_init_structure.Alternate = AUDIO_OUT_SAIx_FS_SD_MCLK_AF; |
MikamiUitOpen | 0:eade5d3ae0eb | 56 | HAL_GPIO_Init(AUDIO_OUT_SAIx_FS_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:eade5d3ae0eb | 57 | |
MikamiUitOpen | 0:eade5d3ae0eb | 58 | gpio_init_structure.Pin = AUDIO_OUT_SAIx_SCK_PIN; |
MikamiUitOpen | 0:eade5d3ae0eb | 59 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
MikamiUitOpen | 0:eade5d3ae0eb | 60 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 61 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
MikamiUitOpen | 0:eade5d3ae0eb | 62 | gpio_init_structure.Alternate = AUDIO_OUT_SAIx_SCK_AF; |
MikamiUitOpen | 0:eade5d3ae0eb | 63 | HAL_GPIO_Init(AUDIO_OUT_SAIx_SCK_SD_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:eade5d3ae0eb | 64 | |
MikamiUitOpen | 0:eade5d3ae0eb | 65 | gpio_init_structure.Pin = AUDIO_OUT_SAIx_SD_PIN; |
MikamiUitOpen | 0:eade5d3ae0eb | 66 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
MikamiUitOpen | 0:eade5d3ae0eb | 67 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 68 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
MikamiUitOpen | 0:eade5d3ae0eb | 69 | gpio_init_structure.Alternate = AUDIO_OUT_SAIx_FS_SD_MCLK_AF; |
MikamiUitOpen | 0:eade5d3ae0eb | 70 | HAL_GPIO_Init(AUDIO_OUT_SAIx_SCK_SD_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:eade5d3ae0eb | 71 | |
MikamiUitOpen | 0:eade5d3ae0eb | 72 | gpio_init_structure.Pin = AUDIO_OUT_SAIx_MCLK_PIN; |
MikamiUitOpen | 0:eade5d3ae0eb | 73 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
MikamiUitOpen | 0:eade5d3ae0eb | 74 | gpio_init_structure.Pull = GPIO_NOPULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 75 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
MikamiUitOpen | 0:eade5d3ae0eb | 76 | gpio_init_structure.Alternate = AUDIO_OUT_SAIx_FS_SD_MCLK_AF; |
MikamiUitOpen | 0:eade5d3ae0eb | 77 | HAL_GPIO_Init(AUDIO_OUT_SAIx_MCLK_GPIO_PORT, &gpio_init_structure); |
MikamiUitOpen | 0:eade5d3ae0eb | 78 | |
MikamiUitOpen | 0:eade5d3ae0eb | 79 | /* Enable the DMA clock */ |
MikamiUitOpen | 0:eade5d3ae0eb | 80 | AUDIO_OUT_SAIx_DMAx_CLK_ENABLE(); |
MikamiUitOpen | 0:eade5d3ae0eb | 81 | |
MikamiUitOpen | 0:eade5d3ae0eb | 82 | if(hsai->Instance == AUDIO_OUT_SAIx) |
MikamiUitOpen | 0:eade5d3ae0eb | 83 | { |
MikamiUitOpen | 0:eade5d3ae0eb | 84 | /* Configure the hdma_saiTx handle parameters */ |
MikamiUitOpen | 0:eade5d3ae0eb | 85 | hdma_sai_tx.Init.Channel = AUDIO_OUT_SAIx_DMAx_CHANNEL; |
MikamiUitOpen | 0:eade5d3ae0eb | 86 | hdma_sai_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; |
MikamiUitOpen | 0:eade5d3ae0eb | 87 | hdma_sai_tx.Init.PeriphInc = DMA_PINC_DISABLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 88 | hdma_sai_tx.Init.MemInc = DMA_MINC_ENABLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 89 | hdma_sai_tx.Init.PeriphDataAlignment = AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE; |
MikamiUitOpen | 0:eade5d3ae0eb | 90 | hdma_sai_tx.Init.MemDataAlignment = AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE; |
MikamiUitOpen | 0:eade5d3ae0eb | 91 | hdma_sai_tx.Init.Mode = DMA_CIRCULAR; |
MikamiUitOpen | 0:eade5d3ae0eb | 92 | hdma_sai_tx.Init.Priority = DMA_PRIORITY_HIGH; |
MikamiUitOpen | 0:eade5d3ae0eb | 93 | hdma_sai_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 94 | hdma_sai_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; |
MikamiUitOpen | 0:eade5d3ae0eb | 95 | hdma_sai_tx.Init.MemBurst = DMA_MBURST_SINGLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 96 | hdma_sai_tx.Init.PeriphBurst = DMA_PBURST_SINGLE; |
MikamiUitOpen | 0:eade5d3ae0eb | 97 | |
MikamiUitOpen | 0:eade5d3ae0eb | 98 | hdma_sai_tx.Instance = AUDIO_OUT_SAIx_DMAx_STREAM; |
MikamiUitOpen | 0:eade5d3ae0eb | 99 | |
MikamiUitOpen | 0:eade5d3ae0eb | 100 | /* Associate the DMA handle */ |
MikamiUitOpen | 0:eade5d3ae0eb | 101 | __HAL_LINKDMA(hsai, hdmatx, hdma_sai_tx); |
MikamiUitOpen | 0:eade5d3ae0eb | 102 | |
MikamiUitOpen | 0:eade5d3ae0eb | 103 | /* Deinitialize the Stream for new transfer */ |
MikamiUitOpen | 0:eade5d3ae0eb | 104 | HAL_DMA_DeInit(&hdma_sai_tx); |
MikamiUitOpen | 0:eade5d3ae0eb | 105 | |
MikamiUitOpen | 0:eade5d3ae0eb | 106 | /* Configure the DMA Stream */ |
MikamiUitOpen | 0:eade5d3ae0eb | 107 | HAL_DMA_Init(&hdma_sai_tx); |
MikamiUitOpen | 0:eade5d3ae0eb | 108 | } |
MikamiUitOpen | 0:eade5d3ae0eb | 109 | |
MikamiUitOpen | 0:eade5d3ae0eb | 110 | /* SAI DMA IRQ Channel configuration */ |
MikamiUitOpen | 0:eade5d3ae0eb | 111 | HAL_NVIC_SetPriority(AUDIO_OUT_SAIx_DMAx_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0); |
MikamiUitOpen | 0:eade5d3ae0eb | 112 | HAL_NVIC_EnableIRQ(AUDIO_OUT_SAIx_DMAx_IRQ); |
MikamiUitOpen | 0:eade5d3ae0eb | 113 | } |