1 /* 2 * Copyright (c) 2006-2022, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2021-01-04 iysheng first version 9 * 2021-09-07 idk500 suit for Vango V85xx 10 * 2021-09-08 ZhuXW add delay function 11 */ 12 13 #include <stdint.h> 14 #include <rthw.h> 15 #include <rtthread.h> 16 17 #include <target.h> 18 #include <board.h> 19 #include <drv_usart.h> 20 21 /* 22 * System Clock Configuration 23 */ SystemClock_Config(void)24void SystemClock_Config(void) 25 { 26 // SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); 27 NVIC_SetPriority(SysTick_IRQn, 0); 28 CLK_InitTypeDef CLK_Struct; 29 30 CLK_Struct.ClockType = CLK_TYPE_AHBSRC \ 31 |CLK_TYPE_PLLL \ 32 |CLK_TYPE_HCLK \ 33 |CLK_TYPE_PCLK; 34 CLK_Struct.AHBSource = CLK_AHBSEL_LSPLL; 35 36 CLK_Struct.PLLL.Frequency = CLK_PLLL_26_2144MHz; 37 CLK_Struct.PLLL.Source = CLK_PLLLSRC_XTALL; 38 CLK_Struct.PLLL.State = CLK_PLLL_ON; 39 CLK_Struct.HCLK.Divider = 1; 40 CLK_Struct.PCLK.Divider = 2; 41 CLK_ClockConfig(&CLK_Struct); 42 } 43 44 /* 45 * This is the timer interrupt service routine. 46 */ SysTick_Handler(void)47void SysTick_Handler(void) 48 { 49 /* enter interrupt */ 50 rt_interrupt_enter(); 51 52 rt_tick_increase(); 53 54 /* leave interrupt */ 55 rt_interrupt_leave(); 56 } 57 58 /** 59 * This function will initial V85xx board. 60 */ rt_hw_board_init()61void rt_hw_board_init() 62 { 63 SystemClock_Config(); 64 65 #ifdef RT_USING_COMPONENTS_INIT 66 rt_components_board_init(); 67 #endif 68 69 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) 70 rt_console_set_device(RT_CONSOLE_DEVICE_NAME); 71 #endif 72 73 #ifdef BSP_USING_SDRAM 74 rt_system_heap_init((void *)EXT_SDRAM_BEGIN, (void *)EXT_SDRAM_END); 75 #else 76 rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); 77 #endif 78 } 79 rt_hw_us_delay(rt_uint32_t us)80void rt_hw_us_delay(rt_uint32_t us) 81 { 82 rt_uint32_t ticks; 83 rt_uint32_t told, tnow, tcnt = 0; 84 rt_uint32_t reload = SysTick->LOAD; 85 86 ticks = us * reload / (1000000 / RT_TICK_PER_SECOND); 87 told = SysTick->VAL; 88 while (1) 89 { 90 tnow = SysTick->VAL; 91 if (tnow != told) 92 { 93 if (tnow < told) 94 { 95 tcnt += told - tnow; 96 } 97 else 98 { 99 tcnt += reload - tnow + told; 100 } 101 told = tnow; 102 if (tcnt >= ticks) 103 { 104 break; 105 } 106 } 107 } 108 } 109 /*@}*/ 110