From c3d247b6ae7dd35a84268739638891bb4704e047 Mon Sep 17 00:00:00 2001
From: Matteo Pignataro <matteo.pignataro@skywarder.eu>
Date: Sat, 7 Oct 2023 12:15:09 +0000
Subject: [PATCH] [SDDriver] Added acceptance of pre-defined clock divider

---
 miosix/arch/common/drivers/sd_stm32f2_f4_f7.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/miosix/arch/common/drivers/sd_stm32f2_f4_f7.cpp b/miosix/arch/common/drivers/sd_stm32f2_f4_f7.cpp
index 33666f61..8e6012a4 100644
--- a/miosix/arch/common/drivers/sd_stm32f2_f4_f7.cpp
+++ b/miosix/arch/common/drivers/sd_stm32f2_f4_f7.cpp
@@ -815,6 +815,10 @@ private:
 
 void ClockController::calibrateClockSpeed(SDIODriver *sdio)
 {
+    #ifdef SD_DIVIDER
+    // The frequency will be divided by a factor of SD_DIVIDER + 2
+    setClockSpeed(SD_DIVIDER);
+    #else
     //During calibration we call readBlock() which will call reduceClockSpeed()
     //so not to invalidate calibration clock reduction must not be available
     clockReductionAvailable=0;
@@ -843,6 +847,7 @@ void ClockController::calibrateClockSpeed(SDIODriver *sdio)
         setClockSpeed(minFreq);
         DBG("Optimal CLKCR=%d\n",minFreq);
     }
+    #endif
 
     //Make clock reduction available
     clockReductionAvailable=MAX_ALLOWED_REDUCTIONS;
-- 
GitLab