From 2dad5d479e73b35f16a8b65a75129a1eab6f021a Mon Sep 17 00:00:00 2001 From: SHONG0504 Date: Thu, 12 Mar 2026 14:08:49 -0400 Subject: [PATCH] WIP --- .../Peripherals/Miscellaneous/STM32F0_RCC.cs | 89 +++++++++++++++++++ .../Peripherals/Miscellaneous/STM32F4_RCC.cs | 1 + .../Peripherals/Timers/STM32F0_RTC.cs | 20 +++++ src/Infrastructure.csproj | 2 + 4 files changed, 112 insertions(+) create mode 100644 src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F0_RCC.cs create mode 100644 src/Emulator/Peripherals/Peripherals/Timers/STM32F0_RTC.cs diff --git a/src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F0_RCC.cs b/src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F0_RCC.cs new file mode 100644 index 000000000..59bf0bcea --- /dev/null +++ b/src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F0_RCC.cs @@ -0,0 +1,89 @@ +using System.Collections.Generic; + +using Antmicro.Renode.Core; +using Antmicro.Renode.Core.Structure.Registers; +using Antmicro.Renode.Peripherals.Bus; +using Antmicro.Renode.Peripherals.Timers; + +namespace Antmicro.Renode.Peripherals.Miscellaneous +{ + [AllowedTranslations(AllowedTranslation.ByteToDoubleWord | AllowedTranslation.WordToDoubleWord)] + public sealed class STM32F0_RCC : IDoubleWordPeripheral, IKnownSize, IProvidesRegisterCollection + { + public STM32F0_RCC(IMachine machine) + { + var registersMap = new Dictionary + { + {(long)Registers.RCC_CR, new DoubleWordRegister(this, 0x00000083) // 0x0000XX83 + .WithFlag(0, out var hsion, name: "HSION") + .WithFlag(1, FieldMode.Read, valueProviderCallback: _ => hsion.Value, name: "HSIRDY") + .WithReservedBits(2, 1) + .WithValueField(3, 5, out var hsitrim, name: "HSITRIM") + .WithTag("HSICAL", 8, 8) + .WithFlag(16, out var hseon, name: "HSEON") + .WithFlag(17, FieldMode.Read, valueProviderCallback: _ => hseon.Value, name: "HSERDY") + .WithTag("HSEBYP", 18, 1) + .WithTag("CSSON", 19, 1) + .WithReservedBits(20, 4) + .WithFlag(24, out var pllon, name: "PLLON") + .WithFlag(25, FieldMode.Read, valueProviderCallback: _ => pllon.Value, name: "PLLRDY") + .WithReservedBits(26, 6) + }, + {(long)Registers.RCC_CFGR, new DoubleWordRegister(this, 0x00000000) + }, + {(long)Registers.RCC_CIR, new DoubleWordRegister(this, 0x00000000) + }, + {(long)Registers.RCC_APB2RSTR, new DoubleWordRegister(this, 0x00000000) + }, + {(long)Registers.RCC_APB1RSTR, new DoubleWordRegister(this, 0x00000000) + }, + {(long)Registers.RCC_AHBENR, new DoubleWordRegister(this, 0x00000014) + }, + {(long)Registers.RCC_APB2ENR, new DoubleWordRegister(this, 0x00000000) + }, + {(long)Registers.RCC_APB1ENR, new DoubleWordRegister(this, 0x00000000) + }, + {(long)Registers.RCC_BDCR, new DoubleWordRegister(this, 0x00000018) + }, + }; + RegistersCollection = new DoubleWordRegisterCollection(this, registersMap); + } + + public uint ReadDoubleWord(long offset) + { + return RegistersCollection.Read(offset); + } + + public void WriteDoubleWord(long offset, uint value) + { + RegistersCollection.Write(offset, value); + } + + public void Reset() + { + RegistersCollection.Reset(); + } + + public long Size => 0x400; // 1kB + + public DoubleWordRegisterCollection RegistersCollection { get; } + + private enum Registers + { + RCC_CR = 0x00, + RCC_CFGR = 0x04, + RCC_CIR = 0x08, + RCC_APB2RSTR = 0x0C, + RCC_APB1RSTR = 0x10, + RCC_AHBENR = 0x14, + RCC_APB2ENR = 0x18, + RCC_APB1ENR = 0x1C, + RCC_BDCR = 0x20, + RCC_CSR = 0x24, + RCC_AHBRSTR = 0x28, + RCC_CFGR2 = 0x2C, + RCC_CFGR3 = 0x30, + RCC_CR2 = 0x34 + } + } +} \ No newline at end of file diff --git a/src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F4_RCC.cs b/src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F4_RCC.cs index 02636e0af..8880dc7cb 100644 --- a/src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F4_RCC.cs +++ b/src/Emulator/Peripherals/Peripherals/Miscellaneous/STM32F4_RCC.cs @@ -34,6 +34,7 @@ public STM32F4_RCC(IMachine machine, STM32F4_RTC rtcPeripheral) // peripherals or their clocks. var registersMap = new Dictionary { + // Possible bug? Reset value is 0x0000XX83 for STM32F405/407/415/417/42x/43x and 0x0000XX81 for STM32F401 but is being set to 0x483 here {(long)Registers.ClockControl, new DoubleWordRegister(this, 0x483) .WithFlag(0, out var hsion, name: "HSION") .WithFlag(1, FieldMode.Read, valueProviderCallback: _ => hsion.Value, name: "HSIRDY") diff --git a/src/Emulator/Peripherals/Peripherals/Timers/STM32F0_RTC.cs b/src/Emulator/Peripherals/Peripherals/Timers/STM32F0_RTC.cs new file mode 100644 index 000000000..187e52ab5 --- /dev/null +++ b/src/Emulator/Peripherals/Peripherals/Timers/STM32F0_RTC.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +using Antmicro.Renode.Core; +using Antmicro.Renode.Core.Structure.Registers; +using Antmicro.Renode.Logging; +using Antmicro.Renode.Peripherals.Bus; +using Antmicro.Renode.Time; +using Antmicro.Renode.Utilities; + +// namespace Antmicro.Renode.Peripherals.Timers +// { +// public class STM32F0_RTC : IDoubleWordPeripheral, IKnownSize +// { +// public STM32F0_RTC(IMachine machine, ulong wakeupTimerFrequency = DefaultWakeupTimerFrequency) +// { + +// } +// } +// } \ No newline at end of file diff --git a/src/Infrastructure.csproj b/src/Infrastructure.csproj index 5265d50bf..b4c22ba25 100644 --- a/src/Infrastructure.csproj +++ b/src/Infrastructure.csproj @@ -817,6 +817,7 @@ + BitBanding.tt @@ -994,6 +995,7 @@ +