[HAL][SAI] Improve audio quality (avoid potential glitch)
diff --git a/Src/stm32f7xx_hal_sai.c b/Src/stm32f7xx_hal_sai.c
index 27dd15b..472a899 100644
--- a/Src/stm32f7xx_hal_sai.c
+++ b/Src/stm32f7xx_hal_sai.c
@@ -1264,6 +1264,9 @@
   /* Process Locked */
   __HAL_LOCK(hsai);
 
+  /* Disable SAI peripheral */
+  SAI_Disable(hsai);
+
   /* Disable the SAI DMA request */
   hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
 
@@ -1295,9 +1298,6 @@
     }
   }
 
-  /* Disable SAI peripheral */
-  SAI_Disable(hsai);
-
   /* Flush the fifo */
   SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);
 
@@ -1323,6 +1323,9 @@
   /* Process Locked */
   __HAL_LOCK(hsai);
 
+  /* Disable SAI peripheral */
+  SAI_Disable(hsai);
+
   /* Check SAI DMA is enabled or not */
   if ((hsai->Instance->CR1 & SAI_xCR1_DMAEN) == SAI_xCR1_DMAEN)
   {
@@ -1361,9 +1364,6 @@
   hsai->Instance->IMR = 0;
   hsai->Instance->CLRFR = 0xFFFFFFFFU;
 
-  /* Disable SAI peripheral */
-  SAI_Disable(hsai);
-
   /* Flush the fifo */
   SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);