30#define PAGE_MASK (PAGE_SIZE - 1U)
36#define CMD_RESET_ENABLE 0x66
37#define CMD_RESET_MEMORY 0x99
38#define CMD_READ_ID 0x9F
39#define CMD_MULTIPLE_IO_READ_ID 0xAF
40#define CMD_READ_DISCOVERY_PARAMETER 0x5A
42#define CMD_READ4B 0x13
43#define CMD_FAST_READ 0x0B
44#define CMD_FAST_READ4B 0x0C
45#define CMD_WRITE_ENABLE 0x06
46#define CMD_WRITE_DISABLE 0x04
47#define CMD_READ_STATUS_REGISTER 0x05
48#define CMD_WRITE_STATUS_REGISTER 0x01
49#define CMD_READ_LOCK_REGISTER 0xE8
50#define CMD_WRITE_LOCK_REGISTER 0xE5
51#define CMD_READ_FLAG_STATUS_REGISTER 0x70
52#define CMD_CLEAR_FLAG_STATUS_REGISTER 0x50
53#define CMD_READ_NV_CONFIGURATION_REGISTER 0xB5
54#define CMD_WRITE_NV_CONFIGURATION_REGISTER 0xB1
55#define CMD_READ_V_CONF_REGISTER 0x85
56#define CMD_WRITE_V_CONF_REGISTER 0x81
57#define CMD_READ_ENHANCED_V_CONF_REGISTER 0x65
58#define CMD_WRITE_ENHANCED_V_CONF_REGISTER 0x61
59#define CMD_PAGE_PROGRAM 0x02
60#define CMD_PAGE_PROGRAM4B 0x12
61#define CMD_SUBSECTOR_ERASE 0x20
62#define CMD_SUBSECTOR_ERASE4B 0x21
63#define CMD_SECTOR_ERASE 0xD8
64#define CMD_SECTOR_ERASE4B 0xDC
65#define CMD_BULK_ERASE 0xC7
66#define CMD_PROGRAM_ERASE_RESUME 0x7A
67#define CMD_PROGRAM_ERASE_SUSPEND 0x75
68#define CMD_READ_OTP_ARRAY 0x4B
69#define CMD_PROGRAM_OTP_ARRAY 0x42
76#define FLAGS_PROGRAM_ERASE 0x80U
77#define FLAGS_ERASE_SUSPEND 0x40U
78#define FLAGS_ERASE_ERROR 0x20U
79#define FLAGS_PROGRAM_ERROR 0x10U
80#define FLAGS_VPP_ERROR 0x08U
81#define FLAGS_PROGRAM_SUSPEND 0x04U
82#define FLAGS_PROTECTION_ERROR 0x02U
83#define FLAGS_RESERVED 0x01U
84#define FLAGS_ALL_ERRORS (FLAGS_ERASE_ERROR | \
85 FLAGS_PROGRAM_ERROR | \
87 FLAGS_PROTECTION_ERROR)
90#if (XSNOR_USE_WSPI == TRUE) || defined(__DOXYGEN__)
316static bool n25q_find_id(
const uint8_t *set,
size_t size, uint8_t element) {
319 for (i = 0; i < size; i++) {
320 if (set[i] == element) {
336 1U, &self->config->buffers->databuf[0]);
356#if (XSNOR_USE_WSPI == TRUE) || defined(__DOXYGEN__)
365 1, &self->config->buffers->databuf[0]);
384 switch (self->config->bus_type) {
400 1, &self->config->buffers->databuf[0]);
410 1, &self->config->buffers->databuf[0]);
445 wspiReceive(self->config->bus.wspi.drv, &cmd, 3U, buf);
480 self->descriptor.page_size = 256U;
481 self->descriptor.sectors_count = 0U;
482 self->descriptor.sectors = NULL;
483 self->descriptor.sectors_size = 0U;
484 self->descriptor.address = 0U;
485 self->descriptor.size = 0U;
519#if XSNOR_USE_WSPI == TRUE
522 self->commands = NULL;
525 self->commands = &
cmd1l;
528 self->commands = &
cmd2l;
531 self->commands = &
cmd4l;
535 self->commands = NULL;
540#if XSNOR_USE_BOTH == TRUE
543#if XSNOR_USE_SPI == TRUE
565#if XSNOR_USE_BOTH == TRUE
568#if XSNOR_USE_WSPI == TRUE
662 self->descriptor.sectors_size = 0x00001000U;
665 self->descriptor.sectors_size = 0x00010000U;
667 self->descriptor.size = (uint32_t)(1U << ((
size_t)config->
buffers->
databuf[2] & 0x1FU));
668 self->descriptor.sectors_count = self->descriptor.size / self->descriptor.sectors_size;
670 if (self->descriptor.size > 0x01000000U) {
677#if XSNOR_USE_WSPI == TRUE
749 size_t chunk = (size_t)(((offset |
PAGE_MASK) + 1U) - offset);
845 1, &self->config->buffers->databuf[0]);
888 offset = (
flash_offset_t)(sector * self->descriptor.sectors_size);
889 n = self->descriptor.sectors_size;
897 for (p = &self->config->buffers->databuf[0];
924#if XSNOR_USE_BOTH == TRUE
930#if XSNOR_USE_WSPI == FALSE
954 switch (self->config->bus_type) {
992#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
#define FLASH_ATTR_SPI_4BYTES_ADDR_HINT
Hint to use 4 bytes addresses in SPI protocol.
void __xsnor_dispose_impl(void *ip)
Implementation of object finalization.
#define XSNOR_BUS_MODE_WSPI_2LINES
void __xsnor_bus_cmd_send(void *ip, uint32_t cmd, size_t n, const uint8_t *p)
Sends a command followed by a data transmit phase.
#define XSNOR_BUFFER_SIZE
Non-cacheable operations buffer.
#define __xsnor_bus_release(self)
#define XSNOR_BUS_MODE_SPI
#define XSNOR_BUS_MODE_WSPI_1LINE
void * __xsnor_objinit_impl(void *ip, const void *vmt)
Implementation of object creation.
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.
#define XSNOR_BUS_MODE_WSPI_4LINES
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.
void __xsnor_bus_cmd_addr_receive(void *ip, uint32_t cmd, flash_offset_t offset, size_t n, uint8_t *p)
Sends a command followed by a flash address and a data receive phase.
#define __xsnor_bus_acquire(self)
static const wspi_command_t cmd_reset_enable_2
#define CMD_CLEAR_FLAG_STATUS_REGISTER
#define N25Q_OPT_NICE_WAITING
Delays insertion.
#define CMD_SUBSECTOR_ERASE
#define CMD_SUBSECTOR_ERASE4B
#define FLAGS_ERASE_SUSPEND
#define CMD_SECTOR_ERASE4B
static const xsnor_commands_t cmd1l_4b
static void n25q_reset_memory(hal_xsnor_micron_n25q_c *self)
static bool n25q_spi_4bytes(const hal_xsnor_micron_n25q_c *self)
flash_error_t __n25q_mmap_on_impl(void *ip, uint8_t **addrp)
Override of method xsnor_device_mmap_on().
static const wspi_command_t cmd_reset_memory_2
flash_error_t __n25q_start_erase_sector_impl(void *ip, flash_sector_t sector)
Override of method xsnor_device_start_erase_sector().
void * __n25q_objinit_impl(void *ip, const void *vmt)
Implementation of object creation.
static void n25q_reset_xip(hal_xsnor_micron_n25q_c *self)
static void n25q_activate_xip(hal_xsnor_micron_n25q_c *self)
static const uint8_t n25q_memory_type_ids[]
flash_error_t __n25q_read_impl(void *ip, flash_offset_t offset, size_t n, uint8_t *rp)
Override of method xsnor_device_read().
#define N25Q_OPT_NO_WIDTH_SWITCH
Switch bus width on initialization.
static const wspi_command_t cmd_reset_enable_1
static const wspi_command_t cmd_reset_memory_4
flash_error_t __n25q_start_erase_all_impl(void *ip)
Override of method xsnor_device_start_erase_all().
const struct hal_xsnor_micron_n25q_vmt __hal_xsnor_micron_n25q_vmt
VMT structure of SNOR Micron N25Q driver class.
static const xsnor_commands_t cmd4l
flash_error_t __n25q_query_erase_impl(void *ip, unsigned *msec)
Override of method xsnor_device_query_erase().
static const xsnor_commands_t cmd2l_4b
flash_error_t __n25q_init_impl(void *ip)
Override of method xsnor_device_init().
static flash_error_t n25q_poll_status(hal_xsnor_micron_n25q_c *self)
void __n25q_dispose_impl(void *ip)
Implementation of object finalization.
#define FLAGS_PROGRAM_ERASE
static const xsnor_commands_t cmd1l
#define CMD_WRITE_ENHANCED_V_CONF_REGISTER
#define CMD_PAGE_PROGRAM4B
static const xsnor_commands_t cmd4l_4b
#define CMD_MULTIPLE_IO_READ_ID
#define CMD_READ_FLAG_STATUS_REGISTER
#define N25Q_OPT_USE_SUBSECTORS
Use 4kB sub-sectors rather than 64kB sectors.
flash_error_t __n25q_program_impl(void *ip, flash_offset_t offset, size_t n, const uint8_t *pp)
Override of method xsnor_device_program().
#define CMD_WRITE_V_CONF_REGISTER
static void n25q_read_id(hal_xsnor_micron_n25q_c *self, uint8_t *buf)
#define N25Q_OPT_DUMMY_CYCLES_MASK
Mask of the dummy cycles field.
void __n25q_mmap_off_impl(void *ip)
Override of method xsnor_device_mmap_off().
static const wspi_command_t cmd_reset_memory_1
static const wspi_command_t cmd_reset_enable_4
static const uint8_t n25q_manufacturer_ids[]
static const xsnor_commands_t cmd2l
flash_error_t __n25q_verify_erase_impl(void *ip, flash_sector_t sector)
Override of method xsnor_device_verify_erase().
static bool n25q_find_id(const uint8_t *set, size_t size, uint8_t element)
#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.
#define WSPI_CFG_ADDR_MODE_FOUR_LINES
#define WSPI_CFG_ADDR_SIZE_24
#define WSPI_CFG_ALT_MODE_FOUR_LINES
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.
#define WSPI_CFG_DATA_MODE_FOUR_LINES
#define WSPI_CFG_CMD_MODE_NONE
#define WSPI_CFG_ADDR_MODE_ONE_LINE
#define WSPI_CFG_CMD_MODE_FOUR_LINES
#define WSPI_CFG_ADDR_MODE_NONE
#define WSPI_CFG_DATA_MODE_TWO_LINES
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.
#define WSPI_CFG_CMD_MODE_TWO_LINES
#define WSPI_CFG_ALT_SIZE_8
void wspiUnmapFlash(WSPIDriver *wspip)
Unmaps from memory space a WSPI flash device.
#define WSPI_CFG_CMD_SIZE_8
#define WSPI_CFG_ADDR_SIZE_32
#define WSPI_CFG_DATA_MODE_ONE_LINE
#define WSPI_CFG_CMD_MODE_ONE_LINE
#define WSPI_CFG_DATA_MODE_NONE
#define WSPI_CFG_ALT_MODE_NONE
#define WSPI_CFG_ADDR_MODE_TWO_LINES
Class hal_xsnor_micron_n25q_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.
WSPIDriver * drv
WSPI driver to be used for physical communication.
int bus_type
Bus type selection switch.
int options
Device-dependent options, used by subclasses only.
union xsnor_bus_configs bus
WSPI driver configuration.
xsnor_buffers_t * buffers
Pointer to the non-cacheable buffers.
struct xsnor_bus_wspi wspi