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.
Fork of ST_FREQUENCY_DIVIDER by
Revision 0:f11903264b5e, committed 2017-04-21
- Comitter:
- davide.aliprandi@st.com
- Date:
- Fri Apr 21 10:22:24 2017 +0200
- Child:
- 1:d75cd2582664
- Commit message:
- Added files.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/FrequencyDivider.cpp Fri Apr 21 10:22:24 2017 +0200
@@ -0,0 +1,12 @@
+#include "drivers/FrequencyDivider.h"
+#include "stm_divider_api.h"
+
+FrequencyDivider::FrequencyDivider()
+{
+ ST_Timer_Init();
+}
+
+void FrequencyDivider::start(void)
+{
+ ST_Timer_Start();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/FrequencyDivider.h Fri Apr 21 10:22:24 2017 +0200
@@ -0,0 +1,28 @@
+#ifndef MBED_FREQUENCY_DIVIDER_H
+#define MBED_FREQUENCY_DIVIDER_H
+
+#include "platform/platform.h"
+#include "hal/stm_i2s_api.h"
+
+
+/** A frequency divider class.
+ *
+ * @Note Synchronization level: No Synchronization.
+ *
+ */
+class FrequencyDivider {
+
+public:
+
+ /**
+ * Creating a frequency divider.
+ */
+ FrequencyDivider();
+
+ /**
+ * Start dividing a frequency.
+ */
+ void start(void);
+};
+
+#endif // MBED_FREQUENCY_DIVIDER_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hal/stm_divider_api.h Fri Apr 21 10:22:24 2017 +0200
@@ -0,0 +1,75 @@
+/**
+ ******************************************************************************
+ * @file stm_divider_api.h
+ * @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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __DIVIDER_H
+#define __DIVIDER_H
+
+/* Includes ------------------------------------------------------------------*/
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Definitions ---------------------------------------------------------------*/
+
+#define AUDIO_IN_TIMER TIM3
+#define AUDIO_IN_TIMER_CLK_ENABLE() __TIM3_CLK_ENABLE()
+#define AUDIO_IN_TIMER_CHOUT_AF GPIO_AF2_TIM3
+#define AUDIO_IN_TIMER_CHOUT_PIN GPIO_PIN_5
+#define AUDIO_IN_TIMER_CHOUT_GPIO_PORT GPIOB
+#define AUDIO_IN_TIMER_CHOUT_GPIO_PORT_CLK_ENABLE() __GPIOB_CLK_ENABLE()
+#define AUDIO_IN_TIMER_CHIN_AF GPIO_AF2_TIM3
+#define AUDIO_IN_TIMER_CHIN_PIN GPIO_PIN_4
+#define AUDIO_IN_TIMER_CHIN_GPIO_PORT GPIOB
+#define AUDIO_IN_TIMER_CHIN_GPIO_PORT_CLK_ENABLE() __GPIOB_CLK_ENABLE()
+
+
+/* Functions -----------------------------------------------------------------*/
+
+uint8_t ST_Timer_Init(void);
+uint8_t ST_Timer_Start(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_lib.json Fri Apr 21 10:22:24 2017 +0200
@@ -0,0 +1,8 @@
+{
+ "name": "stm-frequency-divider",
+ "target_overrides": {
+ "NUCLEO_F401RE": {
+ "target.device_has_add": ["FREQUENCY_DIVIDER"]
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/stm_divider_api.c Fri Apr 21 10:22:24 2017 +0200
@@ -0,0 +1,144 @@
+/**
+ ******************************************************************************
+ * @file stm_divider_api.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 "stm_divider_api.h"
+#include "component_def.h"
+
+
+/* Variables -----------------------------------------------------------------*/
+
+static TIM_HandleTypeDef TimDividerHandle;
+static TIM_SlaveConfigTypeDef sSlaveConfig;
+static TIM_IC_InitTypeDef sICConfig;
+static TIM_OC_InitTypeDef sOCConfig;
+
+
+/* Functions -----------------------------------------------------------------*/
+
+/**
+ * @brief Initializing timer.
+ * @param None.
+ * @retval 0 in case of success, -1 otherwise.
+ */
+uint8_t ST_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 -1;
+ }
+
+ /* 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 -1;
+ }
+
+ /* 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 -1;
+ }
+
+ /* 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 -1;
+ }
+
+ return 0;
+}
+
+/**
+* @brief Starting timer.
+* @param None.
+* @retval 0 in case of success, -1 otherwise.
+*/
+uint8_t ST_Timer_Start(void)
+{
+ if (HAL_TIM_IC_Start(&TimDividerHandle, TIM_CHANNEL_1) != HAL_OK)
+ {
+ return -1;
+ }
+ /* Start the Output Compare */
+ if (HAL_TIM_OC_Start(&TimDividerHandle, TIM_CHANNEL_2) != HAL_OK)
+ {
+ return -1;
+ }
+
+ return 0;
+}
