OpenOCD
fespi.c File Reference
Include dependency graph for fespi.c:

Go to the source code of this file.

Data Structures

struct  fespi_flash_bank
 
struct  fespi_target
 

Macros

#define FESPI_CMD_TIMEOUT   (100)
 
#define FESPI_CSMODE_AUTO   0
 
#define FESPI_CSMODE_HOLD   2
 
#define FESPI_CSMODE_OFF   3
 
#define FESPI_DIR_RX   0
 
#define FESPI_DIR_TX   1
 
#define FESPI_ENDIAN_LSB   1
 
#define FESPI_ENDIAN_MSB   0
 
#define FESPI_FCTRL_EN   0x1
 
#define FESPI_FMT_DIR(x)   (((x) & 0x1) << 3)
 
#define FESPI_FMT_ENDIAN(x)   (((x) & 0x1) << 2)
 
#define FESPI_FMT_LEN(x)   (((x) & 0xf) << 16)
 
#define FESPI_FMT_PROTO(x)   ((x) & 0x3)
 
#define FESPI_INSN_ADDR_LEN(x)   (((x) & 0x7) << 1)
 
#define FESPI_INSN_ADDR_PROTO(x)   (((x) & 0x3) << 10)
 
#define FESPI_INSN_CMD_CODE(x)   (((x) & 0xff) << 16)
 
#define FESPI_INSN_CMD_EN   0x1
 
#define FESPI_INSN_CMD_PROTO(x)   (((x) & 0x3) << 8)
 
#define FESPI_INSN_DATA_PROTO(x)   (((x) & 0x3) << 12)
 
#define FESPI_INSN_PAD_CNT(x)   (((x) & 0xf) << 4)
 
#define FESPI_INSN_PAD_CODE(x)   (((x) & 0xff) << 24)
 
#define FESPI_IP_RXWM   0x2
 
#define FESPI_IP_TXWM   0x1
 
#define FESPI_MAX_TIMEOUT   (3000)
 
#define FESPI_PROBE_TIMEOUT   (100)
 
#define FESPI_PROTO_D   1
 
#define FESPI_PROTO_Q   2
 
#define FESPI_PROTO_S   0
 
#define FESPI_REG_CSDEF   0x14
 
#define FESPI_REG_CSID   0x10
 
#define FESPI_REG_CSMODE   0x18
 
#define FESPI_REG_DCSSCK   0x28
 
#define FESPI_REG_DINTERCS   0x2c
 
#define FESPI_REG_DINTERXFR   0x2e
 
#define FESPI_REG_DSCKCS   0x2a
 
#define FESPI_REG_FCTRL   0x60
 
#define FESPI_REG_FFMT   0x64
 
#define FESPI_REG_FMT   0x40
 
#define FESPI_REG_IE   0x70
 
#define FESPI_REG_IP   0x74
 
#define FESPI_REG_RXCTRL   0x54
 
#define FESPI_REG_RXFIFO   0x4c
 
#define FESPI_REG_SCKDIV   0x00
 
#define FESPI_REG_SCKMODE   0x04
 
#define FESPI_REG_TXCTRL   0x50
 
#define FESPI_REG_TXFIFO   0x48
 
#define FESPI_RXWM(x)   ((x) & 0xffff)
 
#define FESPI_SCK_PHA   0x2
 
#define FESPI_SCK_POL   0x1
 
#define FESPI_TXWM(x)   ((x) & 0xffff)
 

Functions

static int fespi_auto_probe (struct flash_bank *bank)
 
static int fespi_disable_hw_mode (struct flash_bank *bank)
 
static int fespi_enable_hw_mode (struct flash_bank *bank)
 
static int fespi_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int fespi_erase_sector (struct flash_bank *bank, int sector)
 
static int fespi_probe (struct flash_bank *bank)
 
static int fespi_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int fespi_protect_check (struct flash_bank *bank)
 
static int fespi_read_flash_id (struct flash_bank *bank, uint32_t *id)
 
static int fespi_read_reg (struct flash_bank *bank, uint32_t *value, target_addr_t address)
 
static int fespi_rx (struct flash_bank *bank, uint8_t *out)
 
static int fespi_set_dir (struct flash_bank *bank, bool dir)
 
static int fespi_tx (struct flash_bank *bank, uint8_t in)
 
static int fespi_txwm_wait (struct flash_bank *bank)
 
static int fespi_wip (struct flash_bank *bank, int timeout)
 
static int fespi_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int fespi_write_reg (struct flash_bank *bank, target_addr_t address, uint32_t value)
 
 FLASH_BANK_COMMAND_HANDLER (fespi_flash_bank_command)
 
static int get_fespi_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int slow_fespi_write_buffer (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t len)
 

Variables

const struct flash_driver fespi_flash
 
static const uint8_t riscv32_bin []
 
static const uint8_t riscv64_bin []
 
static const struct fespi_target target_devices []
 

Macro Definition Documentation

◆ FESPI_CMD_TIMEOUT

#define FESPI_CMD_TIMEOUT   (100)

Definition at line 108 of file fespi.c.

◆ FESPI_CSMODE_AUTO

#define FESPI_CSMODE_AUTO   0

Definition at line 92 of file fespi.c.

◆ FESPI_CSMODE_HOLD

#define FESPI_CSMODE_HOLD   2

Definition at line 93 of file fespi.c.

◆ FESPI_CSMODE_OFF

#define FESPI_CSMODE_OFF   3

Definition at line 94 of file fespi.c.

◆ FESPI_DIR_RX

#define FESPI_DIR_RX   0

Definition at line 96 of file fespi.c.

◆ FESPI_DIR_TX

#define FESPI_DIR_TX   1

Definition at line 97 of file fespi.c.

◆ FESPI_ENDIAN_LSB

#define FESPI_ENDIAN_LSB   1

Definition at line 104 of file fespi.c.

◆ FESPI_ENDIAN_MSB

#define FESPI_ENDIAN_MSB   0

Definition at line 103 of file fespi.c.

◆ FESPI_FCTRL_EN

#define FESPI_FCTRL_EN   0x1

Definition at line 79 of file fespi.c.

◆ FESPI_FMT_DIR

#define FESPI_FMT_DIR (   x)    (((x) & 0x1) << 3)

Definition at line 68 of file fespi.c.

◆ FESPI_FMT_ENDIAN

#define FESPI_FMT_ENDIAN (   x)    (((x) & 0x1) << 2)

Definition at line 67 of file fespi.c.

◆ FESPI_FMT_LEN

#define FESPI_FMT_LEN (   x)    (((x) & 0xf) << 16)

Definition at line 69 of file fespi.c.

◆ FESPI_FMT_PROTO

#define FESPI_FMT_PROTO (   x)    ((x) & 0x3)

Definition at line 66 of file fespi.c.

◆ FESPI_INSN_ADDR_LEN

#define FESPI_INSN_ADDR_LEN (   x)    (((x) & 0x7) << 1)

Definition at line 82 of file fespi.c.

◆ FESPI_INSN_ADDR_PROTO

#define FESPI_INSN_ADDR_PROTO (   x)    (((x) & 0x3) << 10)

Definition at line 85 of file fespi.c.

◆ FESPI_INSN_CMD_CODE

#define FESPI_INSN_CMD_CODE (   x)    (((x) & 0xff) << 16)

Definition at line 87 of file fespi.c.

◆ FESPI_INSN_CMD_EN

#define FESPI_INSN_CMD_EN   0x1

Definition at line 81 of file fespi.c.

◆ FESPI_INSN_CMD_PROTO

#define FESPI_INSN_CMD_PROTO (   x)    (((x) & 0x3) << 8)

Definition at line 84 of file fespi.c.

◆ FESPI_INSN_DATA_PROTO

#define FESPI_INSN_DATA_PROTO (   x)    (((x) & 0x3) << 12)

Definition at line 86 of file fespi.c.

◆ FESPI_INSN_PAD_CNT

#define FESPI_INSN_PAD_CNT (   x)    (((x) & 0xf) << 4)

Definition at line 83 of file fespi.c.

◆ FESPI_INSN_PAD_CODE

#define FESPI_INSN_PAD_CODE (   x)    (((x) & 0xff) << 24)

Definition at line 88 of file fespi.c.

◆ FESPI_IP_RXWM

#define FESPI_IP_RXWM   0x2

Definition at line 77 of file fespi.c.

◆ FESPI_IP_TXWM

#define FESPI_IP_TXWM   0x1

Definition at line 76 of file fespi.c.

◆ FESPI_MAX_TIMEOUT

#define FESPI_MAX_TIMEOUT   (3000)

Definition at line 110 of file fespi.c.

◆ FESPI_PROBE_TIMEOUT

#define FESPI_PROBE_TIMEOUT   (100)

Definition at line 109 of file fespi.c.

◆ FESPI_PROTO_D

#define FESPI_PROTO_D   1

Definition at line 100 of file fespi.c.

◆ FESPI_PROTO_Q

#define FESPI_PROTO_Q   2

Definition at line 101 of file fespi.c.

◆ FESPI_PROTO_S

#define FESPI_PROTO_S   0

Definition at line 99 of file fespi.c.

◆ FESPI_REG_CSDEF

#define FESPI_REG_CSDEF   0x14

Definition at line 41 of file fespi.c.

◆ FESPI_REG_CSID

#define FESPI_REG_CSID   0x10

Definition at line 40 of file fespi.c.

◆ FESPI_REG_CSMODE

#define FESPI_REG_CSMODE   0x18

Definition at line 42 of file fespi.c.

◆ FESPI_REG_DCSSCK

#define FESPI_REG_DCSSCK   0x28

Definition at line 44 of file fespi.c.

◆ FESPI_REG_DINTERCS

#define FESPI_REG_DINTERCS   0x2c

Definition at line 46 of file fespi.c.

◆ FESPI_REG_DINTERXFR

#define FESPI_REG_DINTERXFR   0x2e

Definition at line 47 of file fespi.c.

◆ FESPI_REG_DSCKCS

#define FESPI_REG_DSCKCS   0x2a

Definition at line 45 of file fespi.c.

◆ FESPI_REG_FCTRL

#define FESPI_REG_FCTRL   0x60

Definition at line 55 of file fespi.c.

◆ FESPI_REG_FFMT

#define FESPI_REG_FFMT   0x64

Definition at line 56 of file fespi.c.

◆ FESPI_REG_FMT

#define FESPI_REG_FMT   0x40

Definition at line 49 of file fespi.c.

◆ FESPI_REG_IE

#define FESPI_REG_IE   0x70

Definition at line 58 of file fespi.c.

◆ FESPI_REG_IP

#define FESPI_REG_IP   0x74

Definition at line 59 of file fespi.c.

◆ FESPI_REG_RXCTRL

#define FESPI_REG_RXCTRL   0x54

Definition at line 53 of file fespi.c.

◆ FESPI_REG_RXFIFO

#define FESPI_REG_RXFIFO   0x4c

Definition at line 51 of file fespi.c.

◆ FESPI_REG_SCKDIV

#define FESPI_REG_SCKDIV   0x00

Definition at line 38 of file fespi.c.

◆ FESPI_REG_SCKMODE

#define FESPI_REG_SCKMODE   0x04

Definition at line 39 of file fespi.c.

◆ FESPI_REG_TXCTRL

#define FESPI_REG_TXCTRL   0x50

Definition at line 52 of file fespi.c.

◆ FESPI_REG_TXFIFO

#define FESPI_REG_TXFIFO   0x48

Definition at line 50 of file fespi.c.

◆ FESPI_RXWM

#define FESPI_RXWM (   x)    ((x) & 0xffff)

Definition at line 74 of file fespi.c.

◆ FESPI_SCK_PHA

#define FESPI_SCK_PHA   0x2

Definition at line 64 of file fespi.c.

◆ FESPI_SCK_POL

#define FESPI_SCK_POL   0x1

Definition at line 63 of file fespi.c.

◆ FESPI_TXWM

#define FESPI_TXWM (   x)    ((x) & 0xffff)

Definition at line 72 of file fespi.c.

Function Documentation

◆ fespi_auto_probe()

static int fespi_auto_probe ( struct flash_bank bank)
static

Definition at line 820 of file fespi.c.

References bank, ERROR_OK, fespi_probe(), and fespi_flash_bank::probed.

◆ fespi_disable_hw_mode()

static int fespi_disable_hw_mode ( struct flash_bank bank)
static

◆ fespi_enable_hw_mode()

static int fespi_enable_hw_mode ( struct flash_bank bank)
static

◆ fespi_erase()

◆ fespi_erase_sector()

static int fespi_erase_sector ( struct flash_bank bank,
int  sector 
)
static

◆ fespi_probe()

◆ fespi_protect()

static int fespi_protect ( struct flash_bank bank,
int  set,
unsigned int  first,
unsigned int  last 
)
static

Definition at line 421 of file fespi.c.

References bank, and ERROR_OK.

◆ fespi_protect_check()

static int fespi_protect_check ( struct flash_bank bank)
static

Definition at line 828 of file fespi.c.

References ERROR_OK.

◆ fespi_read_flash_id()

◆ fespi_read_reg()

static int fespi_read_reg ( struct flash_bank bank,
uint32_t *  value,
target_addr_t  address 
)
static

◆ fespi_rx()

static int fespi_rx ( struct flash_bank bank,
uint8_t *  out 
)
static

◆ fespi_set_dir()

static int fespi_set_dir ( struct flash_bank bank,
bool  dir 
)
static

◆ fespi_tx()

static int fespi_tx ( struct flash_bank bank,
uint8_t  in 
)
static

◆ fespi_txwm_wait()

static int fespi_txwm_wait ( struct flash_bank bank)
static

◆ fespi_wip()

◆ fespi_write()

◆ fespi_write_reg()

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( fespi_flash_bank_command  )

◆ get_fespi_info()

static int get_fespi_info ( struct flash_bank bank,
struct command_invocation cmd 
)
static

Definition at line 834 of file fespi.c.

◆ slow_fespi_write_buffer()

static int slow_fespi_write_buffer ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  len 
)
static

Variable Documentation

◆ fespi_flash

const struct flash_driver fespi_flash
Initial value:
= {
.name = "fespi",
.flash_bank_command = fespi_flash_bank_command,
.erase = fespi_erase,
.protect = fespi_protect,
.write = fespi_write,
.probe = fespi_probe,
.auto_probe = fespi_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = fespi_protect_check,
.info = get_fespi_info,
.free_driver_priv = default_flash_free_driver_priv
}
static int fespi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: fespi.c:481
static int fespi_protect_check(struct flash_bank *bank)
Definition: fespi.c:828
static int fespi_probe(struct flash_bank *bank)
Definition: fespi.c:723
static int get_fespi_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: fespi.c:834
static int fespi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: fespi.c:356
static int fespi_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: fespi.c:421
static int fespi_auto_probe(struct flash_bank *bank)
Definition: fespi.c:820
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.

Definition at line 834 of file fespi.c.

◆ riscv32_bin

const uint8_t riscv32_bin[]
static
Initial value:
= {
}

Definition at line 473 of file fespi.c.

Referenced by fespi_write().

◆ riscv64_bin

const uint8_t riscv64_bin[]
static
Initial value:
= {
}

Definition at line 477 of file fespi.c.

Referenced by fespi_write().

◆ target_devices

const struct fespi_target target_devices[]
static
Initial value:
= {
{ "Freedom E310-G000 SPI Flash", 0x10e31913, 0x10014000 },
{ "Freedom E310-G002 SPI Flash", 0x20000913, 0x10014000 },
{ NULL, 0, 0 }
}
#define NULL
Definition: usb.h:16

Definition at line 1 of file fespi.c.

Referenced by fespi_probe().