141581f13SInès Varhol /* 241581f13SInès Varhol * B-L475E-IOT01A Discovery Kit machine 341581f13SInès Varhol * (B-L475E-IOT01A IoT Node) 441581f13SInès Varhol * 5*4c3308c6SInès Varhol * Copyright (c) 2023-2024 Arnaud Minier <arnaud.minier@telecom-paris.fr> 6*4c3308c6SInès Varhol * Copyright (c) 2023-2024 Inès Varhol <ines.varhol@telecom-paris.fr> 741581f13SInès Varhol * 841581f13SInès Varhol * SPDX-License-Identifier: GPL-2.0-or-later 941581f13SInès Varhol * 1041581f13SInès Varhol * This work is licensed under the terms of the GNU GPL, version 2 or later. 1141581f13SInès Varhol * See the COPYING file in the top-level directory. 1241581f13SInès Varhol * 1341581f13SInès Varhol * This work is heavily inspired by the netduinoplus2 by Alistair Francis. 1441581f13SInès Varhol * Original code is licensed under the MIT License: 1541581f13SInès Varhol * 1641581f13SInès Varhol * Copyright (c) 2014 Alistair Francis <alistair@alistair23.me> 1741581f13SInès Varhol */ 1841581f13SInès Varhol 1941581f13SInès Varhol /* 2041581f13SInès Varhol * The reference used is the STMicroElectronics UM2153 User manual 2141581f13SInès Varhol * Discovery kit for IoT node, multi-channel communication with STM32L4. 2241581f13SInès Varhol * https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html#documentation 2341581f13SInès Varhol */ 2441581f13SInès Varhol 2541581f13SInès Varhol #include "qemu/osdep.h" 2641581f13SInès Varhol #include "qapi/error.h" 2741581f13SInès Varhol #include "hw/boards.h" 2841581f13SInès Varhol #include "hw/qdev-properties.h" 2941581f13SInès Varhol #include "qemu/error-report.h" 3041581f13SInès Varhol #include "hw/arm/stm32l4x5_soc.h" 3141581f13SInès Varhol #include "hw/arm/boot.h" 3241581f13SInès Varhol 3360849fe4SArnaud Minier /* B-L475E-IOT01A implementation is derived from netduinoplus2 */ 3441581f13SInès Varhol 35*4c3308c6SInès Varhol #define TYPE_B_L475E_IOT01A MACHINE_TYPE_NAME("b-l475e-iot01a") 36*4c3308c6SInès Varhol OBJECT_DECLARE_SIMPLE_TYPE(Bl475eMachineState, B_L475E_IOT01A) 37*4c3308c6SInès Varhol 38*4c3308c6SInès Varhol typedef struct Bl475eMachineState { 39*4c3308c6SInès Varhol MachineState parent_obj; 40*4c3308c6SInès Varhol 41*4c3308c6SInès Varhol Stm32l4x5SocState soc; 42*4c3308c6SInès Varhol } Bl475eMachineState; 43*4c3308c6SInès Varhol 44*4c3308c6SInès Varhol static void bl475e_init(MachineState *machine) 4541581f13SInès Varhol { 46*4c3308c6SInès Varhol Bl475eMachineState *s = B_L475E_IOT01A(machine); 4741581f13SInès Varhol const Stm32l4x5SocClass *sc; 4841581f13SInès Varhol 49*4c3308c6SInès Varhol object_initialize_child(OBJECT(machine), "soc", &s->soc, 50*4c3308c6SInès Varhol TYPE_STM32L4X5XG_SOC); 51*4c3308c6SInès Varhol sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal); 5241581f13SInès Varhol 53*4c3308c6SInès Varhol sc = STM32L4X5_SOC_GET_CLASS(&s->soc); 54*4c3308c6SInès Varhol armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0, 55*4c3308c6SInès Varhol sc->flash_size); 5641581f13SInès Varhol } 5741581f13SInès Varhol 58*4c3308c6SInès Varhol static void bl475e_machine_init(ObjectClass *oc, void *data) 5941581f13SInès Varhol { 60*4c3308c6SInès Varhol MachineClass *mc = MACHINE_CLASS(oc); 6141581f13SInès Varhol static const char *machine_valid_cpu_types[] = { 6241581f13SInès Varhol ARM_CPU_TYPE_NAME("cortex-m4"), 6341581f13SInès Varhol NULL 6441581f13SInès Varhol }; 6541581f13SInès Varhol mc->desc = "B-L475E-IOT01A Discovery Kit (Cortex-M4)"; 66*4c3308c6SInès Varhol mc->init = bl475e_init; 6741581f13SInès Varhol mc->valid_cpu_types = machine_valid_cpu_types; 6841581f13SInès Varhol 6941581f13SInès Varhol /* SRAM pre-allocated as part of the SoC instantiation */ 7041581f13SInès Varhol mc->default_ram_size = 0; 7141581f13SInès Varhol } 7241581f13SInès Varhol 73*4c3308c6SInès Varhol static const TypeInfo bl475e_machine_type[] = { 74*4c3308c6SInès Varhol { 75*4c3308c6SInès Varhol .name = TYPE_B_L475E_IOT01A, 76*4c3308c6SInès Varhol .parent = TYPE_MACHINE, 77*4c3308c6SInès Varhol .instance_size = sizeof(Bl475eMachineState), 78*4c3308c6SInès Varhol .class_init = bl475e_machine_init, 79*4c3308c6SInès Varhol } 80*4c3308c6SInès Varhol }; 81*4c3308c6SInès Varhol 82*4c3308c6SInès Varhol DEFINE_TYPES(bl475e_machine_type) 83