Skip to contentSkip to conversation

hw/misc: Add the STM32F4xx Sysconfig device

PATCH In review Alistair Francis 2 participants 9 messages May 2, 2019 – May 3, 2019 1 message not in the archive Arm STM32

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/5 hw/misc: Add the STM32F4xx Sysconfig device

---
 default-configs/arm-softmmu.mak    |   1 +
 hw/misc/Kconfig                    |   3 +
 hw/misc/Makefile.objs              |   1 +
 hw/misc/stm32f4xx_syscfg.c         | 168 +++++++++++++++++++++++++++++
 hw/misc/trace-events               |   6 ++
 include/hw/misc/stm32f4xx_syscfg.h |  61 +++++++++++
 6 files changed, 240 insertions(+)
 create mode 100644 hw/misc/stm32f4xx_syscfg.c
 create mode 100644 include/hw/misc/stm32f4xx_syscfg.h
default-configs/arm-softmmu.mak +1 -0
index 613d19a06d..c5cfdb857d 100644
@@ -96,6 +96,7 @@ CONFIG_STM32F2XX_SYSCFG=y
 CONFIG_STM32F2XX_ADC=y
 CONFIG_STM32F2XX_SPI=y
 CONFIG_STM32F205_SOC=y
+CONFIG_STM32F4XX_SYSCFG=y
 CONFIG_NRF51_SOC=y
 
 CONFIG_CMSDK_APB_TIMER=y
hw/misc/Kconfig +3 -0
index 5f67d0d6d9..c6ff39aeeb 100644
@@ -80,6 +80,9 @@ config IMX
 config STM32F2XX_SYSCFG
     bool
 
+config STM32F4XX_SYSCFG
+    bool
+
 config MIPS_ITU
     bool
 
hw/misc/Makefile.objs +1 -0
index c71e07ae35..1413b1f232 100644
@@ -57,6 +57,7 @@ obj-$(CONFIG_SLAVIO) += slavio_misc.o
 obj-$(CONFIG_ZYNQ) += zynq_slcr.o
 obj-$(CONFIG_ZYNQ) += zynq-xadc.o
 obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
+obj-$(CONFIG_STM32F4XX_SYSCFG) += stm32f4xx_syscfg.o
 obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o
 obj-$(CONFIG_MIPS_CPS) += mips_cpc.o
 obj-$(CONFIG_MIPS_ITU) += mips_itu.o
hw/misc/stm32f4xx_syscfg.c new file +168 -0

168 lines not on this page · raw message

hw/misc/trace-events +6 -0
index 47e1bccf71..276a0a8c92 100644
@@ -84,6 +84,12 @@ mos6522_set_sr_int(void) "set sr_int"
 mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
 mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
 
+# stm32f4xx_syscfg
+stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d"
+stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
+stm32f4xx_syscfg_read(uint64_t addr) "reg read: addr: 0x%" PRIx64 " "
+stm32f4xx_syscfg_write(uint64_t addr, uint64_t data) "reg write: addr: 0x%" PRIx64 " val: 0x%" PRIx64 ""
+
 # tz-mpc.c
 tz_mpc_reg_read(uint32_t offset, uint64_t data, unsigned size) "TZ MPC regs read: offset 0x%x data 0x%" PRIx64 " size %u"
 tz_mpc_reg_write(uint32_t offset, uint64_t data, unsigned size) "TZ MPC regs write: offset 0x%x data 0x%" PRIx64 " size %u"
include/hw/misc/stm32f4xx_syscfg.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.21.0
Reviewed-by on v1 1/5
#2 lore raw

hw/misc/stm32f4xx_syscfg.c line 48

Quoted 9 lines · Alistair Francis
hw/misc/stm32f4xx_syscfg.c new file +6 -0
+static void stm32f4xx_syscfg_set_irq(void *opaque, int irq, int level)
+{
+    STM32F4xxSyscfgState *s = opaque;
+    int icrreg = irq / 4;
+    int startbit = (irq & 3) * 4;
+    uint8_t config = config = irq / 16;;

Stray double-semicolon.

Otherwise

thanks
-- PMM

#3 lore raw

PATCH 2/5 hw/misc: Add the STM32F4xx EXTI device

In reply to a message not in the archive
---
 default-configs/arm-softmmu.mak  |   1 +
 hw/misc/Kconfig                  |   3 +
 hw/misc/Makefile.objs            |   1 +
 hw/misc/stm32f4xx_exti.c         | 187 +++++++++++++++++++++++++++++++
 hw/misc/trace-events             |   5 +
 include/hw/misc/stm32f4xx_exti.h |  60 ++++++++++
 6 files changed, 257 insertions(+)
 create mode 100644 hw/misc/stm32f4xx_exti.c
 create mode 100644 include/hw/misc/stm32f4xx_exti.h
default-configs/arm-softmmu.mak +1 -0
index c5cfdb857d..8eb57de211 100644
@@ -97,6 +97,7 @@ CONFIG_STM32F2XX_ADC=y
 CONFIG_STM32F2XX_SPI=y
 CONFIG_STM32F205_SOC=y
 CONFIG_STM32F4XX_SYSCFG=y
+CONFIG_STM32F4XX_EXTI=y
 CONFIG_NRF51_SOC=y
 
 CONFIG_CMSDK_APB_TIMER=y
hw/misc/Kconfig +3 -0
index c6ff39aeeb..3748b5f11a 100644
@@ -83,6 +83,9 @@ config STM32F2XX_SYSCFG
 config STM32F4XX_SYSCFG
     bool
 
+config STM32F4XX_EXTI
+    bool
+
 config MIPS_ITU
     bool
 
hw/misc/Makefile.objs +1 -0
index 1413b1f232..74c7ca6c05 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_ZYNQ) += zynq_slcr.o
 obj-$(CONFIG_ZYNQ) += zynq-xadc.o
 obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
 obj-$(CONFIG_STM32F4XX_SYSCFG) += stm32f4xx_syscfg.o
+obj-$(CONFIG_STM32F4XX_EXTI) += stm32f4xx_exti.o
 obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o
 obj-$(CONFIG_MIPS_CPS) += mips_cpc.o
 obj-$(CONFIG_MIPS_ITU) += mips_itu.o
hw/misc/stm32f4xx_exti.c new file +187 -0

187 lines not on this page · raw message

hw/misc/trace-events +5 -0
index 276a0a8c92..0cdeb80d65 100644
@@ -90,6 +90,11 @@ stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
 stm32f4xx_syscfg_read(uint64_t addr) "reg read: addr: 0x%" PRIx64 " "
 stm32f4xx_syscfg_write(uint64_t addr, uint64_t data) "reg write: addr: 0x%" PRIx64 " val: 0x%" PRIx64 ""
 
+# stm32f4xx_exti
+stm32f4xx_exti_set_irq(int irq, int leve) "Set EXTI: %d to %d"
+stm32f4xx_exti_read(uint64_t addr) "reg read: addr: 0x%" PRIx64 " "
+stm32f4xx_exti_write(uint64_t addr, uint64_t data) "reg write: addr: 0x%" PRIx64 " val: 0x%" PRIx64 ""
+
 # tz-mpc.c
 tz_mpc_reg_read(uint32_t offset, uint64_t data, unsigned size) "TZ MPC regs read: offset 0x%x data 0x%" PRIx64 " size %u"
 tz_mpc_reg_write(uint32_t offset, uint64_t data, unsigned size) "TZ MPC regs write: offset 0x%x data 0x%" PRIx64 " size %u"
include/hw/misc/stm32f4xx_exti.h new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.21.0
#5 lore raw

PATCH 3/5 armv7m: Allow entry information to be returned

In reply to a message not in the archive

Allow the kernel's entry point information to be returned when loading a kernel.

---
 hw/arm/armv7m.c      | 4 +++-
 include/hw/arm/arm.h | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
hw/arm/armv7m.c +3 -1
index c4b2a9a1f5..2f2755b21e 100644
@@ -286,7 +286,7 @@ static void armv7m_reset(void *opaque)
     cpu_reset(CPU(cpu));
 }
 
-void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
+uint64_t armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
 {
     int image_size;
     uint64_t entry;
@@ -333,6 +333,8 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
      * board must call this function!
      */
     qemu_register_reset(armv7m_reset, cpu);
+
+    return entry;
 }
 
 static Property bitband_properties[] = {
include/hw/arm/arm.h +3 -1
index ffed39252d..48d9181b28 100644
@@ -29,11 +29,13 @@ typedef enum {
  * @kernel_filename: file to load
  * @mem_size: mem_size: maximum image size to load
  *
+ * returns: location of the kernel's entry point
+ *
  * Load the guest image for an ARMv7M system. This must be called by
  * any ARMv7M board. (This is necessary to ensure that the CPU resets
  * correctly on system reset, as well as for kernel loading.)
  */
-void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size);
+uint64_t armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size);
 
 /* arm_boot.c */
 struct arm_boot_info {
Signature · 1 line
2.21.0
#6 lore raw

PATCH 4/5 hw/arm: Add the STM32F4xx SoC

In reply to a message not in the archive
---
 MAINTAINERS                     |   8 +
 default-configs/arm-softmmu.mak |   1 +
 hw/arm/Kconfig                  |   3 +
 hw/arm/Makefile.objs            |   1 +
 hw/arm/stm32f405_soc.c          | 306 ++++++++++++++++++++++++++++++++
 include/hw/arm/stm32f405_soc.h  |  74 ++++++++
 6 files changed, 393 insertions(+)
 create mode 100644 hw/arm/stm32f405_soc.c
 create mode 100644 include/hw/arm/stm32f405_soc.h
MAINTAINERS +8 -0
index 7dd71e0a2d..c1c93743bb 100644
@@ -810,6 +810,14 @@ F: hw/adc/*
 F: hw/ssi/stm32f2xx_spi.c
 F: include/hw/*/stm32*.h
 
+STM32F405
+M: Alistair Francis <[email protected]>
+M: Peter Maydell <[email protected]>
+S: Maintained
+F: hw/arm/stm32f405_soc.c
+F: hw/misc/stm32f4xx_syscfg.c
+F: hw/misc/stm32f4xx_exti.c
+
 Netduino 2
 M: Alistair Francis <[email protected]>
 M: Peter Maydell <[email protected]>
default-configs/arm-softmmu.mak +1 -0
index 8eb57de211..e079f10624 100644
@@ -98,6 +98,7 @@ CONFIG_STM32F2XX_SPI=y
 CONFIG_STM32F205_SOC=y
 CONFIG_STM32F4XX_SYSCFG=y
 CONFIG_STM32F4XX_EXTI=y
+CONFIG_STM32F405_SOC=y
 CONFIG_NRF51_SOC=y
 
 CONFIG_CMSDK_APB_TIMER=y
hw/arm/Kconfig +3 -0
index d298fbdc89..3a98bce15a 100644
@@ -62,6 +62,9 @@ config RASPI
 config STM32F205_SOC
     bool
 
+config STM32F405_SOC
+    bool
+
 config XLNX_ZYNQMP_ARM
     bool
 
hw/arm/Makefile.objs +1 -0
index fa57c7c770..36c3ff54c3 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_STRONGARM) += strongarm.o
 obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
 obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o
 obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
+obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
 obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o
 obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal.o xlnx-versal-virt.o
 obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
hw/arm/stm32f405_soc.c new file +306 -0

306 lines not on this page · raw message

include/hw/arm/stm32f405_soc.h new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.21.0
Reviewed-by on v1 4/5
#7 lore raw

Re: [Qemu-devel] [PATCH v1 4/5] hw/arm: Add the STM32F4xx SoC

Quoted 16 lines · Alistair Francis
---
 MAINTAINERS                     |   8 +
 default-configs/arm-softmmu.mak |   1 +
 hw/arm/Kconfig                  |   3 +
 hw/arm/Makefile.objs            |   1 +
 hw/arm/stm32f405_soc.c          | 306 ++++++++++++++++++++++++++++++++
 include/hw/arm/stm32f405_soc.h  |  74 ++++++++
 6 files changed, 393 insertions(+)
 create mode 100644 hw/arm/stm32f405_soc.c
 create mode 100644 include/hw/arm/stm32f405_soc.h
hw/arm/stm32f405_soc.c new file +2 -0
+static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)
+{

hw/arm/stm32f405_soc.c line 100

Quoted 10 lines
hw/arm/stm32f405_soc.c new file +10 -0
+    STM32F405State *s = STM32F405_SOC(dev_soc);
+    DeviceState *dev, *armv7m;
+    SysBusDevice *busdev;
+    Error *err = NULL;
+    int i;
+
+    s->system_memory = get_system_memory();
+    s->sram = g_new(MemoryRegion, 1);
+    s->flash = g_new(MemoryRegion, 1);
+    s->flash_alias = g_new(MemoryRegion, 1);

What I meant by my comment on v1 was that rather than doing g_new() here you can just have the STM32F405State struct have
MemoryRegion sram;
MemoryRegion flash;
etc

and then instead of
memory_region_init_ram(s->flash, ...)
you use
memory_region_init_ram(&s->flash, ...)
etc

which avoids doing separate memory allocations (which would need to be freed if you then do an error-exit from the realize function, I think).

And you don't need to have an s->system_memory -- that can just be a local variable, because it's just caching the pointer to the global system memory MemoryRegion.

Otherwise

thanks
-- PMM

#8 lore raw

PATCH 5/5 hw/arm: Add the Netduino Plus 2

In reply to a message not in the archive
---
 MAINTAINERS                     |  6 +++
 default-configs/arm-softmmu.mak |  1 +
 hw/arm/Kconfig                  |  3 ++
 hw/arm/Makefile.objs            |  1 +
 hw/arm/netduinoplus2.c          | 77 +++++++++++++++++++++++++++++++++
 5 files changed, 88 insertions(+)
 create mode 100644 hw/arm/netduinoplus2.c
MAINTAINERS +6 -0
index c1c93743bb..fa55b588cc 100644
@@ -824,6 +824,12 @@ M: Peter Maydell <[email protected]>
 S: Maintained
 F: hw/arm/netduino2.c
 
+Netduino Plus 2
+M: Alistair Francis <[email protected]>
+M: Peter Maydell <[email protected]>
+S: Maintained
+F: hw/arm/netduinoplus2.c
+
 SmartFusion2
 M: Subbaraya Sundeep <[email protected]>
 M: Peter Maydell <[email protected]>
default-configs/arm-softmmu.mak +1 -0
index e079f10624..1e2c82f201 100644
@@ -46,6 +46,7 @@ CONFIG_A15MPCORE=y
 
 CONFIG_ARM_V7M=y
 CONFIG_NETDUINO2=y
+CONFIG_NETDUINOPLUS2=y
 
 CONFIG_ARM_GIC=y
 CONFIG_ARM_TIMER=y
hw/arm/Kconfig +3 -0
index 3a98bce15a..13fc779308 100644
@@ -26,6 +26,9 @@ config MUSICPAL
 config NETDUINO2
     bool
 
+config NETDUINOPLUS2
+    bool
+
 config NSERIES
     bool
 
hw/arm/Makefile.objs +1 -0
index 36c3ff54c3..1f216f4d93 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_INTEGRATOR) += integratorcp.o
 obj-$(CONFIG_MAINSTONE) += mainstone.o
 obj-$(CONFIG_MUSICPAL) += musicpal.o
 obj-$(CONFIG_NETDUINO2) += netduino2.o
+obj-$(CONFIG_NETDUINOPLUS2) += netduinoplus2.o
 obj-$(CONFIG_NSERIES) += nseries.o
 obj-$(CONFIG_OMAP) += omap_sx1.o palm.o
 obj-$(CONFIG_PXA2XX) += gumstix.o spitz.o tosa.o z2.o
hw/arm/netduinoplus2.c new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.21.0
#9 lore raw

Re: [Qemu-devel] [PATCH v1 5/5] hw/arm: Add the Netduino Plus 2

Quoted 22 lines · Alistair Francis
---
 MAINTAINERS                     |  6 +++
 default-configs/arm-softmmu.mak |  1 +
 hw/arm/Kconfig                  |  3 ++
 hw/arm/Makefile.objs            |  1 +
 hw/arm/netduinoplus2.c          | 77 +++++++++++++++++++++++++++++++++
 5 files changed, 88 insertions(+)
 create mode 100644 hw/arm/netduinoplus2.c
hw/arm/netduinoplus2.c new file +11 -0
+static void netduinoplus2_init(MachineState *machine)
+{
+    DeviceState *dev;
+    ARMV7MResetArgs reset_args;
+    uint64_t entry;
+
+    dev = qdev_create(NULL, TYPE_STM32F405_SOC);
+    qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4"));
+    object_property_set_bool(OBJECT(dev), true, "realized", &error_fatal);
+
+    entry = armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,

hw/arm/netduinoplus2.c line 69

Quoted 10 lines
hw/arm/netduinoplus2.c new file +10 -0
+                       FLASH_SIZE);
+
+    reset_args = (ARMV7MResetArgs) {
+        .cpu = ARM_CPU(first_cpu),
+        .reset_pc = entry,
+        .reset_sp = (SRAM_BASE_ADDRESS + (SRAM_SIZE * 2) / 3),
+    };
+    qemu_register_reset(armv7m_reset,
+                        g_memdup(&reset_args, sizeof(reset_args)));
+}

I still don't really like having this board interpret -kernel in a different way to all the other M-profile boards. I'd be much happier if it just behaved the same way the others do.

thanks
-- PMM