xref: /qemu/hw/arm/stm32vldiscovery.c (revision f503bc4b)
12ac2410cSAlexandre Iooss /*
22ac2410cSAlexandre Iooss  * ST STM32VLDISCOVERY machine
32ac2410cSAlexandre Iooss  *
42ac2410cSAlexandre Iooss  * Copyright (c) 2021 Alexandre Iooss <erdnaxe@crans.org>
52ac2410cSAlexandre Iooss  * Copyright (c) 2014 Alistair Francis <alistair@alistair23.me>
62ac2410cSAlexandre Iooss  *
72ac2410cSAlexandre Iooss  * Permission is hereby granted, free of charge, to any person obtaining a copy
82ac2410cSAlexandre Iooss  * of this software and associated documentation files (the "Software"), to deal
92ac2410cSAlexandre Iooss  * in the Software without restriction, including without limitation the rights
102ac2410cSAlexandre Iooss  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
112ac2410cSAlexandre Iooss  * copies of the Software, and to permit persons to whom the Software is
122ac2410cSAlexandre Iooss  * furnished to do so, subject to the following conditions:
132ac2410cSAlexandre Iooss  *
142ac2410cSAlexandre Iooss  * The above copyright notice and this permission notice shall be included in
152ac2410cSAlexandre Iooss  * all copies or substantial portions of the Software.
162ac2410cSAlexandre Iooss  *
172ac2410cSAlexandre Iooss  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
182ac2410cSAlexandre Iooss  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
192ac2410cSAlexandre Iooss  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
202ac2410cSAlexandre Iooss  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
212ac2410cSAlexandre Iooss  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
222ac2410cSAlexandre Iooss  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
232ac2410cSAlexandre Iooss  * THE SOFTWARE.
242ac2410cSAlexandre Iooss  */
252ac2410cSAlexandre Iooss 
262ac2410cSAlexandre Iooss #include "qemu/osdep.h"
272ac2410cSAlexandre Iooss #include "qapi/error.h"
282ac2410cSAlexandre Iooss #include "hw/boards.h"
292ac2410cSAlexandre Iooss #include "hw/qdev-properties.h"
30b5ff0c61SPeter Maydell #include "hw/qdev-clock.h"
312ac2410cSAlexandre Iooss #include "qemu/error-report.h"
322ac2410cSAlexandre Iooss #include "hw/arm/stm32f100_soc.h"
332ac2410cSAlexandre Iooss #include "hw/arm/boot.h"
342ac2410cSAlexandre Iooss 
352ac2410cSAlexandre Iooss /* stm32vldiscovery implementation is derived from netduinoplus2 */
362ac2410cSAlexandre Iooss 
372ac2410cSAlexandre Iooss /* Main SYSCLK frequency in Hz (24MHz) */
382ac2410cSAlexandre Iooss #define SYSCLK_FRQ 24000000ULL
392ac2410cSAlexandre Iooss 
stm32vldiscovery_init(MachineState * machine)402ac2410cSAlexandre Iooss static void stm32vldiscovery_init(MachineState *machine)
412ac2410cSAlexandre Iooss {
422ac2410cSAlexandre Iooss     DeviceState *dev;
43b5ff0c61SPeter Maydell     Clock *sysclk;
442ac2410cSAlexandre Iooss 
45b5ff0c61SPeter Maydell     /* This clock doesn't need migration because it is fixed-frequency */
46b5ff0c61SPeter Maydell     sysclk = clock_new(OBJECT(machine), "SYSCLK");
47b5ff0c61SPeter Maydell     clock_set_hz(sysclk, SYSCLK_FRQ);
48b5ff0c61SPeter Maydell 
492ac2410cSAlexandre Iooss     dev = qdev_new(TYPE_STM32F100_SOC);
50f503bc4bSPhilippe Mathieu-Daudé     object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
51b5ff0c61SPeter Maydell     qdev_connect_clock_in(dev, "sysclk", sysclk);
522ac2410cSAlexandre Iooss     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
532ac2410cSAlexandre Iooss 
542ac2410cSAlexandre Iooss     armv7m_load_kernel(ARM_CPU(first_cpu),
552ac2410cSAlexandre Iooss                        machine->kernel_filename,
56761c532aSPeter Maydell                        0, FLASH_SIZE);
572ac2410cSAlexandre Iooss }
582ac2410cSAlexandre Iooss 
stm32vldiscovery_machine_init(MachineClass * mc)592ac2410cSAlexandre Iooss static void stm32vldiscovery_machine_init(MachineClass *mc)
602ac2410cSAlexandre Iooss {
61d6528660SPhilippe Mathieu-Daudé     static const char * const valid_cpu_types[] = {
62d6528660SPhilippe Mathieu-Daudé         ARM_CPU_TYPE_NAME("cortex-m3"),
63d6528660SPhilippe Mathieu-Daudé         NULL
64d6528660SPhilippe Mathieu-Daudé     };
65d6528660SPhilippe Mathieu-Daudé 
662ac2410cSAlexandre Iooss     mc->desc = "ST STM32VLDISCOVERY (Cortex-M3)";
672ac2410cSAlexandre Iooss     mc->init = stm32vldiscovery_init;
68d6528660SPhilippe Mathieu-Daudé     mc->valid_cpu_types = valid_cpu_types;
692ac2410cSAlexandre Iooss }
702ac2410cSAlexandre Iooss 
712ac2410cSAlexandre Iooss DEFINE_MACHINE("stm32vldiscovery", stm32vldiscovery_machine_init)
72