Skip to content

Commit

Permalink
support fast read
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidegit authored Jan 5, 2024
1 parent 0efaa1f commit 7df6227
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sfud/inc/sfud_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#define SFUD_USING_SFDP

#define SFUD_USING_FAST_READ

#define SFUD_USING_FLASH_INFO_TABLE

enum {
Expand Down
13 changes: 13 additions & 0 deletions sfud/inc/sfud_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ if (!(EXPR)) \
#define SFUD_CMD_READ_DATA 0x03
#endif

#ifndef SFUD_CMD_FAST_READ_DATA
#define SFUD_CMD_FAST_READ_DATA 0x0B
#endif

#ifndef SFUD_CMD_DUAL_OUTPUT_READ_DATA
#define SFUD_CMD_DUAL_OUTPUT_READ_DATA 0x3B
#endif
Expand Down Expand Up @@ -175,6 +179,15 @@ if (!(EXPR)) \
#define SFUD_DUMMY_DATA 0xFF
#endif

/* dummy data count for fast read data and etc */
#ifndef SFUD_READ_DUMMY_BYTE_CNT
#ifdef SFUD_USING_FAST_READ
#define SFUD_READ_DUMMY_BYTE_CNT 1
#else
#define SFUD_READ_DUMMY_BYTE_CNT 0
#endif
#endif

/* maximum number of erase type support on JESD216 (V1.0) */
#define SFUD_SFDP_ERASE_TYPE_MAX_NUM 4

Expand Down
12 changes: 11 additions & 1 deletion sfud/src/sfud.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@ static sfud_err software_init(const sfud_flash *flash) {
sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data) {
sfud_err result = SFUD_SUCCESS;
const sfud_spi *spi = &flash->spi;
uint8_t cmd_data[5], cmd_size;
uint8_t cmd_data[5 + SFUD_READ_DUMMY_BYTE_CNT];
uint8_t cmd_size;
uint8_t i;

SFUD_ASSERT(flash);
SFUD_ASSERT(data);
Expand All @@ -429,9 +431,17 @@ sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t
} else
#endif
{
#ifdef SFUD_USING_FAST_READ
cmd_data[0] = SFUD_CMD_FAST_READ_DATA;
#else
cmd_data[0] = SFUD_CMD_READ_DATA;
#endif
make_address_byte_array(flash, addr, &cmd_data[1]);
cmd_size = flash->addr_in_4_byte ? 5 : 4;
for (i = 0; i < SFUD_READ_DUMMY_BYTE_CNT; i++) {
cmd_data[cmd_size] = SFUD_DUMMY_DATA;
cmd_size++;
}
result = spi->wr(spi, cmd_data, cmd_size, data, size);
}
}
Expand Down

0 comments on commit 7df6227

Please sign in to comment.