Skip to content

Commit 4cf572f

Browse files
committed
PortentaH7: add LSI fallback during startup
1 parent b3e2ca7 commit 4cf572f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

variants/PORTENTA_H7_M7/conf/mbed_app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"VIRTIO_MASTER_ONLY",
2323
"NO_ATOMIC_64_SUPPORT",
2424
"METAL_MAX_DEVICE_REGIONS=2",
25-
"RPMSG_BUFFER_SIZE=2048"
25+
"RPMSG_BUFFER_SIZE=2048",
26+
"LSE_STARTUP_TIMEOUT=200"
2627
]
2728
}
2829
}

variants/PORTENTA_H7_M7/variant.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ void fixup3V1Rail() {
235235
i2c.write(8 << 1, data, sizeof(data));
236236
}
237237

238+
extern "C" void lp_ticker_reconfigure_with_lsi();
239+
238240
void initVariant() {
239241
RTCHandle.Instance = RTC;
240242
// Turn off LED from bootloader
@@ -244,6 +246,19 @@ void initVariant() {
244246
// Disable the FMC bank1 (enabled after reset)
245247
// See https://github.com/STMicroelectronics/STM32CubeH7/blob/beced99ac090fece04d1e0eb6648b8075e156c6c/Projects/STM32H747I-DISCO/Applications/OpenAMP/OpenAMP_RTOS_PingPong/Common/Src/system_stm32h7xx.c#L215
246248
FMC_Bank1_R->BTCR[0] = 0x000030D2;
249+
// Check that the selected lsi clock is ok
250+
if (__HAL_RCC_GET_LPTIM4_SOURCE() == RCC_LPTIM4CLKSOURCE_LSI) {
251+
// rtc is not mounted, no need to do other actions
252+
return;
253+
}
254+
// Use micros() to check the lptim precision
255+
// if the error is > 1% , reconfigure the clock using lsi
256+
uint32_t start_ms = millis();
257+
uint32_t start_us = micros();
258+
while (micros() - start_us < 100000);
259+
if (millis() - start_ms != 100) {
260+
lp_ticker_reconfigure_with_lsi();
261+
}
247262
}
248263

249264
#ifdef SERIAL_CDC

0 commit comments

Comments
 (0)