Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@ git clone --recurse-submodules --jobs 8 https://github.com/modm-io/modm.git
- Lightweight unit testing system (suitable for AVRs).
- Hundreds of tests to ensure correct functionality.
- Integration of useful third-party software:
- [FreeRTOS][] and [FreeRTOS+TCP][] operating system.
- [CMSIS][] and [CMSIS-DSP][] interfaces.
- [CrashCatcher][]: Crash reports for HardFaults.
- [Eigen][]: Linear Algebra Library.
- [ETL][]: Embedded Template Library.
- [TinyUSB][]: USB Host/Device stack.
- [FatFS][]: FAT/exFAT filesystem.
- [ROSserial][]: Embedded ROS client.
- [CrashCatcher][]: Crash reports for HardFaults.
- [printf][]: Small printf implementation.
- [Nanopb][]: Embedded Protocol Buffers.
- [FreeRTOS][] and [FreeRTOS+TCP][] operating system.
- [LVGL][]: Embedded Graphics Library.
- [Nanopb][]: Embedded Protocol Buffers.
- [printf][]: Small printf implementation.
- [ROSserial][]: Embedded ROS client.
- [RTT][]: Segger Real-Time Transport.
- [TinyUSB][]: USB Host/Device stack.


## Microcontrollers
Expand Down Expand Up @@ -1050,4 +1051,5 @@ and [many more contributors][contributors].
[Nanopb]: https://github.com/nanopb/nanopb
[LVGL]: https://lvgl.io
[RTT]: https://kb.segger.com/RTT
[Eigen]: https://libeigen.gitlab.io
<!--/links-->
34 changes: 16 additions & 18 deletions src/modm/board/disco_f303vc/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ using namespace modm::literals;
struct SystemClock
{
static constexpr uint32_t Hse = 8_MHz;
static constexpr uint32_t Frequency = 72_MHz;
static constexpr Rcc::PllConfig pll{.Prediv = 1, .Mul = 9};
static constexpr uint32_t Pll = Hse / pll.Prediv * pll.Mul;
static_assert(Pll == Rcc::MaxFrequency);

static constexpr uint32_t Frequency = Pll;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Apb1 = Frequency / 2;
static constexpr uint32_t Apb2 = Frequency;
Expand Down Expand Up @@ -95,26 +99,20 @@ struct SystemClock
static bool inline
enable()
{
Rcc::enableRealTimeClock(Rcc::RealTimeClockSource::ExternalClock);

Rcc::enableExternalClock(); // 8MHz
const Rcc::PllFactors pllFactors{
.pllMul = 9,
.pllPrediv = 1,
.usbPrediv = Rcc::UsbPrescaler::Div1_5
};
Rcc::enablePll(Rcc::PllSource::ExternalClock, pllFactors);
// set flash latency for 72MHz
Rcc::enableHseClock();

Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
// APB1 has max. 36MHz
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div2);
Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
Rcc::setApb1Prescaler(Rcc::ApbPrescaler::Div2);
Rcc::setApb2Prescaler(Rcc::ApbPrescaler::Div1);
Rcc::setUsbClockPrescaler(Rcc::UsbPrescaler::Div1_5);

Rcc::enablePll(Rcc::PllSource::HsePrediv, pll);
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setRealTimeClockSource(Rcc::RealTimeClockSource::HseDiv32);

return true;
}
};
Expand Down
38 changes: 17 additions & 21 deletions src/modm/board/nucleo_f303k8/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ namespace Board
using namespace modm::literals;

/// STM32F303K8 running at 64MHz generated from the internal 8MHz clock
// Dummy clock for devices
struct SystemClock
{
static constexpr uint32_t Frequency = 64_MHz;
static constexpr Rcc::PllConfig pll{.Mul = 16};
static constexpr uint32_t Pll = Rcc::HsiFrequency / 2 * pll.Mul;
static_assert(Pll <= Rcc::MaxFrequency);

static constexpr uint32_t Frequency = Pll;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Apb1 = Frequency / 2;
static constexpr uint32_t Apb2 = Frequency;
Expand All @@ -48,7 +51,7 @@ struct SystemClock
static constexpr uint32_t Usart3 = Apb1;

// I2C1 clock source is HSI per default
static constexpr uint32_t I2c1 = 8_MHz;
static constexpr uint32_t I2c1 = Rcc::HsiFrequency;

static constexpr uint32_t Apb1Timer = Apb1 * 2;
static constexpr uint32_t Apb2Timer = Apb2 * 1;
Expand All @@ -66,27 +69,20 @@ struct SystemClock
static bool inline
enable()
{
Rcc::enableLowSpeedInternalClock();
Rcc::enableRealTimeClock(Rcc::RealTimeClockSource::Lsi);

Rcc::enableInternalClock(); // 8MHz
// 8MHz / 2 * 16 = 64MHz
const Rcc::PllFactors pllFactors{
.pllMul = 16,
.pllPrediv = 2, // only used with Hse
};
Rcc::enablePll(Rcc::PllSource::HsiDiv2, pllFactors);
// set flash latency for 64MHz
Rcc::enableLsiClock();
Rcc::enableHsiClock();

Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
// APB1 has max. 36MHz
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div2);
Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
Rcc::setApb1Prescaler(Rcc::ApbPrescaler::Div2);
Rcc::setApb2Prescaler(Rcc::ApbPrescaler::Div1);

Rcc::enablePll(Rcc::PllSource::HsiDiv2, pll);
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setRealTimeClockSource(Rcc::RealTimeClockSource::Lsi);

return true;
}
};
Expand Down
42 changes: 20 additions & 22 deletions src/modm/board/nucleo_f303re/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ using namespace modm::literals;
/// STM32F303RE running at 64MHz generated from the internal 8MHz clock
struct SystemClock
{
static constexpr uint32_t Frequency = 64_MHz;
static constexpr Rcc::PllConfig pll{.Mul = 16};
static constexpr uint32_t Pll = Rcc::HsiFrequency / 2 * pll.Mul;
static_assert(Pll <= Rcc::MaxFrequency);

static constexpr uint32_t Frequency = Pll;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Apb1 = Frequency / 2;
static constexpr uint32_t Apb2 = Frequency;
Expand All @@ -48,9 +52,9 @@ struct SystemClock
static constexpr uint32_t Usart3 = Apb1;

// I2C clock source is HSI by default
static constexpr uint32_t I2c1 = 8_MHz;
static constexpr uint32_t I2c2 = 8_MHz;
static constexpr uint32_t I2c3 = 8_MHz;
static constexpr uint32_t I2c1 = Rcc::HsiFrequency;
static constexpr uint32_t I2c2 = Rcc::HsiFrequency;
static constexpr uint32_t I2c3 = Rcc::HsiFrequency;

static constexpr uint32_t Apb1Timer = Apb1 * 2;
static constexpr uint32_t Apb2Timer = Apb2 * 1;
Expand All @@ -68,27 +72,21 @@ struct SystemClock
static bool inline
enable()
{
Rcc::enableLowSpeedExternalCrystal();
Rcc::enableRealTimeClock(Rcc::RealTimeClockSource::LowSpeedExternalCrystal);

Rcc::enableInternalClock(); // 8MHz
// 8MHz / 2 * 16 = 64MHz
const Rcc::PllFactors pllFactors{
.pllMul = 16,
.pllPrediv = 2,
};
Rcc::enablePll(Rcc::PllSource::InternalClock, pllFactors);
// set flash latency for 64MHz
Rcc::enableLseCrystal();
Rcc::enableHsiClock();

Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
// APB1 has max. 36MHz
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div2);
Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
Rcc::setApb1Prescaler(Rcc::ApbPrescaler::Div2);
Rcc::setApb2Prescaler(Rcc::ApbPrescaler::Div1);

Rcc::enablePll(Rcc::PllSource::HsiDiv2, pll);
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setRealTimeClockSource(Rcc::RealTimeClockSource::Lse);


return true;
}
};
Expand Down
35 changes: 16 additions & 19 deletions src/modm/board/nucleo_f334r8/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ using namespace modm::literals;
/// STM32F334R8 running at 64MHz generated from the internal 8MHz clock
struct SystemClock
{
static constexpr uint32_t Frequency = 64_MHz;
static constexpr Rcc::PllConfig pll{.Mul = 16};
static constexpr uint32_t Pll = Rcc::HsiFrequency / 2 * pll.Mul;
static_assert(Pll <= Rcc::MaxFrequency);

static constexpr uint32_t Frequency = Pll;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Apb1 = Frequency / 2;
static constexpr uint32_t Apb2 = Frequency;
Expand Down Expand Up @@ -65,27 +69,20 @@ struct SystemClock
static bool inline
enable()
{
Rcc::enableLowSpeedExternalCrystal();
Rcc::enableRealTimeClock(Rcc::RealTimeClockSource::LowSpeedExternalCrystal);

Rcc::enableInternalClock(); // 8MHz
// 8MHz / 2 * 16 = 64MHz
const Rcc::PllFactors pllFactors{
.pllMul = 16,
.pllPrediv = 2, // fixed (/2) for Hsi
};
Rcc::enablePll(Rcc::PllSource::HsiDiv2, pllFactors);
// set flash latency for 64MHz
Rcc::enableLseCrystal();
Rcc::enableHsiClock();

Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
// APB1 has max. 36MHz
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div2);
Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
Rcc::setApb1Prescaler(Rcc::ApbPrescaler::Div2);
Rcc::setApb2Prescaler(Rcc::ApbPrescaler::Div1);

Rcc::enablePll(Rcc::PllSource::HsiDiv2, pll);
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setRealTimeClockSource(Rcc::RealTimeClockSource::Lse);

return true;
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/modm/platform/clock/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,17 @@ def build(env):
ids = []
for driver in drivers:
if device.has_driver(driver):
ids += device.get_driver(driver)["instance"]
ids += device.get_driver(driver).get("instance", [])
return list(map(int, ids))

if t.family in ["h5", "u0", "g0", "u3", "c0", "f0", "l0", "f1", "f2"]:
if t.family in ["h5", "u0", "g0", "u3", "c0", "f0", "l0", "f1", "f2", "f3"]:
p["uart_ids"] = instances("usart", "uart")
p["lpuart_ids"] = instances("lpuart")
p["spi_ids"] = instances("spi")
p["i2c_ids"] = instances("i2c")
p["tim_ids"] = instances("tim")
p["lptim_ids"] = instances("lptim")
p["adc_ids"] = instances("adc")
env.template(f"rcc_{t.family}.hpp.in", "rcc.hpp")
else:
env.template("rcc.hpp.in")
Expand Down
Loading
Loading