File tree Expand file tree Collapse file tree 6 files changed +22
-23
lines changed
Expand file tree Collapse file tree 6 files changed +22
-23
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ using namespace modm::literals;
3535// / supplied by the on-board st-link
3636struct SystemClock
3737{
38+ static constexpr uint32_t Hse = 8_MHz;
3839 static constexpr uint32_t Frequency = 72_MHz;
3940 static constexpr uint32_t Ahb = Frequency;
4041 static constexpr uint32_t Apb1 = Frequency / 2 ;
@@ -89,13 +90,12 @@ struct SystemClock
8990
9091 static constexpr uint32_t Usb = Ahb / 1.5 ;
9192 static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
92- static constexpr uint32_t Rtc = Rcc::LsiFrequency ;
93+ static constexpr uint32_t Rtc = Hse / 32 ;
9394
9495 static bool inline
9596 enable ()
9697 {
97- Rcc::enableLowSpeedInternalClock ();
98- Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::Lsi);
98+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::ExternalClock);
9999
100100 Rcc::enableExternalClock (); // 8MHz
101101 const Rcc::PllFactors pllFactors{
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ using namespace modm::literals;
3636// / STM32F401 running at 168MHz generated from the external 8MHz crystal
3737struct SystemClock
3838{
39+ static constexpr uint32_t Hse = 8_MHz;
3940 static constexpr uint32_t Frequency = 84_MHz;
4041 static constexpr uint32_t Ahb = Frequency;
4142 static constexpr uint32_t Apb1 = Frequency / 4 ;
@@ -72,15 +73,14 @@ struct SystemClock
7273
7374 static constexpr uint32_t Usb = 48_MHz;
7475 static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
75- static constexpr uint32_t Rtc = Rcc::LsiFrequency ;
76+ static constexpr uint32_t Rtc = Hse / 25 ;
7677
7778 static bool inline
7879 enable ()
7980 {
80- Rcc::enableLowSpeedInternalClock ();
81- Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::Lsi);
82-
8381 Rcc::enableExternalCrystal (); // 8MHz
82+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::ExternalClock, 25 );
83+
8484 const Rcc::PllFactors pllFactors{
8585 .pllM = 4 , // 8MHz / M=4 -> 2MHz
8686 .pllN = 168 , // 2MHz * N=168 -> 336MHz
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ using namespace modm::literals;
3434// / STM32F407 running at 168MHz generated from the external 8MHz crystal
3535struct SystemClock
3636{
37+ static constexpr uint32_t Hse = 8_MHz;
3738 static constexpr uint32_t Frequency = 168_MHz;
3839 static constexpr uint32_t Ahb = Frequency;
3940 static constexpr uint32_t Apb1 = Frequency / 4 ;
@@ -83,15 +84,14 @@ struct SystemClock
8384
8485 static constexpr uint32_t Usb = 48_MHz;
8586 static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
86- static constexpr uint32_t Rtc = Rcc::LsiFrequency ;
87+ static constexpr uint32_t Rtc = Hse / 25 ;
8788
8889 static bool inline
8990 enable ()
9091 {
91- Rcc::enableLowSpeedInternalClock ();
92- Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::Lsi);
93-
9492 Rcc::enableExternalCrystal (); // 8MHz
93+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::ExternalClock, 25 );
94+
9595 const Rcc::PllFactors pllFactors{
9696 .pllM = 4 , // 8MHz / M=4 -> 2MHz
9797 .pllN = 168 , // 2MHz * N=168 -> 336MHz
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ using namespace modm::literals;
2929// / STM32F411 running at 96MHz generated from the external 8MHz crystal
3030struct SystemClock
3131{
32+ static constexpr uint32_t Hse = 8_MHz;
3233 static constexpr uint32_t Frequency = 96_MHz;
3334 static constexpr uint32_t Ahb = Frequency;
3435 static constexpr uint32_t Apb1 = Frequency / 2 ;
@@ -68,15 +69,14 @@ struct SystemClock
6869
6970 static constexpr uint32_t Usb = 48_MHz;
7071 static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
71- static constexpr uint32_t Rtc = Rcc::LsiFrequency ;
72+ static constexpr uint32_t Rtc = Hse / 25 ;
7273
7374 static bool inline
7475 enable ()
7576 {
76- Rcc::enableLowSpeedInternalClock ();
77- Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::Lsi);
78-
7977 Rcc::enableExternalCrystal (); // 8MHz
78+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::ExternalClock, 25 );
79+
8080 const Rcc::PllFactors pllFactors{
8181 .pllM = 7 , // 8MHz / M=7 -> ~1.14MHz
8282 .pllN = 336 , // 1.14MHz * N=336 -> 384MHz
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ using namespace modm::literals;
3232// / STM32F429 running at 168MHz from the external 8MHz crystal
3333struct SystemClock
3434{
35+ static constexpr uint32_t Hse = 8_MHz;
3536 static constexpr uint32_t Frequency = 168_MHz;
3637 static constexpr uint32_t Apb1 = Frequency / 4 ;
3738 static constexpr uint32_t Apb2 = Frequency / 2 ;
@@ -80,15 +81,14 @@ struct SystemClock
8081
8182 static constexpr uint32_t Usb = 48_MHz;
8283 static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
83- static constexpr uint32_t Rtc = Rcc::LsiFrequency ;
84+ static constexpr uint32_t Rtc = Hse / 25 ;
8485
8586 static bool inline
8687 enable ()
8788 {
88- Rcc::enableLowSpeedInternalClock ();
89- Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::Lsi);
90-
9189 Rcc::enableExternalCrystal (); // 8 MHz
90+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::ExternalClock, 25 );
91+
9292 const Rcc::PllFactors pllFactors{
9393 .pllM = 4 , // 8MHz / M -> 2MHz
9494 .pllN = 168 , // 2MHz * N -> 336MHz
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ using namespace modm::literals;
3131// / STM32F030 running at 48MHz generated from the external 8MHz crystal
3232struct SystemClock
3333{
34+ static constexpr uint32_t Hse = 8_MHz;
3435 static constexpr uint32_t Frequency = 48_MHz;
3536 static constexpr uint32_t Ahb = Frequency;
3637 static constexpr uint32_t Apb = Frequency;
@@ -52,15 +53,13 @@ struct SystemClock
5253 static constexpr uint32_t Timer16 = Apb;
5354 static constexpr uint32_t Timer17 = Apb;
5455 static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
55- static constexpr uint32_t Rtc = Rcc::LsiFrequency ;
56+ static constexpr uint32_t Rtc = Hse / 32 ;
5657
5758 static bool inline
5859 enable ()
5960 {
60- Rcc::enableLowSpeedInternalClock ();
61- Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::Lsi);
62-
6361 Rcc::enableExternalCrystal (); // 8MHz
62+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::ExternalClock);
6463
6564 // external clock / 1 * 6 = 48MHz
6665 const Rcc::PllFactors pllFactors{
You can’t perform that action at this time.
0 commit comments