Norimasa Okamoto
/
STM32_IAP_test
STM32_IAP test
main_L152RE.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_L152RE) |
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 == 0x437); |
va009039 | 0:51e4fa01745a | 20 | } |
va009039 | 0:51e4fa01745a | 21 | |
va009039 | 0:51e4fa01745a | 22 | TEST(erase,page480) { |
va009039 | 0:51e4fa01745a | 23 | int r = iap.erase(480, 480); |
va009039 | 0:51e4fa01745a | 24 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 25 | uint8_t* p = (uint8_t*)0x801e000; |
va009039 | 0:51e4fa01745a | 26 | dump((uint8_t*)0x801e000); |
va009039 | 0:51e4fa01745a | 27 | for(int i = 0; i < 256; 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,page2047) { |
va009039 | 0:51e4fa01745a | 33 | int r = iap.erase(2047, 2047); |
va009039 | 0:51e4fa01745a | 34 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 35 | uint8_t* p = (uint8_t*)0x0807ff00; |
va009039 | 0:51e4fa01745a | 36 | dump((uint8_t*)0x0807ff00); |
va009039 | 0:51e4fa01745a | 37 | for(int i = 0; i < 256; i++, p++) { |
va009039 | 0:51e4fa01745a | 38 | ASSERT_TRUE(*p == 0x00); |
va009039 | 0:51e4fa01745a | 39 | } |
va009039 | 0:51e4fa01745a | 40 | } |
va009039 | 0:51e4fa01745a | 41 | |
va009039 | 0:51e4fa01745a | 42 | TEST(erase,page2048) { |
va009039 | 0:51e4fa01745a | 43 | int r = iap.erase(2048, 2048); |
va009039 | 0:51e4fa01745a | 44 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 45 | } |
va009039 | 0:51e4fa01745a | 46 | |
va009039 | 0:51e4fa01745a | 47 | TEST(blank_check,page480) { |
va009039 | 0:51e4fa01745a | 48 | int r = iap.blank_check(480, 480); |
va009039 | 0:51e4fa01745a | 49 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 50 | } |
va009039 | 0:51e4fa01745a | 51 | |
va009039 | 0:51e4fa01745a | 52 | TEST(blank_check,page2047) { |
va009039 | 0:51e4fa01745a | 53 | int r = iap.blank_check(2047, 2047); |
va009039 | 0:51e4fa01745a | 54 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 55 | } |
va009039 | 0:51e4fa01745a | 56 | |
va009039 | 0:51e4fa01745a | 57 | TEST(blank_check,page2048) { |
va009039 | 0:51e4fa01745a | 58 | int r = iap.blank_check(2048, 2048); |
va009039 | 0:51e4fa01745a | 59 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 60 | } |
va009039 | 0:51e4fa01745a | 61 | |
va009039 | 0:51e4fa01745a | 62 | 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}; |
va009039 | 0:51e4fa01745a | 63 | |
va009039 | 0:51e4fa01745a | 64 | TEST(write,page480_0x0801e000) { |
va009039 | 0:51e4fa01745a | 65 | ASSERT_TRUE(FLASH_PAGE_SIZE == sizeof(src)); |
va009039 | 0:51e4fa01745a | 66 | int r = iap.write((char*)src, (char*)0x0801e000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 67 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 68 | ASSERT_TRUE(memcmp(src, (void*)0x0801e000, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 69 | } |
va009039 | 0:51e4fa01745a | 70 | |
va009039 | 0:51e4fa01745a | 71 | TEST(erase,page480_481) { |
va009039 | 0:51e4fa01745a | 72 | int r = iap.erase(480, 481); |
va009039 | 0:51e4fa01745a | 73 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 74 | uint8_t* p = (uint8_t*)0x801e000; |
va009039 | 0:51e4fa01745a | 75 | for(int i = 0; i < 256*2; i++, p++) { |
va009039 | 0:51e4fa01745a | 76 | ASSERT_TRUE(*p == 0x00); |
va009039 | 0:51e4fa01745a | 77 | } |
va009039 | 0:51e4fa01745a | 78 | } |
va009039 | 0:51e4fa01745a | 79 | |
va009039 | 0:51e4fa01745a | 80 | TEST(blank_check,page480_481) { |
va009039 | 0:51e4fa01745a | 81 | int r = iap.blank_check(480, 481); |
va009039 | 0:51e4fa01745a | 82 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 83 | } |
va009039 | 0:51e4fa01745a | 84 | |
va009039 | 0:51e4fa01745a | 85 | TEST(write_eeprom,_0x08080000) { |
va009039 | 0:51e4fa01745a | 86 | int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 87 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 88 | ASSERT_TRUE(memcmp(src,(char*)0x08080000, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 89 | } |
va009039 | 0:51e4fa01745a | 90 | |
va009039 | 0:51e4fa01745a | 91 | TEST(read_eeprom,_0x08080000) { |
va009039 | 0:51e4fa01745a | 92 | int r = iap.write_eeprom((char*)src, (char*)0x08080000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 93 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 94 | uint8_t temp[sizeof(src)]; |
va009039 | 0:51e4fa01745a | 95 | r = iap.read_eeprom((char*)0x08080000, (char*)temp, sizeof(src)); |
va009039 | 0:51e4fa01745a | 96 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 97 | ASSERT_TRUE(memcmp(temp, src, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 98 | } |
va009039 | 0:51e4fa01745a | 99 | |
va009039 | 0:51e4fa01745a | 100 | TEST(write_eeprom,_0x08082000) { |
va009039 | 0:51e4fa01745a | 101 | int r = iap.write_eeprom((char*)src, (char*)0x08082000, sizeof(src)); |
va009039 | 0:51e4fa01745a | 102 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 103 | } |
va009039 | 0:51e4fa01745a | 104 | |
va009039 | 0:51e4fa01745a | 105 | TEST(read_eeprom,_0x08082000) { |
va009039 | 0:51e4fa01745a | 106 | uint8_t temp[sizeof(src)]; |
va009039 | 0:51e4fa01745a | 107 | int r = iap.read_eeprom((char*)0x08082000, (char*)temp, sizeof(src)); |
va009039 | 0:51e4fa01745a | 108 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 109 | ASSERT_TRUE(memcmp(temp, src, sizeof(src)) == 0); |
va009039 | 0:51e4fa01745a | 110 | } |
va009039 | 0:51e4fa01745a | 111 | |
va009039 | 0:51e4fa01745a | 112 | TEST(read_eeprom,_0x08084000) { |
va009039 | 0:51e4fa01745a | 113 | uint8_t temp[sizeof(src)]; |
va009039 | 0:51e4fa01745a | 114 | int r = iap.read_eeprom((char*)0x08084000, (char*)temp, sizeof(src)); |
va009039 | 0:51e4fa01745a | 115 | ASSERT_TRUE(r != CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 116 | } |
va009039 | 0:51e4fa01745a | 117 | |
va009039 | 0:51e4fa01745a | 118 | TEST(eeprom,_0x08083f00) { |
va009039 | 0:51e4fa01745a | 119 | int r = iap.write_eeprom((char*)src, (char*)0x08083f00, sizeof(src)); |
va009039 | 0:51e4fa01745a | 120 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 121 | uint8_t temp[sizeof(src)]; |
va009039 | 0:51e4fa01745a | 122 | r = iap.read_eeprom((char*)0x08083f00, (char*)temp, sizeof(temp)); |
va009039 | 0:51e4fa01745a | 123 | ASSERT_TRUE(r == CMD_SUCCESS); |
va009039 | 0:51e4fa01745a | 124 | ASSERT_TRUE(memcmp(temp, src, sizeof(temp)) == 0); |
va009039 | 0:51e4fa01745a | 125 | } |
va009039 | 0:51e4fa01745a | 126 | |
va009039 | 0:51e4fa01745a | 127 | TEST(write_eeprom,_0x08084000) { |
va009039 | 0:51e4fa01745a | 128 | int r = iap.write_eeprom((char*)src, (char*)0x08084000, sizeof(src)); |
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_L152RE |