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

Now added generate Saw Wave to DAC function in generate(); You will hear Stereo saw wave sound now. /media/uploads/p_igmon/i2s_sample_test_audacity.png

more info: http://www.geocities.jp/micro_diys/i2s_test_sample/i2s_test_sample.html

Committer:
p_igmon
Date:
Thu Sep 21 10:20:50 2017 +0000
Revision:
1:48f506a7b488
Parent:
0:dc88722ab141
Added Sample Saw Wave in Function Generate.
; DAC PCM1781 Can Output Saw Wave now.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p_igmon 0:dc88722ab141 1 /**
p_igmon 0:dc88722ab141 2 ******************************************************************************
p_igmon 0:dc88722ab141 3 * File Name : stm32f4xx_hal_msp.c
p_igmon 0:dc88722ab141 4 * Date : 22/06/2014 09:00:07
p_igmon 0:dc88722ab141 5 * Description : This file provides code for the MSP Initialization
p_igmon 0:dc88722ab141 6 * and de-Initialization codes.
p_igmon 0:dc88722ab141 7 ******************************************************************************
p_igmon 0:dc88722ab141 8 *
p_igmon 0:dc88722ab141 9 * COPYRIGHT(c) 2014 STMicroelectronics
p_igmon 0:dc88722ab141 10 *
p_igmon 0:dc88722ab141 11 * Redistribution and use in source and binary forms, with or without modification,
p_igmon 0:dc88722ab141 12 * are permitted provided that the following conditions are met:
p_igmon 0:dc88722ab141 13 * 1. Redistributions of source code must retain the above copyright notice,
p_igmon 0:dc88722ab141 14 * this list of conditions and the following disclaimer.
p_igmon 0:dc88722ab141 15 * 2. Redistributions in binary form must reproduce the above copyright notice,
p_igmon 0:dc88722ab141 16 * this list of conditions and the following disclaimer in the documentation
p_igmon 0:dc88722ab141 17 * and/or other materials provided with the distribution.
p_igmon 0:dc88722ab141 18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
p_igmon 0:dc88722ab141 19 * may be used to endorse or promote products derived from this software
p_igmon 0:dc88722ab141 20 * without specific prior written permission.
p_igmon 0:dc88722ab141 21 *
p_igmon 0:dc88722ab141 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
p_igmon 0:dc88722ab141 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
p_igmon 0:dc88722ab141 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
p_igmon 0:dc88722ab141 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
p_igmon 0:dc88722ab141 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
p_igmon 0:dc88722ab141 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
p_igmon 0:dc88722ab141 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
p_igmon 0:dc88722ab141 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
p_igmon 0:dc88722ab141 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
p_igmon 0:dc88722ab141 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
p_igmon 0:dc88722ab141 32 *
p_igmon 0:dc88722ab141 33 ******************************************************************************
p_igmon 0:dc88722ab141 34 */
p_igmon 0:dc88722ab141 35
p_igmon 0:dc88722ab141 36 #include "synthesizer.h"
p_igmon 0:dc88722ab141 37 extern DigitalOut myled;
p_igmon 0:dc88722ab141 38
p_igmon 0:dc88722ab141 39 extern DMA_HandleTypeDef hdma_i2s2_ext_tx;
p_igmon 0:dc88722ab141 40
p_igmon 0:dc88722ab141 41 void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)
p_igmon 0:dc88722ab141 42 {
p_igmon 0:dc88722ab141 43
p_igmon 0:dc88722ab141 44 // GPIO_InitTypeDef GPIO_InitStruct;
p_igmon 0:dc88722ab141 45 if(hi2s->Instance==SPI2)
p_igmon 0:dc88722ab141 46 {
p_igmon 0:dc88722ab141 47 /* Peripheral clock enable */
p_igmon 0:dc88722ab141 48 __SPI2_CLK_ENABLE();
p_igmon 0:dc88722ab141 49
p_igmon 0:dc88722ab141 50 /**I2S2 GPIO Configuration
p_igmon 0:dc88722ab141 51 PC3 ------> I2S2_SD
p_igmon 0:dc88722ab141 52 PB10 ------> I2S2_CK
p_igmon 0:dc88722ab141 53 PB12 ------> I2S2_WS
p_igmon 0:dc88722ab141 54 PC6 ------> I2S2_MCK
p_igmon 0:dc88722ab141 55 */
p_igmon 0:dc88722ab141 56 /*
p_igmon 0:dc88722ab141 57 GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_6;
p_igmon 0:dc88722ab141 58 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
p_igmon 0:dc88722ab141 59 GPIO_InitStruct.Pull = GPIO_NOPULL;
p_igmon 0:dc88722ab141 60 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
p_igmon 0:dc88722ab141 61 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
p_igmon 0:dc88722ab141 62 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
p_igmon 0:dc88722ab141 63
p_igmon 0:dc88722ab141 64 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_12;
p_igmon 0:dc88722ab141 65 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
p_igmon 0:dc88722ab141 66 GPIO_InitStruct.Pull = GPIO_NOPULL;
p_igmon 0:dc88722ab141 67 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
p_igmon 0:dc88722ab141 68 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
p_igmon 0:dc88722ab141 69 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
p_igmon 0:dc88722ab141 70 */
p_igmon 0:dc88722ab141 71 /* Peripheral DMA init*/
p_igmon 0:dc88722ab141 72
p_igmon 0:dc88722ab141 73 hdma_i2s2_ext_tx.Instance = DMA1_Stream4;
p_igmon 0:dc88722ab141 74 hdma_i2s2_ext_tx.Init.Channel = DMA_CHANNEL_0;
p_igmon 0:dc88722ab141 75 hdma_i2s2_ext_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
p_igmon 0:dc88722ab141 76 hdma_i2s2_ext_tx.Init.PeriphInc = DMA_PINC_DISABLE;
p_igmon 0:dc88722ab141 77 hdma_i2s2_ext_tx.Init.MemInc = DMA_MINC_ENABLE;
p_igmon 0:dc88722ab141 78 hdma_i2s2_ext_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
p_igmon 0:dc88722ab141 79 hdma_i2s2_ext_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
p_igmon 0:dc88722ab141 80 hdma_i2s2_ext_tx.Init.Mode = DMA_NORMAL;
p_igmon 0:dc88722ab141 81 hdma_i2s2_ext_tx.Init.Priority = DMA_PRIORITY_LOW;
p_igmon 0:dc88722ab141 82 hdma_i2s2_ext_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
p_igmon 0:dc88722ab141 83 hdma_i2s2_ext_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
p_igmon 0:dc88722ab141 84 hdma_i2s2_ext_tx.Init.MemBurst = DMA_MBURST_SINGLE;
p_igmon 0:dc88722ab141 85 hdma_i2s2_ext_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
p_igmon 0:dc88722ab141 86 HAL_DMA_Init(&hdma_i2s2_ext_tx);
p_igmon 0:dc88722ab141 87
p_igmon 0:dc88722ab141 88 __HAL_LINKDMA(hi2s,hdmatx,hdma_i2s2_ext_tx);
p_igmon 0:dc88722ab141 89 // myled =1;
p_igmon 0:dc88722ab141 90 }
p_igmon 0:dc88722ab141 91
p_igmon 0:dc88722ab141 92 }
p_igmon 0:dc88722ab141 93
p_igmon 0:dc88722ab141 94 void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
p_igmon 0:dc88722ab141 95 {
p_igmon 0:dc88722ab141 96
p_igmon 0:dc88722ab141 97 if(hi2s->Instance==SPI2)
p_igmon 0:dc88722ab141 98 {
p_igmon 0:dc88722ab141 99 /* Peripheral clock disable */
p_igmon 0:dc88722ab141 100 __SPI2_CLK_DISABLE();
p_igmon 0:dc88722ab141 101
p_igmon 0:dc88722ab141 102 /**I2S2 GPIO Configuration
p_igmon 0:dc88722ab141 103 PC3 ------> I2S2_SD
p_igmon 0:dc88722ab141 104 PB10 ------> I2S2_CK
p_igmon 0:dc88722ab141 105 PB12 ------> I2S2_WS
p_igmon 0:dc88722ab141 106 PC6 ------> I2S2_MCK
p_igmon 0:dc88722ab141 107 */
p_igmon 0:dc88722ab141 108 // HAL_GPIO_DeInit(GPIOC, GPIO_PIN_3|GPIO_PIN_6);
p_igmon 0:dc88722ab141 109
p_igmon 0:dc88722ab141 110 // HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_12);
p_igmon 0:dc88722ab141 111
p_igmon 0:dc88722ab141 112 /* Peripheral DMA DeInit*/
p_igmon 0:dc88722ab141 113 HAL_DMA_DeInit(hi2s->hdmatx);
p_igmon 0:dc88722ab141 114 }
p_igmon 0:dc88722ab141 115
p_igmon 0:dc88722ab141 116 }
p_igmon 0:dc88722ab141 117
p_igmon 0:dc88722ab141 118
p_igmon 0:dc88722ab141 119 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
p_igmon 0:dc88722ab141 120
p_igmon 0:dc88722ab141 121
p_igmon 0:dc88722ab141 122
p_igmon 0:dc88722ab141 123