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 * 2022-12-08 WangShun the first version 9 * 2022-12-13 WangShun put the rt_system_heap_init in head 10 */ 11 12 #include <stdint.h> 13 #include <rthw.h> 14 #include <rtthread.h> 15 #include "udma_uart_driver.h" 16 #include "hal_udma_ctrl_reg_defs.h" 17 #include "hal_udma_uart_reg_defs.h" 18 #include "core-v-mcu-config.h" 19 #include "drv_usart.h" 20 #include "string.h" 21 22 extern void rt_systick_config(void); 23 24 #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 25 #define RT_HEAP_SIZE (64*1024) 26 static rt_uint8_t rt_heap[RT_HEAP_SIZE]; rt_heap_begin_get(void)27void *rt_heap_begin_get(void) 28 { 29 return rt_heap; 30 } rt_heap_end_get(void)31void *rt_heap_end_get(void) 32 { 33 return rt_heap + RT_HEAP_SIZE; 34 } 35 #endif 36 rt_hw_board_init()37void rt_hw_board_init() 38 { 39 /*Initialize heap first, or system_ Semaphore in init cannot be created*/ 40 #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 41 rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); 42 #endif 43 /* System Clock Update */ 44 extern void system_init(void); 45 system_init(); 46 /* System Tick Configuration */ 47 rt_systick_config(); 48 49 volatile uint32_t mtvec = 0; 50 __asm volatile( "csrr %0, mtvec" : "=r"( mtvec ) ); 51 __asm volatile( "csrs mie, %0" :: "r"(0x880) ); 52 53 /* USART driver initialization is open by default */ 54 #ifdef RT_USING_SERIAL 55 rt_hw_usart_init(); 56 #endif 57 #ifdef RT_USING_CONSOLE 58 rt_console_set_device(RT_CONSOLE_DEVICE_NAME); 59 #endif 60 /* Call components board initial (use INIT_BOARD_EXPORT()) */ 61 #ifdef RT_USING_COMPONENTS_INIT 62 rt_components_board_init(); 63 #endif 64 } 65