STM32_IAP test

Dependencies:   STM32_IAP mbed

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Sun May 01 01:17:14 2016 +0000
Commit message:
first commit

Changed in this revision

STM32_IAP.lib Show annotated file Show diff for this revision Revisions of this file
main_F411RE.cpp Show annotated file Show diff for this revision Revisions of this file
main_F446RE.cpp Show annotated file Show diff for this revision Revisions of this file
main_L031K6.cpp Show annotated file Show diff for this revision Revisions of this file
main_L152RE.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mytest.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/STM32_IAP.lib	Sun May 01 01:17:14 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/va009039/code/STM32_IAP/#fd6a08b46228
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_F411RE.cpp	Sun May 01 01:17:14 2016 +0000
@@ -0,0 +1,226 @@
+#if defined(TARGET_NUCLEO_F411RE)
+#include "mbed.h"
+#include "mytest.h"
+#include "IAP.h"
+
+DigitalOut led1(LED1);
+RawSerial pc(USBTX,USBRX);
+IAP iap;
+
+void dump(const uint8_t* addr, size_t size) {
+    for(size_t i = 0; i < size; i++) {
+        if (i%32 == 0) {
+            printf("%p:", addr);
+        }
+        printf(" %02x", *addr);
+        addr++;
+        if (i%32 == 31) {
+            printf("\n");
+        }
+    }
+}
+
+TEST(read_ID,_0x431) {
+    int r = iap.read_ID();
+    ASSERT_TRUE(r == 0x431); 
+}
+
+TEST(erase,sector2) {
+    int r = iap.erase(2, 2);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,sector2) {
+    int r = iap.blank_check(2, 2);
+    //dump((const uint8_t*)0x8008000, 64);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,sector3_sector2) {
+    int r = iap.blank_check(3, 2);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(blank_check,sector8) {
+    int r = iap.blank_check(8, 8);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+uint8_t src[256];
+    
+TEST(write,sector2_0x08008000) {
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)0x08008000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)0x08008000, sizeof(src)) == 0);
+}
+
+TEST(erase,sector2_sector3) {
+    int r = iap.erase(2, 3);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector4) {
+    int r = iap.erase(4, 4);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector5) {
+    int r = iap.erase(5, 5);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector6) {
+    int r = iap.erase(6, 6);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector7) {
+    int r = iap.erase(7, 7);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector8) {
+    int r = iap.erase(8, 8);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(blank_check,sector2_sector7) {
+    int r = iap.blank_check(2, 7);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,sector8_sector9) {
+    int r = iap.blank_check(8, 9);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(write,sector2_0x0800bf00) {
+    const int dst = 0x0800bf00;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector3_0x0800c000) {
+    const int dst = 0x0800c000;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector3_0x0800ff00) {
+    const int dst = 0x0800ff00;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector4_0x08010000) {
+    const int dst = 0x08010000;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector4_0x0801ff00) {
+    const int dst = 0x0801ff00;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector5_0x08020000) {
+    const int dst = 0x08020000;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector5_0x0803ff00) {
+    const int dst = 0x0803ff00;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector6_0x08040000) {
+    const int dst = 0x08040000;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector6_0x0805ff00) {
+    const int dst = 0x0805ff00;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector7_0x08060000) {
+    const int dst = 0x08060000;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector7_0x0807ff00) {
+    const int dst = 0x0807ff00;
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0);
+}
+
+TEST(write,sector8_0x08080000) {
+    const int dst = 0x08080000;
+    int r = iap.write((char*)src, (char*)dst, sizeof(src));
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+int main() {
+    pc.baud(115200);
+    printf("%s\n", __FILE__);
+
+    RUN_ALL_TESTS();
+    for(;;) {
+        led1 = !led1;
+        wait_ms(200);
+    }
+}
+#endif // TARGET_NUCLEO_F411RE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_F446RE.cpp	Sun May 01 01:17:14 2016 +0000
@@ -0,0 +1,101 @@
+#if defined(TARGET_NUCLEO_F446RE)
+#include "mbed.h"
+#include "mytest.h"
+#include "IAP.h"
+
+DigitalOut led1(LED1);
+RawSerial pc(USBTX,USBRX);
+IAP iap;
+
+void dump(const uint8_t* addr, size_t size) {
+    for(size_t i = 0; i < size; i++) {
+        if (i%32 == 0) { printf("%p:", addr); }
+        printf(" %02x%s", *addr++, i%32 == 31 ? "\n" : "");
+    }
+}
+
+TEST(read_ID,test1) {
+    int r = iap.read_ID();
+    ASSERT_TRUE(r == 0x421); 
+}
+
+TEST(erase,sector2) {
+    int r = iap.erase(2, 2);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,sector2) {
+    int r = iap.blank_check(2, 2);
+    //dump((const uint8_t*)0x8008000, 64);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    r = iap.blank_check(3, 2);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+uint8_t src[256];
+    
+TEST(write,sector2_0x08008000) {
+    for(int i = 0; i < sizeof(src); i++) {
+        src[i] = i&0xff;
+    }
+    int r = iap.write((char*)src, (char*)0x08008000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)0x08008000, sizeof(src)) == 0);
+}
+
+TEST(erase,sector3) {
+    int r = iap.erase(3, 3);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector4) {
+    int r = iap.erase(4, 4);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector5) {
+    int r = iap.erase(5, 5);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector6) {
+    int r = iap.erase(6, 6);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector7) {
+    int r = iap.erase(7, 7);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(erase,sector8) {
+    int r = iap.erase(8, 8);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(blank_check,sector3) {
+    int r = iap.blank_check(3, 3);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,sector3_4) {
+    int r = iap.blank_check(3, 4);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,sector3_7) {
+    int r = iap.blank_check(3, 7);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+        
+int main() {
+    pc.baud(115200);
+    printf("%s", __FILE__);
+
+    RUN_ALL_TESTS();
+    for(;;) {
+        led1 = !led1;
+        wait_ms(200);
+    }
+}
+#endif // TARGET_NUCLEO_F446RE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_L031K6.cpp	Sun May 01 01:17:14 2016 +0000
@@ -0,0 +1,142 @@
+#if defined(TARGET_NUCLEO_L031K6)
+#include "mbed.h"
+#include "mytest.h"
+#include "IAP.h"
+
+DigitalOut led1(LED1);
+RawSerial pc(USBTX,USBRX);
+IAP iap;
+
+void dump(const uint8_t* addr, size_t size = 32) {
+    for(size_t i = 0; i < size; i++) {
+        if (i%32 == 0) { printf("%p:", addr); }
+        printf(" %02x%s", *addr++, i%32 == 31 ? "\n" : "");
+    }
+}
+
+TEST(read_ID,test1) {
+    int r = iap.read_ID();
+    ASSERT_TRUE(r == 0x425); 
+}
+
+TEST(erase,page224) {
+    int r = iap.erase(224, 224);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t* p = (uint8_t*)0x08007000;
+    dump((uint8_t*)0x08007000);
+    for(int i = 0; i < 128; i++, p++) {
+        ASSERT_TRUE(*p == 0x00);
+    }
+}
+
+TEST(erase,page256) {
+    int r = iap.erase(256, 256);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(blank_check,page224) {
+    int r = iap.blank_check(224, 224);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,page256) {
+    int r = iap.blank_check(256, 256);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+const uint8_t src[128] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};
+    
+TEST(write,page224_0x08007000) {
+    int r = iap.write((char*)src, (char*)0x08007000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    if (r == CMD_SUCCESS) {
+        ASSERT_TRUE(memcmp(src, (void*)0x08007000, sizeof(src)) == 0);
+    }
+}
+
+TEST(write,page255_0x08007f80) {
+    int r = iap.erase(255, 255);
+    ASSERT_TRUE(r == CMD_SUCCESS);    
+    r = iap.blank_check(255, 255);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    r = iap.write((char*)src, (char*)0x08007f80, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    if (r == CMD_SUCCESS) {
+        ASSERT_TRUE(memcmp(src, (void*)0x08007f80, sizeof(src)) == 0);
+    }
+}
+
+TEST(write,page256_0x08008000) {
+    int r = iap.prepare(256, 256);
+    ASSERT_TRUE(r != CMD_SUCCESS); 
+    r = iap.erase(256, 256);
+    ASSERT_TRUE(r != CMD_SUCCESS);    
+    r = iap.write((char*)src, (char*)0x08008000, sizeof(src));
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(erase,page224_225) {
+    int r = iap.erase(224, 225);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t* p = (uint8_t*)0x08007000;
+    for(int i = 0; i < 128*2; i++, p++) {
+        ASSERT_TRUE(*p == 0x00);
+    }
+}
+
+TEST(blank_check,page224_225) {
+    int r = iap.blank_check(224, 225);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(write_eeprom,_0x08080000) {
+    int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    if (r == CMD_SUCCESS) { 
+        ASSERT_TRUE(memcmp(src,(char*)0x08080000, sizeof(src)) == 0);
+    }
+}
+
+TEST(read_eeprom,_0x08080000) {
+    int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t temp[sizeof(src)];
+    r = iap.read_eeprom((char*)0x08080000, (char*)temp, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    if (r == CMD_SUCCESS) {
+        ASSERT_TRUE(memcmp(temp, src, sizeof(src)) == 0);
+    }
+}
+
+TEST(eeprom,_0x080803f0) { // 0x0808003ff-0x080803ff
+    const size_t size = 16;
+    int r = iap.write_eeprom((char*)src, (char*)0x080803f0, size);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t temp[size];
+    r = iap.read_eeprom((char*)0x080803f0, (char*)temp, sizeof(temp));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    if (r == CMD_SUCCESS) {
+        ASSERT_TRUE(memcmp(temp, src, sizeof(temp)) == 0);
+    }
+}
+
+TEST(eeprom,_0x08080400) { // 0x080800400-0x0808040f
+    const size_t size = 16;
+    int r = iap.write_eeprom((char*)src, (char*)0x08080400, size);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+    uint8_t temp[size];
+    r = iap.read_eeprom((char*)0x08080400, (char*)temp, sizeof(temp));
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+int main() {
+    pc.baud(115200);
+    printf("%s", __FILE__);
+
+    RUN_ALL_TESTS();
+    for(;;) {
+        led1 = !led1;
+        wait_ms(200);
+    }
+}
+#endif // TARGET_NUCLEO_L031K6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_L152RE.cpp	Sun May 01 01:17:14 2016 +0000
@@ -0,0 +1,142 @@
+#if defined(TARGET_NUCLEO_L152RE)
+#include "mbed.h"
+#include "mytest.h"
+#include "IAP.h"
+
+DigitalOut led1(LED1);
+RawSerial pc(USBTX,USBRX);
+IAP iap;
+
+void dump(const uint8_t* addr, size_t size = 32) {
+    for(size_t i = 0; i < size; i++) {
+        if (i%32 == 0) { printf("%p:", addr); }
+        printf(" %02x%s", *addr++, i%32 == 31 ? "\n" : "");
+    }
+}
+
+TEST(read_ID,test1) {
+    int r = iap.read_ID();
+    ASSERT_TRUE(r == 0x437); 
+}
+
+TEST(erase,page480) {
+    int r = iap.erase(480, 480);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t* p = (uint8_t*)0x801e000;
+    dump((uint8_t*)0x801e000);
+    for(int i = 0; i < 256; i++, p++) {
+        ASSERT_TRUE(*p == 0x00);
+    }
+}
+
+TEST(erase,page2047) {
+    int r = iap.erase(2047, 2047);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t* p = (uint8_t*)0x0807ff00;
+    dump((uint8_t*)0x0807ff00);
+    for(int i = 0; i < 256; i++, p++) {
+        ASSERT_TRUE(*p == 0x00);
+    }
+}
+
+TEST(erase,page2048) {
+    int r = iap.erase(2048, 2048);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(blank_check,page480) {
+    int r = iap.blank_check(480, 480);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,page2047) {
+    int r = iap.blank_check(2047, 2047);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(blank_check,page2048) {
+    int r = iap.blank_check(2048, 2048);
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+const uint8_t src[256] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};
+    
+TEST(write,page480_0x0801e000) {
+    ASSERT_TRUE(FLASH_PAGE_SIZE == sizeof(src));
+    int r = iap.write((char*)src, (char*)0x0801e000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src, (void*)0x0801e000, sizeof(src)) == 0);
+}
+
+TEST(erase,page480_481) {
+    int r = iap.erase(480, 481);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t* p = (uint8_t*)0x801e000;
+    for(int i = 0; i < 256*2; i++, p++) {
+        ASSERT_TRUE(*p == 0x00);
+    }
+}
+
+TEST(blank_check,page480_481) {
+    int r = iap.blank_check(480, 481);
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(write_eeprom,_0x08080000) {
+    int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(src,(char*)0x08080000, sizeof(src)) == 0);
+}
+
+TEST(read_eeprom,_0x08080000) {
+    int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t temp[sizeof(src)];
+    r = iap.read_eeprom((char*)0x08080000, (char*)temp, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(temp, src, sizeof(src)) == 0);
+}
+
+TEST(write_eeprom,_0x08082000) {
+    int r = iap.write_eeprom((char*)src, (char*)0x08082000, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+}
+
+TEST(read_eeprom,_0x08082000) {
+    uint8_t temp[sizeof(src)];
+    int r = iap.read_eeprom((char*)0x08082000, (char*)temp, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(temp, src, sizeof(src)) == 0);
+}
+
+TEST(read_eeprom,_0x08084000) {
+    uint8_t temp[sizeof(src)];
+    int r = iap.read_eeprom((char*)0x08084000, (char*)temp, sizeof(src));
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+
+TEST(eeprom,_0x08083f00) {
+    int r = iap.write_eeprom((char*)src, (char*)0x08083f00, sizeof(src));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    uint8_t temp[sizeof(src)];
+    r = iap.read_eeprom((char*)0x08083f00, (char*)temp, sizeof(temp));
+    ASSERT_TRUE(r == CMD_SUCCESS);
+    ASSERT_TRUE(memcmp(temp, src, sizeof(temp)) == 0);
+}
+
+TEST(write_eeprom,_0x08084000) {
+    int r = iap.write_eeprom((char*)src, (char*)0x08084000, sizeof(src));
+    ASSERT_TRUE(r != CMD_SUCCESS);
+}
+        
+int main() {
+    pc.baud(115200);
+    printf("%s", __FILE__);
+
+    RUN_ALL_TESTS();
+    for(;;) {
+        led1 = !led1;
+        wait_ms(200);
+    }
+}
+#endif // TARGET_NUCLEO_L152RE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun May 01 01:17:14 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mytest.h	Sun May 01 01:17:14 2016 +0000
@@ -0,0 +1,81 @@
+// mytest.h 2016/4/30
+#pragma once
+#include "mbed_debug.h"
+
+class BaseTest {
+public:
+    virtual void _run() = 0;
+    char* m_a;
+    char* m_b;
+    int m_line;
+    char* m_file;
+    BaseTest* next;
+};
+
+class reg {
+    BaseTest* head;
+    BaseTest* tail;
+    reg() {
+        head = NULL;
+        tail = NULL;
+    }
+public:
+    static reg* inst() {
+        static reg regtest;
+        return &regtest;
+    }
+    void add(BaseTest* test) {
+        test->next = NULL;
+        if (head == NULL) {
+            head = test;
+            tail = test;
+        } else {
+            tail->next = test;
+            tail = test;
+        }
+    }
+    int run_all_tests(char* a = "") {
+        debug("TEST BUILD at %f\n", MBED_BUILD_TIMESTAMP); 
+        BaseTest* test = head;
+        int pass = 0;
+        int count = 0;
+        char* file = "";
+        while(test) {
+            if (strcmp(a, "") == 0 || strcmp(a, test->m_a) == 0) {
+                if (strcmp(file, test->m_file) != 0) {
+                    file = test->m_file;
+                    debug("%s\n", file);
+                }
+                debug("TEST(%s,%s)@%d ... ",test->m_a, test->m_b, test->m_line);
+                Timer t; t.start();
+                test->_run();
+                debug("OK (%d ms)\n", t.read_ms());
+                pass++;
+            }    
+            test = test->next;
+            count++;
+        }
+        debug("%d/%d TESTS PASSED!!!\n", pass, count);
+        return 0;
+    }
+};
+
+#define TEST(A,B) \
+class class_##A##_##B : public BaseTest { \
+public: \
+    class_##A##_##B(char* a, char* b, char* file, int line) { \
+        m_a = a; m_b = b; \
+        m_file = file; m_line = line; \
+        reg::inst()->add(this); \
+    } \
+    virtual void _run(); \
+}; \
+class_##A##_##B instance_##A##_##B(#A,#B,__FILE__,__LINE__); \
+void class_##A##_##B::_run()
+
+#define RUN_TEST(A,B) instance_##A##_##B._run()
+#define RUN_ALL_TESTS(A) reg::inst()->run_all_tests(#A)
+#define ASSERT_TRUE(A) if(A){}else{debug("\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
+
+#define DBG(FMT, ...) do{debug("[%s:%d]"FMT"\r\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}while(0);
+#define TEST_PRINT(FMT, ...) do{debug("[TEST: %d]"FMT"\r\n", __LINE__, ##__VA_ARGS__);}while(0);