Norimasa Okamoto
/
STM32_IAP_test
STM32_IAP test
main_F411RE.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_F411RE) |
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) { |
va009039 | 0:51e4fa01745a | 11 | for(size_t i = 0; i < size; i++) { |
va009039 | 0:51e4fa01745a | 12 | if (i%32 == 0) { |
va009039 | 0:51e4fa01745a | 13 | printf("%p:", addr); |
va009039 | 0:51e4fa01745a | 14 | } |
va009039 | 0:51e4fa01745a | 15 | printf(" %02x", *addr); |
va009039 | 0:51e4fa01745a | 16 | addr++; |
va009039 | 0:51e4fa01745a | 17 | if (i%32 == 31) { |
va009039 | 0:51e4fa01745a | 18 | printf("\n"); |
va009039 | 0:51e4fa01745a | 19 | } |
va009039 | 0:51e4fa01745a | 20 | } |
va009039 | 0:51e4fa01745a | 21 | } |
va009039 | 0:51e4fa01745a | 22 | |
va009039 | 0:51e4fa01745a | 23 | TEST(read_ID,_0x431) { |
va009039 | 0:51e4fa01745a | 24 | int r = iap.read_ID(); |
va009039 | 0:51e4fa01745a | 25 | ASSERT_TRUE(r == 0x431); |
va009039 | 0:51e4fa01745a | 26 | } |
va009039 | 0:51e4fa01745a | 27 | |
va009039 | 0:51e4fa01745a | 28 | TEST(erase,sector2) { |
va009039 | 0:51e4fa01745a | 29 | int r = iap.erase(2, 2); |
va009039 | 0:51e4fa01745a | 30 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 31 | } |
va009039 | 0:51e4fa01745a | 32 | |
va009039 | 0:51e4fa01745a | 33 | TEST(blank_check,sector2) { |
va009039 | 0:51e4fa01745a | 34 | int r = iap.blank_check(2, 2); |
va009039 | 0:51e4fa01745a | 35 | //dump((const uint8_t*)0x8008000, 64); |
va009039 | 0:51e4fa01745a | 36 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 37 | } |
va009039 | 0:51e4fa01745a | 38 | |
va009039 | 0:51e4fa01745a | 39 | TEST(blank_check,sector3_sector2) { |
va009039 | 0:51e4fa01745a | 40 | int r = iap.blank_check(3, 2); |
va009039 | 0:51e4fa01745a | 41 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 42 | } |
va009039 | 0:51e4fa01745a | 43 | |
va009039 | 0:51e4fa01745a | 44 | TEST(blank_check,sector8) { |
va009039 | 0:51e4fa01745a | 45 | int r = iap.blank_check(8, 8); |
va009039 | 0:51e4fa01745a | 46 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 47 | } |
va009039 | 0:51e4fa01745a | 48 | |
va009039 | 0:51e4fa01745a | 49 | uint8_t src[256]; |
va009039 | 0:51e4fa01745a | 50 | |
va009039 | 0:51e4fa01745a | 51 | TEST(write,sector2_0x08008000) { |
va009039 | 0:51e4fa01745a | 52 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 53 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 54 | } |
va009039 | 0:51e4fa01745a | 55 | int r = iap.write((char*)src, (char*)0x08008000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 56 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 57 | ASSERT_TRUE(memcmp(src, (void*)0x08008000, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 58 | } |
va009039 | 0:51e4fa01745a | 59 | |
va009039 | 0:51e4fa01745a | 60 | TEST(erase,sector2_sector3) { |
va009039 | 0:51e4fa01745a | 61 | int r = iap.erase(2, 3); |
va009039 | 0:51e4fa01745a | 62 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 63 | } |
va009039 | 0:51e4fa01745a | 64 | |
va009039 | 0:51e4fa01745a | 65 | TEST(erase,sector4) { |
va009039 | 0:51e4fa01745a | 66 | int r = iap.erase(4, 4); |
va009039 | 0:51e4fa01745a | 67 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 68 | } |
va009039 | 0:51e4fa01745a | 69 | |
va009039 | 0:51e4fa01745a | 70 | TEST(erase,sector5) { |
va009039 | 0:51e4fa01745a | 71 | int r = iap.erase(5, 5); |
va009039 | 0:51e4fa01745a | 72 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 73 | } |
va009039 | 0:51e4fa01745a | 74 | |
va009039 | 0:51e4fa01745a | 75 | TEST(erase,sector6) { |
va009039 | 0:51e4fa01745a | 76 | int r = iap.erase(6, 6); |
va009039 | 0:51e4fa01745a | 77 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 78 | } |
va009039 | 0:51e4fa01745a | 79 | |
va009039 | 0:51e4fa01745a | 80 | TEST(erase,sector7) { |
va009039 | 0:51e4fa01745a | 81 | int r = iap.erase(7, 7); |
va009039 | 0:51e4fa01745a | 82 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 83 | } |
va009039 | 0:51e4fa01745a | 84 | |
va009039 | 0:51e4fa01745a | 85 | TEST(erase,sector8) { |
va009039 | 0:51e4fa01745a | 86 | int r = iap.erase(8, 8); |
va009039 | 0:51e4fa01745a | 87 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 88 | } |
va009039 | 0:51e4fa01745a | 89 | |
va009039 | 0:51e4fa01745a | 90 | TEST(blank_check,sector2_sector7) { |
va009039 | 0:51e4fa01745a | 91 | int r = iap.blank_check(2, 7); |
va009039 | 0:51e4fa01745a | 92 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 93 | } |
va009039 | 0:51e4fa01745a | 94 | |
va009039 | 0:51e4fa01745a | 95 | TEST(blank_check,sector8_sector9) { |
va009039 | 0:51e4fa01745a | 96 | int r = iap.blank_check(8, 9); |
va009039 | 0:51e4fa01745a | 97 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 98 | } |
va009039 | 0:51e4fa01745a | 99 | |
va009039 | 0:51e4fa01745a | 100 | TEST(write,sector2_0x0800bf00) { |
va009039 | 0:51e4fa01745a | 101 | const int dst = 0x0800bf00; |
va009039 | 0:51e4fa01745a | 102 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 103 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 104 | } |
va009039 | 0:51e4fa01745a | 105 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 106 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 107 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 108 | } |
va009039 | 0:51e4fa01745a | 109 | |
va009039 | 0:51e4fa01745a | 110 | TEST(write,sector3_0x0800c000) { |
va009039 | 0:51e4fa01745a | 111 | const int dst = 0x0800c000; |
va009039 | 0:51e4fa01745a | 112 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 113 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 114 | } |
va009039 | 0:51e4fa01745a | 115 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 116 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 117 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 118 | } |
va009039 | 0:51e4fa01745a | 119 | |
va009039 | 0:51e4fa01745a | 120 | TEST(write,sector3_0x0800ff00) { |
va009039 | 0:51e4fa01745a | 121 | const int dst = 0x0800ff00; |
va009039 | 0:51e4fa01745a | 122 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 123 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 124 | } |
va009039 | 0:51e4fa01745a | 125 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 126 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 127 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 128 | } |
va009039 | 0:51e4fa01745a | 129 | |
va009039 | 0:51e4fa01745a | 130 | TEST(write,sector4_0x08010000) { |
va009039 | 0:51e4fa01745a | 131 | const int dst = 0x08010000; |
va009039 | 0:51e4fa01745a | 132 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 133 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 134 | } |
va009039 | 0:51e4fa01745a | 135 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 136 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 137 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 138 | } |
va009039 | 0:51e4fa01745a | 139 | |
va009039 | 0:51e4fa01745a | 140 | TEST(write,sector4_0x0801ff00) { |
va009039 | 0:51e4fa01745a | 141 | const int dst = 0x0801ff00; |
va009039 | 0:51e4fa01745a | 142 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 143 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 144 | } |
va009039 | 0:51e4fa01745a | 145 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 146 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 147 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 148 | } |
va009039 | 0:51e4fa01745a | 149 | |
va009039 | 0:51e4fa01745a | 150 | TEST(write,sector5_0x08020000) { |
va009039 | 0:51e4fa01745a | 151 | const int dst = 0x08020000; |
va009039 | 0:51e4fa01745a | 152 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 153 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 154 | } |
va009039 | 0:51e4fa01745a | 155 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 156 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 157 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 158 | } |
va009039 | 0:51e4fa01745a | 159 | |
va009039 | 0:51e4fa01745a | 160 | TEST(write,sector5_0x0803ff00) { |
va009039 | 0:51e4fa01745a | 161 | const int dst = 0x0803ff00; |
va009039 | 0:51e4fa01745a | 162 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 163 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 164 | } |
va009039 | 0:51e4fa01745a | 165 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 166 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 167 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 168 | } |
va009039 | 0:51e4fa01745a | 169 | |
va009039 | 0:51e4fa01745a | 170 | TEST(write,sector6_0x08040000) { |
va009039 | 0:51e4fa01745a | 171 | const int dst = 0x08040000; |
va009039 | 0:51e4fa01745a | 172 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 173 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 174 | } |
va009039 | 0:51e4fa01745a | 175 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 176 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 177 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 178 | } |
va009039 | 0:51e4fa01745a | 179 | |
va009039 | 0:51e4fa01745a | 180 | TEST(write,sector6_0x0805ff00) { |
va009039 | 0:51e4fa01745a | 181 | const int dst = 0x0805ff00; |
va009039 | 0:51e4fa01745a | 182 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 183 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 184 | } |
va009039 | 0:51e4fa01745a | 185 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 186 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 187 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 188 | } |
va009039 | 0:51e4fa01745a | 189 | |
va009039 | 0:51e4fa01745a | 190 | TEST(write,sector7_0x08060000) { |
va009039 | 0:51e4fa01745a | 191 | const int dst = 0x08060000; |
va009039 | 0:51e4fa01745a | 192 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 193 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 194 | } |
va009039 | 0:51e4fa01745a | 195 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 196 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 197 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 198 | } |
va009039 | 0:51e4fa01745a | 199 | |
va009039 | 0:51e4fa01745a | 200 | TEST(write,sector7_0x0807ff00) { |
va009039 | 0:51e4fa01745a | 201 | const int dst = 0x0807ff00; |
va009039 | 0:51e4fa01745a | 202 | for(int i = 0; i < sizeof(src); i++) { |
va009039 | 0:51e4fa01745a | 203 | src[i] = i&0xff; |
va009039 | 0:51e4fa01745a | 204 | } |
va009039 | 0:51e4fa01745a | 205 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 206 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 207 | ASSERT_TRUE(memcmp(src, (void*)dst, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 208 | } |
va009039 | 0:51e4fa01745a | 209 | |
va009039 | 0:51e4fa01745a | 210 | TEST(write,sector8_0x08080000) { |
va009039 | 0:51e4fa01745a | 211 | const int dst = 0x08080000; |
va009039 | 0:51e4fa01745a | 212 | int r = iap.write((char*)src, (char*)dst, sizeof(src)); |
va009039 | 0:51e4fa01745a | 213 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 214 | } |
va009039 | 0:51e4fa01745a | 215 | |
va009039 | 0:51e4fa01745a | 216 | int main() { |
va009039 | 0:51e4fa01745a | 217 | pc.baud(115200); |
va009039 | 0:51e4fa01745a | 218 | printf("%s\n", __FILE__); |
va009039 | 0:51e4fa01745a | 219 | |
va009039 | 0:51e4fa01745a | 220 | RUN_ALL_TESTS(); |
va009039 | 0:51e4fa01745a | 221 | for(;;) { |
va009039 | 0:51e4fa01745a | 222 | led1 = !led1; |
va009039 | 0:51e4fa01745a | 223 | wait_ms(200); |
va009039 | 0:51e4fa01745a | 224 | } |
va009039 | 0:51e4fa01745a | 225 | } |
va009039 | 0:51e4fa01745a | 226 | #endif // TARGET_NUCLEO_F411RE |