Prusa MINI Firmware overview
w25x.h File Reference
#include <inttypes.h>

Go to the source code of this file.

Macros

#define W25X_STATUS_BUSY   0x01
 
#define W25X_STATUS_WEL   0x02
 
#define W25X_STATUS_BP0   0x04
 
#define W25X_STATUS_BP1   0x08
 
#define W25X_STATUS_TB   0x20
 
#define W25X_STATUS_SRP   0x80
 
#define W25X_SPI_ENTER()
 

Functions

int8_t w25x_init (void)
 
void w25x_enable_wr (void)
 
void w25x_disable_wr (void)
 
uint8_t w25x_rd_status_reg (void)
 
void w25x_wr_status_reg (uint8_t val)
 
void w25x_rd_data (uint32_t addr, uint8_t *data, uint16_t cnt)
 
void w25x_page_program (uint32_t addr, uint8_t *data, uint16_t cnt)
 
void w25x_page_program_P (uint32_t addr, uint8_t *data, uint16_t cnt)
 
void w25x_sector_erase (uint32_t addr)
 
void w25x_block32_erase (uint32_t addr)
 
void w25x_block64_erase (uint32_t addr)
 
void w25x_chip_erase (void)
 
void w25x_rd_uid (uint8_t *uid)
 
void w25x_wait_busy (void)
 

Macro Definition Documentation

◆ W25X_STATUS_BUSY

#define W25X_STATUS_BUSY   0x01

◆ W25X_STATUS_WEL

#define W25X_STATUS_WEL   0x02

◆ W25X_STATUS_BP0

#define W25X_STATUS_BP0   0x04

◆ W25X_STATUS_BP1

#define W25X_STATUS_BP1   0x08

◆ W25X_STATUS_TB

#define W25X_STATUS_TB   0x20

◆ W25X_STATUS_SRP

#define W25X_STATUS_SRP   0x80

◆ W25X_SPI_ENTER

#define W25X_SPI_ENTER ( )

Function Documentation

◆ w25x_init()

int8_t w25x_init ( void  )
57  {
58  //PIN_OUT(W25X20CL_PIN_CS);
59  _CS_HIGH();
61  if (!w25x_mfrid_devid())
62  return 0;
63  return 1;
64 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ w25x_enable_wr()

void w25x_enable_wr ( void  )
66  {
67  _CS_LOW();
68  _SPI_TX(_CMD_ENABLE_WR); // send command 0x06
69  _CS_HIGH();
70 }

◆ w25x_disable_wr()

void w25x_disable_wr ( void  )
72  {
73  _CS_LOW();
74  _SPI_TX(_CMD_DISABLE_WR); // send command 0x04
75  _CS_HIGH();
76 }

◆ w25x_rd_status_reg()

uint8_t w25x_rd_status_reg ( void  )
78  {
79  _CS_LOW();
80  _SPI_TX(_CMD_RD_STATUS_REG); // send command 0x90
81  uint8_t val = _SPI_RX(); // receive value
82  _CS_HIGH();
83  return val;
84 }
Here is the caller graph for this function:

◆ w25x_wr_status_reg()

void w25x_wr_status_reg ( uint8_t  val)
86  {
87  _CS_LOW();
88  _SPI_TX(_CMD_WR_STATUS_REG); // send command 0x90
89  _SPI_TX(val); // send value
90  _CS_HIGH();
91 }

◆ w25x_rd_data()

void w25x_rd_data ( uint32_t  addr,
uint8_t data,
uint16_t  cnt 
)
93  {
94  _CS_LOW();
95  _SPI_TX(_CMD_RD_DATA); // send command 0x03
96  _SPI_TX(((uint8_t *)&addr)[2]); // send addr bits 16..23
97  _SPI_TX(((uint8_t *)&addr)[1]); // send addr bits 8..15
98  _SPI_TX(((uint8_t *)&addr)[0]); // send addr bits 0..7
99  while (cnt--) // receive data
100  *(data++) = _SPI_RX();
101  _CS_HIGH();
102 }

◆ w25x_page_program()

void w25x_page_program ( uint32_t  addr,
uint8_t data,
uint16_t  cnt 
)
104  {
105  _CS_LOW();
106  _SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
107  _SPI_TX(((uint8_t *)&addr)[2]); // send addr bits 16..23
108  _SPI_TX(((uint8_t *)&addr)[1]); // send addr bits 8..15
109  _SPI_TX(((uint8_t *)&addr)[0]); // send addr bits 0..7
110  while (cnt--) // send data
111  _SPI_TX(*(data++));
112  _CS_HIGH();
113 }

◆ w25x_page_program_P()

void w25x_page_program_P ( uint32_t  addr,
uint8_t data,
uint16_t  cnt 
)
115  {
116  _CS_LOW();
117  _SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
118  _SPI_TX(((uint8_t *)&addr)[2]); // send addr bits 16..23
119  _SPI_TX(((uint8_t *)&addr)[1]); // send addr bits 8..15
120  _SPI_TX(((uint8_t *)&addr)[0]); // send addr bits 0..7
121  while (cnt--) // send data
122  _SPI_TX(*(data++));
123  _CS_HIGH();
124 }

◆ w25x_sector_erase()

void w25x_sector_erase ( uint32_t  addr)
135  {
136  return w25x_erase(_CMD_SECTOR_ERASE, addr);
137 }
Here is the call graph for this function:

◆ w25x_block32_erase()

void w25x_block32_erase ( uint32_t  addr)
139  {
140  return w25x_erase(_CMD_BLOCK32_ERASE, addr);
141 }
Here is the call graph for this function:

◆ w25x_block64_erase()

void w25x_block64_erase ( uint32_t  addr)
143  {
144  return w25x_erase(_CMD_BLOCK64_ERASE, addr);
145 }
Here is the call graph for this function:

◆ w25x_chip_erase()

void w25x_chip_erase ( void  )
147  {
148  _CS_LOW();
149  _SPI_TX(_CMD_CHIP_ERASE); // send command 0xc7
150  _CS_HIGH();
151 }

◆ w25x_rd_uid()

void w25x_rd_uid ( uint8_t uid)
153  {
154  _CS_LOW();
155  _SPI_TX(_CMD_RD_UID); // send command 0x4b
156  uint8_t cnt = 4; // 4 dummy bytes
157  while (cnt--) // receive dummy bytes
158  _SPI_RX();
159  cnt = 8; // 8 bytes UID
160  while (cnt--) // receive UID
161  uid[7 - cnt] = _SPI_RX();
162  _CS_HIGH();
163 }

◆ w25x_wait_busy()

void w25x_wait_busy ( void  )
177  {
179  ;
180 }
Here is the call graph for this function:
_CMD_PAGE_PROGRAM
#define _CMD_PAGE_PROGRAM
Definition: w25x.c:26
_CMD_RD_UID
#define _CMD_RD_UID
Definition: w25x.c:37
_CMD_RD_STATUS_REG
#define _CMD_RD_STATUS_REG
Definition: w25x.c:20
_SPI_RX
#define _SPI_RX()
Definition: w25x.c:45
data
uint8_t data[8]
Definition: masstorage.h:49
w25x_mfrid_devid
int w25x_mfrid_devid(void)
Definition: w25x.c:165
_CMD_WR_STATUS_REG
#define _CMD_WR_STATUS_REG
Definition: w25x.c:21
W25X_SPI_ENTER
#define W25X_SPI_ENTER()
Definition: w25x.h:14
w25x_erase
void w25x_erase(uint8_t cmd, uint32_t addr)
Definition: w25x.c:126
_CMD_BLOCK64_ERASE
#define _CMD_BLOCK64_ERASE
Definition: w25x.c:29
_CMD_CHIP_ERASE
#define _CMD_CHIP_ERASE
Definition: w25x.c:30
w25x_rd_status_reg
uint8_t w25x_rd_status_reg(void)
Definition: w25x.c:78
_CS_HIGH
#define _CS_HIGH()
Definition: w25x.c:40
uint8_t
const uint8_t[]
Definition: 404_html.c:3
W25X_STATUS_BUSY
#define W25X_STATUS_BUSY
Definition: w25x.h:7
_CMD_ENABLE_WR
#define _CMD_ENABLE_WR
Definition: w25x.c:17
_CMD_BLOCK32_ERASE
#define _CMD_BLOCK32_ERASE
Definition: w25x.c:28
_CS_LOW
#define _CS_LOW()
Definition: w25x.c:39
_CMD_DISABLE_WR
#define _CMD_DISABLE_WR
Definition: w25x.c:19
_CMD_SECTOR_ERASE
#define _CMD_SECTOR_ERASE
Definition: w25x.c:27
_SPI_TX
#define _SPI_TX(b)
Definition: w25x.c:44
_CMD_RD_DATA
#define _CMD_RD_DATA
Definition: w25x.c:22