Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE
Fork of X_NUCLEO_CCA02M1 by
Diff: BSP/divisor.c
- Revision:
- 0:d5552d432108
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP/divisor.c Tue Feb 28 11:20:53 2017 +0100
@@ -0,0 +1,144 @@
+/**
+ ******************************************************************************
+ * @file divisor.c
+ * @author AST / Software Platforms and Cloud
+ * @version V1.0
+ * @date November 8th, 2016
+ * @brief Utilities header file for the X_NUCLEO_CCA02M1 expansion board.
+ ******************************************************************************
+ * @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 "cmsis.h"
+#include "divisor.h"
+#include "component.h"
+
+
+/* Variables -----------------------------------------------------------------*/
+
+static TIM_HandleTypeDef TimDividerHandle;
+static TIM_SlaveConfigTypeDef sSlaveConfig;
+static TIM_IC_InitTypeDef sICConfig;
+static TIM_OC_InitTypeDef sOCConfig;
+
+
+/* Functions -----------------------------------------------------------------*/
+
+/**
+ * @brief Initializing audio timer.
+ * @param None.
+ * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+ */
+Status_t AUDIO_IN_Timer_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ /* Enable AUDIO_TIMER clock*/
+ AUDIO_IN_TIMER_CLK_ENABLE();
+ AUDIO_IN_TIMER_CHOUT_GPIO_PORT_CLK_ENABLE();
+ AUDIO_IN_TIMER_CHIN_GPIO_PORT_CLK_ENABLE();
+
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+
+ GPIO_InitStruct.Alternate = AUDIO_IN_TIMER_CHIN_AF;
+ GPIO_InitStruct.Pin = AUDIO_IN_TIMER_CHIN_PIN;
+ HAL_GPIO_Init(AUDIO_IN_TIMER_CHIN_GPIO_PORT, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Alternate = AUDIO_IN_TIMER_CHOUT_AF;
+ GPIO_InitStruct.Pin = AUDIO_IN_TIMER_CHOUT_PIN;
+ HAL_GPIO_Init(AUDIO_IN_TIMER_CHOUT_GPIO_PORT, &GPIO_InitStruct);
+
+ TimDividerHandle.Instance = AUDIO_IN_TIMER;
+
+ /* Configure the Input: channel_1 */
+ sICConfig.ICPolarity = TIM_ICPOLARITY_RISING;
+ sICConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
+ sICConfig.ICPrescaler = TIM_ICPSC_DIV1;
+ sICConfig.ICFilter = 0;
+ if (HAL_TIM_IC_ConfigChannel(&TimDividerHandle, &sICConfig, TIM_CHANNEL_1) != HAL_OK)
+ {
+ return COMPONENT_ERROR;
+ }
+
+ /* Configure TIM1 in Gated Slave mode for the external trigger (Filtered Timer
+ Input 1) */
+ sSlaveConfig.InputTrigger = TIM_TS_TI1FP1;
+ sSlaveConfig.SlaveMode = TIM_SLAVEMODE_EXTERNAL1;
+ if (HAL_TIM_SlaveConfigSynchronization(&TimDividerHandle, &sSlaveConfig) != HAL_OK)
+ {
+ return COMPONENT_ERROR;
+ }
+
+ /* Initialize TIM3 peripheral in PWM mode*/
+ TimDividerHandle.Init.Period = 1;
+ TimDividerHandle.Init.Prescaler = 0;
+ TimDividerHandle.Init.ClockDivision = 0;
+ TimDividerHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
+ TimDividerHandle.Init.RepetitionCounter = 0;
+ if (HAL_TIM_PWM_Init(&TimDividerHandle) != HAL_OK)
+ {
+ return COMPONENT_ERROR;
+ }
+
+ /* Configure the PWM_channel_1 */
+ sOCConfig.OCMode = TIM_OCMODE_PWM1;
+ sOCConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
+ sOCConfig.Pulse = 1;
+ if (HAL_TIM_PWM_ConfigChannel(&TimDividerHandle, &sOCConfig, TIM_CHANNEL_2) != HAL_OK)
+ {
+ return COMPONENT_ERROR;
+ }
+
+ return COMPONENT_OK;
+}
+
+/**
+* @brief Audio Timer Start
+* @param None
+* @retval None
+*/
+uint8_t AUDIO_IN_Timer_Start()
+{
+ if (HAL_TIM_IC_Start(&TimDividerHandle, TIM_CHANNEL_1) != HAL_OK)
+ {
+ return COMPONENT_ERROR;
+ }
+ /* Start the Output Compare */
+ if (HAL_TIM_OC_Start(&TimDividerHandle, TIM_CHANNEL_2) != HAL_OK)
+ {
+ return COMPONENT_ERROR;
+ }
+
+ return COMPONENT_OK;
+}
