Bladeren bron

Unlock the device before write to Flash

Flash erase/write needs to be performed after device unlock. Also fixed the last sector number to be (Flash  size)/4kB - 1.
Mateusz Bugdalski 13 jaren geleden
bovenliggende
commit
df361d3f25
1 gewijzigde bestanden met toevoegingen van 4 en 2 verwijderingen
  1. 4 2
      lpc.c

+ 4 - 2
lpc.c

@@ -101,7 +101,9 @@ void lpc_write(struct lpc_device *dev, const struct sprog_data *d) {
   
   chunk.data = NULL;
   
-  i = dev->part->flash/4; /* number of sectors = Flash size / 4kB */
+  lpc_command(dev, "U 23130\r\n"); /* unlock the device */
+  
+  i = dev->part->flash/4 - 1; /* last sector = Flash size / 4kB - 1 */
   lpc_command(dev, "P 0 %d\r\n", i);
   
   sprog_info("Erasing Flash memory... ");
@@ -110,7 +112,7 @@ void lpc_write(struct lpc_device *dev, const struct sprog_data *d) {
   else
     sprog_info("OK\n");
   
-  i = d->size/4096;
+  i = d->size/4096 - 1;
   lpc_command(dev, "P 0 %d\r\n", i); /* prepare sectors for write */
   
   while(d->size-offset>0) {