IAP compatible.

Fork of IAP by Tedd OKANO

Import programSTM32_IAP_internal_flash_write

STM32_IAP demo.

Import programSTM32_IAP_test

STM32_IAP test

Revision:
9:7e19f12b81b4
Parent:
8:8af7acf9dbf3
Child:
11:937bd817d5bf
--- a/IAP_STM32F4.cpp	Sun Apr 10 11:32:54 2016 +0000
+++ b/IAP_STM32F4.cpp	Mon Apr 11 03:09:59 2016 +0000
@@ -77,24 +77,27 @@
  */
 int IAP::read_ID( void )
 {
-    // TODO
+    IAP_result[1] = HAL_GetDEVID();
     return ( (int)IAP_result[ 1 ] );    //  to return the number itself (this command always returns CMD_SUCCESS)
 }
 
 int *IAP::read_serial( void ) {
-    // TODO
+    memcpy(&IAP_result[1], (void*)0x1fff7a10,  sizeof(uint32_t) * 3);
+    IAP_result[4] = 0; 
     return ( (int *)&IAP_result[ 1 ] );    //  to return the number itself (this command always returns CMD_SUCCESS)
 }
 
 int IAP::blank_check( int start, int end )
 {
-    static const int base[8] = {0x00000, 0x04000, 0x08000, 0xc000, 0x10000, 0x20000, 0x40000, 0x60000};
-    static const int size[8] = {0x4000, 0x4000, 0x4000, 0x4000, 0x10000, 0x20000, 0x20000, 0x20000};         
-    for(int i = start; i <= end; i++) {
-        for(int j = 0; j < size[i]; j++) {
-            if (*(char*)(base[i] + j) != 0x00) {
-                return SECTOR_NOT_BLANK;
-            }
+    if (start >= FLASH_SECTOR_TOTAL || end >= FLASH_SECTOR_TOTAL) {
+        return INVALID_SECTOR;
+    } 
+    static const int offset[8+1] = {0x00000, 0x04000, 0x08000, 0xc000, 0x10000, 0x20000, 0x40000, 0x60000, 0x80000};
+    uint8_t* p = reinterpret_cast<uint8_t*>(FLASH_BASE + offset[start]);
+    uint8_t* e = reinterpret_cast<uint8_t*>(FLASH_BASE + offset[end + 1]);
+    while(p < e) {
+        if (*p++ != 0x00) {
+            return SECTOR_NOT_BLANK;
         }
     }
     return CMD_SUCCESS;