2015-09-23 09:03 AM
Please help me. I am trying t go back to using the legacy standard peripheral library (no Cube) like I used to.
When I try to build a project, I follow the readme file and include the stm324xg_eval files in the project tree..When I do this I get a warning... #error ''Please select first the Evaluation board used in your application (in Project Options)''I don't know how to do this in Keil (anyone know), so as a workaround I did this... #define USE_STM324xG_EVALI then started to get different warnings ..\main.c(180): error: #20: identifier ''TIM3_IRQn'' is undefined NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;and so on (I am trying to build the TIM timbease example).I am using UV5.I would be most grateful if anyone could explain how to get this working smoothly.never been so defeated by Keil!2015-09-23 09:49 AM
USE_STDPERIPH_DRIVER,STM32F40_41xxx,USE_STM324xG_EVAL
Get the STM32F4xx_DSP_StdPeriph_Lib_V1.5.1 Make sure the include paths are correctly configured, and the stm32f4xx_conf.h file is in your project directory. See STM32F4xx_DSP_StdPeriph_Lib_V1.5.1\Project\STM32F4xx_StdPeriph_Templates2015-09-23 12:31 PM
I couldn't make it work, but i found an old f2 library on a flash drive and got that to work.
Anyway, the std FW library doesn't have an example of using the TIM as a timebase to call a function. If we look at the following std fw lib code: /* Compute the prescaler value */ PrescalerValue = (uint32_t) ((SystemCoreClock / 2) / 100000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 10000 - 1;; TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);Is there any way to modify this to start an interrupt that calls a function please? I'm stuck for it, because i need this for my design concept to work, yet if i switch to cube to get it, i find i can't seem to merge examples successfully. If I could overcome the above the rest would be easy on old libs...2015-09-23 01:52 PM
Quick blind port
// STM32 4 Hz STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // LED
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_ResetBits(GPIOD, GPIO_Pin_12);
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
GPIOD->ODR ^= GPIO_Pin_12; // Toggle
}
}
/**************************************************************************************/
void TIM3_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
uint16_t Period, Prescaler;
Prescaler = 10000;
Period = ((SystemCoreClock / (2 * Prescaler)) / 4); // Period for 4 Hz frequency
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = Prescaler - 1;
TIM_TimeBaseStructure.TIM_Period = Period - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
TIM3_Configuration();
while(1); // Don't want to exit
}
/**************************************************************************************/
#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
/**************************************************************************************/
2015-09-24 08:22 AM
Thanks, much appreciated.
Could I also please ask your opinion on this unexpected dynamic behaviour....I am trying to combine this timer-called function with the smartcard example - because the smartcard is going to be an extra level of copy protection in our product.Anyway, I have set up the smartcard example just to get the ''answer to reset'' or A2R of the card and go no further.Now, when I combine the timer code with that, I find that the A2R is no longer read successfully. However, it will work if I wait until after the read from the smartcard before enabling the timer/interrupts. So I suppose my first question is why? Beyond this, it gets more strange. I broke out timer and interrupt activation into their own TIM3_Enable() and TIM3_Disbale() functions.I figured that I could enable the timer, and then disable the timer when a card is in inserted, expecting the A2R to work as normal unaffected by the timer problem (since disabled), and then restart the timer. Yet even with the following code, no A2R is received...but why?/*-------------------------------- Idle task ---------------------------------*/ while(1) { /* Loop while no Smartcard is detected */ while(CardInserted == 0) { } TIM3_Disable(); Delay(400); /* Start SC Demo ---------------------------------------------------------*/ /* Wait A2R --------------------------------------------------------------*/ SCState = SC_POWER_ON; //Set up struct to ask for A2R SC_ADPU.Header.CLA = 0x00; SC_ADPU.Header.INS = SC_GET_A2R; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x00; while(SCState != SC_ACTIVE_ON_T0) { SC_Handler(&SCState, &SC_ADPU, &SC_Responce); } TIM3_Enable();while(1){ //Stoping the smartcard example just after A2R phase
}void TIM3_Enable(void){TIM_Cmd(TIM3, ENABLE); TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);}void TIM3_Disable(void){ TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);TIM_Cmd(TIM3, DISABLE); }2015-09-24 09:07 AM
I have discovered that when I call Tim3_Enable() in my main function, no lines after that point in my main function get executed. Anyone know why? I am using the same timer specs as in the example clive posted above.