2014-02-21 05:16 AM
2014-02-21 05:27 AM
Hi,
First, please answer the following questions: 1- What do you want to do? 2- What are you expecting from this program? 3- How do you know that your program ''works'' or doesn't? 4- What do you mean by ''Why timers are used?''. If you want a global idea about STM32 timers, have a look to thehttp://www.st.com/web/en/resource/technical/document/application_note/DM00042534.pdf
. -Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2014-02-21 06:02 AM
Hi Mayla
1- I would like to configure the TIM7, I din't know but i would like to configure TIM to generate 1 ms then to execute an interruption which toggle LED on PC9, after that the prog(main.c) will toggle both PC9 and PC8 depending on the main c. (Really i can't understand the purpose of the program :p it's a home-work and really i can't deal with it so could u help me dealing with it).cordially Laroussi Salah.2014-02-21 06:37 AM
But remember kids who can do their own homework are more employable.
/* Includes ------------------------------------------------------------------*/
#include ''stm32f10x.h''
#include ''stm32f10x_rcc.h''
#include ''stm32f10x_gpio.h''
#include ''stm32f10x_tim.h''
/* Private function prototypes -----------------------------------------------*/
void Delay(__IO uint32_t nCount);
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
// The discovery board is rated at 24 MHz, not 36 MHz
// skipping the pin/clock disable stuff, it will break the debugger
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
/* Initialize Leds LD3 and LD4 mounted on STM32VLDISCOVERY board */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure Timer 7 interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* COnfigure Timer to generate 1ms */
TIM_TimeBaseStructure.TIM_Period = 1000 - 1;// 1 MHz down to 1 KHz (1 ms)
TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 1000000)-1; // System Clock down to 1 MHz
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
/* Configure Timer 7*/
TIM_TimeBaseInit(TIM7, &TIM_TimeBaseStructure);
/* TIM7 IT enable */
TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);
/* TIM7 enable counter */
TIM_Cmd(TIM7, ENABLE);
// Toggle PC8 with software delay loop, for whatever reason
while (1)
{
GPIO_SetBits(GPIOC,GPIO_Pin_8);
/* Insert delay */
Delay(0x0FFFF);
GPIO_ResetBits(GPIOC,GPIO_Pin_8);
/* Insert delay */
Delay(0x0FFFF);
}
}
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
#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
void TIM7_IRQHandler(void) // Called 1ms (1 KHz), Toggle at 500 Hz (need a scope)
{
static int state = 0;
// Interrupts should be brief, do your stuff and LEAVE
if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET) // Qualify the source
{
TIM_ClearITPendingBit(TIM7, TIM_IT_Update); // Clear the source
/* Toggle LED3 */
state ^= 1;
if (state)
GPIO_SetBits(GPIOC,GPIO_Pin_9);
else
GPIO_ResetBits(GPIOC,GPIO_Pin_9);
}
}
2014-02-21 06:46 AM
Thanks a lot :D :p ;)
2014-04-24 02:35 AM
hi
i use above code for a simple project on IAR compiler, but i receive this fault error when debugging(JTAG):NMI_Handler (BusFault_Handler)
on this line: TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE); --- I see this error always config interrupt for peripherals. what is worse? THX.2014-04-24 04:49 AM
Are you using C++ mode?
Do you have the right startup_stm32f4xx.s? Is the vector table entry linking to your IRQ Handler?2014-04-24 09:53 PM
yes, i am using C++ mode,
default vector table is: 0x08000000. from post,change vector table: 0x08000000 to 0x08003000 but see same fault. also my MCU is : STM32F103RET6 i add this line to your code at first: SystemInit (); that is: void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= (uint32_t)0x00000001; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #ifndef STM32F10X_CL RCC->CFGR &= (uint32_t)0xF8FF0000; #else RCC->CFGR &= (uint32_t)0xF0FF0000; #endif /* STM32F10X_CL */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= (uint32_t)0xFEF6FFFF; /* Reset HSEBYP bit */ RCC->CR &= (uint32_t)0xFFFBFFFF; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= (uint32_t)0xFF80FFFF; #ifdef STM32F10X_CL /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= (uint32_t)0xEBFFFFFF; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000; #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000; #endif /* STM32F10X_CL */ #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */ /* Configure the Flash Latency cycles and enable prefetch buffer */ SetSysClock(); #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } THX.2014-04-25 10:05 AM
I have no idea what the relevance of using SystemInit(), or having a base address of 0x08003000? [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32f100%20how%20start%20TIM1%20interrupt%20handler&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=6065]Cite threads properly
So you're using C++, have you checked the .MAP file to see if the compiler is mangling the function name, and broken the linkage of the vector table to your IRQ Handler?extern ''C'' void TIM7_IRQHandler(void) // C Linkage for Vector Table
{
// ..
}
2014-04-25 09:54 PM