IAP class library for LPC1768, LPC11U24, LPC1114, LPC1347, LPC1549, LPC812 and LPC824

Fork of IAP by Tedd OKANO

Revision:
10:56f1e488b250
Parent:
9:f33e8f9a3677
--- a/IAP.cpp	Sun Jan 17 00:44:10 2016 +0900
+++ b/IAP.cpp	Tue May 03 07:43:30 2016 +0000
@@ -180,8 +180,21 @@
 
 #if defined(TARGET_LPC11UXX) || defined(TARGET_LPC13XX) || defined(TARGET_LPC15XX)
 
+void IAP::init_eeprom()
+{
+#if defined(TARGET_LPC15XX)
+    __disable_irq();
+    LPC_SYSCON->SYSAHBCLKCTRL0 |= 1 << 9;
+    LPC_SYSCON->PRESETCTRL0 |= 1 << 9;
+    LPC_SYSCON->PRESETCTRL0 &= ~(1 << 9);
+    __enable_irq();
+#endif
+}
+
 int IAP::write_eeprom( char *source_addr, char *target_addr, int size )
 {
+    init_eeprom();
+
     IAP_command[ 0 ]    = IAPCommand_EEPROM_Write;
     IAP_command[ 1 ]    = (unsigned int)target_addr;    //  Destination EEPROM address where data bytes are to be written. This address should be a 256 byte boundary.
     IAP_command[ 2 ]    = (unsigned int)source_addr;    //  Source RAM address from which data bytes are to be read. This address should be a word boundary.
@@ -195,6 +208,8 @@
 
 int IAP::read_eeprom( char *source_addr, char *target_addr, int size )
 {
+    init_eeprom();
+
     IAP_command[ 0 ]    = IAPCommand_EEPROM_Read;
     IAP_command[ 1 ]    = (unsigned int)source_addr;    //  Source EEPROM address from which data bytes are to be read. This address should be a word boundary.
     IAP_command[ 2 ]    = (unsigned int)target_addr;    //  Destination RAM address where data bytes are to be written. This address should be a 256 byte boundary.