Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison flash.c @ 75:85f16813c730
Convert \r\n to \n
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 18 Apr 2013 22:44:52 +0930 |
parents | 778adff8b569 |
children |
comparison
equal
deleted
inserted
replaced
74:3f1c101f89bc | 75:85f16813c730 |
---|---|
32 flashcmd(int argc, char **argv) { | 32 flashcmd(int argc, char **argv) { |
33 uint8_t status, tmp, len; | 33 uint8_t status, tmp, len; |
34 uint32_t addr; | 34 uint32_t addr; |
35 | 35 |
36 if (argc == 0) { | 36 if (argc == 0) { |
37 fputs("No command specified\r\n", stdout); | 37 fputs("No command specified\n", stdout); |
38 return; | 38 return; |
39 } | 39 } |
40 | 40 |
41 if (!strcmp(argv[0], "str")) { | 41 if (!strcmp(argv[0], "str")) { |
42 status = flashreadstatus(); | 42 status = flashreadstatus(); |
44 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++) | 44 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++) |
45 if (status & 1 << i) { | 45 if (status & 1 << i) { |
46 fputs(flstattbl[i], stdout); | 46 fputs(flstattbl[i], stdout); |
47 fputs(" ", stdout); | 47 fputs(" ", stdout); |
48 } | 48 } |
49 printf("(0x%02x)\r\n", status); | 49 printf("(0x%02x)\n", status); |
50 } else if (!strcmp(argv[0], "stw")) { | 50 } else if (!strcmp(argv[0], "stw")) { |
51 if (argc != 2) { | 51 if (argc != 2) { |
52 fputs("Incorrect number of arguments\r\n", stdout); | 52 fputs("Incorrect number of arguments\n", stdout); |
53 return; | 53 return; |
54 } | 54 } |
55 tmp = atoi(argv[1]); | 55 tmp = atoi(argv[1]); |
56 flashwritestatus(tmp); | 56 flashwritestatus(tmp); |
57 status = flashreadstatus(); | 57 status = flashreadstatus(); |
58 printf("Wrote 0x%02x to status, now 0x%02x\r\n", tmp, status); | 58 printf("Wrote 0x%02x to status, now 0x%02x\n", tmp, status); |
59 } else if (!strcmp(argv[0], "er")) { | 59 } else if (!strcmp(argv[0], "er")) { |
60 if (argc != 2) { | 60 if (argc != 2) { |
61 fputs("Incorrect number of arguments\r\n", stdout); | 61 fputs("Incorrect number of arguments\n", stdout); |
62 return; | 62 return; |
63 } | 63 } |
64 addr = atoi(argv[1]); | 64 addr = atoi(argv[1]); |
65 flash4kerase(addr); | 65 flash4kerase(addr); |
66 printf("Erased 0x%x\r\n", (unsigned int)addr); | 66 printf("Erased 0x%x\n", (unsigned int)addr); |
67 } else if (!strcmp(argv[0], "rd")) { | 67 } else if (!strcmp(argv[0], "rd")) { |
68 if (argc < 2) { | 68 if (argc < 2) { |
69 fputs("Incorrect number of arguments\r\n", stdout); | 69 fputs("Incorrect number of arguments\n", stdout); |
70 return; | 70 return; |
71 } | 71 } |
72 | 72 |
73 addr = atoi(argv[1]); | 73 addr = atoi(argv[1]); |
74 | 74 |
78 len = 16; | 78 len = 16; |
79 | 79 |
80 flashstartread(addr); | 80 flashstartread(addr); |
81 | 81 |
82 for (uint32_t i = 0; i < len; i++) | 82 for (uint32_t i = 0; i < len; i++) |
83 printf("Read 0x%02x from 0x%06x\r\n", flashreadbyte(), (unsigned int)(addr + i)); | 83 printf("Read 0x%02x from 0x%06x\n", flashreadbyte(), (unsigned int)(addr + i)); |
84 flashstopread(); | 84 flashstopread(); |
85 | 85 |
86 fputs("\r\n", stdout); | 86 fputs("\n", stdout); |
87 } else if (!strcmp(argv[0], "wr")) { | 87 } else if (!strcmp(argv[0], "wr")) { |
88 if (argc < 2) { | 88 if (argc < 2) { |
89 fputs("Incorrect number of arguments\r\n", stdout); | 89 fputs("Incorrect number of arguments\n", stdout); |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 addr = atoi(argv[1]); | 93 addr = atoi(argv[1]); |
94 | 94 |
98 len = 16; | 98 len = 16; |
99 | 99 |
100 for (int i = 0; i < 16; i += 2) { | 100 for (int i = 0; i < 16; i += 2) { |
101 uint16_t data; | 101 uint16_t data; |
102 data = ((i + 1) << 8) | i; | 102 data = ((i + 1) << 8) | i; |
103 printf("Writing 0x%04x to 0x%06x\r\n", data, (unsigned int)(addr + i)); | 103 printf("Writing 0x%04x to 0x%06x\n", data, (unsigned int)(addr + i)); |
104 | 104 |
105 if (i == 0) | 105 if (i == 0) |
106 flashstartwrite(addr, data); | 106 flashstartwrite(addr, data); |
107 else | 107 else |
108 flashwriteword(data); | 108 flashwriteword(data); |
109 } | 109 } |
110 flashstopwrite(); | 110 flashstopwrite(); |
111 } else if (!strcmp(argv[0], "id")) { | 111 } else if (!strcmp(argv[0], "id")) { |
112 printf("Flash ID = 0x%04hx (expect 0xbf41)\r\n", flashreadid()); | 112 printf("Flash ID = 0x%04hx (expect 0xbf41)\n", flashreadid()); |
113 } else { | 113 } else { |
114 fputs("Unknown sub command\r\n", stdout); | 114 fputs("Unknown sub command\n", stdout); |
115 return; | 115 return; |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 void | 119 void |
139 | 139 |
140 /* Wait for not BUSY */ | 140 /* Wait for not BUSY */ |
141 for (cnt = 0; (flashreadstatus() & FL_BUSY) != 0; cnt++) | 141 for (cnt = 0; (flashreadstatus() & FL_BUSY) != 0; cnt++) |
142 ; | 142 ; |
143 | 143 |
144 //printf("cnt = %d\r\n", cnt); | 144 //printf("cnt = %d\n", cnt); |
145 } | 145 } |
146 | 146 |
147 uint16_t | 147 uint16_t |
148 flashreadid(void) { | 148 flashreadid(void) { |
149 uint8_t fac, dev; | 149 uint8_t fac, dev; |
360 | 360 |
361 flashstopread(); | 361 flashstopread(); |
362 | 362 |
363 ramcrc = CRC_GetCRC(); | 363 ramcrc = CRC_GetCRC(); |
364 | 364 |
365 /* printf("RAM CRC 0x%08x Flash CRC 0x%08x\r\n", (uint)ramcrc, (uint)flashcrc); */ | 365 /* printf("RAM CRC 0x%08x Flash CRC 0x%08x\n", (uint)ramcrc, (uint)flashcrc); */ |
366 if (ramcrc == flashcrc) | 366 if (ramcrc == flashcrc) |
367 return 1; | 367 return 1; |
368 else | 368 else |
369 return 0; | 369 return 0; |
370 } | 370 } |
387 int | 387 int |
388 flashwriteblock(uint32_t addr, uint32_t len, void *_data) { | 388 flashwriteblock(uint32_t addr, uint32_t len, void *_data) { |
389 uint16_t *data = _data; | 389 uint16_t *data = _data; |
390 uint32_t crc, vcrc; | 390 uint32_t crc, vcrc; |
391 | 391 |
392 //printf("Writing %u bytes to 0x%06x\r\n", (uint)len, (uint)addr); | 392 //printf("Writing %u bytes to 0x%06x\n", (uint)len, (uint)addr); |
393 | 393 |
394 /* Ensure data is | 394 /* Ensure data is |
395 * - 16 bit aligned | 395 * - 16 bit aligned |
396 * - a multiple of 32 bits in length (for CRCs, the flash only need 16 bits) | 396 * - a multiple of 32 bits in length (for CRCs, the flash only need 16 bits) |
397 * - not longer than a sector | 397 * - not longer than a sector |
419 } | 419 } |
420 | 420 |
421 /* Calculate CRC */ | 421 /* Calculate CRC */ |
422 crc = CRC_GetCRC(); | 422 crc = CRC_GetCRC(); |
423 | 423 |
424 //printf("CRC is 0x%08x\r\n", (uint)crc); | 424 //printf("CRC is 0x%08x\n", (uint)crc); |
425 | 425 |
426 /* Write CRC */ | 426 /* Write CRC */ |
427 flashwriteword(crc); | 427 flashwriteword(crc); |
428 flashwriteword(crc >> 16); | 428 flashwriteword(crc >> 16); |
429 | 429 |