32#define PAGE_MASK (PAGE_SIZE - 1U)
37#define CMD_SPI_READ3B 0x03U
38#define CMD_SPI_FAST_READ3B 0x0BU
39#define CMD_SPI_PP3B 0x02U
40#define CMD_SPI_SE3B 0x20U
41#define CMD_SPI_BE3B 0xD8U
42#define CMD_SPI_CE 0xC7U
43#define CMD_SPI_READ4B 0x13U
44#define CMD_SPI_FAST_READ4B 0x0CU
45#define CMD_SPI_PP4B 0x12U
46#define CMD_SPI_SE4B 0x21U
47#define CMD_SPI_BE4B 0xDCU
48#define CMD_SPI_WREN 0x06U
49#define CMD_SPI_WRDI 0x04U
50#define CMD_SPI_PE_SUSPEND 0xB0U
51#define CMD_SPI_PE_RESUME 0x30U
52#define CMD_SPI_DP 0xB9U
53#define CMD_SPI_SBL 0xC0U
54#define CMD_SPI_ENSO 0xB1U
55#define CMD_SPI_EXSO 0xC1U
56#define CMD_SPI_NOP 0x00U
57#define CMD_SPI_RSTEN 0x66U
58#define CMD_SPI_RST 0x99U
59#define CMD_SPI_RDID 0x9FU
60#define CMD_SPI_RDSFDP 0x5AU
61#define CMD_SPI_RDSR 0x05U
62#define CMD_SPI_RDCR 0x15U
63#define CMD_SPI_WRSR 0x01U
64#define CMD_SPI_RDCR2 0x71U
65#define CMD_SPI_WRCR2 0x72U
66#define CMD_SPI_RDFBR 0x16U
67#define CMD_SPI_WRFBR 0x17U
68#define CMD_SPI_ESFBR 0x18U
69#define CMD_SPI_RDSCUR 0x2BU
70#define CMD_SPI_WRSCUR 0x2FU
71#define CMD_SPI_WRLR 0x2CU
72#define CMD_SPI_RDLR 0x2DU
73#define CMD_SPI_WRSPB 0xE3U
74#define CMD_SPI_ESSPB 0xE4U
75#define CMD_SPI_RDSPB 0xE2U
76#define CMD_SPI_WRDPB 0xE1U
77#define CMD_SPI_RDDPB 0xE0U
78#define CMD_SPI_WPSEL 0x68U
79#define CMD_SPI_GBLK 0x7EU
80#define CMD_SPI_GBULK 0x98U
81#define CMD_SPI_RDPASS 0x27U
82#define CMD_SPI_WRPASS 0x28U
83#define CMD_SPI_PASSULK 0x29U
90#define CMD_OPI_8READ 0xEC13U
91#define CMD_OPI_8DTRD 0xEE11U
92#define CMD_OPI_RDID 0x9F60U
93#define CMD_OPI_RDSFDP 0x5AA5U
94#define CMD_OPI_PP 0x12EDU
95#define CMD_OPI_SE 0x21DEU
96#define CMD_OPI_BE 0xDC23U
97#define CMD_OPI_CE 0xC738U
98#define CMD_OPI_WREN 0x06F9U
99#define CMD_OPI_WRDI 0x04FBU
100#define CMD_OPI_PE_SUSPEND 0xB04FU
101#define CMD_OPI_PE_RESUME 0x30CFU
102#define CMD_OPI_DP 0xB946U
103#define CMD_OPI_SBL 0xC03FU
104#define CMD_OPI_ENSO 0xB14EU
105#define CMD_OPI_EXSO 0xC13EU
106#define CMD_OPI_NOP 0x00FFU
107#define CMD_OPI_RSTEN 0x6699U
108#define CMD_OPI_RST 0x9966U
109#define CMD_OPI_RDSR 0x05FAU
110#define CMD_OPI_RDCR 0x15EAU
111#define CMD_OPI_WRSR 0x01FEU
112#define CMD_OPI_WRCR 0x01FEU
113#define CMD_OPI_RDCR2 0x718EU
114#define CMD_OPI_WRCR2 0x728DU
115#define CMD_OPI_RDFBR 0x16E9U
116#define CMD_OPI_WRFBR 0x17E8U
117#define CMD_OPI_ESFBR 0x18E7U
118#define CMD_OPI_RDSCUR 0x2BD4U
119#define CMD_OPI_WRSCUR 0x2FD0U
120#define CMD_OPI_WRLR 0x2CD3U
121#define CMD_OPI_RDLR 0x2DD2U
122#define CMD_OPI_WRSPB 0xE31CU
123#define CMD_OPI_ESSPB 0xE41BU
124#define CMD_OPI_RDSPB 0xE21DU
125#define CMD_OPI_WRDPB 0xE11EU
126#define CMD_OPI_RDDPB 0xE01FU
127#define CMD_OPI_WPSEL 0x6897U
128#define CMD_OPI_GBLK 0x7E81U
129#define CMD_OPI_GBULK 0x9867U
130#define CMD_OPI_RDPASS 0x27D8U
131#define CMD_OPI_WRPASS 0x28D7U
132#define CMD_OPI_PASSULK 0x29D6U
139#define FLAGS_WPSEL 0x80U
140#define FLAGS_E_FAIL 0x40U
141#define FLAGS_P_FAIL 0x20U
142#define FLAGS_ESB 0x08U
143#define FLAGS_PSB 0x04U
144#define FLAGS_LDSO 0x02U
145#define FLAGS_SECURED_OTP 0x01U
146#define FLAGS_ALL_ERRORS (FLAGS_E_FAIL | FLAGS_P_FAIL)
153#define CFG_C8_SPI (WSPI_CFG_CMD_SIZE_8 | \
154 WSPI_CFG_CMD_MODE_ONE_LINE | \
155 WSPI_CFG_ADDR_MODE_NONE | \
156 WSPI_CFG_ALT_MODE_NONE | \
157 WSPI_CFG_DATA_MODE_NONE)
159#define CFG_C16_8STR (WSPI_CFG_CMD_SIZE_16 | \
160 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
161 WSPI_CFG_ADDR_MODE_NONE | \
162 WSPI_CFG_ALT_MODE_NONE | \
163 WSPI_CFG_DATA_MODE_NONE)
165#define CFG_C16_8DTR (WSPI_CFG_CMD_SIZE_16 | \
166 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
167 WSPI_CFG_ADDR_MODE_NONE | \
168 WSPI_CFG_ALT_MODE_NONE | \
169 WSPI_CFG_DATA_MODE_NONE | \
172#define CFG_C8_A32_SPI (WSPI_CFG_CMD_SIZE_8 | \
173 WSPI_CFG_CMD_MODE_ONE_LINE | \
174 WSPI_CFG_ADDR_MODE_ONE_LINE | \
175 WSPI_CFG_ADDR_SIZE_32 | \
176 WSPI_CFG_ALT_MODE_NONE | \
177 WSPI_CFG_DATA_MODE_NONE)
179#define CFG_C16_A32_8STR (WSPI_CFG_CMD_SIZE_16 | \
180 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
181 WSPI_CFG_ADDR_MODE_EIGHT_LINES | \
182 WSPI_CFG_ADDR_SIZE_32 | \
183 WSPI_CFG_ALT_MODE_NONE | \
184 WSPI_CFG_DATA_MODE_NONE)
186#define CFG_C16_A32_8DTR (WSPI_CFG_CMD_SIZE_16 | \
187 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
188 WSPI_CFG_ADDR_MODE_EIGHT_LINES | \
189 WSPI_CFG_ADDR_SIZE_32 | \
190 WSPI_CFG_ALT_MODE_NONE | \
191 WSPI_CFG_DATA_MODE_NONE | \
194#define CFG_C8_DATA_SPI (WSPI_CFG_CMD_SIZE_8 | \
195 WSPI_CFG_CMD_MODE_ONE_LINE | \
196 WSPI_CFG_ADDR_MODE_NONE | \
197 WSPI_CFG_ALT_MODE_NONE | \
198 WSPI_CFG_DATA_MODE_ONE_LINE)
200#define CFG_C16_DATA_8STR (WSPI_CFG_CMD_SIZE_16 | \
201 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
202 WSPI_CFG_ADDR_MODE_NONE | \
203 WSPI_CFG_ALT_MODE_NONE | \
204 WSPI_CFG_DATA_MODE_EIGHT_LINES)
206#define CFG_C16_DATA_8DTR (WSPI_CFG_CMD_SIZE_16 | \
207 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
208 WSPI_CFG_ADDR_MODE_NONE | \
209 WSPI_CFG_ALT_MODE_NONE | \
210 WSPI_CFG_DATA_MODE_EIGHT_LINES | \
214#define CFG_C8_A32_DATA_SPI (WSPI_CFG_CMD_SIZE_8 | \
215 WSPI_CFG_CMD_MODE_ONE_LINE | \
216 WSPI_CFG_ADDR_MODE_ONE_LINE | \
217 WSPI_CFG_ADDR_SIZE_32 | \
218 WSPI_CFG_ALT_MODE_NONE | \
219 WSPI_CFG_DATA_MODE_ONE_LINE)
221#define CFG_C16_A32_DATA_8STR (WSPI_CFG_CMD_SIZE_16 | \
222 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
223 WSPI_CFG_ADDR_MODE_EIGHT_LINES | \
224 WSPI_CFG_ADDR_SIZE_32 | \
225 WSPI_CFG_ALT_MODE_NONE | \
226 WSPI_CFG_DATA_MODE_EIGHT_LINES)
228#define CFG_C16_A32_DATA_8DTR (WSPI_CFG_CMD_SIZE_16 | \
229 WSPI_CFG_CMD_MODE_EIGHT_LINES | \
230 WSPI_CFG_ADDR_MODE_EIGHT_LINES | \
231 WSPI_CFG_ADDR_SIZE_32 | \
232 WSPI_CFG_ALT_MODE_NONE | \
233 WSPI_CFG_DATA_MODE_EIGHT_LINES | \
238#if (XSNOR_USE_WSPI == TRUE) || defined(__DOXYGEN__)
323static bool mx25_find_id(
const uint8_t *set,
size_t size, uint8_t element) {
326 for (i = 0; i < size; i++) {
327 if (set[i] == element) {
344 1U, &self->config->buffers->databuf[0]);
349 &self->config->buffers->databuf[0]);
351 }
while ((self->config->buffers->databuf[0] & 1U) != 0U);
356 1U, &self->config->buffers->databuf[0]);
361 &self->config->buffers->databuf[0]);
372#if (XSNOR_USE_WSPI == TRUE) || defined(__DOXYGEN__)
404 switch (self->config->bus_type) {
434 wspiReceive(self->config->bus.wspi.drv, &cmd, 3U, buf);
438 uint32_t addr,
const uint8_t *value) {
443 switch (self->config->bus_type) {
474 switch (self->config->bus_type) {
501 wspiSend(self->config->bus.wspi.drv, &cmd, 1, value);
536 self->descriptor.page_size = 256U;
537 self->descriptor.sectors_count = 0U;
538 self->descriptor.sectors = NULL;
539 self->descriptor.sectors_size = 0U;
540 self->descriptor.address = 0U;
541 self->descriptor.size = 0U;
575#if XSNOR_USE_WSPI == TRUE
578 self->commands = NULL;
590 self->commands = NULL;
595#if XSNOR_USE_BOTH == TRUE
598#if XSNOR_USE_SPI == TRUE
620#if XSNOR_USE_BOTH == TRUE
623#if XSNOR_USE_WSPI == TRUE
656 switch (self->config->bus_type) {
659 static const uint8_t cr2_spi[1] = {0x00};
667 static const uint8_t cr2_opi_dtr[1] = {0x02};
678 static const uint8_t cr2_opi_str[1] = {0x01};
700 self->descriptor.sectors_size = 0x00001000U;
703 self->descriptor.sectors_size = 0x00010000U;
705 self->descriptor.size = (uint32_t)(1U << ((
size_t)config->
buffers->
databuf[2] & 0x1FU));
706 self->descriptor.sectors_count = self->descriptor.size / self->descriptor.sectors_size;
726 switch (self->config->bus_type) {
771 size_t chunk = (size_t)(((offset |
PAGE_MASK) + 1U) - offset);
777 switch (self->config->bus_type) {
824 switch (self->config->bus_type) {
860 switch (self->config->bus_type) {
907 switch (self->config->bus_type) {
911 &self->config->buffers->databuf[0]);
915 &self->config->buffers->databuf[16]);
921 &self->config->buffers->databuf[0]);
926 &self->config->buffers->databuf[16]);
935 if (((self->config->buffers->databuf[0] & 1) != 0U) ||
936 ((self->config->buffers->databuf[16] & 8) != 0U)) {
971 offset = (
flash_offset_t)(sector * self->descriptor.sectors_size);
972 n = self->descriptor.sectors_size;
980 for (p = &self->config->buffers->databuf[0];
1007#if XSNOR_USE_BOTH == TRUE
1013#if XSNOR_USE_WSPI == FALSE
1023 switch (self->config->bus_type) {
1065#if XSNOR_USE_WSPI == TRUE
static const struct EFlashDriverVMT vmt
uint32_t flash_sector_t
Type of a flash sector number.
uint32_t flash_offset_t
Type of a flash offset.
#define FLASH_ATTR_REWRITABLE
Programmed pages can be programmed again.
#define FLASH_ATTR_SUSPEND_ERASE_CAPABLE
The device is able to suspend erase operations.
flash_error_t
Type of a flash error code.
#define FLASH_ATTR_ERASED_IS_ONE
Defines one as the erased bit state.
@ FLASH_ERROR_UNIMPLEMENTED
void __xsnor_dispose_impl(void *ip)
Implementation of object finalization.
#define XSNOR_BUFFER_SIZE
Non-cacheable operations buffer.
#define __xsnor_bus_release(self)
#define XSNOR_BUS_MODE_SPI
void * __xsnor_objinit_impl(void *ip, const void *vmt)
Implementation of object creation.
#define XSNOR_BUS_MODE_WSPI_8LINES
void __xsnor_bus_cmd_addr_send(void *ip, uint32_t cmd, flash_offset_t offset, size_t n, const uint8_t *p)
Sends a command followed by a flash address and a data transmit phase.
void __xsnor_bus_cmd_addr(void *ip, uint32_t cmd, flash_offset_t offset)
Sends a command followed by a flash address.
void __xsnor_bus_cmd(void *ip, uint32_t cmd)
Sends a naked command.
struct xsnor_config xsnor_config_t
Type of a SNOR configuration structure.
void __xsnor_bus_cmd_addr_dummy_receive(void *ip, uint32_t cmd, flash_offset_t offset, uint32_t dummy, size_t n, uint8_t *p)
Sends a complete header followed by a data receive phase.
void __xsnor_bus_cmd_receive(void *ip, uint32_t cmd, size_t n, uint8_t *p)
Sends a command followed by a data receive phase.
struct xsnor_commands xsnor_commands_t
Type of a commands configuration structure.
#define __xsnor_bus_acquire(self)
static const xsnor_commands_t cmd_8dtr
#define CFG_C16_A32_DATA_8DTR
flash_error_t __mx25_mmap_on_impl(void *ip, uint8_t **addrp)
Override of method xsnor_device_mmap_on().
#define CMD_SPI_FAST_READ4B
void __mx25_mmap_off_impl(void *ip)
Override of method xsnor_device_mmap_off().
static void mx25_write_cr2(hal_xsnor_macronix_mx25_c *self, uint32_t addr, const uint8_t *value)
static const wspi_command_t cmd_reset_enable_8dtr
static const wspi_command_t cmd_reset_memory_spi
static void mx25_read_id(hal_xsnor_macronix_mx25_c *self, uint8_t *buf)
static bool mx25_find_id(const uint8_t *set, size_t size, uint8_t element)
#define CFG_C16_DATA_8STR
static const wspi_command_t cmd_reset_memory_8dtr
static const wspi_command_t cmd_reset_enable_spi
static void mx25_reset_memory(hal_xsnor_macronix_mx25_c *self)
flash_error_t __mx25_query_erase_impl(void *ip, unsigned *msec)
Override of method xsnor_device_query_erase().
#define MX25_OPT_NO_WIDTH_SWITCH
Switch bus width on initialization.
static const uint8_t mx25_memory_type_ids[]
#define MX25_OPT_DUMMY_CYCLES_MASK
Mask of the dummy cycles field.
#define CFG_C8_A32_DATA_SPI
#define MX25_OPT_USE_SUBSECTORS
Use 4kB sub-sectors rather than 64kB sectors.
static const wspi_command_t cmd_reset_enable_8str
void __mx25_dispose_impl(void *ip)
Implementation of object finalization.
flash_error_t __mx25_program_impl(void *ip, flash_offset_t offset, size_t n, const uint8_t *pp)
Override of method xsnor_device_program().
static flash_error_t mx25_poll_status(hal_xsnor_macronix_mx25_c *self)
flash_error_t __mx25_start_erase_sector_impl(void *ip, flash_sector_t sector)
Override of method xsnor_device_start_erase_sector().
static const wspi_command_t cmd_reset_memory_8str
#define CFG_C16_A32_DATA_8STR
flash_error_t __mx25_read_impl(void *ip, flash_offset_t offset, size_t n, uint8_t *rp)
Override of method xsnor_device_read().
flash_error_t __mx25_init_impl(void *ip)
Override of method xsnor_device_init().
#define CFG_C16_DATA_8DTR
const struct hal_xsnor_macronix_mx25_vmt __hal_xsnor_macronix_mx25_vmt
VMT structure of SNOR Macronix MX25 driver class.
#define MX25_OPT_NICE_WAITING
Delays insertion.
flash_error_t __mx25_start_erase_all_impl(void *ip)
Override of method xsnor_device_start_erase_all().
flash_error_t __mx25_verify_erase_impl(void *ip, flash_sector_t sector)
Override of method xsnor_device_verify_erase().
static const xsnor_commands_t cmd_spi
static const uint8_t mx25_manufacturer_ids[]
void * __mx25_objinit_impl(void *ip, const void *vmt)
Implementation of object creation.
static const xsnor_commands_t cmd_8str
#define MX25_OPT_USE_DTR
Enables DTR in 8 lines mode.
#define osalThreadSleepMicroseconds(usecs)
Delays the invoking thread for the specified number of microseconds.
#define osalDbgAssert(c, remark)
Condition assertion.
#define osalThreadSleepMilliseconds(msecs)
Delays the invoking thread for the specified number of milliseconds.
void wspiMapFlash(WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp)
Maps in memory space a WSPI flash device.
bool wspiReceive(WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, uint8_t *rxbuf)
Sends a command then receives data over the WSPI bus.
bool wspiCommand(WSPIDriver *wspip, const wspi_command_t *cmdp)
Sends a command without data phase.
bool wspiSend(WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, const uint8_t *txbuf)
Sends a command with data over the WSPI bus.
void wspiUnmapFlash(WSPIDriver *wspip)
Unmaps from memory space a WSPI flash device.
Class hal_xsnor_macronix_mx25_c virtual methods table.
Type of a WSPI command descriptor.
uint32_t dummy
Number of dummy cycles to be inserted.
uint32_t cfg
Transfer configuration field.
uint32_t alt
Alternate phase data.
uint32_t addr
Address phase data.
uint32_t cmd
Command phase data.
uint8_t databuf[XSNOR_BUFFER_SIZE]
Non-cacheable data buffer.
int bus_type
Bus type selection switch.
xsnor_buffers_t * buffers
Pointer to the non-cacheable buffers.