#include <stm32f1xx_hal.h>
// Set STM32F103 LED RED (PC13)
#define LED_PORT GPIOC
#define RED_LED GPIO_PIN_14
#define YELLOW_LED GPIO_PIN_15
#define GREEN_LED GPIO_PIN_13
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_13
#define LED_PIN_2 GPIO_PIN_14
#define LED_PIN_3 GPIO_PIN_15
//#define LED_PORT_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE
void Error_Handler(void);
void SystemClock_Config(void);
void initGPIO()
{ GPIO_InitTypeDef GPIO_Config;
GPIO_Config.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_Config.Pull = GPIO_NOPULL;
GPIO_Config.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_Config.Pin = RED_LED | YELLOW_LED | GREEN_LED;
//LED_PORT_CLK_ENABLE();
HAL_GPIO_Init(LED_PORT, &GPIO_Config);
__HAL_RCC_GPIOC_CLK_ENABLE();
}
void delay(uint32_t ttt) {
while (--ttt);
}
int main(void)
{
HAL_Init();
SystemClock_Config();
initGPIO();
while (1){
HAL_GPIO_WritePin (LED_PORT,RED_LED,GPIO_PIN_SET);
HAL_GPIO_WritePin (LED_PORT,YELLOW_LED,GPIO_PIN_RESET);
HAL_GPIO_WritePin (LED_PORT,GREEN_LED,GPIO_PIN_SET);
// 1kHz ticks
// HAL_SYSTICK_Config(SystemCoreClock / 1000);
HAL_Delay(200);
// delay(2000000000);
HAL_GPIO_WritePin (LED_PORT,RED_LED,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_PORT, GREEN_LED, GPIO_PIN_RESET);
HAL_Delay(200);
// delay(2000000000);
}
/*
//HAL_GPIO_WritePin(LED_PORT, RED_LED, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED | GREEN_LED, GPIO_PIN_RESET);
delay(3000);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED, GPIO_PIN_SET);
delay(1500);
HAL_GPIO_WritePin(LED_PORT, RED_LED | YELLOW_LED, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_PORT, GREEN_LED, GPIO_PIN_SET);
delay(3000);
HAL_GPIO_WritePin(LED_PORT, GREEN_LED, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED, GPIO_PIN_SET);
delay(500);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED, GPIO_PIN_RESET);
delay(500);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED, GPIO_PIN_SET);
delay(500);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED, GPIO_PIN_RESET);
delay(500);
HAL_GPIO_WritePin(LED_PORT, YELLOW_LED, GPIO_PIN_SET);
delay(500);
}*/
}
// @brief System Clock Configuration
// @retval None
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/* Initializes the CPU, AHB and APB busses clocks */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/* Initializes the CPU, AHB and APB busses clocks */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) Error_Handler();
}
void Error_Handler(void)
{ /* User can add his own implementation to report the HAL error return state */ }
#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,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) /
}
#endif /* USE_FULL_ASSERT */
void SysTick_Handler(void)
{
HAL_IncTick();
}