MCPcopy Create free account
hub / github.com/PaulStoffregen/SerialFlash / read

Method read

SerialFlashChip.cpp:81–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void SerialFlashChip::read(uint32_t addr, void *buf, uint32_t len)
82{
83 uint8_t *p = (uint8_t *)buf;
84 uint8_t b, f, status, cmd;
85
86 memset(p, 0, len);
87 f = flags;
88 SPIPORT.beginTransaction(SPICONFIG);
89 b = busy;
90 if (b) {
91 // read status register ... chip may no longer be busy
92 CSASSERT();
93 if (flags & FLAG_STATUS_CMD70) {
94 SPIPORT.transfer(0x70);
95 status = SPIPORT.transfer(0);
96 if ((status & 0x80)) b = 0;
97 } else {
98 SPIPORT.transfer(0x05);
99 status = SPIPORT.transfer(0);
100 if (!(status & 1)) b = 0;
101 }
102 CSRELEASE();
103 if (b == 0) {
104 // chip is no longer busy :-)
105 busy = 0;
106 } else if (b < 3) {
107 // TODO: this may not work on Spansion chips
108 // which apparently have 2 different suspend
109 // commands, for program vs erase
110 CSASSERT();
111 SPIPORT.transfer(0x06); // write enable (Micron req'd)
112 CSRELEASE();
113 delayMicroseconds(1);
114 cmd = 0x75; //Suspend program/erase for almost all chips
115 // but Spansion just has to be different for program suspend!
116 if ((f & FLAG_DIFF_SUSPEND) && (b == 1)) cmd = 0x85;
117 CSASSERT();
118 SPIPORT.transfer(cmd); // Suspend command
119 CSRELEASE();
120 if (f & FLAG_STATUS_CMD70) {
121 // Micron chips don't actually suspend until flags read
122 CSASSERT();
123 SPIPORT.transfer(0x70);
124 do {
125 status = SPIPORT.transfer(0);
126 } while (!(status & 0x80));
127 CSRELEASE();
128 } else {
129 CSASSERT();
130 SPIPORT.transfer(0x05);
131 do {
132 status = SPIPORT.transfer(0);
133 } while ((status & 0x01));
134 CSRELEASE();
135 }
136 } else {
137 // chip is busy with an operation that can not suspend
138 SPIPORT.endTransaction(); // is this a good idea?

Callers 9

check_signatureFunction · 0.45
filename_compareFunction · 0.45
openMethod · 0.45
removeMethod · 0.45
string_lengthFunction · 0.45
createMethod · 0.45
readdirMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected