Merge pull request #3234 from fmkong/spi_flash_sfud

[drivers/spi_flash_sfud] accept the error from spi read or write in spi_write_read function.
This commit is contained in:
Bernard Xiong 2019-12-18 20:03:28 +08:00 committed by GitHub
commit a87c2ef970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -156,11 +156,11 @@ static sfud_err spi_write_read(const sfud_spi *spi, const uint8_t *write_buf, si
if(rtt_dev->rt_spi_device->bus->mode & RT_SPI_BUS_MODE_QSPI) { if(rtt_dev->rt_spi_device->bus->mode & RT_SPI_BUS_MODE_QSPI) {
qspi_dev = (struct rt_qspi_device *) (rtt_dev->rt_spi_device); qspi_dev = (struct rt_qspi_device *) (rtt_dev->rt_spi_device);
if (write_size && read_size) { if (write_size && read_size) {
if (rt_qspi_send_then_recv(qspi_dev, write_buf, write_size, read_buf, read_size) == 0) { if (rt_qspi_send_then_recv(qspi_dev, write_buf, write_size, read_buf, read_size) <= 0) {
result = SFUD_ERR_TIMEOUT; result = SFUD_ERR_TIMEOUT;
} }
} else if (write_size) { } else if (write_size) {
if (rt_qspi_send(qspi_dev, write_buf, write_size) == 0) { if (rt_qspi_send(qspi_dev, write_buf, write_size) <= 0) {
result = SFUD_ERR_TIMEOUT; result = SFUD_ERR_TIMEOUT;
} }
} }
@ -173,11 +173,11 @@ static sfud_err spi_write_read(const sfud_spi *spi, const uint8_t *write_buf, si
result = SFUD_ERR_TIMEOUT; result = SFUD_ERR_TIMEOUT;
} }
} else if (write_size) { } else if (write_size) {
if (rt_spi_send(rtt_dev->rt_spi_device, write_buf, write_size) == 0) { if (rt_spi_send(rtt_dev->rt_spi_device, write_buf, write_size) <= 0) {
result = SFUD_ERR_TIMEOUT; result = SFUD_ERR_TIMEOUT;
} }
} else { } else {
if (rt_spi_recv(rtt_dev->rt_spi_device, read_buf, read_size) == 0) { if (rt_spi_recv(rtt_dev->rt_spi_device, read_buf, read_size) <= 0) {
result = SFUD_ERR_TIMEOUT; result = SFUD_ERR_TIMEOUT;
} }
} }
@ -322,7 +322,7 @@ sfud_err sfud_spi_port_init(sfud_flash *flash) {
} }
#ifdef RT_USING_DEVICE_OPS #ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops flash_device_ops = const static struct rt_device_ops flash_device_ops =
{ {
RT_NULL, RT_NULL,
RT_NULL, RT_NULL,
@ -734,6 +734,7 @@ static void sf(uint8_t argc, char **argv) {
for (i = 0; i < size; i += write_size) { for (i = 0; i < size; i += write_size) {
result = sfud_write(sfud_dev, addr + i, write_size, write_data); result = sfud_write(sfud_dev, addr + i, write_size, write_data);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
rt_kprintf("Writing %s failed, already wr for %lu bytes, write %d each time\n", sfud_dev->name, i, write_size);
break; break;
} }
} }
@ -761,6 +762,7 @@ static void sf(uint8_t argc, char **argv) {
} }
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
rt_kprintf("Read %s failed, already rd for %lu bytes, read %d each time\n", sfud_dev->name, i, read_size);
break; break;
} }
} }