1 /* 2 * Copyright (c) 2019 LuoZhongYao 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 #include <zephyr/kernel.h> 7 #include <zephyr/device.h> 8 #include <zephyr/init.h> 9 #include <zephyr/arch/common/semihost.h> 10 11 extern void __stdout_hook_install(int (*fn)(int)); 12 arch_printk_char_out(int _c)13int arch_printk_char_out(int _c) 14 { 15 semihost_poll_out((char)_c); 16 return 0; 17 } 18 semihost_console_init(void)19static int semihost_console_init(void) 20 { 21 22 /* 23 * The printk output callback is arch_printk_char_out by default and 24 * is installed at link time. That makes printk() usable very early. 25 * 26 * We still need to install the stdout callback manually at run time. 27 */ 28 __stdout_hook_install(arch_printk_char_out); 29 30 return 0; 31 } 32 33 SYS_INIT(semihost_console_init, PRE_KERNEL_1, CONFIG_CONSOLE_INIT_PRIORITY); 34