Created
October 22, 2019 20:45
-
-
Save d-boz-wtwh/d38bf0b0171ce8035271637d4d6636c7 to your computer and use it in GitHub Desktop.
Microcontroller Projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 */ | |
while (1) | |
{ | |
/* USER CODE END WHILE */ | |
GPIOB->ODR = 0x0001; //Write to port-b | |
HAL_Delay(1000); | |
GPIOB->ODR = 0x0002; //Write to port-b | |
HAL_Delay(1000); | |
GPIOB->ODR = 0x0003; //Write to port-b | |
HAL_Delay(1000); | |
GPIOB->ODR = 0x0000; //Write to port-b | |
HAL_Delay(1000); | |
}//End While Loop | |
/* USER CODE END 3 */ | |
} | |
/** System Clock Configuration | |
*/ | |
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(); | |
} | |
/**Configure the Systick interrupt time | |
*/ | |
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_GPIOB_CLK_ENABLE(); | |
/*Configure GPIO pin Output Level */ | |
HAL_GPIO_WritePin(GPIOB, Pin1_Pin|Pin2_Pin, GPIO_PIN_RESET); | |
/*Configure GPIO pins : Pin1_Pin Pin2_Pin */ | |
GPIO_InitStruct.Pin = Pin1_Pin|Pin2_Pin; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | |
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
} | |
void Error_Handler(void) | |
{ | |
/* USER CODE BEGIN Error_Handler */ | |
/* User can add his own implementation to report the HAL error return state */ | |
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