mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-28 08:22:06 -07:00
refactor: update gpio examples
This commit is contained in:
parent
c920de408e
commit
b9ee789f78
@ -21,8 +21,6 @@
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "py32f0xx_bsp_button.h"
|
||||
#include "py32f0xx_bsp_led.h"
|
||||
#include "py32f0xx_bsp_printf.h"
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
@ -33,11 +31,6 @@
|
||||
static void APP_LedConfig(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 应用程序入口函数.
|
||||
* @param 无
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
HAL_Init();
|
||||
@ -56,24 +49,21 @@ int main(void)
|
||||
|
||||
static void APP_LedConfig(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE(); /* GPIOB时钟使能 */
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /* 推挽输出 */
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP; /* 使能上拉 */
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; /* GPIO速度 */
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* GPIO初始化 */
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
|
||||
void APP_ErrorHandler(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
||||
@ -34,53 +34,31 @@
|
||||
static void APP_SystemClockConfig(void);
|
||||
static void APP_GpioConfig(void);
|
||||
|
||||
/**
|
||||
* @brief 应用程序入口函数.
|
||||
* @retval int
|
||||
*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* 配置系统时钟 */
|
||||
APP_SystemClockConfig();
|
||||
|
||||
/* 初始化GPIO */
|
||||
APP_GpioConfig();
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* LED灯闪烁 */
|
||||
LL_mDelay(500);
|
||||
LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 系统时钟配置函数
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void APP_SystemClockConfig(void)
|
||||
{
|
||||
/* 使能HSI */
|
||||
LL_RCC_HSI_Enable();
|
||||
while(LL_RCC_HSI_IsReady() != 1)
|
||||
{
|
||||
}
|
||||
while(LL_RCC_HSI_IsReady() != 1);
|
||||
|
||||
/* 设置 AHB 分频*/
|
||||
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
||||
|
||||
/* 配置HSISYS作为系统时钟源 */
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSISYS);
|
||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSISYS)
|
||||
{
|
||||
}
|
||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSISYS);
|
||||
|
||||
/* 设置 APB1 分频*/
|
||||
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
||||
LL_Init1msTick(8000000);
|
||||
|
||||
/* 更新系统时钟全局变量SystemCoreClock(也可以通过调用SystemCoreClockUpdate函数更新) */
|
||||
LL_SetSystemCoreClock(8000000);
|
||||
}
|
||||
|
||||
@ -91,41 +69,19 @@ static void APP_SystemClockConfig(void)
|
||||
*/
|
||||
static void APP_GpioConfig(void)
|
||||
{
|
||||
/* 使能时钟 */
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
|
||||
/* 将PA5引脚配置为输出 */
|
||||
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 错误执行函数
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
void APP_ErrorHandler(void)
|
||||
{
|
||||
/* 无限循环 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief 输出产生断言错误的源文件名及行号
|
||||
* @param file:源文件名指针
|
||||
* @param line:发生断言错误的行号
|
||||
* @retval 无
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* 用户可以根据需要添加自己的打印信息,
|
||||
例如: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* 无限循环 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
|
||||
20
User/main.c
20
User/main.c
@ -21,8 +21,6 @@
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "py32f0xx_bsp_button.h"
|
||||
#include "py32f0xx_bsp_led.h"
|
||||
#include "py32f0xx_bsp_printf.h"
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
@ -35,12 +33,6 @@ static void APP_LedConfig(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/*
|
||||
* Configure the Flash prefetch and the Instruction cache,
|
||||
* the time base source, NVIC and any required global low level hardware
|
||||
* by calling the HAL_MspInit() callback function to be optionally defined in user file
|
||||
* PY32F0xx_hal_msp.c.
|
||||
*/
|
||||
HAL_Init();
|
||||
|
||||
/* LED GPIO init */
|
||||
@ -58,16 +50,16 @@ int main(void)
|
||||
|
||||
static void APP_LedConfig(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE(); /* GPIOB时钟使能 */
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /* 推挽输出 */
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP; /* 使能上拉 */
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; /* GPIO速度 */
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* GPIO初始化 */
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void APP_ErrorHandler(void)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user