From 879162fd7344fb536123cde54921d29f670cdc1c Mon Sep 17 00:00:00 2001
From: iabdalkader <i.abdalkader@gmail.com>
Date: Sat, 30 Nov 2024 14:32:36 +0100
Subject: [PATCH] ports/stm32/spi: Disable WFI for H7.

- See DM00257543 2.2.5
---
 ports/stm32/spi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c
index 5d8720f1fba08..b916dc6e9a308 100644
--- a/ports/stm32/spi.c
+++ b/ports/stm32/spi.c
@@ -569,7 +569,14 @@ static HAL_StatusTypeDef spi_wait_dma_finished(const spi_t *spi, uint32_t t_star
             enable_irq(irq_state);
             return HAL_OK;
         }
+        // See DM00257543 2.2.5
+        // The DTCM-RAM is not accessible in read during Sleep mode (when the CPU clock is
+        // gated). When a read access to the DTCM-RAM is performed by an AHB bus master
+        // (that are the DMAs) while the CPU is in sleep mode (CPU clock is gated), the
+        // data is not transmitted to the AHB bus and the AHB master reads 0x0000_0000.
+        #if !defined(STM32F7)
         __WFI();
+        #endif
         enable_irq(irq_state);
         if (HAL_GetTick() - t_start >= timeout) {
             return HAL_TIMEOUT;