arm: Add nRF51 SoC UART support
v3 cover arm: Add nRF51 SoC UART support
This series adds support for the nRF51 SoC UART, that used in BBC Micro:bit board, and QTest for it.
v3:
* serial_hd() moved to the board code
* sysbus_init_child_obj() used for initialization
* qemu_chr_fe_accept_input() called after byte popping
v2:
* Suspend/Enable functionality added
* Connection to SoC moved to a separate patch
* Added QTest for checking reception functionality
* Mini-kernel test changed to fit current implementation
* Addressed review comments on R_*, uart_can_receive, VMState, uart_transmit
Julia Suvorova (3):
hw/char: Implement nRF51 SoC UART hw/arm/nrf51_soc: Connect UART to nRF51 SoC tests/boot-serial-test: Add microbit board testcase
hw/arm/microbit.c | 2 + hw/arm/nrf51_soc.c | 20 +++ hw/char/Makefile.objs | 1 + hw/char/nrf51_uart.c | 330 +++++++++++++++++++++++++++++++++++ hw/char/trace-events | 4 + include/hw/arm/nrf51_soc.h | 3 + include/hw/char/nrf51_uart.h | 78 +++++++++ tests/boot-serial-test.c | 19 ++ 8 files changed, 457 insertions(+) create mode 100644 hw/char/nrf51_uart.c create mode 100644 include/hw/char/nrf51_uart.h
Signature · 1 line
2.17.1
PATCH v3 1/3 hw/char: Implement nRF51 SoC UART
Not implemented: CTS/NCTS, PSEL*.
--- hw/char/Makefile.objs | 1 + hw/char/nrf51_uart.c | 330 +++++++++++++++++++++++++++++++++++ hw/char/trace-events | 4 + include/hw/char/nrf51_uart.h | 78 +++++++++ 4 files changed, 413 insertions(+) create mode 100644 hw/char/nrf51_uart.c create mode 100644 include/hw/char/nrf51_uart.h
hw/char/Makefile.objs +1 -0
@@ -1,5 +1,6 @@ common-obj-$(CONFIG_IPACK) += ipoctal232.o common-obj-$(CONFIG_ESCC) += escc.o +common-obj-$(CONFIG_NRF51_SOC) += nrf51_uart.o common-obj-$(CONFIG_PARALLEL) += parallel.o common-obj-$(CONFIG_PARALLEL) += parallel-isa.o common-obj-$(CONFIG_PL011) += pl011.o
hw/char/nrf51_uart.c new file +330 -0
330 lines not on this page · raw message
hw/char/trace-events +4 -0
@@ -73,3 +73,7 @@ cmsdk_apb_uart_receive(uint8_t c) "CMSDK APB UART: got character 0x%x from backe cmsdk_apb_uart_tx_pending(void) "CMSDK APB UART: character send to backend pending" cmsdk_apb_uart_tx(uint8_t c) "CMSDK APB UART: character 0x%x sent to backend" cmsdk_apb_uart_set_params(int speed) "CMSDK APB UART: params set to %d 8N1" + +# hw/char/nrf51_uart.c +nrf51_uart_read(uint64_t addr, uint64_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u" +nrf51_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u"
include/hw/char/nrf51_uart.h new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 2/3 hw/arm/nrf51_soc: Connect UART to nRF51 SoC
In reply to Julia SuvorovaWire up nRF51 UART in the corresponding SoC.
--- hw/arm/microbit.c | 2 ++ hw/arm/nrf51_soc.c | 20 ++++++++++++++++++++ include/hw/arm/nrf51_soc.h | 3 +++ 3 files changed, 25 insertions(+)
hw/arm/microbit.c +2 -0
@@ -12,6 +12,7 @@#include "qapi/error.h" #include "hw/boards.h" #include "hw/arm/arm.h" +#include "sysemu/sysemu.h" #include "exec/address-spaces.h" #include "hw/arm/nrf51_soc.h"
@@ -35,6 +36,7 @@ static void microbit_init(MachineState *machine)sysbus_init_child_obj (OBJECT (machine),"nrf51" , soc,sizeof (s->nrf51),TYPE_NRF51_SOC ); +qdev_prop_set_chr (DEVICE (&s->nrf51),"serial0" ,serial_hd (0 ));object_property_set_link (soc,OBJECT (system_memory),"memory" , &error_fatal);object_property_set_bool (soc, true,"realized" , &error_fatal);
hw/arm/nrf51_soc.c +20 -0
@@ -43,9 +43,12 @@#define NRF51822_FLASH_SIZE (256 * 1024)#define NRF51822_SRAM_SIZE (16 * 1024) +#define BASE_TO_IRQ (base) ((base >> 12) & 0x1F) +static void nrf51_soc_realize (DeviceState *dev_soc,Error **errp) {NRF51State *s =NRF51_SOC (dev_soc); +MemoryRegion *mr;Error *err =NULL ;if (!s->board_memory) {
@@ -82,6 +85,18 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp) }memory_region_add_subregion (&s->container,SRAM_BASE , &s->sram); +/* UART */ +object_property_set_bool (OBJECT (&s->uart), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->uart),0 ); +memory_region_add_subregion_overlap (&s->container,UART_BASE , mr,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->uart),0 , +qdev_get_gpio_in (DEVICE (&s->cpu), +BASE_TO_IRQ (UART_BASE ))); +create_unimplemented_device ("nrf51_soc.io" ,IOMEM_BASE ,IOMEM_SIZE );create_unimplemented_device ("nrf51_soc.ficr" ,FICR_BASE ,FICR_SIZE ); create_unimplemented_device("nrf51_soc.private",
@@ -99,6 +114,11 @@ static void nrf51_soc_init(Object *obj)qdev_prop_set_string (DEVICE (&s->cpu),"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m0" ));qdev_prop_set_uint32 (DEVICE (&s->cpu),"num-irq" ,32 ); + +sysbus_init_child_obj (obj,"uart" , &s->uart,sizeof (s->uart), +TYPE_NRF51_UART ); +object_property_add_alias (obj,"serial0" ,OBJECT (&s->uart),"chardev" , + &error_abort); }static Property nrf51_soc_properties[] = {
include/hw/arm/nrf51_soc.h +3 -0
@@ -12,6 +12,7 @@#include "hw/sysbus.h" #include "hw/arm/armv7m.h" +#include "hw/char/nrf51_uart.h" #define TYPE_NRF51_SOC "nrf51-soc"#define NRF51_SOC (obj) \
@@ -24,6 +25,8 @@ typedef struct NRF51State {/*< public >*/ ARMv7MState cpu; +NRF51UARTState uart; +MemoryRegion iomem;MemoryRegion sram;MemoryRegion flash;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v3 2/3] hw/arm/nrf51_soc: Connect UART to nRF51 SoC
Quoted 4 lines · Julia Suvorova via Qemu-devel
Wire up nRF51 UART in the corresponding SoC.
Signed-off-by Julia Suvorova <[email protected]>
Alistair
Quoted 99 lines
--- hw/arm/microbit.c | 2 ++ hw/arm/nrf51_soc.c | 20 ++++++++++++++++++++ include/hw/arm/nrf51_soc.h | 3 +++ 3 files changed, 25 insertions(+)hw/arm/microbit.c +2
-0@@ -12,6 +12,7 @@#include "qapi/error.h" #include "hw/boards.h" #include "hw/arm/arm.h" +#include "sysemu/sysemu.h" #include "exec/address-spaces.h" #include "hw/arm/nrf51_soc.h" @@ -35,6 +36,7 @@ static void microbit_init(MachineState *machine)sysbus_init_child_obj (OBJECT (machine),"nrf51" , soc,sizeof (s->nrf51),TYPE_NRF51_SOC ); +qdev_prop_set_chr (DEVICE (&s->nrf51),"serial0" ,serial_hd (0 ));object_property_set_link (soc,OBJECT (system_memory),"memory" , &error_fatal);object_property_set_bool (soc, true,"realized" , &error_fatal);hw/arm/nrf51_soc.c +20
-0@@ -43,9 +43,12 @@#define NRF51822_FLASH_SIZE (256 * 1024)#define NRF51822_SRAM_SIZE (16 * 1024) +#define BASE_TO_IRQ (base) ((base >> 12) & 0x1F) +static void nrf51_soc_realize (DeviceState *dev_soc,Error **errp) {NRF51State *s =NRF51_SOC (dev_soc); +MemoryRegion *mr;Error *err =NULL ;if (!s->board_memory) {@@ -82,6 +85,18 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp) }memory_region_add_subregion (&s->container,SRAM_BASE , &s->sram); +/* UART */ +object_property_set_bool (OBJECT (&s->uart), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->uart),0 ); +memory_region_add_subregion_overlap (&s->container,UART_BASE , mr,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->uart),0 , +qdev_get_gpio_in (DEVICE (&s->cpu), +BASE_TO_IRQ (UART_BASE ))); +create_unimplemented_device ("nrf51_soc.io" ,IOMEM_BASE ,IOMEM_SIZE );create_unimplemented_device ("nrf51_soc.ficr" ,FICR_BASE ,FICR_SIZE ); create_unimplemented_device("nrf51_soc.private",@@ -99,6 +114,11 @@ static void nrf51_soc_init(Object *obj)qdev_prop_set_string (DEVICE (&s->cpu),"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m0" ));qdev_prop_set_uint32 (DEVICE (&s->cpu),"num-irq" ,32 ); + +sysbus_init_child_obj (obj,"uart" , &s->uart,sizeof (s->uart), +TYPE_NRF51_UART ); +object_property_add_alias (obj,"serial0" ,OBJECT (&s->uart),"chardev" , + &error_abort); }static Property nrf51_soc_properties[] = {include/hw/arm/nrf51_soc.h +3
-1@@ -12,6 +12,7 @@#include "hw/sysbus.h" #include "hw/arm/armv7m.h" +#include "hw/char/nrf51_uart.h" #define TYPE_NRF51_SOC "nrf51-soc"#define NRF51_SOC (obj) \@@ -24,6 +25,8 @@ typedef struct NRF51State {/*< public >*/ ARMv7MState cpu; +NRF51UARTState uart; +MemoryRegion iomem;MemoryRegion sram;MemoryRegion flash; --2.17.1
PATCH v3 3/3 tests/boot-serial-test: Add microbit board testcase
In reply to Julia SuvorovaNew mini-kernel test for nRF51 SoC UART.
--- tests/boot-serial-test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
tests/boot-serial-test.c +19 -0
@@ -62,6 +62,24 @@ static const uint8_t kernel_aarch64[] = { 0xfd, 0xff, 0xff, 0x17, /* b -12 (loop) */ }; +static const uint8_t kernel_nrf51[] = { +0x00 ,0x00 ,0x00 ,0x00 ,/* Stack top address */ +0x09 ,0x00 ,0x00 ,0x00 ,/* Reset handler address */ +0x04 ,0x4a ,/* ldr r2, [pc, #16] Get ENABLE */ +0x04 ,0x21 ,/* movs r1, #4 */ +0x11 ,0x60 ,/* str r1, [r2] */ +0x04 ,0x4a ,/* ldr r2, [pc, #16] Get STARTTX */ +0x01 ,0x21 ,/* movs r1, #1 */ +0x11 ,0x60 ,/* str r1, [r2] */ +0x03 ,0x4a ,/* ldr r2, [pc, #12] Get TXD */ +0x54 ,0x21 ,/* movs r1, 'T' */ +0x11 ,0x60 ,/* str r1, [r2] */ +0xfe ,0xe7 ,/* b . */ +0x00 ,0x25 ,0x00 ,0x40 ,/* 0x40002500 = UART ENABLE */ +0x08 ,0x20 ,0x00 ,0x40 ,/* 0x40002008 = UART STARTTX */ +0x1c ,0x25 ,0x00 ,0x40 /* 0x4000251c = UART TXD */ +}; + typedef struct testdef { const char *arch; /* Target architecture */ const char *machine; /* Name of the machine */
@@ -105,6 +123,7 @@ static testdef_t tests[] = { { "hppa", "hppa", "", "SeaBIOS wants SYSTEM HALT" }, { "aarch64", "virt", "-cpu cortex-a57", "TT", sizeof(kernel_aarch64), kernel_aarch64 }, + { "arm", "microbit", "", "T", sizeof(kernel_nrf51), kernel_nrf51 }, { NULL } };
Signature · 1 line
2.17.1
Quoted 21 lines · Julia Suvorova via Qemu-devel
This series adds support for the nRF51 SoC UART, that used in BBC Micro:bit board, and QTest for it.
v3:
*serial_hd()moved to the board code
*sysbus_init_child_obj()used for initialization
*qemu_chr_fe_accept_input()called after byte poppingv2:
* Suspend/Enable functionality added
* Connection to SoC moved to a separate patch
* Added QTest for checking reception functionality
* Mini-kernel test changed to fit current implementation
* Addressed review comments on R_*,uart_can_receive, VMState,uart_transmitJulia Suvorova (3):
hw/char: Implement nRF51 SoC UART hw/arm/nrf51_soc: Connect UART to nRF51 SoC tests/boot-serial-test: Add microbit board testcase
Quoted 16 lines
hw/arm/microbit.c | 2 + hw/arm/nrf51_soc.c | 20 +++ hw/char/Makefile.objs | 1 + hw/char/nrf51_uart.c | 330 +++++++++++++++++++++++++++++++++++ hw/char/trace-events | 4 + include/hw/arm/nrf51_soc.h | 3 + include/hw/char/nrf51_uart.h | 78 +++++++++ tests/boot-serial-test.c | 19 ++ 8 files changed, 457 insertions(+) create mode 100644 hw/char/nrf51_uart.c create mode 100644 include/hw/char/nrf51_uart.hSignature · 1 line
2.17.1
Peter Maydell
AppliedQuoted 16 lines · Julia Suvorova
This series adds support for the nRF51 SoC UART, that used in BBC Micro:bit board, and QTest for it.
v3:
*serial_hd()moved to the board code
*sysbus_init_child_obj()used for initialization
*qemu_chr_fe_accept_input()called after byte poppingv2:
* Suspend/Enable functionality added
* Connection to SoC moved to a separate patch
* Added QTest for checking reception functionality
* Mini-kernel test changed to fit current implementation
* Addressed review comments on R_*,uart_can_receive, VMState,uart_transmit
Quoted 4 lines
Julia Suvorova (3):
hw/char: Implement nRF51 SoC UART hw/arm/nrf51_soc: Connect UART to nRF51 SoC tests/boot-serial-test: Add microbit board testcase
Applied to target-arm.next, thanks.
What's the current status of the 'microbit' board with these patches? Are we missing anything important? Can we run any interesting guest programs?
thanks
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 16 lines · Julia Suvorova
This series adds support for the nRF51 SoC UART, that used in BBC Micro:bit board, and QTest for it.
v3:
*serial_hd()moved to the board code
*sysbus_init_child_obj()used for initialization
*qemu_chr_fe_accept_input()called after byte poppingv2:
* Suspend/Enable functionality added
* Connection to SoC moved to a separate patch
* Added QTest for checking reception functionality
* Mini-kernel test changed to fit current implementation
* Addressed review comments on R_*,uart_can_receive, VMState,uart_transmitQuoted 4 lines
Julia Suvorova (3):
hw/char: Implement nRF51 SoC UART hw/arm/nrf51_soc: Connect UART to nRF51 SoC tests/boot-serial-test: Add microbit board testcase
Quoted 5 lines
Applied to target-arm.next, thanks.
What's the current status of the 'microbit' board with these patches? Are we missing anything important? Can we run any interesting guest programs?
qemu.git/master can't run interesting programs yet. Missing:
* Steffen Görtz's patches (rng, timer, uicr, ficr)
* Julia's serial qtest (this is a prerequisite for the next item)
* My -kernel vs -device loader fix (currently qemu.git/master is broken and cannot load any kernel at all!)
But we're getting there step by step :).
Stefan