mirror of
				https://github.com/IcedRooibos/py32f0-template.git
				synced 2025-10-31 09:52:05 -07:00 
			
		
		
		
	
		
			
				
	
	
		
			76 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #include "main.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_mDelay(1000);
 | |
|     LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_5);
 | |
|     printf("echo\r\n");
 | |
|   }
 | |
| }
 | |
| 
 | |
| static void APP_SystemClockConfig(void)
 | |
| {
 | |
|   LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct;
 | |
| 
 | |
|   LL_RCC_HSI_Enable();
 | |
|   /* Change this value to adjust frequency */
 | |
|   LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz + 15);
 | |
|   while (LL_RCC_HSI_IsReady() != 1);
 | |
| 
 | |
|   UTILS_ClkInitStruct.AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
 | |
|   UTILS_ClkInitStruct.APB1CLKDivider = LL_RCC_APB1_DIV_1;
 | |
|   LL_PLL_ConfigSystemClock_HSI(&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 */
 | 
