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