From f77faa2657ee77dd24f1a15efeba5c43354e7284 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 6 Oct 2020 08:38:24 +0200 Subject: [PATCH] add direct access to spi flash --- README.md | 1 + src/main.cpp | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 62e4b26..e34b0ff 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ openFPGALoader -- a program to flash FPGA -o, --offset arg start offset in EEPROM --pins arg pin config (only for ft232R) TDI:TDO:TCK:TMS -r, --reset reset FPGA after operations + --spi SPI mode (only for FTDI in serial mode) -v, --verbose Produce verbose output -h, --help Give this help list -V, --Version Print program version diff --git a/src/main.cpp b/src/main.cpp index 63b80ca..8b09640 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,10 +30,12 @@ #include "cable.hpp" #include "device.hpp" #include "display.hpp" +#include "ftdispi.hpp" #include "gowin.hpp" #include "lattice.hpp" #include "jtag.hpp" #include "part.hpp" +#include "spiFlash.hpp" #include "xilinx.hpp" using namespace std; @@ -55,6 +57,7 @@ struct arguments { bool write_flash; bool write_sram; bool is_list_command; + bool spi; }; int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *pins_config); @@ -68,7 +71,7 @@ int main(int argc, char **argv) /* command line args. */ struct arguments args = {false, false, false, 0, "", "", "-", "", -1, 6000000, "-", - false, false, false, false, false, true, false}; + false, false, false, false, false, true, false, false}; /* parse arguments */ try { if (parse_opt(argc, argv, &args, &pins_config)) @@ -83,6 +86,22 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } + /* FLASH direct access */ + if (args.spi) { + FTDIpp_MPSSE::mpsse_bit_config spi_cable = cable_list["ft2232"].config; + int mapping[] = {INTERFACE_A, INTERFACE_B, INTERFACE_C, INTERFACE_D}; + spi_cable.interface = mapping[args.ftdi_channel]; + cout << spi_cable.interface << endl; + FtdiSpi *spi = new FtdiSpi(spi_cable, 6000000, args.verbose); + SPIFlash flash((SPIInterface *)spi, args.verbose); + flash.power_up(); + flash.reset(); + flash.read_id(); + + delete spi; + return EXIT_SUCCESS; + } + /* if a board name is specified try to use this to determine cable */ if (args.board[0] != '-' && board_list.find(args.board) != board_list.end()) { /* set pins config (only when user has not already provided @@ -291,6 +310,8 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p cxxopts::value>(pins)) ("r,reset", "reset FPGA after operations", cxxopts::value(args->reset)) + ("spi", "SPI mode (only for FTDI in serial mode)", + cxxopts::value(args->spi)) ("v,verbose", "Produce verbose output", cxxopts::value(args->verbose)) ("h,help", "Give this help list") ("V,Version", "Print program version");