#include "main.h" #include "py32f0xx_bsp_led.h" #include "py32f0xx_bsp_printf.h" static void APP_SystemClockConfig(void); static void APP_GPIOConfig(void); int main(void) { APP_SystemClockConfig(); APP_GPIOConfig(); BSP_USART_Config(115200); LL_RCC_ConfigMCO(LL_RCC_MCO1SOURCE_SYSCLK, LL_RCC_MCO1_DIV_1); printf("Clock: %ld \r\n", SystemCoreClock); while (1) { LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_5); printf("echo\r\n"); LL_mDelay(1000); } } static void APP_SystemClockConfig(void) { LL_RCC_HSE_Enable(); LL_RCC_HSE_SetFreqRegion(LL_RCC_HSE_16_32MHz); while(LL_RCC_HSE_IsReady() != 1); LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSE); LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); /* Update global SystemCoreClock(or through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(HSE_VALUE); /* Re-init frequency of SysTick source */ LL_InitTick(HSE_VALUE, 1000U); } static void APP_GPIOConfig(void) { LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA); LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB); LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT); /* PA08: MCO output */ // Add USE_FULL_LL_DRIVER to LIB_FLAGS to enable LL_GPIO_InitTypeDef LL_GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = LL_GPIO_PIN_8; GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; /* Alternate mode */ GPIO_InitStruct.Alternate = LL_GPIO_AF5_MCO; GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; /* No pull */ GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOA, &GPIO_InitStruct); } void APP_ErrorHandler(void) { while (1); } #ifdef USE_FULL_ASSERT void assert_failed(uint8_t *file, uint32_t line) { while (1); } #endif /* USE_FULL_ASSERT */