mirror of
https://github.com/trabucayre/openFPGALoader.git
synced 2026-08-30 18:02:38 +02:00
add support for ice40 FPGA and iCEBreaker, icestick, iCE40-HX8K, iCE40-HX1K-EVN boards
This commit is contained in:
@@ -93,6 +93,11 @@ static std::map <std::string, target_cable_t> board_list = {
|
||||
JTAG_BOARD("ecp5_evn", "ft2232", 0, 0),
|
||||
SPI_BOARD("fireant", "efinix", "ft232",
|
||||
DBUS4, DBUS5, DBUS3, DBUS0, DBUS1, DBUS2, DBUS6, 0),
|
||||
/* most ice40 boards uses the same pinout */
|
||||
SPI_BOARD("ice40_generic", "lattice", "ft2232",
|
||||
DBUS7, DBUS6,
|
||||
DBUS4, DBUS0, DBUS1, DBUS2,
|
||||
0, 0),
|
||||
JTAG_BOARD("machXO2EVN", "ft2232", 0, 0),
|
||||
JTAG_BOARD("machXO3SK", "ft2232", 0, 0),
|
||||
JTAG_BOARD("machXO3EVN", "ft2232", 0, 0),
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Gwenhael Goavec-Merou <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ice40.hpp"
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "display.hpp"
|
||||
#include "ftdispi.hpp"
|
||||
#include "device.hpp"
|
||||
#include "rawParser.hpp"
|
||||
#include "spiFlash.hpp"
|
||||
|
||||
Ice40::Ice40(FtdiSpi* spi, const std::string &filename,
|
||||
uint16_t rst_pin, uint16_t done_pin,
|
||||
bool verbose):
|
||||
Device(NULL, filename, verbose), _rst_pin(rst_pin),
|
||||
_done_pin(done_pin)
|
||||
{
|
||||
_spi = spi;
|
||||
_spi->gpio_set_input(_done_pin);
|
||||
_spi->gpio_set_output(_rst_pin);
|
||||
}
|
||||
|
||||
Ice40::~Ice40()
|
||||
{}
|
||||
|
||||
void Ice40::reset()
|
||||
{
|
||||
uint32_t timeout = 1000;
|
||||
_spi->gpio_clear(_rst_pin);
|
||||
usleep(1000);
|
||||
_spi->gpio_set(_rst_pin);
|
||||
printInfo("Reset ", false);
|
||||
do {
|
||||
timeout--;
|
||||
usleep(12000);
|
||||
} while (((_spi->gpio_get(true) & _done_pin) == 0) || timeout > 0);
|
||||
if (timeout == 0)
|
||||
printError("FAIL");
|
||||
else
|
||||
printSuccess("DONE");
|
||||
}
|
||||
|
||||
void Ice40::program(unsigned int offset)
|
||||
{
|
||||
uint32_t timeout = 1000;
|
||||
|
||||
if (_filename == "")
|
||||
return;
|
||||
|
||||
RawParser bit(_filename, false);
|
||||
|
||||
printInfo("Parse file ", false);
|
||||
if (bit.parse() == EXIT_SUCCESS) {
|
||||
printSuccess("DONE");
|
||||
} else {
|
||||
printError("FAIL");
|
||||
return;
|
||||
}
|
||||
|
||||
_spi->gpio_clear(_rst_pin);
|
||||
|
||||
SPIFlash flash(reinterpret_cast<SPIInterface *>(_spi), _verbose);
|
||||
flash.reset();
|
||||
flash.power_up();
|
||||
|
||||
printf("%02x\n", flash.read_status_reg());
|
||||
flash.read_id();
|
||||
flash.erase_and_prog(offset, bit.getData(), bit.getLength() / 8);
|
||||
|
||||
_spi->gpio_set(_rst_pin);
|
||||
usleep(12000);
|
||||
|
||||
printInfo("Wait for CDONE ", false);
|
||||
do {
|
||||
timeout--;
|
||||
usleep(12000);
|
||||
} while (((_spi->gpio_get(true) & _done_pin) == 0) && timeout > 0);
|
||||
if (timeout == 0)
|
||||
printError("FAIL");
|
||||
else
|
||||
printSuccess("DONE");
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Gwenhael Goavec-Merou <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SRC_ICE40_HPP_
|
||||
#define SRC_ICE40_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "device.hpp"
|
||||
#include "ftdispi.hpp"
|
||||
|
||||
class Ice40: public Device {
|
||||
public:
|
||||
Ice40(FtdiSpi *spi, const std::string &filename,
|
||||
uint16_t rst_pin, uint16_t done_pin,
|
||||
bool verbose);
|
||||
~Ice40();
|
||||
|
||||
void program(unsigned int offset = 0) override;
|
||||
/* not supported in SPI Active mode */
|
||||
int idCode() override {return 0;}
|
||||
void reset() override;
|
||||
|
||||
private:
|
||||
FtdiSpi *_spi;
|
||||
uint16_t _rst_pin;
|
||||
uint16_t _done_pin;
|
||||
};
|
||||
|
||||
#endif // SRC_ICE40_HPP_
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "efinix.hpp"
|
||||
#include "ftdispi.hpp"
|
||||
#include "gowin.hpp"
|
||||
#include "ice40.hpp"
|
||||
#include "lattice.hpp"
|
||||
#include "jtag.hpp"
|
||||
#include "part.hpp"
|
||||
@@ -163,6 +164,10 @@ int main(int argc, char **argv)
|
||||
Efinix target(spi, args.bit_file, board->reset_pin, board->done_pin,
|
||||
args.verbose);
|
||||
target.program(args.offset);
|
||||
} else if (board->manufacturer == "lattice") {
|
||||
Ice40 target(spi, args.bit_file, board->reset_pin, board->done_pin,
|
||||
args.verbose);
|
||||
target.program(args.offset);
|
||||
} else {
|
||||
RawParser *bit = NULL;
|
||||
if (board->reset_pin) {
|
||||
|
||||
Reference in New Issue
Block a user