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>
This commit is contained in:
parent
8c051f0809
commit
1811fff2dd
|
@ -139,6 +139,7 @@
|
||||||
/drivers/can/*mcp2515* @karstenkoenig
|
/drivers/can/*mcp2515* @karstenkoenig
|
||||||
/drivers/clock_control/*nrf* @nordic-krch
|
/drivers/clock_control/*nrf* @nordic-krch
|
||||||
/drivers/counter/ @nordic-krch
|
/drivers/counter/ @nordic-krch
|
||||||
|
/drivers/console/semihost_console.c @luozhongyao
|
||||||
/drivers/counter/counter_cmos.c @andrewboie
|
/drivers/counter/counter_cmos.c @andrewboie
|
||||||
/drivers/counter/maxim_ds3231.c @pabigot
|
/drivers/counter/maxim_ds3231.c @pabigot
|
||||||
/drivers/crypto/*nrf_ecb* @maciekfabia @anangl
|
/drivers/crypto/*nrf_ecb* @maciekfabia @anangl
|
||||||
|
|
|
@ -11,3 +11,4 @@ zephyr_sources_if_kconfig(xtensa_sim_console.c)
|
||||||
zephyr_sources_if_kconfig(native_posix_console.c)
|
zephyr_sources_if_kconfig(native_posix_console.c)
|
||||||
zephyr_sources_if_kconfig(uart_mux.c)
|
zephyr_sources_if_kconfig(uart_mux.c)
|
||||||
zephyr_sources_if_kconfig(gsm_mux.c)
|
zephyr_sources_if_kconfig(gsm_mux.c)
|
||||||
|
zephyr_sources_if_kconfig(semihost_console.c)
|
||||||
|
|
|
@ -291,6 +291,20 @@ config NATIVE_POSIX_CONSOLE_INIT_PRIORITY
|
||||||
help
|
help
|
||||||
Device driver initialization priority.
|
Device driver initialization priority.
|
||||||
|
|
||||||
|
config SEMIHOST_CONSOLE
|
||||||
|
bool "Use semihosting for console"
|
||||||
|
select CONSOLE_HAS_DRIVER
|
||||||
|
depends on CPU_CORTEX_M
|
||||||
|
help
|
||||||
|
Enable this option to use semihosting for console.
|
||||||
|
Semihosting is a mechanism that enables code running on an ARM target
|
||||||
|
to communicate and use the Input/Output facilities on a host computer
|
||||||
|
that is running a debugger.
|
||||||
|
Additional information can be found in:
|
||||||
|
https://developer.arm.com/docs/dui0471/k/what-is-semihosting/what-is-semihosting
|
||||||
|
This option is compatible with hardware and with QEMU, through the
|
||||||
|
(automatic) use of the -semihosting-config switch when invoking it.
|
||||||
|
|
||||||
module = UART_CONSOLE
|
module = UART_CONSOLE
|
||||||
module-str = UART console
|
module-str = UART console
|
||||||
source "subsys/logging/Kconfig.template.log_config"
|
source "subsys/logging/Kconfig.template.log_config"
|
||||||
|
|
39
drivers/console/semihost_console.c
Normal file
39
drivers/console/semihost_console.c
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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);
|
Loading…
Reference in a new issue