AnsweredAssumed Answered

Could anyone help me build my STM32F1 HAL project?

Question asked by yuzhou.huang on Sep 15, 2015
Latest reply on Sep 16, 2015 by Keaven
I have a minimum STM32F103ZET6 system board with. I have downloaded STM32CubeF1(Version 1.2.0) package. I build a simple project, which just blink a led, and I compile it with no error/warning. The main.c source code is shown below
#include"stm32f1xx_hal.h"
#include"stm32f1xx_hal_gpio.h"
#include"stm32f1xx_hal_rcc.h"
#include"stm32f1xx_hal_rcc_ex.h"
#include"stdint.h"
void m_delay(volatile uint32_t m_time){
  while(m_time > 0){
    m_time--;
  }
}


void SystemClock_Config(){
  RCC_ClkInitTypeDef Clk_InitStructure = {0};
  RCC_OscInitTypeDef Osc_InitStructure = {0};
  Osc_InitStructure.OscillatorType  = RCC_OSCILLATORTYPE_HSE; 
  Osc_InitStructure.HSEState        = RCC_HSE_ON; 
  Osc_InitStructure.HSEPredivValue    = RCC_HSE_PREDIV_DIV1; 
  Osc_InitStructure.PLL.PLLState    = RCC_PLL_ON; */
  Osc_InitStructure.PLL.PLLSource   = RCC_PLLSOURCE_HSE; 
  Osc_InitStructure.PLL.PLLMUL      = RCC_PLL_MUL9; 
  if (HAL_RCC_OscConfig(&Osc_InitStructure)!= HAL_OK)
  {
    /* Initialization Error */
    while(1); 
  }


  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 
     clocks dividers */
  Clk_InitStructure.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  Clk_InitStructure.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  Clk_InitStructure.AHBCLKDivider = RCC_SYSCLK_DIV1;
  Clk_InitStructure.APB2CLKDivider = RCC_HCLK_DIV1;
  Clk_InitStructure.APB1CLKDivider = RCC_HCLK_DIV2;  
  if (HAL_RCC_ClockConfig(&Clk_InitStructure, FLASH_LATENCY_2)!= HAL_OK)
  {
    /* Initialization Error */
    while(1); 
  }
}
int main(){
  HAL_Init();
  SystemClock_Config();
  __HAL_RCC_GPIOG_CLK_ENABLE();
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_InitStructure.Pin = GPIO_PIN_14;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull = GPIO_PULLUP;
  GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);


  while(1){
    HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, 1);
    HAL_Delay(500);
    HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, 0);
    HAL_Delay(500);
  }
  return 0;
}


But it didn't work well. The pin output HIGH and didn't change its value. It looks like the program block at  "HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, 1)". Even I change the HAL_Delay() to the function I write m_delay(), it also can be blocked.  So what wrong with my code?

Outcomes