Part of MicroGen4 Music Synthesizer Program. (But not test it yet.) I2S ,DMA ,Stereo ,16Bit Dac(PCM1781) See detail: http://www.geocities.jp/micro_diys/index2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f4xx_hal_msp.cpp Source File

stm32f4xx_hal_msp.cpp

00001 /**
00002   ******************************************************************************
00003   * File Name          : stm32f4xx_hal_msp.c
00004   * Date               : 22/06/2014 09:00:07
00005   * Description        : This file provides code for the MSP Initialization 
00006   *                      and de-Initialization codes.
00007   ******************************************************************************
00008   *
00009   * COPYRIGHT(c) 2014 STMicroelectronics
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 
00036 #include "synthesizer.h"
00037 extern DigitalOut myled;
00038 
00039 extern DMA_HandleTypeDef hdma_i2s2_ext_tx;
00040 
00041 void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)
00042 {
00043 
00044 //  GPIO_InitTypeDef GPIO_InitStruct;
00045   if(hi2s->Instance==SPI2)
00046   {
00047     /* Peripheral clock enable */
00048     __SPI2_CLK_ENABLE();
00049   
00050     /**I2S2 GPIO Configuration    
00051     PC3     ------> I2S2_SD
00052     PB10     ------> I2S2_CK
00053     PB12     ------> I2S2_WS
00054     PC6     ------> I2S2_MCK 
00055     */
00056 /*
00057     GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_6;
00058     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00059     GPIO_InitStruct.Pull = GPIO_NOPULL;
00060     GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
00061     GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
00062     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
00063 
00064     GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_12;
00065     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00066     GPIO_InitStruct.Pull = GPIO_NOPULL;
00067     GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
00068     GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
00069     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
00070 */
00071     /* Peripheral DMA init*/
00072   
00073     hdma_i2s2_ext_tx.Instance = DMA1_Stream4;
00074     hdma_i2s2_ext_tx.Init.Channel = DMA_CHANNEL_0;
00075     hdma_i2s2_ext_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
00076     hdma_i2s2_ext_tx.Init.PeriphInc = DMA_PINC_DISABLE;
00077     hdma_i2s2_ext_tx.Init.MemInc = DMA_MINC_ENABLE;
00078     hdma_i2s2_ext_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
00079     hdma_i2s2_ext_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
00080     hdma_i2s2_ext_tx.Init.Mode = DMA_NORMAL;
00081     hdma_i2s2_ext_tx.Init.Priority = DMA_PRIORITY_LOW;
00082     hdma_i2s2_ext_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
00083     hdma_i2s2_ext_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
00084     hdma_i2s2_ext_tx.Init.MemBurst = DMA_MBURST_SINGLE;
00085     hdma_i2s2_ext_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
00086     HAL_DMA_Init(&hdma_i2s2_ext_tx);
00087 
00088     __HAL_LINKDMA(hi2s,hdmatx,hdma_i2s2_ext_tx);
00089 //    myled =1;
00090   }
00091 
00092 }
00093 
00094 void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
00095 {
00096 
00097   if(hi2s->Instance==SPI2)
00098   {
00099     /* Peripheral clock disable */
00100     __SPI2_CLK_DISABLE();
00101   
00102     /**I2S2 GPIO Configuration    
00103     PC3     ------> I2S2_SD
00104     PB10     ------> I2S2_CK
00105     PB12     ------> I2S2_WS
00106     PC6     ------> I2S2_MCK 
00107     */
00108 //    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_3|GPIO_PIN_6);
00109 
00110 //    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_12);
00111 
00112     /* Peripheral DMA DeInit*/
00113     HAL_DMA_DeInit(hi2s->hdmatx);
00114   }
00115 
00116 }
00117 
00118 
00119 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00120 
00121 
00122 
00123