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 Email Notes 8 * 2019-07-16 Kevin.Liu kevin.liu.mchp@gmail.com First Release 9 */ 10 11 #include <string.h> 12 13 #include <atmel_start.h> 14 #include "peripheral_clk_config.h" 15 16 #include <rtthread.h> 17 #include "board.h" 18 19 #ifdef RT_USING_SERIAL 20 extern int rt_hw_uart_init(void); 21 #endif 22 23 static struct io_descriptor* g_stdio; 24 rt_hw_console_output(const char * str)25void rt_hw_console_output(const char *str) 26 { 27 io_write(g_stdio, (uint8_t *)str, strlen(str)); 28 while (TARGET_IO.stat != 0); 29 } 30 RTM_EXPORT(rt_hw_console_output); 31 hw_board_init_usart(void)32static inline void hw_board_init_usart(void) 33 { 34 usart_async_get_io_descriptor(&TARGET_IO, &g_stdio); 35 usart_async_enable(&TARGET_IO); 36 } 37 38 /** 39 * This is the timer interrupt service routine. 40 * 41 */ SysTick_Handler(void)42void SysTick_Handler(void) 43 { 44 /* enter interrupt */ 45 rt_interrupt_enter(); 46 47 rt_tick_increase(); 48 49 /* leave interrupt */ 50 rt_interrupt_leave(); 51 } 52 53 /** 54 * This function will initial SAMC21 board. 55 */ rt_hw_board_init(void)56void rt_hw_board_init(void) 57 { 58 /* Initializes MCU, drivers and middleware */ 59 atmel_start_init(); 60 61 /* enable USART stdout module */ 62 hw_board_init_usart(); 63 64 /* UART driver initialization is open by default */ 65 #ifdef RT_USING_SERIAL 66 rt_hw_uart_init(); 67 #endif 68 69 /* init systick */ 70 SysTick_Config(CONF_CPU_FREQUENCY / RT_TICK_PER_SECOND); 71 72 /* set pend exception priority */ 73 NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); 74 75 #ifdef RT_USING_HEAP 76 #if defined(__ARMCC_VERSION) 77 rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)HEAP_END); 78 #elif __ICCARM__ 79 rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END); 80 #else 81 /* init memory system */ 82 rt_system_heap_init((void*)&__bss_end, (void*)HEAP_END); 83 #endif 84 #endif 85 86 /* Set the shell console output device */ 87 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) 88 rt_console_set_device(RT_CONSOLE_DEVICE_NAME); 89 #endif 90 91 #ifdef RT_USING_COMPONENTS_INIT 92 rt_components_board_init(); 93 #endif 94 } 95 96 /*@}*/ 97