ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
w25q.c File Reference

W25Q serial NOR flash driver (see w25q.h). More...

#include "w25q.h"
#include <string.h>
Include dependency graph for w25q.c:

Go to the source code of this file.

Macros

#define CMD_WREN   0x06u
 
#define CMD_RDSR1   0x05u
 
#define CMD_READ   0x03u /* up to 50 MHz; the binding runs below that */
 
#define CMD_PP   0x02u
 
#define CMD_SE   0x20u /* 4 KB */
 
#define CMD_CE   0xC7u
 
#define CMD_JEDEC   0x9Fu
 
#define CMD_RELEASE_PD   0xABu
 
#define SR1_BUSY   0x01u
 
#define SR1_WEL   0x02u
 
#define T_PP_MS   3u /* page program max */
 
#define T_SE_MS   400u /* sector erase max */
 
#define T_CE_MS   200000u /* chip erase max */
 

Functions

static int cmd1 (w25q_t *d, uint8_t c)
 
static int status (w25q_t *d, uint8_t *sr)
 
static int wait_ready (w25q_t *d, uint32_t max_ms)
 
static int write_enable (w25q_t *d)
 
static void a24 (uint8_t *b, uint8_t cmd, uint32_t a)
 
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_read (w25q_t *d, uint32_t addr, void *buf, uint32_t n)
 
int w25q_prog (w25q_t *d, uint32_t addr, const void *buf, uint32_t n)
 inside one page
 
int w25q_erase_sector (w25q_t *d, uint32_t addr)
 4 KB, waits (≤ 400 ms)
 
int w25q_erase_chip (w25q_t *d)
 waits (≤ 200 s)
 
int w25q_lf_read (void *ctx, uint32_t a, void *b, uint32_t n)
 
int w25q_lf_prog (void *ctx, uint32_t a, const void *b, uint32_t n)
 
int w25q_lf_erase (void *ctx, uint32_t a)
 

Detailed Description

W25Q serial NOR flash driver (see w25q.h).

Commands from the Winbond W25Q128JV datasheet (rev. F), 3-byte addressing.

Definition in file w25q.c.

Macro Definition Documentation

◆ CMD_WREN

#define CMD_WREN   0x06u

Definition at line 9 of file w25q.c.

◆ CMD_RDSR1

#define CMD_RDSR1   0x05u

Definition at line 10 of file w25q.c.

◆ CMD_READ

#define CMD_READ   0x03u /* up to 50 MHz; the binding runs below that */

Definition at line 11 of file w25q.c.

◆ CMD_PP

#define CMD_PP   0x02u

Definition at line 12 of file w25q.c.

◆ CMD_SE

#define CMD_SE   0x20u /* 4 KB */

Definition at line 13 of file w25q.c.

◆ CMD_CE

#define CMD_CE   0xC7u

Definition at line 14 of file w25q.c.

◆ CMD_JEDEC

#define CMD_JEDEC   0x9Fu

Definition at line 15 of file w25q.c.

◆ CMD_RELEASE_PD

#define CMD_RELEASE_PD   0xABu

Definition at line 16 of file w25q.c.

◆ SR1_BUSY

#define SR1_BUSY   0x01u

Definition at line 17 of file w25q.c.

◆ SR1_WEL

#define SR1_WEL   0x02u

Definition at line 18 of file w25q.c.

◆ T_PP_MS

#define T_PP_MS   3u /* page program max */

Definition at line 20 of file w25q.c.

◆ T_SE_MS

#define T_SE_MS   400u /* sector erase max */

Definition at line 21 of file w25q.c.

◆ T_CE_MS

#define T_CE_MS   200000u /* chip erase max */

Definition at line 22 of file w25q.c.

Function Documentation

◆ cmd1()

static int cmd1 ( w25q_t *  d,
uint8_t  c 
)
static

Definition at line 24 of file w25q.c.

References w25q_t::bus, w25q_bus_t::ctx, and w25q_bus_t::xfer.

Referenced by w25q_erase_chip(), w25q_init(), and write_enable().

Here is the caller graph for this function:

◆ status()

static int status ( w25q_t *  d,
uint8_t *  sr 
)
static

Definition at line 26 of file w25q.c.

References w25q_t::bus, CMD_RDSR1, w25q_bus_t::ctx, sr, and w25q_bus_t::xfer.

Referenced by wait_ready(), and write_enable().

Here is the caller graph for this function:

◆ wait_ready()

static int wait_ready ( w25q_t *  d,
uint32_t  max_ms 
)
static

Definition at line 33 of file w25q.c.

References w25q_t::bus, w25q_bus_t::delay_ms, w25q_bus_t::now_ms, sr, SR1_BUSY, and status().

Referenced by w25q_erase_chip(), w25q_erase_sector(), and w25q_prog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_enable()

static int write_enable ( w25q_t *  d)
static

Definition at line 46 of file w25q.c.

References cmd1(), CMD_WREN, sr, SR1_WEL, and status().

Referenced by w25q_erase_chip(), w25q_erase_sector(), and w25q_prog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ a24()

static void a24 ( uint8_t *  b,
uint8_t  cmd,
uint32_t  a 
)
static

Definition at line 54 of file w25q.c.

References b, and cmd().

Referenced by w25q_erase_sector(), w25q_prog(), and w25q_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w25q_init()

int w25q_init ( w25q_t *  d,
const w25q_bus_t *  bus 
)

reads the JEDEC id, releases power-down; 0 = a W25Q-compatible part

Definition at line 59 of file w25q.c.

References w25q_t::bus, w25q_t::cap, cmd1(), CMD_JEDEC, CMD_RELEASE_PD, w25q_bus_t::ctx, w25q_bus_t::delay_ms, w25q_t::mfr, w25q_t::size, w25q_t::type, and w25q_bus_t::xfer.

Here is the call graph for this function:

◆ w25q_read()

int w25q_read ( w25q_t *  d,
uint32_t  addr,
void *  buf,
uint32_t  n 
)

Definition at line 75 of file w25q.c.

References a24(), addr(), w25q_t::base, w25q_t::bus, CMD_READ, w25q_bus_t::ctx, n, w25q_t::size, and w25q_bus_t::xfer.

Referenced by w25q_lf_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w25q_prog()

int w25q_prog ( w25q_t *  d,
uint32_t  addr,
const void *  buf,
uint32_t  n 
)

inside one page

Definition at line 83 of file w25q.c.

References a24(), addr(), w25q_t::base, w25q_t::bus, CMD_PP, w25q_bus_t::ctx, n, w25q_t::size, T_PP_MS, wait_ready(), write_enable(), and w25q_bus_t::xfer_w.

Referenced by w25q_lf_prog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w25q_erase_sector()

int w25q_erase_sector ( w25q_t *  d,
uint32_t  addr 
)

4 KB, waits (≤ 400 ms)

Definition at line 94 of file w25q.c.

References a24(), addr(), w25q_t::base, w25q_t::bus, CMD_SE, w25q_bus_t::ctx, w25q_t::size, T_SE_MS, wait_ready(), write_enable(), and w25q_bus_t::xfer.

Referenced by w25q_lf_erase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w25q_erase_chip()

int w25q_erase_chip ( w25q_t *  d)

waits (≤ 200 s)

Definition at line 104 of file w25q.c.

References cmd1(), CMD_CE, T_CE_MS, wait_ready(), and write_enable().

Here is the call graph for this function:

◆ w25q_lf_read()

int w25q_lf_read ( void *  ctx,
uint32_t  a,
void *  b,
uint32_t  n 
)

Definition at line 111 of file w25q.c.

References b, n, and w25q_read().

Here is the call graph for this function:

◆ w25q_lf_prog()

int w25q_lf_prog ( void *  ctx,
uint32_t  a,
const void *  b,
uint32_t  n 
)

Definition at line 112 of file w25q.c.

References b, n, and w25q_prog().

Here is the call graph for this function:

◆ w25q_lf_erase()

int w25q_lf_erase ( void *  ctx,
uint32_t  a 
)

Definition at line 113 of file w25q.c.

References w25q_erase_sector().

Here is the call graph for this function: