Skip to contentSkip to conversation

stm32vldiscovery: allow overriding of RAM size

PATCH In review Lucas Villa Real 4 participants 5 messages Apr 3, 2023 – Apr 4, 2023 Arm STM32

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 stm32vldiscovery: allow overriding of RAM size

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.

---
 hw/arm/stm32vldiscovery.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/arm/stm32vldiscovery.c +6 -0
index 67675e952f..7ca3ba029e 100644
@@ -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)
Signature · 1 line
2.37.1 (Apple Git-137.1)
#1 lore raw
Quoted 11 lines · Lucas Villa Real

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.

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

thanks
-- PMM

#2 lore raw
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Lucas Villa Real

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.

Quoted 7 lines
Quoted 1 line

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

#3 lore raw
Quoted 21 lines · Lucas C. Villa Real

On Mon, Apr 3, 2023 at 10:54 AM Peter Maydell <[email protected] <mailto:[email protected]>> wrote:

On Mon, 3 Apr 2023 at 13:51, Lucas Villa Real <[email protected] <mailto:[email protected]>> 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 <[email protected]
<mailto:[email protected]>>

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

Quoted 9 lines

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,

Signature · 1 line
Alexandre
#4 lore raw
Quoted 48 lines · Alexandre IOOSS
Quoted 14 lines · Lucas C. Villa Real

On Mon, Apr 3, 2023 at 10:54 AM Peter Maydell <[email protected] <mailto:[email protected]>> wrote:

On Mon, 3 Apr 2023 at 13:51, Lucas Villa Real <[email protected] <mailto:[email protected]>> 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

Quoted 1 line

> value provided on that command line argument. If absent, the

default

Quoted 18 lines

> value of 8KB still applies.
>
> Signed-off-by: Lucas Villa Real <[email protected]
<mailto:[email protected]>>

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.

Quoted 3 lines

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).

Quoted 8 lines

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