cancel
Showing results for 
Search instead for 
Did you mean: 

IAR Simulator

Cesar cfg
Associate II
Posted on December 28, 2016 at 13:41

Hello,

I have made a code that initialize a timer of an STM32F0 to tick every 1 ms and generate an update interrupt , and i want to test if my code work correctly

My questions:

1- The IAR startup file should be Added to my project ?

2- what is the right config to be done to simulate my code ?  

2- The interrupt simulation should be enabled ?

Thank you

#iar-simulator
5 REPLIES 5
Posted on December 28, 2016 at 16:18

Does the IAR simulator support the chip in question?

You should build the code as if it is going to run on real hardware, so yes a statup file with a vector table, and calls to SystemInit() and cstartup as appropriate.

You'd need to enable the interrupt at the source, and in the NVIC.

Using a TIM or SysTick ?

Real debuggable hardware runs about $10, I know Keil has practically abandoned support for simulation

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on December 28, 2016 at 16:43

Thank you for your reply

I am using STM32F051 , how can i verify that the simulator support it ?

I use a Timer to generate an interrupt every 1 ms

Is it necessary to enable 

interrupt simulation to test if the interrupt occure in the exact time ( after 1ms)

0690X00000605x7QAA.png
Posted on December 28, 2016 at 17:02

I typically use Keil, not IAR. You could review the documentation, or speak to IAR Support staff.

I'd expect you need to check that box, and the one for TIM3, and also write code as you would on real hardware, otherwise there seems little point in having a 'simulator'. The simulator needs to reflect exactly what real hardware would do.

What would work on real hardware

// STM32 TIM3 1KHz (1ms) Update STM32F0-Discovery - sourcer32@gmail.com
#include 'stm32f0_discovery.h'
//**************************************************************************************
void TIM3_Config(void)
{
 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 /* TIM3 Periph clock enable */
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
 /* TIM3 Configuration */
 TIM_DeInit(TIM3);
 /* Time base configuration */
 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
 TIM_TimeBaseStructure.TIM_Prescaler = 0;
 TIM_TimeBaseStructure.TIM_Period = (SystemCoreClock / 1000) - 1; // 1 KHz, from 48 MHz
 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 /* TIM1 enable counter */
 TIM_Cmd(TIM3, ENABLE);
 /* Enable the Update Interrupt Request */
 TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
}
//**************************************************************************************
void TIM3_IRQHandler(void)
{
 if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
 {
 /* Clear TIM3_UPDATE interrupt pending bit */
 TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
 // ..
 }
}
//**************************************************************************************
void NVIC_Config(void)
{
 NVIC_InitTypeDef NVIC_InitStructure;
 /* Enable and set TIM3 Interrupt */
 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
}
//**************************************************************************************
int main(void)
{
 NVIC_Config();
 TIM3_Config();
 while(1); /* Infinite loop */
}
//**************************************************************************************
#ifdef USE_FULL_ASSERT
/**
 * @brief Reports the name of the source file and the source line number
 * where the assert_param error has occurred.
 * @param file: pointer to the source file name
 * @param line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t* file, uint32_t line)
{
 /* User can add his own implementation to report the file name and line number,
 ex: printf('Wrong parameters value: file %s on line %d

', file, line) */
 /* Infinite loop */
 while (1)
 {
 }
}
#endif
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on December 28, 2016 at 21:02

I have exactly the same code.

what I did not understand , if i check the box to enable interrupt simulation of the Timer it looks that the timer initialization have no effect ( because with it and without it the interrupt works correctly)

If i uncheck the box the interrupt don't work

Posted on December 28, 2016 at 21:31

I'm sure IAR has some supporting documentation for the simulator, I'm not here to argue its function or usability, I'm sure it is not a gate-level / clock accurate model.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..