mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-29 00:42:06 -07:00
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
#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_UTILS_ClkInitTypeDef UTILS_ClkInitStruct;
|
|
|
|
LL_RCC_HSE_Enable();
|
|
LL_RCC_HSE_SetFreqRegion(LL_RCC_HSE_16_32MHz);
|
|
while(LL_RCC_HSE_IsReady() != 1);
|
|
|
|
UTILS_ClkInitStruct.AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
|
|
UTILS_ClkInitStruct.APB1CLKDivider = LL_RCC_APB1_DIV_1;
|
|
LL_PLL_ConfigSystemClock_HSE(24000000U, LL_UTILS_HSEBYPASS_OFF, &UTILS_ClkInitStruct);
|
|
|
|
/* Re-init frequency of SysTick source, reload = freq/ticks = 48000000/1000 = 48000 */
|
|
LL_InitTick(48000000, 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 */
|