Sawtooth wave on left channel
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.1794174173" name="Floating-point unit" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.369857510" name="Floating-point ABI" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1721672077" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="STM32F411E-DISCO" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1992663669" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32F411E-DISCO || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy | ../FATFS/Target | ../FATFS/App | ../USB_DEVICE/App | ../USB_DEVICE/Target | ../Middlewares/Third_Party/FatFs/src | ../Middlewares/ST/STM32_USB_Device_Library/Core/Inc | ../Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc || || || USE_HAL_DRIVER | STM32F411xE || || Drivers | Core/Startup | Middlewares | Core | FATFS | USB_DEVICE || || || ${workspace_loc:/${ProjName}/STM32F411VETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1992663669" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32F411E-DISCO || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../FATFS/App | ../USB_DEVICE/Target | ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../USB_DEVICE/App | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../FATFS/Target | ../Middlewares/ST/STM32_USB_Device_Library/Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy | ../Middlewares/Third_Party/FatFs/src | ../Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc || || || USE_HAL_DRIVER | STM32F411xE || || Drivers | Core/Startup | Middlewares | Core | FATFS | USB_DEVICE || || || ${workspace_loc:/${ProjName}/STM32F411VETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.975091300" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||
<builder buildPath="${workspace_loc:/F411-DMA-Audio}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1669640011" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.1364992464" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
|
||||
@@ -132,7 +132,7 @@
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.1475300684" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.1239165760" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.492356982" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="STM32F411E-DISCO" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1474171759" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32F411E-DISCO || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy | ../FATFS/Target | ../FATFS/App | ../USB_DEVICE/App | ../USB_DEVICE/Target | ../Middlewares/Third_Party/FatFs/src | ../Middlewares/ST/STM32_USB_Device_Library/Core/Inc | ../Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc || || || USE_HAL_DRIVER | STM32F411xE || || Drivers | Core/Startup | Middlewares | Core | FATFS | USB_DEVICE || || || ${workspace_loc:/${ProjName}/STM32F411VETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1474171759" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32F411E-DISCO || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../FATFS/App | ../USB_DEVICE/Target | ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../USB_DEVICE/App | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../FATFS/Target | ../Middlewares/ST/STM32_USB_Device_Library/Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy | ../Middlewares/Third_Party/FatFs/src | ../Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc || || || USE_HAL_DRIVER | STM32F411xE || || Drivers | Core/Startup | Middlewares | Core | FATFS | USB_DEVICE || || || ${workspace_loc:/${ProjName}/STM32F411VETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.195172514" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||
<builder buildPath="${workspace_loc:/F411-DMA-Audio}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1978478044" managedBuildOn="true" name="Gnu Make Builder.Release" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.1392129692" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="141237957491136193" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-321882623712562213" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
@@ -18,7 +18,7 @@
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="141237957491136193" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-321882623712562213" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
635E684B79701B039C64EA45C3F84D30=786B3C9175F8FD59BE24144A9C2C0972
|
||||
66BE74F758C12D739921AEA421D593D3=0
|
||||
8DF89ED150041C4CBC7CB9A9CAA90856=A7836624F0B1F62198526376ABF87601
|
||||
8DF89ED150041C4CBC7CB9A9CAA90856=AB300AAF2E04A330B7C06C41BF25F205
|
||||
DC22A860405A8BF2F2C095E5B6529F12=AB300AAF2E04A330B7C06C41BF25F205
|
||||
eclipse.preferences.version=1
|
||||
|
||||
@@ -55,6 +55,7 @@ void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void DMA1_Stream5_IRQHandler(void);
|
||||
void OTG_FS_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
|
||||
691
Core/Src/Components/AUDIO.c
Normal file
691
Core/Src/Components/AUDIO.c
Normal file
@@ -0,0 +1,691 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f411e_discovery_audio.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the Audio driver for the STM32F411E-Discovery
|
||||
* board.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*==============================================================================
|
||||
User NOTES
|
||||
1. How To use this driver:
|
||||
--------------------------
|
||||
- This driver supports STM32F411xx devices on STM32F411E-Discovery Kit:
|
||||
a) to play an audio file (all functions names start by BSP_AUDIO_OUT_xxx)
|
||||
b) to record an audio file through MP45DT02, ST MEMS (all functions names start by AUDIO_IN_xxx)
|
||||
|
||||
a) PLAY A FILE:
|
||||
==============
|
||||
+ Call the function BSP_AUDIO_OUT_Init(
|
||||
OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER,
|
||||
OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or
|
||||
OUTPUT_DEVICE_BOTH)
|
||||
Volume: initial volume to be set (0 is min (mute), 100 is max (100%)
|
||||
AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...)
|
||||
this parameter is relative to the audio file/stream type.
|
||||
)
|
||||
This function configures all the hardware required for the audio application (codec, I2C, I2S,
|
||||
GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
|
||||
If the returned value is different from 0 or the function is stuck then the communication with
|
||||
the codec (try to un-plug the power or reset device in this case).
|
||||
- OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream.
|
||||
- OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream.
|
||||
- OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented
|
||||
into the audio jack on the discovery board). When the Headphone is connected it is used
|
||||
as output. When the headphone is disconnected from the audio jack, the output is
|
||||
automatically switched to Speaker.
|
||||
- OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream
|
||||
at the same time.
|
||||
+ Call the function BSP_AUDIO_OUT_Play(
|
||||
pBuffer: pointer to the audio data file address
|
||||
Size: size of the buffer to be sent in Bytes
|
||||
)
|
||||
to start playing (for the first time) from the audio file/stream.
|
||||
+ Call the function BSP_AUDIO_OUT_Pause() to pause playing
|
||||
+ Call the function BSP_AUDIO_OUT_Resume() to resume playing.
|
||||
Note. After calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() should be called
|
||||
for resume (it is not allowed to call BSP_AUDIO_OUT_Play() in this case).
|
||||
Note. This function should be called only when the audio file is played or paused (not stopped).
|
||||
+ For each mode, you may need to implement the relative callback functions into your code.
|
||||
The Callback functions are named BSP_AUDIO_OUT_XXXCallBack() and only their prototypes are declared in
|
||||
the stm32f411e_discovery_audio.h file. (refer to the example for more details on the callbacks implementations)
|
||||
+ To Stop playing, to modify the volume level, the frequency or to mute, use the functions
|
||||
BSP_AUDIO_OUT_Stop(), BSP_AUDIO_OUT_SetVolume(), AUDIO_OUT_SetFrequency() BSP_AUDIO_OUT_SetOutputMode and BSP_AUDIO_OUT_SetMute().
|
||||
+ The driver API and the callback functions are at the end of the stm32f411e_discovery_audio.h file.
|
||||
|
||||
Driver architecture:
|
||||
--------------------
|
||||
+ This driver provide the High Audio Layer: consists of the function API exported in the stm32f411e_discovery_audio.h file
|
||||
(BSP_AUDIO_OUT_Init(), BSP_AUDIO_OUT_Play() ...)
|
||||
+ This driver provide also the Media Access Layer (MAL): which consists of functions allowing to access the media containing/
|
||||
providing the audio file/stream. These functions are also included as local functions into
|
||||
the stm32f411e_discovery_audio.c file (I2S3_Init()...)
|
||||
|
||||
Known Limitations:
|
||||
-------------------
|
||||
1- When using the Speaker, if the audio file quality is not high enough, the speaker output
|
||||
may produce high and uncomfortable noise level. To avoid this issue, to use speaker
|
||||
output properly, try to increase audio file sampling rate (typically higher than 48KHz).
|
||||
This operation will lead to larger file size.
|
||||
2- Communication with the audio codec (through I2C) may be corrupted if it is interrupted by some
|
||||
user interrupt routines (in this case, interrupts could be disabled just before the start of
|
||||
communication then re-enabled when it is over). Note that this communication is only done at
|
||||
the configuration phase (BSP_AUDIO_OUT_Init() or BSP_AUDIO_OUT_Stop()) and when Volume control modification is
|
||||
performed (BSP_AUDIO_OUT_SetVolume() or BSP_AUDIO_OUT_SetMute()or BSP_AUDIO_OUT_SetOutputMode()).
|
||||
When the audio data is played, no communication is required with the audio codec.
|
||||
3- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size,
|
||||
File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file.
|
||||
4- Supports only Stereo audio streaming. To play mono audio streams, each data should be sent twice
|
||||
on the I2S or should be duplicated on the source buffer. Or convert the stream in stereo before playing.
|
||||
5- Supports only 16-bits audio data size.
|
||||
|
||||
b) RECORD A FILE:
|
||||
================
|
||||
+ Call the function BSP_AUDIO_IN_Init(
|
||||
AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...)
|
||||
)
|
||||
This function configures all the hardware required for the audio application (I2S,
|
||||
GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
|
||||
|
||||
+ Call the function BSP_AUDIO_IN_Record(
|
||||
pbuf Main buffer pointer for the recorded data storing
|
||||
size Current size of the recorded buffer
|
||||
)
|
||||
to start recording from the microphone.
|
||||
|
||||
+ User needs to implement user callbacks to retrieve data saved in the record buffer
|
||||
(AUDIO_IN_RxHalfCpltCallback/BSP_AUDIO_IN_ReceiveComplete_CallBack)
|
||||
|
||||
+ Call the function AUDIO_IN_STOP() to stop recording
|
||||
|
||||
==============================================================================*/
|
||||
|
||||
|
||||
/**
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
|
||||
File: AUDIO.c
|
||||
Modifier: ControllersTech.com
|
||||
Updated: 10th JAN 2021
|
||||
|
||||
***************************************************************************************************************
|
||||
Copyright (C) 2017 ControllersTech.com
|
||||
|
||||
This is a free software under the GNU license, you can redistribute it and/or modify it under the terms
|
||||
of the GNU General Public License version 3 as published by the Free Software Foundation.
|
||||
This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly
|
||||
or indirectly by this software, read more about this on the GNU General Public License.
|
||||
|
||||
***************************************************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "AUDIO.h"
|
||||
|
||||
/* These PLL parameters are valid when the f(VCO clock) = 1Mhz */
|
||||
const uint32_t I2SFreq[8] = {8000, 11025, 16000, 22050, 32000, 44100, 48000, 96000};
|
||||
const uint32_t I2SPLLN[8] = {256, 429, 213, 429, 426, 271, 258, 344};
|
||||
const uint32_t I2SPLLR[8] = {5, 4, 4, 4, 4, 6, 3, 1};
|
||||
|
||||
/*##### PLAY #####*/
|
||||
static AUDIO_DrvTypeDef *pAudioDrv;
|
||||
I2S_HandleTypeDef hAudioOutI2s;
|
||||
|
||||
static uint8_t I2S3_Init(uint32_t AudioFreq);
|
||||
extern AUDIO_DrvTypeDef cs43l22_drv;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configures the audio peripherals.
|
||||
* @param OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
|
||||
* OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
|
||||
* @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
|
||||
* @param AudioFreq: Audio frequency used to play the audio stream.
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
|
||||
{
|
||||
uint8_t ret = AUDIO_OK;
|
||||
|
||||
/* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
|
||||
AUDIO_OUT_ClockConfig(&hAudioOutI2s, AudioFreq, NULL);
|
||||
|
||||
/* I2S data transfer preparation:
|
||||
Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
|
||||
hAudioOutI2s.Instance = I2S3;
|
||||
if(HAL_I2S_GetState(&hAudioOutI2s) == HAL_I2S_STATE_RESET)
|
||||
{
|
||||
/* Init the I2S MSP: this __weak function can be redefined by the application*/
|
||||
AUDIO_OUT_MspInit(&hAudioOutI2s, NULL);
|
||||
}
|
||||
|
||||
/* I2S data transfer preparation:
|
||||
Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
|
||||
/* Configure the I2S peripheral */
|
||||
if(I2S3_Init(AudioFreq) != AUDIO_OK)
|
||||
{
|
||||
ret = AUDIO_ERROR;
|
||||
}
|
||||
|
||||
if(ret == AUDIO_OK)
|
||||
{
|
||||
/* Retieve audio codec identifier */
|
||||
if(((cs43l22_drv.ReadID(AUDIO_I2C_ADDRESS)) & CS43L22_ID_MASK) == CS43L22_ID)
|
||||
{
|
||||
/* Initialize the audio driver structure */
|
||||
pAudioDrv = &cs43l22_drv;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = AUDIO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if(ret == AUDIO_OK)
|
||||
{
|
||||
pAudioDrv->Init(AUDIO_I2C_ADDRESS, OutputDevice, Volume, AudioFreq);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts playing audio stream from a data buffer for a determined size.
|
||||
* @param pBuffer: Pointer to the buffer
|
||||
* @param Size: Number of audio data BYTES.
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size)
|
||||
{
|
||||
/* Call the audio Codec Play function */
|
||||
if(pAudioDrv->Play(AUDIO_I2C_ADDRESS, pBuffer, Size) != 0)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the Media layer and enable it for play */
|
||||
HAL_I2S_Transmit_DMA(&hAudioOutI2s, pBuffer, DMA_MAX(Size/AUDIODATA_SIZE));
|
||||
|
||||
/* Return AUDIO_OK when all operations are correctly done */
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sends n-Bytes on the I2S interface.
|
||||
* @param pData: Pointer to data address
|
||||
* @param Size: Number of data to be written
|
||||
*/
|
||||
void AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
|
||||
{
|
||||
HAL_I2S_Transmit_DMA(&hAudioOutI2s, pData, Size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pauses the audio file stream. In case of using DMA, the DMA Pause
|
||||
* feature is used.
|
||||
* WARNING: When calling BSP_AUDIO_OUT_Pause() function for pause, only the
|
||||
* BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play()
|
||||
* function for resume could lead to unexpected behavior).
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_Pause(void)
|
||||
{
|
||||
/* Call the Audio Codec Pause/Resume function */
|
||||
if(pAudioDrv->Pause(AUDIO_I2C_ADDRESS) != 0)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the Media layer pause function */
|
||||
HAL_I2S_DMAPause(&hAudioOutI2s);
|
||||
|
||||
/* Return AUDIO_OK when all operations are correctly done */
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resumes the audio file streaming.
|
||||
* WARNING: When calling BSP_AUDIO_OUT_Pause() function for pause, only
|
||||
* BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play()
|
||||
* function for resume could lead to unexpected behavior).
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_Resume(void)
|
||||
{
|
||||
/* Call the Audio Codec Pause/Resume function */
|
||||
if(pAudioDrv->Resume(AUDIO_I2C_ADDRESS) != 0)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the Media layer resume function */
|
||||
HAL_I2S_DMAResume(&hAudioOutI2s);
|
||||
|
||||
/* Return AUDIO_OK when all operations are correctly done */
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stops audio playing and Power down the Audio Codec.
|
||||
* @param Option: could be one of the following parameters
|
||||
* - CODEC_PDWN_HW: completely shut down the codec (physically).
|
||||
* Then need to reconfigure the Codec after power on.
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_Stop(uint32_t Option)
|
||||
{
|
||||
/* Call DMA Stop to disable DMA stream before stopping codec */
|
||||
HAL_I2S_DMAStop(&hAudioOutI2s);
|
||||
|
||||
/* Call Audio Codec Stop function */
|
||||
if(pAudioDrv->Stop(AUDIO_I2C_ADDRESS, Option) != 0)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Option == CODEC_PDWN_HW)
|
||||
{
|
||||
/* Wait at least 1ms */
|
||||
HAL_Delay(1);
|
||||
|
||||
/* Reset the pin */
|
||||
HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
/* Return AUDIO_OK when all operations are correctly done */
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Controls the current audio volume level.
|
||||
* @param Volume: Volume level to be set in percentage from 0% to 100% (0 for
|
||||
* Mute and 100 for Max volume level).
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_SetVolume(uint8_t Volume)
|
||||
{
|
||||
/* Call the codec volume control function with converted volume value */
|
||||
if(pAudioDrv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Return AUDIO_OK when all operations are correctly done */
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables or disables the MUTE mode by software
|
||||
* @param Cmd: could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to
|
||||
* unmute the codec and restore previous volume level.
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_SetMute(uint32_t Cmd)
|
||||
{
|
||||
/* Call the Codec Mute function */
|
||||
if(pAudioDrv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Return AUDIO_OK when all operations are correctly done */
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Switch dynamically (while audio file is played) the output target
|
||||
* (speaker or headphone).
|
||||
* @note This function modifies a global variable of the audio codec driver: OutputDev.
|
||||
* @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER,
|
||||
* OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO
|
||||
* @retval AUDIO_OK if correct communication, else wrong communication
|
||||
*/
|
||||
uint8_t AUDIO_OUT_SetOutputMode(uint8_t Output)
|
||||
{
|
||||
/* Call the Codec output Device function */
|
||||
if(pAudioDrv->SetOutputMode(AUDIO_I2C_ADDRESS, Output) != 0)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Return AUDIO_OK when all operations are correctly done */
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the audio frequency.
|
||||
* @param AudioFreq: Audio frequency used to play the audio stream.
|
||||
* @note This API should be called after the BSP_AUDIO_OUT_Init() to adjust the
|
||||
* audio frequency.
|
||||
*/
|
||||
void AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
|
||||
{
|
||||
RCC_PeriphCLKInitTypeDef rccclkinit;
|
||||
|
||||
/* Enable PLLI2S clock */
|
||||
HAL_RCCEx_GetPeriphCLKConfig(&rccclkinit);
|
||||
/* PLLI2S_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
|
||||
if ((AudioFreq & 0x7) == 0)
|
||||
{
|
||||
/* Audio frequency multiple of 8 (8/16/32/48/96/192) */
|
||||
/* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 192 Mhz */
|
||||
/* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 192/6 = 32 Mhz */
|
||||
rccclkinit.PeriphClockSelection = RCC_PERIPHCLK_I2S;
|
||||
rccclkinit.PLLI2S.PLLI2SN = 192;
|
||||
rccclkinit.PLLI2S.PLLI2SR = 6;
|
||||
HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Other Frequency (11.025/22.500/44.100) */
|
||||
/* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 290 Mhz */
|
||||
/* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 290/2 = 145 Mhz */
|
||||
rccclkinit.PeriphClockSelection = RCC_PERIPHCLK_I2S;
|
||||
rccclkinit.PLLI2S.PLLI2SN = 290;
|
||||
rccclkinit.PLLI2S.PLLI2SR = 2;
|
||||
HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
|
||||
}
|
||||
|
||||
/* Update the I2S audio frequency configuration */
|
||||
I2S3_Init(AudioFreq);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Transfer completed callbacks.
|
||||
* @param hi2s: I2S handle
|
||||
*/
|
||||
void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
if(hi2s->Instance == I2S3)
|
||||
{
|
||||
/* Call the user function which will manage directly transfer complete */
|
||||
AUDIO_OUT_TransferComplete_CallBack();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Half Transfer completed callbacks.
|
||||
* @param hi2s: I2S handle
|
||||
*/
|
||||
void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
if(hi2s->Instance == I2S3)
|
||||
{
|
||||
/* Manage the remaining file size and new address offset: This function should
|
||||
be coded by user (its prototype is already declared in stm32f4_discovery_audio.h) */
|
||||
AUDIO_OUT_HalfTransfer_CallBack();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clock Config.
|
||||
* @param hi2s: might be required to set audio peripheral predivider if any.
|
||||
* @param AudioFreq: Audio frequency used to play the audio stream.
|
||||
* @note This API is called by BSP_AUDIO_OUT_Init() and BSP_AUDIO_OUT_SetFrequency()
|
||||
* Being __weak it can be overwritten by the application
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
*/
|
||||
__weak void AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
|
||||
{
|
||||
RCC_PeriphCLKInitTypeDef rccclkinit;
|
||||
uint8_t index = 0, freqindex = 0xFF;
|
||||
|
||||
for(index = 0; index < 8; index++)
|
||||
{
|
||||
if(I2SFreq[index] == AudioFreq)
|
||||
{
|
||||
freqindex = index;
|
||||
}
|
||||
}
|
||||
/* Enable PLLI2S clock */
|
||||
HAL_RCCEx_GetPeriphCLKConfig(&rccclkinit);
|
||||
/* PLLI2S_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
|
||||
if ((freqindex & 0x7) == 0)
|
||||
{
|
||||
/* I2S clock config
|
||||
PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) <20> (PLLI2SN/PLLM)
|
||||
I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
|
||||
rccclkinit.PeriphClockSelection = RCC_PERIPHCLK_I2S;
|
||||
rccclkinit.PLLI2S.PLLI2SM = 8;
|
||||
rccclkinit.PLLI2S.PLLI2SN = I2SPLLN[freqindex];
|
||||
rccclkinit.PLLI2S.PLLI2SR = I2SPLLR[freqindex];
|
||||
HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* I2S clock config
|
||||
PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) <20> (PLLI2SN/PLLM)
|
||||
I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
|
||||
rccclkinit.PeriphClockSelection = RCC_PERIPHCLK_I2S;
|
||||
rccclkinit.PLLI2S.PLLI2SM = 8;
|
||||
rccclkinit.PLLI2S.PLLI2SN = 258;
|
||||
rccclkinit.PLLI2S.PLLI2SR = 3;
|
||||
HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO OUT I2S MSP Init.
|
||||
* @param hi2s: might be required to set audio peripheral predivider if any.
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
*/
|
||||
__weak void AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
|
||||
{
|
||||
static DMA_HandleTypeDef hdma_i2sTx;
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable I2S3 clock */
|
||||
I2S3_CLK_ENABLE();
|
||||
|
||||
/*** Configure the GPIOs ***/
|
||||
/* Enable I2S GPIO clocks */
|
||||
I2S3_SCK_SD_CLK_ENABLE();
|
||||
I2S3_WS_CLK_ENABLE();
|
||||
|
||||
/* I2S3 pins configuration: WS, SCK and SD pins ----------------------------*/
|
||||
GPIO_InitStruct.Pin = I2S3_SCK_PIN | I2S3_SD_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
GPIO_InitStruct.Alternate = I2S3_SCK_SD_WS_AF;
|
||||
HAL_GPIO_Init(I2S3_SCK_SD_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = I2S3_WS_PIN ;
|
||||
HAL_GPIO_Init(I2S3_WS_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* I2S3 pins configuration: MCK pin */
|
||||
I2S3_MCK_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = I2S3_MCK_PIN;
|
||||
HAL_GPIO_Init(I2S3_MCK_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* Enable the I2S DMA clock */
|
||||
I2S3_DMAx_CLK_ENABLE();
|
||||
|
||||
if(hi2s->Instance == I2S3)
|
||||
{
|
||||
/* Configure the hdma_i2sTx handle parameters */
|
||||
hdma_i2sTx.Init.Channel = I2S3_DMAx_CHANNEL;
|
||||
hdma_i2sTx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_i2sTx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_i2sTx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_i2sTx.Init.PeriphDataAlignment = I2S3_DMAx_PERIPH_DATA_SIZE;
|
||||
hdma_i2sTx.Init.MemDataAlignment = I2S3_DMAx_MEM_DATA_SIZE;
|
||||
hdma_i2sTx.Init.Mode = DMA_NORMAL;
|
||||
hdma_i2sTx.Init.Priority = DMA_PRIORITY_HIGH;
|
||||
hdma_i2sTx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
||||
hdma_i2sTx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||||
hdma_i2sTx.Init.MemBurst = DMA_MBURST_SINGLE;
|
||||
hdma_i2sTx.Init.PeriphBurst = DMA_PBURST_SINGLE;
|
||||
|
||||
hdma_i2sTx.Instance = I2S3_DMAx_STREAM;
|
||||
|
||||
/* Associate the DMA handle */
|
||||
__HAL_LINKDMA(hi2s, hdmatx, hdma_i2sTx);
|
||||
|
||||
/* Deinitialize the Stream for new transfer */
|
||||
HAL_DMA_DeInit(&hdma_i2sTx);
|
||||
|
||||
/* Configure the DMA Stream */
|
||||
HAL_DMA_Init(&hdma_i2sTx);
|
||||
}
|
||||
|
||||
/* I2S DMA IRQ Channel configuration */
|
||||
HAL_NVIC_SetPriority(I2S3_DMAx_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0);
|
||||
HAL_NVIC_EnableIRQ(I2S3_DMAx_IRQ);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-Initializes BSP_AUDIO_OUT MSP.
|
||||
* @param hi2s: might be required to set audio peripheral predivider if any.
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
*/
|
||||
__weak void AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* I2S DMA IRQ Channel deactivation */
|
||||
HAL_NVIC_DisableIRQ(I2S3_DMAx_IRQ);
|
||||
|
||||
if(hi2s->Instance == I2S3)
|
||||
{
|
||||
/* Deinitialize the Stream for new transfer */
|
||||
HAL_DMA_DeInit(hi2s->hdmatx);
|
||||
}
|
||||
|
||||
/* Disable I2S block */
|
||||
__HAL_I2S_DISABLE(hi2s);
|
||||
|
||||
/* CODEC_I2S pins configuration: SCK and SD pins */
|
||||
GPIO_InitStruct.Pin = I2S3_SCK_PIN | I2S3_SD_PIN;
|
||||
HAL_GPIO_DeInit(I2S3_SCK_SD_GPIO_PORT, GPIO_InitStruct.Pin);
|
||||
|
||||
/* CODEC_I2S pins configuration: WS pin */
|
||||
GPIO_InitStruct.Pin = I2S3_WS_PIN;
|
||||
HAL_GPIO_DeInit(I2S3_WS_GPIO_PORT, GPIO_InitStruct.Pin);
|
||||
|
||||
/* CODEC_I2S pins configuration: MCK pin */
|
||||
GPIO_InitStruct.Pin = I2S3_MCK_PIN;
|
||||
HAL_GPIO_DeInit(I2S3_MCK_GPIO_PORT, GPIO_InitStruct.Pin);
|
||||
|
||||
/* Disable I2S clock */
|
||||
I2S3_CLK_DISABLE();
|
||||
|
||||
/* GPIO pins clock and DMA clock can be shut down in the applic
|
||||
by surcgarging this __weak function */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Manages the DMA full Transfer complete event.
|
||||
*/
|
||||
__weak void AUDIO_OUT_TransferComplete_CallBack(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Manages the DMA Half Transfer complete event.
|
||||
*/
|
||||
__weak void AUDIO_OUT_HalfTransfer_CallBack(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Manages the DMA FIFO error event.
|
||||
*/
|
||||
__weak void AUDIO_OUT_Error_CallBack(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
Static Functions
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Initializes the Audio Codec audio interface (I2S).
|
||||
* @param AudioFreq: Audio frequency to be configured for the I2S peripheral.
|
||||
*/
|
||||
static uint8_t I2S3_Init(uint32_t AudioFreq)
|
||||
{
|
||||
/* Initialize the hAudioOutI2s Instance parameter */
|
||||
hAudioOutI2s.Instance = I2S3;
|
||||
|
||||
/* Disable I2S block */
|
||||
__HAL_I2S_DISABLE(&hAudioOutI2s);
|
||||
|
||||
/* I2S3 peripheral configuration */
|
||||
hAudioOutI2s.Init.AudioFreq = AudioFreq;
|
||||
hAudioOutI2s.Init.ClockSource = I2S_CLOCK_PLL;
|
||||
hAudioOutI2s.Init.CPOL = I2S_CPOL_LOW;
|
||||
hAudioOutI2s.Init.DataFormat = I2S_DATAFORMAT_16B;
|
||||
hAudioOutI2s.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
|
||||
hAudioOutI2s.Init.Mode = I2S_MODE_MASTER_TX;
|
||||
hAudioOutI2s.Init.Standard = I2S_STANDARD;
|
||||
|
||||
/* Initialize the I2S peripheral with the structure above */
|
||||
if(HAL_I2S_Init(&hAudioOutI2s) != HAL_OK)
|
||||
{
|
||||
return AUDIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AUDIO_OK;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief I2S error callbacks.
|
||||
* @param hi2s: I2S handle
|
||||
*/
|
||||
void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s)
|
||||
{
|
||||
/* Manage the error generated on DMA FIFO: This function
|
||||
should be coded by user (its prototype is already declared in stm32f411e_discovery_audio.h) */
|
||||
if(hi2s->Instance == I2S3)
|
||||
{
|
||||
AUDIO_OUT_Error_CallBack();
|
||||
}
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
174
Core/Src/Components/AUDIO.h
Normal file
174
Core/Src/Components/AUDIO.h
Normal file
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f411e_discovery_audio.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* stm32f411e_discovery_audio.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
|
||||
File: AUDIO.h
|
||||
Modifier: ControllersTech.com
|
||||
Updated: 10th JAN 2021
|
||||
|
||||
***************************************************************************************************************
|
||||
Copyright (C) 2017 ControllersTech.com
|
||||
|
||||
This is a free software under the GNU license, you can redistribute it and/or modify it under the terms
|
||||
of the GNU General Public License version 3 as published by the Free Software Foundation.
|
||||
This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly
|
||||
or indirectly by this software, read more about this on the GNU General Public License.
|
||||
|
||||
***************************************************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_H
|
||||
#define __AUDIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "cs43l22.h"
|
||||
#include "AUDIO_LINK.h"
|
||||
//#include "pdm2pcm_glo.h"
|
||||
|
||||
|
||||
#define CODEC_STANDARD 0x04
|
||||
#define I2S_STANDARD I2S_STANDARD_PHILIPS
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t (*Init)(uint16_t, uint16_t, uint8_t, uint32_t);
|
||||
void (*DeInit)(void);
|
||||
uint32_t (*ReadID)(uint16_t);
|
||||
uint32_t (*Play)(uint16_t, uint16_t*, uint16_t);
|
||||
uint32_t (*Pause)(uint16_t);
|
||||
uint32_t (*Resume)(uint16_t);
|
||||
uint32_t (*Stop)(uint16_t, uint32_t);
|
||||
uint32_t (*SetFrequency)(uint16_t, uint32_t);
|
||||
uint32_t (*SetVolume)(uint16_t, uint8_t);
|
||||
uint32_t (*SetMute)(uint16_t, uint32_t);
|
||||
uint32_t (*SetOutputMode)(uint16_t, uint8_t);
|
||||
uint32_t (*Reset)(uint16_t);
|
||||
}AUDIO_DrvTypeDef;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
AUDIO OUT CONFIGURATION
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* I2S peripheral configuration defines */
|
||||
#define I2S3 SPI3
|
||||
#define I2S3_CLK_ENABLE() __HAL_RCC_SPI3_CLK_ENABLE()
|
||||
#define I2S3_CLK_DISABLE() __HAL_RCC_SPI3_CLK_DISABLE()
|
||||
#define I2S3_SCK_SD_WS_AF GPIO_AF6_SPI3
|
||||
#define I2S3_SCK_SD_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define I2S3_MCK_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define I2S3_WS_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define I2S3_WS_PIN GPIO_PIN_4
|
||||
#define I2S3_SCK_PIN GPIO_PIN_10
|
||||
#define I2S3_SD_PIN GPIO_PIN_12
|
||||
#define I2S3_MCK_PIN GPIO_PIN_7
|
||||
#define I2S3_SCK_SD_GPIO_PORT GPIOC
|
||||
#define I2S3_WS_GPIO_PORT GPIOA
|
||||
#define I2S3_MCK_GPIO_PORT GPIOC
|
||||
|
||||
/* I2S DMA Stream definitions */
|
||||
#define I2S3_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define I2S3_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE()
|
||||
#define I2S3_DMAx_STREAM DMA1_Stream7
|
||||
#define I2S3_DMAx_CHANNEL DMA_CHANNEL_0
|
||||
#define I2S3_DMAx_IRQ DMA1_Stream7_IRQn
|
||||
#define I2S3_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
|
||||
#define I2S3_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
|
||||
#define DMA_MAX_SZE 0xFFFF
|
||||
|
||||
#define I2S3_IRQHandler DMA1_Stream7_IRQHandler
|
||||
|
||||
/* Select the interrupt preemption priority and subpriority for the DMA interrupt */
|
||||
#define AUDIO_OUT_IRQ_PREPRIO 0x0E /* Select the preemption priority level(0 is the highest) */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
CONFIGURATION: Audio Driver Configuration parameters
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#define AUDIODATA_SIZE 2 /* 16-bits audio data size */
|
||||
|
||||
/* Audio status definition */
|
||||
#define AUDIO_OK 0
|
||||
#define AUDIO_ERROR 1
|
||||
#define AUDIO_TIMEOUT 2
|
||||
|
||||
#define DMA_MAX(_X_) (((_X_) <= DMA_MAX_SZE)? (_X_):DMA_MAX_SZE)
|
||||
#define HTONS(A) ((((uint16_t)(A) & 0xff00) >> 8) | (((uint16_t)(A) & 0x00ff) << 8))
|
||||
|
||||
uint8_t AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
|
||||
uint8_t AUDIO_OUT_Play(uint16_t *pBuffer, uint32_t Size);
|
||||
void AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
|
||||
uint8_t AUDIO_OUT_Pause(void);
|
||||
uint8_t AUDIO_OUT_Resume(void);
|
||||
uint8_t AUDIO_OUT_Stop(uint32_t Option);
|
||||
uint8_t AUDIO_OUT_SetVolume(uint8_t Volume);
|
||||
void AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
|
||||
uint8_t AUDIO_OUT_SetMute(uint32_t Cmd);
|
||||
uint8_t AUDIO_OUT_SetOutputMode(uint8_t Output);
|
||||
|
||||
/* User Callbacks: user has to implement these functions in his code if they are needed. */
|
||||
/* This function is called when the requested data has been completely transferred. */
|
||||
void AUDIO_OUT_TransferComplete_CallBack(void);
|
||||
|
||||
/* This function is called when half of the requested buffer has been transferred. */
|
||||
void AUDIO_OUT_HalfTransfer_CallBack(void);
|
||||
|
||||
/* This function is called when an Interrupt due to transfer error on or peripheral
|
||||
error occurs. */
|
||||
void AUDIO_OUT_Error_CallBack(void);
|
||||
|
||||
/* These function can be modified in case the current settings (e.g. DMA stream)
|
||||
need to be changed for specific application needs */
|
||||
void AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params);
|
||||
void AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
|
||||
void AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AUDIO_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
267
Core/Src/Components/AUDIO_LINK.c
Normal file
267
Core/Src/Components/AUDIO_LINK.c
Normal file
@@ -0,0 +1,267 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f411e_discovery.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides set of firmware functions to manage LEDs and
|
||||
* push-button available on STM32F411-Discovery Kit from STMicroelectronics.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
|
||||
File: AUDIO_LINK.c
|
||||
Modifier: ControllersTech.com
|
||||
Updated: 10th JAN 2021
|
||||
|
||||
***************************************************************************************************************
|
||||
Copyright (C) 2017 ControllersTech.com
|
||||
|
||||
This is a free software under the GNU license, you can redistribute it and/or modify it under the terms
|
||||
of the GNU General Public License version 3 as published by the Free Software Foundation.
|
||||
This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly
|
||||
or indirectly by this software, read more about this on the GNU General Public License.
|
||||
|
||||
***************************************************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "AUDIO_LINK.h"
|
||||
|
||||
uint32_t I2cxTimeout = I2Cx_TIMEOUT_MAX; /*<! Value of Timeout when I2C communication fails */
|
||||
|
||||
static I2C_HandleTypeDef I2cHandle;
|
||||
|
||||
/* I2Cx bus function */
|
||||
static void I2Cx_Init(void);
|
||||
static void I2Cx_WriteData(uint16_t Addr, uint8_t Reg, uint8_t Value);
|
||||
static uint8_t I2Cx_ReadData(uint16_t Addr, uint8_t Reg);
|
||||
static void I2Cx_Error (void);
|
||||
static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c);
|
||||
|
||||
/* Link functions for AUDIO */
|
||||
void AUDIO_IO_Init(void);
|
||||
void AUDIO_IO_DeInit(void);
|
||||
void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
|
||||
|
||||
/*******************************************************************************
|
||||
BUS OPERATIONS
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************* I2C Routines *********************************/
|
||||
|
||||
/**
|
||||
* @brief I2Cx Bus initialization.
|
||||
*/
|
||||
static void I2Cx_Init(void)
|
||||
{
|
||||
if(HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET)
|
||||
{
|
||||
I2cHandle.Instance = AUDIO_I2Cx;
|
||||
I2cHandle.Init.OwnAddress1 = 0x43;
|
||||
I2cHandle.Init.ClockSpeed = I2Cx_MAX_COMMUNICATION_FREQ;
|
||||
I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
|
||||
I2cHandle.Init.OwnAddress2 = 0x00;
|
||||
I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
|
||||
I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
|
||||
|
||||
/* Init the I2C */
|
||||
I2Cx_MspInit(&I2cHandle);
|
||||
HAL_I2C_Init(&I2cHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a value in a register of the device through BUS.
|
||||
* @param Addr: Device address on BUS Bus.
|
||||
* @param Reg: The target register address to write
|
||||
* @param Value: The target register value to be written
|
||||
*/
|
||||
static void I2Cx_WriteData(uint16_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
status = HAL_I2C_Mem_Write(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2cxTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* Execute user timeout callback */
|
||||
I2Cx_Error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a register of the device through BUS.
|
||||
* @param Addr: Device address on BUS Bus.
|
||||
* @param Reg: The target register address to write
|
||||
* @retval Data read at register address
|
||||
*/
|
||||
static uint8_t I2Cx_ReadData(uint16_t Addr, uint8_t Reg)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint8_t value = 0;
|
||||
|
||||
status = HAL_I2C_Mem_Read(&I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &value, 1, I2cxTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* Execute user timeout callback */
|
||||
I2Cx_Error();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2Cx error treatment function.
|
||||
*/
|
||||
static void I2Cx_Error(void)
|
||||
{
|
||||
/* De-initialize the I2C comunication BUS */
|
||||
HAL_I2C_DeInit(&I2cHandle);
|
||||
|
||||
/* Re- Initiaize the I2C comunication BUS */
|
||||
I2Cx_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2Cx MSP Init.
|
||||
* @param hi2c: I2C handle
|
||||
*/
|
||||
static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* Enable the I2C peripheral */
|
||||
AUDIO_I2Cx_CLOCK_ENABLE();
|
||||
|
||||
/* Enable SCK and SDA GPIO clocks */
|
||||
AUDIO_I2Cx_GPIO_CLK_ENABLE();
|
||||
|
||||
/* I2Cx SD1 & SCK pin configuration */
|
||||
GPIO_InitStructure.Pin = AUDIO_I2Cx_SDA_PIN | AUDIO_I2Cx_SCL_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
|
||||
GPIO_InitStructure.Alternate = AUDIO_I2Cx_AF;
|
||||
|
||||
HAL_GPIO_Init(AUDIO_I2Cx_GPIO_PORT, &GPIO_InitStructure);
|
||||
|
||||
/* Force the I2C peripheral clock reset */
|
||||
AUDIO_I2Cx_FORCE_RESET();
|
||||
|
||||
/* Release the I2C peripheral clock reset */
|
||||
AUDIO_I2Cx_RELEASE_RESET();
|
||||
|
||||
/* Enable and set I2Cx Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority(AUDIO_I2Cx_EV_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(AUDIO_I2Cx_EV_IRQn);
|
||||
|
||||
/* Enable and set I2Cx Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority(AUDIO_I2Cx_ER_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(AUDIO_I2Cx_ER_IRQn);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
LINK OPERATIONS
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/********************************* LINK AUDIO *********************************/
|
||||
|
||||
/**
|
||||
* @brief Initializes Audio low level.
|
||||
*/
|
||||
void AUDIO_IO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable Reset GPIO Clock */
|
||||
AUDIO_RESET_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Audio reset pin configuration -------------------------------------------*/
|
||||
GPIO_InitStruct.Pin = AUDIO_RESET_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStruct);
|
||||
|
||||
I2Cx_Init();
|
||||
|
||||
/* Power Down the codec */
|
||||
CODEC_AUDIO_POWER_OFF();
|
||||
|
||||
/* Wait for a delay to insure registers erasing */
|
||||
HAL_Delay(5);
|
||||
|
||||
/* Power on the codec */
|
||||
CODEC_AUDIO_POWER_ON();
|
||||
|
||||
/* Wait for a delay to insure registers erasing */
|
||||
HAL_Delay(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes Audio low level.
|
||||
*/
|
||||
void AUDIO_IO_DeInit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @param Value: Data to be written
|
||||
*/
|
||||
void AUDIO_IO_Write (uint8_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
I2Cx_WriteData(Addr, Reg, Value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @retval Data to be read
|
||||
*/
|
||||
uint8_t AUDIO_IO_Read (uint8_t Addr, uint8_t Reg)
|
||||
{
|
||||
return I2Cx_ReadData(Addr, Reg);
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
114
Core/Src/Components/AUDIO_LINK.h
Normal file
114
Core/Src/Components/AUDIO_LINK.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f411e_discovery.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains definitions for STM32F401-Discovery Kit's Leds and
|
||||
* push-button hardware resources.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
***************************************************************************************************************
|
||||
|
||||
File: AUDIO_LINK.h
|
||||
Modifier: ControllersTech.com
|
||||
Updated: 10th JAN 2021
|
||||
|
||||
***************************************************************************************************************
|
||||
Copyright (C) 2017 ControllersTech.com
|
||||
|
||||
This is a free software under the GNU license, you can redistribute it and/or modify it under the terms
|
||||
of the GNU General Public License version 3 as published by the Free Software Foundation.
|
||||
This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly
|
||||
or indirectly by this software, read more about this on the GNU General Public License.
|
||||
|
||||
***************************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_LINK_H
|
||||
#define __AUDIO_LINK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
/*############################### I2Cx #######################################*/
|
||||
#define AUDIO_I2Cx I2C1
|
||||
#define AUDIO_I2Cx_CLOCK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()
|
||||
#define AUDIO_I2Cx_GPIO_PORT GPIOB /* GPIOB */
|
||||
#define AUDIO_I2Cx_SCL_PIN GPIO_PIN_6 /* PB.06 */
|
||||
#define AUDIO_I2Cx_SDA_PIN GPIO_PIN_9 /* PB.09 */
|
||||
#define AUDIO_I2Cx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define AUDIO_I2Cx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define AUDIO_I2Cx_AF GPIO_AF4_I2C1
|
||||
|
||||
#define AUDIO_I2Cx_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET()
|
||||
#define AUDIO_I2Cx_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET()
|
||||
|
||||
/* I2C interrupt requests */
|
||||
#define AUDIO_I2Cx_EV_IRQn I2C1_EV_IRQn
|
||||
#define AUDIO_I2Cx_ER_IRQn I2C1_ER_IRQn
|
||||
|
||||
/* I2C speed and timeout max */
|
||||
#define I2Cx_TIMEOUT_MAX 0xA000 /*<! The value of the maximal timeout for I2C waiting loops */
|
||||
#define I2Cx_MAX_COMMUNICATION_FREQ ((uint32_t) 100000)
|
||||
|
||||
|
||||
/*################################### AUDIO ##################################*/
|
||||
/**
|
||||
* @brief AUDIO I2C Interface pins
|
||||
*/
|
||||
/* Device I2C address */
|
||||
#define AUDIO_I2C_ADDRESS 0x94
|
||||
|
||||
/* Audio codec power on/off macro definition */
|
||||
#define CODEC_AUDIO_POWER_OFF() HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_RESET)
|
||||
#define CODEC_AUDIO_POWER_ON() HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_SET)
|
||||
|
||||
/* Audio Reset Pin definition */
|
||||
#define AUDIO_RESET_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define AUDIO_RESET_PIN GPIO_PIN_4
|
||||
#define AUDIO_RESET_GPIO GPIOD
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AUDIO_LINK_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -8,6 +8,18 @@
|
||||
#include "main.h"
|
||||
#include "Start.hpp"
|
||||
|
||||
void Start(){
|
||||
#include "AUDIO.h"
|
||||
|
||||
uint16_t pBuffer[200];
|
||||
|
||||
void Start(){
|
||||
for(uint32_t i = 0; i<100; i++){
|
||||
pBuffer[2*i] = i*655;
|
||||
pBuffer[(2*i)+1] = 32768;
|
||||
}
|
||||
AUDIO_OUT_Init(2, 35, 96000);
|
||||
AUDIO_OUT_Play(pBuffer, 400);
|
||||
while(1){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
493
Core/Src/Components/cs43l22.c
Normal file
493
Core/Src/Components/cs43l22.c
Normal file
@@ -0,0 +1,493 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cs43l22.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the CS43L22 Audio Codec driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "cs43l22.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Components
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CS43L22
|
||||
* @brief This file provides a set of functions needed to drive the
|
||||
* CS43L22 audio codec.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Private_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
#define VOLUME_CONVERT(Volume) (((Volume) > 100)? 255:((uint8_t)(((Volume) * 255) / 100)))
|
||||
/* Uncomment this line to enable verifying data sent to codec after each write
|
||||
operation (for debug purpose) */
|
||||
#if !defined (VERIFY_WRITTENDATA)
|
||||
/* #define VERIFY_WRITTENDATA */
|
||||
#endif /* VERIFY_WRITTENDATA */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Audio codec driver structure initialization */
|
||||
AUDIO_DrvTypeDef cs43l22_drv =
|
||||
{
|
||||
cs43l22_Init,
|
||||
cs43l22_DeInit,
|
||||
cs43l22_ReadID,
|
||||
|
||||
cs43l22_Play,
|
||||
cs43l22_Pause,
|
||||
cs43l22_Resume,
|
||||
cs43l22_Stop,
|
||||
|
||||
cs43l22_SetFrequency,
|
||||
cs43l22_SetVolume,
|
||||
cs43l22_SetMute,
|
||||
cs43l22_SetOutputMode,
|
||||
cs43l22_Reset,
|
||||
};
|
||||
|
||||
static uint8_t Is_cs43l22_Stop = 1;
|
||||
|
||||
volatile uint8_t OutputDev = 0;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Function_Prototypes
|
||||
* @{
|
||||
*/
|
||||
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the audio codec and the control interface.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param OutputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
|
||||
* OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
|
||||
* @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_Init(uint16_t DeviceAddr, uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
/* Initialize the Control interface of the Audio Codec */
|
||||
AUDIO_IO_Init();
|
||||
|
||||
/* Keep Codec powered OFF */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x01);
|
||||
|
||||
/*Save Output device for mute ON/OFF procedure*/
|
||||
switch (OutputDevice)
|
||||
{
|
||||
case OUTPUT_DEVICE_SPEAKER:
|
||||
OutputDev = 0xFA;
|
||||
break;
|
||||
|
||||
case OUTPUT_DEVICE_HEADPHONE:
|
||||
OutputDev = 0xAF;
|
||||
break;
|
||||
|
||||
case OUTPUT_DEVICE_BOTH:
|
||||
OutputDev = 0xAA;
|
||||
break;
|
||||
|
||||
case OUTPUT_DEVICE_AUTO:
|
||||
OutputDev = 0x05;
|
||||
break;
|
||||
|
||||
default:
|
||||
OutputDev = 0x05;
|
||||
break;
|
||||
}
|
||||
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, OutputDev);
|
||||
|
||||
/* Clock configuration: Auto detection */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_CLOCKING_CTL, 0x81);
|
||||
|
||||
/* Set the Slave Mode and the audio Standard */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_INTERFACE_CTL1, CODEC_STANDARD);
|
||||
|
||||
/* Set the Master volume */
|
||||
counter += cs43l22_SetVolume(DeviceAddr, Volume);
|
||||
|
||||
/* If the Speaker is enabled, set the Mono mode and volume attenuation level */
|
||||
if(OutputDevice != OUTPUT_DEVICE_HEADPHONE)
|
||||
{
|
||||
/* Set the Speaker Mono mode */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_PLAYBACK_CTL2, 0x06);
|
||||
|
||||
/* Set the Speaker attenuation level */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_SPEAKER_A_VOL, 0x00);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_SPEAKER_B_VOL, 0x00);
|
||||
}
|
||||
|
||||
/* Additional configuration for the CODEC. These configurations are done to reduce
|
||||
the time needed for the Codec to power off. If these configurations are removed,
|
||||
then a long delay should be added between powering off the Codec and switching
|
||||
off the I2S peripheral MCLK clock (which is the operating clock for Codec).
|
||||
If this delay is not inserted, then the codec will not shut down properly and
|
||||
it results in high noise after shut down. */
|
||||
|
||||
/* Disable the analog soft ramp */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_ANALOG_ZC_SR_SETT, 0x00);
|
||||
/* Disable the digital soft ramp */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MISC_CTL, 0x04);
|
||||
/* Disable the limiter attack level */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_LIMIT_CTL1, 0x00);
|
||||
/* Adjust Bass and Treble levels */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_TONE_CTL, 0x0F);
|
||||
/* Adjust PCM volume level */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_PCMA_VOL, 0x0A);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_PCMB_VOL, 0x0A);
|
||||
|
||||
/* Return communication control value */
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitializes the audio codec.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void cs43l22_DeInit(void)
|
||||
{
|
||||
/* Deinitialize Audio Codec interface */
|
||||
AUDIO_IO_DeInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the CS43L22 ID.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval The CS43L22 ID
|
||||
*/
|
||||
uint32_t cs43l22_ReadID(uint16_t DeviceAddr)
|
||||
{
|
||||
uint8_t Value;
|
||||
/* Initialize the Control interface of the Audio Codec */
|
||||
AUDIO_IO_Init();
|
||||
|
||||
Value = AUDIO_IO_Read(DeviceAddr, CS43L22_CHIPID_ADDR);
|
||||
Value = (Value & CS43L22_ID_MASK);
|
||||
|
||||
return((uint32_t) Value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start the audio Codec play feature.
|
||||
* @note For this codec no Play options are required.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
if(Is_cs43l22_Stop == 1)
|
||||
{
|
||||
/* Enable the digital soft ramp */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MISC_CTL, 0x06);
|
||||
|
||||
/* Enable Output device */
|
||||
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
||||
|
||||
/* Power on the Codec */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x9E);
|
||||
Is_cs43l22_Stop = 0;
|
||||
}
|
||||
|
||||
/* Return communication control value */
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pauses playing on the audio codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_Pause(uint16_t DeviceAddr)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
/* Pause the audio file playing */
|
||||
/* Mute the output first */
|
||||
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_ON);
|
||||
|
||||
/* Put the Codec in Power save mode */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x01);
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resumes playing on the audio codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_Resume(uint16_t DeviceAddr)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
volatile uint32_t index = 0x00;
|
||||
/* Resumes the audio file playing */
|
||||
/* Unmute the output first */
|
||||
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
||||
|
||||
for(index = 0x00; index < 0xFF; index++);
|
||||
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, OutputDev);
|
||||
|
||||
/* Exit the Power save mode */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x9E);
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stops audio Codec playing. It powers down the codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param CodecPdwnMode: selects the power down mode.
|
||||
* - CODEC_PDWN_HW: Physically power down the codec. When resuming from this
|
||||
* mode, the codec is set to default configuration
|
||||
* (user should re-Initialize the codec in order to
|
||||
* play again the audio stream).
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
/* Mute the output first */
|
||||
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_ON);
|
||||
|
||||
/* Disable the digital soft ramp */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MISC_CTL, 0x04);
|
||||
|
||||
/* Power down the DAC and the speaker (PMDAC and PMSPK bits)*/
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x9F);
|
||||
|
||||
Is_cs43l22_Stop = 1;
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets higher or lower the codec volume level.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param Volume: a byte value from 0 to 255 (refer to codec registers
|
||||
* description for more details).
|
||||
*
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
uint8_t convertedvol = VOLUME_CONVERT(Volume);
|
||||
|
||||
if(convertedvol > 0xE6)
|
||||
{
|
||||
/* Set the Master volume */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_A_VOL, convertedvol - 0xE7);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_B_VOL, convertedvol - 0xE7);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the Master volume */
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_A_VOL, convertedvol + 0x19);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_B_VOL, convertedvol + 0x19);
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets new frequency.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param AudioFreq: Audio frequency used to play the audio stream.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables or disables the mute feature on the audio codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
|
||||
* mute mode.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_SetMute(uint16_t DeviceAddr, uint32_t Cmd)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
/* Set the Mute mode */
|
||||
if(Cmd == AUDIO_MUTE_ON)
|
||||
{
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xFF);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_A_VOL, 0x01);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_B_VOL, 0x01);
|
||||
}
|
||||
else /* AUDIO_MUTE_OFF Disable the Mute */
|
||||
{
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_A_VOL, 0x00);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_B_VOL, 0x00);
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, OutputDev);
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Switch dynamically (while audio file is played) the output target
|
||||
* (speaker or headphone).
|
||||
* @note This function modifies a global variable of the audio codec driver: OutputDev.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER,
|
||||
* OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_SetOutputMode(uint16_t DeviceAddr, uint8_t Output)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
switch (Output)
|
||||
{
|
||||
case OUTPUT_DEVICE_SPEAKER:
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xFA); /* SPK always ON & HP always OFF */
|
||||
OutputDev = 0xFA;
|
||||
break;
|
||||
|
||||
case OUTPUT_DEVICE_HEADPHONE:
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xAF); /* SPK always OFF & HP always ON */
|
||||
OutputDev = 0xAF;
|
||||
break;
|
||||
|
||||
case OUTPUT_DEVICE_BOTH:
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xAA); /* SPK always ON & HP always ON */
|
||||
OutputDev = 0xAA;
|
||||
break;
|
||||
|
||||
case OUTPUT_DEVICE_AUTO:
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0x05); /* Detect the HP or the SPK automatically */
|
||||
OutputDev = 0x05;
|
||||
break;
|
||||
|
||||
default:
|
||||
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0x05); /* Detect the HP or the SPK automatically */
|
||||
OutputDev = 0x05;
|
||||
break;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resets cs43l22 registers.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs43l22_Reset(uint16_t DeviceAddr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes/Read a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @param Value: Data to be written
|
||||
* @retval None
|
||||
*/
|
||||
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
AUDIO_IO_Write(Addr, Reg, Value);
|
||||
|
||||
#ifdef VERIFY_WRITTENDATA
|
||||
/* Verify that the data has been correctly written */
|
||||
result = (AUDIO_IO_Read(Addr, Reg) == Value)? 0:1;
|
||||
#endif /* VERIFY_WRITTENDATA */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
228
Core/Src/Components/cs43l22.h
Normal file
228
Core/Src/Components/cs43l22.h
Normal file
@@ -0,0 +1,228 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cs43l22.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for the cs43l22.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CS43L22_H
|
||||
#define __CS43L22_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "AUDIO.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Component
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CS43L22
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
/*************************** Codec User defines ******************************/
|
||||
/******************************************************************************/
|
||||
/* Codec output DEVICE */
|
||||
#define OUTPUT_DEVICE_SPEAKER 1
|
||||
#define OUTPUT_DEVICE_HEADPHONE 2
|
||||
#define OUTPUT_DEVICE_BOTH 3
|
||||
#define OUTPUT_DEVICE_AUTO 4
|
||||
|
||||
/* Volume Levels values */
|
||||
#define DEFAULT_VOLMIN 0x00
|
||||
#define DEFAULT_VOLMAX 0xFF
|
||||
#define DEFAULT_VOLSTEP 0x04
|
||||
|
||||
#define AUDIO_PAUSE 0
|
||||
#define AUDIO_RESUME 1
|
||||
|
||||
/* Codec POWER DOWN modes */
|
||||
#define CODEC_PDWN_HW 1
|
||||
#define CODEC_PDWN_SW 2
|
||||
|
||||
/* MUTE commands */
|
||||
#define AUDIO_MUTE_ON 1
|
||||
#define AUDIO_MUTE_OFF 0
|
||||
|
||||
/* AUDIO FREQUENCY */
|
||||
#define AUDIO_FREQUENCY_192K ((uint32_t)192000)
|
||||
#define AUDIO_FREQUENCY_96K ((uint32_t)96000)
|
||||
#define AUDIO_FREQUENCY_48K ((uint32_t)48000)
|
||||
#define AUDIO_FREQUENCY_44K ((uint32_t)44100)
|
||||
#define AUDIO_FREQUENCY_32K ((uint32_t)32000)
|
||||
#define AUDIO_FREQUENCY_22K ((uint32_t)22050)
|
||||
#define AUDIO_FREQUENCY_16K ((uint32_t)16000)
|
||||
#define AUDIO_FREQUENCY_11K ((uint32_t)11025)
|
||||
#define AUDIO_FREQUENCY_8K ((uint32_t)8000)
|
||||
|
||||
/** CS43l22 Registers ***/
|
||||
#define CS43L22_REG_ID 0x01
|
||||
#define CS43L22_REG_POWER_CTL1 0x02
|
||||
#define CS43L22_REG_POWER_CTL2 0x04
|
||||
#define CS43L22_REG_CLOCKING_CTL 0x05
|
||||
#define CS43L22_REG_INTERFACE_CTL1 0x06
|
||||
#define CS43L22_REG_INTERFACE_CTL2 0x07
|
||||
#define CS43L22_REG_PASSTHR_A_SELECT 0x08
|
||||
#define CS43L22_REG_PASSTHR_B_SELECT 0x09
|
||||
#define CS43L22_REG_ANALOG_ZC_SR_SETT 0x0A
|
||||
#define CS43L22_REG_PASSTHR_GANG_CTL 0x0C
|
||||
#define CS43L22_REG_PLAYBACK_CTL1 0x0D
|
||||
#define CS43L22_REG_MISC_CTL 0x0E
|
||||
#define CS43L22_REG_PLAYBACK_CTL2 0x0F
|
||||
#define CS43L22_REG_PASSTHR_A_VOL 0x14
|
||||
#define CS43L22_REG_PASSTHR_B_VOL 0x15
|
||||
#define CS43L22_REG_PCMA_VOL 0x1A
|
||||
#define CS43L22_REG_PCMB_VOL 0x1B
|
||||
#define CS43L22_REG_BEEP_FREQ_ON_TIME 0x1C
|
||||
#define CS43L22_REG_BEEP_VOL_OFF_TIME 0x1D
|
||||
#define CS43L22_REG_BEEP_TONE_CFG 0x1E
|
||||
#define CS43L22_REG_TONE_CTL 0x1F
|
||||
#define CS43L22_REG_MASTER_A_VOL 0x20
|
||||
#define CS43L22_REG_MASTER_B_VOL 0x21
|
||||
#define CS43L22_REG_HEADPHONE_A_VOL 0x22
|
||||
#define CS43L22_REG_HEADPHONE_B_VOL 0x23
|
||||
#define CS43L22_REG_SPEAKER_A_VOL 0x24
|
||||
#define CS43L22_REG_SPEAKER_B_VOL 0x25
|
||||
#define CS43L22_REG_CH_MIXER_SWAP 0x26
|
||||
#define CS43L22_REG_LIMIT_CTL1 0x27
|
||||
#define CS43L22_REG_LIMIT_CTL2 0x28
|
||||
#define CS43L22_REG_LIMIT_ATTACK_RATE 0x29
|
||||
#define CS43L22_REG_OVF_CLK_STATUS 0x2E
|
||||
#define CS43L22_REG_BATT_COMPENSATION 0x2F
|
||||
#define CS43L22_REG_VP_BATTERY_LEVEL 0x30
|
||||
#define CS43L22_REG_SPEAKER_STATUS 0x31
|
||||
#define CS43L22_REG_TEMPMONITOR_CTL 0x32
|
||||
#define CS43L22_REG_THERMAL_FOLDBACK 0x33
|
||||
#define CS43L22_REG_CHARGE_PUMP_FREQ 0x34
|
||||
|
||||
/******************************************************************************/
|
||||
/****************************** REGISTER MAPPING ******************************/
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief CS43L22 ID
|
||||
*/
|
||||
#define CS43L22_ID 0xE0
|
||||
#define CS43L22_ID_MASK 0xF8
|
||||
/**
|
||||
* @brief Chip ID Register: Chip I.D. and Revision Register
|
||||
* Read only register
|
||||
* Default value: 0x01
|
||||
* [7:3] CHIPID[4:0]: I.D. code for the CS43L22.
|
||||
* Default value: 11100b
|
||||
* [2:0] REVID[2:0]: CS43L22 revision level.
|
||||
* Default value:
|
||||
* 000 - Rev A0
|
||||
* 001 - Rev A1
|
||||
* 010 - Rev B0
|
||||
* 011 - Rev B1
|
||||
*/
|
||||
#define CS43L22_CHIPID_ADDR 0x01
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS43L22_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
Audio Codec functions
|
||||
------------------------------------------------------------------------------*/
|
||||
/* High Layer codec functions */
|
||||
uint32_t cs43l22_Init(uint16_t DeviceAddr, uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
|
||||
void cs43l22_DeInit(void);
|
||||
uint32_t cs43l22_ReadID(uint16_t DeviceAddr);
|
||||
uint32_t cs43l22_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size);
|
||||
uint32_t cs43l22_Pause(uint16_t DeviceAddr);
|
||||
uint32_t cs43l22_Resume(uint16_t DeviceAddr);
|
||||
uint32_t cs43l22_Stop(uint16_t DeviceAddr, uint32_t Cmd);
|
||||
uint32_t cs43l22_SetVolume(uint16_t DeviceAddr, uint8_t Volume);
|
||||
uint32_t cs43l22_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq);
|
||||
uint32_t cs43l22_SetMute(uint16_t DeviceAddr, uint32_t Cmd);
|
||||
uint32_t cs43l22_SetOutputMode(uint16_t DeviceAddr, uint8_t Output);
|
||||
uint32_t cs43l22_Reset(uint16_t DeviceAddr);
|
||||
|
||||
/* AUDIO IO functions */
|
||||
void AUDIO_IO_Init(void);
|
||||
void AUDIO_IO_DeInit(void);
|
||||
void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
|
||||
|
||||
/* Audio driver structure */
|
||||
|
||||
//extern AUDIO_DrvTypeDef cs43l22_drv;
|
||||
|
||||
#endif /* __CS43L22_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -24,6 +24,7 @@
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "Components/Start.hpp"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -45,6 +46,7 @@
|
||||
|
||||
I2S_HandleTypeDef hi2s2;
|
||||
I2S_HandleTypeDef hi2s3;
|
||||
DMA_HandleTypeDef hdma_spi3_tx;
|
||||
|
||||
SD_HandleTypeDef hsd;
|
||||
|
||||
@@ -63,6 +65,7 @@ static void MX_I2S2_Init(void);
|
||||
static void MX_I2S3_Init(void);
|
||||
static void MX_SPI1_Init(void);
|
||||
static void MX_SDIO_SD_Init(void);
|
||||
static void MX_DMA_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
@@ -108,8 +111,9 @@ int main(void)
|
||||
MX_I2S3_Init();
|
||||
MX_SPI1_Init();
|
||||
MX_SDIO_SD_Init();
|
||||
MX_FATFS_Init();
|
||||
MX_DMA_Init();
|
||||
MX_USB_DEVICE_Init();
|
||||
MX_FATFS_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
Start();
|
||||
/* USER CODE END 2 */
|
||||
@@ -142,11 +146,12 @@ void SystemClock_Config(void)
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||
RCC_OscInitStruct.PLL.PLLN = 192;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 8;
|
||||
@@ -161,7 +166,7 @@ void SystemClock_Config(void)
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
|
||||
@@ -182,7 +187,7 @@ void PeriphCommonClock_Config(void)
|
||||
*/
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S;
|
||||
PeriphClkInitStruct.PLLI2S.PLLI2SN = 200;
|
||||
PeriphClkInitStruct.PLLI2S.PLLI2SM = 5;
|
||||
PeriphClkInitStruct.PLLI2S.PLLI2SM = 10;
|
||||
PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||
{
|
||||
@@ -358,6 +363,22 @@ static void MX_SPI1_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void)
|
||||
{
|
||||
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Stream5_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
extern DMA_HandleTypeDef hdma_spi3_tx;
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
@@ -225,6 +226,28 @@ void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)
|
||||
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* I2S3 DMA Init */
|
||||
/* SPI3_TX Init */
|
||||
hdma_spi3_tx.Instance = DMA1_Stream5;
|
||||
hdma_spi3_tx.Init.Channel = DMA_CHANNEL_0;
|
||||
hdma_spi3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_spi3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_spi3_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_spi3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||||
hdma_spi3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
|
||||
hdma_spi3_tx.Init.Mode = DMA_CIRCULAR;
|
||||
hdma_spi3_tx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
hdma_spi3_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
||||
hdma_spi3_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||||
hdma_spi3_tx.Init.MemBurst = DMA_MBURST_SINGLE;
|
||||
hdma_spi3_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
|
||||
if (HAL_DMA_Init(&hdma_spi3_tx) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(hi2s,hdmatx,hdma_spi3_tx);
|
||||
|
||||
/* USER CODE BEGIN SPI3_MspInit 1 */
|
||||
|
||||
/* USER CODE END SPI3_MspInit 1 */
|
||||
@@ -280,6 +303,8 @@ void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
|
||||
|
||||
HAL_GPIO_DeInit(GPIOC, I2S3_MCK_Pin|I2S3_SCK_Pin|I2S3_SD_Pin);
|
||||
|
||||
/* I2S3 DMA DeInit */
|
||||
HAL_DMA_DeInit(hi2s->hdmatx);
|
||||
/* USER CODE BEGIN SPI3_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END SPI3_MspDeInit 1 */
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||
extern DMA_HandleTypeDef hdma_spi3_tx;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
@@ -198,6 +199,20 @@ void SysTick_Handler(void)
|
||||
/* please refer to the startup file (startup_stm32f4xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 stream5 global interrupt.
|
||||
*/
|
||||
void DMA1_Stream5_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Stream5_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Stream5_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_spi3_tx);
|
||||
/* USER CODE BEGIN DMA1_Stream5_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Stream5_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USB On The Go FS global interrupt.
|
||||
*/
|
||||
|
||||
80
F411-DMA-Audio Debug.launch
Normal file
80
F411-DMA-Audio Debug.launch
Normal file
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="com.st.stm32cube.ide.mcu.debug.launch.launchConfigurationType">
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.access_port_id" value="0"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="false"/>
|
||||
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{"fItems":[{"fIsFromMainTab":true,"fPath":"Debug/F411-DMA-Audio.elf","fProjectName":"F411-DMA-Audio","fPerformBuild":true,"fDownload":true,"fLoadSymbols":true}]}"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.remoteCommand" value="target remote"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startServer" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.divby0" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.unaligned" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.haltonexception" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swd_mode" value="true"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_port" value="61235"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_hclk" value="16000000"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.useRemoteTarget" value="true"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.vector_table" value=""/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.verify_flash_download" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_allow_halt" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_signal_halt" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_external_loader" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_logging" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_max_halt_delay" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_shared_stlink" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader" value=""/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader_init" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.frequency" value="0"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.halt_all_on_reset" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.log_file" value="C:\Users\Gabriel\OneDrive\Documentos\TrabalhosPessoais\Playgrounds\F411-DMA-Audio\Debug\st-link_gdbserver_log.txt"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="enable"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="connect_under_reset"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{"fVersion":1,"fItems":[{"fDisplayName":"Reset","fIsSuppressible":false,"fResetAttribute":"Software system reset","fResetStrategies":[{"fDisplayName":"Software system reset","fLaunchAttribute":"system_reset","fGdbCommands":["monitor reset\r\n"],"fCmdOptions":["-g"]},{"fDisplayName":"Hardware reset","fLaunchAttribute":"hardware_reset","fGdbCommands":["monitor reset hardware\r\n"],"fCmdOptions":["-g"]},{"fDisplayName":"Core reset","fLaunchAttribute":"core_reset","fGdbCommands":["monitor reset core\r\n"],"fCmdOptions":["-g"]},{"fDisplayName":"None","fLaunchAttribute":"no_reset","fGdbCommands":[],"fCmdOptions":["-g"]}],"fGdbCommandGroup":{"name":"Additional commands","commands":[]},"fStartApplication":true}]}"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.enableRtosProxy" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyCustomProperties" value=""/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriver" value="threadx"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverAuto" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverPort" value="cortex_m0"/>
|
||||
<intAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyPort" value="60000"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="false"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId" value="com.st.stm32cube.ide.mcu.debug.stlink"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
|
||||
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="61234"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="true"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
|
||||
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
|
||||
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/F411-DMA-Audio.elf"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="F411-DMA-Audio"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.986831023"/>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/F411-DMA-Audio"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="4"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><memoryBlockExpressionList context="reserved-for-future-use"/>"/>
|
||||
<stringAttribute key="process_factory_id" value="com.st.stm32cube.ide.mcu.debug.launch.HardwareDebugProcessFactory"/>
|
||||
</launchConfiguration>
|
||||
@@ -1,4 +1,19 @@
|
||||
#MicroXplorer Configuration settings - do not modify
|
||||
Dma.Request0=SPI3_TX
|
||||
Dma.RequestsNb=1
|
||||
Dma.SPI3_TX.0.Direction=DMA_MEMORY_TO_PERIPH
|
||||
Dma.SPI3_TX.0.FIFOMode=DMA_FIFOMODE_ENABLE
|
||||
Dma.SPI3_TX.0.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL
|
||||
Dma.SPI3_TX.0.Instance=DMA1_Stream5
|
||||
Dma.SPI3_TX.0.MemBurst=DMA_MBURST_SINGLE
|
||||
Dma.SPI3_TX.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
|
||||
Dma.SPI3_TX.0.MemInc=DMA_MINC_ENABLE
|
||||
Dma.SPI3_TX.0.Mode=DMA_CIRCULAR
|
||||
Dma.SPI3_TX.0.PeriphBurst=DMA_PBURST_SINGLE
|
||||
Dma.SPI3_TX.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
|
||||
Dma.SPI3_TX.0.PeriphInc=DMA_PINC_DISABLE
|
||||
Dma.SPI3_TX.0.Priority=DMA_PRIORITY_LOW
|
||||
Dma.SPI3_TX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst
|
||||
FATFS.BSP.number=1
|
||||
FATFS0.BSP.STBoard=false
|
||||
FATFS0.BSP.api=Unknown
|
||||
@@ -30,18 +45,19 @@ I2S3.VirtualMode=I2S_MODE_MASTER
|
||||
KeepUserPlacement=false
|
||||
Mcu.CPN=STM32F411VET6
|
||||
Mcu.Family=STM32F4
|
||||
Mcu.IP0=FATFS
|
||||
Mcu.IP1=I2C1
|
||||
Mcu.IP10=USB_OTG_FS
|
||||
Mcu.IP2=I2S2
|
||||
Mcu.IP3=I2S3
|
||||
Mcu.IP4=NVIC
|
||||
Mcu.IP5=RCC
|
||||
Mcu.IP6=SDIO
|
||||
Mcu.IP7=SPI1
|
||||
Mcu.IP8=SYS
|
||||
Mcu.IP9=USB_DEVICE
|
||||
Mcu.IPNb=11
|
||||
Mcu.IP0=DMA
|
||||
Mcu.IP1=FATFS
|
||||
Mcu.IP10=USB_DEVICE
|
||||
Mcu.IP11=USB_OTG_FS
|
||||
Mcu.IP2=I2C1
|
||||
Mcu.IP3=I2S2
|
||||
Mcu.IP4=I2S3
|
||||
Mcu.IP5=NVIC
|
||||
Mcu.IP6=RCC
|
||||
Mcu.IP7=SDIO
|
||||
Mcu.IP8=SPI1
|
||||
Mcu.IP9=SYS
|
||||
Mcu.IPNb=12
|
||||
Mcu.Name=STM32F411V(C-E)Tx
|
||||
Mcu.Package=LQFP100
|
||||
Mcu.Pin0=PE2
|
||||
@@ -93,6 +109,7 @@ Mcu.UserName=STM32F411VETx
|
||||
MxCube.Version=6.5.0
|
||||
MxDb.Version=DB.6.0.50
|
||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true
|
||||
NVIC.DMA1_Stream5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true
|
||||
NVIC.ForceEnableDMAVector=true
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true
|
||||
@@ -214,12 +231,10 @@ PC12.Signal=I2S3_SD
|
||||
PC14-OSC32_IN.GPIOParameters=GPIO_Label
|
||||
PC14-OSC32_IN.GPIO_Label=PC14-OSC32_IN
|
||||
PC14-OSC32_IN.Locked=true
|
||||
PC14-OSC32_IN.Mode=LSE-External-Oscillator
|
||||
PC14-OSC32_IN.Signal=RCC_OSC32_IN
|
||||
PC15-OSC32_OUT.GPIOParameters=GPIO_Label
|
||||
PC15-OSC32_OUT.GPIO_Label=PC15-OSC32_OUT
|
||||
PC15-OSC32_OUT.Locked=true
|
||||
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
|
||||
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
|
||||
PC2.Mode=Full_Duplex_Master
|
||||
PC2.Signal=I2S2_ext_SD
|
||||
@@ -294,12 +309,10 @@ PE5.Signal=GPXTI5
|
||||
PH0\ -\ OSC_IN.GPIOParameters=GPIO_Label
|
||||
PH0\ -\ OSC_IN.GPIO_Label=PH0-OSC_IN
|
||||
PH0\ -\ OSC_IN.Locked=true
|
||||
PH0\ -\ OSC_IN.Mode=HSE-External-Clock-Source
|
||||
PH0\ -\ OSC_IN.Signal=RCC_OSC_IN
|
||||
PH1\ -\ OSC_OUT.GPIOParameters=GPIO_Label
|
||||
PH1\ -\ OSC_OUT.GPIO_Label=PH1-OSC_OUT
|
||||
PH1\ -\ OSC_OUT.Locked=true
|
||||
PH1\ -\ OSC_OUT.Mode=HSE-External-Clock-Source
|
||||
PH1\ -\ OSC_OUT.Signal=RCC_OSC_OUT
|
||||
PinOutPanel.RotationAngle=0
|
||||
ProjectManager.AskForMigrate=true
|
||||
@@ -329,12 +342,12 @@ ProjectManager.StackSize=0x400
|
||||
ProjectManager.TargetToolchain=STM32CubeIDE
|
||||
ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UnderRoot=true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_I2C1_Init-I2C1-false-HAL-true,4-MX_I2S2_Init-I2S2-false-HAL-true,5-MX_I2S3_Init-I2S3-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_USB_HOST_Init-USB_HOST-false-HAL-false
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_I2C1_Init-I2C1-false-HAL-true,4-MX_I2S2_Init-I2S2-false-HAL-true,5-MX_I2S3_Init-I2S3-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_SDIO_SD_Init-SDIO-false-HAL-true,8-MX_DMA_Init-DMA-false-HAL-true,9-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,10-MX_FATFS_Init-FATFS-false-HAL-false
|
||||
RCC.48MHZClocksFreq_Value=48000000
|
||||
RCC.AHBFreq_Value=96000000
|
||||
RCC.APB1CLKDivider=RCC_HCLK_DIV4
|
||||
RCC.APB1Freq_Value=24000000
|
||||
RCC.APB1TimFreq_Value=48000000
|
||||
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
||||
RCC.APB1Freq_Value=48000000
|
||||
RCC.APB1TimFreq_Value=96000000
|
||||
RCC.APB2Freq_Value=96000000
|
||||
RCC.APB2TimFreq_Value=96000000
|
||||
RCC.CortexFreq_Value=96000000
|
||||
@@ -345,16 +358,17 @@ RCC.HCLKFreq_Value=96000000
|
||||
RCC.HSE_VALUE=8000000
|
||||
RCC.HSI_VALUE=16000000
|
||||
RCC.I2SClocksFreq_Value=160000000
|
||||
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SM,PLLI2SN,PLLM,PLLP,PLLQ,PLLQCLKFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOInputMFreq_Value,VCOOutputFreq_Value,VcooutputI2S
|
||||
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SM,PLLI2SN,PLLM,PLLP,PLLQ,PLLQCLKFreq_Value,PLLSourceVirtualString,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOInputMFreq_Value,VCOOutputFreq_Value,VcooutputI2S
|
||||
RCC.LSI_VALUE=32000
|
||||
RCC.MCO2PinFreq_Value=96000000
|
||||
RCC.PLLCLKFreq_Value=96000000
|
||||
RCC.PLLI2SM=5
|
||||
RCC.PLLI2SM=10
|
||||
RCC.PLLI2SN=200
|
||||
RCC.PLLM=4
|
||||
RCC.PLLM=8
|
||||
RCC.PLLP=RCC_PLLP_DIV4
|
||||
RCC.PLLQ=8
|
||||
RCC.PLLQCLKFreq_Value=48000000
|
||||
RCC.PLLSourceVirtualString=RCC_PLLSOURCE_HSI
|
||||
RCC.RTCFreq_Value=32000
|
||||
RCC.RTCHSEDivFreq_Value=4000000
|
||||
RCC.SYSCLKFreq_VALUE=96000000
|
||||
|
||||
Reference in New Issue
Block a user