Hello,
I’m trying to make a simple blinky program using a stm32f3 Discovery board, but for some reason HAL_GetTick();
will return always 0
while calling HAL_Delay(20);
My platformio.ini looks like this:
[env:disco_f303vc]
platform = ststm32
board = disco_f303vc
framework = stm32cube
board_build.f_cpu = 72000000L
build_flags = -Wl,-u_printf_float
-D HSE_VALUE=8000000UL
Code is here:
#include "stm32f3xx_hal.h"
static void SystemClock_Config(void);
#define LED_PIN12 GPIO_PIN_12
#define LED_PIN8 GPIO_PIN_8
#define LED_GPIO_PORT GPIOE
#define LED_GPIOE_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define LED_GPIOE_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
void LED_Init();
int main(void) {
HAL_Init();
LED_Init();
SystemClock_Config();
SystemCoreClockUpdate();
while (1)
{
/* USER CODE END WHILE */
HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN12);
HAL_Delay(20);
HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN8);
HAL_Delay(20);
}
}
void LED_Init() {
LED_GPIOE_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = LED_PIN8;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; //GPIO_SPEED_HIGH;
HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
HAL_GPIO_WritePin(LED_GPIO_PORT, LED_PIN8, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = LED_PIN12;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
HAL_GPIO_WritePin(LED_GPIO_PORT, LED_PIN12, GPIO_PIN_RESET);
}
void Error_Handler(void)
{
while(1)
{
}
}
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
Error_Handler();
}
/* Configures the USB clock */
// HAL_RCCEx_GetPeriphCLKConfig(&RCC_PeriphClkInit);
// RCC_PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
// HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit);
/* 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_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2)!= HAL_OK)
{
Error_Handler();
}
}
void SysTick_Handler(void) {
HAL_IncTick();
}