diff options
author | Miodrag Milanović <mmicko@gmail.com> | 2022-05-30 10:09:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-30 10:09:53 +0200 |
commit | 29556af238e4efea040eded319ebe9c781510733 (patch) | |
tree | 27be66a2e7713990c2e5b811152256c80b0abaa1 /iceprog/iceprog.c | |
parent | eaea10ba4c318ba393d78dcfce92f88ce0286ff4 (diff) | |
parent | 98d8bee04f2d51fa0e9d5804f0525e89618bce96 (diff) | |
download | icestorm-29556af238e4efea040eded319ebe9c781510733.tar.gz icestorm-29556af238e4efea040eded319ebe9c781510733.tar.bz2 icestorm-29556af238e4efea040eded319ebe9c781510733.zip |
Merge pull request #283 from smunaut/misc
Misc improvements to iceprog
Diffstat (limited to 'iceprog/iceprog.c')
-rw-r--r-- | iceprog/iceprog.c | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c index f80a432..8ee6443 100644 --- a/iceprog/iceprog.c +++ b/iceprog/iceprog.c @@ -96,16 +96,16 @@ enum flash_cmd { static void set_cs_creset(int cs_b, int creset_b) { uint8_t gpio = 0; - uint8_t direction = 0x93; + uint8_t direction = 0x03; - if (cs_b) { + if (!cs_b) { // ADBUS4 (GPIOL0) - gpio |= 0x10; + direction |= 0x10; } - if (creset_b) { + if (!creset_b) { // ADBUS7 (GPIOL3) - gpio |= 0x80; + direction |= 0x80; } mpsse_set_gpio(gpio, direction); @@ -202,9 +202,15 @@ static void flash_reset() { uint8_t data[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + // This disables CRM is if it was enabled flash_chip_select(); mpsse_xfer_spi(data, 8); flash_chip_deselect(); + + // This disables QPI if it was enable + flash_chip_select(); + mpsse_xfer_spi_bits(0xFF, 2); + flash_chip_deselect(); } static void flash_power_up() @@ -446,6 +452,34 @@ static void flash_disable_protection() } +static void flash_enable_quad() +{ + fprintf(stderr, "Enabling Quad operation...\n"); + + // Allow write + flash_write_enable(); + + // Write Status Register 2 <- 0x02 + uint8_t data[2] = { FC_WSR2, 0x02 }; + flash_chip_select(); + mpsse_xfer_spi(data, 2); + flash_chip_deselect(); + + flash_wait(); + + // Read Status Register 1 + data[0] = FC_RSR2; + + flash_chip_select(); + mpsse_xfer_spi(data, 2); + flash_chip_deselect(); + + if ((data[1] & 0x02) != 0x02) + fprintf(stderr, "failed to set QE=1, SR2 now equal to 0x%02x (expected 0x%02x)\n", data[1], data[1] | 0x02); + + fprintf(stderr, "SR2: %08x\n", data[1]); +} + // --------------------------------------------------------- // iceprog implementation // --------------------------------------------------------- @@ -484,6 +518,7 @@ static void help(const char *progname) fprintf(stderr, " -c do not write flash, only verify (`check')\n"); fprintf(stderr, " -S perform SRAM programming\n"); fprintf(stderr, " -t just read the flash ID sequence\n"); + fprintf(stderr, " -Q just set the flash QE=1 bit\n"); fprintf(stderr, "\n"); fprintf(stderr, "Erase mode (only meaningful in default mode):\n"); fprintf(stderr, " [default] erase aligned chunks of 64kB in write mode\n"); @@ -543,7 +578,7 @@ int main(int argc, char **argv) bool bulk_erase = false; bool dont_erase = false; bool prog_sram = false; - bool test_mode = false; + int test_mode = 0; bool slow_clock = false; bool disable_protect = false; bool disable_verify = false; @@ -565,7 +600,7 @@ int main(int argc, char **argv) /* Decode command line parameters */ int opt; char *endptr; - while ((opt = getopt_long(argc, argv, "d:i:I:rR:e:o:cbnStvspXk", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "d:i:I:rR:e:o:cbnStQvspXk", long_options, NULL)) != -1) { switch (opt) { case 'd': /* device string */ devstr = optarg; @@ -653,7 +688,10 @@ int main(int argc, char **argv) prog_sram = true; break; case 't': /* just read flash id */ - test_mode = true; + test_mode = 1; + break; + case 'Q': /* just read flash id */ + test_mode = 2; break; case 'v': /* provide verbose output */ verbose = true; @@ -682,7 +720,7 @@ int main(int argc, char **argv) /* Make sure that the combination of provided parameters makes sense */ - if (read_mode + erase_mode + check_mode + prog_sram + test_mode > 1) { + if (read_mode + erase_mode + check_mode + prog_sram + !!test_mode > 1) { fprintf(stderr, "%s: options `-r'/`-R', `-e`, `-c', `-S', and `-t' are mutually exclusive\n", my_name); return EXIT_FAILURE; } @@ -840,7 +878,10 @@ int main(int argc, char **argv) flash_reset(); flash_power_up(); - flash_read_id(); + if (test_mode == 1) + flash_read_id(); + else + flash_enable_quad(); flash_power_down(); |