From 3ea356a72054b540e1c529fee5f55b10324254a4 Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Fri, 9 Mar 2012 22:02:29 +0000
Subject: [PATCH] Added Dataflash operational checks and aborts to all projects
 using the Dataflash to ensure it is working correctly before use.

---
 Demos/Device/ClassDriver/MassStorage/MassStorage.c |  7 +++++++
 .../MassStorageKeyboard/MassStorageKeyboard.c      |  7 +++++++
 .../VirtualSerialMassStorage.c                     |  7 +++++++
 Demos/Device/LowLevel/MassStorage/MassStorage.c    |  7 +++++++
 LUFA/DoxygenPages/ChangeLog.txt                    |  1 +
 Maintenance/makefile                               | 14 +++++++-------
 .../StandaloneProgrammer/StandaloneProgrammer.c    |  7 +++++++
 Projects/TempDataLogger/TempDataLogger.c           |  7 +++++++
 8 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/Demos/Device/ClassDriver/MassStorage/MassStorage.c b/Demos/Device/ClassDriver/MassStorage/MassStorage.c
index 55afed124..6a720f983 100644
--- a/Demos/Device/ClassDriver/MassStorage/MassStorage.c
+++ b/Demos/Device/ClassDriver/MassStorage/MassStorage.c
@@ -92,6 +92,13 @@ void SetupHardware(void)
 	Dataflash_Init();
 	USB_Init();
 
+	/* Check if the Dataflash is working, abort if not */
+	if (!(DataflashManager_CheckDataflashOperation()))
+	{
+		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		for(;;);
+	}
+
 	/* Clear Dataflash sector protections, if enabled */
 	DataflashManager_ResetDataflashProtections();
 }
diff --git a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c
index 9f1c5c90d..bfdf09ceb 100644
--- a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c
+++ b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c
@@ -117,6 +117,13 @@ void SetupHardware(void)
 	Dataflash_Init();
 	USB_Init();
 
+	/* Check if the Dataflash is working, abort if not */
+	if (!(DataflashManager_CheckDataflashOperation()))
+	{
+		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		for(;;);
+	}
+
 	/* Clear Dataflash sector protections, if enabled */
 	DataflashManager_ResetDataflashProtections();
 }
diff --git a/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c b/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c
index 13c34d942..d8ffea873 100644
--- a/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c
+++ b/Demos/Device/ClassDriver/VirtualSerialMassStorage/VirtualSerialMassStorage.c
@@ -131,6 +131,13 @@ void SetupHardware(void)
 	Dataflash_Init();
 	USB_Init();
 
+	/* Check if the Dataflash is working, abort if not */
+	if (!(DataflashManager_CheckDataflashOperation()))
+	{
+		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		for(;;);
+	}
+
 	/* Clear Dataflash sector protections, if enabled */
 	DataflashManager_ResetDataflashProtections();
 }
diff --git a/Demos/Device/LowLevel/MassStorage/MassStorage.c b/Demos/Device/LowLevel/MassStorage/MassStorage.c
index e58ac745f..947636cf8 100644
--- a/Demos/Device/LowLevel/MassStorage/MassStorage.c
+++ b/Demos/Device/LowLevel/MassStorage/MassStorage.c
@@ -80,6 +80,13 @@ void SetupHardware(void)
 	Dataflash_Init();
 	USB_Init();
 
+	/* Check if the Dataflash is working, abort if not */
+	if (!(DataflashManager_CheckDataflashOperation()))
+	{
+		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		for(;;);
+	}
+
 	/* Clear Dataflash sector protections, if enabled */
 	DataflashManager_ResetDataflashProtections();
 }
diff --git a/LUFA/DoxygenPages/ChangeLog.txt b/LUFA/DoxygenPages/ChangeLog.txt
index d806c6ee8..c769c07e9 100644
--- a/LUFA/DoxygenPages/ChangeLog.txt
+++ b/LUFA/DoxygenPages/ChangeLog.txt
@@ -12,6 +12,7 @@
   *   - Added support for the BitWizard Multio and Big-Multio boards
   *  - Library Applications:
   *   - Modified the CDC Host demos to set a default CDC Line Encoding on enumerated devices
+  *   - Added Dataflash operational checks and aborts to all projects using the Dataflash to ensure it is working correctly before use
   *
   *  <b>Changed:</b>
   *  - Core:
diff --git a/Maintenance/makefile b/Maintenance/makefile
index d7230781d..ae40fd757 100644
--- a/Maintenance/makefile
+++ b/Maintenance/makefile
@@ -23,12 +23,6 @@ upgrade-doxygen:
 	done;
 	@echo Doxygen configuration update complete.
 
-# Validate the working branch - compile all documentation, demos/projects/examples and run build tests
-validate-branch:
-	make -s -C $(LUFA_ROOT) doxygen
-	make -s -C $(LUFA_ROOT) all	
-	make -s -C $(LUFA_ROOT)/BuildTests all
-
 # Check the working branch documentation, ensure no placeholder values
 check-documentation-placeholders:
 	@echo Checking for release suitability...
@@ -42,5 +36,11 @@ check-documentation-placeholders:
 	fi;
 	@echo Done.
 
+# Validate the working branch - compile all documentation, demos/projects/examples and run build tests
+validate-branch:
+	make -s -C $(LUFA_ROOT) doxygen
+	make -s -C $(LUFA_ROOT) all	
+	make -s -C $(LUFA_ROOT)/BuildTests all
+
 # Validate the working branch for general release, check for placeholder documentation then build and test everything
-validate-release: check-documentation-placeholders validate-branch
\ No newline at end of file
+validate-release: check-documentation-placeholders validate-branch
diff --git a/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c b/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c
index cc79a8321..86318e9cb 100644
--- a/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c
+++ b/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c
@@ -155,6 +155,13 @@ void SetupHardware(void)
 	Serial_CreateStream(NULL);
 
 	#if defined(USB_CAN_BE_DEVICE)
+	/* Check if the Dataflash is working, abort if not */
+	if (!(DataflashManager_CheckDataflashOperation()))
+	{
+		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		for(;;);
+	}
+
 	/* Clear Dataflash sector protections, if enabled */
 	DataflashManager_ResetDataflashProtections();
 	#endif
diff --git a/Projects/TempDataLogger/TempDataLogger.c b/Projects/TempDataLogger/TempDataLogger.c
index 258bfc386..83590b311 100644
--- a/Projects/TempDataLogger/TempDataLogger.c
+++ b/Projects/TempDataLogger/TempDataLogger.c
@@ -207,6 +207,13 @@ void SetupHardware(void)
 	TCCR1B  = (1 << WGM12) | (1 << CS12) | (1 << CS10);
 	TIMSK1  = (1 << OCIE1A);
 
+	/* Check if the Dataflash is working, abort if not */
+	if (!(DataflashManager_CheckDataflashOperation()))
+	{
+		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		for(;;);
+	}
+
 	/* Clear Dataflash sector protections, if enabled */
 	DataflashManager_ResetDataflashProtections();
 }
-- 
GitLab