From: AceVest Date: Sat, 1 Jun 2019 07:15:14 +0000 (+0800) Subject: F103HAL gpio output open drain mode X-Git-Url: http://zhaoyanbai.com/repos/jquery-3.1.1.min.js?a=commitdiff_plain;h=175f14d8d96be06b781de94c8cfb55c5abab6f47;p=acecode.git F103HAL gpio output open drain mode --- diff --git a/learn/stm32/F103HAL/F103HAL.elf.launch b/learn/stm32/F103HAL/F103HAL.elf.launch index 925476b..27e5676 100644 --- a/learn/stm32/F103HAL/F103HAL.elf.launch +++ b/learn/stm32/F103HAL/F103HAL.elf.launch @@ -65,5 +65,6 @@ + diff --git a/learn/stm32/F103HAL/Src/System.c b/learn/stm32/F103HAL/Src/System.c new file mode 100644 index 0000000..3abf807 --- /dev/null +++ b/learn/stm32/F103HAL/Src/System.c @@ -0,0 +1,32 @@ +/* + * System.c + * + * Created on: Jun 1, 2019 + * Author: ace + */ + + +#include "stm32f1xx_hal.h" + +void SystemPreInit() { + __HAL_RCC_GPIOB_CLK_ENABLE(); +} + + +#define LED_Pin GPIO_PIN_6 +#define LED_GPIO_Port GPIOB + +void SystemSetup() { + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pin = LED_Pin; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + + HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct); +} + +void SystemLoop() { + HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); + HAL_Delay(1000); +} diff --git a/learn/stm32/F103HAL/Src/main.c b/learn/stm32/F103HAL/Src/main.c index d211515..e6d0a59 100644 --- a/learn/stm32/F103HAL/Src/main.c +++ b/learn/stm32/F103HAL/Src/main.c @@ -56,7 +56,9 @@ void SystemClock_Config(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ - +void SystemPreInit(); +void SystemSetup(); +void SystemLoop(); /* USER CODE END 0 */ /** @@ -83,19 +85,20 @@ int main(void) SystemClock_Config(); /* USER CODE BEGIN SysInit */ - + SystemPreInit(); /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ - + SystemSetup(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { + SystemLoop(); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */