Skip to content

Instantly share code, notes, and snippets.

@d-boz-wtwh
Created October 22, 2019 20:46
Show Gist options
  • Save d-boz-wtwh/d611697b93ef77d1c74bdb33036d38fb to your computer and use it in GitHub Desktop.
Save d-boz-wtwh/d611697b93ef77d1c74bdb33036d38fb to your computer and use it in GitHub Desktop.
Microcontroller Projects
/********************************************************************************
Property off: www.microcontroller-project.com
Written by : Usman Ali Butt
Date : 21-June-2018
******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_hal.h"
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
int main(void)
{
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
GPIOA->ODR = 0x0001;
HAL_Delay(250); //Quater second delay
GPIOA->ODR = 0x0003;
HAL_Delay(250); //Quater second delay
GPIOA->ODR = 0x0007;
HAL_Delay(250); //Quater second delay
GPIOA->ODR = 0x000F;
HAL_Delay(250); //Quater second delay
GPIOA->ODR = 0x001F;
HAL_Delay(250); //Quater second delay
GPIOA->ODR = 0x003F;
HAL_Delay(250); //Quater second delay
GPIOA->ODR = 0x007F;
HAL_Delay(250); //Quater second delay
GPIOA->ODR = 0x00FF;
HAL_Delay(1000); //1 second delay
GPIOA->ODR = 0x0000; //Reset all Leds
}
/* USER CODE END 3 */
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
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();
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, PA0_Pin|PA1_Pin|PA2_Pin|PA3_Pin
|PA4_Pin|PA5_Pin|PA6_Pin|PA7_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : PA0_Pin PA1_Pin PA2_Pin PA3_Pin
PA4_Pin PA5_Pin PA6_Pin PA7_Pin */
GPIO_InitStruct.Pin = PA0_Pin|PA1_Pin|PA2_Pin|PA3_Pin
|PA4_Pin|PA5_Pin|PA6_Pin|PA7_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void Error_Handler(void)
{
while(1)
{
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment