Skip to content

Commit 6a68ecb

Browse files
committed
system(h7): update STM32H7xx system
Signed-off-by: Frederic Pillon <[email protected]>
1 parent cc79807 commit 6a68ecb

File tree

1 file changed

+113
-6
lines changed

1 file changed

+113
-6
lines changed

Diff for: system/STM32H7xx/system_stm32h7xx.c

+113-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*
77
* This file provides two functions and one global variable to be called from
88
* user application:
9+
* - ExitRun0Mode(): Specifies the Power Supply source. This function is
10+
* called at startup just after reset and before the call
11+
* of SystemInit(). This call is made inside
12+
* the "startup_stm32h7xx.s" file.
13+
*
914
* - SystemInit(): This function is called at startup just after reset and
1015
* before branch to main program. This call is made inside
1116
* the "startup_stm32h7xx.s" file.
@@ -265,12 +270,21 @@ void SystemInit (void)
265270
#endif /* DATA_IN_D2_SRAM */
266271

267272
#if !defined(DUAL_CORE) || defined(CORE_CM7)
268-
/*
269-
* Disable the FMC bank1 (enabled after reset).
270-
* This, prevents CPU speculation access on this bank which blocks the use of FMC during
271-
* 24us. During this time the others FMC master (such as LTDC) cannot use it!
272-
*/
273-
FMC_Bank1_R->BTCR[0] = 0x000030D2;
273+
if(READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN) == 0U)
274+
{
275+
/* Enable the FMC interface clock */
276+
SET_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
277+
278+
/*
279+
* Disable the FMC bank1 (enabled after reset).
280+
* This, prevents CPU speculation access on this bank which blocks the use of FMC during
281+
* 24us. During this time the others FMC master (such as LTDC) cannot use it!
282+
*/
283+
FMC_Bank1_R->BTCR[0] = 0x000030D2;
284+
285+
/* Disable the FMC interface clock */
286+
CLEAR_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
287+
}
274288
#endif /* !DUAL_CORE || CORE_CM7 */
275289

276290
/* Configure the Vector Table location add offset address for cortex-M7 or for cortex-M4 ------------------*/
@@ -413,6 +427,99 @@ void SystemCoreClockUpdate (void)
413427
}
414428

415429

430+
/**
431+
* @brief Exit Run* mode and Configure the system Power Supply
432+
*
433+
* @note This function exits the Run* mode and configures the system power supply
434+
* according to the definition to be used at compilation preprocessing level.
435+
* The application shall set one of the following configuration option:
436+
* - PWR_LDO_SUPPLY
437+
* - PWR_DIRECT_SMPS_SUPPLY
438+
* - PWR_EXTERNAL_SOURCE_SUPPLY
439+
* - PWR_SMPS_1V8_SUPPLIES_LDO
440+
* - PWR_SMPS_2V5_SUPPLIES_LDO
441+
* - PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO
442+
* - PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO
443+
* - PWR_SMPS_1V8_SUPPLIES_EXT
444+
* - PWR_SMPS_2V5_SUPPLIES_EXT
445+
*
446+
* @note The function modifies the PWR->CR3 register to enable or disable specific
447+
* power supply modes and waits until the voltage level flag is set, indicating
448+
* that the power supply configuration is stable.
449+
*
450+
* @param None
451+
* @retval None
452+
*/
453+
void ExitRun0Mode(void)
454+
{
455+
#if defined(USE_PWR_LDO_SUPPLY)
456+
#if defined(SMPS)
457+
/* Exit Run* mode by disabling SMPS and enabling LDO */
458+
PWR->CR3 = (PWR->CR3 & ~PWR_CR3_SMPSEN) | PWR_CR3_LDOEN;
459+
#else
460+
/* Enable LDO mode */
461+
PWR->CR3 |= PWR_CR3_LDOEN;
462+
#endif /* SMPS */
463+
/* Wait till voltage level flag is set */
464+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
465+
{}
466+
#elif defined(USE_PWR_EXTERNAL_SOURCE_SUPPLY)
467+
#if defined(SMPS)
468+
/* Exit Run* mode */
469+
PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_SMPSEN | PWR_CR3_LDOEN)) | PWR_CR3_BYPASS;
470+
#else
471+
PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_LDOEN)) | PWR_CR3_BYPASS;
472+
#endif /* SMPS */
473+
/* Wait till voltage level flag is set */
474+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
475+
{}
476+
#elif defined(USE_PWR_DIRECT_SMPS_SUPPLY) && defined(SMPS)
477+
/* Exit Run* mode */
478+
PWR->CR3 &= ~(PWR_CR3_LDOEN);
479+
/* Wait till voltage level flag is set */
480+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
481+
{}
482+
#elif defined(USE_PWR_SMPS_1V8_SUPPLIES_LDO) && defined(SMPS)
483+
/* Exit Run* mode */
484+
PWR->CR3 |= PWR_CR3_SMPSLEVEL_0 | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
485+
/* Wait till voltage level flag is set */
486+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
487+
{}
488+
#elif defined(USE_PWR_SMPS_2V5_SUPPLIES_LDO) && defined(SMPS)
489+
/* Exit Run* mode */
490+
PWR->CR3 |= PWR_CR3_SMPSLEVEL_1 | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
491+
/* Wait till voltage level flag is set */
492+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
493+
{}
494+
#elif defined(USE_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO) && defined(SMPS)
495+
/* Exit Run* mode */
496+
PWR->CR3 |= PWR_CR3_SMPSLEVEL_0 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
497+
/* Wait till voltage level flag is set */
498+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
499+
{}
500+
#elif defined(USE_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO) && defined(SMPS)
501+
/* Exit Run* mode */
502+
PWR->CR3 |= PWR_CR3_SMPSLEVEL_1 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
503+
/* Wait till voltage level flag is set */
504+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
505+
{}
506+
#elif defined(USE_PWR_SMPS_1V8_SUPPLIES_EXT) && defined(SMPS)
507+
/* Exit Run* mode */
508+
PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_LDOEN)) | PWR_CR3_SMPSLEVEL_0 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_BYPASS;
509+
/* Wait till voltage level flag is set */
510+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
511+
{}
512+
#elif defined(USE_PWR_SMPS_2V5_SUPPLIES_EXT) && defined(SMPS)
513+
/* Exit Run* mode */
514+
PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_LDOEN)) | PWR_CR3_SMPSLEVEL_1 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_BYPASS;
515+
/* Wait till voltage level flag is set */
516+
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
517+
{}
518+
#else
519+
/* No system power supply configuration is selected at exit Run* mode */
520+
#endif /* USE_PWR_LDO_SUPPLY */
521+
}
522+
416523
/**
417524
* @}
418525
*/

0 commit comments

Comments
 (0)