diff mbox series

stm32vldiscovery: allow overriding of RAM size

Message ID 20230403121537.71320-1-lucas@osdyne.com
State New
Headers show
Series stm32vldiscovery: allow overriding of RAM size | expand

Commit Message

Lucas C. Villa Real April 3, 2023, 12:15 p.m. UTC
stm32vldiscovery comes with 8KB of SRAM, which may be too low when
running some workloads on QEMU. The command line argument "-m mem_size"
is not recognized by the current implementation, though, so one cannot
easily override the default memory size.

This patch fixes that by adding a memory subregion according to the
value provided on that command line argument. If absent, the default
value of 8KB still applies.

Signed-off-by: Lucas Villa Real <lucas@osdyne.com>
---
 hw/arm/stm32vldiscovery.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Peter Maydell April 3, 2023, 1:54 p.m. UTC | #1
On Mon, 3 Apr 2023 at 13:51, Lucas Villa Real <lucasvr@gmail.com> wrote:
>
> stm32vldiscovery comes with 8KB of SRAM, which may be too low when
> running some workloads on QEMU. The command line argument "-m mem_size"
> is not recognized by the current implementation, though, so one cannot
> easily override the default memory size.
>
> This patch fixes that by adding a memory subregion according to the
> value provided on that command line argument. If absent, the default
> value of 8KB still applies.
>
> Signed-off-by: Lucas Villa Real <lucas@osdyne.com>

Does the real hardware have (options for) more than 8K of SRAM here ?

thanks
-- PMM
Lucas C. Villa Real April 3, 2023, 2:48 p.m. UTC | #2
On Mon, Apr 3, 2023 at 10:54 AM Peter Maydell <peter.maydell@linaro.org>
wrote:

> On Mon, 3 Apr 2023 at 13:51, Lucas Villa Real <lucasvr@gmail.com> wrote:
> >
> > stm32vldiscovery comes with 8KB of SRAM, which may be too low when
> > running some workloads on QEMU. The command line argument "-m mem_size"
> > is not recognized by the current implementation, though, so one cannot
> > easily override the default memory size.
> >
> > This patch fixes that by adding a memory subregion according to the
> > value provided on that command line argument. If absent, the default
> > value of 8KB still applies.
> >
> > Signed-off-by: Lucas Villa Real <lucas@osdyne.com>
>
> Does the real hardware have (options for) more than 8K of SRAM here ?
>
> thanks
> -- PMM
>

Yes, it's possible to add more (p)SRAM via the STM32F10xxx's FSMC (flexible
static memory controller). The new memory is mapped to FSMC bank 1 at
0x6000_0000, though (as opposed to the embedded SRAM's fixed address at
0x2000_0000), as I have now realized. I'm happy to send an updated patch so
that "-m mem_size" creates a memory subregion at 0x6000_0000 instead.

Best regards,
Lucas
Alexandre IOOSS April 4, 2023, 6:22 a.m. UTC | #3
On 4/3/23 16:48, Lucas C. Villa Real wrote:
> On Mon, Apr 3, 2023 at 10:54 AM Peter Maydell <peter.maydell@linaro.org 
> <mailto:peter.maydell@linaro.org>> wrote:
> 
>     On Mon, 3 Apr 2023 at 13:51, Lucas Villa Real <lucasvr@gmail.com
>     <mailto:lucasvr@gmail.com>> wrote:
>      >
>      > stm32vldiscovery comes with 8KB of SRAM, which may be too low when
>      > running some workloads on QEMU. The command line argument "-m
>     mem_size"
>      > is not recognized by the current implementation, though, so one
>     cannot
>      > easily override the default memory size.
>      >
>      > This patch fixes that by adding a memory subregion according to the
>      > value provided on that command line argument. If absent, the default
>      > value of 8KB still applies.
>      >
>      > Signed-off-by: Lucas Villa Real <lucas@osdyne.com
>     <mailto:lucas@osdyne.com>>
> 
>     Does the real hardware have (options for) more than 8K of SRAM here ?
> 
>     thanks
>     -- PMM
> 
> 
> Yes, it's possible to add more (p)SRAM via the STM32F10xxx's FSMC 
> (flexible static memory controller). The new memory is mapped to FSMC 
> bank 1 at 0x6000_0000, though (as opposed to the embedded SRAM's fixed 
> address at 0x2000_0000), as I have now realized. I'm happy to send an 
> updated patch so that "-m mem_size" creates a memory subregion at 
> 0x6000_0000 instead.
> 
> Best regards,
> Lucas
> 

Looking at the STM32F100xx reference manual page 494 
(https://www.st.com/resource/en/reference_manual/rm0041-stm32f100xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf), 
FSMC is only present on high-density value line devices only. This is 
not the case of the STM32VLDISCOVERY which uses a STM32F100RB 
(low/medium-density value line).

Correct me if I'm wrong, but I believe you cannot buy a STM32VLDISCOVERY 
that could support FSMC or have more than 8KB of on-chip SRAM.

However, could it be a good idea to implement a generic STM32F100xx 
machine in QEMU that is "high-density" by default and that could be 
configured using command line options ? This could cover a wide range of 
cases with a single machine.

Thanks,
Lucas C. Villa Real April 4, 2023, 4:39 p.m. UTC | #4
On Tue, Apr 4, 2023 at 3:23 AM Alexandre IOOSS <erdnaxe@crans.org> wrote:

> On 4/3/23 16:48, Lucas C. Villa Real wrote:
> > On Mon, Apr 3, 2023 at 10:54 AM Peter Maydell <peter.maydell@linaro.org
> > <mailto:peter.maydell@linaro.org>> wrote:
> >
> >     On Mon, 3 Apr 2023 at 13:51, Lucas Villa Real <lucasvr@gmail.com
> >     <mailto:lucasvr@gmail.com>> wrote:
> >      >
> >      > stm32vldiscovery comes with 8KB of SRAM, which may be too low when
> >      > running some workloads on QEMU. The command line argument "-m
> >     mem_size"
> >      > is not recognized by the current implementation, though, so one
> >     cannot
> >      > easily override the default memory size.
> >      >
> >      > This patch fixes that by adding a memory subregion according to
> the
> >      > value provided on that command line argument. If absent, the
> default
> >      > value of 8KB still applies.
> >      >
> >      > Signed-off-by: Lucas Villa Real <lucas@osdyne.com
> >     <mailto:lucas@osdyne.com>>
> >
> >     Does the real hardware have (options for) more than 8K of SRAM here ?
> >
> >     thanks
> >     -- PMM
> >
> >
> > Yes, it's possible to add more (p)SRAM via the STM32F10xxx's FSMC
> > (flexible static memory controller). The new memory is mapped to FSMC
> > bank 1 at 0x6000_0000, though (as opposed to the embedded SRAM's fixed
> > address at 0x2000_0000), as I have now realized. I'm happy to send an
> > updated patch so that "-m mem_size" creates a memory subregion at
> > 0x6000_0000 instead.
> >
> > Best regards,
> > Lucas
> >
>
> Looking at the STM32F100xx reference manual page 494
> (
> https://www.st.com/resource/en/reference_manual/rm0041-stm32f100xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf),
>
> FSMC is only present on high-density value line devices only. This is
> not the case of the STM32VLDISCOVERY which uses a STM32F100RB
> (low/medium-density value line).
>
> Correct me if I'm wrong, but I believe you cannot buy a STM32VLDISCOVERY
> that could support FSMC or have more than 8KB of on-chip SRAM.
>
> However, could it be a good idea to implement a generic STM32F100xx
> machine in QEMU that is "high-density" by default and that could be
> configured using command line options ? This could cover a wide range of
> cases with a single machine.
>

Oh, you're right: FSMC is only featured on high-density STM32F100xx
devices. Since I'm mostly dealing with QEMU (i.e., no real hardware) at
this point in time I wasn't aware of that limitation. Thanks for the heads
up.

Given that the current STM32 port doesn't implement many devices, I presume
that adding support for a "high-density" machine would come down to making
changes to the flash and register boundary addresses, mostly? If that's the
case, then it makes sense to support such a generic machine. I've limited
time to work on that, but I can give it a kick start and we can coordinate
offline if that's OK with you.

Lucas
diff mbox series

Patch

diff --git a/hw/arm/stm32vldiscovery.c b/hw/arm/stm32vldiscovery.c
index 67675e952f..7ca3ba029e 100644
--- a/hw/arm/stm32vldiscovery.c
+++ b/hw/arm/stm32vldiscovery.c
@@ -29,6 +29,7 @@ 
 #include "hw/qdev-properties.h"
 #include "hw/qdev-clock.h"
 #include "qemu/error-report.h"
+#include "exec/address-spaces.h"
 #include "hw/arm/stm32f100_soc.h"
 #include "hw/arm/boot.h"
 
@@ -42,6 +43,9 @@  static void stm32vldiscovery_init(MachineState *machine)
     DeviceState *dev;
     Clock *sysclk;
 
+    /* Allow overriding the emulated board's RAM size */
+    memory_region_add_subregion(get_system_memory(), SRAM_BASE_ADDRESS, machine->ram);
+
     /* This clock doesn't need migration because it is fixed-frequency */
     sysclk = clock_new(OBJECT(machine), "SYSCLK");
     clock_set_hz(sysclk, SYSCLK_FRQ);
@@ -60,6 +64,8 @@  static void stm32vldiscovery_machine_init(MachineClass *mc)
 {
     mc->desc = "ST STM32VLDISCOVERY (Cortex-M3)";
     mc->init = stm32vldiscovery_init;
+    mc->default_ram_id = "stm32vldiscovery.ram";
+    mc->default_ram_size = SRAM_SIZE;
 }
 
 DEFINE_MACHINE("stm32vldiscovery", stm32vldiscovery_machine_init)