2014-06-08 11:46 AM
Hi, i'm trying to make a led toggle every second with SysTick but it's not working. The toggle occurs every 3 secs more or less. I also tried to do it with timers but i can't get the frequency right. However in the SysTick example provided in ''STM32Cube_FW_F4_V1.1.0'' the Led's toggle when they have to. I'm clearly having problems when i tried to develope all the code by myself but i can't see the source of error. I think the problem is the clock source configuration but all seem fine to me. I hope someone can help me.
Heres the code:#include ''stm32f4xx.h''
#include ''stm32f4xx_conf.h''
RCC_ClocksTypeDef RCC_ClockFreq;
static
void
LED(
void
);
static
void
Delay(uint16_t);
uint16_t delay=0;
uint16_t count=0;
uint8_t source=0;
void
SysTick_Handler(
void
)
{
count++;
}
int
main(
void
){
LED();
source=RCC_GetSYSCLKSource ();
RCC_GetClocksFreq(&RCC_ClockFreq);
SysTick_Config(SystemCoreClock/1000);
SysTick_CLKSourceConfig (SysTick_CLKSource_HCLK);
GPIO_ToggleBits(GPIOG,GPIO_Pin_14);
while
(1){
GPIO_ToggleBits(GPIOG,GPIO_Pin_13);
Delay(1000);
}
}
/******************************************************************************/
void
LED(
void
){
GPIO_InitTypeDef GPIO_InitStructure;
// LED Port Info
// Enable the port clock
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOG, ENABLE);
// Prepare the port info
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14;
// Line 12
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
// As Output
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
// Push-pull
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
// At 100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
// Without pull-up-down
// Initialize the port
GPIO_Init (GPIOG, &GPIO_InitStructure);
}
/******************************************************************************/
void
Delay(uint16_t delay){
count=0;
while
(count<delay){}
}
SYSCLK = 180MHz = HCLK.
I'm using Keil uVision 5.
Thanks
#frequency #stm32f429i #solved #systick #!psychic
2014-06-08 12:14 PM
I have no particular interest working with the HAL/CUBE libraries.
Generally you'd want to confirm internal clocking using the MCO (PA8) pin to route out clocks and measure them on a scope. Clock settings are entirely ratios of some other clock, the part has no specific knowledge of those clocks. The DISCO series boards typically use an 8 MHz external source (not a crystal directly), and the EVAL series boards typically use an 25 MHz crystal. You must therefore be conscious of the setting of HSE_VALUE within your project, and the PLL settings typically expressed in system_stm32f4xx.c The ratio of 25:8 is 3.125:1 You may also use the 16 MHz HSI clock, which is fixed and known, but not stable enough for USB/CAN interfacing.2014-06-08 12:31 PM
Thanks for the answer.
I'm using the fuction RCC_GetClockFrequency to know HCLK which is theoretically the clock source of the SysTick. I understand i might have some error due to the source but i'm not getting anything near 1 second but 3 seconds. Sadly i can't measure the frequency since i don't have the equipment. I'll try different clock sources and see the result. here is the configuration of the clocks in my project:/**=============================================================================
* Supported STM32F42xxx/43xxx devices
*-----------------------------------------------------------------------------
* System Clock source | PLL (HSE)
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 180000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 180000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 4
*-----------------------------------------------------------------------------
* APB2 Prescaler | 2
*-----------------------------------------------------------------------------
* HSE Frequency(Hz) | 25000000
*-----------------------------------------------------------------------------
* PLL_M | 25
*-----------------------------------------------------------------------------
* PLL_N | 360
*-----------------------------------------------------------------------------
* PLL_P | 2
*-----------------------------------------------------------------------------
* PLL_Q | 7
*-----------------------------------------------------------------------------
* PLLI2S_N | NA
*-----------------------------------------------------------------------------
* PLLI2S_R | NA
*-----------------------------------------------------------------------------
* I2S input clock | NA
*-----------------------------------------------------------------------------
* VDD(V) | 3.3
*-----------------------------------------------------------------------------
* Main regulator output voltage | Scale1 mode
*-----------------------------------------------------------------------------
* Flash Latency(WS) | 5
*-----------------------------------------------------------------------------
* Prefetch Buffer | ON
*-----------------------------------------------------------------------------
* Instruction cache | ON
*-----------------------------------------------------------------------------
* Data cache | ON
*-----------------------------------------------------------------------------
* Require 48MHz for USB OTG FS, | Disabled
* SDIO and RNG clock |
*-----------------------------------------------------------------------------
*=============================================================================*/
________________
Attachments : system_stm32f4xx.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I09N&d=%2Fa%2F0X0000000bbx%2FYFZLbXOOHK4sCQDGxLgv4lVWokgfam.0sSz3T3LSy7E&asPdf=false
2014-06-08 12:38 PM
The GetClocks just provides a mathematical computation. 25 / 8 = 3.125
You failed to mention what board you are using, or provide a schematic if it is a custom one. If you have an STM32F429I-DISCO the external clocks source IS NOT 25MHZ, you will need to adjust HSE_VALUE and PLL_M to 8000000 and 8 respectively2014-06-08 01:06 PM
You were absolutely right. I thought that these files provided for uVision were configured for the board i'm using that is, as you said, the STM32F429I-DISCO. It was my fault i didn't realize that those files are configured for the microcontroller and not the board.
You also solve my problem with the timers.Thank you.