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_FAST_READ 0x0B
43#define CMD_WRITE_ENABLE 0x06
44#define CMD_WRITE_DISABLE 0x04
45#define CMD_READ_STATUS_REGISTER 0x05
46#define CMD_WRITE_STATUS_REGISTER 0x01
47#define CMD_READ_LOCK_REGISTER 0xE8
48#define CMD_WRITE_LOCK_REGISTER 0xE5
49#define CMD_READ_FLAG_STATUS_REGISTER 0x70
50#define CMD_CLEAR_FLAG_STATUS_REGISTER 0x50
51#define CMD_READ_NV_CONFIGURATION_REGISTER 0xB5
52#define CMD_WRITE_NV_CONFIGURATION_REGISTER 0xB1
53#define CMD_READ_V_CONF_REGISTER 0x85
54#define CMD_WRITE_V_CONF_REGISTER 0x81
55#define CMD_READ_ENHANCED_V_CONF_REGISTER 0x65
56#define CMD_WRITE_ENHANCED_V_CONF_REGISTER 0x61
57#define CMD_PAGE_PROGRAM 0x02
58#define CMD_SUBSECTOR_ERASE 0x20
59#define CMD_SECTOR_ERASE 0xD8
60#define CMD_BULK_ERASE 0xC7
61#define CMD_PROGRAM_ERASE_RESUME 0x7A
62#define CMD_PROGRAM_ERASE_SUSPEND 0x75
63#define CMD_READ_OTP_ARRAY 0x4B
64#define CMD_PROGRAM_OTP_ARRAY 0x42
71#define FLAGS_PROGRAM_ERASE 0x80U
72#define FLAGS_ERASE_SUSPEND 0x40U
73#define FLAGS_ERASE_ERROR 0x20U
74#define FLAGS_PROGRAM_ERROR 0x10U
75#define FLAGS_VPP_ERROR 0x08U
76#define FLAGS_PROGRAM_SUSPEND 0x04U
77#define FLAGS_PROTECTION_ERROR 0x02U
78#define FLAGS_RESERVED 0x01U
79#define FLAGS_ALL_ERRORS (FLAGS_ERASE_ERROR | \
80 FLAGS_PROGRAM_ERROR | \
82 FLAGS_PROTECTION_ERROR)
85#if (XSNOR_USE_WSPI == TRUE) || defined(__DOXYGEN__)
230static bool n25q_find_id(
const uint8_t *set,
size_t size, uint8_t element) {
233 for (i = 0; i < size; i++) {
234 if (set[i] == element) {
250 1U, &self->config->buffers->databuf[0]);
265#if (XSNOR_USE_WSPI == TRUE) || defined(__DOXYGEN__)
274 1, &self->config->buffers->databuf[0]);
293 switch (self->config->bus_type) {
309 1, &self->config->buffers->databuf[0]);
319 1, &self->config->buffers->databuf[0]);
354 wspiReceive(self->config->bus.wspi.drv, &cmd, 3U, buf);
389 self->descriptor.page_size = 256U;
390 self->descriptor.sectors_count = 0U;
391 self->descriptor.sectors = NULL;
392 self->descriptor.sectors_size = 0U;
393 self->descriptor.address = 0U;
394 self->descriptor.size = 0U;
428#if XSNOR_USE_WSPI == TRUE
431 self->commands = NULL;
434 self->commands = &
cmd1l;
437 self->commands = &
cmd2l;
440 self->commands = &
cmd4l;
444 self->commands = NULL;
449#if XSNOR_USE_BOTH == TRUE
452#if XSNOR_USE_SPI == TRUE
474#if XSNOR_USE_BOTH == TRUE
477#if XSNOR_USE_WSPI == TRUE
571 self->descriptor.sectors_size = 0x00001000U;
574 self->descriptor.sectors_size = 0x00010000U;
576 self->descriptor.sectors_count = (1U << (size_t)config->
buffers->
databuf[2]) / self->descriptor.sectors_size;
577 self->descriptor.size = (size_t)self->descriptor.sectors_count * self->descriptor.sectors_size;
628 size_t chunk = (size_t)(((offset |
PAGE_MASK) + 1U) - offset);
715 1, &self->config->buffers->databuf[0]);
758 offset = (
flash_offset_t)(sector * self->descriptor.sectors_size);
759 n = self->descriptor.sectors_size;
767 for (p = &self->config->buffers->databuf[0];
794#if XSNOR_USE_BOTH == TRUE
800#if XSNOR_USE_WSPI == FALSE
823 switch (self->config->bus_type) {
861#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_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 FLAGS_ERASE_SUSPEND
static void n25q_reset_memory(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().
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_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_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