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

Go to the source code of this file.

Data Structures

struct  sector_info
 
struct  stmqspi_flash_bank
 

Macros

#define OCTOSPI_CCR_MASS_ERASE    ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ADDR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))
 
#define OCTOSPI_CCR_PAGE_PROG    ((OCTOSPI_MODE_CCR & QSPI_NO_ALTB))
 
#define OCTOSPI_CCR_READ   OCTOSPI_MODE_CCR
 
#define OCTOSPI_CCR_READ_ID
 
#define OCTOSPI_CCR_READ_MID   OCTOSPI_CCR_READ_ID
 
#define OCTOSPI_CCR_READ_SFDP(len)
 
#define OCTOSPI_CCR_READ_STATUS
 
#define OCTOSPI_CCR_SECTOR_ERASE    ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))
 
#define OCTOSPI_CCR_WRITE_ENABLE    ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ADDR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))
 
#define OCTOSPI_MODE   (stmqspi_info->saved_cr & 0xCFFFFFFF)
 
#define OCTOSPI_MODE_CCR
 
#define OPI_CMD(cmd)   ((OPI_MODE ? ((((uint16_t)(cmd)) << 8) | (~(cmd) & 0xFFU)) : (cmd)))
 
#define OPI_DUMMY    ((stmqspi_info->saved_ccr & OCTOSPI_DQSEN) ? 6U : 4U)
 
#define OPI_MODE   ((stmqspi_info->saved_ccr & OCTOSPI_ISIZE_MASK) != 0)
 
#define QSPI_CCR_MASS_ERASE
 
#define QSPI_CCR_PAGE_PROG
 
#define QSPI_CCR_READ
 
#define QSPI_CCR_READ_ID
 
#define QSPI_CCR_READ_MID
 
#define QSPI_CCR_READ_SFDP
 
#define QSPI_CCR_READ_STATUS
 
#define QSPI_CCR_SECTOR_ERASE
 
#define QSPI_CCR_WRITE_ENABLE
 
#define QSPI_MODE
 
#define SPI_ADSIZE   (((stmqspi_info->saved_ccr >> SPI_ADSIZE_POS) & 0x3) + 1)
 
#define SPI_CMD_TIMEOUT   (100)
 
#define SPI_MASS_ERASE_TIMEOUT   (400000)
 
#define SPI_MAX_TIMEOUT   (2000)
 
#define SPI_PROBE_TIMEOUT   (100)
 

Functions

 COMMAND_HANDLER (stmqspi_handle_cmd)
 
 COMMAND_HANDLER (stmqspi_handle_mass_erase_command)
 
 COMMAND_HANDLER (stmqspi_handle_set)
 
static int find_sfdp_dummy (struct flash_bank *bank, int len)
 
 FLASH_BANK_COMMAND_HANDLER (stmqspi_flash_bank_command)
 
static int get_stmqspi_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static uint32_t h_to_le_32 (uint32_t val)
 
static int log2u (uint32_t word)
 
static int octospi_cmd (struct flash_bank *bank, uint32_t mode, uint32_t ccr, uint32_t ir)
 
static int poll_busy (struct flash_bank *bank, int timeout)
 
static int qspi_erase_sector (struct flash_bank *bank, unsigned int sector)
 
static int qspi_read_write_block (struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count, bool write)
 
static int qspi_verify (struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int qspi_write_enable (struct flash_bank *bank)
 
static int read_flash_id (struct flash_bank *bank, uint32_t *id1, uint32_t *id2)
 
static int read_sfdp_block (struct flash_bank *bank, uint32_t addr, uint32_t words, uint32_t *buffer)
 
static int read_status_reg (struct flash_bank *bank, uint16_t *status)
 
static int set_mm_mode (struct flash_bank *bank)
 
static int stmqspi_abort (struct flash_bank *bank)
 
static int stmqspi_auto_probe (struct flash_bank *bank)
 
static int stmqspi_blank_check (struct flash_bank *bank)
 
static int stmqspi_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int stmqspi_probe (struct flash_bank *bank)
 
static int stmqspi_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int stmqspi_protect_check (struct flash_bank *bank)
 
static int stmqspi_read (struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int stmqspi_verify (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int stmqspi_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int wait_till_ready (struct flash_bank *bank, int timeout)
 

Variables

static const struct command_registration stmqspi_command_handlers []
 
static const struct command_registration stmqspi_exec_command_handlers []
 
const struct flash_driver stmqspi_flash
 

Macro Definition Documentation

◆ OCTOSPI_CCR_MASS_ERASE

#define OCTOSPI_CCR_MASS_ERASE    ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ADDR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))

Definition at line 131 of file stmqspi.c.

◆ OCTOSPI_CCR_PAGE_PROG

#define OCTOSPI_CCR_PAGE_PROG    ((OCTOSPI_MODE_CCR & QSPI_NO_ALTB))

Definition at line 134 of file stmqspi.c.

◆ OCTOSPI_CCR_READ

#define OCTOSPI_CCR_READ   OCTOSPI_MODE_CCR

Definition at line 97 of file stmqspi.c.

◆ OCTOSPI_CCR_READ_ID

#define OCTOSPI_CCR_READ_ID
Value:
#define OPI_MODE
Definition: stmqspi.c:91
#define OCTOSPI_MODE_CCR
Definition: stmqspi.c:93
#define OCTOSPI_NO_ALTB
Definition: stmqspi.h:90
#define OCTOSPI_NO_ADDR
Definition: stmqspi.h:91
#define OCTOSPI_NO_DDTR
Definition: stmqspi.h:96

Definition at line 114 of file stmqspi.c.

◆ OCTOSPI_CCR_READ_MID

#define OCTOSPI_CCR_READ_MID   OCTOSPI_CCR_READ_ID

Definition at line 118 of file stmqspi.c.

◆ OCTOSPI_CCR_READ_SFDP

#define OCTOSPI_CCR_READ_SFDP (   len)
Value:
(((len) < 4) ? OCTOSPI_ADDR3 : OCTOSPI_ADDR4))
#define OCTOSPI_ADDR4
Definition: stmqspi.h:93
#define OCTOSPI_ADDR3
Definition: stmqspi.h:92

Definition at line 121 of file stmqspi.c.

◆ OCTOSPI_CCR_READ_STATUS

#define OCTOSPI_CCR_READ_STATUS
Value:

Definition at line 110 of file stmqspi.c.

◆ OCTOSPI_CCR_SECTOR_ERASE

#define OCTOSPI_CCR_SECTOR_ERASE    ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))

Definition at line 128 of file stmqspi.c.

◆ OCTOSPI_CCR_WRITE_ENABLE

#define OCTOSPI_CCR_WRITE_ENABLE    ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ADDR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))

Definition at line 125 of file stmqspi.c.

◆ OCTOSPI_MODE

#define OCTOSPI_MODE   (stmqspi_info->saved_cr & 0xCFFFFFFF)

Definition at line 89 of file stmqspi.c.

◆ OCTOSPI_MODE_CCR

#define OCTOSPI_MODE_CCR
Value:
(stmqspi_info->saved_ccr & \
#define OCTOSPI_ALTB_MODE
Definition: stmqspi.h:87
#define OCTOSPI_8LINE_MODE
Definition: stmqspi.h:88

Definition at line 93 of file stmqspi.c.

◆ OPI_CMD

#define OPI_CMD (   cmd)    ((OPI_MODE ? ((((uint16_t)(cmd)) << 8) | (~(cmd) & 0xFFU)) : (cmd)))

Definition at line 139 of file stmqspi.c.

◆ OPI_DUMMY

#define OPI_DUMMY    ((stmqspi_info->saved_ccr & OCTOSPI_DQSEN) ? 6U : 4U)

Definition at line 107 of file stmqspi.c.

◆ OPI_MODE

#define OPI_MODE   ((stmqspi_info->saved_ccr & OCTOSPI_ISIZE_MASK) != 0)

Definition at line 91 of file stmqspi.c.

◆ QSPI_CCR_MASS_ERASE

#define QSPI_CCR_MASS_ERASE
Value:
(QSPI_WRITE_MODE | stmqspi_info->dev.chip_erase_cmd))
#define QSPI_MODE
Definition: stmqspi.c:46
#define QSPI_NO_ALTB
Definition: stmqspi.h:52
#define QSPI_NO_DATA
Definition: stmqspi.h:51
#define QSPI_WRITE_MODE
Definition: stmqspi.h:46
#define QSPI_NO_ADDR
Definition: stmqspi.h:53
#define QSPI_DCYC_MASK
Definition: stmqspi.h:43

Definition at line 80 of file stmqspi.c.

◆ QSPI_CCR_PAGE_PROG

#define QSPI_CCR_PAGE_PROG
Value:
(QSPI_WRITE_MODE | stmqspi_info->dev.pprog_cmd))

Definition at line 84 of file stmqspi.c.

◆ QSPI_CCR_READ

#define QSPI_CCR_READ
Value:
(QSPI_READ_MODE | (stmqspi_info->saved_ccr & \
#define QSPI_4LINE_MODE
Definition: stmqspi.h:50
#define QSPI_ALTB_MODE
Definition: stmqspi.h:49
#define QSPI_ADDR4
Definition: stmqspi.h:55
#define QSPI_READ_MODE
Definition: stmqspi.h:47

Definition at line 51 of file stmqspi.c.

◆ QSPI_CCR_READ_ID

#define QSPI_CCR_READ_ID
Value:

Definition at line 59 of file stmqspi.c.

◆ QSPI_CCR_READ_MID

#define QSPI_CCR_READ_MID
Value:

Definition at line 63 of file stmqspi.c.

◆ QSPI_CCR_READ_SFDP

#define QSPI_CCR_READ_SFDP
Value:
#define SPIFLASH_READ_SFDP
Definition: spi.h:80
#define QSPI_ADDR3
Definition: stmqspi.h:54

Definition at line 68 of file stmqspi.c.

◆ QSPI_CCR_READ_STATUS

#define QSPI_CCR_READ_STATUS
Value:

Definition at line 55 of file stmqspi.c.

◆ QSPI_CCR_SECTOR_ERASE

#define QSPI_CCR_SECTOR_ERASE
Value:
(QSPI_WRITE_MODE | stmqspi_info->dev.erase_cmd))

Definition at line 76 of file stmqspi.c.

◆ QSPI_CCR_WRITE_ENABLE

#define QSPI_CCR_WRITE_ENABLE
Value:

Definition at line 72 of file stmqspi.c.

◆ QSPI_MODE

#define QSPI_MODE
Value:
(stmqspi_info->saved_ccr & \

Definition at line 46 of file stmqspi.c.

◆ SPI_ADSIZE

#define SPI_ADSIZE   (((stmqspi_info->saved_ccr >> SPI_ADSIZE_POS) & 0x3) + 1)

Definition at line 137 of file stmqspi.c.

◆ SPI_CMD_TIMEOUT

#define SPI_CMD_TIMEOUT   (100)

Definition at line 151 of file stmqspi.c.

◆ SPI_MASS_ERASE_TIMEOUT

#define SPI_MASS_ERASE_TIMEOUT   (400000)

Definition at line 154 of file stmqspi.c.

◆ SPI_MAX_TIMEOUT

#define SPI_MAX_TIMEOUT   (2000)

Definition at line 153 of file stmqspi.c.

◆ SPI_PROBE_TIMEOUT

#define SPI_PROBE_TIMEOUT   (100)

Definition at line 152 of file stmqspi.c.

Function Documentation

◆ COMMAND_HANDLER() [1/3]

◆ COMMAND_HANDLER() [2/3]

◆ COMMAND_HANDLER() [3/3]

◆ find_sfdp_dummy()

◆ FLASH_BANK_COMMAND_HANDLER()

◆ get_stmqspi_info()

◆ h_to_le_32()

static uint32_t h_to_le_32 ( uint32_t  val)
inlinestatic

Definition at line 142 of file stmqspi.c.

References h_u32_to_le().

Referenced by qspi_read_write_block(), qspi_verify(), and stmqspi_blank_check().

◆ log2u()

static int log2u ( uint32_t  word)
static

Definition at line 596 of file stmqspi.c.

References BIT.

Referenced by COMMAND_HANDLER().

◆ octospi_cmd()

◆ poll_busy()

◆ qspi_erase_sector()

◆ qspi_read_write_block()

◆ qspi_verify()

◆ qspi_write_enable()

◆ read_flash_id()

◆ read_sfdp_block()

◆ read_status_reg()

◆ set_mm_mode()

◆ stmqspi_abort()

◆ stmqspi_auto_probe()

static int stmqspi_auto_probe ( struct flash_bank bank)
static

Definition at line 2366 of file stmqspi.c.

References bank, ERROR_OK, stmqspi_flash_bank::probed, and stmqspi_probe().

◆ stmqspi_blank_check()

◆ stmqspi_erase()

◆ stmqspi_probe()

◆ stmqspi_protect()

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

Definition at line 1048 of file stmqspi.c.

References bank, ERROR_OK, and LOG_WARNING.

◆ stmqspi_protect_check()

static int stmqspi_protect_check ( struct flash_bank bank)
static

Definition at line 2376 of file stmqspi.c.

References ERROR_OK.

◆ stmqspi_read()

static int stmqspi_read ( struct flash_bank bank,
uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

◆ stmqspi_verify()

◆ stmqspi_write()

◆ wait_till_ready()

static int wait_till_ready ( struct flash_bank bank,
int  timeout 
)
static

Variable Documentation

◆ stmqspi_command_handlers

const struct command_registration stmqspi_command_handlers[]
static
Initial value:
= {
{
.name = "stmqspi",
.mode = COMMAND_ANY,
.help = "stmqspi flash command group",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration stmqspi_exec_command_handlers[]
Definition: stmqspi.c:2413

Definition at line 2382 of file stmqspi.c.

◆ stmqspi_exec_command_handlers

const struct command_registration stmqspi_exec_command_handlers[]
static
Initial value:
= {
{
.name = "mass_erase",
.handler = stmqspi_handle_mass_erase_command,
.mode = COMMAND_EXEC,
.usage = "bank_id",
.help = "Mass erase entire flash device.",
},
{
.name = "set",
.handler = stmqspi_handle_set,
.mode = COMMAND_EXEC,
.usage = "bank_id name chip_size page_size read_cmd qread_cmd pprg_cmd "
"[ mass_erase_cmd ] [ sector_size sector_erase_cmd ]",
.help = "Set params of single flash chip",
},
{
.name = "cmd",
.handler = stmqspi_handle_cmd,
.mode = COMMAND_EXEC,
.usage = "bank_id num_resp cmd_byte ...",
.help = "Send low-level command cmd_byte and following bytes or read num_resp.",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 2382 of file stmqspi.c.

◆ stmqspi_flash

const struct flash_driver stmqspi_flash
Initial value:
= {
.name = "stmqspi",
.flash_bank_command = stmqspi_flash_bank_command,
.erase = stmqspi_erase,
.protect = stmqspi_protect,
.write = stmqspi_write,
.read = stmqspi_read,
.verify = stmqspi_verify,
.probe = stmqspi_probe,
.auto_probe = stmqspi_auto_probe,
.erase_check = stmqspi_blank_check,
.protect_check = stmqspi_protect_check,
.free_driver_priv = default_flash_free_driver_priv,
}
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
static int stmqspi_protect_check(struct flash_bank *bank)
Definition: stmqspi.c:2376
static int stmqspi_verify(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stmqspi.c:1668
static int stmqspi_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: stmqspi.c:1048
static int stmqspi_probe(struct flash_bank *bank)
Definition: stmqspi.c:2067
static int stmqspi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stmqspi.c:1607
static int stmqspi_blank_check(struct flash_bank *bank)
Definition: stmqspi.c:1063
static int stmqspi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stmqspi.c:1569
static const struct command_registration stmqspi_command_handlers[]
Definition: stmqspi.c:2439
static int stmqspi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: stmqspi.c:995
static int stmqspi_auto_probe(struct flash_bank *bank)
Definition: stmqspi.c:2366
static int get_stmqspi_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: stmqspi.c:2382

Definition at line 2382 of file stmqspi.c.