| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

MFT_Mode_1a_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : MFT_Mode_1a_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the MFT Mode 1a 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
160 /* Includes ------------------------------------------------------------------*/
161 #include "BlueNRG1.h"
162 #include "BlueNRG1_conf.h"
163 #include "SDK_EVAL_Config.h"
164
165
178 /* Private typedef -----------------------------------------------------------*/
179 /* Private define ------------------------------------------------------------*/
180 #define PWM1_PIN GPIO_Pin_3
181
182 /* Private macro -------------------------------------------------------------*/
183 /* Private variables ---------------------------------------------------------*/
184 /* Private function prototypes -----------------------------------------------*/
185 void GPIO_Configuration(void);
186 void MFT_Configuration(void);
187
188 /* Private functions ---------------------------------------------------------*/
189
190
196 int main(void)
197 {
198 /* System initialization function */
199 SystemInit();
200
201 /* Identify BlueNRG1 platform */
202 SdkEvalIdentification();
203
204 /* LEDs initialization */
205 SdkEvalLedInit(LED1);
206
207 /* GPIO configuration */
208 GPIO_Configuration();
209
210 /* MFT configuration */
211 MFT_Configuration();
212
213 /* Connect PWM output from timer to TnA pin */
214 MFT_TnXEN(MFT2, MFT_TnA, ENABLE);
215
216 /* Select software trigger for pulse-train generation */
217 MFT_PulseTrainTriggerSelect(MFT2, MFT_SOFTWARE_TRIGGER);
218
219 /* Enable MFT2 interrupt A and B */
220 MFT_EnableIT(MFT2, MFT_IT_TNA | MFT_IT_TNB, ENABLE);
221
222 /* Software delay before start the timer pulses */
223 for(volatile uint32_t i=0;i<0x2FFFF;i++);
224
225 /* Start MFT2 timer */
226 MFT_Cmd(MFT2, ENABLE);
227
228 /* Trigger pulse-train generation */
229 MFT_PulseTrainSoftwareTrigger(MFT2);
230
231 /* Infinite loop */
232 while(1);
233 }
234
235
241 void GPIO_Configuration(void)
242 {
243 GPIO_InitType GPIO_InitStructure;
244
245 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO, ENABLE);
246
248 GPIO_InitStructure.GPIO_Pin = PWM1_PIN;
249 GPIO_InitStructure.GPIO_Mode = Serial1_Mode;
250 GPIO_InitStructure.GPIO_Pull = DISABLE;
251 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
252 GPIO_Init( &GPIO_InitStructure);
253
254 }
255
261 void MFT_Configuration()
262 {
263 NVIC_InitType NVIC_InitStructure;
264 MFT_InitType timer_init;
265
266 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_MTFX2, ENABLE);
267
268 /* MFT2 configuration */
269 timer_init.MFT_Mode = MFT_MODE_1a;
270 timer_init.MFT_Prescaler = 160-1; /* 10 us clock */
271
272 timer_init.MFT_Clock1 = MFT_PRESCALED_CLK;
273 timer_init.MFT_Clock2 = MFT_PRESCALED_CLK;
274 timer_init.MFT_CRA = 50000 - 1; /* 500 ms positive duration */
275 timer_init.MFT_CRB = 25000 - 1; /* 250 ms negative duration */
276 MFT_Init(MFT2, &timer_init);
277
278 /* Set the number of cycles */
279 MFT_SetCounter(MFT2, 0, 30-1); /* 30 pulse */
280
281 /* Enable MFT Interrupt */
282 NVIC_InitStructure.NVIC_IRQChannel = MFT2A_IRQn;
283 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LOW_PRIORITY;
284 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
285 NVIC_Init(&NVIC_InitStructure);
286 }
287
288 #ifdef USE_FULL_ASSERT
289
296 void assert_failed(uint8_t* file, uint32_t line)
297 {
298 /* User can add his own implementation to report the file name and line number,
299 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
300
301 /* Infinite loop */
302 while (1)
303 {
304 }
305 }
306
307 #endif
308
321 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
main
int main(void)
Main program code.
Definition: MFT_Mode_1a_main.c:196
GPIO_Configuration
void GPIO_Configuration(void)
GPIO Configuration.
Definition: MFT_Mode_1a_main.c:241
MFT_Configuration
void MFT_Configuration(void)
MFT_Configuration.
Definition: MFT_Mode_1a_main.c:261
PWM1_PIN
#define PWM1_PIN
Definition: MFT_Mode_1a_main.c:180