Advertisement
Guest User

Untitled

a guest
Nov 1st, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. #include "qemu/osdep.h"
  2. #include "qemu/units.h"
  3. #include "qemu/cutils.h"
  4. #include "qapi/error.h"
  5. #include "qemu/error-report.h"
  6. #include "hw/arm/boot.h"
  7. #include "hw/arm/armv7m.h"
  8. #include "hw/or-irq.h"
  9. #include "hw/boards.h"
  10. #include "exec/address-spaces.h"
  11. #include "sysemu/sysemu.h"
  12. #include "hw/qdev-properties.h"
  13. #include "hw/misc/unimp.h"
  14. #include "hw/char/cmsdk-apb-uart.h"
  15. #include "hw/timer/cmsdk-apb-timer.h"
  16. #include "hw/timer/cmsdk-apb-dualtimer.h"
  17. #include "hw/misc/mps2-scc.h"
  18. #include "hw/misc/mps2-fpgaio.h"
  19. #include "hw/ssi/pl022.h"
  20. #include "hw/i2c/arm_sbcon_i2c.h"
  21. #include "hw/net/lan9118.h"
  22. #include "net/net.h"
  23. #include "hw/watchdog/cmsdk-apb-watchdog.h"
  24. #include "hw/qdev-clock.h"
  25. #include "qom/object.h"
  26.  
  27.  
  28. #define TYPE_STM32WB5MMGH6TR_MACHINE MACHINE_TYPE_NAME("stm32wb5mmgh6tr")
  29. #define STM32WB5MMGH6TR_MACHINE(obj) \
  30. OBJECT_CHECK(STM32WB5MMGH6TRMachineState, (obj), TYPE_STM32WB5MMGH6TR_MACHINE)
  31.  
  32. /* Main SYSCLK frequency in Hz */
  33. #define SYSCLK_FRQ 25000000
  34. #define REFCLK_FRQ (1 * 1000 * 1000)
  35.  
  36. #define FLASH_BASE_ADDR 0x08000000
  37. #define FLASH_SIZE (1 * MiB)
  38.  
  39. #define SRAM1_BASE_ADDR 0x20000000
  40. #define SRAM1_SIZE (256 * KiB)
  41.  
  42. #define SRAM2_BASE_ADDR 0x10000000
  43. #define SRAM2_SIZE (128 * KiB)
  44.  
  45. typedef struct STM32WB5MMGH6TRMachineState {
  46. MachineState parent;
  47. ARMv7MState armv7m;
  48. MemoryRegion flash;
  49. MemoryRegion sram1;
  50. MemoryRegion sram2;
  51. Clock *sysclk;
  52. Clock *refclk;
  53. } STM32WB5MMGH6TRMachineState;
  54.  
  55. static void stm32wb5mmgh6tr_init(MachineState *machine)
  56. {
  57. STM32WB5MMGH6TRMachineState *sms = STM32WB5MMGH6TR_MACHINE(machine);
  58. MachineClass *mc = MACHINE_GET_CLASS(machine);
  59. DeviceState *armv7m;
  60.  
  61. /* This clock doesn't need migration because it is fixed-frequency */
  62. sms->sysclk = clock_new(OBJECT(machine), "SYSCLK");
  63. clock_set_hz(sms->sysclk, SYSCLK_FRQ);
  64.  
  65. sms->refclk = clock_new(OBJECT(machine), "REFCLK");
  66. clock_set_hz(sms->refclk, REFCLK_FRQ);
  67.  
  68. // Initialization code here...
  69. object_initialize_child(OBJECT(sms), "armv7m", &sms->armv7m, TYPE_ARMV7M);
  70. armv7m = DEVICE(&sms->armv7m);
  71.  
  72. qdev_connect_clock_in(armv7m, "cpuclk", sms->sysclk);
  73. qdev_connect_clock_in(armv7m, "refclk", sms->refclk);
  74. qdev_prop_set_string(armv7m, "cpu-type", mc->default_cpu_type);
  75. object_property_set_link(OBJECT(&sms->armv7m), "memory",
  76. OBJECT(get_system_memory()), &error_abort);
  77. sysbus_realize(SYS_BUS_DEVICE(&sms->armv7m), &error_fatal);
  78.  
  79. // Initialize Flash
  80. memory_region_init_ram(&sms->flash, OBJECT(machine), "stm32wb5mmgh6tr.flash", FLASH_SIZE, &error_fatal);
  81. memory_region_add_subregion(get_system_memory(), FLASH_BASE_ADDR, &sms->flash);
  82.  
  83. // Initialize SRAM1
  84. memory_region_init_ram(&sms->sram1, OBJECT(machine), "stm32wb5mmgh6tr.sram1", SRAM1_SIZE, &error_fatal);
  85. memory_region_add_subregion(get_system_memory(), SRAM1_BASE_ADDR, &sms->sram1);
  86.  
  87. // Initialize SRAM2
  88. memory_region_init_ram(&sms->sram2, OBJECT(machine), "stm32wb5mmgh6tr.sram2", SRAM2_SIZE, &error_fatal);
  89. memory_region_add_subregion(get_system_memory(), SRAM2_BASE_ADDR, &sms->sram2);
  90.  
  91.  
  92. // Load kernel
  93. // armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
  94. // 0x20000000, 512 * 1024); // Adjust these values as per STM32WB5MMGH6TR specs
  95. }
  96.  
  97. static void stm32wb5mmgh6tr_class_init(ObjectClass *oc, void *data)
  98. {
  99. MachineClass *mc = MACHINE_CLASS(oc);
  100.  
  101. mc->desc = "STM32WB5MMGH6TR Board";
  102. mc->init = stm32wb5mmgh6tr_init;
  103. mc->max_cpus = 1;
  104. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
  105. }
  106.  
  107. static const TypeInfo stm32wb5mmgh6tr_machine_info = {
  108. .name = TYPE_STM32WB5MMGH6TR_MACHINE,
  109. .parent = TYPE_MACHINE,
  110. .instance_size = sizeof(STM32WB5MMGH6TRMachineState),
  111. .class_init = stm32wb5mmgh6tr_class_init,
  112. };
  113.  
  114. static void stm32wb5mmgh6tr_machine_init(void)
  115. {
  116. type_register_static(&stm32wb5mmgh6tr_machine_info);
  117. }
  118.  
  119. type_init(stm32wb5mmgh6tr_machine_init);
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement