Skip to content

Commit 294b380

Browse files
ledneczkirleh
andcommitted
[rcc] Add support for I2S pll on STM32F4
and remove deprecated enablePll() function that are not using `enablePll` struct. Co-authored-by: Raphael Lehmann <[email protected]>
1 parent e158b11 commit 294b380

File tree

3 files changed

+66
-85
lines changed

3 files changed

+66
-85
lines changed

src/modm/platform/clock/stm32/module.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def build(env):
7777
(target["family"] == "l4" and target["name"][0] in ["p", "q", "r", "s"])
7878
properties["pllsai_p_usb"] = (target["family"] == "f7") or \
7979
((target["family"] == "f4") and target["name"] in ["46", "69", "79"])
80+
properties["plli2s"] = (target["family"] == "f4")
8081
properties["cfgr1"] = ("CDCFGR1" if target.name in ["a0", "a3", "b0", "b3"] else "D1CFGR") \
8182
if target.family == "h7" else "CFGR"
8283
properties["d1"] = ("CD" if target.name in ["a0", "a3", "b0", "b3"] else "D1") \

src/modm/platform/clock/stm32/rcc.cpp.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,29 @@ Rcc::enablePll{{id}}(PllSource source, const PllFactors& pllFactors, uint32_t wa
317317

318318
%% endfor
319319

320+
%% if plli2s
321+
bool
322+
modm::platform::Rcc::enablePllI2s(const PllI2sFactors& pllFactors, uint32_t waitCycles)
323+
{
324+
// Read reserved and don't care values and clear all other values
325+
uint32_t tmp = RCC->PLLI2SCFGR & ~(RCC_PLLI2SCFGR_PLLI2SN | RCC_PLLI2SCFGR_PLLI2SR);
326+
// set PLL divider and multiplier
327+
tmp |= (((uint32_t) pllFactors.pllN) << RCC_PLLI2SCFGR_PLLI2SN_Pos) & RCC_PLLI2SCFGR_PLLI2SN;
328+
tmp |= (((uint32_t) pllFactors.pllR) << RCC_PLLI2SCFGR_PLLI2SR_Pos) & RCC_PLLI2SCFGR_PLLI2SR;
329+
RCC->PLLI2SCFGR = tmp;
330+
331+
// enable I2S PLL
332+
RCC->CR |= RCC_CR_PLLI2SON;
333+
// wait till I2S PLL gets ready or time is up
334+
while ((RCC->CR & RCC_CR_PLLI2SRDY) == 0)
335+
{
336+
if (not --waitCycles)
337+
return false;
338+
}
339+
return true;
340+
}
341+
%% endif
342+
320343
%% if pllsai_p_usb
321344
bool
322345
Rcc::enablePllSai(const PllSaiFactors& pllFactors, uint32_t waitCycles)

src/modm/platform/clock/stm32/rcc.hpp.in

Lines changed: 42 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -593,91 +593,6 @@ public:
593593
enablePllSai(const PllSaiFactors& pllFactors, uint32_t waitCycles = 2048);
594594
%% endif
595595

596-
// DEPRECATE: 2022q1
597-
%% if target.family in ["f2", "f4", "f7", "l4", "g0", "g4"]
598-
/**
599-
* Enable PLL.
600-
*
601-
* \code
602-
* VCO input frequency = PLL input clock frequency / PLLM [with 2 <= PLLM <= 63]
603-
* VCO output frequency = VCO input frequency × PLLN [with 64 <= PLLN <= 432]
604-
* \endcode
605-
*
606-
* \param source
607-
* Source select for PLL and for plli2s. If you are using
608-
* HSE you must enable it first (see enableHse()).
609-
*
610-
* \param pllM
611-
* Division factor for the main PLL (PLL) and
612-
* audio PLL (PLLI2S) input clock (with 2 <= pllM <= 63).
613-
* The software has to set these bits correctly to ensure
614-
* that frequency of selected source divided by pllM
615-
* is in ranges from 1 to 2 MHz.
616-
*
617-
* \param pllN
618-
* Main PLL (PLL) multiplication factor for VCO (with 64 <= pllN <= 432).
619-
* The software has to set these bits correctly to ensure
620-
* that the VCO output frequency is
621-
* - 336 MHz for ST32F4. Core will run at 168 MHz.
622-
* - 240 MHz for ST32F2. Core will run at 120 MHz.
623-
*
624-
* Example:
625-
*
626-
*/
627-
[[deprecated("Use PllFactors as argument instead")]] static bool
628-
enablePll(PllSource source, uint8_t pllM, uint16_t pllN,
629-
%% if target.family in ["l4", "g0", "g4"]
630-
uint8_t pllR,
631-
%% else
632-
uint8_t pllP,
633-
%% endif
634-
uint32_t waitCycles = 2048)
635-
{
636-
PllFactors pllFactors{
637-
.pllM = pllM,
638-
.pllN = pllN,
639-
%% if target.family in ["l4", "g0", "g4"]
640-
.pllR = pllR,
641-
%% else
642-
.pllP = pllP,
643-
%% endif
644-
};
645-
return enablePll(source, pllFactors, waitCycles);
646-
}
647-
%% elif target.family in ["l1"]
648-
[[deprecated("Use PllFactors as argument instead")]] static bool
649-
enablePll(PllSource source, PllMultiplier pllMul, uint8_t pllDiv,
650-
uint32_t waitCycles = 2048)
651-
{
652-
PllFactors pllFactors{
653-
.pllMul = pllMul,
654-
.pllDiv = pllDiv,
655-
};
656-
return enablePll(source, pllFactors, waitCycles);
657-
}
658-
%% elif target.family in ["f0", "f1", "f3"]
659-
[[deprecated("Use PllFactors as argument instead")]] static bool
660-
enablePll(PllSource source,
661-
uint8_t pllMul,
662-
%% if pllprediv2
663-
uint8_t pllPrediv, uint8_t pllPrediv2,
664-
%% elif pllprediv
665-
uint8_t pllPrediv,
666-
%% endif
667-
uint32_t waitCycles = 2048)
668-
{
669-
PllFactors pllFactors{
670-
.pllMul = pllMul,
671-
%% if pllprediv2
672-
.pllPrediv = pllPrediv,
673-
.pllPrediv2 = pllPrediv2,
674-
%% elif pllprediv
675-
.pllPrediv = pllPrediv,
676-
%% endif
677-
};
678-
return enablePll(source, pllFactors, waitCycles);
679-
}
680-
%% endif
681596
%% if target.family == "l0"
682597
static inline bool
683598
isHsiPredivider4Active()
@@ -689,6 +604,48 @@ public:
689604
setHsiPredivider4Enabled(bool divideBy4, uint32_t waitCycles = 2048);
690605
%% endif
691606

607+
%% if target["family"] == "f4"
608+
/**
609+
* Input clock for I2S Pll is the HSE or HSI divided by M.
610+
*
611+
* f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN / PLLM)
612+
*
613+
* f(PLL I2S clock output) = f(VCO clock) / PLLI2SR
614+
*/
615+
struct PllI2sFactors
616+
{
617+
/**
618+
* @brief multiplication factor for VCO
619+
*
620+
* Caution: The software has to set these bits correctly
621+
* to ensure that the VCO output frequency
622+
* is between 100 and 432 MHz.
623+
*
624+
* 50 <= `pllN` <= 432
625+
*/
626+
const uint16_t pllN;
627+
628+
/**
629+
* @brief division factor for I2S clocks
630+
*
631+
* Caution: The I2Ss requires a frequency lower than
632+
* or equal to 192 MHz to work correctly.
633+
*
634+
* 2 <= `pllR` <= 7
635+
*/
636+
const uint16_t pllR;
637+
};
638+
639+
/**
640+
* @brief Configure factors for I2S pll and enable.
641+
*
642+
* @param pllFactors See `PllI2sFactors`
643+
* @param waitCycles Number of cycles to wait for pll to become stable. Defaults to 2048.
644+
*/
645+
static bool
646+
enablePllI2s(const PllI2sFactors& pllFactors, uint32_t waitCycles = 2048);
647+
%% endif
648+
692649
// sinks
693650
static bool
694651
enableSystemClock(SystemClockSource src, uint32_t waitCycles = 2048);

0 commit comments

Comments
 (0)