Skip to content

Commit dd3204a

Browse files
committed
main, board: added --pins argument compatible with SPI mode
1 parent 319c08e commit dd3204a

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ openFPGALoader -c cmsisdap fpga_bitstream.bit
4949
## Usage
5050

5151
```
52-
Usage: openFPGALoader [OPTION...] BIT_FILE
52+
Usage: ./openFPGALoader [OPTION...] BIT_FILE
5353
openFPGALoader -- a program to flash FPGA
5454
5555
--altsetting arg DFU interface altsetting (only for DFU mode)
@@ -89,7 +89,8 @@ openFPGALoader -- a program to flash FPGA
8989
with dump-flash
9090
--file-type arg provides file type instead of let's deduced
9191
by using extension
92-
--flash-sector arg flash sector (Lattice and Altera MAX10 parts only)
92+
--flash-sector arg flash sector (Lattice and Altera MAX10 parts
93+
only)
9394
--fpga-part arg fpga model flavor + package
9495
--freq arg jtag frequency (Hz)
9596
-f, --write-flash write bitstream in flash (default: false)
@@ -102,7 +103,8 @@ openFPGALoader -- a program to flash FPGA
102103
-m, --write-sram write bitstream in SRAM (default: true)
103104
-o, --offset arg Start address (in bytes) for read/write into
104105
non volatile memory (default: 0)
105-
--pins arg pin config TDI:TDO:TCK:TMS
106+
--pins arg pin config TDI:TDO:TCK:TMS or
107+
MOSI:MISO:SCK:CS[:HOLDN:WPN]
106108
--probe-firmware arg firmware for JTAG probe (usbBlasterII)
107109
--protect-flash arg protect SPI flash area
108110
--quiet Produce quiet output (no progress bar)
@@ -127,6 +129,7 @@ openFPGALoader -- a program to flash FPGA
127129
-D, --read-dna Read DNA (Xilinx FPGA only)
128130
-X, --read-xadc Read XADC (Xilinx FPGA only)
129131
--read-register arg Read Status Register(Xilinx FPGA only)
132+
--user-flash arg User flash file (Gowin LittleBee FPGA only)
130133
-V, --Version Print program version
131134
132135
Mandatory or optional arguments to long options are also mandatory or optional

src/board.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ typedef struct {
5050
uint8_t tck_pin; /*! TCK pin value */
5151
uint8_t tdi_pin; /*! TDI pin value */
5252
uint8_t tdo_pin; /*! TDO pin value */
53+
uint8_t ext0_pin; /* Compat with spi_pins_conf_t */
54+
uint8_t ext1_pin; /* Compat with spi_pins_conf_t */
5355
} jtag_pins_conf_t;
5456

5557
typedef struct {
@@ -93,7 +95,7 @@ typedef struct {
9395
#define JTAG_BOARD(_name, _fpga_part, _cable, _rst, _done, _freq) \
9496
{_name, {"", _cable, _fpga_part, _rst, _done, 0, COMM_JTAG, {}, {}, _freq, 0, 0, -1}}
9597
#define JTAG_BITBANG_BOARD(_name, _fpga_part, _cable, _rst, _done, _tms, _tck, _tdi, _tdo, _freq) \
96-
{_name, {"", _cable, _fpga_part, _rst, _done, 0, COMM_JTAG, { _tms, _tck, _tdi, _tdo }, {}, \
98+
{_name, {"", _cable, _fpga_part, _rst, _done, 0, COMM_JTAG, { _tms, _tck, _tdi, _tdo, 0, 0 }, {}, \
9799
_freq, 0, 0, -1}}
98100
#define SPI_BOARD(_name, _manufacturer, _fpga_part, _cable, _rst, _done, _oe, _cs, _sck, _si, _so, _holdn, _wpn, _freq) \
99101
{_name, {_manufacturer, _cable, _fpga_part, _rst, _done, _oe, COMM_SPI, {}, \

src/main.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int main(int argc, char **argv)
114114
{
115115
cable_t cable;
116116
target_board_t *board = NULL;
117-
jtag_pins_conf_t pins_config = {0, 0, 0, 0};
117+
jtag_pins_conf_t pins_config = {0, 0, 0, 0, 0, 0};
118118

119119
/* command line args. */
120120
struct arguments args = {0,
@@ -265,12 +265,22 @@ int main(int argc, char **argv)
265265
args.prg_type = Device::WR_FLASH;
266266

267267
FtdiSpi *spi = NULL;
268-
spi_pins_conf_t pins_config;
269-
if (board)
270-
pins_config = board->spi_pins_config;
268+
spi_pins_conf_t spi_pins_config;
269+
if (board && !args.pin_config)
270+
spi_pins_config = board->spi_pins_config;
271+
if (args.pin_config) {
272+
printInfo("Board default pins configuration overridden");
273+
spi_pins_config.cs_pin = (1 << pins_config.tms_pin);
274+
spi_pins_config.sck_pin = (1 << pins_config.tck_pin);
275+
spi_pins_config.mosi_pin = (1 << pins_config.tdi_pin);
276+
spi_pins_config.miso_pin = (1 << pins_config.tdo_pin);
277+
spi_pins_config.miso_pin = (1 << pins_config.tdo_pin);
278+
spi_pins_config.holdn_pin = (1 << pins_config.ext0_pin);
279+
spi_pins_config.wpn_pin = (1 << pins_config.ext1_pin);
280+
}
271281

272282
try {
273-
spi = new FtdiSpi(cable, pins_config, args.freq, args.verbose);
283+
spi = new FtdiSpi(cable, spi_pins_config, args.freq, args.verbose);
274284
} catch (std::exception &e) {
275285
printError("Error: Failed to claim cable");
276286
return EXIT_FAILURE;
@@ -844,7 +854,7 @@ int parse_opt(int argc, char **argv, struct arguments *args,
844854
"write bitstream in SRAM (default: true)")
845855
("o,offset", "Start address (in bytes) for read/write into non volatile memory (default: 0)",
846856
cxxopts::value<unsigned int>(args->offset))
847-
("pins", "pin config TDI:TDO:TCK:TMS",
857+
("pins", "pin config TDI:TDO:TCK:TMS or MOSI:MISO:SCK:CS[:HOLDN:WPN]",
848858
cxxopts::value<vector<string>>(pins))
849859
("probe-firmware", "firmware for JTAG probe (usbBlasterII)",
850860
cxxopts::value<string>(args->probe_firmware))
@@ -1006,8 +1016,8 @@ int parse_opt(int argc, char **argv, struct arguments *args,
10061016
}
10071017

10081018
if (result.count("pins")) {
1009-
if (pins.size() != 4) {
1010-
printError("Error: pin_config need 4 pins");
1019+
if (pins.size() < 4 || pins.size() > 6) {
1020+
printError("Error: pin_config need 4 pins in JTAG mode or 6 pins in SPI Mode");
10111021
throw std::exception();
10121022
}
10131023

@@ -1021,7 +1031,7 @@ int parse_opt(int argc, char **argv, struct arguments *args,
10211031
{"DCD", FT232RL_DCD},
10221032
{"RI" , FT232RL_RI}};
10231033

1024-
for (int i = 0; i < 4; i++) {
1034+
for (size_t i = 0; i < pins.size(); i++) {
10251035
int pin_num;
10261036
try {
10271037
pin_num = std::stoi(pins[i], nullptr, 0);
@@ -1046,6 +1056,12 @@ int parse_opt(int argc, char **argv, struct arguments *args,
10461056
case 3:
10471057
pins_config->tms_pin = pin_num;
10481058
break;
1059+
case 4:
1060+
pins_config->ext0_pin = pin_num;
1061+
break;
1062+
case 5:
1063+
pins_config->ext1_pin = pin_num;
1064+
break;
10491065
}
10501066
}
10511067
args->pin_config = true;

0 commit comments

Comments
 (0)