xref: /qemu/hw/arm/olimex-stm32-h405.c (revision ee5bffa9fce10a3b191fe35279e2460e0a1ba320)
1*ee5bffa9SFelipe Balbi /*
2*ee5bffa9SFelipe Balbi  * ST STM32VLDISCOVERY machine
3*ee5bffa9SFelipe Balbi  * Olimex STM32-H405 machine
4*ee5bffa9SFelipe Balbi  *
5*ee5bffa9SFelipe Balbi  * Copyright (c) 2022 Felipe Balbi <balbi@kernel.org>
6*ee5bffa9SFelipe Balbi  *
7*ee5bffa9SFelipe Balbi  * Permission is hereby granted, free of charge, to any person obtaining a copy
8*ee5bffa9SFelipe Balbi  * of this software and associated documentation files (the "Software"), to deal
9*ee5bffa9SFelipe Balbi  * in the Software without restriction, including without limitation the rights
10*ee5bffa9SFelipe Balbi  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11*ee5bffa9SFelipe Balbi  * copies of the Software, and to permit persons to whom the Software is
12*ee5bffa9SFelipe Balbi  * furnished to do so, subject to the following conditions:
13*ee5bffa9SFelipe Balbi  *
14*ee5bffa9SFelipe Balbi  * The above copyright notice and this permission notice shall be included in
15*ee5bffa9SFelipe Balbi  * all copies or substantial portions of the Software.
16*ee5bffa9SFelipe Balbi  *
17*ee5bffa9SFelipe Balbi  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*ee5bffa9SFelipe Balbi  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*ee5bffa9SFelipe Balbi  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*ee5bffa9SFelipe Balbi  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21*ee5bffa9SFelipe Balbi  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22*ee5bffa9SFelipe Balbi  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23*ee5bffa9SFelipe Balbi  * THE SOFTWARE.
24*ee5bffa9SFelipe Balbi  */
25*ee5bffa9SFelipe Balbi 
26*ee5bffa9SFelipe Balbi #include "qemu/osdep.h"
27*ee5bffa9SFelipe Balbi #include "qapi/error.h"
28*ee5bffa9SFelipe Balbi #include "hw/boards.h"
29*ee5bffa9SFelipe Balbi #include "hw/qdev-properties.h"
30*ee5bffa9SFelipe Balbi #include "hw/qdev-clock.h"
31*ee5bffa9SFelipe Balbi #include "qemu/error-report.h"
32*ee5bffa9SFelipe Balbi #include "hw/arm/stm32f405_soc.h"
33*ee5bffa9SFelipe Balbi #include "hw/arm/boot.h"
34*ee5bffa9SFelipe Balbi 
35*ee5bffa9SFelipe Balbi /* olimex-stm32-h405 implementation is derived from netduinoplus2 */
36*ee5bffa9SFelipe Balbi 
37*ee5bffa9SFelipe Balbi /* Main SYSCLK frequency in Hz (168MHz) */
38*ee5bffa9SFelipe Balbi #define SYSCLK_FRQ 168000000ULL
39*ee5bffa9SFelipe Balbi 
40*ee5bffa9SFelipe Balbi static void olimex_stm32_h405_init(MachineState *machine)
41*ee5bffa9SFelipe Balbi {
42*ee5bffa9SFelipe Balbi     DeviceState *dev;
43*ee5bffa9SFelipe Balbi     Clock *sysclk;
44*ee5bffa9SFelipe Balbi 
45*ee5bffa9SFelipe Balbi     /* This clock doesn't need migration because it is fixed-frequency */
46*ee5bffa9SFelipe Balbi     sysclk = clock_new(OBJECT(machine), "SYSCLK");
47*ee5bffa9SFelipe Balbi     clock_set_hz(sysclk, SYSCLK_FRQ);
48*ee5bffa9SFelipe Balbi 
49*ee5bffa9SFelipe Balbi     dev = qdev_new(TYPE_STM32F405_SOC);
50*ee5bffa9SFelipe Balbi     qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4"));
51*ee5bffa9SFelipe Balbi     qdev_connect_clock_in(dev, "sysclk", sysclk);
52*ee5bffa9SFelipe Balbi     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
53*ee5bffa9SFelipe Balbi 
54*ee5bffa9SFelipe Balbi     armv7m_load_kernel(ARM_CPU(first_cpu),
55*ee5bffa9SFelipe Balbi                        machine->kernel_filename,
56*ee5bffa9SFelipe Balbi                        0, FLASH_SIZE);
57*ee5bffa9SFelipe Balbi }
58*ee5bffa9SFelipe Balbi 
59*ee5bffa9SFelipe Balbi static void olimex_stm32_h405_machine_init(MachineClass *mc)
60*ee5bffa9SFelipe Balbi {
61*ee5bffa9SFelipe Balbi     mc->desc = "Olimex STM32-H405 (Cortex-M4)";
62*ee5bffa9SFelipe Balbi     mc->init = olimex_stm32_h405_init;
63*ee5bffa9SFelipe Balbi     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
64*ee5bffa9SFelipe Balbi 
65*ee5bffa9SFelipe Balbi     /* SRAM pre-allocated as part of the SoC instantiation */
66*ee5bffa9SFelipe Balbi     mc->default_ram_size = 0;
67*ee5bffa9SFelipe Balbi }
68*ee5bffa9SFelipe Balbi 
69*ee5bffa9SFelipe Balbi DEFINE_MACHINE("olimex-stm32-h405", olimex_stm32_h405_machine_init)
70