W25Q128J Part Drivers API Documentation

This page documents the API of the W25Q128J Part Drivers.

An overview of the driver is also available here: main_doc .

Functions

Functions

int32_t w25q128j_io_init ( w25q128j_io_t * pio )

initialize the IO layer. This specific implementation does nothing.

Note

This function must be overridden (using codegen or otherwise) with a proper implementation).

Return values :

0 – (always succeeds)

w25q128j_status_t w25q128j_init ( w25q128j_obj_t * pobj , uint32_t dev_id )

Initializes the memory.

Parameters :
  • pobj – : W25Q128J part object pointer

  • id – : Configuration ID

Return values :

error – status

w25q128j_status_t w25q128j_deinit ( w25q128j_obj_t * pobj )

De-Initializes the memory.

Parameters :

pobj – : w25q128j part object pointer

Return values :

error – status

w25q128j_status_t w25q128j_reset ( w25q128j_obj_t * pobj )

Resets the flash memory.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_suspend ( w25q128j_obj_t * pobj )

Suspend erase block/sector or page program operation.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_resume ( w25q128j_obj_t * pobj )

Resume erase block/sector or page program operation.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_get_info ( const w25q128j_obj_t * pobj , w25q128j_info_t * p_info )

Gets Flash information.

Parameters :
  • pobj – : w25q128j part object pointer

  • p_info – : Pointer to information structure.

Return values :

error – status.

w25q128j_status_t w25q128j_get_status ( w25q128j_obj_t * pobj , w25q128j_status_t * p_status )

Reads current status of the flash memory.

Parameters :
  • pobj – : w25q128j part object pointer

  • p_status – : Pointer to store current memory status

Return values :

error – status.

w25q128j_status_t w25q128j_read_id ( w25q128j_obj_t * pobj , uint8_t * p_id )

Reads the w25q128j flash memory Manufacturer ID.

Parameters :
  • pobj – : W25Q128J part object pointer

  • p_id – : Pointer to store the part Manufacturer ID

Return values :

error – status

w25q128j_status_t w25q128j_read_jedec_id ( w25q128j_obj_t * pobj , uint8_t * p_id )

Reads the w25q128j flash memory JEDEC ID.

Parameters :
  • pobj – : W25Q128J part object pointer

  • p_jedec_id – : Pointer to store the part JEDEC ID

Return values :

error – status

w25q128j_status_t w25q128j_read_unique_id ( w25q128j_obj_t * pobj , uint8_t * p_id )

Reads the w25q128j flash memory unique ID. The unique ID is a factory-set read-only 64-bit number that is unique to each W25Q128J device.

Parameters :
  • pobj – : W25Q128J part object pointer

  • p_id – : Pointer to store the part unique ID

Return values :

error – status

w25q128j_status_t w25q128j_read_status_reg1 ( w25q128j_obj_t * pobj , uint8_t * p_value )

Reads the w25q128j status register1.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_value – : Pointer to status register1 value

Return values :

error – status

w25q128j_status_t w25q128j_read_status_reg2 ( w25q128j_obj_t * pobj , uint8_t * p_value )

Reads the w25q128j status register2.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_value – : Pointer to status register2 value

Return values :

error – status

w25q128j_status_t w25q128j_read_status_reg3 ( w25q128j_obj_t * pobj , uint8_t * p_value )

Reads the w25q128j status register3.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_value – : Pointer to status register3 value

Return values :

error – status

w25q128j_status_t w25q128j_write_status_reg1 ( w25q128j_obj_t * pobj , uint8_t value )

Writes the w25q128j status register1.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_value – : The 8-bits data we want to write into the status register1

Return values :

error – status

w25q128j_status_t w25q128j_write_status_reg2 ( w25q128j_obj_t * pobj , uint8_t value )

Writes the w25q128j status register2.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_value – : The 8-bits data we want to write into the status register2

Return values :

error – status

w25q128j_status_t w25q128j_write_status_reg3 ( w25q128j_obj_t * pobj , uint8_t value )

Writes the w25q128j status register3.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_value – : The 8-bits data we want to write into the status register2

Return values :

error – status

w25q128j_status_t w25q128j_write_enable ( w25q128j_obj_t * pobj )

Sets the Write Enable Latch (WEL) bit in the Status Register to a 1.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_write_disable ( w25q128j_obj_t * pobj )

Resets the Write Enable Latch (WEL) bit in the Status Register to a 0.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_read ( w25q128j_obj_t * pobj , uint8_t * p_data , uint32_t read_addr , uint32_t size_byte )

allows one or more data bytes to be sequentially read from the w25q128j flash memory.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_data – : Pointer to read data

  • read_addr – : Read start address

  • size_byte – : Size of data to read

Return values :

error – status

w25q128j_status_t w25q128j_fast_read ( w25q128j_obj_t * pobj , uint8_t * p_data , uint32_t read_addr , uint32_t size_byte )

allows one or more data bytes to be sequentially read from the w25q128j flash memory. The Fast Read instruction is similar to the Read Data instruction except that it can operate at the highest possible Clock frequency (133Mhz)

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_data – : Pointer to read data

  • read_addr – : Read start address

  • size_byte – : Size of data to read

Return values :

error – status

w25q128j_status_t w25q128j_write ( w25q128j_obj_t * pobj , const uint8_t * p_data , uint32_t write_addr , uint32_t size_byte )

Allows one or more data bytes to be sequentially written at previously erased (FFh) memory locations.

Parameters :
  • pobj – : Pointer to the part object structure

  • p_data – : Pointer to data to be written.

  • write_addr – : Write start address.

  • size_byte – : Size of data to write in bytes.

Return values :

error – status

w25q128j_status_t w25q128j_erase ( w25q128j_obj_t * pobj , uint32_t addr , w25q128j_erase_t size )

Erases the specified block of flash memory. W25Q128J supports 4K sector or 32K block or 64K erase commands.

Parameters :
  • pobj – : Part object pointer.

  • addr – : Sector/block Address to erase

  • size – : size configuration W25Q128J_ERASE_SECTOR (4K) or W25Q128J_ERASE_32K_BLOCK (32K) or W25Q128J_ERASE_64K_BLOCK (64K)

Return values :

error – status.

w25q128j_status_t w25q128j_erase_sectors ( w25q128j_obj_t * pobj , uint32_t erase_addr , uint32_t size_byte )

Erases sequentially one or multiple sectors (4K) from the W25Q128J NOR flash memory.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • erase_addr – : Start address of the data to be erased

  • size_byte – : Size of data to be erased in bytes .

Return values :

error – status

w25q128j_status_t w25q128j_chip_erase ( w25q128j_obj_t * pobj )

Erase full w25q128j chip.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_enter_power_down ( w25q128j_obj_t * pobj )

enter power down.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_exit_power_down ( w25q128j_obj_t * pobj )

exit power down.

Parameters :

pobj – : W25Q128J part Object Pointer

Return values :

error – status

w25q128j_status_t w25q128j_read_dma ( w25q128j_obj_t * pobj , uint8_t * p_data , uint32_t read_addr , uint32_t size_byte )

allows one or more data bytes to be sequentially read from the w25q128j physical memory using DMA.

Parameters :
  • pobj – : W25Q128J part Object Pointer

  • p_data – : Pointer to read data

  • read_addr – : Read start address

  • size_byte – : Size of data to read

Return values :

error – status

w25q128j_status_t w25q128j_write_dma ( w25q128j_obj_t * pobj , const uint8_t * p_data , uint32_t write_addr , uint32_t size_byte )

Allows one or more data bytes to be sequentially written at previously erased (FFh) memory locations using DMA.

Parameters :
  • pobj – : Pointer to the part object structure

  • p_data – : Pointer to data to be written.

  • write_addr – : Write start address.

  • size_byte – : Size of data to write in bytes.

Return values :

error – status

w25q128j_status_t w25q128j_register_read_cplt_callback ( w25q128j_obj_t * pobj , w25q128j_callback_t cb , void * arg )

Registers the read complete callback function.

Parameters :
  • pobj – : Pointer to part object

  • cb – : Pointer to the callback function

  • arg – : Pointer to the user data.

Return values :

error – status

w25q128j_status_t w25q128j_register_write_cplt_callback ( w25q128j_obj_t * pobj , w25q128j_callback_t cb , void * arg )

Registers the write complete callback function.

Parameters :
  • pobj – : Pointer to part object

  • cb – : Pointer to the callback function

  • arg – : Pointer to the user data

Return values :

error – status

w25q128j_async_write_phase_t w25q128j_get_async_write_phase ( w25q128j_obj_t * pobj )

Gets the current phase of the asynchronous write state machine.

Return values :

asynchronous – write phase

w25q128j_async_read_phase_t w25q128j_get_async_read_phase ( w25q128j_obj_t * pobj )

Gets the current phase of the asynchronous read state machine.

Return values :

asynchronous – read phase

Types

Enums

enum w25q128j_status_t

Enumeration defining the software error code.

Values:

enumerator W25Q128J_OK

Success Status

enumerator W25Q128J_ERROR

Error Status

enumerator W25Q128J_SUSPENDED

Program or Erase operation suspended

enumerator W25Q128J_BUSY

Memory Busy write or erase operation in progress

enum w25q128j_init_state_t

Enumeration defining the W25Q128J init state.

Values:

enumerator W25Q128J_INIT_NO

Instance is not initialized

enumerator W25Q128J_INIT_OK

Instance is initialized

enum w25q128j_erase_t

Enumeration defining the memory erase size.

Values:

enumerator W25Q128J_ERASE_SECTOR

4K size Sector erase

enumerator W25Q128J_ERASE_32K_BLOCK

32K size Block erase

enumerator W25Q128J_ERASE_64K_BLOCK

64K size Block erase

enum w25q128j_async_write_phase_t

Values:

enumerator W25Q128J_ASYNC_WRITE_IDLE

Idle state - No ongoing transfer

enumerator W25Q128J_ASYNC_WEL

Send the write enable cmd

enumerator W25Q128J_ASYNC_WRITE_CMD

Send the write page cmd

enumerator W25Q128J_ASYNC_WRITE_DATA

Send data to write

enum w25q128j_async_read_phase_t

Values:

enumerator W25Q128J_ASYNC_READ_IDLE

Idle state - No ongoing transfer

enumerator W25Q128J_ASYNC_READING

Read transfer ongoing

Typedefs

typedef struct w25q128j_obj_s w25q128j_obj_t
typedef void ( * w25q128j_callback_t ) ( w25q128j_obj_t * pobj , void * arg )
struct w25q128j_info_t

Structure defining the Flash Memory information.

Public Members

uint32_t flash_size

Size of the flash

uint32_t erase_block_64k_size

Size of blocks (64k) for the erase operation

uint32_t erase_block_64k_number

Number of blocks (64k) for the erase operation

uint32_t erase_block_32k_size

Size of blocks (32k) for the erase operation

uint32_t erase_block_32k_number

Number of blocks (32k) for the erase operation

uint32_t erase_sector_size

Size of sector for the erase operation

uint32_t erase_sector_number

Number of sectors for the erase operation

uint32_t prog_page_size

Size of pages for the program operation

uint32_t prog_pages_number

Number of pages for the program operation

struct w25q128j_io_t

Public Members

hal_spi_handle_t * phspi

SPI HAL handle for communication with the part

hal_gpio_t cs_port

Hardware chip select port

uint32_t cs_pin

Hardware chip select pin

uint32_t id

Instance ID

struct w25q128j_obj_s

Public Members

w25q128j_init_state_t is_initialized

Init state

w25q128j_io_t pio

IO interface

volatile uint32_t inhibit_callbacks

Used for multi-pages writes

w25q128j_callback_ctx_t rd_cb_ctx

Read Complete: Callback data

w25q128j_callback_ctx_t wr_cb_ctx

Write Complete: Callback data

w25q128j_async_read_phase_t rd_phase

Async write phase

w25q128j_async_write_phase_t wr_phase

Async read phase

uint32_t current_address

Current write address - async writes

const uint8_t * p_buff

Pointer to the write buffer - async writes

uint16_t first_page_size

First page size

uint16_t last_page_size

Last page size

uint8_t is_first_page

Used to check if it is the first page to write

Constants and macros

Defines

W25Q128J_SPI_POLL_TIMEOUT 1000U

Default SPI timeout (1s)

W25Q128J_CS_PIN_SET HAL_GPIO_PIN_SET

Select the W25Q128J memory

W25Q128J_CS_PIN_RESET HAL_GPIO_PIN_RESET

Deselect the W25Q128J memory

W25Q128J_MEM_ADDR_MASK1 0x00FF0000U

Memory address mask 1

W25Q128J_MEM_ADDR_MASK2 0x0000FF00U

Memory address mask 2

W25Q128J_MEM_ADDR_MASK3 0x000000FFU

Memory address mask 3

W25Q128J_FLASH_SIZE 0x1000000U /* 128 MBits => 16MBytes */

W25Q128J Configuration.

W25Q128J_BLOCK_SIZE 0x10000U /* 256 blocks of 64KBytes */
W25Q128J_SUBBLOCK_SIZE 0x8000U /* 512 blocks of 32 KBytes */
W25Q128J_SECTOR_SIZE 0x1000U /* 4096 sectors of 4kBytes */
W25Q128J_PAGE_SIZE 0x100U /* 65536 pages of 256 bytes */
W25Q128J_DUMMY_BYTE 0x00U

Dummy byte value

W25Q128J_NUM_OF_BLOCK ( W25Q128J_FLASH_SIZE / W25Q128J_BLOCK_SIZE )
W25Q128J_NUM_PAGE_PER_BLOCK ( W25Q128J_BLOCK_SIZE / W25Q128J_PAGE_SIZE )

Total number of pages => 65536

W25Q128J_PAGE_COUNT ( W25Q128J_NUM_PAGE_PER_BLOCK * W25Q128J_NUM_OF_BLOCK )
W25Q128J_CHIP_ERASE_MAX_TIME 200000

Chip erase maximum time

W25Q128J_BLOCK_ERASE_MAX_TIME 2000

Block erase maximum time

W25Q128J_SUBBLOCK_ERASE_MAX_TIME 1600

Sub-block erase maximum time

W25Q128J_SECTOR_ERASE_MAX_TIME 400

Sector erase maximum time

W25Q128J_RESET_ENABLE_CMD 0x66U

Reset enable

W25Q128J_RESET_MEMORY_CMD 0x99U

Reset memory

W25Q128J_READ_ID_CMD 0x90U

Read ID

W25Q128J_READ_ID_DUAL_CMD 0x92U

Read ID dual

W25Q128J_READ_ID_QUAD_CMD 0x94U

Read ID quad

W25Q128J_READ_JEDEC_ID_CMD 0x9FU

Read JDEC ID

W25Q128J_READ_UNIQUE_ID_CMD 0x4BU

Read UNIQUE ID

W25Q128J_READ_DATA_CMD 0x03U

Read data

W25Q128J_FAST_READ_CMD 0x0BU

Fast read

W25Q128J_FAST_READ_DUAL_OUT_CMD 0x3BU

Fast read dual output

W25Q128J_FAST_READ_DUAL_INOUT_CMD 0xBBU

Fast read dual I/O

W25Q128J_FAST_READ_QUAD_OUT_CMD 0x6BU

Fast read quad output

W25Q128J_FAST_READ_QUAD_INOUT_CMD 0xEBU

Fast read quad I/O

W25Q128J_WRITE_ENABLE_CMD 0x06U

Write enable

W25Q128J_VOL_SR_WRITE_ENABLE_CMD 0x50U

Volatile status register write enable

W25Q128J_WRITE_DISABLE_CMD 0x04U
W25Q128J_READ_STATUS_REG1_CMD 0x05U

Read status register 1

W25Q128J_READ_STATUS_REG2_CMD 0x35U

Read status register 2

W25Q128J_READ_STATUS_REG3_CMD 0x15U

Read status register 3

W25Q128J_WRITE_STATUS_REG1_CMD 0x01U

Write status register 1

W25Q128J_WRITE_STATUS_REG2_CMD 0x31U

Write status register 2

W25Q128J_WRITE_STATUS_REG3_CMD 0x11U

Write status register 3

W25Q128J_READ_SFDP_REG_CMD 0x5AU

Read SFDP register

W25Q128J_READ_BLOCK_SECTOR_LOCK 0x3DU

Read block sector lock

W25Q128J_ERASE_SECURITY_REG_CMD 0x44U

Erase security register

W25Q128J_PROG_SECURITY_REG_CMD 0x42U

Program security register

W25Q128J_READ_SECURITY_REG_CMD 0x48U

Read security register

W25Q128J_PAGE_PROG_CMD 0x02U

Page program

W25Q128J_QUAD_PAGE_PROG_CMD 0x32U

Quad page program

W25Q128J_SECTOR_ERASE_CMD 0x20U

Sector erase

W25Q128J_BLOCK_ERASE_32K_CMD 0x52U

Bock erase 32K

W25Q128J_BLOCK_ERASE_64K_CMD 0xD8U

Bock erase 64K

W25Q128J_CHIP_ERASE_CMD 0xC7U

Chip erase

W25Q128J_CHIP_ERASE_CMD_1 0x60U

Chip erase

W25Q128J_ERASE_PROG_SUSPEND_CMD 0x75U

Erase program suspend

W25Q128J_ERASE_PROG_RESUME_CMD 0x7AU

Erase program resume

W25Q128J_POWER_DOWN_CMD 0xB9U

Power down

W25Q128J_RELEASE_POWER_DOWN_CMD 0xABU

Release power down

W25Q128J_SET_BURST_WRAP_CMD 0x77U

Set burst wrap

W25Q128J_INDIV_BLOCK_SECTOR_LOCK 0x36U

Individual block sector lock

W25Q128J_INDIV_BLOCK_SECTOR_UNLOCK 0x39U

Individual block sector unlock

W25Q128J_GLOBAL_BLOCK_SECTOR_LOCK 0x7EU

Global block sector lock

W25Q128J_GLOBAL_BLOCK_SECTOR_UNLOCK 0x98U

Global block sector unlock

W25Q128J_READ_ID_CMD_SIZE 4U

Read ID command size

W25Q128J_ID_SIZE 2U

ID size

W25Q128J_READ_JDEC_ID_CMD_SIZE 1U

Read JDEC ID command size

W25Q128J_JDEC_ID_SIZE 4U

JDEC ID size

W25Q128J_UNIQUE_ID_CMD_SIZE 1U

Unique ID command size

W25Q128J_UNIQUE_ID_SIZE 8U

Unique ID size

W25Q128J_RESET_ENABLE_CMD_SIZE 1U

Reset enable command size

W25Q128J_RESET_CMD_SIZE 1U

Reset command size

W25Q128J_SUSPEND_CMD_SIZE 1U

Suspend command size

W25Q128J_RESUME_CMD_SIZE 1U

Resume command size

W25Q128J_WRITE_ENABLE_CMD_SIZE 1U

Write enable command size

W25Q128J_WRITE_DISABLE_CMD_SIZE 1U

Write disable command size

W25Q128J_READ_STATUS_REG_CMD_SIZE 1U

Read status register command size

W25Q128J_STATUS_REG_DATA_SIZE 1U

Status register data size

W25Q128J_WRITE_STATUS_REG_CMD_SIZE 2U

Write status register command size

W25Q128J_BLOCK_ERASE_CMD_SIZE 4U

Block erase command size

W25Q128J_CHIP_ERASE_CMD_SIZE 1U

Chip erase command size

W25Q128J_READ_DATA_CMD_SIZE 4U

Read data command size

W25Q128J_FAST_DATA_CMD_SIZE 5U

Fast read command size

W25Q128J_PAGE_PROGRAM_CMD_SIZE 4U

Page program command size

W25Q128J_ENTER_POWER_DOWN_CMD_SIZE 1U

Enter power down command size

W25Q128J_EXIT_POWER_DOWN_CMD_SIZE 1U

Exit power down command size

W25Q128J_SR1_BUSY 0x01U

Erase/Write in progress

W25Q128J_SR1_WEL 0x02U

Write enable latch

W25Q128J_SR1_BP 0x1CU

Block protected bits

W25Q128J_SR1_TB 0x20U

Top/Bottom protect

W25Q128J_SR1_SEC 0x40U

Sector protect

W25Q128J_SR1_PROTECT_ALL W25Q128J_SR1_BP

Enable protection

W25Q128J_SR1_WRITE_PROTECTION_DISABLE 0x00U

Disable protection

W25Q128J_SR2_QE_DIS 0x00U

Quad Disable

W25Q128J_SR2_SRL 0x01U

Status Register Lock

W25Q128J_SR2_QE 0x02U

Quad Enable

W25Q128J_SR2_LB 0x3CU

Security Register Lock bits

W25Q128J_SR2_CMP 0x40U

Complement protect

W25Q128J_SR2_SUS 0x80U

Suspend Status

W25Q128J_SR3_WPS 0x04U

Write Protect Selection

W25Q128J_SR3_DRV 0x60U

Output Driver Strength