Skip to content

Commit 84969aa

Browse files
committed
Fix file write() for len > 255
1 parent 844a00e commit 84969aa

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/utility/spi_drv.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,22 @@ int SpiDrv::waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, u
449449
return 1;
450450
}
451451

452+
void SpiDrv::sendParamNoLen(uint8_t* param, size_t param_len, uint8_t lastParam)
453+
{
454+
int i = 0;
455+
// Send Spi paramLen
456+
sendParamLen8(0);
457+
458+
// Send Spi param data
459+
for (i=0; i<param_len; ++i)
460+
{
461+
spiTransfer(param[i]);
462+
}
463+
464+
// if lastParam==1 Send Spi END CMD
465+
if (lastParam == 1)
466+
spiTransfer(END_CMD);
467+
}
452468

453469
void SpiDrv::sendParam(uint8_t* param, uint8_t param_len, uint8_t lastParam)
454470
{

src/utility/spi_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class SpiDrv
8585

8686
static void sendParam(uint8_t* param, uint8_t param_len, uint8_t lastParam = NO_LAST_PARAM);
8787

88+
static void sendParamNoLen(uint8_t* param, size_t param_len, uint8_t lastParam = NO_LAST_PARAM);
89+
8890
static void sendParamLen8(uint8_t param_len);
8991

9092
static void sendParamLen16(uint16_t param_len);

src/utility/wifi_drv.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,20 +1110,25 @@ int8_t WiFiDrv::downloadFile(const char* url, uint8_t url_len, const char *filen
11101110
return _data;
11111111
}
11121112

1113-
int8_t WiFiDrv::fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, uint8_t len)
1113+
int8_t WiFiDrv::fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t len)
11141114
{
11151115
WAIT_FOR_SLAVE_SELECT();
11161116
// Send Command
1117-
SpiDrv::sendCmd(operation, PARAM_NUMS_3);
1117+
uint8_t numParams = PARAM_NUMS_3;
1118+
if (operation == WRITE_FILE) {
1119+
numParams = PARAM_NUMS_4;
1120+
}
1121+
1122+
SpiDrv::sendCmd(operation, numParams);
11181123
SpiDrv::sendParam((uint8_t*)&offset, sizeof(offset), NO_LAST_PARAM);
11191124
SpiDrv::sendParam((uint8_t*)&len, sizeof(len), NO_LAST_PARAM);
11201125
SpiDrv::sendParam((uint8_t*)filename, filename_len, (operation == WRITE_FILE) ? NO_LAST_PARAM : LAST_PARAM);
11211126
if (operation == WRITE_FILE) {
1122-
SpiDrv::sendParam((uint8_t*)buffer, len, LAST_PARAM);
1127+
SpiDrv::sendParamNoLen((uint8_t*)buffer, len, LAST_PARAM);
11231128
}
11241129

11251130
// pad to multiple of 4
1126-
int commandSize = 7 + sizeof(offset) + sizeof(len) + filename_len;
1131+
int commandSize = 4 + numParams + sizeof(offset) + sizeof(len) + filename_len;
11271132
while (commandSize % 4) {
11281133
SpiDrv::readChar();
11291134
commandSize++;

src/utility/wifi_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class WiFiDrv
288288

289289
static int8_t downloadFile(const char* url, uint8_t url_len, const char *filename, uint8_t filename_len);
290290

291-
static int8_t fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, uint8_t len);
291+
static int8_t fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t len);
292292

293293
static int8_t readFile(const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t buffer_len) {
294294
return fileOperation(READ_FILE, filename, filename_len, offset, buffer, buffer_len);

0 commit comments

Comments
 (0)