Trouble With the System Clock

Hello,

I'm new to embedded systems programming, with plenty of previous experience working with Programmable Logic Controllers and I'm trying to branch out. I recently acquired an STM32F407 discovery board and have been trying to work with it in an attempt to learn something about embedded system development.

I'm currently working to set up a simple blinking light program but I keep running into trouble setting up a delay timer, every time I run the program I get a Systick_Handler interrupt and with my limited knowledge base I'm having trouble pinpointing what is causing the problem and I've been knocking my head against this problem for a while. Admittedly a large chunk of my program was copied from other sources and scanned through it to at least try to understand that is happening.

Here is the current code of the project.
*********************************************************

#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4_discovery.h"
// New Libraries here

void ConfigureLEDpins(void);
static void SystemClock_Config(void);

int main(void)
{
HAL_Init();
SystemClock_Config();
ConfigureLEDpins();
SystemCoreClock = HAL_RCC_GetHCLKFreq();
SysTick_Config(SystemCoreClock / 100);
while(1)
{
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
HAL_Delay(1000);
}
}

void ConfigureLEDpins(void)
{
__HAL_RCC_GPIOD_CLK_ENABLE();
GPIO_InitTypeDef LEDConfigData;
LEDConfigData.Mode = GPIO_MODE_OUTPUT_PP;
LEDConfigData.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
HAL_GPIO_Init(GPIOD, &LEDConfigData);
}

void SystemClock_Config(void) // Copied from the Demostration program from STM
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;

/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();

/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

/* STM32F405x/407x/415x/417x Revision Z devices: prefetch is supported */
if (HAL_GetREVID() == 0x1001)
{
/* Enable the Flash prefetch */
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
}
}

*********************************************

I've read through a few online tutorials but I can't seem to find what I'm missing. Chances are as a beginner I am forgetting something likely basic but I can't figure out what's wrong with it.

Any help would be appreciated.

Parents Reply Children
No data
More questions in this forum