eeprom_teensy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. #include <ch.h>
  2. #include <hal.h>
  3. #include "eeprom_teensy.h"
  4. #include "eeconfig.h"
  5. /*************************************/
  6. /* Hardware backend */
  7. /* */
  8. /* Code from PJRC/Teensyduino */
  9. /*************************************/
  10. /* Teensyduino Core Library
  11. * http://www.pjrc.com/teensy/
  12. * Copyright (c) 2013 PJRC.COM, LLC.
  13. *
  14. * Permission is hereby granted, free of charge, to any person obtaining
  15. * a copy of this software and associated documentation files (the
  16. * "Software"), to deal in the Software without restriction, including
  17. * without limitation the rights to use, copy, modify, merge, publish,
  18. * distribute, sublicense, and/or sell copies of the Software, and to
  19. * permit persons to whom the Software is furnished to do so, subject to
  20. * the following conditions:
  21. *
  22. * 1. The above copyright notice and this permission notice shall be
  23. * included in all copies or substantial portions of the Software.
  24. *
  25. * 2. If the Software is incorporated into a build system that allows
  26. * selection among a list of target devices, then similar target
  27. * devices manufactured by PJRC.COM must be included in the list of
  28. * target devices and selectable in the same manner.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  31. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  33. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  34. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  35. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  36. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  37. * SOFTWARE.
  38. */
  39. #if defined(K20x) /* chip selection */
  40. /* Teensy 3.0, 3.1, 3.2; mchck; infinity keyboard */
  41. /*
  42. ^^^ Here be dragons:
  43. NXP AppNote AN4282 section 3.1 states that partitioning must only be done once.
  44. Once EEPROM partitioning is done, the size is locked to this initial configuration.
  45. Attempts to modify the EEPROM_SIZE setting may brick your board.
  46. */
  47. // Writing unaligned 16 or 32 bit data is handled automatically when
  48. // this is defined, but at a cost of extra code size. Without this,
  49. // any unaligned write will cause a hard fault exception! If you're
  50. // absolutely sure all 16 and 32 bit writes will be aligned, you can
  51. // remove the extra unnecessary code.
  52. //
  53. # define HANDLE_UNALIGNED_WRITES
  54. // Minimum EEPROM Endurance
  55. // ------------------------
  56. # if (EEPROM_SIZE == 2048) // 35000 writes/byte or 70000 writes/word
  57. # define EEESIZE 0x33
  58. # elif (EEPROM_SIZE == 1024) // 75000 writes/byte or 150000 writes/word
  59. # define EEESIZE 0x34
  60. # elif (EEPROM_SIZE == 512) // 155000 writes/byte or 310000 writes/word
  61. # define EEESIZE 0x35
  62. # elif (EEPROM_SIZE == 256) // 315000 writes/byte or 630000 writes/word
  63. # define EEESIZE 0x36
  64. # elif (EEPROM_SIZE == 128) // 635000 writes/byte or 1270000 writes/word
  65. # define EEESIZE 0x37
  66. # elif (EEPROM_SIZE == 64) // 1275000 writes/byte or 2550000 writes/word
  67. # define EEESIZE 0x38
  68. # elif (EEPROM_SIZE == 32) // 2555000 writes/byte or 5110000 writes/word
  69. # define EEESIZE 0x39
  70. # endif
  71. /** \brief eeprom initialization
  72. *
  73. * FIXME: needs doc
  74. */
  75. void eeprom_initialize(void) {
  76. uint32_t count = 0;
  77. uint16_t do_flash_cmd[] = {0xf06f, 0x037f, 0x7003, 0x7803, 0xf013, 0x0f80, 0xd0fb, 0x4770};
  78. uint8_t status;
  79. if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) {
  80. // FlexRAM is configured as traditional RAM
  81. // We need to reconfigure for EEPROM usage
  82. FTFL->FCCOB0 = 0x80; // PGMPART = Program Partition Command
  83. FTFL->FCCOB4 = EEESIZE; // EEPROM Size
  84. FTFL->FCCOB5 = 0x03; // 0K for Dataflash, 32K for EEPROM backup
  85. __disable_irq();
  86. // do_flash_cmd() must execute from RAM. Luckily the C syntax is simple...
  87. (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT));
  88. __enable_irq();
  89. status = FTFL->FSTAT;
  90. if (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL)) {
  91. FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL));
  92. return; // error
  93. }
  94. }
  95. // wait for eeprom to become ready (is this really necessary?)
  96. while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
  97. if (++count > 20000) break;
  98. }
  99. }
  100. # define FlexRAM ((uint8_t *)0x14000000)
  101. /** \brief eeprom read byte
  102. *
  103. * FIXME: needs doc
  104. */
  105. uint8_t eeprom_read_byte(const uint8_t *addr) {
  106. uint32_t offset = (uint32_t)addr;
  107. if (offset >= EEPROM_SIZE) return 0;
  108. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  109. return FlexRAM[offset];
  110. }
  111. /** \brief eeprom read word
  112. *
  113. * FIXME: needs doc
  114. */
  115. uint16_t eeprom_read_word(const uint16_t *addr) {
  116. uint32_t offset = (uint32_t)addr;
  117. if (offset >= EEPROM_SIZE - 1) return 0;
  118. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  119. return *(uint16_t *)(&FlexRAM[offset]);
  120. }
  121. /** \brief eeprom read dword
  122. *
  123. * FIXME: needs doc
  124. */
  125. uint32_t eeprom_read_dword(const uint32_t *addr) {
  126. uint32_t offset = (uint32_t)addr;
  127. if (offset >= EEPROM_SIZE - 3) return 0;
  128. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  129. return *(uint32_t *)(&FlexRAM[offset]);
  130. }
  131. /** \brief eeprom read block
  132. *
  133. * FIXME: needs doc
  134. */
  135. void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
  136. uint32_t offset = (uint32_t)addr;
  137. uint8_t *dest = (uint8_t *)buf;
  138. uint32_t end = offset + len;
  139. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  140. if (end > EEPROM_SIZE) end = EEPROM_SIZE;
  141. while (offset < end) {
  142. *dest++ = FlexRAM[offset++];
  143. }
  144. }
  145. /** \brief eeprom is ready
  146. *
  147. * FIXME: needs doc
  148. */
  149. int eeprom_is_ready(void) {
  150. return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0;
  151. }
  152. /** \brief flexram wait
  153. *
  154. * FIXME: needs doc
  155. */
  156. static void flexram_wait(void) {
  157. while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
  158. // TODO: timeout
  159. }
  160. }
  161. /** \brief eeprom_write_byte
  162. *
  163. * FIXME: needs doc
  164. */
  165. void eeprom_write_byte(uint8_t *addr, uint8_t value) {
  166. uint32_t offset = (uint32_t)addr;
  167. if (offset >= EEPROM_SIZE) return;
  168. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  169. if (FlexRAM[offset] != value) {
  170. FlexRAM[offset] = value;
  171. flexram_wait();
  172. }
  173. }
  174. /** \brief eeprom write word
  175. *
  176. * FIXME: needs doc
  177. */
  178. void eeprom_write_word(uint16_t *addr, uint16_t value) {
  179. uint32_t offset = (uint32_t)addr;
  180. if (offset >= EEPROM_SIZE - 1) return;
  181. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  182. # ifdef HANDLE_UNALIGNED_WRITES
  183. if ((offset & 1) == 0) {
  184. # endif
  185. if (*(uint16_t *)(&FlexRAM[offset]) != value) {
  186. *(uint16_t *)(&FlexRAM[offset]) = value;
  187. flexram_wait();
  188. }
  189. # ifdef HANDLE_UNALIGNED_WRITES
  190. } else {
  191. if (FlexRAM[offset] != value) {
  192. FlexRAM[offset] = value;
  193. flexram_wait();
  194. }
  195. if (FlexRAM[offset + 1] != (value >> 8)) {
  196. FlexRAM[offset + 1] = value >> 8;
  197. flexram_wait();
  198. }
  199. }
  200. # endif
  201. }
  202. /** \brief eeprom write dword
  203. *
  204. * FIXME: needs doc
  205. */
  206. void eeprom_write_dword(uint32_t *addr, uint32_t value) {
  207. uint32_t offset = (uint32_t)addr;
  208. if (offset >= EEPROM_SIZE - 3) return;
  209. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  210. # ifdef HANDLE_UNALIGNED_WRITES
  211. switch (offset & 3) {
  212. case 0:
  213. # endif
  214. if (*(uint32_t *)(&FlexRAM[offset]) != value) {
  215. *(uint32_t *)(&FlexRAM[offset]) = value;
  216. flexram_wait();
  217. }
  218. return;
  219. # ifdef HANDLE_UNALIGNED_WRITES
  220. case 2:
  221. if (*(uint16_t *)(&FlexRAM[offset]) != value) {
  222. *(uint16_t *)(&FlexRAM[offset]) = value;
  223. flexram_wait();
  224. }
  225. if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) {
  226. *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16;
  227. flexram_wait();
  228. }
  229. return;
  230. default:
  231. if (FlexRAM[offset] != value) {
  232. FlexRAM[offset] = value;
  233. flexram_wait();
  234. }
  235. if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) {
  236. *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8;
  237. flexram_wait();
  238. }
  239. if (FlexRAM[offset + 3] != (value >> 24)) {
  240. FlexRAM[offset + 3] = value >> 24;
  241. flexram_wait();
  242. }
  243. }
  244. # endif
  245. }
  246. /** \brief eeprom write block
  247. *
  248. * FIXME: needs doc
  249. */
  250. void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
  251. uint32_t offset = (uint32_t)addr;
  252. const uint8_t *src = (const uint8_t *)buf;
  253. if (offset >= EEPROM_SIZE) return;
  254. if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
  255. if (len >= EEPROM_SIZE) len = EEPROM_SIZE;
  256. if (offset + len >= EEPROM_SIZE) len = EEPROM_SIZE - offset;
  257. while (len > 0) {
  258. uint32_t lsb = offset & 3;
  259. if (lsb == 0 && len >= 4) {
  260. // write aligned 32 bits
  261. uint32_t val32;
  262. val32 = *src++;
  263. val32 |= (*src++ << 8);
  264. val32 |= (*src++ << 16);
  265. val32 |= (*src++ << 24);
  266. if (*(uint32_t *)(&FlexRAM[offset]) != val32) {
  267. *(uint32_t *)(&FlexRAM[offset]) = val32;
  268. flexram_wait();
  269. }
  270. offset += 4;
  271. len -= 4;
  272. } else if ((lsb == 0 || lsb == 2) && len >= 2) {
  273. // write aligned 16 bits
  274. uint16_t val16;
  275. val16 = *src++;
  276. val16 |= (*src++ << 8);
  277. if (*(uint16_t *)(&FlexRAM[offset]) != val16) {
  278. *(uint16_t *)(&FlexRAM[offset]) = val16;
  279. flexram_wait();
  280. }
  281. offset += 2;
  282. len -= 2;
  283. } else {
  284. // write 8 bits
  285. uint8_t val8 = *src++;
  286. if (FlexRAM[offset] != val8) {
  287. FlexRAM[offset] = val8;
  288. flexram_wait();
  289. }
  290. offset++;
  291. len--;
  292. }
  293. }
  294. }
  295. /*
  296. void do_flash_cmd(volatile uint8_t *fstat)
  297. {
  298. *fstat = 0x80;
  299. while ((*fstat & 0x80) == 0) ; // wait
  300. }
  301. 00000000 <do_flash_cmd>:
  302. 0: f06f 037f mvn.w r3, #127 ; 0x7f
  303. 4: 7003 strb r3, [r0, #0]
  304. 6: 7803 ldrb r3, [r0, #0]
  305. 8: f013 0f80 tst.w r3, #128 ; 0x80
  306. c: d0fb beq.n 6 <do_flash_cmd+0x6>
  307. e: 4770 bx lr
  308. */
  309. #elif defined(KL2x) /* chip selection */
  310. /* Teensy LC (emulated) */
  311. # define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
  312. extern uint32_t __eeprom_workarea_start__;
  313. extern uint32_t __eeprom_workarea_end__;
  314. static uint32_t flashend = 0;
  315. void eeprom_initialize(void) {
  316. const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
  317. do {
  318. if (*p++ == 0xFFFF) {
  319. flashend = (uint32_t)(p - 2);
  320. return;
  321. }
  322. } while (p < (uint16_t *)SYMVAL(__eeprom_workarea_end__));
  323. flashend = (uint32_t)(p - 1);
  324. }
  325. uint8_t eeprom_read_byte(const uint8_t *addr) {
  326. uint32_t offset = (uint32_t)addr;
  327. const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
  328. const uint16_t *end = (const uint16_t *)((uint32_t)flashend);
  329. uint16_t val;
  330. uint8_t data = 0xFF;
  331. if (!end) {
  332. eeprom_initialize();
  333. end = (const uint16_t *)((uint32_t)flashend);
  334. }
  335. if (offset < EEPROM_SIZE) {
  336. while (p <= end) {
  337. val = *p++;
  338. if ((val & 255) == offset) data = val >> 8;
  339. }
  340. }
  341. return data;
  342. }
  343. static void flash_write(const uint16_t *code, uint32_t addr, uint32_t data) {
  344. // with great power comes great responsibility....
  345. uint32_t stat;
  346. *(uint32_t *)&(FTFA->FCCOB3) = 0x06000000 | (addr & 0x00FFFFFC);
  347. *(uint32_t *)&(FTFA->FCCOB7) = data;
  348. __disable_irq();
  349. (*((void (*)(volatile uint8_t *))((uint32_t)code | 1)))(&(FTFA->FSTAT));
  350. __enable_irq();
  351. stat = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR | FTFA_FSTAT_ACCERR | FTFA_FSTAT_FPVIOL);
  352. if (stat) {
  353. FTFA->FSTAT = stat;
  354. }
  355. MCM->PLACR |= MCM_PLACR_CFCC;
  356. }
  357. void eeprom_write_byte(uint8_t *addr, uint8_t data) {
  358. uint32_t offset = (uint32_t)addr;
  359. const uint16_t *p, *end = (const uint16_t *)((uint32_t)flashend);
  360. uint32_t i, val, flashaddr;
  361. uint16_t do_flash_cmd[] = {0x2380, 0x7003, 0x7803, 0xb25b, 0x2b00, 0xdafb, 0x4770};
  362. uint8_t buf[EEPROM_SIZE];
  363. if (offset >= EEPROM_SIZE) return;
  364. if (!end) {
  365. eeprom_initialize();
  366. end = (const uint16_t *)((uint32_t)flashend);
  367. }
  368. if (++end < (uint16_t *)SYMVAL(__eeprom_workarea_end__)) {
  369. val = (data << 8) | offset;
  370. flashaddr = (uint32_t)end;
  371. flashend = flashaddr;
  372. if ((flashaddr & 2) == 0) {
  373. val |= 0xFFFF0000;
  374. } else {
  375. val <<= 16;
  376. val |= 0x0000FFFF;
  377. }
  378. flash_write(do_flash_cmd, flashaddr, val);
  379. } else {
  380. for (i = 0; i < EEPROM_SIZE; i++) {
  381. buf[i] = 0xFF;
  382. }
  383. val = 0;
  384. for (p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); p < (uint16_t *)SYMVAL(__eeprom_workarea_end__); p++) {
  385. val = *p;
  386. if ((val & 255) < EEPROM_SIZE) {
  387. buf[val & 255] = val >> 8;
  388. }
  389. }
  390. buf[offset] = data;
  391. for (flashaddr = (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); flashaddr < (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_end__); flashaddr += 1024) {
  392. *(uint32_t *)&(FTFA->FCCOB3) = 0x09000000 | flashaddr;
  393. __disable_irq();
  394. (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFA->FSTAT));
  395. __enable_irq();
  396. val = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR | FTFA_FSTAT_ACCERR | FTFA_FSTAT_FPVIOL);
  397. ;
  398. if (val) FTFA->FSTAT = val;
  399. MCM->PLACR |= MCM_PLACR_CFCC;
  400. }
  401. flashaddr = (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__);
  402. for (i = 0; i < EEPROM_SIZE; i++) {
  403. if (buf[i] == 0xFF) continue;
  404. if ((flashaddr & 2) == 0) {
  405. val = (buf[i] << 8) | i;
  406. } else {
  407. val = val | (buf[i] << 24) | (i << 16);
  408. flash_write(do_flash_cmd, flashaddr, val);
  409. }
  410. flashaddr += 2;
  411. }
  412. flashend = flashaddr;
  413. if ((flashaddr & 2)) {
  414. val |= 0xFFFF0000;
  415. flash_write(do_flash_cmd, flashaddr, val);
  416. }
  417. }
  418. }
  419. /*
  420. void do_flash_cmd(volatile uint8_t *fstat)
  421. {
  422. *fstat = 0x80;
  423. while ((*fstat & 0x80) == 0) ; // wait
  424. }
  425. 00000000 <do_flash_cmd>:
  426. 0: 2380 movs r3, #128 ; 0x80
  427. 2: 7003 strb r3, [r0, #0]
  428. 4: 7803 ldrb r3, [r0, #0]
  429. 6: b25b sxtb r3, r3
  430. 8: 2b00 cmp r3, #0
  431. a: dafb bge.n 4 <do_flash_cmd+0x4>
  432. c: 4770 bx lr
  433. */
  434. uint16_t eeprom_read_word(const uint16_t *addr) {
  435. const uint8_t *p = (const uint8_t *)addr;
  436. return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8);
  437. }
  438. uint32_t eeprom_read_dword(const uint32_t *addr) {
  439. const uint8_t *p = (const uint8_t *)addr;
  440. return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
  441. }
  442. void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
  443. const uint8_t *p = (const uint8_t *)addr;
  444. uint8_t * dest = (uint8_t *)buf;
  445. while (len--) {
  446. *dest++ = eeprom_read_byte(p++);
  447. }
  448. }
  449. int eeprom_is_ready(void) {
  450. return 1;
  451. }
  452. void eeprom_write_word(uint16_t *addr, uint16_t value) {
  453. uint8_t *p = (uint8_t *)addr;
  454. eeprom_write_byte(p++, value);
  455. eeprom_write_byte(p, value >> 8);
  456. }
  457. void eeprom_write_dword(uint32_t *addr, uint32_t value) {
  458. uint8_t *p = (uint8_t *)addr;
  459. eeprom_write_byte(p++, value);
  460. eeprom_write_byte(p++, value >> 8);
  461. eeprom_write_byte(p++, value >> 16);
  462. eeprom_write_byte(p, value >> 24);
  463. }
  464. void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
  465. uint8_t * p = (uint8_t *)addr;
  466. const uint8_t *src = (const uint8_t *)buf;
  467. while (len--) {
  468. eeprom_write_byte(p++, *src++);
  469. }
  470. }
  471. #else
  472. # error Unsupported Teensy EEPROM.
  473. #endif /* chip selection */
  474. // The update functions just calls write for now, but could probably be optimized
  475. void eeprom_update_byte(uint8_t *addr, uint8_t value) {
  476. eeprom_write_byte(addr, value);
  477. }
  478. void eeprom_update_word(uint16_t *addr, uint16_t value) {
  479. uint8_t *p = (uint8_t *)addr;
  480. eeprom_write_byte(p++, value);
  481. eeprom_write_byte(p, value >> 8);
  482. }
  483. void eeprom_update_dword(uint32_t *addr, uint32_t value) {
  484. uint8_t *p = (uint8_t *)addr;
  485. eeprom_write_byte(p++, value);
  486. eeprom_write_byte(p++, value >> 8);
  487. eeprom_write_byte(p++, value >> 16);
  488. eeprom_write_byte(p, value >> 24);
  489. }
  490. void eeprom_update_block(const void *buf, void *addr, size_t len) {
  491. uint8_t * p = (uint8_t *)addr;
  492. const uint8_t *src = (const uint8_t *)buf;
  493. while (len--) {
  494. eeprom_write_byte(p++, *src++);
  495. }
  496. }