1 /* 2 * Copyright (c) 2006-2023, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2022-08-23 liYony first version 9 */ 10 11 #include "board.h" 12 #include <stdint.h> 13 #include "drv_usart.h" 14 #include "drv_gpio.h" 15 #include <rthw.h> 16 #include <rtthread.h> 17 18 extern uint32_t SystemCoreClock; 19 _SysTick_Config(rt_uint32_t ticks)20static uint32_t _SysTick_Config(rt_uint32_t ticks) 21 { 22 NVIC_SetPriority(SysTicK_IRQn,0xf0); 23 NVIC_SetPriority(Software_IRQn,0xf0); 24 NVIC_EnableIRQ(SysTicK_IRQn); 25 NVIC_EnableIRQ(Software_IRQn); 26 SysTick->CTLR=0; 27 SysTick->SR=0; 28 SysTick->CNT=0; 29 SysTick->CMP=ticks-1; 30 SysTick->CTLR=0xF; 31 return 0; 32 } 33 34 #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 35 #define RT_HEAP_SIZE (1024*10) 36 static uint32_t rt_heap[RT_HEAP_SIZE]; rt_heap_begin_get(void)37rt_weak void *rt_heap_begin_get(void) 38 { 39 return rt_heap; 40 } 41 rt_heap_end_get(void)42rt_weak void *rt_heap_end_get(void) 43 { 44 return rt_heap + RT_HEAP_SIZE; 45 } 46 #endif 47 48 /** 49 * This function will initial your board. 50 */ rt_hw_board_init()51void rt_hw_board_init() 52 { 53 /* System Tick Configuration */ 54 _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); 55 56 #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 57 rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); 58 #endif 59 /* USART driver initialization is open by default */ 60 #ifdef RT_USING_SERIAL 61 rt_hw_usart_init(); 62 #endif 63 #ifdef RT_USING_CONSOLE 64 rt_console_set_device(RT_CONSOLE_DEVICE_NAME); 65 #endif 66 #ifdef RT_USING_PIN 67 /* pin must initialized before i2c */ 68 rt_hw_pin_init(); 69 #endif 70 /* Call components board initial (use INIT_BOARD_EXPORT()) */ 71 #ifdef RT_USING_COMPONENTS_INIT 72 rt_components_board_init(); 73 #endif 74 75 } 76 77 void SysTick_Handler(void) __attribute__((interrupt())); SysTick_Handler(void)78void SysTick_Handler(void) 79 { 80 GET_INT_SP(); 81 /* enter interrupt */ 82 rt_interrupt_enter(); 83 SysTick->SR=0; 84 rt_tick_increase(); 85 /* leave interrupt */ 86 rt_interrupt_leave(); 87 FREE_INT_SP(); 88 89 } 90