| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

MFT_Mode_1_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : MFT_Mode_1_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the MFT Mode 1 functionality
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
156 /* Includes ------------------------------------------------------------------*/
157 #include "BlueNRG1.h"
158 #include "BlueNRG1_conf.h"
159 #include "SDK_EVAL_Config.h"
160
174 /* Private typedef -----------------------------------------------------------*/
175 /* Private define ------------------------------------------------------------*/
176 #define PWM0_PIN GPIO_Pin_2
177 #define PWM1_PIN GPIO_Pin_3
178
179 /* Private macro -------------------------------------------------------------*/
180 /* Private variables ---------------------------------------------------------*/
181 /* Private function prototypes -----------------------------------------------*/
182 void GPIO_Configuration(void);
183 void MFT_Configuration(void);
184
185 /* Private functions ---------------------------------------------------------*/
186
187
193 int main(void)
194 {
195 /* System initialization function */
196 SystemInit();
197
198 /* Identify BlueNRG1 platform */
199 SdkEvalIdentification();
200
201 /* LEDs initialization */
202 SdkEvalLedInit(LED1);
203 SdkEvalLedInit(LED2);
204
205 /* GPIO configuration */
206 GPIO_Configuration();
207
208 /* MFT configuration */
209 MFT_Configuration();
210
211 /* Connect PWM output from timers to TnA pins */
212 MFT_TnXEN(MFT1, MFT_TnA, ENABLE);
213 MFT_TnXEN(MFT2, MFT_TnA, ENABLE);
214
216 MFT_EnableIT(MFT1, MFT_IT_TNA | MFT_IT_TNB, ENABLE);
217 MFT_EnableIT(MFT2, MFT_IT_TNA | MFT_IT_TNB, ENABLE);
218
219 /* Start MFT timers */
220 MFT_Cmd(MFT1, ENABLE);
221 MFT_Cmd(MFT2, ENABLE);
222
223 /* Infinite loop */
224 while(1);
225 }
226
227
234 void GPIO_Configuration(void)
235 {
236 GPIO_InitType GPIO_InitStructure;
237
238 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO, ENABLE);
239
240 /* Configure PWM pins */
241 GPIO_InitStructure.GPIO_Pin = PWM0_PIN | PWM1_PIN;
242 GPIO_InitStructure.GPIO_Mode = Serial1_Mode;
243 GPIO_InitStructure.GPIO_Pull = DISABLE;
244 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
245 GPIO_Init( &GPIO_InitStructure);
246
247 }
248
254 void MFT_Configuration(void)
255 {
256 NVIC_InitType NVIC_InitStructure;
257 MFT_InitType timer_init;
258
259 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_MTFX1 | CLOCK_PERIPH_MTFX2, ENABLE);
260
261 MFT_StructInit(&timer_init);
262
263 timer_init.MFT_Mode = MFT_MODE_1;
264 timer_init.MFT_Prescaler = 160-1; /* 10 us clock */
265
266 /* MFT1 configuration */
267 timer_init.MFT_Clock1 = MFT_PRESCALED_CLK;
268 timer_init.MFT_Clock2 = MFT_NO_CLK;
269 timer_init.MFT_CRA = 25000 - 1; /* 250 ms positive duration */
270 timer_init.MFT_CRB = 50000 - 1; /* 500 ms negative duration */
271 MFT_Init(MFT1, &timer_init);
272
273 /* MFT2 configuration */
274 timer_init.MFT_Clock1 = MFT_PRESCALED_CLK;
275 timer_init.MFT_Clock2 = MFT_NO_CLK;
276 timer_init.MFT_CRA = 5000 - 1; /* 50 ms positive duration */
277 timer_init.MFT_CRB = 10000 - 1; /* 100 ms negative duration */
278 MFT_Init(MFT2, &timer_init);
279
280 /* Enable MFT2 Interrupt 1 */
281 NVIC_InitStructure.NVIC_IRQChannel = MFT1A_IRQn;
282 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LOW_PRIORITY;
283 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
284 NVIC_Init(&NVIC_InitStructure);
285
286 /* Enable MFT2 Interrupt 2 */
287 NVIC_InitStructure.NVIC_IRQChannel = MFT2A_IRQn;
288 NVIC_Init(&NVIC_InitStructure);
289 }
290
291 #ifdef USE_FULL_ASSERT
292
299 void assert_failed(uint8_t* file, uint32_t line)
300 {
301 /* User can add his own implementation to report the file name and line number,
302 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
303
304 /* Infinite loop */
305 while (1)
306 {
307 }
308 }
309
310 #endif
311
323 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
PWM0_PIN
#define PWM0_PIN
Definition: MFT_Mode_1_main.c:176
main
int main(void)
Main program code.
Definition: MFT_Mode_1_main.c:193
PWM1_PIN
#define PWM1_PIN
Definition: MFT_Mode_1_main.c:177
GPIO_Configuration
void GPIO_Configuration(void)
GPIO Configuration. Configure outputs GPIO pins.
Definition: MFT_Mode_1_main.c:234
MFT_Configuration
void MFT_Configuration(void)
MFT_Configuration.
Definition: MFT_Mode_1_main.c:254