project of ftm_periodic_interrupt in SDK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

project of ftm_periodic_interrupt in SDK

1,077 Views
jtpark
Contributor IV

Greetings,

I tested  the ftm_periodic_interrupt s/w in S32DS for AMM 2018.R1.

I met the abnormal function as below.

When I monitored the variable value of count, count is set the "1" due to ovf_timer interrupt.

However I using the count in main loop, it was not working in main loop.

(it was not able to do the toggle function.)

I loaded the S/W in "S32DS Project from Example".

(S32K14x EAR SDK v0.8.6 Example Projects/ timer/ ftm_periodic_interrupt_s32k142)

Which problem it is?

ftm_periodic_interrupt_sw.png

/*
* Copyright (c) 2015 - 2016 , Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED 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 NXP OR ITS 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.
*/


/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "clockMan1.h"
#include "pin_mux.h"
#include "flexTimer_mc1.h"
#if CPU_INIT_CONFIG
#include "Init_Config.h"
#endif

volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */

#include <stdint.h>
#include <stdbool.h>

/* This example is setup to work by default with EVB. To use it with other boards
please comment the following line
*/

#define EVB

#ifdef EVB
#define LED_PIN 15U /* LED pin on PTD15 for the EVB Board */
#define LED_GPIO PTD
#else
#define LED_PIN 0U /* LED pin PTC0 */
#define LED_GPIO PTC
#endif

/* Flex Timer Instance interrupt service routine
* - this will toggle LED 1 and clear the timer overflow flag of the FTM
* instance
*/
unsigned char count_flag = 0 ;
void ftmTimerISR(void)
{
/* Static variable for storing the timer overflow count */
static uint8_t s_overflowCount = 0U;
/*
* Since the FTM timer is configured to raise an IRQ every 100 ms,
* the number of overflows for 1s is 10
*/
if(s_overflowCount < 10U)
{
/* If the overflow count is below 10, increment it */
s_overflowCount++;
}
else
{
/* If the overflow count is 10, toggle the LED and reset the variable */
/* Toggle LED */
// PINS_DRV_TogglePins(LED_GPIO, 1 << LED_PIN);
s_overflowCount = 0U;
count_flag = 1 ;
}
/* Clear FTM Timer Overflow flag */
FTM_DRV_ClearStatusFlags(INST_FLEXTIMER_MC1, (uint32_t)FTM_TIME_OVER_FLOW_FLAG);
}

/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - __start (startup asm routine)
* - __init_hardware()
* - main()
* - PE_low_level_init()
* - Common_Init()
* - Peripherals_Init()
*/
void delay(unsigned int i)
{
while(i--);
}
int main(void)
{
/* Write your local variable definition here */
ftm_state_t ftmStateStruct;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */

/* Initialize and configure clocks
* - see clock manager component for details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

/* Initialize pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

/* Initialize GPIO
* - set direction (out)
* - set initial value
*/
PINS_DRV_SetPinsDirection(LED_GPIO, (1 << LED_PIN));
PINS_DRV_SetPins(LED_GPIO, (1 << LED_PIN));

/* Initialize Flex Timer instance as simple timer */
FTM_DRV_Init(INST_FLEXTIMER_MC1, &flexTimer_mc1_InitConfig, &ftmStateStruct);

/* Install handler for the Timer overflow interrupt and enable it */
INT_SYS_InstallHandler(FTM0_Ovf_Reload_IRQn, &ftmTimerISR, (isr_t*) 0);
INT_SYS_EnableIRQ(FTM0_Ovf_Reload_IRQn);

/* Setup the counter to trigger an interrupt every 100 ms */
FTM_DRV_InitCounter(INST_FLEXTIMER_MC1, &flexTimer_mc1_TimerConfig);
/* Start the counter */
FTM_DRV_CounterStart(INST_FLEXTIMER_MC1);

/* Unless an IRQ has been raised, do nothing */
while(1){
if(count_flag){
count_flag = 0 ;
PINS_DRV_TogglePins(LED_GPIO, 1 << LED_PIN);
}
}

/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.1 [05.21]
** for the Freescale S32K series of microcontrollers.
**
** ###################################################################
*/

Labels (1)
Tags (1)
0 Kudos
3 Replies

1,067 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi jtpark,

Please select None(-O0) for Optimization Level.

Optimization Level.png

Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,065 Views
jtpark
Contributor IV

Dear Robin,

 

Thank you for kind answer.

I changed the optimization to "none" but it was not working.

Did you set the break point at the "count_flag =0" ?


Thanks.

 

 

0 Kudos

1,058 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Break point at count_flag will stop the debug. You can see the count_flag=1.
I directly copied the entire main.c to the ftm_periodic_interrupt_s32k142 project and test it on S32K142EVB.

breakpoint count_flag.png

0 Kudos