Norimasa Okamoto
/
STM32_IAP_test
STM32_IAP test
main_L031K6.cpp@0:51e4fa01745a, 2016-05-01 (annotated)
- Committer:
- va009039
- Date:
- Sun May 01 01:17:14 2016 +0000
- Revision:
- 0:51e4fa01745a
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:51e4fa01745a | 1 | #if defined(TARGET_NUCLEO_L031K6) |
va009039 | 0:51e4fa01745a | 2 | #include "mbed.h" |
va009039 | 0:51e4fa01745a | 3 | #include "mytest.h" |
va009039 | 0:51e4fa01745a | 4 | #include "IAP.h" |
va009039 | 0:51e4fa01745a | 5 | |
va009039 | 0:51e4fa01745a | 6 | DigitalOut led1(LED1); |
va009039 | 0:51e4fa01745a | 7 | RawSerial pc(USBTX,USBRX); |
va009039 | 0:51e4fa01745a | 8 | IAP iap; |
va009039 | 0:51e4fa01745a | 9 | |
va009039 | 0:51e4fa01745a | 10 | void dump(const uint8_t* addr, size_t size = 32) { |
va009039 | 0:51e4fa01745a | 11 | for(size_t i = 0; i < size; i++) { |
va009039 | 0:51e4fa01745a | 12 | if (i%32 == 0) { printf("%p:", addr); } |
va009039 | 0:51e4fa01745a | 13 | printf(" %02x%s", *addr++, i%32 == 31 ? "\n" : ""); |
va009039 | 0:51e4fa01745a | 14 | } |
va009039 | 0:51e4fa01745a | 15 | } |
va009039 | 0:51e4fa01745a | 16 | |
va009039 | 0:51e4fa01745a | 17 | TEST(read_ID,test1) { |
va009039 | 0:51e4fa01745a | 18 | int r = iap.read_ID(); |
va009039 | 0:51e4fa01745a | 19 | ASSERT_TRUE(r == 0x425); |
va009039 | 0:51e4fa01745a | 20 | } |
va009039 | 0:51e4fa01745a | 21 | |
va009039 | 0:51e4fa01745a | 22 | TEST(erase,page224) { |
va009039 | 0:51e4fa01745a | 23 | int r = iap.erase(224, 224); |
va009039 | 0:51e4fa01745a | 24 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 25 | uint8_t* p = (uint8_t*)0x08007000; |
va009039 | 0:51e4fa01745a | 26 | dump((uint8_t*)0x08007000); |
va009039 | 0:51e4fa01745a | 27 | for(int i = 0; i < 128; i++, p++) { |
va009039 | 0:51e4fa01745a | 28 | ASSERT_TRUE(*p == 0x00); |
va009039 | 0:51e4fa01745a | 29 | } |
va009039 | 0:51e4fa01745a | 30 | } |
va009039 | 0:51e4fa01745a | 31 | |
va009039 | 0:51e4fa01745a | 32 | TEST(erase,page256) { |
va009039 | 0:51e4fa01745a | 33 | int r = iap.erase(256, 256); |
va009039 | 0:51e4fa01745a | 34 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 35 | } |
va009039 | 0:51e4fa01745a | 36 | |
va009039 | 0:51e4fa01745a | 37 | TEST(blank_check,page224) { |
va009039 | 0:51e4fa01745a | 38 | int r = iap.blank_check(224, 224); |
va009039 | 0:51e4fa01745a | 39 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 40 | } |
va009039 | 0:51e4fa01745a | 41 | |
va009039 | 0:51e4fa01745a | 42 | TEST(blank_check,page256) { |
va009039 | 0:51e4fa01745a | 43 | int r = iap.blank_check(256, 256); |
va009039 | 0:51e4fa01745a | 44 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 45 | } |
va009039 | 0:51e4fa01745a | 46 | |
va009039 | 0:51e4fa01745a | 47 | 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}; |
va009039 | 0:51e4fa01745a | 48 | |
va009039 | 0:51e4fa01745a | 49 | TEST(write,page224_0x08007000) { |
va009039 | 0:51e4fa01745a | 50 | int r = iap.write((char*)src, (char*)0x08007000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 51 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 52 | if (r == CMD_SUCCESS) { |
va009039 | 0:51e4fa01745a | 53 | ASSERT_TRUE(memcmp(src, (void*)0x08007000, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 54 | } |
va009039 | 0:51e4fa01745a | 55 | } |
va009039 | 0:51e4fa01745a | 56 | |
va009039 | 0:51e4fa01745a | 57 | TEST(write,page255_0x08007f80) { |
va009039 | 0:51e4fa01745a | 58 | int r = iap.erase(255, 255); |
va009039 | 0:51e4fa01745a | 59 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 60 | r = iap.blank_check(255, 255); |
va009039 | 0:51e4fa01745a | 61 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 62 | r = iap.write((char*)src, (char*)0x08007f80, sizeof(src)); |
va009039 | 0:51e4fa01745a | 63 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 64 | if (r == CMD_SUCCESS) { |
va009039 | 0:51e4fa01745a | 65 | ASSERT_TRUE(memcmp(src, (void*)0x08007f80, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 66 | } |
va009039 | 0:51e4fa01745a | 67 | } |
va009039 | 0:51e4fa01745a | 68 | |
va009039 | 0:51e4fa01745a | 69 | TEST(write,page256_0x08008000) { |
va009039 | 0:51e4fa01745a | 70 | int r = iap.prepare(256, 256); |
va009039 | 0:51e4fa01745a | 71 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 72 | r = iap.erase(256, 256); |
va009039 | 0:51e4fa01745a | 73 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 74 | r = iap.write((char*)src, (char*)0x08008000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 75 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 76 | } |
va009039 | 0:51e4fa01745a | 77 | |
va009039 | 0:51e4fa01745a | 78 | TEST(erase,page224_225) { |
va009039 | 0:51e4fa01745a | 79 | int r = iap.erase(224, 225); |
va009039 | 0:51e4fa01745a | 80 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 81 | uint8_t* p = (uint8_t*)0x08007000; |
va009039 | 0:51e4fa01745a | 82 | for(int i = 0; i < 128*2; i++, p++) { |
va009039 | 0:51e4fa01745a | 83 | ASSERT_TRUE(*p == 0x00); |
va009039 | 0:51e4fa01745a | 84 | } |
va009039 | 0:51e4fa01745a | 85 | } |
va009039 | 0:51e4fa01745a | 86 | |
va009039 | 0:51e4fa01745a | 87 | TEST(blank_check,page224_225) { |
va009039 | 0:51e4fa01745a | 88 | int r = iap.blank_check(224, 225); |
va009039 | 0:51e4fa01745a | 89 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 90 | } |
va009039 | 0:51e4fa01745a | 91 | |
va009039 | 0:51e4fa01745a | 92 | TEST(write_eeprom,_0x08080000) { |
va009039 | 0:51e4fa01745a | 93 | int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 94 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 95 | if (r == CMD_SUCCESS) { |
va009039 | 0:51e4fa01745a | 96 | ASSERT_TRUE(memcmp(src,(char*)0x08080000, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 97 | } |
va009039 | 0:51e4fa01745a | 98 | } |
va009039 | 0:51e4fa01745a | 99 | |
va009039 | 0:51e4fa01745a | 100 | TEST(read_eeprom,_0x08080000) { |
va009039 | 0:51e4fa01745a | 101 | int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 102 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 103 | uint8_t temp[sizeof(src)]; |
va009039 | 0:51e4fa01745a | 104 | r = iap.read_eeprom((char*)0x08080000, (char*)temp, sizeof(src)); |
va009039 | 0:51e4fa01745a | 105 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 106 | if (r == CMD_SUCCESS) { |
va009039 | 0:51e4fa01745a | 107 | ASSERT_TRUE(memcmp(temp, src, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 108 | } |
va009039 | 0:51e4fa01745a | 109 | } |
va009039 | 0:51e4fa01745a | 110 | |
va009039 | 0:51e4fa01745a | 111 | TEST(eeprom,_0x080803f0) { // 0x0808003ff-0x080803ff |
va009039 | 0:51e4fa01745a | 112 | const size_t size = 16; |
va009039 | 0:51e4fa01745a | 113 | int r = iap.write_eeprom((char*)src, (char*)0x080803f0, size); |
va009039 | 0:51e4fa01745a | 114 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 115 | uint8_t temp[size]; |
va009039 | 0:51e4fa01745a | 116 | r = iap.read_eeprom((char*)0x080803f0, (char*)temp, sizeof(temp)); |
va009039 | 0:51e4fa01745a | 117 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 118 | if (r == CMD_SUCCESS) { |
va009039 | 0:51e4fa01745a | 119 | ASSERT_TRUE(memcmp(temp, src, sizeof(temp)) == 0); |
va009039 | 0:51e4fa01745a | 120 | } |
va009039 | 0:51e4fa01745a | 121 | } |
va009039 | 0:51e4fa01745a | 122 | |
va009039 | 0:51e4fa01745a | 123 | TEST(eeprom,_0x08080400) { // 0x080800400-0x0808040f |
va009039 | 0:51e4fa01745a | 124 | const size_t size = 16; |
va009039 | 0:51e4fa01745a | 125 | int r = iap.write_eeprom((char*)src, (char*)0x08080400, size); |
va009039 | 0:51e4fa01745a | 126 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 127 | uint8_t temp[size]; |
va009039 | 0:51e4fa01745a | 128 | r = iap.read_eeprom((char*)0x08080400, (char*)temp, sizeof(temp)); |
va009039 | 0:51e4fa01745a | 129 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 130 | } |
va009039 | 0:51e4fa01745a | 131 | |
va009039 | 0:51e4fa01745a | 132 | int main() { |
va009039 | 0:51e4fa01745a | 133 | pc.baud(115200); |
va009039 | 0:51e4fa01745a | 134 | printf("%s", __FILE__); |
va009039 | 0:51e4fa01745a | 135 | |
va009039 | 0:51e4fa01745a | 136 | RUN_ALL_TESTS(); |
va009039 | 0:51e4fa01745a | 137 | for(;;) { |
va009039 | 0:51e4fa01745a | 138 | led1 = !led1; |
va009039 | 0:51e4fa01745a | 139 | wait_ms(200); |
va009039 | 0:51e4fa01745a | 140 | } |
va009039 | 0:51e4fa01745a | 141 | } |
va009039 | 0:51e4fa01745a | 142 | #endif // TARGET_NUCLEO_L031K6 |