zephyr/drivers/console/semihost_console.c
ZhongYao Luo 1811fff2dd console: Add semihosting console
Many chips have only one serial port. When the serial port is occupied
by other devices, there is a lack of a console to output debugging
information. Semihosting can provide a console. The disadvantage of
semihosting is that a debugger must be connected, so it can only be
used for online debugging.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-07 23:33:38 -05:00

40 lines
734 B
C

/*
* Copyright (c) 2019 LuoZhongYao
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <sys/printk.h>
extern void __printk_hook_install(int (*fn)(int));
extern void __stdout_hook_install(int (*fn)(int));
static int semihost_console_out(int ch)
{
static unsigned char c;
c = ch;
__asm__ __volatile__ (
"movs r1, %0\n"
"movs r0, #3\n"
"bkpt 0xab\n"
:
: "r" (&c)
: "r0", "r1");
return ch;
}
static int semihost_console_init(struct device *dev)
{
ARG_UNUSED(dev);
__printk_hook_install(semihost_console_out);
__stdout_hook_install(semihost_console_out);
return 0;
}
SYS_INIT(semihost_console_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);