stm32vldiscovery.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * ST STM32VLDISCOVERY machine
  3. *
  4. * Copyright (c) 2021 Alexandre Iooss <erdnaxe@crans.org>
  5. * Copyright (c) 2014 Alistair Francis <alistair@alistair23.me>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  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/stm32f100_soc.h"
  32. #include "hw/arm/boot.h"
  33. /* stm32vldiscovery implementation is derived from netduinoplus2 */
  34. /* Main SYSCLK frequency in Hz (24MHz) */
  35. #define SYSCLK_FRQ 24000000ULL
  36. static void stm32vldiscovery_init(MachineState *machine)
  37. {
  38. DeviceState *dev;
  39. Clock *sysclk;
  40. /* This clock doesn't need migration because it is fixed-frequency */
  41. sysclk = clock_new(OBJECT(machine), "SYSCLK");
  42. clock_set_hz(sysclk, SYSCLK_FRQ);
  43. dev = qdev_new(TYPE_STM32F100_SOC);
  44. object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
  45. qdev_connect_clock_in(dev, "sysclk", sysclk);
  46. sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
  47. armv7m_load_kernel(STM32F100_SOC(dev)->armv7m.cpu,
  48. machine->kernel_filename,
  49. 0, FLASH_SIZE);
  50. }
  51. static void stm32vldiscovery_machine_init(MachineClass *mc)
  52. {
  53. static const char * const valid_cpu_types[] = {
  54. ARM_CPU_TYPE_NAME("cortex-m3"),
  55. NULL
  56. };
  57. mc->desc = "ST STM32VLDISCOVERY (Cortex-M3)";
  58. mc->init = stm32vldiscovery_init;
  59. mc->valid_cpu_types = valid_cpu_types;
  60. }
  61. DEFINE_MACHINE("stm32vldiscovery", stm32vldiscovery_machine_init)