Skip to contentSkip to conversation

hw/arm: Add minimal support for the B-L475E-IOT01A board

RFC PATCH Superseded ~inesvarhol 2 participants 5 messages Nov 15, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover hw/arm: Add minimal support for the B-L475E-IOT01A board

This patch allows to emulate the B-L475E-IOT01A ARM Cortex-M4 board. This is RFC since the implementation isn't complete yet, there are no implemented
peripherals, and it's a first contribution to QEMU.

Inès Varhol (2):
hw/arm: Add minimal support for the STM32L475VG SoC hw/arm: Add minimal support for the B-L475E-IOT01A board

 configs/devices/arm-softmmu/default.mak |   1 +
 hw/arm/Kconfig                          |  11 ++
 hw/arm/b-l475e-iot01a.c                 |  71 +++++++
 hw/arm/meson.build                      |   2 +
 hw/arm/stm32l475vg_soc.c                | 241 ++++++++++++++++++++++++
 include/hw/arm/stm32l475vg_soc.h        |  60 ++++++
 6 files changed, 386 insertions(+)
 create mode 100644 hw/arm/b-l475e-iot01a.c
 create mode 100644 hw/arm/stm32l475vg_soc.c
 create mode 100644 include/hw/arm/stm32l475vg_soc.h
Signature · 1 line
2.38.5
#1 lore raw

RFC PATCH 1/2 hw/arm: Add minimal support for the STM32L475VG SoC

From: Inès Varhol <[email protected]>

This patch adds a new STM32L475VG SoC, it is necessary to add support for the B-L475E-IOT01A board.
The implementation is derived from the STM32F405 SoC.
The implementation contains no peripherals, only memory regions are implemented.

---
 hw/arm/Kconfig                   |   5 +
 hw/arm/meson.build               |   1 +
 hw/arm/stm32l475vg_soc.c         | 241 +++++++++++++++++++++++++++++++
 include/hw/arm/stm32l475vg_soc.h |  60 ++++++++
 4 files changed, 307 insertions(+)
 create mode 100644 hw/arm/stm32l475vg_soc.c
 create mode 100644 include/hw/arm/stm32l475vg_soc.h
hw/arm/Kconfig +5 -0
index 3ada335a24..763510afeb 100644
@@ -448,6 +448,11 @@ config STM32F405_SOC
     select STM32F4XX_SYSCFG
     select STM32F4XX_EXTI
 
+config STM32L475VG_SOC
+    bool
+    select ARM_V7M
+    select OR_IRQ
+
 config XLNX_ZYNQMP_ARM
     bool
     default y if PIXMAN
hw/arm/meson.build +1 -0
index 68245d3ad1..6b2e1228e5 100644
@@ -42,6 +42,7 @@ arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c'))
 arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c'))
 arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c'))
 arm_ss.add(when: 'CONFIG_STM32F405_SOC', if_true: files('stm32f405_soc.c'))
+arm_ss.add(when: 'CONFIG_STM32L475VG_SOC', if_true: files('stm32l475vg_soc.c'))
 arm_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp.c', 'xlnx-zcu102.c'))
 arm_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal.c', 'xlnx-versal-virt.c'))
 arm_ss.add(when: 'CONFIG_FSL_IMX25', if_true: files('fsl-imx25.c', 'imx25_pdk.c'))
hw/arm/stm32l475vg_soc.c new file +241 -0

241 lines not on this page · raw message

include/hw/arm/stm32l475vg_soc.h new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.38.5
#2 lore raw

Re: [PATCH RFC 1/2] hw/arm: Add minimal support for the STM32L475VG SoC

Hi Inès,

Quoted 4 lines · ~inesvarhol

From: Inès Varhol <[email protected]>

This patch adds a new STM32L475VG SoC, it is necessary to add support for the B-L475E-IOT01A board.

Thanks for your first contribution! See my comments inline.

Quoted 1 line

The implementation is derived from the STM32F405 SoC.

You might want to Cc the STM32F405 maintainer to get more reviewers (doing that for you).

$ ./scripts/get_maintainer.pl -f hw/arm/stm32f405_soc.c
Alistair Francis <[email protected]> (maintainer:STM32F405)
Peter Maydell <[email protected]> (maintainer:STM32F405)
[email protected] (open list:STM32F405)
[email protected] (open list:All patches CC here)

Also, do not forget to Cc the [email protected] list which is almost a subset of qemu-devel@ subscribers.

Quoted 35 lines

The implementation contains no peripherals, only memory regions are implemented.

---
  hw/arm/Kconfig                   |   5 +
  hw/arm/meson.build               |   1 +
  hw/arm/stm32l475vg_soc.c         | 241 +++++++++++++++++++++++++++++++
  include/hw/arm/stm32l475vg_soc.h |  60 ++++++++
  4 files changed, 307 insertions(+)

create mode 100644 hw/arm/stm32l475vg_soc.c create mode 100644 include/hw/arm/stm32l475vg_soc.h

hw/arm/Kconfig +5 -0
index 3ada335a24..763510afeb 100644
@@ -448,6 +448,11 @@ config STM32F405_SOC
      select STM32F4XX_SYSCFG
      select STM32F4XX_EXTI
 
+config STM32L475VG_SOC
+    bool
+    select ARM_V7M
+    select OR_IRQ
+
  config XLNX_ZYNQMP_ARM
      bool
      default y if PIXMAN
hw/arm/meson.build +0 -0
index 68245d3ad1..6b2e1228e5 100644

hw/arm/meson.build arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c')) · line 45

Quoted 4 lines
hw/arm/meson.build +1 -0
@@ -42,6 +42,7 @@ arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c'))
  arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c'))
  arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c'))
  arm_ss.add(when: 'CONFIG_STM32F405_SOC', if_true: files('stm32f405_soc.c'))
+arm_ss.add(when: 'CONFIG_STM32L475VG_SOC', if_true: files('stm32l475vg_soc.c'))

"V" refers to the packaging. This SoC can be encapsulated in multiple formats, for example as 64-pin LQFP or as 100-pin.

For QEMU the packaging is irrelevant, so you can strip the -V suffix.

"G" refers to the flash/sram size (here 1 MiB / 320 KiB). With few more lines we can support the "C" (256 KiB / 128 KiB) and "E" (512 / 128).

(See for example how hw/avr/atmega.c uses a class_init() method to set the flash_size/sram_size values for the different SoC it models). (I'm not asking to do that now, just giving you references. This can be done later on top).

This SoC is from the USB OTG lines family, maybe better name it generically as STM32L4x5, so we can reuse the base class for the whole family?

Quoted 9 lines
hw/arm/meson.build +0 -0
  arm_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp.c', 'xlnx-zcu102.c'))
  arm_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal.c', 'xlnx-versal-virt.c'))
  arm_ss.add(when: 'CONFIG_FSL_IMX25', if_true: files('fsl-imx25.c', 'imx25_pdk.c'))
hw/arm/stm32l475vg_soc.c new file +0 -0
new file mode 100644
index 0000000000..7dd5d70eb3

hw/arm/stm32l475vg_soc.c line 7

Quoted 7 lines
hw/arm/stm32l475vg_soc.c new file +7 -0
@@ -0,0 +1,241 @@
+/*
+ * STM32L475VG SoC
+ *
+ * Copyright (c) 2014 Alistair Francis <[email protected]>
+ * Copyright (c) 2023 Arnaud Minier <[email protected]>
+ * Copyright (c) 2023 Inès Varhol <[email protected]>
+ *

Consider including a SPDX tag which is easier to process than a full license:

* SPDX-License-Identifier: MIT

Quoted 24 lines
hw/arm/stm32l475vg_soc.c new file +24 -0
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "exec/address-spaces.h"
+#include "sysemu/sysemu.h"
+#include "hw/arm/stm32l475vg_soc.h"

hw/arm/stm32l475vg_soc.c line 41

Quoted 10 lines
hw/arm/stm32l475vg_soc.c new file +10 -0
+#include "hw/qdev-clock.h"
+#include "hw/misc/unimp.h"
+
+/* stm32l475vg_soc implementation is derived from stm32f405_soc */
+
+static void stm32l475vg_soc_initfn(Object *obj)
+{
+    STM32L475VGState *s = STM32L475VG_SOC(obj);
+
+    object_initialize_child(obj, "armv7m", &s->armv7m, TYPE_ARMV7M);

Since you only "forward" the 'cpu-type' property from the board to the ARM core, you can do:

       object_property_add_alias(obj, "cpu-type",
                                 OBJECT(&s->armv7m), "cpu-type");

So the board code setting this property directly sets the core cpu type, and you don't need to register any stm32l475vg_soc_properties[].

*But* this SoC family can only accept Cortex-M4 cores. Better would be to hardcode the type previous to the realize call, instead of letting the board code decide which CPU type to use. Also we could check at the SoC level that the board CPU type requested is really a Cortex-M4, returning an error otherwise.

I see you follow the template from hw/arm/netduino2.c. Hmm OK then, no need to over-engineer at this point.

hw/arm/stm32l475vg_soc.c line 50

Quoted 8 lines
hw/arm/stm32l475vg_soc.c new file +8 -0
+    s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0);
+    s->refclk = qdev_init_clock_in(DEVICE(s), "refclk", NULL, NULL, 0);
+}
+
+static void stm32l475vg_soc_realize(DeviceState *dev_soc, Error **errp)
+{
+    STM32L475VGState *s = STM32L475VG_SOC(dev_soc);
+    MemoryRegion *system_memory = get_system_memory();

Note for myself, this SoC aperture is 4GiB. get_system_memory() is wider. Not an issue.

hw/arm/stm32l475vg_soc.c line 52

Quoted 2 lines
hw/arm/stm32l475vg_soc.c new file +2 -0
+    DeviceState *armv7m;
+    Error *err = NULL;

Using the ERRP_GUARD() macro is safer. See include/qapi/error.h.

Quoted 16 lines
hw/arm/stm32l475vg_soc.c new file +16 -0
+
+    /*
+     * We use s->refclk internally and only define it with qdev_init_clock_in()
+     * so it is correctly parented and not leaked on an init/deinit; it is not
+     * intended as an externally exposed clock.
+     */
+    if (clock_has_source(s->refclk)) {
+        error_setg(errp, "refclk clock must not be wired up by the board code");
+        return;
+    }
+
+    if (!clock_has_source(s->sysclk)) {
+        error_setg(errp, "sysclk clock must be wired up by the board code");
+        return;
+    }
+

hw/arm/stm32l475vg_soc.c line 78

Quoted 10 lines
hw/arm/stm32l475vg_soc.c new file +10 -0
+    /*
+     * TODO: ideally we should model the SoC RCC and its ability to
+     * change the sysclk frequency and define different sysclk sources.
+     */
+
+    /* The refclk always runs at frequency HCLK / 8 */
+    clock_set_mul_div(s->refclk, 8, 1);
+    clock_set_source(s->refclk, s->sysclk);
+
+    memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32L475VG.flash",

Just name it "flash" as in datasheet.

hw/arm/stm32l475vg_soc.c line 85

Quoted 7 lines
hw/arm/stm32l475vg_soc.c new file +7 -0
+                           FLASH_SIZE, &err);
+    if (err != NULL) {
+        error_propagate(errp, err);
+        return;
+    }
+    memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc),
+                             "STM32L475VG.flash.alias", &s->flash, 0,

"flash_boot_alias".

hw/arm/stm32l475vg_soc.c line 91

Quoted 6 lines
hw/arm/stm32l475vg_soc.c new file +6 -0
+                             FLASH_SIZE);
+
+    memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash);
+    memory_region_add_subregion(system_memory, 0, &s->flash_alias);
+
+    memory_region_init_ram(&s->sram1, NULL, "STM32L475VG.sram1", SRAM1_SIZE,

Why NULL and not OBJECT(dev_soc) like for the flash earlier?

hw/arm/stm32l475vg_soc.c line 91

Quoted 1 line
hw/arm/stm32l475vg_soc.c new file +1 -0
+                           &err);

"SRAM1".

hw/arm/stm32l475vg_soc.c line 99

Quoted 7 lines
hw/arm/stm32l475vg_soc.c new file +7 -0
+    if (err != NULL) {
+        error_propagate(errp, err);
+        return;
+    }
+    memory_region_add_subregion(system_memory, SRAM1_BASE_ADDRESS, &s->sram1);
+
+    memory_region_init_ram(&s->sram2, NULL, "STM32L475VG.sram2", SRAM2_SIZE,

Ditto OBJECT(dev_soc) parent.

hw/arm/stm32l475vg_soc.c line 99

Quoted 1 line
hw/arm/stm32l475vg_soc.c new file +1 -0
+                           &err);

"SRAM2"

hw/arm/stm32l475vg_soc.c line 109

Quoted 9 lines
hw/arm/stm32l475vg_soc.c new file +9 -0
+    if (err != NULL) {
+        error_propagate(errp, err);
+        return;
+    }
+    memory_region_add_subregion(system_memory, SRAM2_BASE_ADDRESS, &s->sram2);
+
+    armv7m = DEVICE(&s->armv7m);
+    qdev_prop_set_uint32(armv7m, "num-irq", 96);
+    qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type);

This SoC family can only accept Cortex-M4 cores. Better would be to hardcode it here. Hmm I see, the code you used as template, hw/arm/netduino2.c, do the same. OK.

Quoted 122 lines
hw/arm/stm32l475vg_soc.c new file +122 -0
+    qdev_prop_set_bit(armv7m, "enable-bitband", true);
+    qdev_connect_clock_in(armv7m, "cpuclk", s->sysclk);
+    qdev_connect_clock_in(armv7m, "refclk", s->refclk);
+    object_property_set_link(OBJECT(&s->armv7m), "memory",
+                             OBJECT(system_memory), &error_abort);
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) {
+        return;
+    }
+
+    /* APB1 BUS */
+    create_unimplemented_device("TIM2",      0x40000000, 0x400);
+    create_unimplemented_device("TIM3",      0x40000400, 0x400);
+    create_unimplemented_device("TIM4",      0x40000800, 0x400);
+    create_unimplemented_device("TIM5",      0x40000C00, 0x400);
+    create_unimplemented_device("TIM6",      0x40001000, 0x400);
+    create_unimplemented_device("TIM7",      0x40001400, 0x400);
+    /* RESERVED:    0x40001800, 0x1000 */
+    create_unimplemented_device("RTC",       0x40002800, 0x400);
+    create_unimplemented_device("WWDG",      0x40002C00, 0x400);
+    create_unimplemented_device("IWDG",      0x40003000, 0x400);
+    /* RESERVED:    0x40001800, 0x400 */
+    create_unimplemented_device("SPI2",      0x40003800, 0x400);
+    create_unimplemented_device("SPI3",      0x40003C00, 0x400);
+    /* RESERVED:    0x40004000, 0x400 */
+    create_unimplemented_device("USART2",    0x40004400, 0x400);
+    create_unimplemented_device("USART3",    0x40004800, 0x400);
+    create_unimplemented_device("UART4",     0x40004C00, 0x400);
+    create_unimplemented_device("UART5",     0x40005000, 0x400);
+    create_unimplemented_device("I2C1",      0x40005400, 0x400);
+    create_unimplemented_device("I2C2",      0x40005800, 0x400);
+    create_unimplemented_device("I2C3",      0x40005C00, 0x400);
+    /* RESERVED:    0x40006000, 0x400 */
+    create_unimplemented_device("CAN1",      0x40006400, 0x400);
+    /* RESERVED:    0x40006800, 0x400 */
+    create_unimplemented_device("PWR",       0x40007000, 0x400);
+    create_unimplemented_device("DAC1",      0x40007400, 0x400);
+    create_unimplemented_device("OPAMP",     0x40007800, 0x400);
+    create_unimplemented_device("LPTIM1",    0x40007C00, 0x400);
+    create_unimplemented_device("LPUART1",   0x40008000, 0x400);
+    /* RESERVED:    0x40008400, 0x400 */
+    create_unimplemented_device("SWPMI1",    0x40008800, 0x400);
+    /* RESERVED:    0x40008C00, 0x800 */
+    create_unimplemented_device("LPTIM2",    0x40009400, 0x400);
+    /* RESERVED:    0x40009800, 0x6800 */
+
+    /* APB2 BUS */
+    create_unimplemented_device("SYSCFG",    0x40010000, 0x30);
+    create_unimplemented_device("VREFBUF",   0x40010030, 0x1D0);
+    create_unimplemented_device("COMP",      0x40010200, 0x200);
+    create_unimplemented_device("EXTI",      0x40010400, 0x400);
+    /* RESERVED:    0x40010800, 0x1400 */
+    create_unimplemented_device("FIREWALL",  0x40011C00, 0x400);
+    /* RESERVED:    0x40012000, 0x800 */
+    create_unimplemented_device("SDMMC1",    0x40012800, 0x400);
+    create_unimplemented_device("TIM1",      0x40012C00, 0x400);
+    create_unimplemented_device("SPI1",      0x40013000, 0x400);
+    create_unimplemented_device("TIM8",      0x40013400, 0x400);
+    create_unimplemented_device("USART1",    0x40013800, 0x400);
+    /* RESERVED:    0x40013C00, 0x400 */
+    create_unimplemented_device("TIM15",     0x40014000, 0x400);
+    create_unimplemented_device("TIM16",     0x40014400, 0x400);
+    create_unimplemented_device("TIM17",     0x40014800, 0x400);
+    /* RESERVED:    0x40014C00, 0x800 */
+    create_unimplemented_device("SAI1",      0x40015400, 0x400);
+    create_unimplemented_device("SAI2",      0x40015800, 0x400);
+    /* RESERVED:    0x40015C00, 0x400 */
+    create_unimplemented_device("DFSDM1",    0x40016000, 0x400);
+    /* RESERVED:    0x40016400, 0x9C00 */
+
+    /* AHB1 BUS */
+    create_unimplemented_device("DMA1",      0x40020000, 0x400);
+    create_unimplemented_device("DMA2",      0x40020400, 0x400);
+    /* RESERVED:    0x40020800, 0x800 */
+    create_unimplemented_device("RCC",       0x40021000, 0x400);
+    /* RESERVED:    0x40021400, 0xC00 */
+    create_unimplemented_device("FLASH",     0x40022000, 0x400);
+    /* RESERVED:    0x40022400, 0xC00 */
+    create_unimplemented_device("CRC",       0x40023000, 0x400);
+    /* RESERVED:    0x40023400, 0x400 */
+    create_unimplemented_device("TSC",       0x40024000, 0x400);
+
+    /* RESERVED:    0x40024400, 0x7FDBC00 */
+
+    /* AHB2 BUS */
+    create_unimplemented_device("GPIOA",     0x48000000, 0x400);
+    create_unimplemented_device("GPIOB",     0x48000400, 0x400);
+    create_unimplemented_device("GPIOC",     0x48000800, 0x400);
+    create_unimplemented_device("GPIOD",     0x48000C00, 0x400);
+    create_unimplemented_device("GPIOE",     0x48001000, 0x400);
+    create_unimplemented_device("GPIOF",     0x48001400, 0x400);
+    create_unimplemented_device("GPIOG",     0x48001800, 0x400);
+    create_unimplemented_device("GPIOH",     0x48001C00, 0x400);
+    /* RESERVED:    0x48002000, 0x7FDBC00 */
+    create_unimplemented_device("OTG_FS",    0x50000000, 0x40000);
+    create_unimplemented_device("ADC",       0x50040000, 0x400);
+    /* RESERVED:    0x50040400, 0x20400 */
+    create_unimplemented_device("RNG",       0x50060800, 0x400);
+
+    /* AHB3 BUS */
+    create_unimplemented_device("FMC",       0xA0000000, 0x1000);
+    create_unimplemented_device("QUADSPI",   0xA0001000, 0x400);
+}
+
+static Property stm32l475vg_soc_properties[] = {
+    DEFINE_PROP_STRING("cpu-type", STM32L475VGState, cpu_type),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void stm32l475vg_soc_class_init(ObjectClass *klass, void *data)
+{
+
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = stm32l475vg_soc_realize;
+    device_class_set_props(dc, stm32l475vg_soc_properties);
+    /* No vmstate or reset required: device has no internal state */
+}
+
+static const TypeInfo stm32l475vg_soc_info = {
+    .name          = TYPE_STM32L475VG_SOC,
+    .parent        = TYPE_DEVICE,
+    .instance_size = sizeof(STM32L475VGState),

hw/arm/stm32l475vg_soc.c line 241

Quoted 10 lines
hw/arm/stm32l475vg_soc.c new file +10 -0
+    .instance_init = stm32l475vg_soc_initfn,
+    .class_init    = stm32l475vg_soc_class_init,
+};
+
+static void stm32l475vg_soc_register_types(void)
+{
+    type_register_static(&stm32l475vg_soc_info);
+}
+
+type_init(stm32l475vg_soc_register_types)

Although for a single TypeInfo entry there is no difference, DEFINE_TYPES() is preferred over type_init().

include/hw/arm/stm32l475vg_soc.h line 2

Quoted 8 lines
include/hw/arm/stm32l475vg_soc.h new file +2 -0
new file mode 100644
index 0000000000..a224cb6384
@@ -0,0 +1,60 @@
+/*
+ * STM32L475VG SoC

"STM32L4x5 SoC family"

include/hw/arm/stm32l475vg_soc.h line 6

Quoted 4 lines
include/hw/arm/stm32l475vg_soc.h new file +4 -0
+ *
+ * Copyright (c) 2023 Arnaud Minier <[email protected]>
+ * Copyright (c) 2023 Inès Varhol <[email protected]>
+ *

Again SPDX tag if possible.

Quoted 14 lines
include/hw/arm/stm32l475vg_soc.h new file +14 -0
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

include/hw/arm/stm32l475vg_soc.h line 30

Quoted 10 lines
include/hw/arm/stm32l475vg_soc.h new file +10 -0
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef HW_ARM_STM32L475VG_SOC_H
+#define HW_ARM_STM32L475VG_SOC_H
+
+#include "hw/arm/armv7m.h"
+#include "qom/object.h"

You also need to include "hw/qdev-core.h" and "exec/memory.h" to get the DeviceState and MemoryRegion definitions, because STM32L475VGState uses these types.

For Clock* we don't need anything because it is forward declared by "qemu/typedefs.h", which all QEMU source files already include.

include/hw/arm/stm32l475vg_soc.h line 40

Quoted 9 lines
include/hw/arm/stm32l475vg_soc.h new file +9 -0
+#define TYPE_STM32L475VG_SOC "stm32l475vg-soc"
+OBJECT_DECLARE_SIMPLE_TYPE(STM32L475VGState, STM32L475VG_SOC)
+
+#define FLASH_BASE_ADDRESS 0x08000000
+#define FLASH_SIZE (1024 * 1024)
+#define SRAM1_BASE_ADDRESS 0x20000000
+#define SRAM1_SIZE (96 * 1024)
+#define SRAM2_BASE_ADDRESS 0x10000000
+#define SRAM2_SIZE (32 * 1024)

These definitions are specific to the SoC. No code out of the SoC should require them, so no need to expose them. Better keep them local in the stm32l4x5xx_soc.c source file.

include/hw/arm/stm32l475vg_soc.h line 45

Quoted 4 lines
include/hw/arm/stm32l475vg_soc.h new file +4 -0
+struct STM32L475VGState {
+    /*< private >*/
+    DeviceState parent_obj;
+    /*< public >*/

Please remove these <private/public> lines, we try to not use them anymore.

Quoted 4 lines
include/hw/arm/stm32l475vg_soc.h new file +4 -0
+    char *cpu_type;
+
+    ARMv7MState armv7m;
+

include/hw/arm/stm32l475vg_soc.h line 60

Quoted 10 lines
include/hw/arm/stm32l475vg_soc.h new file +10 -0
+    MemoryRegion sram1;
+    MemoryRegion sram2;
+    MemoryRegion flash;
+    MemoryRegion flash_alias;
+
+    Clock *sysclk;
+    Clock *refclk;
+};
+
+#endif

Very good first contribution, I'm glad you posted it :)

I mostly asked for minor style change. Looking for your next iteration!

Regards,

Phil.

#3 lore raw

RFC PATCH 2/2 hw/arm: Add minimal support for the B-L475E-IOT01A board

In reply to ~inesvarhol

From: Inès Varhol <[email protected]>

This commit adds a new B-L475E-IOT01A board using the STM32L475VG SoC. The implementation is derived from the Netduino Plus 2 machine. There are no peripherals implemented, only memory regions.

---
 configs/devices/arm-softmmu/default.mak |  1 +
 hw/arm/Kconfig                          |  6 +++
 hw/arm/b-l475e-iot01a.c                 | 71 +++++++++++++++++++++++++
 hw/arm/meson.build                      |  1 +
 4 files changed, 79 insertions(+)
 create mode 100644 hw/arm/b-l475e-iot01a.c
configs/devices/arm-softmmu/default.mak +1 -0
index 980c48a7d9..023faa2f75 100644
@@ -19,6 +19,7 @@ CONFIG_ARM_VIRT=y
 # CONFIG_NSERIES=n
 # CONFIG_STELLARIS=n
 # CONFIG_STM32VLDISCOVERY=n
+# CONFIG_B_L475E_IOT01A=n
 # CONFIG_REALVIEW=n
 # CONFIG_VERSATILE=n
 # CONFIG_VEXPRESS=n
hw/arm/Kconfig +6 -0
index 763510afeb..4d4ed96168 100644
@@ -448,6 +448,12 @@ config STM32F405_SOC
     select STM32F4XX_SYSCFG
     select STM32F4XX_EXTI
 
+config B_L475E_IOT01A
+    bool
+    default y
+    depends on TCG && ARM
+    select STM32L475VG_SOC
+
 config STM32L475VG_SOC
     bool
     select ARM_V7M
hw/arm/b-l475e-iot01a.c new file +71 -0

71 lines not on this page · raw message

hw/arm/meson.build +1 -0
index 6b2e1228e5..579c28f546 100644
@@ -42,6 +42,7 @@ arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c'))
 arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c'))
 arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c'))
 arm_ss.add(when: 'CONFIG_STM32F405_SOC', if_true: files('stm32f405_soc.c'))
+arm_ss.add(when: 'CONFIG_B_L475E_IOT01A', if_true: files('b-l475e-iot01a.c'))
 arm_ss.add(when: 'CONFIG_STM32L475VG_SOC', if_true: files('stm32l475vg_soc.c'))
 arm_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp.c', 'xlnx-zcu102.c'))
 arm_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal.c', 'xlnx-versal-virt.c'))
Signature · 1 line
2.38.5
Reviewed-by on v1 2/2
#4 lore raw

Hi Inès,

Quoted 7 lines · ~inesvarhol

From: Inès Varhol <[email protected]>

This commit adds a new B-L475E-IOT01A board using the STM32L475VG SoC. The implementation is derived from the Netduino Plus 2 machine. There are no peripherals implemented, only memory regions.

"default avatar" got converted to text :)

Quoted 44 lines
---
  configs/devices/arm-softmmu/default.mak |  1 +
  hw/arm/Kconfig                          |  6 +++
  hw/arm/b-l475e-iot01a.c                 | 71 +++++++++++++++++++++++++
  hw/arm/meson.build                      |  1 +
  4 files changed, 79 insertions(+)

create mode 100644 hw/arm/b-l475e-iot01a.c

configs/devices/arm-softmmu/default.mak +1 -0
index 980c48a7d9..023faa2f75 100644
@@ -19,6 +19,7 @@ CONFIG_ARM_VIRT=y
  # CONFIG_NSERIES=n
  # CONFIG_STELLARIS=n
  # CONFIG_STM32VLDISCOVERY=n
+# CONFIG_B_L475E_IOT01A=n
  # CONFIG_REALVIEW=n
  # CONFIG_VERSATILE=n
  # CONFIG_VEXPRESS=n
hw/arm/Kconfig +6 -0
index 763510afeb..4d4ed96168 100644
@@ -448,6 +448,12 @@ config STM32F405_SOC
      select STM32F4XX_SYSCFG
      select STM32F4XX_EXTI
 
+config B_L475E_IOT01A
+    bool
+    default y
+    depends on TCG && ARM
+    select STM32L475VG_SOC
+
  config STM32L475VG_SOC
      bool
      select ARM_V7M
hw/arm/b-l475e-iot01a.c new file +0 -0
new file mode 100644
index 0000000000..bfcb386d52

hw/arm/b-l475e-iot01a.c line 8

Quoted 8 lines
hw/arm/b-l475e-iot01a.c new file +8 -0
@@ -0,0 +1,71 @@
+/*
+ * B-L475E-IOT01A Discovery Kit machine
+ * (B-L475E-IOT01A IoT Node)
+ *
+ * Copyright (c) 2014 Alistair Francis <[email protected]>
+ * Copyright (c) 2023 Arnaud Minier <[email protected]>
+ * Copyright (c) 2023 Ines Varhol <[email protected]>
+ *

Please add a SPDX tag if possible.

Quoted 45 lines
hw/arm/b-l475e-iot01a.c new file +45 -0
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/boards.h"
+#include "hw/qdev-properties.h"
+#include "hw/qdev-clock.h"
+#include "qemu/error-report.h"
+#include "hw/arm/stm32l475vg_soc.h"
+#include "hw/arm/boot.h"
+
+/* B-L475E-IOT01A implementation is derived from netduinoplus2 */
+
+/* Main SYSCLK frequency in Hz (80MHz) */
+#define SYSCLK_FRQ 80000000ULL
+
+static void b_l475e_iot01a_init(MachineState *machine)
+{
+    DeviceState *dev;
+    Clock *sysclk;
+
+    /* This clock doesn't need migration because it is fixed-frequency */
+    sysclk = clock_new(OBJECT(machine), "SYSCLK");
+    clock_set_hz(sysclk, SYSCLK_FRQ);
+
+    dev = qdev_new(TYPE_STM32L475VG_SOC);
+    qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4"));
+    qdev_connect_clock_in(dev, "sysclk", sysclk);

hw/arm/b-l475e-iot01a.c line 62

Quoted 10 lines
hw/arm/b-l475e-iot01a.c new file +9 -0
+    qdev_realize(DEVICE(dev), NULL, &error_fatal);
+
+    armv7m_load_kernel(ARM_CPU(first_cpu),
+                       machine->kernel_filename,
+                       0, FLASH_SIZE);
+}
+
 
+static void b_l475e_iot01a_machine_init(MachineClass *mc)
+{

We can enforce the CPU type using:

       static const char *machine_valid_cpu_types[] = {
           ARM_CPU_TYPE_NAME("cortex-m4"),
           NULL
       };

hw/arm/b-l475e-iot01a.c line 65

Quoted 3 lines
hw/arm/b-l475e-iot01a.c new file +3 -0
+    mc->desc = "B-L475E-IOT01A Discovery Kit (Cortex-M4)";
+    mc->init = b_l475e_iot01a_init;
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
       mc->valid_cpu_types = machine_valid_cpu_types;

Otherwise, clean patch :)

Regards,

Phil.

Quoted 18 lines
hw/arm/b-l475e-iot01a.c new file +6 -0
+
+    /* SRAM pre-allocated as part of the SoC instantiation */
+    mc->default_ram_size = 0;
+}
+
+DEFINE_MACHINE("b-l475e-iot01a", b_l475e_iot01a_machine_init)
hw/arm/meson.build +1 -0
index 6b2e1228e5..579c28f546 100644
@@ -42,6 +42,7 @@ arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c'))
  arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c'))
  arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c'))
  arm_ss.add(when: 'CONFIG_STM32F405_SOC', if_true: files('stm32f405_soc.c'))
+arm_ss.add(when: 'CONFIG_B_L475E_IOT01A', if_true: files('b-l475e-iot01a.c'))
  arm_ss.add(when: 'CONFIG_STM32L475VG_SOC', if_true: files('stm32l475vg_soc.c'))
  arm_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zynqmp.c', 'xlnx-zcu102.c'))
  arm_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal.c', 'xlnx-versal-virt.c'))