10#define CMD_RDSR1 0x05u
15#define CMD_JEDEC 0x9Fu
16#define CMD_RELEASE_PD 0xABu
22#define T_CE_MS 200000u
36 for (uint32_t k = 0;; ++k) {
41 if (!d->
bus.
now_ms && k > max_ms * 100u)
return -2;
54static void a24(uint8_t *
b, uint8_t
cmd, uint32_t a)
56 b[0] =
cmd;
b[1] = (uint8_t)(a >> 16);
b[2] = (uint8_t)(a >> 8);
b[3] = (uint8_t)a;
61 memset(d, 0,
sizeof *d);
65 uint8_t
id[3] = { 0, 0, 0 };
68 d->
mfr =
id[0]; d->
type =
id[1]; d->
cap =
id[2];
70 if (d->
mfr != 0xEFu || (d->
type != 0x40u && d->
type != 0x70u) || d->
cap < 0x14u || d->
cap > 0x18u)
return -2;
85 if (
n == 0u)
return 0;
90 if (d->
bus.
xfer_w(d->
bus.
ctx, c, 4, (
const uint8_t *)buf,
n) != 0)
return -1;
static uint32_t addr(uint16_t sect)
static void cmd(uint8_t port, const uint8_t *c, uint32_t n, uint8_t armed, uint32_t now)
int(* xfer)(void *ctx, const uint8_t *tx, uint32_t ntx, uint8_t *rx, uint32_t nrx)
CS low, write tx (ntx bytes), read rx (nrx bytes), CS high; 0 = ok.
int(* xfer_w)(void *ctx, const uint8_t *tx, uint32_t ntx, const uint8_t *data, uint32_t n)
same, with a second write buffer after tx (page program data)
void(* delay_ms)(uint32_t ms)
yields the task while the chip is busy
uint32_t base
start of the log area
uint32_t size
bytes, from the JEDEC id
int w25q_init(w25q_t *d, const w25q_bus_t *bus)
reads the JEDEC id, releases power-down; 0 = a W25Q-compatible part
int w25q_lf_erase(void *ctx, uint32_t a)
static void a24(uint8_t *b, uint8_t cmd, uint32_t a)
int w25q_lf_read(void *ctx, uint32_t a, void *b, uint32_t n)
int w25q_prog(w25q_t *d, uint32_t addr, const void *buf, uint32_t n)
inside one page
int w25q_erase_chip(w25q_t *d)
waits (≤ 200 s)
int w25q_read(w25q_t *d, uint32_t addr, void *buf, uint32_t n)
static int wait_ready(w25q_t *d, uint32_t max_ms)
static int cmd1(w25q_t *d, uint8_t c)
static int write_enable(w25q_t *d)
int w25q_lf_prog(void *ctx, uint32_t a, const void *b, uint32_t n)
static int status(w25q_t *d, uint8_t *sr)
int w25q_erase_sector(w25q_t *d, uint32_t addr)
4 KB, waits (≤ 400 ms)
Winbond W25Q serial NOR flash (W25Q128JV on the ACwing FC: 16 MB, 4 KB sectors, 256-byte pages,...