Skip to content

Commit af203f3

Browse files
author
Varga Viktor
committed
Fix for espressif#723, SPI communication problem described in "Improve SPI interface (GIT8266O-397)"
1 parent d11de77 commit af203f3

File tree

1 file changed

+6
-9
lines changed
  • components/esp8266/driver

1 file changed

+6
-9
lines changed

components/esp8266/driver/spi.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,8 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_master_trans(spi_host_t host, spi_
489489
SPI[host]->data_buf[y] = trans->mosi[y];
490490
}
491491
} else {
492-
ESP_LOGW(TAG,"Using unaligned data may reduce transmission efficiency");
493-
memset(spi_object[host]->buf, 0, sizeof(uint32_t) * 16);
494-
memcpy(spi_object[host]->buf, trans->mosi, trans->bits.mosi / 8 + (trans->bits.mosi % 8) ? 1 : 0);
492+
memcpy(spi_object[host]->buf, trans->mosi, trans->bits.mosi / 8 + ((trans->bits.mosi % 8) ? 1 : 0));
493+
495494
for (x = 0; x < trans->bits.mosi; x += 32) {
496495
y = x / 32;
497496
SPI[host]->data_buf[y] = spi_object[host]->buf[y];
@@ -522,19 +521,17 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_master_trans(spi_host_t host, spi_
522521
if (trans->bits.miso && trans->miso) {
523522
while (SPI[host]->cmd.usr);
524523

525-
if ((uint32_t)(trans->miso) % 4 == 0) {
524+
if ((uint32_t)(trans->miso) % 4 == 0 && trans->bits.miso % 32 == 0) {
526525
for (x = 0; x < trans->bits.miso; x += 32) {
527526
y = x / 32;
528527
trans->miso[y] = SPI[host]->data_buf[y];
529528
}
530529
} else {
531-
ESP_LOGW(TAG,"Using unaligned data may reduce transmission efficiency");
532-
memset(spi_object[host]->buf, 0, sizeof(uint32_t) * 16);
533530
for (x = 0; x < trans->bits.miso; x += 32) {
534531
y = x / 32;
535532
spi_object[host]->buf[y] = SPI[host]->data_buf[y];
536533
}
537-
memcpy(trans->miso, spi_object[host]->buf, trans->bits.miso / 8 + (trans->bits.miso % 8) ? 1 : 0);
534+
memcpy(trans->miso, spi_object[host]->buf, trans->bits.miso / 8 + ((trans->bits.miso % 8) ? 1 : 0));
538535
}
539536
}
540537

@@ -577,7 +574,7 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_slave_trans(spi_host_t host, spi_t
577574
} else {
578575
ESP_LOGW(TAG,"Using unaligned data may reduce transmission efficiency");
579576
memset(spi_object[host]->buf, 0, sizeof(uint32_t) * 16);
580-
memcpy(spi_object[host]->buf, trans->miso, trans->bits.miso / 8 + (trans->bits.miso % 8) ? 1 : 0);
577+
memcpy(spi_object[host]->buf, trans->miso, trans->bits.miso / 8 + ((trans->bits.miso % 8) ? 1 : 0));
581578
for (x = 0; x < trans->bits.miso; x += 32) {
582579
y = x / 32;
583580
SPI[host]->data_buf[y] = spi_object[host]->buf[y];
@@ -599,7 +596,7 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_slave_trans(spi_host_t host, spi_t
599596
y = x / 32;
600597
spi_object[host]->buf[y] = SPI[host]->data_buf[y];
601598
}
602-
memcpy(trans->mosi, spi_object[host]->buf, trans->bits.mosi / 8 + (trans->bits.mosi % 8) ? 1 : 0);
599+
memcpy(trans->mosi, spi_object[host]->buf, trans->bits.mosi / 8 + ((trans->bits.mosi % 8) ? 1 : 0));
603600
}
604601
}
605602

0 commit comments

Comments
 (0)