예제 #1
0
    void initClocks() {
        // enable HSI and set it as the system clock source
        RCC_HSICmd(ENABLE);
        while(!(RCC->CR & RCC_CR_HSIRDY)); // wait for it to be ready
        RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);

        // disable PLL and PLLI2S
        RCC_PLLCmd(DISABLE);
        RCC_PLLI2SCmd(DISABLE);

        // disable HSE and CSS (disabling the HSE also disables CSS)
        RCC_HSEConfig(RCC_HSE_OFF);

        // Configure PLL values and set source to HSE
        RCC_PLLConfig(
                RCC_PLLSource_HSE,
                DESIRED_PLL_M,
                DESIRED_PLL_N,
                DESIRED_PLL_P,
                DESIRED_PLL_Q
        );

        // set PLL I2S to our new values
        RCC_PLLI2SConfig(
                DESIRED_PLL_I2S_N,
                DESIRED_PLL_I2S_R
        );

        // set I2S clock source to PLLI2S
        RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);

        // set AHB, APB1, APB2 prescalers
        RCC_HCLKConfig(DESIRED_HCLK_DIV);
        RCC_PCLK1Config(DESIRED_PCLK1_DIV);
        RCC_PCLK2Config(DESIRED_PCKL2_DIV);

        // enable HSE
        RCC_HSEConfig(RCC_HSE_ON);
        if(RCC_WaitForHSEStartUp() == ERROR) RCC_DeInit(); // SHUT DOWN, EVERYTHING!

        // enable CSS
        RCC_ClockSecuritySystemCmd(ENABLE);

        // enable PLL
        RCC_PLLCmd(ENABLE);
        while(!(RCC->CR & RCC_CR_PLLRDY)); // wait for ready

        // enable PLL I2S
        RCC_PLLI2SCmd(ENABLE);

        // set system clock source to PLL
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

        if(!checkClocks()){
            // No actual error reporting done here because we don't want to depend on GPIO etc
            while(1);
        }

    }
예제 #2
0
void audioInit()
{
    I2S_InitTypeDef I2S_InitStructure;

    Audio_GPIO_Init();

    /*CONFIG the I2S_RCC ,MUST before enabling the I2S APB clock*/
    //PLLI2SN 302,PLLI2SR 2,I2SDIV 53,I2SODD 1,FS 44.1KHZ,16bit,Error 0.0011%
    RCC_PLLI2SConfig(302,2);
    RCC_PLLI2SCmd(ENABLE);
    RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);

    /* Enable the CODEC_I2S peripheral clock */
    RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
    /* CODEC_I2S peripheral configuration */
    SPI_I2S_DeInit(CODEC_I2S);
    I2S_InitStructure.I2S_AudioFreq = AudioFreq;
    I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
    I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
    I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;//clk 0 when idle state
    I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
#ifdef CODEC_MCLK_ENABLED
    I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
#elif defined(CODEC_MCLK_DISABLED)
    I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
#else
    #error "No selection for the MCLK output has been defined !"
#endif /* CODEC_MCLK_ENABLED */

    /* Initialize the I2S peripheral with the structure above */
    I2S_Init(CODEC_I2S, &I2S_InitStructure);
    I2S_Cmd(CODEC_I2S, ENABLE);
    //interrupt
#ifdef CODEC_USE_INT
    SPI_I2S_ITConfig(CODEC_I2S,SPI_I2S_IT_TXE,ENABLE);
#elif defined(CODEC_USE_DMA)
#error "DMA is not initialized"
#endif
}