xref: /openbmc/qemu/hw/arm/b-l475e-iot01a.c (revision 988f2442)
1 /*
2  * B-L475E-IOT01A Discovery Kit machine
3  * (B-L475E-IOT01A IoT Node)
4  *
5  * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr>
6  * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr>
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  *
10  * This work is licensed under the terms of the GNU GPL, version 2 or later.
11  * See the COPYING file in the top-level directory.
12  *
13  * This work is heavily inspired by the netduinoplus2 by Alistair Francis.
14  * Original code is licensed under the MIT License:
15  *
16  * Copyright (c) 2014 Alistair Francis <alistair@alistair23.me>
17  */
18 
19 /*
20  * The reference used is the STMicroElectronics UM2153 User manual
21  * Discovery kit for IoT node, multi-channel communication with STM32L4.
22  * https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html#documentation
23  */
24 
25 #include "qemu/osdep.h"
26 #include "qapi/error.h"
27 #include "hw/boards.h"
28 #include "hw/qdev-properties.h"
29 #include "hw/qdev-clock.h"
30 #include "qemu/error-report.h"
31 #include "hw/arm/stm32l4x5_soc.h"
32 #include "hw/arm/boot.h"
33 
34 /* Main SYSCLK frequency in Hz (80MHz) */
35 #define MAIN_SYSCLK_FREQ_HZ 80000000ULL
36 
37 static void b_l475e_iot01a_init(MachineState *machine)
38 {
39     const Stm32l4x5SocClass *sc;
40     DeviceState *dev;
41     Clock *sysclk;
42 
43     /* This clock doesn't need migration because it is fixed-frequency */
44     sysclk = clock_new(OBJECT(machine), "SYSCLK");
45     clock_set_hz(sysclk, MAIN_SYSCLK_FREQ_HZ);
46 
47     dev = qdev_new(TYPE_STM32L4X5XG_SOC);
48     object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
49     qdev_connect_clock_in(dev, "sysclk", sysclk);
50     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
51 
52     sc = STM32L4X5_SOC_GET_CLASS(dev);
53     armv7m_load_kernel(ARM_CPU(first_cpu),
54                        machine->kernel_filename,
55                        0, sc->flash_size);
56 }
57 
58 static void b_l475e_iot01a_machine_init(MachineClass *mc)
59 {
60     static const char *machine_valid_cpu_types[] = {
61         ARM_CPU_TYPE_NAME("cortex-m4"),
62         NULL
63     };
64     mc->desc = "B-L475E-IOT01A Discovery Kit (Cortex-M4)";
65     mc->init = b_l475e_iot01a_init;
66     mc->valid_cpu_types = machine_valid_cpu_types;
67 
68     /* SRAM pre-allocated as part of the SoC instantiation */
69     mc->default_ram_size = 0;
70 }
71 
72 DEFINE_MACHINE("b-l475e-iot01a", b_l475e_iot01a_machine_init)
73