Skip to content

Commit

Permalink
Merge pull request #7663 from blues/fix-swan_r5_LSE_drive_level
Browse files Browse the repository at this point in the history
fix: Increases drive strength of the 32kHz external crystal
  • Loading branch information
dhalbert authored Mar 1, 2023
2 parents 8e87b92 + e2c6cf5 commit 965caa0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ports/stm/boards/swan_r5/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
#define BOARD_HAS_HIGH_SPEED_CRYSTAL (0)

// Increase drive strength of 32kHz external crystal, in line with calculations specified in ST AN2867 sections 3.3, 3.4, and STM32L4 datasheet DS12023 Table 58. LSE oscillator characteristics.
// The drive strength RCC_LSEDRIVE_LOW is marginal for the 32kHz crystal oscillator stability, and RCC_LSEDRIVE_MEDIUMLOW meets the calculated drive strength with a small margin for parasitic capacitance.
#define BOARD_LSE_DRIVE_LEVEL RCC_LSEDRIVE_MEDIUMLOW

// Bootloader only
#ifdef UF2_BOOTLOADER_ENABLED
Expand Down
4 changes: 3 additions & 1 deletion ports/stm/peripherals/stm32l4/clocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#error HSE support needs to be added for the L4 family.
#elif !BOARD_HAS_LOW_SPEED_CRYSTAL
#error LSE clock source required
#elif !defined(BOARD_LSE_DRIVE_LEVEL)
#error BOARD_LSE_DRIVE_LEVEL is not defined for this board. The board should define the drive strength of 32kHz external crystal in line with calculations specified in ST AN2867 sections 3.3, 3.4, and STM32L4 datasheet DS12023 Table 58, LSE oscillator characteristics.
#endif

void Error_Handler(void) {
Expand All @@ -57,7 +59,7 @@ void stm32_peripherals_clocks_init(void) {

// Configure LSE Drive
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
__HAL_RCC_LSEDRIVE_CONFIG(BOARD_LSE_DRIVE_LEVEL);
__HAL_RCC_PWR_CLK_ENABLE();

/** Configure the main internal regulator output voltage
Expand Down

0 comments on commit 965caa0

Please sign in to comment.