Rewrite GOWIN algorithms

This commit is contained in:
Alexey Starikovskiy 2023-09-01 20:24:33 +03:00 committed by Gwenhael Goavec-Merou
parent cceac16fc5
commit 1789feb2cf
2 changed files with 415 additions and 433 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,38 +3,37 @@
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com> * Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/ */
#ifndef GOWIN_HPP_ #ifndef SRC_GOWIN_HPP_
#define GOWIN_HPP_ #define SRC_GOWIN_HPP_
#include <stdint.h> #include <stdint.h>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "device.hpp"
#include "configBitstreamParser.hpp" #include "configBitstreamParser.hpp"
#include "device.hpp"
#include "jtag.hpp" #include "jtag.hpp"
#include "spiInterface.hpp" #include "spiInterface.hpp"
class Gowin: public Device, SPIInterface { class Gowin: public Device, SPIInterface {
public: public:
Gowin(Jtag *jtag, std::string filename, const std::string &file_type, std::string mcufw, Gowin(Jtag *jtag, std::string filename, const std::string &file_type,
Device::prog_type_t prg_type, bool external_flash, std::string mcufw, Device::prog_type_t prg_type,
bool verify, int8_t verbose); bool external_flash, bool verify, int8_t verbose);
~Gowin(); ~Gowin();
uint32_t idCode() override; uint32_t idCode() override;
void reset() override; void reset() override;
void program(unsigned int offset, bool unprotect_flash) override; void program(unsigned int offset, bool unprotect_flash) override;
void programFlash();
bool connectJtagToMCU() override; bool connectJtagToMCU() override;
/* spi interface */ /* spi interface */
virtual bool protect_flash(uint32_t len) override { bool protect_flash(uint32_t len) override {
(void) len; (void) len;
printError("protect flash not supported"); return false;} printError("protect flash not supported"); return false;}
virtual bool unprotect_flash() override { bool unprotect_flash() override {
printError("unprotect flash not supported"); return false;} printError("unprotect flash not supported"); return false;}
virtual bool bulk_erase_flash() override { bool bulk_erase_flash() override {
printError("bulk erase flash not supported"); return false;} printError("bulk erase flash not supported"); return false;}
int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx,
uint32_t len) override; uint32_t len) override;
@ -43,16 +42,21 @@ class Gowin: public Device, SPIInterface {
uint32_t timeout, bool verbose) override; uint32_t timeout, bool verbose) override;
private: private:
bool wr_rd(uint8_t cmd, uint8_t *tx, int tx_len, bool send_command(uint8_t cmd);
uint8_t *rx, int rx_len, bool verbose = false); void spi_gowin_write(const uint8_t *wr, uint8_t *rd, unsigned len);
bool EnableCfg(); uint32_t readReg32(uint8_t cmd);
bool DisableCfg(); void sendClkUs(unsigned us);
bool enableCfg();
bool disableCfg();
bool pollFlag(uint32_t mask, uint32_t value); bool pollFlag(uint32_t mask, uint32_t value);
bool eraseSRAM(); bool eraseSRAM();
bool eraseFLASH(); bool eraseFLASH();
bool flashSRAM(const uint8_t *data, int length); void programFlash();
bool flashFLASH(uint32_t page, const uint8_t *data, int length); void programExtFlash(unsigned int offset, bool unprotect_flash);
void displayReadReg(uint32_t dev); void programSRAM();
bool writeSRAM(const uint8_t *data, int length);
bool writeFLASH(uint32_t page, const uint8_t *data, int length);
void displayReadReg(const char *, uint32_t dev);
uint32_t readStatusReg(); uint32_t readStatusReg();
uint32_t readUserCode(); uint32_t readUserCode();
/*! /*!
@ -63,6 +67,7 @@ class Gowin: public Device, SPIInterface {
ConfigBitstreamParser *_fs; ConfigBitstreamParser *_fs;
bool is_gw1n1; bool is_gw1n1;
bool is_gw2a; bool is_gw2a;
bool is_gw1n4;
bool is_gw5a; bool is_gw5a;
bool skip_checksum; /**< bypass checksum verification (GW2A) */ bool skip_checksum; /**< bypass checksum verification (GW2A) */
bool _external_flash; /**< select between int or ext flash */ bool _external_flash; /**< select between int or ext flash */
@ -73,4 +78,4 @@ class Gowin: public Device, SPIInterface {
uint8_t _spi_msk; /** default spi msk with only do out */ uint8_t _spi_msk; /** default spi msk with only do out */
ConfigBitstreamParser *_mcufw; ConfigBitstreamParser *_mcufw;
}; };
#endif // GOWIN_HPP_ #endif // SRC_GOWIN_HPP_