OpenOCD
spi.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2018-2019 by Andreas Bolsch *
5  * andreas.bolsch@mni.thm.de *
6  * *
7  * Copyright (C) 2012 by George Harris *
8  * george@luminairecoffee.com *
9  * *
10  * Copyright (C) 2010 by Antonio Borneo *
11  * borneo.antonio@gmail.com *
12  ***************************************************************************/
13 
14 #ifndef OPENOCD_FLASH_NOR_SPI_H
15 #define OPENOCD_FLASH_NOR_SPI_H
16 
17 #ifndef __ASSEMBLER__
18 
19 /* data structure to maintain flash ids from different vendors */
20 struct flash_device {
21  const char *name;
22  uint8_t read_cmd;
23  uint8_t dread_cmd;
24  uint8_t dread_mode;
25  uint8_t dread_dclk;
26  uint8_t qread_cmd;
27  uint8_t pprog_cmd;
28  uint8_t erase_cmd;
29  uint8_t chip_erase_cmd;
30  uint32_t device_id;
31  uint32_t pagesize;
32  uint32_t sectorsize;
33  uint32_t size_in_bytes;
34 };
35 
36 #define FLASH_ID(n, re, qr, pp, es, ces, id, psize, ssize, size) \
37 { \
38  .name = n, \
39  .read_cmd = re, \
40  .qread_cmd = qr, \
41  .pprog_cmd = pp, \
42  .erase_cmd = es, \
43  .chip_erase_cmd = ces, \
44  .device_id = id, \
45  .pagesize = psize, \
46  .sectorsize = ssize, \
47  .size_in_bytes = size, \
48 }
49 
50 #define FRAM_ID(n, re, qr, pp, id, size) \
51 { \
52  .name = n, \
53  .read_cmd = re, \
54  .qread_cmd = qr, \
55  .pprog_cmd = pp, \
56  .erase_cmd = 0x00, \
57  .chip_erase_cmd = 0x00, \
58  .device_id = id, \
59  .pagesize = 0, \
60  .sectorsize = 0, \
61  .size_in_bytes = size, \
62 }
63 
64 extern const struct flash_device flash_devices[];
65 
66 #endif
67 
68 /* fields in SPI flash status register */
69 #define SPIFLASH_BSY 0
70 #define SPIFLASH_BSY_BIT (1 << SPIFLASH_BSY) /* WIP Bit of SPI SR */
71 #define SPIFLASH_WE 1
72 #define SPIFLASH_WE_BIT (1 << SPIFLASH_WE) /* WEL Bit of SPI SR */
73 
74 /* SPI Flash Commands */
75 #define SPIFLASH_READ_ID 0x9F /* Read Flash Identification */
76 #define SPIFLASH_READ_MID 0xAF /* Read Flash Identification, multi-io */
77 #define SPIFLASH_READ_STATUS 0x05 /* Read Status Register */
78 #define SPIFLASH_WRITE_ENABLE 0x06 /* Write Enable */
79 #define SPIFLASH_PAGE_PROGRAM 0x02 /* Page Program */
80 #define SPIFLASH_FAST_READ 0x0B /* Fast Read */
81 #define SPIFLASH_READ 0x03 /* Normal Read */
82 #define SPIFLASH_MASS_ERASE 0xC7 /* Mass Erase */
83 #define SPIFLASH_READ_SFDP 0x5A /* Read Serial Flash Discoverable Parameters */
84 
85 #define SPIFLASH_DEF_PAGESIZE 256 /* default for non-page-oriented devices (FRAMs) */
86 
87 #endif /* OPENOCD_FLASH_NOR_SPI_H */
const struct flash_device flash_devices[]
Definition: spi.c:24
uint8_t dread_mode
Definition: spi.h:24
uint8_t read_cmd
Definition: spi.h:22
uint32_t sectorsize
Definition: spi.h:32
uint32_t device_id
Definition: spi.h:30
uint8_t chip_erase_cmd
Definition: spi.h:29
const char * name
Definition: spi.h:21
uint32_t pagesize
Definition: spi.h:31
uint32_t size_in_bytes
Definition: spi.h:33
uint8_t pprog_cmd
Definition: spi.h:27
uint8_t dread_dclk
Definition: spi.h:25
uint8_t erase_cmd
Definition: spi.h:28
uint8_t qread_cmd
Definition: spi.h:26
uint8_t dread_cmd
Definition: spi.h:23