2021-06-26 15:24:07 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-12-06 07:27:08 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef GOWIN_HPP_
|
|
|
|
|
#define GOWIN_HPP_
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "device.hpp"
|
2021-09-15 20:18:49 +02:00
|
|
|
#include "configBitstreamParser.hpp"
|
2020-03-06 09:05:57 +01:00
|
|
|
#include "jtag.hpp"
|
2021-09-15 20:18:49 +02:00
|
|
|
#include "spiInterface.hpp"
|
2019-12-06 07:27:08 +01:00
|
|
|
|
2021-09-15 20:18:49 +02:00
|
|
|
class Gowin: public Device, SPIInterface {
|
2019-12-06 07:27:08 +01:00
|
|
|
public:
|
2022-07-20 23:25:53 +02:00
|
|
|
Gowin(Jtag *jtag, std::string filename, const std::string &file_type, std::string mcufw,
|
2021-09-15 20:18:49 +02:00
|
|
|
Device::prog_type_t prg_type, bool external_flash,
|
2021-06-25 08:58:45 +02:00
|
|
|
bool verify, int8_t verbose);
|
2019-12-06 07:27:08 +01:00
|
|
|
~Gowin();
|
|
|
|
|
int idCode() override;
|
2020-01-15 09:49:09 +01:00
|
|
|
void reset() override;
|
2021-12-22 19:11:35 +01:00
|
|
|
void program(unsigned int offset, bool unprotect_flash) override;
|
2020-01-04 17:37:16 +01:00
|
|
|
void programFlash();
|
2022-07-20 23:27:32 +02:00
|
|
|
bool connectJtagToMCU() override;
|
2019-12-06 07:27:08 +01:00
|
|
|
|
2021-09-15 20:18:49 +02:00
|
|
|
/* spi interface */
|
2021-12-22 19:11:35 +01:00
|
|
|
virtual bool protect_flash(uint32_t len) override {
|
|
|
|
|
(void) len;
|
|
|
|
|
printError("protect flash not supported"); return false;}
|
|
|
|
|
virtual bool unprotect_flash() override {
|
|
|
|
|
printError("unprotect flash not supported"); return false;}
|
2022-03-10 08:51:54 +01:00
|
|
|
virtual bool bulk_erase_flash() override {
|
|
|
|
|
printError("bulk erase flash not supported"); return false;}
|
2021-09-15 20:18:49 +02:00
|
|
|
int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx,
|
|
|
|
|
uint32_t len) override;
|
|
|
|
|
int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override;
|
|
|
|
|
int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
|
|
|
|
|
uint32_t timeout, bool verbose) override;
|
|
|
|
|
|
2019-12-06 07:27:08 +01:00
|
|
|
private:
|
|
|
|
|
bool wr_rd(uint8_t cmd, uint8_t *tx, int tx_len,
|
|
|
|
|
uint8_t *rx, int rx_len, bool verbose = false);
|
|
|
|
|
bool EnableCfg();
|
|
|
|
|
bool DisableCfg();
|
|
|
|
|
bool pollFlag(uint32_t mask, uint32_t value);
|
|
|
|
|
bool eraseSRAM();
|
2020-01-04 17:37:16 +01:00
|
|
|
bool eraseFLASH();
|
2019-12-06 07:27:08 +01:00
|
|
|
bool flashSRAM(uint8_t *data, int length);
|
2022-07-20 23:25:53 +02:00
|
|
|
bool flashFLASH(uint32_t page, uint8_t *data, int length);
|
2019-12-06 07:27:08 +01:00
|
|
|
void displayReadReg(uint32_t dev);
|
|
|
|
|
uint32_t readStatusReg();
|
|
|
|
|
uint32_t readUserCode();
|
2023-02-16 20:02:36 +01:00
|
|
|
/*!
|
|
|
|
|
* \brief compare usercode register with fs checksum and/or
|
|
|
|
|
* .fs usercode field
|
|
|
|
|
*/
|
|
|
|
|
void checkCRC();
|
2021-09-15 20:18:49 +02:00
|
|
|
ConfigBitstreamParser *_fs;
|
2020-05-23 14:51:48 +02:00
|
|
|
bool is_gw1n1;
|
2022-09-06 21:24:40 +02:00
|
|
|
bool is_gw2a;
|
2023-02-16 20:02:36 +01:00
|
|
|
bool skip_checksum; /**< bypass checksum verification (GW2A) */
|
2021-09-15 20:18:49 +02:00
|
|
|
bool _external_flash; /**< select between int or ext flash */
|
|
|
|
|
uint8_t _spi_sck; /**< clk signal offset in bscan SPI */
|
|
|
|
|
uint8_t _spi_cs; /**< cs signal offset in bscan SPI */
|
|
|
|
|
uint8_t _spi_di; /**< di signal (mosi) offset in bscan SPI */
|
|
|
|
|
uint8_t _spi_do; /**< do signal (miso) offset in bscan SPI */
|
|
|
|
|
uint8_t _spi_msk; /** default spi msk with only do out */
|
2022-07-24 17:31:36 +02:00
|
|
|
ConfigBitstreamParser *_mcufw;
|
2019-12-06 07:27:08 +01:00
|
|
|
};
|
|
|
|
|
#endif // GOWIN_HPP_
|