From 0dce96ca21bcde277a09ecfefa2b798143b57968 Mon Sep 17 00:00:00 2001
From: arighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Date: Mon, 14 Mar 2011 14:40:07 +0000
Subject: [PATCH] STM32: flash: make flash_wait() a voluntary preemption point

A process that writes large chunks of data to the embedded flash can
monopolize the CPU for a very long time if the flash is fast enough to
write data words.

This is bad from the real-time perspective, so make flash_wait() a
voluntary preemption point, also in the case when the flash is fast
enough and never goes in busy state.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4771 38d2e660-2303-0410-9eaa-f027e97ec537
---
 bertos/cpu/cortex-m3/drv/flash_stm32.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/bertos/cpu/cortex-m3/drv/flash_stm32.c b/bertos/cpu/cortex-m3/drv/flash_stm32.c
index 816cdd58..d92e9142 100644
--- a/bertos/cpu/cortex-m3/drv/flash_stm32.c
+++ b/bertos/cpu/cortex-m3/drv/flash_stm32.c
@@ -67,6 +67,7 @@ static bool flash_wait(struct KBlock *blk)
 	ticks_t start = timer_clock();
 	while (true)
 	{
+		cpu_relax();
 		if (!(EMB_FLASH->SR & FLASH_FLAG_BSY))
 			break;
 
@@ -90,8 +91,6 @@ static bool flash_wait(struct KBlock *blk)
 			LOG_ERR("Timeout..\n");
 			return false;
 		}
-
-		cpu_relax();
 	}
 
 	return true;
-- 
2.34.1