p igmon
/
uGen4x
PCM Digital Synthesizer
i2s_dma.cpp@0:ad6637c36dc7, 2016-09-02 (annotated)
- Committer:
- p_igmon
- Date:
- Fri Sep 02 13:24:16 2016 +0000
- Revision:
- 0:ad6637c36dc7
for Micro Gen4 Synthesizer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p_igmon | 0:ad6637c36dc7 | 1 | #include "synthesizer.h" |
p_igmon | 0:ad6637c36dc7 | 2 | |
p_igmon | 0:ad6637c36dc7 | 3 | extern Serial pc; |
p_igmon | 0:ad6637c36dc7 | 4 | //extern RawSerial PC; |
p_igmon | 0:ad6637c36dc7 | 5 | extern DigitalOut myled; |
p_igmon | 0:ad6637c36dc7 | 6 | |
p_igmon | 0:ad6637c36dc7 | 7 | extern GENERATOR *pgen;// = &dgen[0]; |
p_igmon | 0:ad6637c36dc7 | 8 | extern GENERATOR_TEMP *pgen_temp;// = &dgen_temp[0]; |
p_igmon | 0:ad6637c36dc7 | 9 | |
p_igmon | 0:ad6637c36dc7 | 10 | extern I2S_HandleTypeDef hi2s2; |
p_igmon | 0:ad6637c36dc7 | 11 | extern DMA_HandleTypeDef hdma_i2s2_ext_tx; |
p_igmon | 0:ad6637c36dc7 | 12 | |
p_igmon | 0:ad6637c36dc7 | 13 | |
p_igmon | 0:ad6637c36dc7 | 14 | S16 DMA_Buffer[DMA_BUFFERSIZE]; |
p_igmon | 0:ad6637c36dc7 | 15 | //S16 * DMA_Buffer = (S16 *)0x20008000; |
p_igmon | 0:ad6637c36dc7 | 16 | __IO BUFFER_StateTypeDef BufferOffset = DMA_Idle; |
p_igmon | 0:ad6637c36dc7 | 17 | |
p_igmon | 0:ad6637c36dc7 | 18 | |
p_igmon | 0:ad6637c36dc7 | 19 | static const PinMap PinMap_I2S_MCK[] = { |
p_igmon | 0:ad6637c36dc7 | 20 | {PC_6, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 21 | // {PC_7, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, |
p_igmon | 0:ad6637c36dc7 | 22 | {NC, NC, 0} |
p_igmon | 0:ad6637c36dc7 | 23 | }; |
p_igmon | 0:ad6637c36dc7 | 24 | |
p_igmon | 0:ad6637c36dc7 | 25 | static const PinMap PinMap_I2S_CK[] = { |
p_igmon | 0:ad6637c36dc7 | 26 | {PB_10, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 27 | {PB_13, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 28 | // {PD_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 29 | // {PC_10, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, |
p_igmon | 0:ad6637c36dc7 | 30 | {NC, NC, 0} |
p_igmon | 0:ad6637c36dc7 | 31 | }; |
p_igmon | 0:ad6637c36dc7 | 32 | |
p_igmon | 0:ad6637c36dc7 | 33 | static const PinMap PinMap_I2S_WS[] = { |
p_igmon | 0:ad6637c36dc7 | 34 | {PB_12, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 35 | {PB_9, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 36 | // {PA_15, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, |
p_igmon | 0:ad6637c36dc7 | 37 | {NC, NC, 0} |
p_igmon | 0:ad6637c36dc7 | 38 | }; |
p_igmon | 0:ad6637c36dc7 | 39 | |
p_igmon | 0:ad6637c36dc7 | 40 | static const PinMap PinMap_I2S_SD[] = { |
p_igmon | 0:ad6637c36dc7 | 41 | {PC_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 42 | {PB_15, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, |
p_igmon | 0:ad6637c36dc7 | 43 | // {PC_12, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, |
p_igmon | 0:ad6637c36dc7 | 44 | // {PD_6, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI3)}, |
p_igmon | 0:ad6637c36dc7 | 45 | {NC, NC, 0} |
p_igmon | 0:ad6637c36dc7 | 46 | }; |
p_igmon | 0:ad6637c36dc7 | 47 | |
p_igmon | 0:ad6637c36dc7 | 48 | |
p_igmon | 0:ad6637c36dc7 | 49 | |
p_igmon | 0:ad6637c36dc7 | 50 | void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) |
p_igmon | 0:ad6637c36dc7 | 51 | { |
p_igmon | 0:ad6637c36dc7 | 52 | if(hi2s->Instance == I2S2) |
p_igmon | 0:ad6637c36dc7 | 53 | { |
p_igmon | 0:ad6637c36dc7 | 54 | BufferOffset = DMA_FullComplete; |
p_igmon | 0:ad6637c36dc7 | 55 | HAL_I2S_Transmit_DMA(&hi2s2, (uint16_t*)&DMA_Buffer[0], DMA_BUFFERSIZE); |
p_igmon | 0:ad6637c36dc7 | 56 | } |
p_igmon | 0:ad6637c36dc7 | 57 | } |
p_igmon | 0:ad6637c36dc7 | 58 | |
p_igmon | 0:ad6637c36dc7 | 59 | void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) |
p_igmon | 0:ad6637c36dc7 | 60 | { |
p_igmon | 0:ad6637c36dc7 | 61 | if(hi2s->Instance == I2S2) BufferOffset = DMA_HalfComplete; |
p_igmon | 0:ad6637c36dc7 | 62 | } |
p_igmon | 0:ad6637c36dc7 | 63 | |
p_igmon | 0:ad6637c36dc7 | 64 | |
p_igmon | 0:ad6637c36dc7 | 65 | |
p_igmon | 0:ad6637c36dc7 | 66 | void init_dmabuffer(void){ |
p_igmon | 0:ad6637c36dc7 | 67 | int16_t *ptr0 = (int16_t*)&DMA_Buffer[0]; |
p_igmon | 0:ad6637c36dc7 | 68 | for (int i =0;i < DMA_BUFFERSIZE/2 ;i++){ |
p_igmon | 0:ad6637c36dc7 | 69 | *ptr0++ = 0;// Lch |
p_igmon | 0:ad6637c36dc7 | 70 | *ptr0++ = 0;// Rch |
p_igmon | 0:ad6637c36dc7 | 71 | } |
p_igmon | 0:ad6637c36dc7 | 72 | } |
p_igmon | 0:ad6637c36dc7 | 73 | |
p_igmon | 0:ad6637c36dc7 | 74 | |
p_igmon | 0:ad6637c36dc7 | 75 | void i2s_dma_init(void) { |
p_igmon | 0:ad6637c36dc7 | 76 | pinmap_pinout(PC_6, PinMap_I2S_MCK); |
p_igmon | 0:ad6637c36dc7 | 77 | pinmap_pinout(PB_13, PinMap_I2S_CK); |
p_igmon | 0:ad6637c36dc7 | 78 | pinmap_pinout(PB_12, PinMap_I2S_WS); |
p_igmon | 0:ad6637c36dc7 | 79 | pinmap_pinout(PB_15, PinMap_I2S_SD); |
p_igmon | 0:ad6637c36dc7 | 80 | |
p_igmon | 0:ad6637c36dc7 | 81 | pin_mode(PC_6, PullUp); |
p_igmon | 0:ad6637c36dc7 | 82 | pin_mode(PB_13, PullUp); |
p_igmon | 0:ad6637c36dc7 | 83 | pin_mode(PB_12, PullUp); |
p_igmon | 0:ad6637c36dc7 | 84 | pin_mode(PB_15, PullUp); |
p_igmon | 0:ad6637c36dc7 | 85 | |
p_igmon | 0:ad6637c36dc7 | 86 | init_dmabuffer(); |
p_igmon | 0:ad6637c36dc7 | 87 | |
p_igmon | 0:ad6637c36dc7 | 88 | HAL_I2S_Transmit_DMA(&hi2s2, (uint16_t *)&DMA_Buffer[0],DMA_BUFFERSIZE / 2); |
p_igmon | 0:ad6637c36dc7 | 89 | /* |
p_igmon | 0:ad6637c36dc7 | 90 | pc.printf("DMA CR =%4x \n\r" ,DMA1_Stream4->CR); |
p_igmon | 0:ad6637c36dc7 | 91 | pc.printf("DMA FCR =%4x \n\r" ,DMA1_Stream4->FCR); |
p_igmon | 0:ad6637c36dc7 | 92 | |
p_igmon | 0:ad6637c36dc7 | 93 | pc.printf("DMA M0AR =%4x M1AR =%4x PAR = %4x \n\r" ,DMA1_Stream4->M0AR ,DMA1_Stream4->M1AR ,DMA1_Stream4->PAR); |
p_igmon | 0:ad6637c36dc7 | 94 | pc.printf("I2S CR2 = %4x \n\r" ,SPI2->CR2); |
p_igmon | 0:ad6637c36dc7 | 95 | pc.printf("I2S SR = %4x \n\r" ,SPI2->SR); |
p_igmon | 0:ad6637c36dc7 | 96 | pc.printf("I2S I2SCFGR = %4x \n\r" ,SPI2->I2SCFGR); |
p_igmon | 0:ad6637c36dc7 | 97 | pc.printf("I2S I2SPR = %4x \n\r" ,SPI2->I2SPR); |
p_igmon | 0:ad6637c36dc7 | 98 | pc.printf("RCC->PLLI2SCFGR = %4x \n\r" ,RCC->PLLI2SCFGR); |
p_igmon | 0:ad6637c36dc7 | 99 | */ |
p_igmon | 0:ad6637c36dc7 | 100 | |
p_igmon | 0:ad6637c36dc7 | 101 | // HAL_RCC_MCOConfig(uint32_t RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_5); |
p_igmon | 0:ad6637c36dc7 | 102 | } |
p_igmon | 0:ad6637c36dc7 | 103 | |
p_igmon | 0:ad6637c36dc7 | 104 | |
p_igmon | 0:ad6637c36dc7 | 105 | |
p_igmon | 0:ad6637c36dc7 | 106 | |
p_igmon | 0:ad6637c36dc7 | 107 |